XPosed实践
2021-04-14 本文已影响0人
吃饱了就送
项目配置
官方教程
首先清单文件
<meta-data
android:name="xposedmodule"
android:value="true" />
<meta-data
android:name="xposeddescription"
android:value="test_xposed" />
<meta-data
android:name="xposedminversion"
android:value="82" />
添加app下依赖
compileOnly 'de.robv.android.xposed:api:82'
在main目录下建立assets资源文件夹
目录结构
XposedInit里写hook逻辑,XposedBridge.log的日志在XPosed Installer的日志里看
public class XposedInit implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
XposedBridge.log("========test");
if(lpparam.packageName.equals("com.example.xposed")){
XposedHelpers.findAndHookMethod("com.example.xposed.MainActivity", lpparam.classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
XposedBridge.log("beforeHookedMethod");
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
XposedBridge.log("========afterHookedMethod");
Class<?> aClass = lpparam.classLoader.loadClass("com.example.xposed.MainActivity");
Field textView = aClass.getDeclaredField("textView");
textView.setAccessible(true);
TextView tv = (TextView) textView.get(param.thisObject);
tv.setText("success");
}
});
}
}
}
下载XPosed Installer
root的手机直接下载Xposed Installer,由于Android 5.0以上采用ART,而5.0以下默认采用Dalvik, 所以是有两个版本的Xposed,附上下载链接: Android 4.0.3-4.4:repo.xposed.info/module/de.r… Android 5.0以上::forum.xda-developers.com/showthread.…
未root下载太极或者virtualPosed
长按桌面会出现添加项目和设置,此时先添加项目
桌面
桌面上滑进入首页
点击左上角,打开模块勾选自己编写的hook项目
模块
此时回到桌面点击设置,然后点击重启
设置
现在进入首页点击hook项目就可了
hook前hook后
其它一些API
替换方法,跳转到其它activity
XposedHelpers.findAndHookMethod("me.suncloud.marrymemo.view.SplashActivity", lpparam.classLoader, "onLaunchFinish", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("replaceHookedMethod");
Class<?> aClass = XposedHelpers.findClass("com.hlj.hljmvlibrary.activities.WeddingMvListVideoActivity", lpparam.classLoader);
((Activity)param.thisObject).startActivity(new Intent((Activity)param.thisObject, aClass));
((Activity)param.thisObject).finish();
return null;
}
});
修改方法返回值
XposedHelpers.findAndHookMethod("com.hunliji.hljtinker.utils.Utils", lpparam.classLoader, "isXposedExists", Throwable.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
param.setResult(false);
}
});
fastjson打印Object
String className = "com.hlj.hljmvlibrary.activities.VideoMakeActivity";
Class<?> mvMakeClass = XposedHelpers.findClass("com.hlj.hljmvlibrary.models.MvVideoMakeBean", lpparam.classLoader);
XposedHelpers.findAndHookMethod(className, lpparam.classLoader, "setData", mvMakeClass, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Field movieId = param.thisObject.getClass().getDeclaredField("movieId");
Field mouldId = param.thisObject.getClass().getDeclaredField("mouldId");
movieId.setAccessible(true);
mouldId.setAccessible(true);
XposedBridge.log("========movieId===" + movieId.get(param.thisObject).toString());
XposedBridge.log("========mouldId===" + mouldId.get(param.thisObject).toString());
super.beforeHookedMethod(param);
for (Object arg : param.args) {
Object toJSON = JSON.toJSON(arg);
XposedBridge.log("========args===" + toJSON.toString());
}
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
XposedBridge.log("========afterHookedMethod");
}
});