如何挂钩包含自定义类数组的方法?
[Lcom/samsung/android/uniform/widget/notification/NotificationItem;
这是smali参数。我可以使用XposedHelpers.findClass()
来获得该类,但是无法创建它的数组。
答案 0 :(得分: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;
}
}
答案 1 :(得分:0)
尝试一下:
XposedHelpers.findAndHookMethod(class, "xxxMethod", "com.samsung.android.uniform.widget.notification.NotificationItem[]", new XC_MethodHook() {
...
});