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

xposed代码示例

时间:2019-09-30 16:54:51      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:loader   抽象   sed   throws   tst   override   dem   for   函数   

package com.example.xposedhook;

import android.util.Log;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class HookStatic implements IXposedHookLoadPackage {

    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
        if(loadPackageParam.packageName.equals("com.cxa.xposeddemo"));
        Class<?> clazz=XposedHelpers.findClass("com.cxa.xposeddemo.Demo",loadPackageParam.classLoader);
        XposedHelpers.setStaticIntField(clazz,"字段名",100);
        XposedHelpers.setStaticObjectField(clazz,"字段名","字段值");
        //Hook构造函数  XC_MethodHook是抽象类需要实现其方法
        XposedHelpers.findAndHookConstructor(clazz,new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                Log.d("cxa","无参构造函数");
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                Log.d("cxa","无参构造函数后");
            }
        });

        //Hook构造函数  XC_MethodHook是抽象类需要实现其方法
        // clazz后面可以跟参数:格式String.class或者int.class传字节码:[类型.class]
        XposedHelpers.findAndHookConstructor(clazz,String.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                param.args[0] ="cxa修改后"; //修改第一个参数
                //Log.d("cxa","无参构造函数");
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                Log.d("cxa","有参构造函数后");
            }
        });

        //hook函数
        XposedHelpers.findAndHookMethod(clazz, "", String.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                Log.d("cxa","函数before");
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                Log.d("cxa","函数after");
            }
        });


    }
}

xposed代码示例

标签:loader   抽象   sed   throws   tst   override   dem   for   函数   

原文地址:https://www.cnblogs.com/c-x-a/p/11613035.html

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