Giter Club home page Giter Club logo

xcubebase_riru's Introduction

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.

In addition, currently the only necessary file (folder) is /data/adb/riru/modules/<name>. Riru will check if it exists and load /system/lib(64)/libriru_<name>.so.

API changes

API v10 (from 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 v9 (from 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.

xcubebase_riru's People

Contributors

svengong avatar

Stargazers

 avatar  avatar rys avatar ज्योति द्विवेदी avatar  avatar  avatar  avatar Hank avatar ZhangSan avatar  avatar  avatar thunder avatar kpa avatar  avatar Ziv Chen avatar  avatar yifeng avatar SsageParuders avatar SeeFlowerX avatar Xiaomeng Zhao avatar 突突兔 avatar spiro-gong avatar 残血战士 avatar PayNeXC avatar copper friddle avatar 手机用户Xh2vb13n avatar stickycookie avatar Xing avatar  avatar aweNousaku avatar dongwang avatar  avatar  avatar bill avatar Skr avatar Kingking avatar  avatar PiteChen avatar Abell avatar fraaannn avatar Chen Xiang‘An avatar Monkeylord avatar Carlos Hwang avatar wuxianlin avatar San avatar Breathleas avatar catkin avatar CaiRuJi avatar dodola avatar tomato avatar qtfreet00 avatar  avatar Lanminy avatar huangjin avatar  avatar  avatar

Watchers

James Cloos avatar  avatar 残血战士 avatar

xcubebase_riru's Issues

android 11 有bug

安卓11forkAndSpecializePost这个回调函数没有触发,specializeAppProcessPost触发了但是注入gumjs就报错了,有没有解决办法啊

大佬,为什么sync没啥问题,但是一直无法build成功,已经将frida两种架构的a文件,塞进去了

Build command failed.
Error while executing process C:\Users\yenkoclin\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C C:\Users\yenkoclin\Desktop\xcubebase_riru\module.cxx\cmake\debug\armeabi-v7a riru_template}
ninja: Entering directory `C:\Users\yenkoclin\Desktop\xcubebase_riru\module.cxx\cmake\debug\armeabi-v7a'

ninja: error: 'C:/Users/yenkoclin/Desktop/xcubebase_riru/module/src/main/cpp/armeabi-v7a/libfrida-gumjs.a', needed by 'C:/Users/yenkoclin/Desktop/xcubebase_riru/module/build/intermediates/cmake/debug/obj/armeabi-v7a/libriru_template.so', missing and no known rule to make it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.