2

如何挂钩包含自定义类数组的方法?

[Lcom/samsung/android/uniform/widget/notification/NotificationItem;

这是 smali 的论点。我可以得到这个类,XposedHelpers.findClass()但我不能创建它的数组..

4

2 回答 2

0

试试这个。

Class<?> notificationItemClass = Class.forName("...NotificationItem");
Class<?> notificationItemClassArray = java.lang.reflect.Array.newInstance(notificationItemClass, 2).getClass();

这是一个演示:

package com.aegis.log.controller.open;

import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by gallonyin on 2019/1/25.
 */
public class TestReflection {

  public static void main(String[] args) throws ClassNotFoundException,
    InstantiationException, IllegalAccessException,
    IllegalArgumentException, SecurityException,
    InvocationTargetException, NoSuchMethodException {

    Class<?> relativeClass = Class.forName("com.aegis.log.controller.judgetool.Relative");
    Object relativeFather = relativeClass.newInstance();
    Object relativeMother = relativeClass.newInstance();
    relativeClass.getMethod("setName", String.class).invoke(relativeFather,
      "father");
    relativeClass.getMethod("setName", String.class).invoke(relativeMother,
      "mother");

    Class<?> personClass = Class.forName("com.aegis.log.controller.judgetool.Person");
    Object personObject = personClass.newInstance();

    Object[] temp = (Object[]) Array.newInstance(relativeClass, 2);
    temp[0] = relativeFather;
    temp[1] = relativeMother;

    Class<?> relativeArrayClass = Array.newInstance(relativeClass, 2).getClass();
    Method setParents = personClass.getMethod("setParents", relativeArrayClass);
    setParents.invoke(personObject, relativeArrayClass.cast(temp));
    personClass.getMethod("getParents").invoke(personObject);
  }
}

public class Person {
  private Relative[] parents;

  public void getParents() {
    for (Relative r : parents)
      r.getName();
  }

  public void setParents(Relative[] parents) {
    this.parents = parents;
  }
}

public class Relative {
  private String name;

  public void getName() {
    System.out.println(name);
  }

  public void setName(String name) {
    this.name = name;
  }
}
于 2019-01-25T09:52:07.333 回答
0

尝试这个:

XposedHelpers.findAndHookMethod(class, "xxxMethod", "com.samsung.android.uniform.widget.notification.NotificationItem[]", new XC_MethodHook() {
            ...
        });
于 2020-04-23T09:41:01.280 回答