Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Jan 7, 2020
1 parent 5976cdf commit 4f1bc25
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 116 deletions.
62 changes: 5 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Riru is a very simple but useful thing. Only requires to replace one system file

The name Riru comes from a character. (https://www.pixiv.net/member_illust.php?mode=medium&illust_id=74128856)

[中文说明](https://github.com/RikkaApps/Riru/blob/master/README.zh-CN.md)

## Requirements

* Rooted Android 6.0+ devices
Expand All @@ -27,64 +25,14 @@ Then we can call `RegisterNatives` again to replace them.

There is only one `libmemtrack.so`, if someone wants to do something by replacing it, others can't. So I made Riru occupy libmemtrack but provide the ability to make modules.

## Build Requirements

Android NDK (add the directory with `ndk-build` to `PATH`)

## Build core

* Magisk Module

Run `:riru-core:assembleMagiskRelease` task in the command line (use `gradlew`) or Android Studio, zip will be saved to `release`

## Build your own module

1. Copy `riru-module-template` and rename to your name
2. Change module name in `riru-your-module/jni/main/Android.mk`
3. Change module information in `build.gradle`
4. Write your code
5. Run `:riru-your-module:assembleMagiskRelease` task in command line (use `gradlew`) or Android Studio, zip will be saved to `release`

## Where your own module needs attention

* DO NOT overwrite `android.os.SystemProperties#native_set` in core, or your data may be wiped
([Detail info](https://github.com/RikkaApps/Riru/blob/v7/riru-core/jni/main/jni_native_method.cpp#L162-L176))
(If you really need to hook this, remember to clear exception)
* DO NO print log (`__android_log_print`) in `nativeForkAndSpecialize(Pre/Post)` `nativeForkSystemServer(Pre/Post)` when in zygote process, or it may cause zygote not work
(magic not confirmed, [Detail info](https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66))
* Add `-ffixed-x18` to both compiler and linker parameter, or it will cause problems on Android Q (see template)
## Build

## Riru API

* Currently, one module version can only support one API version
* See template for details

### v4 (core v19+)

* Add `api=4` to `riru_module.prop` to declare API version
* Check and deny installation if Riru version is below v19 in `config.sh`
* Add `specializeAppProcessPre` `specializeAppProcessPost` used by Android Q beta 3 (see template)

### v3 (core v18+)

* Add `api=3` to `riru_module.prop` to declare API version
* Check and deny installation if Riru version is below v18 in `config.sh`
* Parameter of `nativeForkAndSpecializePre` changes (compare to v2, added `jstring *packageName, jobjectArray *packagesForUID, jstring *sandboxId` in the end)

### v2 (core v16-v17.1)

* Export `int getApiVersion() { return 2; }` to declare API version
* Parameter of `nativeForkAndSpecializePre` changes (compare to v1, all parameter is pointer)
Run gradle task `:module:assembleRelease` task from Android Studio or command line, zip will be saved to `out`.

## Install

Current only support Magisk.

1. Install core zip in Magisk
2. Install module zip in Magisk

## Modules
Install zip in Magisk Manager.

[Riru-LocationReportEnabler](https://github.com/RikkaApps/Riru-LocationReportEnabler) (also a good example)
## Create your own module

[Riru-EdXposed](https://github.com/ElderDrivers/EdXposed) (port Xposed to Android P & Q)
[View template](https://github.com/RikkaApps/Riru-Template)
62 changes: 6 additions & 56 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Riru 这个名字来自 https://www.pixiv.net/member_illust.php?mode=medium&illu
## 需求

* Root 过的 Android 6.0+ 设备
* Magisk (用于替换系统文件,暂时只提供 Magisk zip,当然你也可以直接去换文件)
* Magisk (用于替换系统文件,暂时只提供 Magisk zip)

## 她怎么工作呢?

Expand All @@ -24,64 +24,14 @@ JNI 函数 (`com.android.internal.os.Zygote#nativeForkAndSpecialize` & `com.andr

因为 `libmemtrack.so` 只有一个,如果有人想用替换 libmemtrack 的套路来做点什么别人就做不了。所以就制造了 Riru 来占下 libmemtrack 但是提供了模块这样的东西。

## 构建需求
## 构建

Android NDK (把有 `ndk-build` 的目录加到 `PATH`)

## 构建 core

* Magisk 模块

在命令行 (用 `gradlew`) 或者 Android Studio 执行 `:riru-core:assembleMagiskRelease`,zip 会被存到 `release`

## 构建你自己的模块

1. 复制 `riru-module-template` 并重命名
2.`riru-your-module/jni/main/Android.mk` 中修改模块名字
3.`build.gradle` 修改模块信息
4. 发明你自己的魔法(
5. 直接在命令行 (用 `gradlew`) 或者 Android Studio 执行 `:riru-your-module:assembleMagiskRelease`,zip 会被存到 `release`

## 自己的模块需要注意的地方

* 不要掩盖 core 中 hook 的 `android.os.SystemProperties#native_set`
否则在 Android P 以上可能导致数据抹除([详细信息](https://github.com/RikkaApps/Riru/blob/v7/riru-core/jni/main/jni_native_method.cpp#L162-L176))(如果一定要 hook 则要记得清掉异常)
* 不要在 `nativeForkAndSpecialize(Pre/Post)` `nativeForkSystemServer(Pre/Post)` 中在还处于 zygote 进程时输出 log(`__android_log_print`),
否则可能导致 zygote 不工作(未确定的魔法,[详细信息](https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66)
* 编译时需要为编译和链接指令加上 `-ffixed-x18`,否则在 Android Q 上会产生问题(参考 template)

## Riru API

* 目前,一个模块版本只可支持一个 API 版本
* 看 template 来知道具体做法

### v4 (core v19+)

*`riru_module.prop` 加入 `api=4` 来声明 API 版本
*`config.sh` 检查并拒绝在 Riru v19 以下安装
* 增加 Android Q beta 3 使用的 `specializeAppProcessPre` `specializeAppProcessPost`(请参看 template)

### v3 (core v18+)

*`riru_module.prop` 加入 `api=3` 来声明 API 版本
*`config.sh` 检查并拒绝在 Riru v18 以下安装
* `nativeForkAndSpecializePre` 参数变化(相对 v2,末尾增加 `jstring *packageName, jobjectArray *packagesForUID, jstring *sandboxId`

### v2 (core v16-v17.1)

* 导出 `int getApiVersion() { return 2; }` 来声明版本号
* `nativeForkAndSpecializePre` 参数变化(相对 v1,所有参数都是指针)
* 加入 `shouldSkipUid`
在 Android Studio 或命令行执行 gradle task `:riru-core:assembleMagiskRelease`,zip 会被存到 `release`

## 安装

目前只支持 Magisk

1. Install core zip in Magisk
2. Install module zip in Magisk

## 模块
在 Magisk Manager 中安装 zip。

[Riru-LocationReportEnabler](https://github.com/RikkaApps/Riru-LocationReportEnabler) (also a good example)
## 创造你自己的模块

[Riru-EdXposed](https://github.com/ElderDrivers/EdXposed) (port Xposed to Android P & Q)
[查看模板](https://github.com/RikkaApps/Riru-Template)
6 changes: 3 additions & 3 deletions module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def zipName = "magisk-${moduleProp['id']}-${moduleProp['version']}.zip"
import java.nio.file.Files
import java.security.MessageDigest

static def calcSha1(file) {
static def sha256sum(file) {
def md = MessageDigest.getInstance("SHA-256")
file.eachByte 4096, { bytes, size ->
md.update(bytes, 0, size);
}
return md.digest().encodeHex()
}

static def renameOrFail(File from, File to) {
static def renameOrFail(from, to) {
if (!from.renameTo(to)) {
throw new IOException("Unable reanme file $from to $to")
}
Expand Down Expand Up @@ -90,7 +90,7 @@ android.libraryVariants.all { variant ->
exclude "README.md", "META-INF"
}.visit { f ->
if (f.directory) return
file(f.file.path + ".sha256sum").text = calcSha1(f.file)
file(f.file.path + ".sha256sum").text = sha256sum(f.file)
}
}
task.finalizedBy zipMagiskMoudle
Expand Down

0 comments on commit 4f1bc25

Please sign in to comment.