简体   繁体   English

ArrayList的挂接方法<myobject>范围</myobject>

[英]Hooking method with ArrayList<MyObject> parameter

I have a class MyObject and an app which main activity implements a Method test(ArrayList<MyObject> x)我有一个 class MyObject和一个主要活动实现方法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 .现在我需要将方法test与 xposed 挂钩以获取参数x How can i access and iterate through the ArrayList and call the getX method?我如何访问和遍历 ArrayList 并调用getX方法? My first approach was to pass this as argument for the findAndHookMethod method:我的第一种方法是将其作为findAndHookMethod方法的参数传递:

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

But i don't know how to wrap this into an ArrayList.但我不知道如何将其包装到 ArrayList 中。

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.建议使用编译好的APK文件,使用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:方法参数定义ArrayList<MyObject>包括两个部分:

  1. The object type ArrayList object 型ArrayList
  2. A (generics) type parameter MyObject一个(泛型)类型参数MyObject

Generics were not part of the original Java definition and when this concept was later added it was restricted to the compiler. Generics 不是原始 Java 定义的一部分,后来添加此概念时,它仅限于编译器。 Therefore the generics type parameter only exists at compiler time in the method signature.因此 generics 类型参数仅在编译器时存在于方法签名中。 In the app dex byte code and at rune-time you will only see the method test this way:在 app dex 字节码和 rune-time 中,您只会以这种方式看到方法测试:

void test(ArrayList x)

Or the same in Smali code as it it output by apktool:或者在 Smali 代码中与 apktool 的 output 相同:

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.因此,如果您想挂钩此方法,则MyObject完全无关紧要。 Just hook the test method that has the java.util.ArrayList parameter and you are done.只需挂钩具有java.util.ArrayList参数的测试方法即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM