1. 程式人生 > >xposed自定義參數

xposed自定義參數

類對象 獲取 tcl class對象 set 利用反射 end 允許 protected

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對象

xposed自定義參數