Adventures on Security
  • Hello World!
  • Frida
    • Analysis of Network Security Configuration bypasses with Frida
  • frida scripting guide
    • Frida scripting guide for Java
    • Primitive types
    • Methods
    • Access to content of classes
    • "this" reference
    • Arrays
    • Enums
    • Inheritance
    • Interfaces
    • Inner classes
    • Exception handling
Powered by GitBook
On this page

Was this helpful?

  1. frida scripting guide

"this" reference

How to get and use the "this" parameter from Java

PreviousAccess to content of classesNextArrays

Last updated 3 years ago

Was this helpful?

**** NOTE: BLOG MOVED TO ****

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.

https://cmrodriguez.me/