/EasyHook

让 Xposed 模块开发变得更简单

Primary LanguageKotlinMIT LicenseMIT

EasyHook

  • Xposed API wrapper for Kotlin

Usage

  • In project root directory
git submodule add -b <branch> 'https://github.com/Mufanc/EasyHook' easyhook 
  • In settings.gradle.kts
include(
    ":easyhook:api",
    ":easyhook:ksp-xposed"
)
  • In project build.gradle.kts
val applicationModuleName by extra(":app")  // replace with your app module name 
  • In module build.gradle.kts
plugins {
    id("com.google.devtools.ksp") version "<version>"
}

dependencies {
    implementation(project(":easyhook:api"))
    ksp(project(":easyhook:ksp-xposed"))
}

Demo

  • Before
class HookEntry : IXposedHookLoadPackage {
    
    companion object {
        const val TAG = "CustomTAG"
    }
    
    override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
        if (lpparam.packageName == BuildConfig.APPLICATION_ID) {
            XposedHelpers.findAndHookMethod(
                Activity::class.java,
                "onCreate",
                Bundle::class.java,
                object : XC_MethodHook() {
                    override fun afterHookedMethod(param: MethodHookParam?) {
                        Log.i(TAG, "Activity created!")
                    }
                }
            )
        }
    }
}
  • After
@XposedEntry
class HookEntry : HookHelper("CustomTAG") {
    override fun onHook() = handle {
        onLoadPackage(BuildConfig.APPLICATION_ID) {
            Activity::class.java.hook {
                method({ name == "onCreate" }) {
                    Logger.i("Activity created!")
                }
            }
        }
    }
}