简体   繁体   中英

Frida +Python+Javascript what does “java.use (”XXX“) ” do when the class can not be found?

I use the following javascrip inside python (in android + frida environment) to hook a method.

jscode ="""
Java.perform(function () { 
    console.log("start hook...");
    var d =java.use("myapp.okhttp3.internal.f.a");
    d.verify.implementation =function(p1, p2){
    console.log("ssl unpinning for"); 
    return true; 
    }
});
""" 

This is the python file:

import sys  
import os  
import threading  
import subprocess  
import frida  
import time


jscode ="""
Java.perform(function () { 
    console.log("start hook...");
    var d =java.use("myapp.okhttp3.internal.f.a");
    d.verify.implementation =function(p1, p2){
    console.log("ssl unpinning for"); 
    return true; 
    }
});
"""  
os.system('adb forward tcp:27042 tcp:27042')  
os.system('adb forward tcp:27043 tcp:27043')  

APP_NAME = 'myapp'   
device = frida.get_usb_device(1)
pid = device.spawn([APP_NAME])  
device.resume(pid)  
time.sleep(1)  
process = device.attach(pid)  
print('success')
script = process.create_script(jscode) 
print(pid) 
script.load() 
print('script loaded') 
input()

My question is: Does var d =java.use("myapp.okhttp3.internal.fa") throw "class not found exception" when the class can not be found, and how to view this exception? can I use codes like console.log(java.use("myapp.okhttp3.internal.fa") to log "class not found exception"?

You can use surround try-catch in js and catch @ handle in python

try {
  var d =...
} catch (e) {
  send(JSON.stringify(e));
}

In python side

def on_message(msg, _data):
  # check if msg has error and handle

script.on('message', on_message)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM