Frida Android

Frida Scripting Guide (4) - ’this’ Reference

Frida Scripting Guide (4) - ’this’ Reference

In this post I’ll show how to access the this reference. In Java (and a lot of other languages as well) there is always a special variable called this that references the object which is running the method. In Frida, whenever someone is rewriting a method, he has access to the “this” parameter. Check the following script as an example:

BasicTypes.addTwoInts.implementation = function (var1,var2) {
    console.log("the method is being called");
    return this.addTwoInts(var1,var2);
}

In this case the “this” references the class BasicTypes. So by calling the “this.addTwoInts” we are calling the original implementation of the method, instead of reimplementing it. This feature is useful for many use cases as:

  • know if a method is being called (as shown in the example above)
  • print the input values to know what is being received by the function.
  • print the stack trace to know where it is being called.

In all these cases the idea is not to change the workflow of the methods, just trace or debug the functionality.

Next: Arrays