0

I have a class MyObject and an app which main activity implements a Method test(ArrayList<MyObject> x)

    public class MyObject {

    private String x;

    MyObject(String x) {
        this.x = x;
    }

    public String getX() {
        return x;
    }
}

Now i need to hook the method test with xposed to get the parameter x. How can i access and iterate through the ArrayList and call the getX method? My first approach was to pass this as argument for the findAndHookMethod method:

final Class<?> myObject = XposedHelpers.findClass(
    "com.xposed.packagehook.MyObject", lpparam.classLoader);`

But i don't know how to wrap this into an ArrayList.

Robert
  • 39,162
  • 17
  • 99
  • 152
b0r.py
  • 71
  • 1
  • 7

1 Answers1

1

When developing hooks it is not a good idea to use the application source code as base. It is recommended to use the compiled APK file and decompile it using a tool like apktool. The reason for this is that the compiled code sometimes looks a bit different to what you expect:

The method parameter definition ArrayList<MyObject> comprises of two sections:

  1. The object type ArrayList
  2. A (generics) type parameter MyObject

Generics were not part of the original Java definition and when this concept was later added it was restricted to the compiler. Therefore the generics type parameter only exists at compiler time in the method signature. In the app dex byte code and at rune-time you will only see the method test this way:

void test(ArrayList x)

Or the same in Smali code as it it output by apktool:

method public test(Ljava/util/ArrayList;)V

Some decompiler may also show the generic type parameter, but that information comes from an annotation that is not part of the method signature you need for hooking the method.

Hence if you want to hook this method the MyObject is totally irrelevant. Just hook the test method that has the java.util.ArrayList parameter and you are done.

Robert
  • 39,162
  • 17
  • 99
  • 152
  • Ok. So i can access the ArrayList. But how can i call the getX method, since i dont have the MyObject class in my xposed app? – b0r.py Jun 13 '20 at 12:36
  • @Mow As it is Java you can still access each an every method via reflection. A very similar example can be found [here (especially the last lines of the code)](https://stackoverflow.com/a/54362743/150978) which invokes the method `setParents` on a Person object that is defined by the app. – Robert Jun 14 '20 at 10:42
  • I have done it with the `XposedHelpers.callMethod` method. – b0r.py Jun 14 '20 at 13:45