其他分享
首页 > 其他分享> > xposed代码示例

xposed代码示例

作者:互联网

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");
            }
        });


    }
}

标签:Log,xposed,XC,代码,示例,param,clazz,cxa,Override
来源: https://www.cnblogs.com/c-x-a/p/11613035.html