package com.example.exposedlesson01;
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 Main implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
String t_packageName = lpparam.packageName;
if ("hfdcxy.com.myapplication".equals(t_packageName)) {
XposedBridge.log("hooked!!!");
Class<?> aClass = lpparam.classLoader.loadClass("hfdcxy.com.myapplication.MainActivity");
XposedHelpers.findAndHookMethod(aClass, "check", String.class, String.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
// origin args
String name = (String)param.args[0];
String password = (String)param.args[1];
XposedBridge.log("hooked!!! name: " + name);
XposedBridge.log("hooked!!! password: " + password);
// modify
param.args[0] = "hfdcxy";
param.args[1] = "1234";
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
}
});
}
}
}
build.gradle
不要引入source,只引入api即可,否则不报错,但是永远找不到IXposedHookLoadPackage
dependencies {
......
//以下一句引用
compileOnly 'de.robv.android.xposed:api:82'
}
setting,gradle
中添加dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
//以下一句引用
maven { url "https://api.xposed.info/"}
}
}
最后完美hook
日志:
02-15 18:21:50.066 4987 4987 I EdXposed-Bridge: hooked!!!
02-15 18:22:00.305 4987 4987 I EdXposed-Bridge: hooked!!! name: ddd
02-15 18:22:00.305 4987 4987 I EdXposed-Bridge: hooked!!! password: fdd
02-15 18:22:06.627 4987 4987 I EdXposed-Bridge: hooked!!! name: ddd
02-15 18:22:06.627 4987 4987 I EdXposed-Bridge: hooked!!! password: fdd