xposed代码示例

Posted c-x-a

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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");
            
        );


    


以上是关于xposed代码示例的主要内容,如果未能解决你的问题,请参考以下文章

Xposed插件dump Cocos2d-x应用的lua脚本

用xposed框架写代码可以用debug调试吗?

xposed微信模块源代码

xposed可以hook所有的java函数吗?

解决AndroidStudio修改代码运行没变化没生效的问题-Xposed插件重载

查找和定位Android应用的按钮点击事件的代码位置基于Xposed Hook实现