标签:etc length rgs override result reflect log win pos
java反射机制允许在不显式调用类及类方法的前提下,实现创建类对象、调用类方法等一系列操作。 目标函数为TestArray,其参数为我们自定义的Person类的数组。 public class test { public static void main(String[] args){ Person person1 = new Person("aa",12,"male"); Person person2 = new Person("ab",13,"female"); Person person3 = new Person("ac",14,"male"); Person[] person = new Person[]{person1,person2,person3}; System.out.print(TestArray(Person[] person)); } public String TestArray(Person[] person){ String result = ""; for (int i =0;i<person.length;i++){ result += "name = "+person[i].getName()+",age = " +person[i].getAge()+",gender = "+person[i].getGender()+"\n"; } return result; }; } Person 类为: public class Person { private String name; private int age; private String gender; public Person(String name,int age,String gender){ this.name = name; this.age = age; this.gender = gender; }; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } } 使用Xposed去hook方法TestArray(Person[] person)时,hook方法为: Class<?> personClass = findClass("com.zq.inputmethodtest.Person",lpparam.classLoader); findAndHookMethod("com.zq.inputmethodtest.MainActivity", lpparam.classLoader, "TestArray",java.lang.reflect.Array.newInstance(personClass, 2).getClass(), new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { param.setResult("person数组被修改"); Log.d("InputTest-->after ",""+ param.getResult()); } }); 利用反射方法获取Person类的class对象
标签:etc length rgs override result reflect log win pos
原文地址:https://www.cnblogs.com/codeDevotee/p/9461881.html