# Riru - Template
[Riru](https://github.com/RikkaApps/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](https://topjohnwu.github.io/Magisk/guides.html#magisk-modules) 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)
<details>
<summary><b>Background of rirud:</b></summary>
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.
</details>
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.
<details>
<summary><b>Pseudocode of read file:</b></summary>
```
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
}
```
</details>
<details>
<summary><b>Pseudocode of read dir:</b></summary>
```
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)
}
```
</details>
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`](https://cs.android.com/android/platform/superproject/+/android-11.0.0_r1:art/libnativebridge/native_bridge.cc;l=227) 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](https://github.com/RikkaApps/Riru/blob/master/core/src/main/cpp/hide.cpp)). 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.
没有合适的资源?快使用搜索试试~ 我知道了~
基于magisk 和riru的frida持久化方案.zip
共34个文件
sh:5个
h:5个
gradle:4个
需积分: 3 0 下载量 79 浏览量
2024-01-15
10:16:24
上传
评论
收藏 1.51MB ZIP 举报
温馨提示
方案是为解决特定问题或达成特定目标而制定的一系列计划或步骤。它的作用是提供一种系统性的方法,以有效地应对挑战、优化流程或实现目标。以下是方案的主要作用: 问题解决: 方案的核心目标是解决问题。通过系统性的规划和执行,方案能够分析问题的根本原因,提供可行的解决方案,并引导实施过程,确保问题得到合理解决。 目标达成: 方案通常与明确的目标相关联,它提供了一种达成这些目标的计划。无论是企业战略、项目管理还是个人发展,方案的制定都有助于明确目标并提供达成目标的路径。 资源优化: 方案在设计时考虑了可用资源,以最大化其效用。通过明智的资源分配,方案可以在有限的资源条件下实现最大的效益,提高效率并减少浪费。 风险管理: 方案通常会对潜在的风险进行评估,并制定相应的风险管理策略。这有助于减轻潜在问题的影响,提高方案的可行性和可持续性。 决策支持: 方案提供了决策者所需的信息和数据,以便做出明智的决策。这种数据驱动的方法有助于减少不确定性,提高决策的准确性。 团队协作: 复杂的问题通常需要多个人的协同努力。方案提供了一个共同的框架,帮助团队成员理解各自的职责和任务,促进协作并确保整个团队朝着共同的目标努力。 监控与评估: 方案通常包括监控和评估的机制,以确保实施的有效性。通过定期的评估,可以及时调整方案,以适应变化的环境或新的挑战。 总体而言,方案的作用在于提供一种有序、有计划的方法,以解决问题、实现目标,并在实施过程中最大化资源利用和风险管理。
资源推荐
资源详情
资源评论
收起资源包目录
基于magisk 和riru的frida持久化方案.zip (34个子文件)
SJT-code
gradle.properties 1KB
gradle
wrapper
gradle-wrapper.jar 53KB
gradle-wrapper.properties 232B
.gitattributes 35B
template
magisk_module
riru.sh 2KB
.gitattributes 277B
verify.sh 1KB
uninstall.sh 108B
customize.sh 2KB
README.md 17B
META-INF
com
google
android
update-binary 4KB
updater-script 8B
post-fs-data.sh 281B
LICENSE 1KB
gradlew.bat 2KB
build.gradle 498B
settings.gradle 18B
module.example.gradle 966B
gradlew 5KB
module
src
main
pkg.conf 40B
cpp
CMakeLists.txt 1KB
includes
armeabi-v7a
frida-gum.h 1.73MB
frida-gumjs.h 2.81MB
arm64-v8a
frida-gum.h 1.73MB
frida-gumjs.h 2.81MB
frida-gumjs-example.cpp 5KB
frida-gumjs-example.h 244B
main.cpp 8KB
AndroidManifest.xml 37B
build.gradle 5KB
.gitignore 37B
.gitignore 269B
README.md 5KB
Manual.md 417B
共 34 条
- 1
资源评论
JJJ69
- 粉丝: 6222
- 资源: 5780
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功