Skip to content

About

Java method hooking for Android, with an Xposed-compatible API

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

exteraHook

exteraHook

Java method hooking for Android apps, with an Xposed-compatible API. It powers the plugins of exteraGram.

License

What it does

  • Hooks Java methods and constructors inside the app's own process, on Android 7.0 (API 24) and later, through LSPlant.
  • Has its own API, com.exteragram.hook, built around a chain of interceptors. An interceptor can call the original any number of times, with other arguments or another receiver.
  • Keeps the classic de.robv.android.xposed API (XposedBridge, XC_MethodHook) as a thin layer over that chain, so existing Xposed-style code and Python plugins through Chaquopy keep working.
  • Experimental partial hooks: a single call site, field read or write, or instruction inside a method, done by rewriting that method's dex.
  • Runtime helpers: calling the original method, deoptimizing callers that inlined a hooked method, allocating objects without a constructor, and turning off hidden API restrictions and the profile saver.
import com.exteragram.hook.ExteraHook

val target = SomeClass::class.java.getDeclaredMethod("targetMethod", String::class.java)

val handle = ExteraHook.hook(target).intercept { chain ->
    "hooked(${chain.proceed()})"
}

handle.unhook()

How to add it to an app, use it from Java, Kotlin or Python, and what the runtime does under the hood is in docs/host-integration.md.

Modules

  • exterahook (hook-core/): the library.
  • shadowhook (third_party/shadowhook/): ShadowHook 2.0.1 for inline hooks, built from source.
  • third_party/LSPlant-master/: LSPlant with exteraHook's changes, a separate Gradle build that the root build includes.
  • test-host: an app with a scenario for every runtime path. It runs them through instrumentation, on Gradle Managed Devices, or from its own screen.

Building

You need:

  • JDK 17 to 24. Gradle 8.14 does not run on JDK 25, which recent Android Studio versions bundle;
  • Android SDK 36, NDK 29.0.14206865 and CMake 3.28 or newer;
  • a local.properties with sdk.dir both in the root and in third_party/LSPlant-master.
./gradlew :exterahook:testDebugUnitTest
./gradlew :exterahook:assembleRelease
./gradlew :test-host:connectedUniversalDebugAndroidTest
./gradlew :test-host:matrixCheck

Publishing

The artifacts are not on a public Maven repository. Publish them into a local one that your app reads:

./gradlew :exterahook:publish -PlocalPublishRepo=/path/to/maven-repo
./gradlew :shadowhook:publish -PlocalPublishRepo=/path/to/maven-repo
cd third_party/LSPlant-master
./gradlew :lsplant:publishLsplantPublicationToLocalExteraRepoRepository \
  -PlocalPublishRepo=/path/to/maven-repo

This publishes:

  • com.exteragram.hook:hook-core:1.0.1
  • com.exteragram.hook.thirdparty:lsplant:6.4-extera.9
  • com.bytedance.android:shadowhook:2.0.1

An app that uses hook-core also needs these three and org.lsposed.hiddenapibypass:hiddenapibypass. The native parts are static libraries consumed through prefab.

Notes

  • Only armeabi-v7a and arm64-v8a are supported.
  • The exterahook AAR does not package libshadowhook.so or libshadowhook_nothing.so.
  • The arm64 build of ShadowHook uses -mbranch-protection=standard.
  • Turning off hidden API restrictions can be a problem for Google Play. Decide that per app.

License

exteraHook is licensed under the GNU Lesser General Public License v3.0 or later, with additional terms: an app that ships exteraHook and has a user interface must name it, with a link to this repository, among the legal notices it displays.

Third-party code in this repository keeps its own license, see NOTICE.md. LSPlant is modified, see its list of changes.

About

Java method hooking for Android, with an Xposed-compatible API

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages