Skip to content

Repository files navigation

DownloadJoin the chat at https://gitter.im/android-hacker/epic

中文文档入口

What is it?

Epic is the continution of Dexposed on ART(Supporting 4.0~8.1).

Dexposed is a powerful yet non-invasive runtime AOP (Aspect-oriented Programming) framework for Android app development, based on the work of open-source Xposedframework project.

The AOP of Dexposed is implemented purely non-invasive, without any annotation processor, weaver or bytecode rewriter. The integration is as simple as loading a small JNI library in just one line of code at the initialization phase of your app.

Not only the code of your app, but also the code of Android framework that running in your app process can be hooked.

Epic keeps the same API and all capability of Dexposed, you can do anything which is supported by Dexposed.

Typical use-cases

  • Classic AOP programming
  • Instrumentation (for testing, performance monitoring and etc.)
  • Security audit (sensitive api check,Smash shell)
  • Just for fun :)

Integration

Directly add epic aar to your project as compile libraries, it contains a jar file "dexposedbridge.jar" two so files "libdexposed.so libepic.so" from 'epic' directory.

Gradle dependency like following(jcenter):

dependencies {
compile 'me.weishu:epic:0.3.6'
}

Everything is ready.

Basic usage

There are three injection points for a given method: before, after, origin.

Example 1: monitor the creation and destroy of java thread

classThreadMethodHookextendsXC_MethodHook{
@OverrideprotectedvoidbeforeHookedMethod(MethodHookParamparam) throwsThrowable {
super.beforeHookedMethod(param);
Threadt = (Thread) param.thisObject;
Log.i(TAG, "thread:" + t + ", started..");
}
@OverrideprotectedvoidafterHookedMethod(MethodHookParamparam) throwsThrowable {
super.afterHookedMethod(param);
Threadt = (Thread) param.thisObject;
Log.i(TAG, "thread:" + t + ", exit..");
}
}
DexposedBridge.hookAllConstructors(Thread.class, newXC_MethodHook() {
@OverrideprotectedvoidafterHookedMethod(MethodHookParamparam) throwsThrowable {
super.afterHookedMethod(param);
Threadthread = (Thread) param.thisObject;
Class<?> clazz = thread.getClass();
if (clazz != Thread.class) {
Log.d(TAG, "found class extend Thread:" + clazz);
DexposedBridge.findAndHookMethod(clazz, "run", newThreadMethodHook());
}
Log.d(TAG, "Thread: " + thread.getName() + " class:" + thread.getClass() + " is created.");
}
});
DexposedBridge.findAndHookMethod(Thread.class, "run", newThreadMethodHook());

Example 2: Intercept the dex loading behavior

DexposedBridge.findAndHookMethod(DexFile.class, "loadDex", String.class, String.class, int.class, newXC_MethodHook() {
@OverrideprotectedvoidbeforeHookedMethod(MethodHookParamparam) throwsThrowable {
super.beforeHookedMethod(param);
Stringdex = (String) param.args[0];
Stringodex = (String) param.args[1];
Log.i(TAG, "load dex, input:" + dex + ", output:" + odex);
}
});

Checkout the sample project to find out more.

Support

Epic support all dalvik runtime arm architecture devices from Android 2.3 to 4.4 (no include 3.0), which inherits from Dexposed. Further more, it support ART thumb2 and arm64 architecture from Android 5.0 to 8.1. arm32, x86, x86_64 and mips are not supported now. The stability is not proved in any online product, it is only personal use now(mainly for performance analysis), Welcome to any compatibility issues or PRs.

Follow is support status.

RuntimeAndroid VersionSupport
Dalvik2.2Not Test
Dalvik2.3Yes
Dalvik3.0No
Dalvik4.0-4.4Yes
ARTL (5.0)Yes
ARTL MR1 (5.1)Yes
ARTM (6.0)Yes
ARTN (7.0)Yes
ARTN MR1 (7.1)Yes
ARTO (8.0)Yes
ARTO MR1(8.1)Yes

And the architecture support status:

RuntimeArchSupport
DalvikAllYes
ARTThumb2Yes
ARTARM64Yes
ARTARM32No
ARTx86/x86_64No
ARTmipsNo

Known Issues

  1. Short method (instruction less 8 bytes on thumb2 or less 16bytes in ARM64) are not supported.
  2. Fully inlined methods are not supported.
  3. Method parameters which contains float/double are not fully test on platform which support hardware float point(armeabi-v7a, arm64-v8a)
  4. arm64 in Android L is not supported.

Contribute

We are open to constructive contributions from the community, especially pull request and quality bug report. Currently, the implementation for ART is not proved in large scale, we value your help to test or improve the implementation.

You can clone this project, build and install the sample app, just make some click in your device, if some bugs/crash occurs, please file an issue or a pull request, I am very appreciative :)

Thanks

  1. Dexposed
  2. Xposed
  3. mar-v-in/ArtHook
  4. Nougat_dlfunctions

Contact me

twsxtd@gmail.com

Join discussion

About

Dynamic java method AOP hook for Android(continution of Dexposed on ART), Supporting 4.0~8.1

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages