Jtik是一个在android平台,以Java方法为粒度的运行时动态hook框架。其实现基于 ART TI,可以hook应用本身以及系统java方法。 由于使用的是系统公开接口,不涉及ART虚拟机内部的ArtMethod等内存结构修改,理论上适配性会比较强。
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.chancerly:jtik:0.0.1-Beta'
}
//if you want hook framework method,like Activity.onCreate
//JtikConfig.needHookSystemClass = true;
Jtik.init(context);
举例:有一个类Test
public class Test {
public int run(int a, int b){
...
}
}
Hook 类Test
的run
方法:
Jtik.hook(classLoader.loadClass("Test").getDeclaredMethod("run", int.class, int.class),
new com.zxc.jtik.MethodHook.Builder().setMethodEnterListener((o, objects) -> {
//do something on method enter...
}).setMethodExitListener((o, o1) -> {
//do something on method exit...
return o1;
}).setParamModifier(0, (thisObject, inParam) -> {
//do something if you want to modify the parameter...
return 6;//the parameter value you chage to
}).build());
理论上Android 8.0+全支持