Introduce

YukiHookAPI is an integrated Hook API Framework, which does not provide any Hook functions, and needs the support of Xposed related basic APIs.

Background

This is an efficient Hook API rebuilt based on the Xposed API using Kotlin, and creates rich function extensions for the development of Xposed Modules.

The name is taken from "ももくり" heroine Yuki Kuriharaopen in new window.

Formerly the Innocent Xposed API used in Development Learning Projectopen in new window, now renamed and open sourced.

Usage

YukiHookAPI is built entirely with Kotlin lambda syntax.

Abandoning the original less friendly XposedHelpers, you can use it to easily create Xposed Modules and easily implement custom Hook API.

Language Requirement

Please use Kotlin, the framework part of the code composition is also compatible with Java but the implementation of the basic Hook scene may not work at all.

All demo code in this document will be described using Kotlin, if you don't know how to use Kotlin then you may not be able to use YukiHookAPI.

Part of the Java Demo code can be found hereopen in new window, but not recommended.

Source of Inspiration

Previously, when we built an Xposed Module, we first needed to create an xposed_init file under assets.

Then, manually fill in your own entry class name into the file and use XposedHelpers to implement our Hook logic.

Since Kotlin is the main Android development language, this API is really not very elegant to use.

Is there any easy to use, light, elegant solution?

With this idea, YukiHookAPI was born.

Now, we only need to write a small amount of code, and all the time and expense are handed over to automation.

With Kotlin's elegant lambda writing and YukiHookAPI, you can make your Hook logic more beautiful and clear.

The following example

@InjectYukiHookWithXposed
class HookEntry : IYukiHookXposedInit {

    override fun onHook() = encase {
        loadZygote {
            ActivityClass.hook {
                injectMember {
                    method {
                        name = "onCreate"
                        param(BundleClass)
                    }
                    beforeHook {
                        // Your code here.
                    }
                    afterHook {
                        // Your code here.
                    }
                }
            }
            resources().hook {
                injectResource {
                    conditions {
                        name = "sym_def_app_icon"
                        mipmap()
                    }
                    replaceToModuleResource(R.mipmap.ic_launcher)
                }
            }
        }
        loadApp(name = "com.android.browser") {
            ActivityClass.hook {
                injectMember {
                    method {
                        name = "onCreate"
                        param(BundleClass)
                    }
                    beforeHook {
                        // Your code here.
                    }
                    afterHook {
                        // Your code here.
                    }
                }
            }
            resources().hook {
                injectResource {
                    conditions {
                        name = "ic_launcher"
                        mipmap()
                    }
                    replaceToModuleResource(R.mipmap.ic_launcher)
                }
            }
        }
    }
}
class HookEntry : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPackageResources {

    private lateinit var moduleResources: XModuleResources

    override fun initZygote(sparam: IXposedHookZygoteInit.StartupParam) {
        moduleResources = XModuleResources.createInstance(sparam.modulePath, null)
        XResources.setSystemWideReplacement(
            "android", "mipmap", "sym_def_app_icon",
            moduleResources.fwd(R.mipmap.ic_launcher)
        )
        XposedHelpers.findAndHookMethod(
                Activity::class.java.name,
                null, "onCreate",
                Bundle::class.java,
                object : XC_MethodHook() {
                    override fun beforeHookedMethod(param: MethodHookParam?) {
                        // Your code here.
                    }

                    override fun afterHookedMethod(param: MethodHookParam?) {
                        // Your code here.
                    }
                })
    }

    override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
        if (lpparam.packageName == "com.android.browser")
            XposedHelpers.findAndHookMethod(
                Activity::class.java.name,
                lpparam.classLoader, "onCreate",
                Bundle::class.java,
                object : XC_MethodHook() {
                    override fun beforeHookedMethod(param: MethodHookParam?) {
                        // Your code here.
                    }

                    override fun afterHookedMethod(param: MethodHookParam?) {
                        // Your code here.
                    }
                })
    }

    override fun handleInitPackageResources(resparam: XC_InitPackageResources.InitPackageResourcesParam) {
        if (resparam.packageName == "com.android.browser")
            resparam.res.setReplacement(
                "com.android.browser", "mipmap", "ic_launcher",
                moduleResources.fwd(R.mipmap.ic_launcher)
            )
    }
}

Yes, you read that right, just needing these codes can completely replace the Xposed API to achieve the same function.

Now, with the help of the efficient and powerful YukiHookAPI, you can implement a very simple Xposed Module.

Suppored Hook Framework

The following are the Hook Framework and Xposed framework supported by YukiHookAPI.

Hook FrameworkSTDescription
LSPosedopen in new windowStable use in multiple scenarios
LSPatchopen in new windowWIP after this project is improved
EdXposedopen in new windowMaintenance has stopped, no longer recommended
Pineopen in new windowOnly available
SandHookopen in new windowOnly available
Whaleopen in new windowNeed xposed-hook-based-on-whaleopen in new window
YAHFAopen in new windowNeed to implement the Xposed API yourself
FastHookopen in new windowNeed to implement the Xposed API yourself
Epicopen in new windowNeed Dexposedopen in new window by yourself
TaiChiopen in new windowOnly available for Xposed Module
Xposedopen in new windowRecommended minimum system version is Android 7.0