Interfaces
how to use interfaces
**** NOTE: BLOG MOVED TO https://cmrodriguez.me/ ****
An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods.
An interface is different from a class in several ways:
You cannot instantiate an interface.
An interface does not contain any constructors.
All of the methods in an interface are abstract.
An interface cannot contain instance fields. The only fields that can appear in an interface must be declared both static and final.
An interface is not extended by a class; it is implemented by a class.
To test this functionality I've created in the application an interface called MyInterface, and a class that implements the interface called MyInterfaceClass.
In order to get the interface representation in Frida we use the same code as we would use for a class:
We can't intercept or modify the abstract methods exposed by the interface. As an example I tried to implement the getMessage method from the interface in the following way:
When we call the getMessage from the implementation of the getMessage method in the MyInterfaceClass, the console.log is not triggered. If we want to change the implementation, we have to do it in each class the abstract method is implemented. In this case we did it on the only class implementing MyInterface:
Note that we can't instantiate an interface, it will throw the following error:
When we get an instance of a class that implements an interface, we can call the interfaces' methods, but Frida will end up calling the classes implementations as in the following examples:
Last updated