• This repository has been archived on 03/Feb/2022
  • Stars
    star
    146
  • Rank 252,769 (Top 5 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Module template of Riru.

Riru - Template

Riru module template.

Build

  1. Rename module.example.gradle to module.gradle
  2. Replace module info in module.gradle (all lines end with "replace with yours")
  3. Write your codes
  4. Run gradle task :module:assembleRelease task from Android Studio or command line, zip will be saved in out.

File structure

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.

API changes

API 26 (Riru v26)

  • Remove the support of pre-24 modules

  • /data/adb/dev_random is planned to be moved to another place in the next major version

  • Libraries 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

API 25 (Riru v25)

  • Modules can be unloaded (see main.cpp)
  • shouldSkipUid is removed for API 25 modules

API 24 (Riru v24)

  • The Riru API version is unified with Riru version, now the API version is 24
  • The /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)
  • The init function is called only once (see main.cpp)
  • It's recommended to place modules files in the Magisk module folder, zygote has permission read this folder directly (the path is passed through init function, see main.cpp)

API 10 (Riru v23)

Background of rirud:

Riru v22.0 move config files to /data/adb, this makes patch SELinux rules a must. However Magisk's sepolicy.rule actually not work for maybe lots of devices. As the release of Riru v22.0, these people "suddenly" appears.

sepolicy.rule support was added from Magisk v20.2, a long time ago, no one report to Magisk 😒.

To workaround this "problem", "rirud" is introduced. It will be started by post-fs-data.sh and run a socket runs under u:r:zygote:s0 context. All file operations can be done through this socket.

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.

Pseudocode of read file:
socket(PF_UNIX, SOCK_STREAM)
setup_sockaddr("rirud")

write(ACTION_READ_FILE /* 4 */, sizeof(uint32))
write(path_size, sizeof(uint32))
write(path, path_size)

errno = read(sizeof(int32_t)) // errno of "open" in "rirud"
if (errno != 0) return

bytes_count = read(sizeof(int32_t))

if (bytes_count > 0) {
  // file has size
  // read total "bytes_count" bytes
} else if (bytes_count == 0) {
  // file has no size, read until 0
  // read until 0
}
Pseudocode of read dir:
socket(PF_UNIX, SOCK_STREAM)
setup_sockaddr("rirud")

write(ACTION_READ_DIR /* 5 */, sizeof(uint32))
write(path_size, sizeof(uint32))
write(path, path_size)

errno = read(sizeof(int32_t)) // errno of "opendir" in "rirud"
if (errno != 0) return

while (true) {
  write(1 /* continue */, sizeof(uint8))

  reply = read(sizeof(int32))
  if (reply == -1) break // end
  if (reply != 0) continue  // reply is errno of "readdir" in "rirud"

  d_type = read(sizeof(uchar))
  d_name = read(256)
}

Example implementation: https://github.com/RikkaApps/Riru-LocationReportEnabler/commit/89b2e396efcd928121ba3d254b96af1560cfaf4d

API 9 (Riru v22)

API

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:

  • Module can support different Riru versions
  • Riru itself will not relay on ".prop" file (unreliable) to get module information

Riru

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).

Module installer

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.

More Repositories

1

Shizuku

Using system APIs directly with adb/root privileges from normal apps through a Java process started with app_process.
Kotlin
9,849
star
2

Riru

Inject into zygote process
C++
4,875
star
3

Sui

Modern super user interface implementation on Android.
Java
1,829
star
4

StorageRedirect-assets

Assets (rules, apks etc) for Storage Redirect app.
Python
667
star
5

WADB

A simple switch for adb (Android Debug Bridge) over network.
Kotlin
548
star
6

Riru-LocationReportEnabler

A Riru module. Enable location report by hook system_property_get.
C++
449
star
7

Shizuku-API

The API and the developer guide for Shizuku and Sui.
Java
403
star
8

App-Ops-issue-tracker

Issue tracker for https://play.google.com/store/apps/details?id=rikka.appops
303
star
9

RikkaX

Rikka's Android libraries.
Java
268
star
10

HiddenApiRefinePlugin

A Gradle plugin that improves the experience when developing Android apps, especially system tools, that use hidden APIs.
Java
262
star
11

FCM-for-Mojo

Firebase Cloud Messaging for Mojo-Webqq.
Java
209
star
12

SaveCopy

Simple Android app, handle ACTION_VIEW, ACTION_SEND, ACTION_SEND_MULTIPLE, save a copy of the file. For bad apps which only allow users to open files.
Java
132
star
13

FontProvider

Provide NotoCJK (and other) fonts to other app.
Java
105
star
14

websites

Websites for Rikka apps.
Vue
71
star
15

MaterialThemeBuilder

A gradle plugin that generates Material Design 3 theme for Android projects.
Java
54
star
16

FCM-for-Mojo-Server

Server for FCM-for-Mojo
JavaScript
33
star
17

magisk-custom-sepolicy-installer

(Replaced by official solution from Magisk) Installer template for custom Magisk with "sepolicy_custom" support.
Shell
29
star
18

RikkaApps.github.io.backup

CSS
28
star
19

AutoResConfig

A gradle plugin generates resConfig & languages array from project res folder.
Java
27
star
20

Riru-AppConfig

A Riru module. Per-app system property, config (locale, etc.) modification.
10
star
21

TakoStats

Issue tracker & localization for TakoStats.
9
star
22

RikkaApps.github.io

8
star
23

AppOps-Localization

Localization files for AppOps.
4
star