Riru module template.
module.example.gradle
to module.gradle
module.gradle
(all lines end with "replace with yours"):module:assembleRelease
task from Android Studio or command line, zip will be saved in out
.A Riru module is a Magisk module, please read Magisk module document first.
If the folder $MODPATH/riru
exists, the module is considered as a Riru module. All files in $MODPATH/riru/lib(64)
will be loaded by Riru.
/data/adb/dev_random
is planned to be moved to another place in the next major versionLibraries in /dev
do not have stacktrace, developers have to put so file into /system
, Riru v26 makes this simpler
Create an empty file, libxxx
(no .so
suffix), at $MODPATH/riru/lib(64)
, Riru will try to load /system/lib(64)/libxxx.so
main.cpp
)shouldSkipUid
is removed for API 25 modules/data/adb/riru/modules/<name>
folder is deprecated, modules only need to place library files in $MODPATH/riru/lib(64)
(see customize.sh
post-fs-data.sh
)init
function is called only once (see main.cpp
)init
function, see main.cpp
)From Riru v23, "read file" and "read dir" function are added for "rirud". Modules can use this to read files that zygote itself has not permission to access. Note, for hide purpose, "rirud" socket is only available before system_server is started.
In order to give the module enough freedom (like how to allocate memory), there is no "API". The module needs to implement socket codes by itself.
Example implementation: https://github.com/RikkaApps/Riru-LocationReportEnabler/commit/89b2e396efcd928121ba3d254b96af1560cfaf4d
Functions like nativeForkAnd...
do not need to be exported directly. The only function to export is void *init(void *)
. See the comment of init
and template's implementation for more.
This has these advantages:
Starting v22.0, Riru has switched to "native bridge" (ro.dalvik.vm.native.bridge
) to inject zygote, this will lead Riru and modules be loaded later (LoadNativeBridge
vs __attribute__((constructor))
).
For most modules, this should have no problem, but modules like Xposed frameworks may have to make changes.
Magisk may provider Riru-like features in the far future, and of course, it will have more strict restrictions, module codes will not be run in zygote. Maybe Xposed framework modules should prepare for this?
Riru v22 also provides hide function to make the memory of the module to anonymous memory (see the implementation). This is an opt-in behavior (module->supportHide
) and Riru itself also has a global toggle (/data/adb/riru/enable_hide
).
RIRU_PATH
has been changed to /data/adb/riru
for hide purpose. If you have other files in /data/misc/riru
, move them here (or anywhere else if you want).
Note /data/adb/riru
have the same SELinux like other Magisk files (set by Riru in post-fs-data), u:object_r:magisk_file:s0
. DO NOT reset the context to something else.