Inject into zygote process
Deprecated
All Riru users and Riru modules should migrate to Zygisk.
Riru
Riru only does one thing, inject into zygote in order to allow modules to run their codes in apps or the system server.
The name, Riru, comes from a character. (https://www.pixiv.net/memberillust.php?mode=medium&illustid=74128856)
Requirements
Android 6.0+ devices rooted with Magisk
Guide
Install
- From Magisk Manager
> The Magisk version requirement is enforced by Magisk Manager. You can check Magisk's module installer script.
- Manually
Common problems
- Third-party ROMs have incorrect SELinux rule
- Have low quality module that changes
ro.dalvik.vm.native.bridgeinstalled
ro.dalvik.vm.native.bridge, Riru will not work. (Riru will automatically set it back)
A typical example is, some "optimize" modules change this property. Since changing this property is meaningless for "optimization", their quality is very questionable. In fact, changing properties for optimization is a joke.
How Riru works?
- How to inject into the zygote process?
Then we found a super easy way, the "native bridge" (ro.dalvik.vm.native.bridge). The specific "so" file will be automatically "dlopen-ed" and "dlclose-ed" by the system. This way is from here.
- How to know if we are in an app process or a system server process?
com.android.internal.os.Zygote#nativeForkAndSpecialize & com.android.internal.os.Zygote#nativeForkSystemServer) is to fork the app process or the system server process.
So we need to replace these functions with ours. This part is simple, hook jniRegisterNativeMethods since all Java native methods in libandroid_runtime.so is registered through this function.
Then we can call the original jniRegisterNativeMethods again to replace them.
How does Hide works?
From v22.0, Riru provides a hidden mechanism (idea from Haruue Icymoon), make the memory of Riru and module to anonymous memory to hide from "/proc/maps string scanning".
Build
Gradle tasks:
:riru:assembleDebug/Release
out.
:riru:pushDebug/Release
/data/local/tmp.
:riru:flashDebug/Release
adb shell su -c magisk --install-module.
:riru:flashAndRebootDebug/Release
Module template
https://github.com/RikkaApps/Riru-ModuleTemplate
Module API changes
https://github.com/RikkaApps/Riru-ModuleTemplate/blob/master/README.md#api-changes