码迷,mamicode.com
首页 > 其他好文 > 详细

xposed自定义参数

时间:2018-08-12 10:32:13      阅读:694      评论:0      收藏:0      [点我收藏+]

标签: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对象

 

xposed自定义参数

标签:etc   length   rgs   override   result   reflect   log   win   pos   

原文地址:https://www.cnblogs.com/codeDevotee/p/9461881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!