Riru

通过替换 libmemtrack 注入 zygote 进程。「Inject zygote process by replace libmemtrack.」

  • 所有者: RikkaApps/Riru
  • 平台: Android
  • 许可证:
  • 分类:
  • 主题:
  • 喜欢:
    55
      比较:

Github星跟踪图

Riru

Riru 是一个非常简单但有用的东西。只需要替换一个系统文件,就可以让 Riru 模块在应用程序或系统服务器的进程中运行它们的代码。

Riru 这个名字来自一个角色。(https://www.pixiv.net/member_illust.php?mode=medium&illust_id=74128856)

要求

  • Rooted Android 6.0+ 设备
  • Magisk (用于替换系统文件,暂时仅提供 Magisk zip)

它是如何运作的?

简而言之,替换将由zygote进程加载的共享库。

首先,我们需要找到那个库。这个库需要尽可能简单,所以我们找到了 libmemtrack,它只有10个导出函数。然后我们可以提供一个名为 libmemtrack 的库,其中包括所有函数,这样功能就不会受到影响,而且我们可以在 zygote 过程中进行。(但是,现在选择 libmemtrack 似乎不太合适)。

接下来的问题是,如何知道我们是处于应用程序进程中还是系统服务器进程中。我们发现在“fork”应用程序或系统服务器时,将调用一些JNI函数(com.android.internal.os.Zygote#nativeForkAndSpecializecom.android.internal.os.Zygote#nativeForkSystemServer)。 因此,我们只需要将这些功能替换为我们的功能即可。这部分很简单,只需“hook” jniRegisterNativeMethods,因为 libandroid_runtime 中的所有 Java 本机方法都已使用此函数注册。然后,我们可以再次调用 RegisterNatives 来替换它们。

为什么是 Riru?

只有一个 libmemtrack.so,因此,如果有人想通过替换它来做某事,其他人则不能。因此,我让 Riru 占用了 libmemtrack,但提供了制作模块的能力。

构建

从 Android Studio 或命令行运行 gradle task :module:assembleRelease,zip 将被保存到 out

安装

在 Magisk 管理器中安装 zip。

生成你自己的模块

View template

主要指标

概览
名称与所有者RikkaApps/Riru
主编程语言C++
编程语言Shell (语言数: 5)
平台Android
许可证
所有者活动
创建于2018-08-20 11:10:27
推送于2023-12-24 09:16:43
最后一次提交2023-12-24 17:16:42
发布数80
最新版本名称v26.1.7 (发布于 )
第一版名称v2 (发布于 )
用户参与
星数5.1k
关注者数195
派生数591
提交数533
已启用问题?
问题数257
打开的问题数1
拉请求数39
打开的拉请求数0
关闭的拉请求数8
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

Riru

Riru is a very simple but useful thing. Only requires to replace one system file, it will provide the ability to Riru modules to run their code in apps' or system server's process.

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

Requirements

  • Rooted Android 6.0+ devices
  • Magisk (use to replace system files, temporarily only provide Magisk zip)

How it works?

In short, replace a shared library which will be loaded by the zygote process.

First, we need to find that library. The library needs to be as simple as possible, so we found libmemtrack, with only 10 exported functions.
Then we can provide a library named libmemtrack with all its functions, so the functionality will not be affected and we will able to in the zygote process. (However, it seems that choose libmemtrack is not so appropriate now)

Now the next question, how to know if we are in an app process or a system server process.
We found some JNI functions (com.android.internal.os.Zygote#nativeForkAndSpecialize & com.android.internal.os.Zygote#nativeForkSystemServer) will be called when a app or system server is forked.
So we just need to replace these functions to ours. This part is simple, just hook jniRegisterNativeMethods since all Java native method in libandroid_runtime is registered with this function.
Then we can call RegisterNatives again to replace them.

Why Riru is made?

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

Run gradle task :module:assembleRelease task from Android Studio or command line, zip will be saved to out.

Install

Install zip in Magisk Manager.

Create your own module

View template