Skip to content

Repository files navigation

hermes

English | 日本語

Overview

hermes is an Android dynamic method hooking playground project.
It combines Kotlin/Java APIs with a Rust native core to test ART method interception and replacement. It supports Android 8.0+ and the following ABIs: armeabi-v7a, arm64-v8a, x86, x86_64.

Repository layout:

  • hermes/: core library (Kotlin + Rust)
  • app/: sample app (Jetpack Compose UI for visual hook testing)

Installation

Hermes is published on Maven Central:

Add dependency in your app/library module:

dependencies {
    implementation("io.github.enuwbt:hermes:0.1.1")
    implementation(kotlin("reflect")) // required for KFunction-based APIs
}

If needed, ensure repositories include Maven Central:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
    }
}

Usage

1. Define hooks with DSL

import io.github.enuwbt.hermes.defineInterceptsOf

MyClass::class.defineInterceptsOf {
    method("sum", Int::class, Int::class) {
        implementation = { a: Int, b: Int ->
            self.memberFunction()
            val originalValue = original(a, b) as Int
            originalValue + 1
        }
    }
}

2. Hook a reflected method directly

import io.github.enuwbt.hermes.Hermes
import io.github.enuwbt.hermes.InterceptCallback

val method = MyClass::class.java.getDeclaredMethod("sum", Int::class.javaPrimitiveType, Int::class.javaPrimitiveType)
Hermes.intercept(method, object : InterceptCallback() {
    override fun onInvoke(receiver: Any?, args: Array<out Any?>): Any? {
        val originalValue = original(receiver, args) as Int
        return originalValue + 10
    }
})

3. Hook by function reference (Class::method.intercept)

import io.github.enuwbt.hermes.intercept
import io.github.enuwbt.hermes.InterceptCallback

MyClass::sum.intercept(object : InterceptCallback() {
    override fun onInvoke(receiver: Any?, args: Array<out Any?>): Any? {
        val originalValue = original(receiver, args) as Int
        return originalValue + 100
    }
})

Requirements

  • Android Studio (latest stable recommended)
  • JDK 11
  • Android SDK / NDK (as required by Gradle config)
  • Rust toolchain (cargo)
  • Rust Android targets (e.g. armv7-linux-androideabi, i686-linux-android, x86_64-linux-android, aarch64-linux-android)

Build

./gradlew cargoNdkBuild
./gradlew assembleDebug

Run the Sample

  1. Install the app module on a device/emulator
  2. Open the app and use each test item:
    • Call: run current implementation
    • Hook: install interception for that method
    • Result: show execution result

Notes

  • This project is intended for research/testing purposes.
  • Behavior may vary depending on Android version and CPU architecture.
  • Do not commit local.properties (environment-specific).

Credit

Third-Party Licenses

  • xz-embedded: 0BSD (hermes/src/main/rust/third_party/xz-embedded)

License

This project is licensed under the MIT License.
See LICENSE for details.

About

Android ART method hook library powered by Kotlin and Rust.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages