#coding=utf-8
import frida
import sys
session = frida.get_remote_device().attach("com.example.hooktest")
#print session.enumerate_modules()
jscode = """
Java.perform(function(){
send("Running Script");
var getString = undefined;
exports = Module.enumerateExportsSync("libtest.so");
for(i=0; i<exports.length; i++){
if(exports.name == "Java_com_example_hooktest_MainActivity_getString"){
getString = exports.address;
send("getInt is at " + getString);
break;
}
}
var getInt = undefined;
exports = Module.enumerateExportsSync("libtest.so");
for(i=0; i<exports.length; i++){
if(exports.name == "getInt"){
getInt = exports.address;
send("getInt is at " + getInt);
break;
}
}
var fungetInt = new NativeFunction(getInt, 'int', ['int']);
Interceptor.attach(getString,{
onEnter: function (args) {
send("onEnter");
var res = fungetInt(99999);
send(res);
},
onLeave: function (retval) {
send("onLeave");
}
});
});
"""
def on_message(message, data):
print message
script = session.create_script(jscode)
script.on('message', on_message)
script.load()
sys.stdin.read()