Loading... ## 工作目录 ![image.png](http://type.zimopy.com/usr/uploads/2024/01/3215148312.png) ## 开始编写 ### 第一步 安装XposedBridgeApi.jar 下载,并放到`lib`文件夹里面: <div class="hideContent">此处内容需要评论回复后(审核通过)方可阅读。</div> ### 第二步 引入jar包 编辑app>build.gradle文件 ```yaml //引用导入的包 compileOnly fileTree(include: ['*.jar'], dir: 'lib') implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' ``` ### 第三步 添加xposed_init 在assets资源文件里面添加`xposed_init`文件,内容为 ```bash com.huoyu.xposed_demo_hello.xposed_start # 这里的是 将自己的启动类名放进来:包名加类名 ``` ### 第四步 修改AndroidManifest.xml 在application里面添加 ```xml <!--告诉xposed这是插件--> <meta-data android:name="xposedmodule" android:value="true" /> <!--插件版本--> <meta-data android:name="xposedminversion" android:value="30" /> <!--插件描述--> <meta-data android:name="xposeddescription" android:value="xposed_hello" /> ``` ### MainActivty.class ```java package com.huoyu.xposed_demo_hello; import androidx.appcompat.app.AppCompatActivity; import com.huoyu.xposed_demo_hello.xposed_start; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // TextView textView = new TextView(this); // textView.setText("Xposed RPC Demo"); // setContentView(textView); } } ``` ### xposed_start.class ```java package com.huoyu.xposed_demo_hello; import android.util.Log; import de.robv.android.xposed.IXposedHookLoadPackage; import de.robv.android.xposed.XC_MethodHook; import de.robv.android.xposed.XposedBridge; import de.robv.android.xposed.XposedHelpers; import de.robv.android.xposed.callbacks.XC_LoadPackage; //xposed api案例 public class xposed_start implements IXposedHookLoadPackage { @Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable { if (loadPackageParam.packageName.equals("com.zimo.demo")) { Log.d("进入软件","等待hook激活"); //HOOK 无参构造函数 //查找类字节码 Class<?> aClass = XposedHelpers.findClass("com.qianyu.fridaapp.Money", loadPackageParam.classLoader); //设置变量的值 XposedHelpers.setObjectField(aClass,"name","大哥"); XposedHelpers.setIntField(aClass,"num",6666666); XposedHelpers.findAndHookConstructor(aClass,new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { Log.d("huoyu","Hook构造函数之前"); } @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { Log.d("huoyu","Hook构造函数之后"); } }); //修改构造函数的参数 //查找类字节码 Class<?> aClass_g = XposedHelpers.findClass("com.zimo.demo.Structure", loadPackageParam.classLoader); XposedHelpers.findAndHookConstructor(aClass_g,int.class, String.class,new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { // super.beforeHookedMethod(param); Log.d("huoyu","修改参数之前_参数1:"+param.args[0].toString()); Log.d("huoyu","修改参数之前_参数2:"+param.args[1].toString()); Log.d("huoyu","Hook构造函数之前"); // 修改参数 param.args[0]=666666; param.args[1]="大哥"; } @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { // super.afterHookedMethod(param); Log.d("huoyu","Hook构造函数之后"); Log.d("huoyu","修改参数之后_参数1:"+param.args[0].toString()); Log.d("huoyu","修改参数之后_参数2:"+param.args[1].toString()); } }); //HOOK 普通方法 Class<?> aClass_pu = XposedHelpers.findClass("com.zimo.demo.Utils", loadPackageParam.classLoader); XposedHelpers.findAndHookMethod(aClass_pu, "Take_ginse_tw", int.class, int.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { Log.d("huoyu","HOOK普通方法之前 "+param.args[0]+" "+param.args[1]); // 改变参数之前的结果 Log.d("huoyu",param.getResult().toString()); } @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { Log.d("huoyu","HOOK普通方法之后"); // 更改返回值 param.setResult(9999); // 打印改变参数之后的操作的目标类方法的函数返回值ֵ Log.d("huoyu",param.getResult().toString()); // 下面的是在手机xp框架的日志里面 XposedBridge.log("huoyu" + param.getResult()); } }); // HOOK重载方法 无参 XposedHelpers.findAndHookMethod(aClass_pu, "Thanks", new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { Log.d("huoyu",param.getResult().toString()); } }); // HOOK重载方法 带参 XposedHelpers.findAndHookConstructor(aClass_pu, "Thanks", Long.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { Log.d("huoyu","重载方法 改变之前参数是:"+param.args[0]); param.args[0]="66666666"; } @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { // super.afterHookedMethod(param); Log.d("huoyu","重载方法 改变之后参数是:"+param.args[0]); } }); //HOOK普通方法 复杂参数 //HOOK 自定义参数 方法 // HOOK覆盖函数 // HOOK 内部类 并且主动调用 } } } ``` 没报错的话,打包运行就可以了 最后修改:2024 年 05 月 25 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏