1.创建项目后,右键app创建一个目录lib,将XposedBridgeApi-54.jar,拖拽进lib目录,然后右键添加进本地链接库
2.更改app下的build.gradle文件, 在依赖关系dependencies里最后一行加上
provided files('lib/XposedBridgeApi-54.jar')
3.新建文件夹assets
4.在assets下创建文件xposed_init文件,hook类方法的入口地址eg:
com.example.administrator.xposed.XposedBigBang
5.AndroidManifest.xml设置
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.Xmodule" android:versionName="1.0" android:versionCode="1">
<uses-sdk android:minSdkVersion="15"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<meta-data
android:name="xposedmodule"
android:value="true"/>
<meta-data
android:name="xposeddescription"
android:value="Xposed模块示例"/>
<meta-data
android:name="xposedminversion"
android:value="54"/><!-- 对应的XposedBridge版本号 -->
</application>
</manifest>
6.确定好入口地址,就创建入口文件即java目录下的com.example.administrator包中新建一个java类文件名为XposedBigBang,对应上面的入口地址
7.
package com.example.administrator.xposed; //这里选择自己项目对应的包
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;
public class XposedBigBang implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
// 标记目标app包名
if (!lpparam.packageName.equals("com.example.administrator.helloworld")) //这里选择自己要hook的包
return;
// Log.d("!!!!!!!!","HOOK CONTENT !!"); //输出到android device monitor的日志中
// XposedBridge.log("Loaded app: " + lpparam.packageName); //输出到xposed的日志中
// findAndHookMethod(hook方法的类名,classLoader,hook方法名,hook方法参数...,XC_MethodHook)
XposedHelpers.findAndHookMethod("android.content.ContextWrapper", lpparam.classLoader, "getPackageManager",String.class,
new XC_MethodHook() {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// Class clazz = param.thisObject.getClass(); 获取参数对象
// XposedBridge.log("class name:"+clazz.getName());
// XposedBridge.log("BEFORE HOOK SUCCESSFUL");
Log.d("BEFORE 参数1",param.args[0].toString()); 可以打印出方法的第一个参数
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// Class clazz = param.thisObject.getClass();
// Object obj=param.getResult(); 获取方法返回的结果,要注意结果的类型。
// // XposedBridge.log("class name:"+clazz.getName());
// XposedBridge.log("AFTER HOOK SUCCESSFUL");
// Log.d("create file","");
// XposedBridge.log(obj.toString()); 将结果转化成字符打印到日志
}
});
}
}
8.用到的xposed版本:de.robv.android.xposed.installer_v33_36570c.apk(不是最新的,适合新手练手)