frida / frida-node

Frida Node.js bindings
281 stars 65 forks source link

Correct way to get args in onLeave? #65

Closed CaledoniaProject closed 3 years ago

CaledoniaProject commented 3 years ago

The testMethod has a pointer argument which will be modified in the method. I need to read its value in onLeave. Right now I had to store the variable in onEnter then read it in onLeave.

I'm wondering if there's a better way to do that? It's not healthy for multithread programs.

    let data = null
    Interceptor.attach(testMethod, {
        onEnter: function (args) {
            data = args[4]
        },
        onLeave: function (retval) {
            console.log(Memory.readInt(data))           
        }
    });
FrenchYeti commented 3 years ago

Hi,

Simple by doing :

Interceptor.attach(testMethod, {
onEnter: function (args) {
this.data = args[4];
}, onLeave: function (retval){
console.log(Memory.readInt(this.data))
}
});

You can also use CPU context to save the value of 4th arg (example with arm64):

this.data = this.context.x4;

-------- Message d'origine -------- Le 10 août 2021 à 16:51, CaledoniaProject a écrit :

The testMethod has a pointer argument which will be modified in the method. I need to read its value in onLeave. Right now I had to store the variable in onEnter then read it in onLeave.

I'm wondering if there's a better way to do that? It's not healthy for multithread programs.

let data = null Interceptor.attach(testMethod, { onEnter: function (args) { data = args[4] }, onLeave: function (retval) { console.log(Memory.readInt(data)) } });

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

oleavr commented 3 years ago

Also some useful hints here.

CaledoniaProject commented 3 years ago

Thanks!