Frida: How to access class member variable if there's a member function called the same name?

Created on 9 Apr 2019  路  3Comments  路  Source: frida/frida

A class looks like:

class x {
    double f = 200.0d;
    public void f() {...}
}

A variable and a function, both called 'f'. In hook function, all this.f is actually pointing to the function, how to access the variable?

Most helpful comment

From the docs https://www.frida.re/docs/examples/android/

Note we use this.m.value = 0 instead of this.m = 0 to set the field鈥檚 value. If there is also a method in this class called m, we need to use this._m.value = 0 to set the value of field m. In general, when looking at the properties of objects it will be necessary to use .value to access the values those fields refer to.

All 3 comments

Try this._f(). Useful reading Overcoming some gotchas in frida

From the docs https://www.frida.re/docs/examples/android/

Note we use this.m.value = 0 instead of this.m = 0 to set the field鈥檚 value. If there is also a method in this class called m, we need to use this._m.value = 0 to set the value of field m. In general, when looking at the properties of objects it will be necessary to use .value to access the values those fields refer to.

Thanks. this._f works :)

Was this page helpful?
0 / 5 - 0 ratings