Say app use a button to trigger function call.
Button btn = new Button(this);
btn.setText("Test");
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hello();
}
});
The function define:
public int hello() {
Log.v(TAG,"hello frida!");
return 0;
}
The script to hook hello
API:
Java.perform(function () {
var clzname = "com.sample.MainActivity";
var instance = Java.use(clzname);
instance.hello.overload().implementation = function () {
console.log("[*] onEnter hello...");
var retval = this.hello();
return retval;
};
});
If launch app, then attach script:
frida -U -l hook.js com.sample
it works fine, below log will output:
-> [*] onEnter hello...
But if launch app, then click button to trigger the API call firstly, then attach script, it does not work, no output from console.
Does that means if API already being called, then we can not hook it? How to fix my script?