Android xposed Hook 初探01
程序员文章站
2022-05-12 14:02:41
...
参考资料
https://blog.csdn.net/qq_42229759/article/details/103066214
事前准备:
xposed.apk
XposedBridgeApi-82.jar
环境目录:
test001/app/mylib 目录下存放的是XposedBridgeApi-82.jar 相关的包
test001/app/src/main/assets/xposed_init 文件中的内容是实现hook的包 + 类; 例如
com.example.test001.HookTest
在build.gradle 中需要将xpose的包引入
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// 引入mylib中的jar
compileOnly fileTree(dir: 'mylib', include: ['*.jar'])
}
/test001/app/src/main/java/HookTest 中是 Hook实现的方法
package com.example.test001;// hook 导入包
import java.lang.reflect.Method;
import java.util.Map;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import de.robv.android.xposed.XC_MethodHook;
public class HookTest implements IXposedHookLoadPackage{
String signurl_classname = "com.chanjet.library.utils.FormatUrlUtils";
String md5password_classname = "com.chanjet.library.utils.EncryptUtils";
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (!loadPackageParam.packageName.equals("com.foundao.bjnews")) {
return;
}
XposedBridge.log("xposed 测试");
// Class clazz = loadPackageParam.classLoader.loadClass(signurl_classname);
// XposedHelpers.findAndHookMethod(clazz, "formatUrlMap", new XC_MethodHook() {
// 打印类中的方法名
Class <?> a_class = XposedHelpers.findClass(signurl_classname, loadPackageParam.classLoader);
for(Method method : a_class.getDeclaredMethods()){
XposedBridge.log("方法名:"+ method.getName());
}
// signurl signurl_classname 为 由包到类的名称 signUrl 为方法名称 Map.class 是方法中参数的类型
XposedHelpers.findAndHookMethod(signurl_classname, loadPackageParam.classLoader, "signUrl", Map.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
XposedBridge.log("signUrl params: " + param.args[0].toString());
}
});
// formaturlmap
XposedHelpers.findAndHookMethod(signurl_classname, loadPackageParam.classLoader, "formatUrlMap", Map.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
// 获取结果
Object f_result = param.getResult();
XposedBridge.log("formatUrlMap params: " + param.args[0].toString());
XposedBridge.log("formatUrlMap result: " + f_result.toString());
}
});
Class <?> b_class = XposedHelpers.findClass(md5password_classname, loadPackageParam.classLoader);
for(Method method : b_class.getDeclaredMethods()){
XposedBridge.log("方法名: " + method.getName());
}
// hook多个参数的函数, 注 boolean 类型的参数 用boolean,不能使用Boolean
XposedHelpers.findAndHookMethod(md5password_classname, loadPackageParam.classLoader, "md5Password", String.class, boolean.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
XposedBridge.log("md5password param1:" + param.args[0].toString());
Object result = param.getResult();
XposedBridge.log("md5password result:" + result.toString());
}
});
}
}
hook 函数:
上述hook功能 将参数和结果卸载了xposed 的日志中了。
在手机上安装好virtualxposed以后, 可以在xposed-install 中的日志进行查看。
上一篇: 萌新的linux之旅1