From 0e9307bfd6fe44d055a022b99ef3e9fec17a7d20 Mon Sep 17 00:00:00 2001 From: echo Date: Tue, 12 Nov 2024 11:34:03 -0500 Subject: [PATCH 01/46] remove: Rust dependencies information from `README.md` (#74) This commit removes information about Rust dependencies used in previous Zygiskd from "README.md" file. --- README.md | 19 ------------------- README_CN.md | 19 ------------------- 2 files changed, 38 deletions(-) diff --git a/README.md b/README.md index e28f4d8..0e6fde9 100644 --- a/README.md +++ b/README.md @@ -25,27 +25,8 @@ The Zygisk Next developers are famous and trusted in the Android community, howe | Tool | Description | |-----------------|----------------------------------------| -| `rustc` | The Rust compiler | | `Android NDK` | Native Development Kit for Android | -### Rust Dependencies - -| Dependency | Description | -|------------------|---------------------------------------------------------------| -| `android_logger` | Logger for Android platform | -| `anyhow` | Error handling library | -| `bitflags` | Macro to generate structures for bitwise operations | -| `const_format` | Compile-time string formatting | -| `futures` | Abstractions for asynchronous programming | -| `konst` | Compile-time constant evaluation | -| `lazy_static` | Macro for declaring lazily evaluated static variables | -| `libc` | FFI bindings to native C libraries | -| `log` | Logging facade | -| `memfd` | Memory file descriptor utilities | -| `num_enum` | Derive macros to convert between numbers and enums | -| `passfd` | Passing file descriptors over Unix sockets | -| `proc-maps` | Parse and analyze process memory maps | - ### C++ Dependencies | Dependency | Description | diff --git a/README_CN.md b/README_CN.md index 7d03c7f..6b5b29f 100644 --- a/README_CN.md +++ b/README_CN.md @@ -25,27 +25,8 @@ Zygisk Next 的开发者们在Android社区享有盛誉,备受信任。但这 | 工具 | 简介 | |---------------|------------------------------------| -| `rustc` | Rust 编译器 | | `Android NDK` | Android 本地开发工具包 | -### Rust 依赖 - -| 依赖 | 简介 | -|------------------|-------------------------------------------------------| -| `android_logger` | Android 日志记录工具 | -| `anyhow` | 错误处理库 | -| `bitflags` | 用于生成位操作结构的宏 | -| `const_format` | 编译时字符串格式化 | -| `futures` | 异步编程的抽象实现 | -| `konst` | 编译时常量比较 | -| `lazy_static` | 用于声明静态延迟比较变量的宏 | -| `libc` | 对各平台系统C语言库的原始 FFI 绑定 | -| `log` | 日志外观框架 | -| `memfd` | 内存文件描述符实用程序 | -| `num_enum` | 在数字类型和枚举类型之间进行转换的衍生宏 | -| `passfd` | 通过Unix套接字传递文件描述符 | -| `proc-maps` | 解析和分析进程内存映射 | - ### C++ 依赖 | 依赖 | 简介 | From 21325ec4093c661d4c73012a00ca0f37979653f8 Mon Sep 17 00:00:00 2001 From: SheepChef <50871867+SheepChef@users.noreply.github.com> Date: Wed, 13 Nov 2024 01:47:08 +0800 Subject: [PATCH 02/46] fix: WebUI branch URL in READMEs (#77) This commit fixes the URL of the new WebUI branch in the READMEs. Signed-off-by: SheepChef <50871867+SheepChef@users.noreply.github.com> --- README.md | 2 +- README_CN.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0e6fde9..f65fa2d 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ There are currently no available stable releases. (Coming Soon) ## Translation -As of now, we don't have integration with another platform for translations but you may contribute to the [add/webui](https://github.com/PerformanC/ReZygisk/tree/add/webui) branch. Please don't forget to include your GitHub profile in [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/webui/TRANSLATOR.md) so that people can see your contribution. +As of now, we don't have integration with another platform for translations but you may contribute to the [add/new-webui](https://github.com/PerformanC/ReZygisk/tree/add/new-webui) branch. Please don't forget to include your GitHub profile in [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/new-webui/TRANSLATOR.md) so that people can see your contribution. ## Support For any question related to ReZygisk or other PerformanC projects, feel free to join any of the following channels below: diff --git a/README_CN.md b/README_CN.md index 6b5b29f..8da3c45 100644 --- a/README_CN.md +++ b/README_CN.md @@ -43,9 +43,9 @@ Zygisk Next 的开发者们在Android社区享有盛誉,备受信任。但这 ## 翻译 -您可以向 [add/webui](https://github.com/PerformanC/ReZygisk/tree/add/webui) 分支贡献翻译。 +您可以向 [add/new-webui](https://github.com/PerformanC/ReZygisk/tree/add/new-webui) 分支贡献翻译。 -请不要忘记在 [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/webui/TRANSLATOR.md) 中添加您的 GitHub 账号信息,以便人们看到您的贡献。 +请不要忘记在 [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/new-webui/TRANSLATOR.md) 中添加您的 GitHub 账号信息,以便人们看到您的贡献。 ## 支持 From f4af759aabffc2e8d24c9fd9ca42257b69d6e19b Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Tue, 12 Nov 2024 20:38:28 -0300 Subject: [PATCH 03/46] fix: `free` in garbage data pointer; fix: Zygiskd wrong message length This commit fixes the issue where "free" would be executed in a pointer which has garbage data, leading to crashes. This was fixed by setting to NULL, so that it's clean. It also fixes the issue where Zygiskd messages for "DAEMON_SET_INFO" would not count the NULL-terminator, causing crashes. --- loader/src/ptracer/monitor.cpp | 4 ++-- zygiskd/src/zygiskd.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/loader/src/ptracer/monitor.cpp b/loader/src/ptracer/monitor.cpp index 805b2c0..36f4bdc 100644 --- a/loader/src/ptracer/monitor.cpp +++ b/loader/src/ptracer/monitor.cpp @@ -117,8 +117,8 @@ struct Status { bool zygote_injected = false; bool daemon_running = false; pid_t daemon_pid = -1; - char *daemon_info; - char *daemon_error_info; + char *daemon_info = NULL; + char *daemon_error_info = NULL; }; Status status64; diff --git a/zygiskd/src/zygiskd.c b/zygiskd/src/zygiskd.c index 93338ae..dcb88d8 100644 --- a/zygiskd/src/zygiskd.c +++ b/zygiskd/src/zygiskd.c @@ -394,7 +394,7 @@ void zygiskd_start(char *restrict argv[]) { size_t msg_length = strlen("Root: , Modules: ") + strlen(impl_name) + module_list_len + 1; struct MsgHead *msg = malloc(sizeof(struct MsgHead) + msg_length); - msg->length = snprintf(msg->data, msg_length, "Root: %s, Modules: %s", impl_name, module_list); + msg->length = snprintf(msg->data, msg_length, "Root: %s, Modules: %s", impl_name, module_list) + 1; msg->cmd = DAEMON_SET_INFO; unix_datagram_sendto(CONTROLLER_SOCKET, (void *)msg, sizeof(struct MsgHead) + msg->length); From 7da7b8bd07638c4d03ffea2ec157e954ad36c000 Mon Sep 17 00:00:00 2001 From: Keeperorowner Date: Fri, 15 Nov 2024 06:16:23 +0800 Subject: [PATCH 04/46] improve: Simplified Chinese README translation (#80) This commit improves translations in the Simplified Chinese README. Signed-off-by: Keeperorowner --- README_CN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_CN.md b/README_CN.md index 8da3c45..bcdb007 100644 --- a/README_CN.md +++ b/README_CN.md @@ -11,9 +11,9 @@ ReZygisk 是 Zygisk 的另一个独立实现,从 Zygisk Next 分叉而来, > > 您可以从 [Actions](https://github.com/PerformanC/ReZygisk/actions) 页面下载自动构建包,但要注意自负风险。使用不稳定的版本时,设备可能会陷入启动循环(Bootloop)。 -## 为什么要ReZygisk? +## 为什么要选择 ReZygisk? -最新版本的 Zygisk Next 并不开源,仅其核心开发者有权查阅全部源代码。这不仅阻止了其他开发者贡献代码,还阻止了他们对项目代码进行审计。Zygisk Next 是一个以超级用户(root)权限运行的模块,可以访问整个系统,闭源后存在重大安全隐患。 +最新版本的 Zygisk Next 并不开源,仅其核心开发者有权查阅全部源代码。这不仅阻止了其他开发者贡献代码,还阻止了他人对项目代码进行审计。Zygisk Next 是一个以超级用户(root)权限运行的模块,可以访问整个系统,闭源后存在重大安全隐患。 Zygisk Next 的开发者们在Android社区享有盛誉,备受信任。但这并不意味着他们的项目就一定没有任何恶意代码和漏洞。我们(PerformanC)理解他们出于某些原因不愿保持开源,但我们坚信,开源是更好的选择。 From 5d9276e9e0d0da2cf33af6900eddea91a1384c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E6=84=8F=E6=8C=BD=E7=A7=8B=E9=A2=A8?= <94283631+RejectVanity@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:32:22 +0800 Subject: [PATCH 05/46] add: `README_zh-TW.md` translation (#84) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds Traditional Chinese translation for README. Signed-off-by: 何意挽秋風 <94283631+RejectVanity@users.noreply.github.com> --- README.md | 2 +- README_CN.md => READMEs/README_zh-CN.md | 8 ++-- READMEs/README_zh-TW.md | 62 +++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 5 deletions(-) rename README_CN.md => READMEs/README_zh-CN.md (92%) create mode 100644 READMEs/README_zh-TW.md diff --git a/README.md b/README.md index f65fa2d..3fbf1e8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ReZygisk -[中文](https://github.com/PerformanC/ReZygisk/blob/main/README_CN.md) +[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md) ReZygisk is a fork of Zygisk Next, a standalone implementation of Zygisk, providing Zygisk API support for KernelSU, Magisk (besides built-in), and APatch (Work In Progress). diff --git a/README_CN.md b/READMEs/README_zh-CN.md similarity index 92% rename from README_CN.md rename to READMEs/README_zh-CN.md index bcdb007..da3af96 100644 --- a/README_CN.md +++ b/READMEs/README_zh-CN.md @@ -23,15 +23,15 @@ Zygisk Next 的开发者们在Android社区享有盛誉,备受信任。但这 ## 依赖 -| 工具 | 简介 | +| 工具 | 简介 | |---------------|------------------------------------| -| `Android NDK` | Android 本地开发工具包 | +| `Android NDK` | Android 本地开发工具包 | ### C++ 依赖 -| 依赖 | 简介 | +| 依赖 | 简介 | |---------|-----------------------------| -| `lsplt` | Android 程序链接表钩子 | +| `lsplt` | Android 程序链接表钩子 | ## 用法 diff --git a/READMEs/README_zh-TW.md b/READMEs/README_zh-TW.md new file mode 100644 index 0000000..5762ead --- /dev/null +++ b/READMEs/README_zh-TW.md @@ -0,0 +1,62 @@ +# ReZygisk +> 繁體中文(README_zh-TW.md)是根據[英文版自述檔案(README.md)](https://github.com/PerformanC/ReZygisk/blob/main/README.md)翻譯,僅供參考以便理解英文內容,翻譯可能滯後。 + +ReZygisk 是 Zygisk Next 的一個分支,這是一個獨立實現的 Zygisk,為 KernelSU、Magisk(除了內建支援外)和 APatch(開發中)提供 Zygisk API 支援。 + +此專案致力於用 C 語言重寫原有的 C++ 和 Rust 代碼,藉此以更現代且高效的方式實現 Zygisk API,並採用更寬鬆的授權條款。 + +> [!NOTE] +> 此模組/分支仍在開發中(WIP);請僅安裝正式版本的壓縮包。 +> +> 雖然你可以從 [Actions](https://github.com/PerformanC/ReZygisk/actions) 頁面安裝 .zip 檔,但若因此導致裝置進入開機循環(Bootloop),後果須自行承擔。 + +## 為什麼選擇ReZygisk? + +最新版本的 Zygisk Next 已轉為閉源,只有核心開發者能查閱完整的原始碼。這不僅限制了其他開發者的貢獻,也無法進行代碼審計。由於 Zygisk Next 是一個以超級使用者(root)權限運行的模組,能夠存取整個系統,若閉源將帶來重大的安全風險。 + +雖然 Zygisk Next 的開發者在 Android 社群中享有盛譽,並且備受信任,但這並不代表他們的專案就完全沒有任何惡意程式碼或漏洞。我們(PerformanC)理解他們因某些原因選擇保持閉源,但我們堅信開源才是更好的選擇。 + +## 優勢 + +- 永遠是自由及開放原始碼軟體(FOSS) + +## 依賴項 + +| 工具 | 說明 | +|-----------------|---------------------------------------| +| `Android NDK` | Android 原生開發工具包 | + +### C++ 依賴項 + +| 依賴 | 說明 | +|----------|----------------------------------------------| +| `lsplt` | Android 的簡單 PLT(程式連結表) 勾取 | + +## 用法 + +我們目前正在開發中。(敬請期待) + +## 安裝 + +目前沒有穩定版本可供下載。(敬請期待) + +## 翻譯 + +目前我們尚未與其他平台整合進行翻譯,但您可以為 [add/new-webui](https://github.com/PerformanC/ReZygisk/tree/add/new-webui)分支做出貢獻。請別忘了在 [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/new-webui/TRANSLATOR.md) 中包含您的 GitHub 個人檔案,讓大家能夠看到您的貢獻。 + +## 支援 +如有關於 ReZygisk 或其他 PerformanC 專案的任何問題,歡迎加入以下任一頻道: + +- Discord 頻道: [PerformanC](https://discord.gg/uPveNfTuCJ) +- ReZygisk Telegram 頻道: [@rezygiskchat](https://t.me/rezygiskchat) +- PerformanC Telegram 頻道: [@performancorg](https://t.me/performancorg) + +## 貢獻 + +要為 ReZygisk 貢獻,必須遵循 PerformanC 的[貢獻指南](https://github.com/PerformanC/contributing),並遵守其安全政策、行為準則以及語法標準。 + +## 授權條款 + +在 ReZygisk 專案中,舊的 Zygisk Next 部分採用了 GPL 授權,而由 PerformanC 組織重寫的程式碼則採用 AGPL 3.0 授權。 + +您可以在[開放原始碼倡議(Open Source Initiative)](https://opensource.org/licenses/AGPL-3.0)上閱讀更多相關資訊。 From b5b5c2f9d8d88c08bf70dfba55a3127512c4b1d3 Mon Sep 17 00:00:00 2001 From: Fyphen Date: Sat, 23 Nov 2024 16:48:49 +0900 Subject: [PATCH 06/46] add: ja_JP README (#88) * Create README_ja-JP.md Signed-off-by: Fyphen * Update README_ja-JP.md Signed-off-by: Fyphen --------- Signed-off-by: Fyphen --- READMEs/README_ja-JP.md | 73 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 READMEs/README_ja-JP.md diff --git a/READMEs/README_ja-JP.md b/READMEs/README_ja-JP.md new file mode 100644 index 0000000..80633b8 --- /dev/null +++ b/READMEs/README_ja-JP.md @@ -0,0 +1,73 @@ +# ReZygisk + +[English](https://github.com/PerformanC/ReZygisk/blob/main/README.md)|[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md) + +ReZygiskはkernelSU、Magisk、APatchにZygiskのAPIサポートを提供するスタンドアローンZygiskであるZygisk Nextのフォークです。 + +ReZygiskは更に高速かつ効率的なZygisk APIとより寛容なライセンスを、コードベースをC(もともとはC++とRustでした)でアップデート/書き直すことで実現することを目標としています。 + +> [!NOTE] +> このモジュール/フォークはWIP(Work in Progress、すべての作業が進行中であることを意味します): ReleasesタブのZipのみを使用するようにしてください。 +> +> GitHub [Actions](https://github.com/PerformanC/ReZygisk/actions) よりZipをダウンロードして使用することも可能ですが、デバイスがブートループなどの不具合が起きる可能性があります。ユーザー自身の裁量にて使用してください。 + +## ReZygiskを使う理由 + +Zygisk Nextの最新リリースはクローズドソースであり、コードはプロジェクトの開発者のみアクセスできるものです。これはコミュニティがコードに貢献することを妨げるだけではなく、コード監査をも難しくしています。これはZygisk Nextがルート権限で作動するアプリであるため、セキュリティ上深刻な問題です。 + +Zygisk Nextの開発者はAndroid Communityにて有名かつ信用されています。が、これはコード自体が悪意の無いこと/脆弱でないことを証明するものではありません。 + +我々(PerformanC)はZygisk Nextの開発者らがコードをクローズドに保つ重要な理由があることは承知していますが、我々はオープンソース/コミュニティドリブンにすることが重要だと考えています。 + +## メリット + +- オープンソース、Free to Use、FOSS (永続的) + +## 依存関係 + +| ツール | 説明 | +|-----------------|----------------------------------------| +| `Android NDK` | Androidのネイティブ開発環境キット | + +### C++ 依存関係 + +| 依存 | 説明 | +|------------|-------------------------------| +| `lsplt` | シンプルなAndroidのPLTフック | + +## 使い方 + +ただいま調理中です、しばらくお待ち下さい!(できるだけ早くお届けします) + +## インストール + +現状、ステーブルリリースはありません。(できるだけ早くお届けします) + +## 翻訳 + +現状では、翻訳を他のプラットフォーム上で展開することはしていません。 + +が、[add/new-webui](https://github.com/PerformanC/ReZygisk/tree/add/new-webui) ブランチにて翻訳作業に参加していただくことができます。 + +他の開発者さんたちがあなたの貢献を確認できるように、 [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/new-webui/TRANSLATOR.md) にあなたのプロフィールを追加することを忘れないでください! + +## サポート +For any question related to ReZygisk or other PerformanC projects, feel free to join any of the following channels below: +ReZygisk/他のPerformanCのプロジェクトに対する質問がある場合は、以下のどれかに参加してください! + +- Discord チャンネル: [PerformanC](https://discord.gg/uPveNfTuCJ) +- ReZygisk Telegram チャンネル: [@rezygiskchat](https://t.me/rezygiskchat) +- PerformanC Telegram チャンネル: [@performancorg](https://t.me/performancorg) + +## 貢献 + +貢献をしたい場合、PerformanCの[Contribution Guidelines](https://github.com/PerformanC/contributing)に従うことが必要になります。 + +セキュリティーポリシー、行動規範、シンタックススタンダードを採用してください。 + +## ライセンス + +ReZygiskは基本的にDr-TSNGによるGPLライセンス下にてライセンスされています。 + +ただし、書き直しされたコードに関してはPerformanCによるAGPL3.0ライセンスにてライセンスされています。 +詳細については [Open Source Initiative](https://opensource.org/licenses/AGPL-3.0) を参照してください。 From d498a9ab0177eb9087e7eef3978a22640f6cfaa5 Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Sun, 24 Nov 2024 19:18:50 +0100 Subject: [PATCH 07/46] fix: trigger Zygisk modules service.sh in parallel (#91) This commit fixes 2 issues: - service.sh of files were not being executed in parallel, a behavior described in: https://github.com/topjohnwu/Magisk/blob/master/docs/guides.md#boot-scripts . This was fixed by using "&" in the end of the command to execute the module's service.sh, telling the shell to not block. - Gradle wrapper used in ReZygisk was old, causing failing CIs. It also updates the NDK version to ensure we'll be operating smoothly. --- .github/workflows/ci.yml | 2 +- build.gradle.kts | 2 +- gradle/wrapper/gradle-wrapper.jar | Bin 63721 -> 43583 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 297 ++++++++++++++--------- gradlew.bat | 183 +++++++------- module/src/service.sh | 2 +- 7 files changed, 280 insertions(+), 208 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61afb40..c7869ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: java-version: "17" - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4.2.1 with: gradle-home-cache-cleanup: true diff --git a/build.gradle.kts b/build.gradle.kts index 445eb0f..fd2df21 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,7 +33,7 @@ val androidMinSdkVersion by extra(26) val androidTargetSdkVersion by extra(34) val androidCompileSdkVersion by extra(34) val androidBuildToolsVersion by extra("34.0.0") -val androidCompileNdkVersion by extra("26.0.10792818") +val androidCompileNdkVersion by extra("27.2.12479018") val androidSourceCompatibility by extra(JavaVersion.VERSION_11) val androidTargetCompatibility by extra(JavaVersion.VERSION_11) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135c49b765f8051ef9d0a6055ff8e46073d8..a4b76b9530d66f5e68d973ea569d8e19de379189 100644 GIT binary patch literal 43583 zcma&N1CXTcmMvW9vTb(Rwr$&4wr$(C?dmSu>@vG-+vuvg^_??!{yS%8zW-#zn-LkA z5&1^$^{lnmUON?}LBF8_K|(?T0Ra(xUH{($5eN!MR#ZihR#HxkUPe+_R8Cn`RRs(P z_^*#_XlXmGv7!4;*Y%p4nw?{bNp@UZHv1?Um8r6)Fei3p@ClJn0ECfg1hkeuUU@Or zDaPa;U3fE=3L}DooL;8f;P0ipPt0Z~9P0)lbStMS)ag54=uL9ia-Lm3nh|@(Y?B`; zx_#arJIpXH!U{fbCbI^17}6Ri*H<>OLR%c|^mh8+)*h~K8Z!9)DPf zR2h?lbDZQ`p9P;&DQ4F0sur@TMa!Y}S8irn(%d-gi0*WxxCSk*A?3lGh=gcYN?FGl z7D=Js!i~0=u3rox^eO3i@$0=n{K1lPNU zwmfjRVmLOCRfe=seV&P*1Iq=^i`502keY8Uy-WNPwVNNtJFx?IwAyRPZo2Wo1+S(xF37LJZ~%i)kpFQ3Fw=mXfd@>%+)RpYQLnr}B~~zoof(JVm^^&f zxKV^+3D3$A1G;qh4gPVjhrC8e(VYUHv#dy^)(RoUFM?o%W-EHxufuWf(l*@-l+7vt z=l`qmR56K~F|v<^Pd*p~1_y^P0P^aPC##d8+HqX4IR1gu+7w#~TBFphJxF)T$2WEa zxa?H&6=Qe7d(#tha?_1uQys2KtHQ{)Qco)qwGjrdNL7thd^G5i8Os)CHqc>iOidS} z%nFEDdm=GXBw=yXe1W-ShHHFb?Cc70+$W~z_+}nAoHFYI1MV1wZegw*0y^tC*s%3h zhD3tN8b=Gv&rj}!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$FG3k@ep36BRa^>~UmnRPziS>Z=`Jb2x*Q#`%A zU*i3&Vg?TluO@X0O;r2Jl6LKLUOVhSqg1*qOt^|8*c7 zo(298@+r$k_wQNGHv{|$tW(T8L+4_`FQ{kEW5Jgg{yf7ey4ss_(SNKfz(N9lx&a;< je(UuV8hP?p&}TPdm1I$XmG#(RzlD&B2izSj9sl%y5~4qc diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3fa8f86..df97d72 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 4f906e0..f5feea6 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,69 +15,104 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +122,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +133,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 107acd3..9b42019 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,89 +1,94 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/module/src/service.sh b/module/src/service.sh index d544d9d..20a24ce 100644 --- a/module/src/service.sh +++ b/module/src/service.sh @@ -15,7 +15,7 @@ if [ "$(which magisk)" ]; then if [ -f "$file/service.sh" ]; then cd "$file" log -p i -t "zygisk-sh" "Manually trigger service.sh for $file" - sh "$(realpath ./service.sh)" + sh "$(realpath ./service.sh)" & cd "$MODDIR" fi fi From 9bcbec91aa60f2faa7ff6b4e96f87ad4b5f1405d Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Sun, 24 Nov 2024 18:15:31 +0100 Subject: [PATCH 08/46] improve: turn on CMAKE_EXPORT_COMPILE_COMMANDS To make `clangd` work properly, one needs to make symbolic links ``` ln -sf $PWD/loader/build/tools/debug/arm64-v8a/compile_commands.json loader/build ``` --- loader/build.gradle.kts | 1 + loader/src/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/loader/build.gradle.kts b/loader/build.gradle.kts index 144ffba..442f3a2 100644 --- a/loader/build.gradle.kts +++ b/loader/build.gradle.kts @@ -49,6 +49,7 @@ android { externalNativeBuild.cmake { path("src/CMakeLists.txt") + buildStagingDirectory = layout.buildDirectory.get().asFile } defaultConfig { diff --git a/loader/src/CMakeLists.txt b/loader/src/CMakeLists.txt index c8dc73a..84ba7b9 100644 --- a/loader/src/CMakeLists.txt +++ b/loader/src/CMakeLists.txt @@ -3,6 +3,8 @@ project("loader") find_package(cxx REQUIRED CONFIG) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + add_definitions(-DZKSU_VERSION=\"${ZKSU_VERSION}\") aux_source_directory(common COMMON_SRC_LIST) From 3d79939d7bb30841c5f85013dfab9515fd1a4145 Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Fri, 29 Nov 2024 08:16:54 +0100 Subject: [PATCH 09/46] fix: linker64 static symbols lookup with suffix On Android 15+ in some devices, the symbol names of some static variables such as `solist`, has a `llvm` suffix in its exported name. Current commit handles this case and close #63 as fixed. --- loader/src/common/elf_util.cpp | 28 ++++++ loader/src/include/elf_util.h | 6 ++ loader/src/include/solist.hpp | 171 +++++++++++++++++++-------------- 3 files changed, 134 insertions(+), 71 deletions(-) diff --git a/loader/src/common/elf_util.cpp b/loader/src/common/elf_util.cpp index 4ea0732..d265b3c 100644 --- a/loader/src/common/elf_util.cpp +++ b/loader/src/common/elf_util.cpp @@ -179,6 +179,7 @@ ElfW(Addr) ElfImg::LinearLookup(std::string_view name) const { } } } + if (auto i = symtabs_.find(name); i != symtabs_.end()) { return i->second->st_value; } else { @@ -186,6 +187,33 @@ ElfW(Addr) ElfImg::LinearLookup(std::string_view name) const { } } +std::string_view ElfImg::LinearLookupByPrefix(std::string_view name) const { + if (symtabs_.empty()) { + symtabs_.reserve(symtab_count); + if (symtab_start != nullptr && symstr_offset_for_symtab != 0) { + for (ElfW(Off) i = 0; i < symtab_count; i++) { + unsigned int st_type = ELF_ST_TYPE(symtab_start[i].st_info); + const char *st_name = offsetOf(header, symstr_offset_for_symtab + + symtab_start[i].st_name); + if ((st_type == STT_FUNC || st_type == STT_OBJECT) && symtab_start[i].st_size) { + symtabs_.emplace(st_name, &symtab_start[i]); + } + } + } + } + + auto size = name.size(); + for (auto symtab : symtabs_) { + if (symtab.first.size() < size) continue; + + if (symtab.first.substr(0, size) == name) { + return symtab.first; + } + } + + return ""; +} + ElfImg::~ElfImg() { //open elf file local diff --git a/loader/src/include/elf_util.h b/loader/src/include/elf_util.h index 95559f8..1b8c0b7 100644 --- a/loader/src/include/elf_util.h +++ b/loader/src/include/elf_util.h @@ -48,6 +48,10 @@ namespace SandHook { } } + std::string_view findSymbolNameByPrefix(std::string_view prefix) const { + return LinearLookupByPrefix(prefix); + } + template constexpr T getSymbAddress(std::string_view name) const { return reinterpret_cast(getSymbAddress(name)); @@ -72,6 +76,8 @@ namespace SandHook { ElfW(Addr) LinearLookup(std::string_view name) const; + std::string_view LinearLookupByPrefix(std::string_view name) const; + constexpr static uint32_t ElfHash(std::string_view name); constexpr static uint32_t GnuHash(std::string_view name); diff --git a/loader/src/include/solist.hpp b/loader/src/include/solist.hpp index 5feb94d..73ff917 100644 --- a/loader/src/include/solist.hpp +++ b/loader/src/include/solist.hpp @@ -6,98 +6,127 @@ #include #include "elf_util.h" -namespace SoList -{ - class SoInfo { - public: -#ifdef __LP64__ +namespace SoList { + class SoInfo { + public: + #ifdef __LP64__ inline static size_t solist_next_offset = 0x30; constexpr static size_t solist_realpath_offset = 0x1a8; -#else + #else inline static size_t solist_next_offset = 0xa4; constexpr static size_t solist_realpath_offset = 0x174; -#endif + #endif - inline static const char *(*get_realpath_sym)(SoInfo *) = nullptr; - inline static const char *(*get_soname_sym)(SoInfo *) = nullptr; + inline static const char *(*get_realpath_sym)(SoInfo *) = NULL; + inline static const char *(*get_soname_sym)(SoInfo *) = NULL; - inline SoInfo *get_next() { - return *(SoInfo **) ((uintptr_t) this + solist_next_offset); - } + inline SoInfo *get_next() { + return *(SoInfo **) ((uintptr_t) this + solist_next_offset); + } - inline const char *get_path() { - return get_realpath_sym ? get_realpath_sym(this) : ((std::string *) ((uintptr_t) this + solist_realpath_offset))->c_str(); - } + inline const char *get_path() { + if (get_realpath_sym) return get_realpath_sym(this); - inline const char *get_name() { - return get_soname_sym ? get_soname_sym(this) : *((const char **) ((uintptr_t) this + solist_realpath_offset - sizeof(void *))); - } + return ((std::string *) ((uintptr_t) this + solist_realpath_offset))->c_str(); + } - void nullify_name() { - const char** name = (const char**)get_soname_sym(this); + inline const char *get_name() { + if (get_soname_sym) return get_soname_sym(this); - static const char* empty_string = ""; - *name = reinterpret_cast(&empty_string); - } + return ((std::string *) ((uintptr_t) this + solist_realpath_offset - sizeof(void *)))->c_str(); + } - void nullify_path() { - const char** name = (const char**)get_realpath_sym(this); + void nullify_name() { + const char **name = (const char**)get_soname_sym(this); - static const char* empty_string = ""; - *name = reinterpret_cast(&empty_string); - } - }; + static const char *empty_string = ""; + *name = reinterpret_cast(&empty_string); + } - static SoInfo *solist = nullptr; - static SoInfo *somain = nullptr; + void nullify_path() { + const char **name = (const char**)get_realpath_sym(this); - template - inline T *getStaticPointer(const SandHook::ElfImg &linker, const char* name) - { - auto *addr = reinterpret_cast(linker.getSymbAddress(name)); - return addr == nullptr ? nullptr : *addr; + static const char *empty_string = ""; + *name = reinterpret_cast(&empty_string); + } + }; + + static SoInfo *solist = NULL; + static SoInfo *somain = NULL; + + template + inline T *getStaticPointer(const SandHook::ElfImg &linker, const char *name) { + auto *addr = reinterpret_cast(linker.getSymbAddress(name)); + + return addr == NULL ? NULL : *addr; + } + + static void NullifySoName(const char* target_name) { + for (auto *iter = solist; iter; iter = iter->get_next()) { + if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_name)) { + iter->nullify_path(); + LOGI("Cleared SOList entry for %s", target_name); + } } - static void NullifySoName(const char* target_name) { - for (auto *iter = solist; iter; iter = iter->get_next()) { - if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_name)) { - iter->nullify_path(); - LOGI("Cleared SOList entry for %s", target_name); - } - } + for (auto *iter = somain; iter; iter = iter->get_next()) { + if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_name)) { + iter->nullify_path(); - for (auto *iter = somain; iter; iter = iter->get_next()) { - if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_name)) { - iter->nullify_path(); - break; - } - } + break; + } + } + } + + static bool Initialize() { + SandHook::ElfImg linker("/linker"); + + /* INFO: Since Android 15, the symbol names for the linker have a suffix, + this makes it impossible to hardcode the symbol names. To allow + this to work on all versions, we need to iterate over the loaded + symbols and find the correct ones. + + See #63 for more information. + */ + + std::string_view solist_sym_name = linker.findSymbolNameByPrefix("__dl__ZL6solist"); + if (solist_sym_name.empty()) return false; + + /* INFO: The size isn't a magic number, it's the size for the string: .llvm.7690929523238822858 */ + char llvm_sufix[25 + 1]; + + if (solist_sym_name.length() != strlen("__dl__ZL6solist")) { + strncpy(llvm_sufix, solist_sym_name.data() + strlen("__dl__ZL6solist"), sizeof(llvm_sufix)); + } else { + llvm_sufix[0] = '\0'; } - static bool Initialize() { - SandHook::ElfImg linker("/linker"); - solist = getStaticPointer(linker, "__dl__ZL6solist"); - somain = getStaticPointer(linker, "__dl__ZL6somain"); + solist = getStaticPointer(linker, solist_sym_name.data()); + if (solist == NULL) return false; - if (solist != nullptr && somain != nullptr) - { - SoInfo::get_realpath_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo12get_realpathEv")); - SoInfo::get_soname_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo10get_sonameEv")); - auto vsdo = getStaticPointer(linker, "__dl__ZL4vdso"); + char somain_sym_name[sizeof("__dl__ZL6somain") + sizeof(llvm_sufix)]; + snprintf(somain_sym_name, sizeof(somain_sym_name), "__dl__ZL6somain%s", llvm_sufix); - for (size_t i = 0; i < 1024 / sizeof(void *); i++) - { - auto *possible_next = *(void **) ((uintptr_t) solist + i * sizeof(void *)); - if (possible_next == somain || (vsdo != nullptr && possible_next == vsdo)) - { - SoInfo::solist_next_offset = i * sizeof(void *); - break; - } - } + char vsdo_sym_name[sizeof("__dl__ZL4vdso") + sizeof(llvm_sufix)]; + snprintf(vsdo_sym_name, sizeof(vsdo_sym_name), "__dl__ZL4vdso%s", llvm_sufix); - return (SoInfo::get_realpath_sym != nullptr && SoInfo::get_soname_sym != nullptr); - } + somain = getStaticPointer(linker, somain_sym_name); + if (somain == NULL) return false; - return false; + auto vsdo = getStaticPointer(linker, vsdo_sym_name); + + SoInfo::get_realpath_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo12get_realpathEv")); + SoInfo::get_soname_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo10get_sonameEv")); + + for (size_t i = 0; i < 1024 / sizeof(void *); i++) { + auto *possible_next = *(void **) ((uintptr_t) solist + i * sizeof(void *)); + if (possible_next == somain || (vsdo != NULL && possible_next == vsdo)) { + SoInfo::solist_next_offset = i * sizeof(void *); + + break; + } } -} \ No newline at end of file + + return (SoInfo::get_realpath_sym != NULL && SoInfo::get_soname_sym != NULL); + } +} From 6c41a8188d1911d76793c07b390d30693f7a14d7 Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Fri, 29 Nov 2024 11:25:45 +0100 Subject: [PATCH 10/46] improve: drop soinfo records of loaded modules In Bionic linker, the `soinfo` structure has a field `next`, which points to the next loaded library in a linked list consisting of all loaded libraries. Hence, an injected process can easily find all loaded libraries. Previously in ReZygisk, module library records are hidden by setting the `pathname` field to be empty, which is futile but easier to detect. Current idea of dropping record can be found in the following commit: https://github.com/RikkaApps/Riru/commit/5d635e8c66a018b5086f28e083b18b0d0656022b --- loader/src/include/solist.hpp | 97 ++++++++++++++++++++++++++--------- loader/src/injector/hook.cpp | 8 +-- 2 files changed, 73 insertions(+), 32 deletions(-) diff --git a/loader/src/include/solist.hpp b/loader/src/include/solist.hpp index 73ff917..c65798b 100644 --- a/loader/src/include/solist.hpp +++ b/loader/src/include/solist.hpp @@ -5,6 +5,7 @@ #include #include "elf_util.h" +#include "logging.h" namespace SoList { class SoInfo { @@ -36,23 +37,59 @@ namespace SoList { return ((std::string *) ((uintptr_t) this + solist_realpath_offset - sizeof(void *)))->c_str(); } - void nullify_name() { - const char **name = (const char**)get_soname_sym(this); - - static const char *empty_string = ""; - *name = reinterpret_cast(&empty_string); - } - - void nullify_path() { - const char **name = (const char**)get_realpath_sym(this); - - static const char *empty_string = ""; - *name = reinterpret_cast(&empty_string); + void set_next(SoInfo *si) { + *(SoInfo **) ((uintptr_t) this + solist_next_offset) = si; } }; + class ProtectedDataGuard { + public: + ProtectedDataGuard() { + if (ctor != nullptr) + (this->*ctor)(); + } + + ~ProtectedDataGuard() { + if (dtor != nullptr) + (this->*dtor)(); + } + + static bool setup(const SandHook::ElfImg &linker) { + ctor = MemFunc{.data = {.p = reinterpret_cast(linker.getSymbAddress( + "__dl__ZN18ProtectedDataGuardC2Ev")), .adj = 0}}.f; + dtor = MemFunc{.data = {.p = reinterpret_cast(linker.getSymbAddress( + "__dl__ZN18ProtectedDataGuardD2Ev")), .adj = 0}}.f; + return ctor != nullptr && dtor != nullptr; + } + + ProtectedDataGuard(const ProtectedDataGuard &) = delete; + + void operator=(const ProtectedDataGuard &) = delete; + + private: + using FuncType = void (ProtectedDataGuard::*)(); + + static FuncType ctor; + static FuncType dtor; + + union MemFunc { + FuncType f; + + struct { + void *p; + std::ptrdiff_t adj; + } data; + }; + }; + + static SoInfo *solist = NULL; static SoInfo *somain = NULL; + static SoInfo **sonext = NULL; + ProtectedDataGuard::FuncType ProtectedDataGuard::ctor = NULL; + ProtectedDataGuard::FuncType ProtectedDataGuard::dtor = NULL; + + static bool Initialize(); template inline T *getStaticPointer(const SandHook::ElfImg &linker, const char *name) { @@ -61,25 +98,28 @@ namespace SoList { return addr == NULL ? NULL : *addr; } - static void NullifySoName(const char* target_name) { - for (auto *iter = solist; iter; iter = iter->get_next()) { - if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_name)) { - iter->nullify_path(); - LOGI("Cleared SOList entry for %s", target_name); - } + static void DropSoPath(const char* target_path) { + if (solist == NULL && !Initialize()) { + LOGE("Failed to initialize solist"); + return; } - - for (auto *iter = somain; iter; iter = iter->get_next()) { - if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_name)) { - iter->nullify_path(); - - break; + SoInfo *prev = NULL; + for (auto iter = solist; iter; iter = iter->get_next()) { + if (prev != NULL && iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_path)) { + SoList::ProtectedDataGuard guard; + prev->set_next(iter->get_next()); + if (iter == *sonext) { + *sonext = prev; + } + LOGI("Dropped solist record for %s loaded at %s", iter->get_name(), iter->get_path()); } + prev = iter; } } static bool Initialize() { SandHook::ElfImg linker("/linker"); + if (!ProtectedDataGuard::setup(linker)) return false; /* INFO: Since Android 15, the symbol names for the linker have a suffix, this makes it impossible to hardcode the symbol names. To allow @@ -107,13 +147,20 @@ namespace SoList { char somain_sym_name[sizeof("__dl__ZL6somain") + sizeof(llvm_sufix)]; snprintf(somain_sym_name, sizeof(somain_sym_name), "__dl__ZL6somain%s", llvm_sufix); + char sonext_sym_name[sizeof("__dl__ZL6sonext") + sizeof(llvm_sufix)]; + snprintf(sonext_sym_name, sizeof(somain_sym_name), "__dl__ZL6sonext%s", llvm_sufix); + char vsdo_sym_name[sizeof("__dl__ZL4vdso") + sizeof(llvm_sufix)]; snprintf(vsdo_sym_name, sizeof(vsdo_sym_name), "__dl__ZL4vdso%s", llvm_sufix); somain = getStaticPointer(linker, somain_sym_name); if (somain == NULL) return false; - auto vsdo = getStaticPointer(linker, vsdo_sym_name); + sonext = linker.getSymbAddress(sonext_sym_name); + if (sonext == NULL) return false; + + SoInfo *vsdo = getStaticPointer(linker, vsdo_sym_name); + if (vsdo == NULL) return false; SoInfo::get_realpath_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo12get_realpathEv")); SoInfo::get_soname_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo10get_sonameEv")); diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index 4f02f6b..a1b715c 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -582,13 +582,7 @@ void ZygiskContext::run_modules_post() { m.tryUnload(); } - // Remove from SoList to avoid detection - bool solist_res = SoList::Initialize(); - if (!solist_res) { - LOGE("Failed to initialize SoList"); - } else { - SoList::NullifySoName("jit-cache"); - } + SoList::DropSoPath("jit-cache"); // Remap as well to avoid checking of /memfd:jit-cache for (auto &info : lsplt::MapInfo::Scan()) { From 060a1f3cf96000bcccf0891217d0afcc9de79e2b Mon Sep 17 00:00:00 2001 From: Md Arif <111168803+sabamdarif@users.noreply.github.com> Date: Sat, 7 Dec 2024 19:03:22 +0000 Subject: [PATCH 11/46] add: GrapheneOS support (#53) This commit adds support for devices that run GrapheneOS by hooking on JNI methods they renamed. Signed-off-by: Md Arif <111168803+sabamdarif@users.noreply.github.com> --- loader/src/injector/gen_jni_hooks.py | 19 +++++++-- loader/src/injector/jni_hooks.hpp | 59 ++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/loader/src/injector/gen_jni_hooks.py b/loader/src/injector/gen_jni_hooks.py index 1f134a5..a3adbf6 100644 --- a/loader/src/injector/gen_jni_hooks.py +++ b/loader/src/injector/gen_jni_hooks.py @@ -77,6 +77,7 @@ jintArray = JArray(jint) jstring = JType('jstring', 'Ljava/lang/String;') jboolean = JType('jboolean', 'Z') jlong = JType('jlong', 'J') +jlongArray = JArray(jlong) void = JType('void', 'V') class ForkAndSpec(JNIHook): @@ -210,6 +211,18 @@ server_l = ForkServer('l', [uid, gid, gids, runtime_flags, rlimits, server_samsung_q = ForkServer('samsung_q', [uid, gid, gids, runtime_flags, Anon(jint), Anon(jint), rlimits, permitted_capabilities, effective_capabilities]) +# GrapheneOS Android 14 Support +server_grapheneos_u = ForkServer('grapheneos_u', [uid, gid, gids, runtime_flags, Anon(jint), Anon(jint), rlimits, + permitted_capabilities, effective_capabilities]) + +fas_grapheneos_u = ForkAndSpec('grapheneos_u', [uid, gid, gids, runtime_flags, rlimits, mount_external, + se_info, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir, + is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, Anon(jlongArray)]) + +spec_grapheneos_u = SpecApp('grapheneos_u', [uid, gid, gids, runtime_flags, rlimits, mount_external, + se_info, nice_name, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, + whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, Anon(jlongArray)]) + hook_map = {} def gen_jni_def(clz, methods): @@ -245,13 +258,13 @@ with open('jni_hooks.hpp', 'w') as f: zygote = 'com/android/internal/os/Zygote' - methods = [fas_l, fas_o, fas_p, fas_q_alt, fas_r, fas_u, fas_samsung_m, fas_samsung_n, fas_samsung_o, fas_samsung_p] + methods = [fas_l, fas_o, fas_p, fas_q_alt, fas_r, fas_u, fas_samsung_m, fas_samsung_n, fas_samsung_o, fas_samsung_p, fas_grapheneos_u] f.write(gen_jni_def(zygote, methods)) - methods = [spec_q, spec_q_alt, spec_r, spec_u, spec_samsung_q] + methods = [spec_q, spec_q_alt, spec_r, spec_u, spec_samsung_q, spec_grapheneos_u] f.write(gen_jni_def(zygote, methods)) - methods = [server_l, server_samsung_q] + methods = [server_l, server_samsung_q, server_grapheneos_u] f.write(gen_jni_def(zygote, methods)) f.write('\n} // namespace\n') diff --git a/loader/src/injector/jni_hooks.hpp b/loader/src/injector/jni_hooks.hpp index b4daaaf..b31a7fd 100644 --- a/loader/src/injector/jni_hooks.hpp +++ b/loader/src/injector/jni_hooks.hpp @@ -127,6 +127,24 @@ void *nativeForkAndSpecialize_orig = nullptr; ctx.nativeForkAndSpecialize_post(); return ctx.pid; } +[[clang::no_stack_protector]] jint nativeForkAndSpecialize_grapheneos_u(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jlongArray _15) { + AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir); + args.fds_to_ignore = &fds_to_ignore; + args.is_child_zygote = &is_child_zygote; + args.is_top_app = &is_top_app; + args.pkg_data_info_list = &pkg_data_info_list; + args.whitelisted_data_info_list = &whitelisted_data_info_list; + args.mount_data_dirs = &mount_data_dirs; + args.mount_storage_dirs = &mount_storage_dirs; + args.mount_sysprop_overrides = &mount_sysprop_overrides; + ZygiskContext ctx(env, &args); + ctx.nativeForkAndSpecialize_pre(); + reinterpret_cast(nativeForkAndSpecialize_orig)( + env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _15 + ); + ctx.nativeForkAndSpecialize_post(); + return ctx.pid; +} std::array nativeForkAndSpecialize_methods = { JNINativeMethod { "nativeForkAndSpecialize", @@ -178,6 +196,11 @@ std::array nativeForkAndSpecialize_methods = { "(II[II[[IILjava/lang/String;IILjava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;)I", (void *) &nativeForkAndSpecialize_samsung_p }, + JNINativeMethod { + "nativeForkAndSpecialize", + "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/String;ZZZ[J)I", + (void *) &nativeForkAndSpecialize_grapheneos_u + }, }; void *nativeSpecializeAppProcess_orig = nullptr; @@ -243,6 +266,22 @@ void *nativeSpecializeAppProcess_orig = nullptr; ); ctx.nativeSpecializeAppProcess_post(); } +[[clang::no_stack_protector]] void nativeSpecializeAppProcess_grapheneos_u(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jlongArray _16) { + AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir); + args.is_child_zygote = &is_child_zygote; + args.is_top_app = &is_top_app; + args.pkg_data_info_list = &pkg_data_info_list; + args.whitelisted_data_info_list = &whitelisted_data_info_list; + args.mount_data_dirs = &mount_data_dirs; + args.mount_storage_dirs = &mount_storage_dirs; + args.mount_sysprop_overrides = &mount_sysprop_overrides; + ZygiskContext ctx(env, &args); + ctx.nativeSpecializeAppProcess_pre(); + reinterpret_cast(nativeSpecializeAppProcess_orig)( + env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _16 + ); + ctx.nativeSpecializeAppProcess_post(); +} std::array nativeSpecializeAppProcess_methods = { JNINativeMethod { "nativeSpecializeAppProcess", @@ -269,6 +308,11 @@ std::array nativeSpecializeAppProcess_methods = { "(II[II[[IILjava/lang/String;IILjava/lang/String;ZLjava/lang/String;Ljava/lang/String;)V", (void *) &nativeSpecializeAppProcess_samsung_q }, + JNINativeMethod { + "nativeSpecializeAppProcess", + "(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/String;ZZZ[J)V", + (void *) &nativeSpecializeAppProcess_grapheneos_u + }, }; void *nativeForkSystemServer_orig = nullptr; @@ -292,6 +336,16 @@ void *nativeForkSystemServer_orig = nullptr; ctx.nativeForkSystemServer_post(); return ctx.pid; } +[[clang::no_stack_protector]] jint nativeForkSystemServer_grapheneos_u(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _13, jint _14, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities) { + ServerSpecializeArgs_v1 args(uid, gid, gids, runtime_flags, permitted_capabilities, effective_capabilities); + ZygiskContext ctx(env, &args); + ctx.nativeForkSystemServer_pre(); + reinterpret_cast(nativeForkSystemServer_orig)( + env, clazz, uid, gid, gids, runtime_flags, _13, _14, rlimits, permitted_capabilities, effective_capabilities + ); + ctx.nativeForkSystemServer_post(); + return ctx.pid; +} std::array nativeForkSystemServer_methods = { JNINativeMethod { "nativeForkSystemServer", @@ -303,6 +357,11 @@ std::array nativeForkSystemServer_methods = { "(II[IIII[[IJJ)I", (void *) &nativeForkSystemServer_samsung_q }, + JNINativeMethod { + "nativeForkSystemServer", + "(II[IIII[[IJJ)I", + (void *) &nativeForkSystemServer_grapheneos_u + }, }; } // namespace From 8fb5d9197acde8f25e7932a5da3b7e3bd4d1a886 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Thu, 12 Dec 2024 20:10:38 -0300 Subject: [PATCH 12/46] fix: `magisk` file detection This commit fixes the detection for the "magisk" file which can be in 2 different folders, with 3 possible different names. --- zygiskd/src/root_impl/magisk.c | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/zygiskd/src/root_impl/magisk.c b/zygiskd/src/root_impl/magisk.c index 298dc55..d33e71a 100644 --- a/zygiskd/src/root_impl/magisk.c +++ b/zygiskd/src/root_impl/magisk.c @@ -24,6 +24,7 @@ char *magisk_managers[] = { }; #define SBIN_MAGISK lp_select("/sbin/magisk32", "/sbin/magisk64") +#define BITLESS_SBIN_MAGISK "/sbin/magisk" #define DEBUG_RAMDISK_MAGISK lp_select("/debug_ramdisk/magisk32", "/debug_ramdisk/magisk64") #define BITLESS_DEBUG_RAMDISK_MAGISK "/debug_ramdisk/magisk" @@ -39,31 +40,41 @@ void magisk_get_existence(struct root_impl_state *state) { } errno = 0; - if (stat(DEBUG_RAMDISK_MAGISK, &s) != 0) { + if (stat(BITLESS_SBIN_MAGISK, &s) != 0) { if (errno != ENOENT) { - LOGE("Failed to stat Magisk %s binary: %s\n", DEBUG_RAMDISK_MAGISK, strerror(errno)); + LOGE("Failed to stat Magisk %s binary: %s\n", BITLESS_SBIN_MAGISK, strerror(errno)); } errno = 0; - if (stat(BITLESS_DEBUG_RAMDISK_MAGISK, &s) != 0) { + if (stat(DEBUG_RAMDISK_MAGISK, &s) != 0) { if (errno != ENOENT) { - LOGE("Failed to stat Magisk /debug_ramdisk/magisk binary: %s\n", strerror(errno)); + LOGE("Failed to stat Magisk %s binary: %s\n", DEBUG_RAMDISK_MAGISK, strerror(errno)); } errno = 0; - state->state = Inexistent; + if (stat(BITLESS_DEBUG_RAMDISK_MAGISK, &s) != 0) { + if (errno != ENOENT) { + LOGE("Failed to stat Magisk /debug_ramdisk/magisk binary: %s\n", strerror(errno)); + } + errno = 0; - return; + state->state = Inexistent; + + return; + } + + /* INFO: /debug_ramdisk/magisk64 (or 32) doesn't exist but /debug_ramdisk/magisk does */ + strcpy(path_to_magisk, BITLESS_DEBUG_RAMDISK_MAGISK); + } else { + /* INFO: /sbin/magisk doesn't exist but /debug_ramdisk/magisk does */ + strcpy(path_to_magisk, DEBUG_RAMDISK_MAGISK); } - - /* INFO: /debug_ramdisk/magisk64 (or 32) doesn't exist but /debug_ramdisk/magisk does */ - strcpy(path_to_magisk, BITLESS_DEBUG_RAMDISK_MAGISK); } else { - /* INFO: /sbin/magisk doesn't exist but /debug_ramdisk/magisk does */ - strcpy(path_to_magisk, DEBUG_RAMDISK_MAGISK); + /* INFO: /sbin/magisk64 (or 32) doesn't exist but /sbin/magisk does */ + strcpy(path_to_magisk, BITLESS_SBIN_MAGISK); } } else { - /* INFO: /sbin/magisk exists */ + /* INFO: /sbin/magisk64 (or 32) exists */ strcpy(path_to_magisk, SBIN_MAGISK); } From 5e43e4a71b5231cb8f822651e23228bca34ea87a Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Thu, 12 Dec 2024 15:57:41 +0100 Subject: [PATCH 13/46] improve: hook pthread_attr_setstacksize Relying on dlclose to unload libzygisk.so will block us to clean its trace in the solist. This commit allows us to unmap libzygisk.so without using dlclose. To call munmap, we use the function pthread_attr_setstacksize instead of pthread_attr_destroy, so that tail-call can still be applied here since it has the same signature as munmap. --- loader/src/injector/entry.cpp | 11 ++++++----- loader/src/injector/hook.cpp | 18 ++++++++++-------- loader/src/injector/zygisk.hpp | 5 ++--- loader/src/ptracer/ptracer.cpp | 18 ++++++++++++++++-- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/loader/src/injector/entry.cpp b/loader/src/injector/entry.cpp index 1cabc27..40a71b6 100644 --- a/loader/src/injector/entry.cpp +++ b/loader/src/injector/entry.cpp @@ -1,16 +1,17 @@ #include "daemon.h" #include "logging.h" #include "zygisk.hpp" -#include "module.hpp" using namespace std; -void *self_handle = nullptr; +void *start_addr = nullptr; +size_t block_size = 0; extern "C" [[gnu::visibility("default")]] -void entry(void* handle, const char* path) { +void entry(void* addr, size_t size, const char* path) { LOGI("Zygisk library injected, version %s", ZKSU_VERSION); - self_handle = handle; + start_addr = addr; + block_size = size; zygiskd::Init(path); if (!zygiskd::PingHeartbeat()) { @@ -22,6 +23,6 @@ void entry(void* handle, const char* path) { logging::setfd(zygiskd::RequestLogcatFd()); #endif - LOGI("Start hooking"); + LOGI("Start hooking, call %p", hook_functions); hook_functions(); } diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index a1b715c..16bb8d1 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -176,22 +176,24 @@ DCL_HOOK_FUNC(void, android_log_close) { // We cannot directly call `dlclose` to unload ourselves, otherwise when `dlclose` returns, // it will return to our code which has been unmapped, causing segmentation fault. -// Instead, we hook `pthread_attr_destroy` which will be called when VM daemon threads start. -DCL_HOOK_FUNC(int, pthread_attr_destroy, void *target) { - int res = old_pthread_attr_destroy((pthread_attr_t *)target); +// Instead, we hook `pthread_attr_setstacksize` which will be called when VM daemon threads start. +DCL_HOOK_FUNC(int, pthread_attr_setstacksize, void *target, size_t size) { + int res = old_pthread_attr_setstacksize((pthread_attr_t *)target, size); + LOGV("Call pthread_attr_setstacksize in [tid, pid]: %d, %d", gettid(), getpid()); // Only perform unloading on the main thread if (gettid() != getpid()) return res; - LOGV("pthread_attr_destroy"); + LOGV("Clean zygisk reminders"); if (should_unmap_zygisk) { unhook_functions(); if (should_unmap_zygisk) { - // Because both `pthread_attr_destroy` and `dlclose` have the same function signature, + // Because both `pthread_attr_setstacksize` and `dlclose` have the same function signature, // we can use `musttail` to let the compiler reuse our stack frame and thus - // `dlclose` will directly return to the caller of `pthread_attr_destroy`. - [[clang::musttail]] return dlclose(self_handle); + // `dlclose` will directly return to the caller of `pthread_attr_setstacksize`. + LOGV("Unmap libzygisk.so"); + [[clang::musttail]] return munmap(start_addr, block_size); } } @@ -858,7 +860,7 @@ static void hook_unloader() { } } - PLT_HOOK_REGISTER(art_dev, art_inode, pthread_attr_destroy); + PLT_HOOK_REGISTER(art_dev, art_inode, pthread_attr_setstacksize); hook_commit(); } diff --git a/loader/src/injector/zygisk.hpp b/loader/src/injector/zygisk.hpp index 5c06f8b..636367b 100644 --- a/loader/src/injector/zygisk.hpp +++ b/loader/src/injector/zygisk.hpp @@ -1,10 +1,9 @@ #pragma once -#include #include -#include -extern void *self_handle; +extern void *start_addr; +extern size_t block_size; void hook_functions(); diff --git a/loader/src/ptracer/ptracer.cpp b/loader/src/ptracer/ptracer.cpp index 9182ddd..f790f98 100644 --- a/loader/src/ptracer/ptracer.cpp +++ b/loader/src/ptracer/ptracer.cpp @@ -222,10 +222,24 @@ bool inject_on_main(int pid, const char *lib_path) { return false; } - /* call injector entry(handle, path) */ + /* record the address range of libzygisk.so */ + map = MapInfo::Scan(std::to_string(pid)); + void *start_addr = nullptr; + size_t block_size = 0; + for (auto &info : map) { + if (strstr(info.path.c_str(), "libzygisk.so")) { + void *addr = (void *)info.start; + if (start_addr == nullptr) start_addr = addr; + size_t size = info.end - info.start; + block_size += size; + LOGD("found block %s: [%p-%p] with size %zu", info.path.c_str(), addr, (void *)info.end, size); + } + } + /* call injector entry(start_addr, block_size, path) */ args.clear(); - args.push_back(remote_handle); + args.push_back((uintptr_t) start_addr); + args.push_back(block_size); str = push_string(pid, regs, zygiskd::GetTmpPath().c_str()); args.push_back((long) str); From b7138d635347f9d7848cdcd85710444b243370a2 Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Sun, 15 Dec 2024 15:40:40 +0100 Subject: [PATCH 14/46] add: drop soinfo for libzygisk.so 1. fix typo vsdo -> vdso and allow this symbol to be not found, which is the case for the 32bit linkers on some devices 2. use soinfo_free to fully remove the soinfo record of libzygisk.so 3. set `soinfo.size = 0` to avoid the library being unmapped while removing its soinfo record 4. add more debug logs for troubleshooting --- loader/src/include/solist.hpp | 75 +++++++++++++++++++++++++--------- loader/src/injector/entry.cpp | 3 +- loader/src/injector/hook.cpp | 10 +++-- loader/src/injector/zygisk.hpp | 2 + 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/loader/src/include/solist.hpp b/loader/src/include/solist.hpp index c65798b..77ab4a5 100644 --- a/loader/src/include/solist.hpp +++ b/loader/src/include/solist.hpp @@ -11,20 +11,27 @@ namespace SoList { class SoInfo { public: #ifdef __LP64__ - inline static size_t solist_next_offset = 0x30; + inline static size_t solist_size_offset = 0x18; + inline static size_t solist_next_offset = 0x28; constexpr static size_t solist_realpath_offset = 0x1a8; #else + inline static size_t solist_size_offset = 0x90; inline static size_t solist_next_offset = 0xa4; constexpr static size_t solist_realpath_offset = 0x174; #endif inline static const char *(*get_realpath_sym)(SoInfo *) = NULL; inline static const char *(*get_soname_sym)(SoInfo *) = NULL; + inline static void (*soinfo_free)(SoInfo *) = NULL; inline SoInfo *get_next() { return *(SoInfo **) ((uintptr_t) this + solist_next_offset); } + inline size_t get_size() { + return *(size_t *) ((uintptr_t) this + solist_size_offset); + } + inline const char *get_path() { if (get_realpath_sym) return get_realpath_sym(this); @@ -40,6 +47,10 @@ namespace SoList { void set_next(SoInfo *si) { *(SoInfo **) ((uintptr_t) this + solist_next_offset) = si; } + + void set_size(size_t size) { + *(size_t *) ((uintptr_t) this + solist_size_offset) = size; + } }; class ProtectedDataGuard { @@ -69,8 +80,8 @@ namespace SoList { private: using FuncType = void (ProtectedDataGuard::*)(); - static FuncType ctor; - static FuncType dtor; + inline static FuncType ctor = NULL; + inline static FuncType dtor = NULL; union MemFunc { FuncType f; @@ -86,8 +97,6 @@ namespace SoList { static SoInfo *solist = NULL; static SoInfo *somain = NULL; static SoInfo **sonext = NULL; - ProtectedDataGuard::FuncType ProtectedDataGuard::ctor = NULL; - ProtectedDataGuard::FuncType ProtectedDataGuard::dtor = NULL; static bool Initialize(); @@ -103,23 +112,22 @@ namespace SoList { LOGE("Failed to initialize solist"); return; } - SoInfo *prev = NULL; for (auto iter = solist; iter; iter = iter->get_next()) { - if (prev != NULL && iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_path)) { + if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_path)) { SoList::ProtectedDataGuard guard; - prev->set_next(iter->get_next()); - if (iter == *sonext) { - *sonext = prev; + LOGI("dropping solist record for %s loaded at %s with size %zu", iter->get_name(), iter->get_path(), iter->get_size()); + if (iter->get_size() > 0) { + iter->set_size(0); + SoInfo::soinfo_free(iter); } - LOGI("Dropped solist record for %s loaded at %s", iter->get_name(), iter->get_path()); } - prev = iter; } } static bool Initialize() { SandHook::ElfImg linker("/linker"); if (!ProtectedDataGuard::setup(linker)) return false; + LOGD("found symbol ProtectedDataGuard"); /* INFO: Since Android 15, the symbol names for the linker have a suffix, this makes it impossible to hardcode the symbol names. To allow @@ -131,6 +139,11 @@ namespace SoList { std::string_view solist_sym_name = linker.findSymbolNameByPrefix("__dl__ZL6solist"); if (solist_sym_name.empty()) return false; + LOGD("found symbol name %s", solist_sym_name.data()); + + std::string_view soinfo_free_name = linker.findSymbolNameByPrefix("__dl__ZL11soinfo_freeP6soinfo"); + if (soinfo_free_name.empty()) return false; + LOGD("found symbol name %s", soinfo_free_name.data()); /* INFO: The size isn't a magic number, it's the size for the string: .llvm.7690929523238822858 */ char llvm_sufix[25 + 1]; @@ -143,6 +156,7 @@ namespace SoList { solist = getStaticPointer(linker, solist_sym_name.data()); if (solist == NULL) return false; + LOGD("found symbol solist"); char somain_sym_name[sizeof("__dl__ZL6somain") + sizeof(llvm_sufix)]; snprintf(somain_sym_name, sizeof(somain_sym_name), "__dl__ZL6somain%s", llvm_sufix); @@ -150,30 +164,51 @@ namespace SoList { char sonext_sym_name[sizeof("__dl__ZL6sonext") + sizeof(llvm_sufix)]; snprintf(sonext_sym_name, sizeof(somain_sym_name), "__dl__ZL6sonext%s", llvm_sufix); - char vsdo_sym_name[sizeof("__dl__ZL4vdso") + sizeof(llvm_sufix)]; - snprintf(vsdo_sym_name, sizeof(vsdo_sym_name), "__dl__ZL4vdso%s", llvm_sufix); + char vdso_sym_name[sizeof("__dl__ZL4vdso") + sizeof(llvm_sufix)]; + snprintf(vdso_sym_name, sizeof(vdso_sym_name), "__dl__ZL4vdso%s", llvm_sufix); somain = getStaticPointer(linker, somain_sym_name); if (somain == NULL) return false; + LOGD("found symbol somain"); sonext = linker.getSymbAddress(sonext_sym_name); if (sonext == NULL) return false; + LOGD("found symbol sonext"); - SoInfo *vsdo = getStaticPointer(linker, vsdo_sym_name); - if (vsdo == NULL) return false; + SoInfo *vdso = getStaticPointer(linker, vdso_sym_name); + if (vdso != NULL) { + LOGD("found symbol vdso"); + } else { + LOGD("symbol vdso is missing"); + } SoInfo::get_realpath_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo12get_realpathEv")); + if (SoInfo::get_realpath_sym == NULL) return false; + LOGD("found symbol get_realpath_sym"); + SoInfo::get_soname_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo10get_sonameEv")); + if (SoInfo::get_soname_sym == NULL) return false; + LOGD("found symbol get_soname_sym"); + + SoInfo::soinfo_free = reinterpret_cast(linker.getSymbAddress(soinfo_free_name)); + if (SoInfo::soinfo_free == NULL) return false; + LOGD("found symbol soinfo_free"); + for (size_t i = 0; i < 1024 / sizeof(void *); i++) { - auto *possible_next = *(void **) ((uintptr_t) solist + i * sizeof(void *)); - if (possible_next == somain || (vsdo != NULL && possible_next == vsdo)) { + auto possible_field = (uintptr_t) solist + i * sizeof(void *); + auto possible_size_of_somain = *(size_t *)((uintptr_t) somain + i * sizeof(void *)); + if (possible_size_of_somain < 0x100000 && possible_size_of_somain > 0x100) { + SoInfo::solist_size_offset = i * sizeof(void *); + LOGD("solist_size_offset is %zu * %zu = %p", i, sizeof(void *), (void*) SoInfo::solist_size_offset); + } + if (*(void **)possible_field == somain || (vdso != NULL && *(void **)possible_field == vdso)) { SoInfo::solist_next_offset = i * sizeof(void *); - + LOGD("solist_next_offset is %zu * %zu = %p", i, sizeof(void *), (void*) SoInfo::solist_next_offset); break; } } - return (SoInfo::get_realpath_sym != NULL && SoInfo::get_soname_sym != NULL); + return true; } } diff --git a/loader/src/injector/entry.cpp b/loader/src/injector/entry.cpp index 40a71b6..36409aa 100644 --- a/loader/src/injector/entry.cpp +++ b/loader/src/injector/entry.cpp @@ -23,6 +23,7 @@ void entry(void* addr, size_t size, const char* path) { logging::setfd(zygiskd::RequestLogcatFd()); #endif - LOGI("Start hooking, call %p", hook_functions); + LOGI("start plt hooking"); hook_functions(); + clean_trace(path); } diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index 16bb8d1..4d4f2a8 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -185,14 +185,13 @@ DCL_HOOK_FUNC(int, pthread_attr_setstacksize, void *target, size_t size) { if (gettid() != getpid()) return res; - LOGV("Clean zygisk reminders"); if (should_unmap_zygisk) { unhook_functions(); if (should_unmap_zygisk) { // Because both `pthread_attr_setstacksize` and `dlclose` have the same function signature, // we can use `musttail` to let the compiler reuse our stack frame and thus // `dlclose` will directly return to the caller of `pthread_attr_setstacksize`. - LOGV("Unmap libzygisk.so"); + LOGI("unmap libzygisk.so loaded at %p with size %zu", start_addr, block_size); [[clang::musttail]] return munmap(start_addr, block_size); } } @@ -584,7 +583,7 @@ void ZygiskContext::run_modules_post() { m.tryUnload(); } - SoList::DropSoPath("jit-cache"); + clean_trace("jit-cache"); // Remap as well to avoid checking of /memfd:jit-cache for (auto &info : lsplt::MapInfo::Scan()) { @@ -816,6 +815,11 @@ static void hook_register(dev_t dev, ino_t inode, const char *symbol, void *new_ #define PLT_HOOK_REGISTER(DEV, INODE, NAME) \ PLT_HOOK_REGISTER_SYM(DEV, INODE, #NAME, NAME) +void clean_trace(const char* path) { + LOGD("clean solist trace for path %s", path); + SoList::DropSoPath(path); +} + void hook_functions() { default_new(plt_hook_list); default_new(jni_hook_list); diff --git a/loader/src/injector/zygisk.hpp b/loader/src/injector/zygisk.hpp index 636367b..f704181 100644 --- a/loader/src/injector/zygisk.hpp +++ b/loader/src/injector/zygisk.hpp @@ -7,6 +7,8 @@ extern size_t block_size; void hook_functions(); +void clean_trace(const char* path); + void revert_unmount_ksu(); void revert_unmount_magisk(); From 2814aaf67fc3993394e5b3801a4cf9a2606b63a8 Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Sat, 14 Dec 2024 13:11:03 +0100 Subject: [PATCH 15/46] remove: unnecessary memory mapping renaming Note that it is impossible to hide injecting trace of virtual memory maps from the hooked target process. ReZygisk will only focus on removing its trace for approcess that are not hooked by modules. --- loader/src/include/solist.hpp | 7 ++- loader/src/injector/hook.cpp | 107 +++++++++------------------------ loader/src/injector/zygisk.hpp | 2 +- 3 files changed, 36 insertions(+), 80 deletions(-) diff --git a/loader/src/include/solist.hpp b/loader/src/include/solist.hpp index 77ab4a5..51a4f2e 100644 --- a/loader/src/include/solist.hpp +++ b/loader/src/include/solist.hpp @@ -107,10 +107,11 @@ namespace SoList { return addr == NULL ? NULL : *addr; } - static void DropSoPath(const char* target_path) { + static bool DropSoPath(const char* target_path) { + bool path_found = false; if (solist == NULL && !Initialize()) { LOGE("Failed to initialize solist"); - return; + return path_found; } for (auto iter = solist; iter; iter = iter->get_next()) { if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_path)) { @@ -119,9 +120,11 @@ namespace SoList { if (iter->get_size() > 0) { iter->set_size(0); SoInfo::soinfo_free(iter); + path_found = true; } } } + return path_found; } static bool Initialize() { diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index 4d4f2a8..0c86588 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -583,80 +583,7 @@ void ZygiskContext::run_modules_post() { m.tryUnload(); } - clean_trace("jit-cache"); - - // Remap as well to avoid checking of /memfd:jit-cache - for (auto &info : lsplt::MapInfo::Scan()) { - if (strstr(info.path.c_str(), "jit-cache-zygisk")) - { - void *addr = (void *)info.start; - size_t size = info.end - info.start; - // MAP_SHARED should fix the suspicious mapping. - void *copy = mmap(nullptr, size, PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); - if (copy == MAP_FAILED) { - LOGE("Failed to mmap jit-cache-zygisk"); - continue; - } - - if ((info.perms & PROT_READ) == 0) { - mprotect(addr, size, PROT_READ); - } - memcpy(copy, addr, size); - mremap(copy, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, addr); - mprotect(addr, size, info.perms); - } - } - - // Don't know if there's a header for things like this - // so I just put it into a lambda - auto generateRandomString = [](char *str, int length) { - const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - srand(time(NULL)); - - for (int i = 0; i < length; i++) { - int key = rand() % (sizeof(charset) - 1); - str[i] = charset[key]; - } - - str[length] = '\0'; - }; - - // Randomize name of anonymous mappings - // We don't run this in the previous loop because LSPosed might also add - // mappings that are not related to /memfd:jit-zygisk-cache - // - // Since we changed to MAP_SHARED, I don't think this is still needed but let's - // leave it here just in case. - for (auto info : lsplt::MapInfo::Scan()) { - // I had some problems with info.perms & PROT_EXEC so I had to change lsplt source a bit. - // If that problem occurs here, do strchr(info.perms_str.c_str(), 'x') instead and add perms_str - // to the lsplt MapInfo struct and set it to the raw perms string in Scan(); - if (info.perms & PROT_EXEC && info.path.empty()) { - // Generate Random Name - char randomString[11]; - generateRandomString(randomString, 10); - LOGI("Randomized Memory map name: %s", randomString); - - // Memory address of random string - uintptr_t strAddr = (uintptr_t)&randomString; - - // https://lore.kernel.org/lkml/1383170047-21074-2-git-send-email-ccross@android.com/ - prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, info.start, info.end - info.start, strAddr); - } - - // Remap as MAP_SHARED - if (info.perms & PROT_EXEC && info.dev == 0 && info.path.find("anon") != std::string::npos) { - void *addr = reinterpret_cast(info.start); - size_t size = info.end - info.start; - void *copy = mmap(nullptr, size, PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); - if ((info.perms & PROT_READ) == 0) { - mprotect(addr, size, PROT_READ); - } - memcpy(copy, addr, size); - mremap(copy, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, addr); - mprotect(addr, size, info.perms); - } - } + clean_trace("jit-cache-zygisk", true); } /* Zygisksu changed: Load module fds */ @@ -815,9 +742,35 @@ static void hook_register(dev_t dev, ino_t inode, const char *symbol, void *new_ #define PLT_HOOK_REGISTER(DEV, INODE, NAME) \ PLT_HOOK_REGISTER_SYM(DEV, INODE, #NAME, NAME) -void clean_trace(const char* path) { - LOGD("clean solist trace for path %s", path); - SoList::DropSoPath(path); +void clean_trace(const char* path, bool spoof_maps) { + LOGD("cleaning trace for path %s", path); + + if (!SoList::DropSoPath(path) || !spoof_maps) { + return; + } + + LOGD("spoofing virtual maps for %s", path); + // spoofing map names is futile in Android, we do it simply + // to avoid Zygisk detections based on string comparison + for (auto &info : lsplt::MapInfo::Scan()) { + if (strstr(info.path.c_str(), path)) + { + void *addr = (void *)info.start; + size_t size = info.end - info.start; + void *copy = mmap(nullptr, size, PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); + if (copy == MAP_FAILED) { + LOGE("failed to backup block %s [%p, %p]", info.path.c_str(), addr, (void*)info.end); + continue; + } + + if ((info.perms & PROT_READ) == 0) { + mprotect(addr, size, PROT_READ); + } + memcpy(copy, addr, size); + mremap(copy, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, addr); + mprotect(addr, size, info.perms); + } + } } void hook_functions() { diff --git a/loader/src/injector/zygisk.hpp b/loader/src/injector/zygisk.hpp index f704181..744755e 100644 --- a/loader/src/injector/zygisk.hpp +++ b/loader/src/injector/zygisk.hpp @@ -7,7 +7,7 @@ extern size_t block_size; void hook_functions(); -void clean_trace(const char* path); +void clean_trace(const char* path, bool spoof_maps = false); void revert_unmount_ksu(); From 5e072bd919d6c2b38d31359762c500a05c48f87b Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Sun, 15 Dec 2024 01:05:23 +0100 Subject: [PATCH 16/46] improve: cache scanned virtual maps Reading the file `/proc/self/maps` is detectable by the target process. Hence, we should cache scanned virtual maps after `libart.so` is loaded for later plt hooks in the target process. --- .gitmodules | 2 +- loader/src/external/lsplt | 2 +- loader/src/injector/hook.cpp | 41 +++++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.gitmodules b/.gitmodules index 340c732..e46b92c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "loader/src/external/lsplt"] path = loader/src/external/lsplt - url = https://github.com/LSPosed/lsplt + url = https://github.com/JingMatrix/LSPlt diff --git a/loader/src/external/lsplt b/loader/src/external/lsplt index 5d2b820..9848042 160000 --- a/loader/src/external/lsplt +++ b/loader/src/external/lsplt @@ -1 +1 @@ -Subproject commit 5d2b820cf968fcd8162697d208ad406805b6db25 +Subproject commit 984804293e6f7f87604479fefd57976a2c222a89 diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index 0c86588..ef0ad6a 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -122,6 +122,7 @@ struct ZygiskContext { vector> *plt_hook_list; map, StringCmp> *jni_hook_list; bool should_unmap_zygisk = false; +std::vector cached_map_infos = {}; } // namespace @@ -187,6 +188,7 @@ DCL_HOOK_FUNC(int, pthread_attr_setstacksize, void *target, size_t size) { if (should_unmap_zygisk) { unhook_functions(); + cached_map_infos.clear(); if (should_unmap_zygisk) { // Because both `pthread_attr_setstacksize` and `dlclose` have the same function signature, // we can use `musttail` to let the compiler reuse our stack frame and thus @@ -205,6 +207,8 @@ DCL_HOOK_FUNC(char *, strdup, const char *s) { if (strcmp(s, "com.android.internal.os.ZygoteInit") == 0) { LOGV("strdup %s", s); initialize_jni_hook(); + cached_map_infos = lsplt::MapInfo::Scan(); + LOGD("cached_map_infos updated"); } return old_strdup(s); @@ -268,7 +272,7 @@ void initialize_jni_hook() { auto get_created_java_vms = reinterpret_cast( dlsym(RTLD_DEFAULT, "JNI_GetCreatedJavaVMs")); if (!get_created_java_vms) { - for (auto &map: lsplt::MapInfo::Scan()) { + for (auto &map: cached_map_infos) { if (!map.path.ends_with("/libnativehelper.so")) continue; void *h = dlopen(map.path.data(), RTLD_LAZY); if (!h) { @@ -349,7 +353,7 @@ bool ZygiskModule::RegisterModuleImpl(ApiTable *api, long *module) { api->v2.getFlags = [](auto) { return ZygiskModule::getFlags(); }; } if (api_version >= 4) { - api->v4.pltHookCommit = lsplt::CommitHook; + api->v4.pltHookCommit = []() { return lsplt::CommitHook(cached_map_infos); }; api->v4.pltHookRegister = [](dev_t dev, ino_t inode, const char *symbol, void *fn, void **backup) { if (dev == 0 || inode == 0 || symbol == nullptr || fn == nullptr) return; @@ -383,7 +387,7 @@ void ZygiskContext::plt_hook_exclude(const char *regex, const char *symbol) { void ZygiskContext::plt_hook_process_regex() { if (register_info.empty()) return; - for (auto &map : lsplt::MapInfo::Scan()) { + for (auto &map : cached_map_infos) { if (map.offset != 0 || !map.is_private || !(map.perms & PROT_READ)) continue; for (auto ®: register_info) { if (regexec(®.regex, map.path.data(), 0, nullptr, 0) != 0) @@ -411,7 +415,7 @@ bool ZygiskContext::plt_hook_commit() { register_info.clear(); ignore_info.clear(); } - return lsplt::CommitHook(); + return lsplt::CommitHook(cached_map_infos); } @@ -719,8 +723,8 @@ ZygiskContext::~ZygiskContext() { } // namespace -static bool hook_commit() { - if (lsplt::CommitHook()) { +static bool hook_commit(std::vector &map_infos = cached_map_infos) { + if (lsplt::CommitHook(map_infos)) { return true; } else { LOGE("plt_hook failed"); @@ -752,23 +756,23 @@ void clean_trace(const char* path, bool spoof_maps) { LOGD("spoofing virtual maps for %s", path); // spoofing map names is futile in Android, we do it simply // to avoid Zygisk detections based on string comparison - for (auto &info : lsplt::MapInfo::Scan()) { - if (strstr(info.path.c_str(), path)) + for (auto &map : lsplt::MapInfo::Scan()) { + if (strstr(map.path.c_str(), path)) { - void *addr = (void *)info.start; - size_t size = info.end - info.start; + void *addr = (void *)map.start; + size_t size = map.end - map.start; void *copy = mmap(nullptr, size, PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); if (copy == MAP_FAILED) { - LOGE("failed to backup block %s [%p, %p]", info.path.c_str(), addr, (void*)info.end); + LOGE("failed to backup block %s [%p, %p]", map.path.c_str(), addr, (void*)map.end); continue; } - if ((info.perms & PROT_READ) == 0) { + if ((map.perms & PROT_READ) == 0) { mprotect(addr, size, PROT_READ); } memcpy(copy, addr, size); mremap(copy, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, addr); - mprotect(addr, size, info.perms); + mprotect(addr, size, map.perms); } } } @@ -783,7 +787,8 @@ void hook_functions() { // ino_t native_bridge_inode = 0; // dev_t native_bridge_dev = 0; - for (auto &map : lsplt::MapInfo::Scan()) { + cached_map_infos = lsplt::MapInfo::Scan(); + for (auto &map : cached_map_infos) { if (map.path.ends_with("libandroid_runtime.so")) { android_runtime_inode = map.inode; android_runtime_dev = map.dev; @@ -809,7 +814,7 @@ static void hook_unloader() { ino_t art_inode = 0; dev_t art_dev = 0; - for (auto &map : lsplt::MapInfo::Scan()) { + for (auto &map : cached_map_infos) { if (map.path.ends_with("/libart.so")) { art_inode = map.inode; art_dev = map.dev; @@ -817,6 +822,12 @@ static void hook_unloader() { } } + if (art_dev == 0 || art_inode == 0) { + LOGE("virtual map for libart.so is not cached"); + return; + } else { + LOGD("hook_unloader called with libart.so [%zu:%lu]", art_dev, art_inode); + } PLT_HOOK_REGISTER(art_dev, art_inode, pthread_attr_setstacksize); hook_commit(); } From 0671f2e497140e40071f67e67481541def4258bb Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Mon, 16 Dec 2024 10:08:09 +0100 Subject: [PATCH 17/46] improve: reset linker module counters Two counters for module loading and unloading are introduced in the commit https://cs.android.com/android/_/android/platform/bionic/+/a2e83ab34845759f0999d0ec88f4cdf558c0a9f5. To remove linker traces of libzygisk.so and Zygisk modules, we should reset them properly. --- loader/src/include/solist.hpp | 35 +++++++++++++++++++++++++++++----- loader/src/injector/entry.cpp | 2 +- loader/src/injector/hook.cpp | 17 +++++++++++------ loader/src/injector/module.hpp | 5 +++-- loader/src/injector/zygisk.hpp | 2 +- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/loader/src/include/solist.hpp b/loader/src/include/solist.hpp index 51a4f2e..f55d4b1 100644 --- a/loader/src/include/solist.hpp +++ b/loader/src/include/solist.hpp @@ -98,6 +98,9 @@ namespace SoList { static SoInfo *somain = NULL; static SoInfo **sonext = NULL; + static uint64_t *g_module_load_counter = NULL; + static uint64_t *g_module_unload_counter = NULL; + static bool Initialize(); template @@ -127,6 +130,27 @@ namespace SoList { return path_found; } + static void ResetCounters(size_t load, size_t unload) { + if (solist == NULL && !Initialize()) { + LOGE("Failed to initialize solist"); + return; + } + if (g_module_load_counter == NULL || g_module_unload_counter == NULL) { + LOGI("g_module counters not defined, skip reseting them"); + return; + } + auto loaded_modules = *g_module_load_counter; + auto unloaded_modules = *g_module_unload_counter; + if (loaded_modules >= load) { + *g_module_load_counter = loaded_modules - load; + LOGD("reset g_module_load_counter to %zu", (size_t) *g_module_load_counter); + } + if (unloaded_modules >= unload) { + *g_module_unload_counter = unloaded_modules - unload; + LOGD("reset g_module_unload_counter to %zu", (size_t) *g_module_unload_counter); + } + } + static bool Initialize() { SandHook::ElfImg linker("/linker"); if (!ProtectedDataGuard::setup(linker)) return false; @@ -179,11 +203,7 @@ namespace SoList { LOGD("found symbol sonext"); SoInfo *vdso = getStaticPointer(linker, vdso_sym_name); - if (vdso != NULL) { - LOGD("found symbol vdso"); - } else { - LOGD("symbol vdso is missing"); - } + if (vdso != NULL) LOGD("found symbol vdso"); SoInfo::get_realpath_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo12get_realpathEv")); if (SoInfo::get_realpath_sym == NULL) return false; @@ -197,6 +217,11 @@ namespace SoList { if (SoInfo::soinfo_free == NULL) return false; LOGD("found symbol soinfo_free"); + g_module_load_counter = reinterpret_cast(linker.getSymbAddress("__dl__ZL21g_module_load_counter")); + if (g_module_load_counter != NULL) LOGD("found symbol g_module_load_counter"); + + g_module_unload_counter = reinterpret_cast(linker.getSymbAddress("__dl__ZL23g_module_unload_counter")); + if (g_module_unload_counter != NULL) LOGD("found symbol g_module_unload_counter"); for (size_t i = 0; i < 1024 / sizeof(void *); i++) { auto possible_field = (uintptr_t) solist + i * sizeof(void *); diff --git a/loader/src/injector/entry.cpp b/loader/src/injector/entry.cpp index 36409aa..a927042 100644 --- a/loader/src/injector/entry.cpp +++ b/loader/src/injector/entry.cpp @@ -25,5 +25,5 @@ void entry(void* addr, size_t size, const char* path) { LOGI("start plt hooking"); hook_functions(); - clean_trace(path); + clean_trace(path, 1, 0, false); } diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index ef0ad6a..ae41b6a 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -578,16 +578,21 @@ void ZygiskContext::run_modules_pre() { void ZygiskContext::run_modules_post() { flags[POST_SPECIALIZE] = true; + + size_t modules_unloaded = 0; for (const auto &m : modules) { if (flags[APP_SPECIALIZE]) { m.postAppSpecialize(args.app); } else if (flags[SERVER_FORK_AND_SPECIALIZE]) { m.postServerSpecialize(args.server); } - m.tryUnload(); + if (m.tryUnload()) modules_unloaded++; } - clean_trace("jit-cache-zygisk", true); + if (modules.size() > 0) { + LOGD("modules unloaded: %zu/%zu", modules_unloaded, modules.size()); + clean_trace("jit-cache-zygisk", modules.size(), modules_unloaded, true); + } } /* Zygisksu changed: Load module fds */ @@ -746,12 +751,12 @@ static void hook_register(dev_t dev, ino_t inode, const char *symbol, void *new_ #define PLT_HOOK_REGISTER(DEV, INODE, NAME) \ PLT_HOOK_REGISTER_SYM(DEV, INODE, #NAME, NAME) -void clean_trace(const char* path, bool spoof_maps) { +void clean_trace(const char* path, size_t load, size_t unload, bool spoof_maps) { LOGD("cleaning trace for path %s", path); - if (!SoList::DropSoPath(path) || !spoof_maps) { - return; - } + if (load > 0 || unload >0) SoList::ResetCounters(load, unload); + bool path_found = SoList::DropSoPath(path); + if (!path_found || !spoof_maps) return; LOGD("spoofing virtual maps for %s", path); // spoofing map names is futile in Android, we do it simply diff --git a/loader/src/injector/module.hpp b/loader/src/injector/module.hpp index dfbde57..24111fc 100644 --- a/loader/src/injector/module.hpp +++ b/loader/src/injector/module.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include "api.hpp" @@ -209,7 +210,7 @@ case 5: \ int getModuleDir() const; void setOption(zygisk::Option opt); static uint32_t getFlags(); - void tryUnload() const { if (unload) dlclose(handle); } + bool tryUnload() const { return unload && dlclose(handle) == 0; }; void clearApi() { memset(&api, 0, sizeof(api)); } int getId() const { return id; } @@ -235,4 +236,4 @@ case 5: \ } mod; }; -} // namespace \ No newline at end of file +} // namespace diff --git a/loader/src/injector/zygisk.hpp b/loader/src/injector/zygisk.hpp index 744755e..793ba78 100644 --- a/loader/src/injector/zygisk.hpp +++ b/loader/src/injector/zygisk.hpp @@ -7,7 +7,7 @@ extern size_t block_size; void hook_functions(); -void clean_trace(const char* path, bool spoof_maps = false); +void clean_trace(const char* path, size_t load = 1, size_t unload = 0, bool spoof_maps = false); void revert_unmount_ksu(); From 95073d9f4a61317295309f24e1843f6b9605ef66 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Wed, 18 Dec 2024 13:07:06 -0300 Subject: [PATCH 18/46] fix: checking `malloc` against non `NULL` not `NULL` This commit fixes an issue where one of the "malloc", a libc function to allocate dynamic memory, "if"s were checking its return against non-NULL instead of NULL, making it seem to have failed when it didn't. --- loader/src/ptracer/monitor.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/loader/src/ptracer/monitor.cpp b/loader/src/ptracer/monitor.cpp index 36f4bdc..af7f28c 100644 --- a/loader/src/ptracer/monitor.cpp +++ b/loader/src/ptracer/monitor.cpp @@ -270,13 +270,13 @@ struct SocketHandler : public EventHandler { LOGD("received daemon64 info %s", msg->data); /* Will only happen if somehow the daemon restarts */ - if (status64.daemon_info != NULL) { + if (status64.daemon_info) { free(status64.daemon_info); status64.daemon_info = NULL; } status64.daemon_info = (char *)malloc(msg->length); - if (status64.daemon_info == NULL) { + if (!status64.daemon_info) { PLOGE("malloc daemon64 info"); break; @@ -291,13 +291,13 @@ struct SocketHandler : public EventHandler { case DAEMON32_SET_INFO: { LOGD("received daemon32 info %s", msg->data); - if (status32.daemon_info != NULL) { + if (status32.daemon_info) { free(status32.daemon_info); status32.daemon_info = NULL; } status32.daemon_info = (char *)malloc(msg->length); - if (status32.daemon_info == NULL) { + if (!status32.daemon_info) { PLOGE("malloc daemon32 info"); break; @@ -314,13 +314,13 @@ struct SocketHandler : public EventHandler { status64.daemon_running = false; - if (status64.daemon_error_info != NULL) { + if (status64.daemon_error_info) { free(status64.daemon_error_info); status64.daemon_error_info = NULL; } status64.daemon_error_info = (char *)malloc(msg->length); - if (status64.daemon_error_info == NULL) { + if (!status64.daemon_error_info) { PLOGE("malloc daemon64 error info"); break; @@ -337,13 +337,13 @@ struct SocketHandler : public EventHandler { status32.daemon_running = false; - if (status32.daemon_error_info != NULL) { + if (status32.daemon_error_info) { free(status32.daemon_error_info); status32.daemon_error_info = NULL; } status32.daemon_error_info = (char *)malloc(msg->length); - if (status32.daemon_error_info == NULL) { + if (!status32.daemon_error_info) { PLOGE("malloc daemon32 error info"); break; @@ -447,7 +447,7 @@ static bool ensure_daemon_created(bool is_64bit) { \ if (!status##abi.daemon_error_info) { \ status##abi.daemon_error_info = (char *)malloc(strlen(status_str) + 1); \ - if (status##abi.daemon_error_info) { \ + if (!status##abi.daemon_error_info) { \ LOGE("malloc daemon" #abi " error info failed"); \ \ return; \ @@ -800,10 +800,10 @@ void init_monitor() { looper.RegisterHandler(ptraceHandler, EPOLLIN | EPOLLET); looper.Loop(); - if (status64.daemon_info != NULL) free(status64.daemon_info); - if (status64.daemon_error_info != NULL) free(status64.daemon_error_info); - if (status32.daemon_info != NULL) free(status32.daemon_info); - if (status32.daemon_error_info != NULL) free(status32.daemon_error_info); + if (status64.daemon_info) free(status64.daemon_info); + if (status64.daemon_error_info) free(status64.daemon_error_info); + if (status32.daemon_info) free(status32.daemon_info); + if (status32.daemon_error_info) free(status32.daemon_error_info); LOGI("exit"); } From 6b0b71a690a47a6720faaf885e085618fed1af3d Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Sat, 21 Dec 2024 16:46:36 -0300 Subject: [PATCH 19/46] fix: Zygiskd remote read types This commit fixes the mismatch between types sent by lizygisk.so and read by Zygiskd, causing issues. --- zygiskd/build.gradle.kts | 2 +- zygiskd/src/companion.c | 42 ++++++++++++++++++++++++++------ zygiskd/src/constants.h | 18 +++++++------- zygiskd/src/root_impl/apatch.c | 2 +- zygiskd/src/root_impl/kernelsu.c | 6 ++--- zygiskd/src/utils.c | 5 +--- zygiskd/src/utils.h | 3 --- zygiskd/src/zygiskd.c | 37 ++++++++++++++-------------- 8 files changed, 68 insertions(+), 47 deletions(-) diff --git a/zygiskd/build.gradle.kts b/zygiskd/build.gradle.kts index 033cb8a..b830189 100644 --- a/zygiskd/build.gradle.kts +++ b/zygiskd/build.gradle.kts @@ -29,7 +29,7 @@ val commitHash: String by rootProject.extra val CStandardFlags = arrayOf( "-D_GNU_SOURCE", "-std=c99", "-Wpedantic", "-Wall", "-Wextra", "-Werror", "-Wformat", "-Wuninitialized", "-Wshadow", "-Wno-zero-length-array", - "-Wno-fixed-enum-extension", "-Iroot_impl", "-llog", + "-Wconversion", "-Wno-fixed-enum-extension", "-Iroot_impl", "-llog", "-DMIN_APATCH_VERSION=$minAPatchVersion", "-DMIN_KSU_VERSION=$minKsuVersion", "-DMAX_KSU_VERSION=$maxKsuVersion", diff --git a/zygiskd/src/companion.c b/zygiskd/src/companion.c index 486b6fa..ee54945 100644 --- a/zygiskd/src/companion.c +++ b/zygiskd/src/companion.c @@ -31,8 +31,7 @@ zygisk_companion_entry_func load_module(int fd) { void *handle = android_dlopen(path, RTLD_NOW); void *entry = dlsym(handle, "zygisk_companion_entry"); - if (entry == NULL) return NULL; - + return (zygisk_companion_entry_func)entry; } @@ -42,12 +41,37 @@ void *entry_thread(void *arg) { int fd = args->fd; zygisk_companion_entry_func module_entry = args->entry; + struct stat st0; + if (fstat(fd, &st0) == -1) { + LOGE("Failed to get client fd stats\n"); + + close(fd); + free(args); + + pthread_exit(NULL); + } + module_entry(fd); - close(fd); + struct stat st1; + if (fstat(fd, &st1) == -1) { + LOGE("Failed to get client fd stats\n"); + + close(fd); + free(args); + + pthread_exit(NULL); + } + + if (st0.st_dev != st1.st_dev || st0.st_ino != st1.st_ino) { + LOGI("Client fd changed. Closing.\n"); + + close(fd); + } + free(args); - pthread_exit(NULL); + return NULL; } /* WARNING: Dynamic memory based */ @@ -67,7 +91,7 @@ void companion_entry(int fd) { } name[name_length] = '\0'; - LOGI(" - Module name: `%.*s`\n", (int)name_length, name); + LOGI(" - Module name: \"%s\"\n", name); int library_fd = read_fd(fd); ssize_t ret = 0; @@ -86,7 +110,7 @@ void companion_entry(int fd) { close(library_fd); if (module_entry == NULL) { - LOGI("No companion module entry for module: %.*s\n", (int)name_length, name); + LOGE("No companion module entry for module: %s\n", name); ret = write_uint8_t(fd, 0); ASSURE_SIZE_WRITE("ZygiskdCompanion", "module_entry", ret, sizeof(uint8_t)); @@ -99,7 +123,7 @@ void companion_entry(int fd) { while (1) { if (!check_unix_socket(fd, true)) { - LOGI("Something went wrong in companion. Bye!\n"); + LOGE("Something went wrong in companion. Bye!\n"); exit(0); @@ -117,13 +141,15 @@ void companion_entry(int fd) { if (args == NULL) { LOGE("Failed to allocate memory for thread args\n"); + close(client_fd); + exit(0); } args->fd = client_fd; args->entry = module_entry; - LOGI("New companion request.\n - Module name: %.*s\n - Client fd: %d\n", (int)name_length, name, args->fd); + LOGI("New companion request.\n - Module name: %s\n - Client fd: %d\n", name, args->fd); ret = write_uint8_t(args->fd, 1); ASSURE_SIZE_WRITE("ZygiskdCompanion", "client_fd", ret, sizeof(uint8_t)); diff --git a/zygiskd/src/constants.h b/zygiskd/src/constants.h index 55f8a56..8342ebb 100644 --- a/zygiskd/src/constants.h +++ b/zygiskd/src/constants.h @@ -25,15 +25,15 @@ #define SYSTEM_SERVER_STARTED 10 enum DaemonSocketAction { - PingHeartbeat, - RequestLogcatFd, - GetProcessFlags, - GetInfo, - ReadModules, - RequestCompanionSocket, - GetModuleDir, - ZygoteRestart, - SystemServerStarted + PingHeartbeat = 0, + RequestLogcatFd = 1, + GetProcessFlags = 2, + GetInfo = 3, + ReadModules = 4, + RequestCompanionSocket = 5, + GetModuleDir = 6, + ZygoteRestart = 7, + SystemServerStarted = 8 }; enum ProcessFlags: uint32_t { diff --git a/zygiskd/src/root_impl/apatch.c b/zygiskd/src/root_impl/apatch.c index fadac60..f899038 100644 --- a/zygiskd/src/root_impl/apatch.c +++ b/zygiskd/src/root_impl/apatch.c @@ -115,7 +115,7 @@ bool _apatch_get_package_config(struct packages_config *restrict config) { char *uid_str = strtok(NULL, ","); if (uid_str == NULL) continue; - config->configs[config->size].uid = atoi(uid_str); + config->configs[config->size].uid = (uid_t)atoi(uid_str); config->configs[config->size].root_granted = strcmp(allow_str, "1") == 0; config->configs[config->size].umount_needed = strcmp(exclude_str, "1") == 0; diff --git a/zygiskd/src/root_impl/kernelsu.c b/zygiskd/src/root_impl/kernelsu.c index 775b1c6..f9f0968 100644 --- a/zygiskd/src/root_impl/kernelsu.c +++ b/zygiskd/src/root_impl/kernelsu.c @@ -14,7 +14,7 @@ so we need to cast it to signed int to avoid any potential UB. */ -#define KERNEL_SU_OPTION 0xdeadbeef +#define KERNEL_SU_OPTION (int)0xdeadbeef #define CMD_GET_VERSION 2 #define CMD_UID_GRANTED_ROOT 12 @@ -52,7 +52,7 @@ bool ksu_uid_granted_root(uid_t uid) { bool granted = false; prctl(KERNEL_SU_OPTION, CMD_UID_GRANTED_ROOT, uid, &granted, &result); - if (result != KERNEL_SU_OPTION) return false; + if ((int)result != KERNEL_SU_OPTION) return false; return granted; } @@ -62,7 +62,7 @@ bool ksu_uid_should_umount(uid_t uid) { bool umount = false; prctl(KERNEL_SU_OPTION, CMD_UID_SHOULD_UMOUNT, uid, &umount, &result); - if (result != KERNEL_SU_OPTION) return false; + if ((int)result != KERNEL_SU_OPTION) return false; return umount; } diff --git a/zygiskd/src/utils.c b/zygiskd/src/utils.c index 88314b9..2285844 100644 --- a/zygiskd/src/utils.c +++ b/zygiskd/src/utils.c @@ -272,9 +272,6 @@ int read_fd(int fd) { return read(fd, val, sizeof(type)); \ } -write_func(int) -read_func(int) - write_func(size_t) read_func(size_t) @@ -365,7 +362,7 @@ bool exec_command(char *restrict buf, size_t len, const char *restrict file, cha } else { close(link[1]); - int nbytes = read(link[0], buf, len); + ssize_t nbytes = read(link[0], buf, len); if (nbytes > 0) buf[nbytes - 1] = '\0'; /* INFO: If something went wrong, at least we must ensure it is NULL-terminated */ else buf[0] = '\0'; diff --git a/zygiskd/src/utils.h b/zygiskd/src/utils.h index c7f7a99..f5f6372 100644 --- a/zygiskd/src/utils.h +++ b/zygiskd/src/utils.h @@ -80,9 +80,6 @@ int unix_listener_from_path(char *path); ssize_t write_fd(int fd, int sendfd); int read_fd(int fd); -write_func_def(int); -read_func_def(int); - write_func_def(size_t); read_func_def(size_t); diff --git a/zygiskd/src/zygiskd.c b/zygiskd/src/zygiskd.c index dcb88d8..702bf90 100644 --- a/zygiskd/src/zygiskd.c +++ b/zygiskd/src/zygiskd.c @@ -30,7 +30,7 @@ struct Module { struct Context { struct Module *modules; - int len; + size_t len; }; enum Architecture { @@ -85,14 +85,14 @@ int create_library_fd(const char *restrict so_path) { /* INFO: This is required as older implementations of glibc may not have the memfd_create function call, causing a crash. */ - int memfd = syscall(SYS_memfd_create, "jit-cache-zygisk", MFD_ALLOW_SEALING); + int memfd = (int)syscall(SYS_memfd_create, "jit-cache-zygisk", MFD_ALLOW_SEALING); if (memfd == -1) { LOGE("Failed creating memfd: %s\n", strerror(errno)); return -1; } - if (sendfile(memfd, so_fd, NULL, so_size) == -1) { + if (sendfile(memfd, so_fd, NULL, (size_t)so_size) == -1) { LOGE("Failed copying so file to memfd: %s\n", strerror(errno)); close(so_fd); @@ -174,7 +174,7 @@ static void load_modules(enum Architecture arch, struct Context *restrict contex } - context->modules = realloc(context->modules, ((context->len + 1) * sizeof(struct Module))); + context->modules = realloc(context->modules, (size_t)((context->len + 1) * sizeof(struct Module))); if (context->modules == NULL) { LOGE("Failed reallocating memory for modules.\n"); @@ -189,7 +189,7 @@ static void load_modules(enum Architecture arch, struct Context *restrict contex } static void free_modules(struct Context *restrict context) { - for (int i = 0; i < context->len; i++) { + for (size_t i = 0; i < context->len; i++) { free(context->modules[i].name); if (context->modules[i].companion != -1) close(context->modules[i].companion); } @@ -344,7 +344,7 @@ void zygiskd_start(char *restrict argv[]) { msg->length = sprintf(msg->data, "Unsupported environment: Multiple root implementations found"); } - unix_datagram_sendto(CONTROLLER_SOCKET, (void *)msg, sizeof(struct MsgHead) + msg->length); + unix_datagram_sendto(CONTROLLER_SOCKET, (void *)msg, (size_t)((int)sizeof(struct MsgHead) + msg->length)); free(msg); } else { @@ -357,7 +357,7 @@ void zygiskd_start(char *restrict argv[]) { module_list = strdup("None"); module_list_len = strlen("None"); } else { - for (int i = 0; i < context.len; i++) { + for (size_t i = 0; i < context.len; i++) { if (i != context.len - 1) { module_list = realloc(module_list, module_list_len + strlen(context.modules[i].name) + strlen(", ") + 1); if (module_list == NULL) { @@ -397,7 +397,7 @@ void zygiskd_start(char *restrict argv[]) { msg->length = snprintf(msg->data, msg_length, "Root: %s, Modules: %s", impl_name, module_list) + 1; msg->cmd = DAEMON_SET_INFO; - unix_datagram_sendto(CONTROLLER_SOCKET, (void *)msg, sizeof(struct MsgHead) + msg->length); + unix_datagram_sendto(CONTROLLER_SOCKET, (void *)msg, (size_t)((int)sizeof(struct MsgHead) + msg->length)); free(msg); free(module_list); @@ -440,7 +440,7 @@ void zygiskd_start(char *restrict argv[]) { break; } case ZygoteRestart: { - for (int i = 0; i < context.len; i++) { + for (size_t i = 0; i < context.len; i++) { if (context.modules[i].companion != -1) { close(context.modules[i].companion); context.modules[i].companion = -1; @@ -534,7 +534,7 @@ void zygiskd_start(char *restrict argv[]) { } } - ret = write_int(client_fd, flags); + ret = write_uint32_t(client_fd, flags); ASSURE_SIZE_WRITE_BREAK("GetProcessFlags", "flags", ret, sizeof(flags)); break; @@ -562,10 +562,11 @@ void zygiskd_start(char *restrict argv[]) { } } - ssize_t ret = write_size_t(client_fd, flags); + ssize_t ret = write_uint32_t(client_fd, flags); ASSURE_SIZE_WRITE_BREAK("GetInfo", "flags", ret, sizeof(flags)); - uint32_t pid = getpid(); + /* TODO: Use pid_t */ + uint32_t pid = (uint32_t)getpid(); ret = write_uint32_t(client_fd, pid); ASSURE_SIZE_WRITE_BREAK("GetInfo", "pid", ret, sizeof(pid)); @@ -612,10 +613,8 @@ void zygiskd_start(char *restrict argv[]) { struct Module *module = &context.modules[index]; if (module->companion != -1) { - LOGI(" - Polling companion for module \"%s\"\n", module->name); - if (!check_unix_socket(module->companion, false)) { - LOGE(" - Poll companion for module \"%s\" crashed\n", module->name); + LOGE(" - Companion for module \"%s\" crashed\n", module->name); close(module->companion); module->companion = -1; @@ -626,7 +625,7 @@ void zygiskd_start(char *restrict argv[]) { module->companion = spawn_companion(argv, module->name, module->lib_fd); if (module->companion > 0) { - LOGI(" - Spawned companion for \"%s\"\n", module->name); + LOGI(" - Spawned companion for \"%s\": %d\n", module->name, module->companion); } else { if (module->companion == -2) { LOGE(" - No companion spawned for \"%s\" because it has no entry.\n", module->name); @@ -654,14 +653,16 @@ void zygiskd_start(char *restrict argv[]) { close(module->companion); module->companion = -1; - /* INFO: RequestCompanionSocket by defailt doesn't close the client_fd */ + /* INFO: RequestCompanionSocket by default doesn't close the client_fd */ close(client_fd); } } else { + LOGE(" - Failed to spawn companion for module \"%s\"\n", module->name); + ret = write_uint8_t(client_fd, 0); ASSURE_SIZE_WRITE_BREAK("RequestCompanionSocket", "response", ret, sizeof(int)); - /* INFO: RequestCompanionSocket by defailt doesn't close the client_fd */ + /* INFO: RequestCompanionSocket by default doesn't close the client_fd */ close(client_fd); } From 7a892e0d62f0dea4e484ccc673b48f4ce9b05d12 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Sun, 22 Dec 2024 14:57:39 -0300 Subject: [PATCH 20/46] improve: `companion.c`, `dl.c` and `utils.c` code This commit improves the code for multiple files by making "read_string" function already make the string NULL-terminated, avoiding code duplication. Also for "companion.c" fixes an "if" where it would read "client_fd" and check if "fd" is equal to "-1", instead of "client_fd", also does some overall code improvements there like detaching the thread, avoiding memory leaks in the exit, of the thread itself. --- zygiskd/src/companion.c | 79 ++++++++++++++++++++--------------------- zygiskd/src/dl.c | 7 ++-- zygiskd/src/utils.c | 27 +++++++------- zygiskd/src/utils.h | 2 +- zygiskd/src/zygiskd.c | 11 +++--- 5 files changed, 59 insertions(+), 67 deletions(-) diff --git a/zygiskd/src/companion.c b/zygiskd/src/companion.c index ee54945..0646a77 100644 --- a/zygiskd/src/companion.c +++ b/zygiskd/src/companion.c @@ -14,59 +14,56 @@ #include -#include "companion.h" #include "dl.h" #include "utils.h" -typedef void (*zygisk_companion_entry_func)(int); +typedef void (*zygisk_companion_entry)(int); struct companion_module_thread_args { int fd; - zygisk_companion_entry_func entry; + zygisk_companion_entry entry; }; -zygisk_companion_entry_func load_module(int fd) { +zygisk_companion_entry load_module(int fd) { char path[PATH_MAX]; snprintf(path, sizeof(path), "/proc/self/fd/%d", fd); void *handle = android_dlopen(path, RTLD_NOW); void *entry = dlsym(handle, "zygisk_companion_entry"); - - return (zygisk_companion_entry_func)entry; + + return (zygisk_companion_entry)entry; } void *entry_thread(void *arg) { struct companion_module_thread_args *args = (struct companion_module_thread_args *)arg; int fd = args->fd; - zygisk_companion_entry_func module_entry = args->entry; + zygisk_companion_entry module_entry = args->entry; - struct stat st0; + struct stat st0 = { 0 }; if (fstat(fd, &st0) == -1) { - LOGE("Failed to get client fd stats\n"); + LOGE("Failed to get initial client fd stats: %s\n", strerror(errno)); - close(fd); free(args); - pthread_exit(NULL); + return NULL; } module_entry(fd); + /* INFO: Only attempt to close the client fd if it appears to be the same file + and if we can successfully stat it again. This prevents double closes + if the module companion already closed the fd. + */ struct stat st1; - if (fstat(fd, &st1) == -1) { - LOGE("Failed to get client fd stats\n"); + if (fstat(fd, &st1) == 0) { + if (st0.st_dev == st1.st_dev && st0.st_ino == st1.st_ino) { + LOGI("Client fd stats unchanged. Closing.\n"); - close(fd); - free(args); - - pthread_exit(NULL); - } - - if (st0.st_dev != st1.st_dev || st0.st_ino != st1.st_ino) { - LOGI("Client fd changed. Closing.\n"); - - close(fd); + close(fd); + } else { + LOGI("Client fd stats changed, assuming module handled closing.\n"); + } } free(args); @@ -78,45 +75,44 @@ void *entry_thread(void *arg) { void companion_entry(int fd) { LOGI("New companion entry.\n - Client fd: %d\n", fd); - /* TODO: Use non-NULL string termination */ char name[256 + 1]; - ssize_t name_length = read_string(fd, name, sizeof(name) - 1); - if (name_length == -1) { + ssize_t ret = read_string(fd, name, sizeof(name)); + if (ret == -1) { LOGE("Failed to read module name\n"); - ssize_t ret = write_uint8_t(fd, 2); - ASSURE_SIZE_WRITE("ZygiskdCompanion", "name", ret, sizeof(uint8_t)); + /* TODO: Is that appropriate? */ + close(fd); exit(0); } - name[name_length] = '\0'; LOGI(" - Module name: \"%s\"\n", name); int library_fd = read_fd(fd); - ssize_t ret = 0; if (library_fd == -1) { LOGE("Failed to receive library fd\n"); - ret = write_uint8_t(fd, 2); - ASSURE_SIZE_WRITE("ZygiskdCompanion", "library_fd", ret, sizeof(uint8_t)); + /* TODO: Is that appropriate? */ + close(fd); exit(0); } LOGI(" - Library fd: %d\n", library_fd); - zygisk_companion_entry_func module_entry = load_module(library_fd); + zygisk_companion_entry module_entry = load_module(library_fd); close(library_fd); if (module_entry == NULL) { - LOGE("No companion module entry for module: %s\n", name); + LOGE(" - No companion module entry for module: %s\n", name); ret = write_uint8_t(fd, 0); ASSURE_SIZE_WRITE("ZygiskdCompanion", "module_entry", ret, sizeof(uint8_t)); exit(0); } else { + LOGI(" - Module entry found\n"); + ret = write_uint8_t(fd, 1); ASSURE_SIZE_WRITE("ZygiskdCompanion", "module_entry", ret, sizeof(uint8_t)); } @@ -126,12 +122,10 @@ void companion_entry(int fd) { LOGE("Something went wrong in companion. Bye!\n"); exit(0); - - break; } - + int client_fd = read_fd(fd); - if (fd == -1) { + if (client_fd == -1) { LOGE("Failed to receive client fd\n"); exit(0); @@ -149,12 +143,15 @@ void companion_entry(int fd) { args->fd = client_fd; args->entry = module_entry; - LOGI("New companion request.\n - Module name: %s\n - Client fd: %d\n", name, args->fd); + LOGI("New companion request.\n - Module name: %s\n - Client fd: %d\n", name, client_fd); - ret = write_uint8_t(args->fd, 1); + ret = write_uint8_t(client_fd, 1); ASSURE_SIZE_WRITE("ZygiskdCompanion", "client_fd", ret, sizeof(uint8_t)); - + pthread_t thread; pthread_create(&thread, NULL, entry_thread, args); + pthread_detach(thread); + + LOGI(" - Spawned companion thread for client fd: %d\n", client_fd); } } diff --git a/zygiskd/src/dl.c b/zygiskd/src/dl.c index 5018b0f..26770da 100644 --- a/zygiskd/src/dl.c +++ b/zygiskd/src/dl.c @@ -13,14 +13,13 @@ #include #include "companion.h" -#include "dl.h" #include "utils.h" #define ANDROID_NAMESPACE_TYPE_SHARED 0x2 #define ANDROID_DLEXT_USE_NAMESPACE 0x200 typedef struct AndroidNamespace { - unsigned char _unused[0]; + uint8_t _unused[0]; } AndroidNamespace; typedef struct AndroidDlextinfo { @@ -33,6 +32,8 @@ typedef struct AndroidDlextinfo { AndroidNamespace *library_namespace; } AndroidDlextinfo; +extern void *android_dlopen_ext(const char *filename, int flags, const AndroidDlextinfo *extinfo); + typedef AndroidNamespace *(*AndroidCreateNamespaceFn)( const char *name, const char *ld_library_path, @@ -43,8 +44,6 @@ typedef AndroidNamespace *(*AndroidCreateNamespaceFn)( const void *caller_addr ); -extern void *android_dlopen_ext(const char *filename, int flags, const AndroidDlextinfo *extinfo); - void *android_dlopen(char *path, int flags) { char *dir = dirname(path); struct AndroidDlextinfo info = { diff --git a/zygiskd/src/utils.c b/zygiskd/src/utils.c index 2285844..eff45d9 100644 --- a/zygiskd/src/utils.c +++ b/zygiskd/src/utils.c @@ -282,18 +282,16 @@ write_func(uint8_t) read_func(uint8_t) ssize_t write_string(int fd, const char *restrict str) { - size_t len[1]; - len[0] = strlen(str); - - ssize_t written_bytes = write(fd, &len, sizeof(size_t)); + size_t str_len = strlen(str); + ssize_t written_bytes = write(fd, &str_len, sizeof(size_t)); if (written_bytes != sizeof(size_t)) { LOGE("Failed to write string length: Not all bytes were written (%zd != %zu).\n", written_bytes, sizeof(size_t)); return -1; } - written_bytes = write(fd, str, len[0]); - if ((size_t)written_bytes != len[0]) { + written_bytes = write(fd, str, str_len); + if ((size_t)written_bytes != str_len) { LOGE("Failed to write string: Not all bytes were written.\n"); return -1; @@ -302,31 +300,30 @@ ssize_t write_string(int fd, const char *restrict str) { return written_bytes; } -ssize_t read_string(int fd, char *restrict str, size_t len) { - size_t str_len_buf[1]; - - ssize_t read_bytes = read(fd, &str_len_buf, sizeof(size_t)); +ssize_t read_string(int fd, char *restrict buf, size_t buf_size) { + size_t str_len = 0; + ssize_t read_bytes = read(fd, &str_len, sizeof(size_t)); if (read_bytes != (ssize_t)sizeof(size_t)) { LOGE("Failed to read string length: Not all bytes were read (%zd != %zu).\n", read_bytes, sizeof(size_t)); return -1; } - size_t str_len = str_len_buf[0]; - - if (str_len > len) { - LOGE("Failed to read string: Buffer is too small (%zu > %zu).\n", str_len, len); + if (str_len > buf_size - 1) { + LOGE("Failed to read string: Buffer is too small (%zu > %zu - 1).\n", str_len, buf_size); return -1; } - read_bytes = read(fd, str, str_len); + read_bytes = read(fd, buf, str_len); if (read_bytes != (ssize_t)str_len) { LOGE("Failed to read string: Promised bytes doesn't exist (%zd != %zu).\n", read_bytes, str_len); return -1; } + if (str_len > 0) buf[str_len] = '\0'; + return read_bytes; } diff --git a/zygiskd/src/utils.h b/zygiskd/src/utils.h index f5f6372..f9655f8 100644 --- a/zygiskd/src/utils.h +++ b/zygiskd/src/utils.h @@ -91,7 +91,7 @@ read_func_def(uint8_t); ssize_t write_string(int fd, const char *restrict str); -ssize_t read_string(int fd, char *restrict str, size_t len); +ssize_t read_string(int fd, char *restrict buf, size_t buf_size); bool exec_command(char *restrict buf, size_t len, const char *restrict file, char *const argv[]); diff --git a/zygiskd/src/zygiskd.c b/zygiskd/src/zygiskd.c index 702bf90..6031955 100644 --- a/zygiskd/src/zygiskd.c +++ b/zygiskd/src/zygiskd.c @@ -465,13 +465,15 @@ void zygiskd_start(char *restrict argv[]) { break; } + /* TODO: Move to another thread and save client fds to an epoll list + so that we can, in a single-thread, deal with multiple logcats */ case RequestLogcatFd: { uint8_t level = 0; ssize_t ret = read_uint8_t(client_fd, &level); ASSURE_SIZE_READ_BREAK("RequestLogcatFd", "level", ret, sizeof(level)); char tag[128 + 1]; - ret = read_string(client_fd, tag, sizeof(tag) - 1); + ret = read_string(client_fd, tag, sizeof(tag)); if (ret == -1) { LOGE("Failed reading logcat tag.\n"); @@ -480,10 +482,7 @@ void zygiskd_start(char *restrict argv[]) { break; } - tag[ret] = '\0'; - - /* INFO: Non-NULL terminated */ - char message[1024]; + char message[1024 + 1]; ret = read_string(client_fd, message, sizeof(message)); if (ret == -1) { LOGE("Failed reading logcat message.\n"); @@ -493,7 +492,7 @@ void zygiskd_start(char *restrict argv[]) { break; } - __android_log_print(level, tag, "%.*s", (int)ret, message); + __android_log_print(level, tag, "%s", message); break; } From b0a296fc294a8f9606291ca3cec6cc21ac6531c5 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Tue, 24 Dec 2024 16:56:49 -0300 Subject: [PATCH 21/46] add: support for magic mount in KSU and APatch This commit allows ReZygisk to u(n)mount mounted paths in KSU and APatch environments using magic mount. --- loader/src/injector/unmount.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/loader/src/injector/unmount.cpp b/loader/src/injector/unmount.cpp index 1e0dd56..a657467 100644 --- a/loader/src/injector/unmount.cpp +++ b/loader/src/injector/unmount.cpp @@ -37,21 +37,30 @@ void revert_unmount_ksu() { ksu_loop = info.source; continue; } + // Unmount everything mounted to /data/adb if (info.target.starts_with("/data/adb")) { targets.emplace_back(info.target); } + + // Unmount everything mounted to /data/adb + if (info.root.starts_with("/adb/modules")) { + targets.emplace_back(info.target); + } + // Unmount ksu overlays if (info.type == "overlay" && info.source == KSU_OVERLAY_SOURCE && std::find(DEVICE_PARTITIONS.begin(), DEVICE_PARTITIONS.end(), info.target) != DEVICE_PARTITIONS.end()) { targets.emplace_back(info.target); } + // Unmount temp dir if (info.type == "tmpfs" && info.source == KSU_OVERLAY_SOURCE) { targets.emplace_back(info.target); } } + for (auto& info: parse_mount_info("self")) { // Unmount everything from ksu loop except ksu module dir if (info.source == ksu_loop && info.target != MODULE_DIR) { @@ -98,21 +107,30 @@ void revert_unmount_apatch() { ap_loop = info.source; continue; } + // Unmount everything mounted to /data/adb if (info.target.starts_with("/data/adb")) { targets.emplace_back(info.target); } + + // Unmount everything mounted to /data/adb + if (info.root.starts_with("/adb/modules")) { + targets.emplace_back(info.target); + } + // Unmount ksu overlays if (info.type == "overlay" && info.source == AP_OVERLAY_SOURCE && std::find(DEVICE_PARTITIONS.begin(), DEVICE_PARTITIONS.end(), info.target) != DEVICE_PARTITIONS.end()) { targets.emplace_back(info.target); } + // Unmount temp dir if (info.type == "tmpfs" && info.source == AP_OVERLAY_SOURCE) { targets.emplace_back(info.target); } } + for (auto& info: parse_mount_info("self")) { // Unmount everything from ksu loop except ksu module dir if (info.source == ap_loop && info.target != MODULE_DIR) { From 3605857d84a971e6a7e4d5bb349f13b4d53dfc00 Mon Sep 17 00:00:00 2001 From: "Pedro.js" Date: Sat, 28 Dec 2024 19:09:05 -0300 Subject: [PATCH 22/46] improve: companion handler fd closing; fix: PIPE signal handling (#103) This commit improves how we decide to close the fd that connects the injected module with the companion, avoiding both double close and fd leaks. --- zygiskd/src/.gitignore | 2 - zygiskd/src/companion.c | 71 +++++++++++++++++++++++------------ zygiskd/src/dl.c | 82 +++++++++++++---------------------------- zygiskd/src/dl.h | 2 +- zygiskd/src/utils.c | 10 ++--- zygiskd/src/utils.h | 14 +++++-- 6 files changed, 89 insertions(+), 92 deletions(-) delete mode 100644 zygiskd/src/.gitignore diff --git a/zygiskd/src/.gitignore b/zygiskd/src/.gitignore deleted file mode 100644 index 8f961c3..0000000 --- a/zygiskd/src/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -zygiskd64 -zygiskd32 \ No newline at end of file diff --git a/zygiskd/src/companion.c b/zygiskd/src/companion.c index 0646a77..9261b6f 100644 --- a/zygiskd/src/companion.c +++ b/zygiskd/src/companion.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -17,6 +18,9 @@ #include "dl.h" #include "utils.h" +#undef LOG_TAG +#define LOG_TAG lp_select("zygiskd-companion32", "zygiskd-companion64") + typedef void (*zygisk_companion_entry)(int); struct companion_module_thread_args { @@ -28,12 +32,23 @@ zygisk_companion_entry load_module(int fd) { char path[PATH_MAX]; snprintf(path, sizeof(path), "/proc/self/fd/%d", fd); - void *handle = android_dlopen(path, RTLD_NOW); + void *handle = dlopen_ext(path, RTLD_NOW); + + if (!handle) return NULL; + void *entry = dlsym(handle, "zygisk_companion_entry"); + if (!entry) { + LOGE("Failed to dlsym zygisk_companion_entry: %s\n", dlerror()); + + dlclose(handle); + + return NULL; + } return (zygisk_companion_entry)entry; } +/* WARNING: Dynamic memory based */ void *entry_thread(void *arg) { struct companion_module_thread_args *args = (struct companion_module_thread_args *)arg; @@ -42,7 +57,7 @@ void *entry_thread(void *arg) { struct stat st0 = { 0 }; if (fstat(fd, &st0) == -1) { - LOGE("Failed to get initial client fd stats: %s\n", strerror(errno)); + LOGE(" - Failed to get initial client fd stats: %s\n", strerror(errno)); free(args); @@ -56,14 +71,10 @@ void *entry_thread(void *arg) { if the module companion already closed the fd. */ struct stat st1; - if (fstat(fd, &st1) == 0) { - if (st0.st_dev == st1.st_dev && st0.st_ino == st1.st_ino) { - LOGI("Client fd stats unchanged. Closing.\n"); + if (fstat(fd, &st1) != -1 || st0.st_ino == st1.st_ino) { + LOGI(" - Client fd changed after module entry\n"); - close(fd); - } else { - LOGI("Client fd stats changed, assuming module handled closing.\n"); - } + close(fd); } free(args); @@ -80,10 +91,7 @@ void companion_entry(int fd) { if (ret == -1) { LOGE("Failed to read module name\n"); - /* TODO: Is that appropriate? */ - close(fd); - - exit(0); + goto cleanup; } LOGI(" - Module name: \"%s\"\n", name); @@ -92,10 +100,7 @@ void companion_entry(int fd) { if (library_fd == -1) { LOGE("Failed to receive library fd\n"); - /* TODO: Is that appropriate? */ - close(fd); - - exit(0); + goto cleanup; } LOGI(" - Library fd: %d\n", library_fd); @@ -109,7 +114,7 @@ void companion_entry(int fd) { ret = write_uint8_t(fd, 0); ASSURE_SIZE_WRITE("ZygiskdCompanion", "module_entry", ret, sizeof(uint8_t)); - exit(0); + goto cleanup; } else { LOGI(" - Module entry found\n"); @@ -117,18 +122,25 @@ void companion_entry(int fd) { ASSURE_SIZE_WRITE("ZygiskdCompanion", "module_entry", ret, sizeof(uint8_t)); } + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + + sigemptyset(&sa.sa_mask); + sa.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &sa, NULL); + while (1) { if (!check_unix_socket(fd, true)) { LOGE("Something went wrong in companion. Bye!\n"); - exit(0); + break; } int client_fd = read_fd(fd); if (client_fd == -1) { LOGE("Failed to receive client fd\n"); - exit(0); + break; } struct companion_module_thread_args *args = malloc(sizeof(struct companion_module_thread_args)); @@ -137,7 +149,7 @@ void companion_entry(int fd) { close(client_fd); - exit(0); + break; } args->fd = client_fd; @@ -149,9 +161,20 @@ void companion_entry(int fd) { ASSURE_SIZE_WRITE("ZygiskdCompanion", "client_fd", ret, sizeof(uint8_t)); pthread_t thread; - pthread_create(&thread, NULL, entry_thread, args); - pthread_detach(thread); + if (pthread_create(&thread, NULL, entry_thread, (void *)args) == 0) + continue; - LOGI(" - Spawned companion thread for client fd: %d\n", client_fd); + LOGE(" - Failed to create thread for companion module\n"); + + close(client_fd); + free(args); + + break; } + + cleanup: + close(fd); + LOGE("Companion thread exited\n"); + + exit(0); } diff --git a/zygiskd/src/dl.c b/zygiskd/src/dl.c index 26770da..0be28f0 100644 --- a/zygiskd/src/dl.c +++ b/zygiskd/src/dl.c @@ -11,77 +11,47 @@ #include #include +#include #include "companion.h" #include "utils.h" -#define ANDROID_NAMESPACE_TYPE_SHARED 0x2 -#define ANDROID_DLEXT_USE_NAMESPACE 0x200 +#define __LOADER_ANDROID_CREATE_NAMESPACE_TYPE(name) struct android_namespace_t *(*name)( \ + const char *name, \ + const char *ld_library_path, \ + const char *default_library_path, \ + uint64_t type, \ + const char *permitted_when_isolated_path, \ + struct android_namespace_t *parent, \ + const void *caller_addr) -typedef struct AndroidNamespace { - uint8_t _unused[0]; -} AndroidNamespace; - -typedef struct AndroidDlextinfo { - uint64_t flags; - void *reserved_addr; - size_t reserved_size; - int relro_fd; - int library_fd; - off64_t library_fd_offset; - AndroidNamespace *library_namespace; -} AndroidDlextinfo; - -extern void *android_dlopen_ext(const char *filename, int flags, const AndroidDlextinfo *extinfo); - -typedef AndroidNamespace *(*AndroidCreateNamespaceFn)( - const char *name, - const char *ld_library_path, - const char *default_library_path, - uint64_t type, - const char *permitted_when_isolated_path, - AndroidNamespace *parent, - const void *caller_addr -); - -void *android_dlopen(char *path, int flags) { +void *dlopen_ext(const char* path, int flags) { + android_dlextinfo info = { 0 }; char *dir = dirname(path); - struct AndroidDlextinfo info = { - .flags = 0, - .reserved_addr = NULL, - .reserved_size = 0, - .relro_fd = 0, - .library_fd = 0, - .library_fd_offset = 0, - .library_namespace = NULL, - }; - void *handle = dlsym(RTLD_DEFAULT, "__loader_android_create_namespace"); - AndroidCreateNamespaceFn android_create_namespace_fn = (AndroidCreateNamespaceFn)handle; + __LOADER_ANDROID_CREATE_NAMESPACE_TYPE(__loader_android_create_namespace) = (__LOADER_ANDROID_CREATE_NAMESPACE_TYPE( ))dlsym(RTLD_DEFAULT, "__loader_android_create_namespace"); - AndroidNamespace *ns = android_create_namespace_fn( - path, - dir, - NULL, - ANDROID_NAMESPACE_TYPE_SHARED, - NULL, - NULL, - (const void *)&android_dlopen - ); + struct android_namespace_t *ns = __loader_android_create_namespace == NULL ? NULL : + __loader_android_create_namespace(path, dir, NULL, + 2, /* ANDROID_NAMESPACE_TYPE_SHARED */ + NULL, NULL, + (void *)&dlopen_ext); - if (ns != NULL) { + if (ns) { info.flags = ANDROID_DLEXT_USE_NAMESPACE; info.library_namespace = ns; - LOGI("Open %s with namespace %p\n", path, (void *)ns); + LOGI("Open %s with namespace %p", path, (void *)ns); } else { - LOGI("Cannot create namespace for %s\n", path); + LOGW("Cannot create namespace for %s", path); } - void *result = android_dlopen_ext(path, flags, &info); - if (result == NULL) { - LOGE("Failed to dlopen %s: %s\n", path, dlerror()); + void *handle = android_dlopen_ext(path, flags, &info); + if (handle) { + LOGI("dlopen %s: %p", path, handle); + } else { + LOGE("dlopen %s: %s", path, dlerror()); } - return result; + return handle; } diff --git a/zygiskd/src/dl.h b/zygiskd/src/dl.h index 97ba83e..de5060f 100644 --- a/zygiskd/src/dl.h +++ b/zygiskd/src/dl.h @@ -1,6 +1,6 @@ #ifndef DL_H #define DL_H -void *android_dlopen(char *path, int flags); +void *dlopen_ext(char *path, int flags); #endif /* DL_H */ diff --git a/zygiskd/src/utils.c b/zygiskd/src/utils.c index eff45d9..d0e7eba 100644 --- a/zygiskd/src/utils.c +++ b/zygiskd/src/utils.c @@ -228,11 +228,11 @@ ssize_t write_fd(int fd, int sendfd) { int read_fd(int fd) { char cmsgbuf[CMSG_SPACE(sizeof(int))]; - char buf[1] = { 0 }; - + + int cnt = 1; struct iovec iov = { - .iov_base = buf, - .iov_len = 1 + .iov_base = &cnt, + .iov_len = sizeof(cnt) }; struct msghdr msg = { @@ -242,7 +242,7 @@ int read_fd(int fd) { .msg_controllen = sizeof(cmsgbuf) }; - ssize_t ret = recvmsg(fd, &msg, 0); + ssize_t ret = recvmsg(fd, &msg, MSG_WAITALL); if (ret == -1) { LOGE("recvmsg: %s\n", strerror(errno)); diff --git a/zygiskd/src/utils.h b/zygiskd/src/utils.h index f9655f8..7cc6bbf 100644 --- a/zygiskd/src/utils.h +++ b/zygiskd/src/utils.h @@ -9,12 +9,18 @@ #define CONCAT_(x,y) x##y #define CONCAT(x,y) CONCAT_(x,y) -#define LOGI(...) \ - __android_log_print(ANDROID_LOG_INFO, lp_select("zygiskd32", "zygiskd64"), __VA_ARGS__); \ +#define LOG_TAG lp_select("zygiskd32", "zygiskd64") + +#define LOGI(...) \ + __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__); \ printf(__VA_ARGS__); -#define LOGE(...) \ - __android_log_print(ANDROID_LOG_ERROR , lp_select("zygiskd32", "zygiskd64"), __VA_ARGS__); \ +#define LOGW(...) \ + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__); \ + printf(__VA_ARGS__); + +#define LOGE(...) \ + __android_log_print(ANDROID_LOG_ERROR , LOG_TAG, __VA_ARGS__); \ printf(__VA_ARGS__); #define ASSURE_SIZE_WRITE(area_name, subarea_name, sent_size, expected_size) \ From d8034b7bde6157823d632fd718689db053083d8d Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Sun, 29 Dec 2024 19:16:09 -0300 Subject: [PATCH 23/46] add: Magisk Kitsune SuList support This commit adds support for the Kitsune SuList, a denylist in whitelist mode. --- zygiskd/src/root_impl/magisk.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/zygiskd/src/root_impl/magisk.c b/zygiskd/src/root_impl/magisk.c index d33e71a..9f4e364 100644 --- a/zygiskd/src/root_impl/magisk.c +++ b/zygiskd/src/root_impl/magisk.c @@ -31,6 +31,7 @@ char *magisk_managers[] = { enum magisk_variants variant = Official; /* INFO: Longest path */ static char path_to_magisk[sizeof(DEBUG_RAMDISK_MAGISK)]; +bool is_using_sulist = false; void magisk_get_existence(struct root_impl_state *state) { struct stat s; @@ -78,7 +79,7 @@ void magisk_get_existence(struct root_impl_state *state) { strcpy(path_to_magisk, SBIN_MAGISK); } - char *argv[] = { "magisk", "-v", NULL }; + char *argv[4] = { "magisk", "-v", NULL, NULL }; char magisk_info[128]; if (!exec_command(magisk_info, sizeof(magisk_info), (const char *)path_to_magisk, argv)) { @@ -113,6 +114,27 @@ void magisk_get_existence(struct root_impl_state *state) { return; } + /* INFO: Magisk Kitsune has a feature called SuList, which is a whitelist of + which processes are allowed to see root. Although only Kitsune has + this option, there are Kitsune forks without "-kitsune" suffix, so + to avoid excluding them from taking advantage of that feature, we + will not check the variant. + */ + argv[1] = "--sqlite"; + argv[2] = "select value from settings where key = 'sulist' limit 1"; + + char sulist_enabled[32]; + if (!exec_command(sulist_enabled, sizeof(sulist_enabled), (const char *)path_to_magisk, argv)) { + LOGE("Failed to execute magisk binary: %s\n", strerror(errno)); + errno = 0; + + state->state = Abnormal; + + return; + } + + is_using_sulist = strcmp(sulist_enabled, "value=1") == 0; + if (atoi(magisk_version) >= MIN_MAGISK_VERSION) state->state = Supported; else state->state = TooOld; } @@ -158,7 +180,10 @@ bool magisk_uid_should_umount(uid_t uid) { char *package_name = strtok(result + strlen("package:"), " "); char sqlite_cmd[256]; - snprintf(sqlite_cmd, sizeof(sqlite_cmd), "select 1 from denylist where package_name=\"%s\" limit 1", package_name); + if (is_using_sulist) + snprintf(sqlite_cmd, sizeof(sqlite_cmd), "select 1 from sulist where package_name=\"%s\" limit 1", package_name); + else + snprintf(sqlite_cmd, sizeof(sqlite_cmd), "select 1 from denylist where package_name=\"%s\" limit 1", package_name); char *const argv[] = { "magisk", "--sqlite", sqlite_cmd, NULL }; @@ -169,7 +194,8 @@ bool magisk_uid_should_umount(uid_t uid) { return false; } - return result[0] != '\0'; + if (is_using_sulist) return result[0] == '\0'; + else return result[0] != '\0'; } bool magisk_uid_is_manager(uid_t uid) { From e56cc85948a29b90973f3578c4402abc35bb8d7f Mon Sep 17 00:00:00 2001 From: Lucky Kiddos <95188840+GuitarHeroStyles@users.noreply.github.com> Date: Sat, 11 Jan 2025 11:17:51 +0700 Subject: [PATCH 24/46] add: Indonesian README.md (#108) This commit adds Indonesian translation for README. Signed-off-by: Lucky Kiddos <95188840+GuitarHeroStyles@users.noreply.github.com> --- README.md | 2 +- READMEs/README_id-ID.md | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 READMEs/README_id-ID.md diff --git a/README.md b/README.md index 3fbf1e8..b987ffe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ReZygisk -[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md) +[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md)|[Bahasa Indonesia](/READMEs/README_id-ID.md) ReZygisk is a fork of Zygisk Next, a standalone implementation of Zygisk, providing Zygisk API support for KernelSU, Magisk (besides built-in), and APatch (Work In Progress). diff --git a/READMEs/README_id-ID.md b/READMEs/README_id-ID.md new file mode 100644 index 0000000..6bc9471 --- /dev/null +++ b/READMEs/README_id-ID.md @@ -0,0 +1,63 @@ +# ReZygisk + +[English](https://github.com/PerformanC/ReZygisk) + +ReZygisk adalah turunan dari Zygisk Next, sebuah implementasi mandiri Zygisk, yang mendukung API Zygisk untuk KernelSU, Magisk (selain versi bawaan), dan APatch (dalam tahap pengembangan). + +Proyek ini bertujuan untuk memodernisasi dan menulis ulang basis kode ke dalam bahasa pemorgraman C (dari C++ dan Rust), memungkinkan implementasi API Zygisk yang lebih efisien dan cepat dengan lisensi yang lebih permisif. + +> [!NOTE] +> [CATATAN] +> +> Modul/turunan ini sedang dalam tahap pengembangan. gunakan hanya file .zip dari halaman Rilis. +> +> Anda dapat menginstal file .zip dari halaman [Actions](https://github.com/PerformanC/ReZygisk/actions), namun instalan ini sepenuhnya menjadi tanggung jawab Anda karena perangkat dapat mengalami bootloop. + +## Mengapa? + +Rilisan terbaru dari Zygisk Next tidak bersifat open-source, dengan kode yang sepenuhnya dikendalikan oleh developernya. Hal ini tidak hanya membatasi kemampuan kami untuk berkontribusi pada proyek ini, tetapi juga membuat kode tidak dapat diaudit, yang menjadi masalah utama keamanan karena Zygisk Next adalah modul yang berjalan dengan hak superuser (root), yang memiliki akses ke seluruh sistem. + +Meskipun developer Zygisk Next terkenal dan dipercaya dalam komunitas Android, hal ini tidak menjamin bahwa kode tersebut bebas dari bahaya atau kerentanan. Kami (PerformanC) memahami alasan mereka untuk menjaga kode tetap tertutup, tetapi kami memiliki pandangan yang berbeda. + +## Kelebihan + +- FOSS (Free and Open Source Software) Selamanya. + +## Komponen Pendukung + +| Alat | Deskripsi | +|-----------------|------------------------------------------| +| `Android NDK` | Native Development Kit untuk Android | + +### Komponen Pendukung C++ + +| Komponen | Deskripsi | +|------------|---------------------------------| +| `lsplt` | Simple PLT Hook untuk Android | + +## Penggunaan + +Kami saat ini sedang dalam tahap pengembangan. (Segera Hadir) + +## Instalasi + +Saat ini belum tersedia rilisan yang stabil. (Segera Hadir) + +## Terjemahan + +Saat ini, kami belum terintegrasi dengan platform lain untuk penerjemahan, tetapi Anda dapat berkontribusi pada cabang [add/new-webui](https://github.com/PerformanC/ReZygisk/tree/add/new-webui). Jangan lupa untuk menyertakan profil GitHub Anda di [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/new-webui/TRANSLATOR.md) agar orang lain dapat melihat kontribusi Anda. + +## Dukungan +Untuk pertanyaan terkait ReZygisk atau proyek PerformanC lainnya, silakan bergabung ke salah satu saluran berikut: + +- Saluran Discord: [PerformanC](https://discord.gg/uPveNfTuCJ) +- Saluran Telegram ReZygisk: [@rezygiskchat](https://t.me/rezygiskchat) +- Saluran Telegram PerformanC: [@performancorg](https://t.me/performancorg) + +## Kontribusi + +Wajib mengikuti [Pedoman Kontribusi](https://github.com/PerformanC/contributing) PerformanC untuk berkontribusi pada ReZygisk. Sesuai dengan Kebijakan Keamanan, Kode Etik, dan standar struktur dan format yang berlaku. + +## Lisensi + +ReZygisk sebagian besar berlisensi di bawah GPL, oleh Dr-TSNG, tetapi juga AGPL 3.0, oleh The PerformanC Organization, untuk kode yang ditulis ulang. Anda dapat juga membaca lebih lanjut di [Open Source Initiative](https://opensource.org/licenses/AGPL-3.0). From 3bc3b478ff9e4ee26c1dfeafe8a18105b8428255 Mon Sep 17 00:00:00 2001 From: "Arisu: Rain" Date: Sat, 11 Jan 2025 00:57:26 -0800 Subject: [PATCH 25/46] add: vietnamese README (#110) This commit adds Vietnam language README to the repository. --- README.md | 2 +- READMEs/README_vi-VN.md | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 READMEs/README_vi-VN.md diff --git a/README.md b/README.md index b987ffe..fc76a76 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ReZygisk -[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md)|[Bahasa Indonesia](/READMEs/README_id-ID.md) +[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md)|[Bahasa Indonesia](/READMEs/README_id-ID.md)|[Tiếng Việt](/READMEs/README_vi-VN.md)| ReZygisk is a fork of Zygisk Next, a standalone implementation of Zygisk, providing Zygisk API support for KernelSU, Magisk (besides built-in), and APatch (Work In Progress). diff --git a/READMEs/README_vi-VN.md b/READMEs/README_vi-VN.md new file mode 100644 index 0000000..7c63d50 --- /dev/null +++ b/READMEs/README_vi-VN.md @@ -0,0 +1,61 @@ +# ReZygisk + +[English](../README.md) + +ReZygisk làm một nhánh phát triển lấy từ ZygiskNext, một triển khai độc lập của Zygisk, cung cấp và hỗ trợ Zygisk API cho KernelSU, Magisk (bên cạnh tích hợp) và APatch (Đang trong quá trình phát triển). + +Mục tiêu của ReZygisk là mô-đun hoá và viết lại toàn bộ codebase từ C++/Rust sang C, cho phép triển khai API Zygisk hiệu quả hơn và nhanh hơn với giấy phép dễ dàng tái sử dụng hơn. + +> [!NOTE] +> Mô-đun này đang trong quá trình phát triển; chỉ nên sử dụng file .zip từ các bản phát hành. +> +> Mạc dù bạn có thể cài đặt mô-đun được lấy từ trang [Actions](https://github.com/PerformanC/ReZygisk/actions), nhưng sẽ chỉ phụ thuộc vào bạn có chấp nhận rủi ro hay không vì các mô-đun này có thể gây lỗi cho hệ điều hành. Ví dụ: Bootloop (Lỗi liên tục khởi động lại máy) + +## Tại sao nhánh phát triển này lại xuất hiện? + +Bản ra mắt mới nhất của Zygisk Next không còn là mã nguồn mở, dành toàn bộ quyền phát triển phần mềm cho những nhà phát triển gốc. Không chỉ giới hạn chúng ta đóng gốp cho dự án, mà còn bất khả thi trong việc kiểm trả độ đảm bảo của mã, điều mà có thể coi là mối quan tâm lớn về tính bảo mật và độ an toàn, bởi Zygisk Next là mô-đun chạy dưới quyền quản trị (root), có khả năng truy cập vào toàn bộ hệ thống trong thiết bị của bạn. + +Các nhà phát triển Zygisk Next đều là những người nổi tiếng và được tin tưởng bởi cộng đồng sử dụng Android, tuy nhiên, điều đó không có nghĩa là mã nguồn của họ không có lỗ hổng hoặc có nguy cơ bị tấn công. Chúng tôi (PerformanC) thông cảm được lý do mà học đóng mã nguồn của họ vào, tuy nhiễn chúng tôi tin vào điều ngược lại. + +## Ưu điểm + +- Mã nguồn mở (Vĩnh Viễn) + +## Các công cụ/thư viện được sử dụng + +| Công cụ | Mô tả | +|-----------------|-------------------------------------------| +| `Android NDK` | Bộ công cụ phát triển cốt lõi cho Android | + +### Các công cụ/thư viện của C++ được sử dụng + +| Thư Viện | Mô Tả | +|------------|----------------------------------------------| +| `lsplt` | Công cụ **móc** vào PLT đơn giản cho Android | + +## Các sử dụng + +Chúng tôi đang trong quá trình phát triển (Sắp ra mắt) + +## Cài Đặt + +Hiện chưa có bản ra mắt ổn định (Sắp ra mắt) + +## Dịch WebUI cho mô-đun + +Hiện tai, chúng tôi chưa tích hợp nền táng dịch nào để dịch một cách thuận tiện nhưng bạn có thể đóng góp vào nhánh [add/new-webui](https://github.com/PerformanC/ReZygisk/tree/add/new-webui). Đừng quên thêm trang cá nhân Github của bạn vào [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/new-webui/TRANSLATOR.md) để mọi người thâys được đóng góp của bạn + +## Hỗ trợ +Nếu bạn có những câu hỏi nào dành cho ReZygisk hoặc bất kì một dự án nào của PerformanC, hãy tự nhiên tham gia các kênh trò chuyện dưới đây: + +- Discord: [PerformanC](https://discord.gg/uPveNfTuCJ) +- Telegram [ReZygisk]: [@rezygiskchat](https://t.me/rezygiskchat) +- Telegram [PerformanC]: [@performancorg](https://t.me/performancorg) + +## Đóng góp cho dự án này + +Tuân theo [hướng dẫn đóng góp](https://github.com/PerformanC/contributing) của PerformanC là một điều tất yếu mà bạn bắt buộc phải làm. Hãy tuân theo chính sách bảo mật, quy tắc ứng xử/đóng góp mã nguồn và tiêu chuẩn cú pháp riêng. + +## Bản quyền + +Hầu hết các thành phần của ReZygisk để dưới bản quyền GPL (bởi Dr-TSNG) và AGPL 3.0 (bởiThe PerformanC Organization) cho những phần được viết lại. Bạn có thể xem thêm trong trang [Open Source Initiative](https://opensource.org/licenses/AGPL-3.0). \ No newline at end of file From cfd4a92b3110b1aa70071ab3e629bf3a40adecb9 Mon Sep 17 00:00:00 2001 From: "Pedro.js" Date: Sat, 11 Jan 2025 07:05:52 -0300 Subject: [PATCH 26/46] add: Brazilian Portuguese `README.md` (#112) This commit adds the language from Brazil to the list of available translations of README.md file --- README.md | 2 +- READMEs/README_pt-BR.md | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 READMEs/README_pt-BR.md diff --git a/README.md b/README.md index fc76a76..1fd98df 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ReZygisk -[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md)|[Bahasa Indonesia](/READMEs/README_id-ID.md)|[Tiếng Việt](/READMEs/README_vi-VN.md)| +[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md)|[Bahasa Indonesia](/READMEs/README_id-ID.md)|[Tiếng Việt](/READMEs/README_vi-VN.md)|[Português Brasileiro](/READMEs/README_pt-BR.md) ReZygisk is a fork of Zygisk Next, a standalone implementation of Zygisk, providing Zygisk API support for KernelSU, Magisk (besides built-in), and APatch (Work In Progress). diff --git a/READMEs/README_pt-BR.md b/READMEs/README_pt-BR.md new file mode 100644 index 0000000..46d070a --- /dev/null +++ b/READMEs/README_pt-BR.md @@ -0,0 +1,62 @@ +# ReZygisk + +[English](../README.md) + +ReZygisk é uma fork do Zygisk Next, uma implementação do Zygisk independente, fornecendo a API do Zygisk para o kernelSU, Magisk (além do embutido) e APatch (a ser desenvolvido). + +Ele foca em modernizar e re-escrever o código fonte para C (de C++ e Rust), permitindo uma implementação da API do Zygisk com uma licença mais permissiva. + +> [!NOTE] +> Este módulo/fork ainda está em processo de desenvolvimento; apenas use .zip da aba Releases. +> +> Apesar de você poder instalar um .zip da aba [Actions](https://github.com/PerformanC/ReZygisk/actions), é de sua conta e risco, já que pode acarretar em um bootloop. + +## Por quê? + +Os últimos lançamentos do Zygisk Next não possuem código aberto, reservando-o para os seus desenvolvedores. Isso não só limita nossa capacidade de contribuir com o projeto, mas também impossibilita a auditoria do código, uma preocupação grave de segurança, já que o Zygisk Next é um módulo que roda como superuser (super usuário/root), tendo acesso a todo o sistema. + +Os desenvolvedores do Zygisk Next são famosos e confiados pela comunidade Android, mas isso não significa que o código não seja nem malicioso nem vulnerável. Nós (PerformanC) reconhecemos seus motivos de manterem o código recluso a eles, mas a gente acredita no contrário. + +## Vantagens + +- FOSS (Pra sempre) + +## Dependências + +| Ferramenta | Descrição | +|-----------------|--------------------------------------------| +| `Android NDK` | Kit de Desenvolvimento Nativo para Android | + +### Dependências C++ + +| Dependência | Descrição | +|-------------|-------------------------------| +| `lsplt` | PLT Hook simples para Android | + +## Forma de uso + +Estamos ainda em processo de desenvolvimento desta aba. (Em breve) + +## Processo de instalação + +Estamos ainda em processo de desenvolvimento desta aba. (Em breve) + +## Tradução + +Até agora, a gente não possui uma plataforma para traduções, mas você pode contribuir para a branch [add/new-webui](https://github.com/PerformanC/ReZygisk/tree/add/new-webui). Por favor, não esqueça de incluir seu perfil do GitHub no [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/new-webui/TRANSLATOR.md) para que assim outras pessoas vejam sua contribuição. + +## Suporte + +Para quaisquer problemas no ReZygisk ou qualquer projeto da PerformanC, sinta-se livre para entrar em qualquer canal abaixo: + +- Server do Discord: [PerformanC](https://discord.gg/uPveNfTuCJ) +- Canal do Telegram ReZygisk: [@rezygiskchat](https://t.me/rezygiskchat) +- Canal do Telegram PerformanC: [@performancorg](https://t.me/performancorg) + +## Contribuição + +É obrigatório seguir as [Regras de Contribuição](https://github.com/PerformanC/contributing) da PerformanC para contribuir ao ReZygisk, seguindo sua Política de Segurança, Código de Conduta, e padronização de sintaxe. + +## Licença + +ReZygisk é majoritamente licenciado em GPL, por Dr-TSNG, mas também em AGPL 3.0, pela A Organização PerformanC (The PerformanC Organization) para código re-escrito. Você pode ler mais em [Open Source Initiative](https://opensource.org/licenses/AGPL-3.0). From bc6cf67c7be00461a70e6a4683eac81aff72a17b Mon Sep 17 00:00:00 2001 From: Berk Mirsat Date: Mon, 27 Jan 2025 14:40:28 +0300 Subject: [PATCH 27/46] add: Turkish README.md (#114) This commit adds README translations for Turkey's launguage. --- README.md | 2 +- READMEs/README_tr-TR.md | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 READMEs/README_tr-TR.md diff --git a/README.md b/README.md index 1fd98df..92b4a6c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ReZygisk -[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md)|[Bahasa Indonesia](/READMEs/README_id-ID.md)|[Tiếng Việt](/READMEs/README_vi-VN.md)|[Português Brasileiro](/READMEs/README_pt-BR.md) +[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md)|[Bahasa Indonesia](/READMEs/README_id-ID.md)|[Tiếng Việt](/READMEs/README_vi-VN.md)|[Português Brasileiro](/READMEs/README_pt-BR.md)|[Türkçe](/READMEs/README_tr-TR.md) ReZygisk is a fork of Zygisk Next, a standalone implementation of Zygisk, providing Zygisk API support for KernelSU, Magisk (besides built-in), and APatch (Work In Progress). diff --git a/READMEs/README_tr-TR.md b/READMEs/README_tr-TR.md new file mode 100644 index 0000000..2e7093c --- /dev/null +++ b/READMEs/README_tr-TR.md @@ -0,0 +1,61 @@ +# ReZygisk + +[English](../README.md) + +ReZygisk, Zygisk Next'in bir forkudur ve Zygisk'in bağımsız bir uygulamasıdır. KernelSU, Magisk (yerleşik olanın dışında) ve APatch (Çalışmalar Devam Ediyor) için Zygisk API desteği sağlar. + +Amacı, C++ ve Rust'tan C diline geçerek kod tabanını modernize etmek ve yeniden yazmaktır. Bu, daha verimli ve hızlı bir Zygisk API uygulaması sağlarken daha esnek bir lisans sunar. + +> [!NOT] +> Bu modül/fork şu anda geliştirme aşamasındadır (WIP - Work In Progress); yalnızca Release'deki .zip dosyasını kullanın. +> +> [Actions](https://github.com/PerformanC/ReZygisk/actions) sayfasındaki .zip dosyasını yüklemek tamamen sizin sorumluluğunuzdadır; cihazınız bootloop'a girebilir. + +## Neden? + +Zygisk Next'in son sürümleri açık kaynaklı değildir ve tamamen geliştiricilerine ayrılmıştır. Bu durum, projeye katkıda bulunma yeteneğimizi sınırlamakla kalmaz, aynı zamanda kodun denetlenmesini imkansız hale getirir. Bu, Zygisk Next'in süper kullanıcı (root) ayrıcalıklarıyla çalışması ve tüm sisteme erişimi olması nedeniyle büyük bir güvenlik sorunudur. + +Zygisk Next geliştiricileri, Android topluluğunda tanınmış ve güvenilir kişilerdir, ancak bu, kodun kötü niyetli veya hassas olmadığını garanti etmez. PerformanC olarak, kodu kapalı kaynaklı tutma nedenlerini anlasak da, bunun tersini savunuyoruz. + +## Avantajlar + +- Sonsuza kadar açık kaynak (FOSS) + +## Bağımlılıklar + +| Araç | Açıklama | +|------------------|--------------------------------------| +| `Android NDK` | Android için Yerel Geliştirme Kiti | + +### C++ Bağımlılıkları + +| Bağımlılık | Açıklama | +|------------|---------------------------------| +| `lsplt` | Android için Basit PLT Hook | + +## Kullanım + +Şu anda geliştirme aşamasındayız. (Yakında) + +## Kurulum + +Şu anda mevcut kararlı sürüm yoktur. (Yakında) + +## Çeviri + +Şu anda başka bir platformla entegre bir çeviri sistemimiz bulunmuyor, ancak [add/new-webui](https://github.com/PerformanC/ReZygisk/tree/add/new-webui) branch'ine katkıda bulunabilirsiniz. Lütfen GitHub profilinizi [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/new-webui/TRANSLATOR.md) dosyasına eklemeyi unutmayın, böylece katkılarınız görülebilir. + +## Destek +ReZygisk veya diğer PerformanC projeleriyle ilgili herhangi bir soru için aşağıdaki kanallardan herhangi birine katılabilirsiniz: + +- Discord Kanalı: [PerformanC](https://discord.gg/uPveNfTuCJ) +- ReZygisk Telegram Kanalı: [@rezygiskchat](https://t.me/rezygiskchat) +- PerformanC Telegram Kanalı: [@performancorg](https://t.me/performancorg) + +## Katkıda Bulunma + +ReZygisk'e katkıda bulunmak için PerformanC'nin [Katkı Yönergeleri](https://github.com/PerformanC/contributing)'ni takip etmek zorunludur. Güvenlik Politikası, Davranış Kuralları ve sözdizimi standartlarına uyulmalıdır. + +## Lisans + +ReZygisk, büyük ölçüde Dr-TSNG tarafından GPL lisansı altında, ancak yeniden yazılmış kodlar için The PerformanC Organization tarafından AGPL 3.0 lisansı altında lisanslanmıştır. Daha fazla bilgi için [Open Source Initiative](https://opensource.org/licenses/AGPL-3.0)'e göz atabilirsiniz. From 92e2f528a905e27dfa321e4131f6125355fa8edb Mon Sep 17 00:00:00 2001 From: Reveny <113244907+reveny@users.noreply.github.com> Date: Sat, 22 Mar 2025 23:12:24 +0100 Subject: [PATCH 28/46] add: Android 9 support (#117) This commit makes ReZygisk load Zygisk libraries directly, not utilizing memfd, as it doesn't exist in older versions of Android. --- loader/src/common/dl.cpp | 14 +++++++++++++- loader/src/common/files.cpp | 15 +++++++++++++++ loader/src/include/files.hpp | 3 +++ loader/src/injector/hook.cpp | 4 ++-- zygiskd/src/zygiskd.c | 30 +----------------------------- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/loader/src/common/dl.cpp b/loader/src/common/dl.cpp index 4bcd3b3..6d30432 100644 --- a/loader/src/common/dl.cpp +++ b/loader/src/common/dl.cpp @@ -6,6 +6,7 @@ #include #include "dl.h" +#include "files.hpp" #include "logging.h" extern "C" [[gnu::weak]] struct android_namespace_t* @@ -50,11 +51,22 @@ void* DlopenMem(int fd, int flags) { .library_fd = fd }; - auto* handle = android_dlopen_ext("/jit-cache-zygisk", flags, &info); + /* INFO: We need to find the path of the fd since passing "" to android_dlopen_ext + will not work and passing the original "jit-cache-zygisk" will cause a detection again. */ + char path[PATH_MAX]; + if (get_path_from_fd(fd, path, sizeof(path)) != 0) { + LOGE("Failed to get path for fd: %d", fd); + return NULL; + } + + LOGD("Path for fd %d: %s", fd, path); + + auto *handle = android_dlopen_ext(path, flags, &info); if (handle) { LOGV("dlopen fd %d: %p", fd, handle); } else { LOGE("dlopen fd %d: %s", fd, dlerror()); } + return handle; } diff --git a/loader/src/common/files.cpp b/loader/src/common/files.cpp index e597295..ade40de 100644 --- a/loader/src/common/files.cpp +++ b/loader/src/common/files.cpp @@ -120,3 +120,18 @@ sDIR make_dir(DIR *dp) { sFILE make_file(FILE *fp) { return sFILE(fp, [](FILE *fp){ return fp ? fclose(fp) : 1; }); } + +int get_path_from_fd(int fd, char *buf, size_t size) { + if (fd < 0 || !buf || size == 0) return -1; + + /* NOTE: We assume that the path is always at /data/adb/modules/xxx + which should never be longer than 128 chars. */ + char proc_path[128]; + snprintf(proc_path, sizeof(proc_path), "/proc/self/fd/%d", fd); + + ssize_t len = readlink(proc_path, buf, size - 1); + if (len == -1) return -1; + + buf[len] = '\0'; + return 0; +} \ No newline at end of file diff --git a/loader/src/include/files.hpp b/loader/src/include/files.hpp index 73bc9e2..4f16e0c 100644 --- a/loader/src/include/files.hpp +++ b/loader/src/include/files.hpp @@ -2,6 +2,7 @@ #include #include #include +#include struct mount_info { unsigned int id; @@ -26,6 +27,8 @@ void file_readline(const char *file, const std::function std::vector parse_mount_info(const char *pid); +int get_path_from_fd(int fd, char *buf, size_t size); + using sFILE = std::unique_ptr; using sDIR = std::unique_ptr; sDIR make_dir(DIR *dp); diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index ae41b6a..5255d37 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -591,7 +591,7 @@ void ZygiskContext::run_modules_post() { if (modules.size() > 0) { LOGD("modules unloaded: %zu/%zu", modules_unloaded, modules.size()); - clean_trace("jit-cache-zygisk", modules.size(), modules_unloaded, true); + clean_trace("/data/adb", modules.size(), modules_unloaded, true); } } @@ -762,7 +762,7 @@ void clean_trace(const char* path, size_t load, size_t unload, bool spoof_maps) // spoofing map names is futile in Android, we do it simply // to avoid Zygisk detections based on string comparison for (auto &map : lsplt::MapInfo::Scan()) { - if (strstr(map.path.c_str(), path)) + if (strstr(map.path.c_str(), path) && strstr(map.path.c_str(), "libzygisk") == 0) { void *addr = (void *)map.start; size_t size = map.end - map.start; diff --git a/zygiskd/src/zygiskd.c b/zygiskd/src/zygiskd.c index 6031955..0c0d952 100644 --- a/zygiskd/src/zygiskd.c +++ b/zygiskd/src/zygiskd.c @@ -83,35 +83,7 @@ int create_library_fd(const char *restrict so_path) { return -1; } - /* INFO: This is required as older implementations of glibc may not - have the memfd_create function call, causing a crash. */ - int memfd = (int)syscall(SYS_memfd_create, "jit-cache-zygisk", MFD_ALLOW_SEALING); - if (memfd == -1) { - LOGE("Failed creating memfd: %s\n", strerror(errno)); - - return -1; - } - - if (sendfile(memfd, so_fd, NULL, (size_t)so_size) == -1) { - LOGE("Failed copying so file to memfd: %s\n", strerror(errno)); - - close(so_fd); - close(memfd); - - return -1; - } - - close(so_fd); - - if (fcntl(memfd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_SEAL) == -1) { - LOGE("Failed sealing memfd: %s\n", strerror(errno)); - - close(memfd); - - return -1; - } - - return memfd; + return so_fd; } /* WARNING: Dynamic memory based */ From 9aafc279d5f7a492acff3f0de1ddbc2ecc8d8d9c Mon Sep 17 00:00:00 2001 From: Reveny <113244907+reveny@users.noreply.github.com> Date: Sun, 23 Mar 2025 19:11:33 +0100 Subject: [PATCH 29/46] improve: use all threads for compiling (#118) This commit speeds up the build process by almost 50% when building with github actions by using all system threads to compile ReZygisk. --- loader/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/loader/build.gradle.kts b/loader/build.gradle.kts index 442f3a2..f9d9f8e 100644 --- a/loader/build.gradle.kts +++ b/loader/build.gradle.kts @@ -56,6 +56,7 @@ android { externalNativeBuild.cmake { arguments += "-DANDROID_STL=none" arguments += "-DLSPLT_STANDALONE=ON" + arguments += "-DCMAKE_BUILD_PARALLEL_LEVEL=${Runtime.getRuntime().availableProcessors()}" cFlags("-std=c18", *defaultCFlags) cppFlags("-std=c++20", *defaultCFlags) ccachePath?.let { From 886e2f8396979781d82983f9536b76f75373d909 Mon Sep 17 00:00:00 2001 From: "Pedro.js" Date: Sat, 29 Mar 2025 12:17:57 -0300 Subject: [PATCH 30/46] improve: mounting system, compatibility; remove: logging on release (#111) This commit adds numerous improvements to the state of hidden'ility of ReZygisk, and also for compatibility. Recommended to check #111 for more information. --- loader/src/common/daemon.cpp | 47 ++-- loader/src/common/dl.cpp | 9 +- loader/src/common/elf_util.cpp | 6 +- loader/src/common/logging.cpp | 36 --- loader/src/include/daemon.h | 18 +- loader/src/include/elf_util.h | 16 +- loader/src/include/logging.h | 39 ++-- loader/src/include/solist.hpp | 61 ++--- loader/src/injector/entry.cpp | 8 +- loader/src/injector/hook.cpp | 95 ++++---- loader/src/injector/module.hpp | 8 +- loader/src/injector/unmount.cpp | 145 ------------ loader/src/injector/zygisk.hpp | 6 - module/src/sepolicy.rule | 30 +-- zygiskd/build.gradle.kts | 2 +- zygiskd/src/constants.h | 35 ++- zygiskd/src/root_impl/common.c | 3 + zygiskd/src/utils.c | 389 +++++++++++++++++++++++++++++++- zygiskd/src/utils.h | 2 + zygiskd/src/zygiskd.c | 78 +++---- 20 files changed, 621 insertions(+), 412 deletions(-) delete mode 100644 loader/src/common/logging.cpp delete mode 100644 loader/src/injector/unmount.cpp diff --git a/loader/src/common/daemon.cpp b/loader/src/common/daemon.cpp index 34a188c..bd558ca 100644 --- a/loader/src/common/daemon.cpp +++ b/loader/src/common/daemon.cpp @@ -63,19 +63,6 @@ namespace zygiskd { return true; } - int RequestLogcatFd() { - int fd = Connect(1); - if (fd == -1) { - PLOGE("RequestLogcatFd"); - - return -1; - } - - socket_utils::write_u8(fd, (uint8_t) SocketAction::RequestLogcatFd); - - return fd; - } - uint32_t GetProcessFlags(uid_t uid) { int fd = Connect(1); if (fd == -1) { @@ -94,8 +81,8 @@ namespace zygiskd { return res; } - std::vector ReadModules() { - std::vector modules; + std::vector ReadModules() { + std::vector modules; int fd = Connect(1); if (fd == -1) { PLOGE("ReadModules"); @@ -260,4 +247,34 @@ namespace zygiskd { close(fd); } else info->running = false; } + + std::string UpdateMountNamespace(enum mount_namespace_state nms_state) { + int fd = Connect(1); + if (fd == -1) { + PLOGE("UpdateMountNamespace"); + + return ""; + } + + socket_utils::write_u8(fd, (uint8_t) SocketAction::UpdateMountNamespace); + socket_utils::write_u32(fd, getpid()); + socket_utils::write_u8(fd, (uint8_t)nms_state); + + uint32_t target_pid = socket_utils::read_u32(fd); + int target_fd = 0; + + if (target_pid == 0) goto error; + + target_fd = (int)socket_utils::read_u32(fd); + if (target_fd == 0) goto error; + + close(fd); + + return "/proc/" + std::to_string(target_pid) + "/fd/" + std::to_string(target_fd); + + error: + close(fd); + + return ""; + } } diff --git a/loader/src/common/dl.cpp b/loader/src/common/dl.cpp index 6d30432..352b8f9 100644 --- a/loader/src/common/dl.cpp +++ b/loader/src/common/dl.cpp @@ -46,9 +46,14 @@ void* DlopenExt(const char* path, int flags) { } void* DlopenMem(int fd, int flags) { - auto info = android_dlextinfo{ + auto info = android_dlextinfo { .flags = ANDROID_DLEXT_USE_LIBRARY_FD, - .library_fd = fd + .reserved_addr = NULL, + .reserved_size = 0, + .relro_fd = 0, + .library_fd = fd, + .library_fd_offset = 0, + .library_namespace = NULL }; /* INFO: We need to find the path of the fd since passing "" to android_dlopen_ext diff --git a/loader/src/common/elf_util.cpp b/loader/src/common/elf_util.cpp index d265b3c..2ce61b8 100644 --- a/loader/src/common/elf_util.cpp +++ b/loader/src/common/elf_util.cpp @@ -187,7 +187,7 @@ ElfW(Addr) ElfImg::LinearLookup(std::string_view name) const { } } -std::string_view ElfImg::LinearLookupByPrefix(std::string_view name) const { +ElfW(Addr) ElfImg::LinearLookupByPrefix(std::string_view name) const { if (symtabs_.empty()) { symtabs_.reserve(symtab_count); if (symtab_start != nullptr && symstr_offset_for_symtab != 0) { @@ -207,11 +207,11 @@ std::string_view ElfImg::LinearLookupByPrefix(std::string_view name) const { if (symtab.first.size() < size) continue; if (symtab.first.substr(0, size) == name) { - return symtab.first; + return symtab.second->st_value; } } - return ""; + return 0; } diff --git a/loader/src/common/logging.cpp b/loader/src/common/logging.cpp deleted file mode 100644 index 887025f..0000000 --- a/loader/src/common/logging.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -#include "logging.h" -#include "socket_utils.h" - -namespace logging { - static int logfd = -1; - - void setfd(int fd) { - close(logfd); - logfd = fd; - } - - int getfd() { - return logfd; - } - - void log(int prio, const char* tag, const char* fmt, ...) { - if (logfd == -1) { - va_list ap; - va_start(ap, fmt); - __android_log_vprint(prio, tag, fmt, ap); - va_end(ap); - } else { - char buf[BUFSIZ]; - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - socket_utils::write_u8(logfd, prio); - socket_utils::write_string(logfd, tag); - socket_utils::write_string(logfd, buf); - } - } -} diff --git a/loader/src/include/daemon.h b/loader/src/include/daemon.h index dfb04cc..dad3c18 100644 --- a/loader/src/include/daemon.h +++ b/loader/src/include/daemon.h @@ -61,18 +61,23 @@ struct zygote_info { bool running; }; +enum mount_namespace_state { + Clean, + Rooted, + Module +}; + namespace zygiskd { - struct Module { + struct ModuleInfo { std::string name; UniqueFd memfd; - inline explicit Module(std::string name, int memfd) : name(name), memfd(memfd) {} + inline explicit ModuleInfo(std::string name, int memfd) : name(name), memfd(memfd) {} }; enum class SocketAction { PingHeartBeat, - RequestLogcatFd, GetProcessFlags, GetInfo, ReadModules, @@ -80,6 +85,7 @@ namespace zygiskd { GetModuleDir, ZygoteRestart, SystemServerStarted, + UpdateMountNamespace }; void Init(const char *path); @@ -88,9 +94,7 @@ namespace zygiskd { bool PingHeartbeat(); - int RequestLogcatFd(); - - std::vector ReadModules(); + std::vector ReadModules(); uint32_t GetProcessFlags(uid_t uid); @@ -103,4 +107,6 @@ namespace zygiskd { void SystemServerStarted(); void GetInfo(struct zygote_info *info); + + std::string UpdateMountNamespace(enum mount_namespace_state mns_state); } diff --git a/loader/src/include/elf_util.h b/loader/src/include/elf_util.h index 1b8c0b7..42a08c6 100644 --- a/loader/src/include/elf_util.h +++ b/loader/src/include/elf_util.h @@ -48,8 +48,13 @@ namespace SandHook { } } - std::string_view findSymbolNameByPrefix(std::string_view prefix) const { - return LinearLookupByPrefix(prefix); + constexpr ElfW(Addr) getSymbAddressByPrefix(std::string_view prefix) const { + ElfW(Addr) offset = LinearLookupByPrefix(prefix); + if (offset > 0 && base != nullptr) { + return static_cast((uintptr_t) base + offset - bias); + } else { + return 0; + } } template @@ -57,6 +62,11 @@ namespace SandHook { return reinterpret_cast(getSymbAddress(name)); } + template + constexpr T getSymbAddressByPrefix(std::string_view prefix) const { + return reinterpret_cast(getSymbAddressByPrefix(prefix)); + } + bool isValid() const { return base != nullptr; } @@ -76,7 +86,7 @@ namespace SandHook { ElfW(Addr) LinearLookup(std::string_view name) const; - std::string_view LinearLookupByPrefix(std::string_view name) const; + ElfW(Addr) LinearLookupByPrefix(std::string_view name) const; constexpr static uint32_t ElfHash(std::string_view name); diff --git a/loader/src/include/logging.h b/loader/src/include/logging.h index 0318bbe..687fdaf 100644 --- a/loader/src/include/logging.h +++ b/loader/src/include/logging.h @@ -1,35 +1,30 @@ -#pragma once +#ifndef LOGGING_H +#define LOGGING_H #include #include #include #ifndef LOG_TAG -#if defined(__LP64__) -# define LOG_TAG "zygisk-core64" -#else -# define LOG_TAG "zygisk-core32" -#endif + #ifdef __LP64__ + #define LOG_TAG "zygisk-core64" + #else + #define LOG_TAG "zygisk-core32" + #endif #endif #ifndef NDEBUG -#define LOGD(...) logging::log(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) -#define LOGV(...) logging::log(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) + #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) + #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) #else -#define LOGD(...) -#define LOGV(...) + #define LOGD(...) + #define LOGV(...) #endif -#define LOGI(...) logging::log(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) -#define LOGW(...) logging::log(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) -#define LOGE(...) logging::log(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) -#define LOGF(...) logging::log(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__) + +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) +#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) +#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__) #define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)) -namespace logging { - void setfd(int fd); - - int getfd(); - - [[gnu::format(printf, 3, 4)]] - void log(int prio, const char* tag, const char* fmt, ...); -} +#endif /* LOGGING_H */ \ No newline at end of file diff --git a/loader/src/include/solist.hpp b/loader/src/include/solist.hpp index f55d4b1..6835517 100644 --- a/loader/src/include/solist.hpp +++ b/loader/src/include/solist.hpp @@ -21,7 +21,6 @@ namespace SoList { #endif inline static const char *(*get_realpath_sym)(SoInfo *) = NULL; - inline static const char *(*get_soname_sym)(SoInfo *) = NULL; inline static void (*soinfo_free)(SoInfo *) = NULL; inline SoInfo *get_next() { @@ -38,12 +37,6 @@ namespace SoList { return ((std::string *) ((uintptr_t) this + solist_realpath_offset))->c_str(); } - inline const char *get_name() { - if (get_soname_sym) return get_soname_sym(this); - - return ((std::string *) ((uintptr_t) this + solist_realpath_offset - sizeof(void *)))->c_str(); - } - void set_next(SoInfo *si) { *(SoInfo **) ((uintptr_t) this + solist_next_offset) = si; } @@ -110,6 +103,13 @@ namespace SoList { return addr == NULL ? NULL : *addr; } + template + inline T *getStaticPointerByPrefix(const SandHook::ElfImg &linker, const char *name) { + auto *addr = reinterpret_cast(linker.getSymbAddressByPrefix(name)); + + return addr == NULL ? NULL : *addr; + } + static bool DropSoPath(const char* target_path) { bool path_found = false; if (solist == NULL && !Initialize()) { @@ -117,9 +117,9 @@ namespace SoList { return path_found; } for (auto iter = solist; iter; iter = iter->get_next()) { - if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_path)) { + if (iter->get_path() && strstr(iter->get_path(), target_path)) { SoList::ProtectedDataGuard guard; - LOGI("dropping solist record for %s loaded at %s with size %zu", iter->get_name(), iter->get_path(), iter->get_size()); + LOGV("dropping solist record loaded at %s with size %zu", iter->get_path(), iter->get_size()); if (iter->get_size() > 0) { iter->set_size(0); SoInfo::soinfo_free(iter); @@ -136,7 +136,7 @@ namespace SoList { return; } if (g_module_load_counter == NULL || g_module_unload_counter == NULL) { - LOGI("g_module counters not defined, skip reseting them"); + LOGD("g_module counters not defined, skip reseting them"); return; } auto loaded_modules = *g_module_load_counter; @@ -163,57 +163,26 @@ namespace SoList { See #63 for more information. */ - - std::string_view solist_sym_name = linker.findSymbolNameByPrefix("__dl__ZL6solist"); - if (solist_sym_name.empty()) return false; - LOGD("found symbol name %s", solist_sym_name.data()); - - std::string_view soinfo_free_name = linker.findSymbolNameByPrefix("__dl__ZL11soinfo_freeP6soinfo"); - if (soinfo_free_name.empty()) return false; - LOGD("found symbol name %s", soinfo_free_name.data()); - - /* INFO: The size isn't a magic number, it's the size for the string: .llvm.7690929523238822858 */ - char llvm_sufix[25 + 1]; - - if (solist_sym_name.length() != strlen("__dl__ZL6solist")) { - strncpy(llvm_sufix, solist_sym_name.data() + strlen("__dl__ZL6solist"), sizeof(llvm_sufix)); - } else { - llvm_sufix[0] = '\0'; - } - - solist = getStaticPointer(linker, solist_sym_name.data()); + solist = getStaticPointerByPrefix(linker, "__dl__ZL6solist"); if (solist == NULL) return false; LOGD("found symbol solist"); - char somain_sym_name[sizeof("__dl__ZL6somain") + sizeof(llvm_sufix)]; - snprintf(somain_sym_name, sizeof(somain_sym_name), "__dl__ZL6somain%s", llvm_sufix); - - char sonext_sym_name[sizeof("__dl__ZL6sonext") + sizeof(llvm_sufix)]; - snprintf(sonext_sym_name, sizeof(somain_sym_name), "__dl__ZL6sonext%s", llvm_sufix); - - char vdso_sym_name[sizeof("__dl__ZL4vdso") + sizeof(llvm_sufix)]; - snprintf(vdso_sym_name, sizeof(vdso_sym_name), "__dl__ZL4vdso%s", llvm_sufix); - - somain = getStaticPointer(linker, somain_sym_name); + somain = getStaticPointerByPrefix(linker, "__dl__ZL6somain"); if (somain == NULL) return false; LOGD("found symbol somain"); - sonext = linker.getSymbAddress(sonext_sym_name); + sonext = linker.getSymbAddressByPrefix("__dl__ZL6sonext"); if (sonext == NULL) return false; LOGD("found symbol sonext"); - SoInfo *vdso = getStaticPointer(linker, vdso_sym_name); + SoInfo *vdso = getStaticPointerByPrefix(linker, "__dl__ZL4vdso"); if (vdso != NULL) LOGD("found symbol vdso"); SoInfo::get_realpath_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo12get_realpathEv")); if (SoInfo::get_realpath_sym == NULL) return false; LOGD("found symbol get_realpath_sym"); - SoInfo::get_soname_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo10get_sonameEv")); - if (SoInfo::get_soname_sym == NULL) return false; - LOGD("found symbol get_soname_sym"); - - SoInfo::soinfo_free = reinterpret_cast(linker.getSymbAddress(soinfo_free_name)); + SoInfo::soinfo_free = reinterpret_cast(linker.getSymbAddressByPrefix("__dl__ZL11soinfo_freeP6soinfo")); if (SoInfo::soinfo_free == NULL) return false; LOGD("found symbol soinfo_free"); diff --git a/loader/src/injector/entry.cpp b/loader/src/injector/entry.cpp index a927042..fabe209 100644 --- a/loader/src/injector/entry.cpp +++ b/loader/src/injector/entry.cpp @@ -9,7 +9,7 @@ size_t block_size = 0; extern "C" [[gnu::visibility("default")]] void entry(void* addr, size_t size, const char* path) { - LOGI("Zygisk library injected, version %s", ZKSU_VERSION); + LOGD("Zygisk library injected, version %s", ZKSU_VERSION); start_addr = addr; block_size = size; zygiskd::Init(path); @@ -19,11 +19,7 @@ void entry(void* addr, size_t size, const char* path) { return; } -#ifdef NDEBUG - logging::setfd(zygiskd::RequestLogcatFd()); -#endif - - LOGI("start plt hooking"); + LOGD("start plt hooking"); hook_functions(); clean_trace(path, 1, 0, false); } diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index 5255d37..5b77ba3 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -137,6 +137,36 @@ DCL_HOOK_FUNC(int, fork) { return (g_ctx && g_ctx->pid >= 0) ? g_ctx->pid : old_fork(); } +bool update_mnt_ns(enum mount_namespace_state mns_state, bool dry_run) { + std::string ns_path = zygiskd::UpdateMountNamespace(mns_state); + if (ns_path.empty()) { + PLOGE("Failed to update mount namespace"); + + return false; + } + + if (dry_run) return true; + + int updated_ns = open(ns_path.data(), O_RDONLY); + if (updated_ns == -1) { + PLOGE("Failed to open mount namespace [%s]", ns_path.data()); + + return false; + } + + LOGD("set mount namespace to [%s] fd=[%d]\n", ns_path.data(), updated_ns); + if (setns(updated_ns, CLONE_NEWNS) == -1) { + PLOGE("Failed to set mount namespace [%s]", ns_path.data()); + close(updated_ns); + + return false; + } + + close(updated_ns); + + return true; +} + // Unmount stuffs in the process's private mount namespace DCL_HOOK_FUNC(int, unshare, int flags) { int res = old_unshare(flags); @@ -144,37 +174,22 @@ DCL_HOOK_FUNC(int, unshare, int flags) { // For some unknown reason, unmounting app_process in SysUI can break. // This is reproducible on the official AVD running API 26 and 27. // Simply avoid doing any unmounts for SysUI to avoid potential issues. - (g_ctx->info_flags & PROCESS_IS_SYS_UI) == 0) { - if (g_ctx->flags[DO_REVERT_UNMOUNT]) { - if (g_ctx->info_flags & PROCESS_ROOT_IS_KSU) { - revert_unmount_ksu(); - } else if (g_ctx->info_flags & PROCESS_ROOT_IS_APATCH){ - revert_unmount_apatch(); - } else if (g_ctx->info_flags & PROCESS_ROOT_IS_MAGISK) { - revert_unmount_magisk(); - } + !g_ctx->flags[SERVER_FORK_AND_SPECIALIZE] && !(g_ctx->info_flags & PROCESS_IS_FIRST_STARTED)) { + if (g_ctx->info_flags & (PROCESS_IS_MANAGER | PROCESS_GRANTED_ROOT)) { + update_mnt_ns(Rooted, false); + } else if (!(g_ctx->flags[DO_REVERT_UNMOUNT])) { + update_mnt_ns(Module, false); } - /* Zygisksu changed: No umount app_process */ - - // Restore errno back to 0 - errno = 0; + old_unshare(CLONE_NEWNS); } + + /* INFO: To spoof the errno value */ + errno = 0; + return res; } -// Close logd_fd if necessary to prevent crashing -// For more info, check comments in zygisk_log_write -DCL_HOOK_FUNC(void, android_log_close) { - if (g_ctx == nullptr) { - // Happens during un-managed fork like nativeForkApp, nativeForkUsap - logging::setfd(-1); - } else if (!g_ctx->flags[SKIP_FD_SANITIZATION]) { - logging::setfd(-1); - } - old_android_log_close(); -} - // We cannot directly call `dlclose` to unload ourselves, otherwise when `dlclose` returns, // it will return to our code which has been unmapped, causing segmentation fault. // Instead, we hook `pthread_attr_setstacksize` which will be called when VM daemon threads start. @@ -189,11 +204,13 @@ DCL_HOOK_FUNC(int, pthread_attr_setstacksize, void *target, size_t size) { if (should_unmap_zygisk) { unhook_functions(); cached_map_infos.clear(); + if (should_unmap_zygisk) { // Because both `pthread_attr_setstacksize` and `dlclose` have the same function signature, // we can use `musttail` to let the compiler reuse our stack frame and thus // `dlclose` will directly return to the caller of `pthread_attr_setstacksize`. - LOGI("unmap libzygisk.so loaded at %p with size %zu", start_addr, block_size); + LOGD("unmap libzygisk.so loaded at %p with size %zu", start_addr, block_size); + [[clang::musttail]] return munmap(start_addr, block_size); } } @@ -598,14 +615,18 @@ void ZygiskContext::run_modules_post() { /* Zygisksu changed: Load module fds */ void ZygiskContext::app_specialize_pre() { flags[APP_SPECIALIZE] = true; + info_flags = zygiskd::GetProcessFlags(g_ctx->args.app->uid); + if (info_flags & PROCESS_IS_FIRST_STARTED) { + update_mnt_ns(Clean, true); + } if ((info_flags & PROCESS_ON_DENYLIST) == PROCESS_ON_DENYLIST) { - flags[DO_REVERT_UNMOUNT] = true; + flags[DO_REVERT_UNMOUNT] = true; } if ((info_flags & (PROCESS_IS_MANAGER | PROCESS_ROOT_IS_MAGISK)) == (PROCESS_IS_MANAGER | PROCESS_ROOT_IS_MAGISK)) { - LOGI("Manager process detected. Notifying that Zygisk has been enabled."); + LOGD("Manager process detected. Notifying that Zygisk has been enabled."); setenv("ZYGISK_ENABLED", "1", 1); } else { @@ -620,7 +641,6 @@ void ZygiskContext::app_specialize_post() { // Cleanups env->ReleaseStringUTFChars(args.app->nice_name, process); g_ctx = nullptr; - logging::setfd(-1); } bool ZygiskContext::exempt_fd(int fd) { @@ -653,11 +673,10 @@ void ZygiskContext::nativeForkSystemServer_pre() { flags[SERVER_FORK_AND_SPECIALIZE] = true; fork_pre(); - if (pid != 0) - return; - - run_modules_pre(); - zygiskd::SystemServerStarted(); + if (is_child()) { + run_modules_pre(); + zygiskd::SystemServerStarted(); + } sanitize_fds(); } @@ -673,12 +692,9 @@ void ZygiskContext::nativeForkSystemServer_post() { void ZygiskContext::nativeForkAndSpecialize_pre() { process = env->GetStringUTFChars(args.app->nice_name, nullptr); LOGV("pre forkAndSpecialize [%s]", process); - flags[APP_FORK_AND_SPECIALIZE] = true; - /* Zygisksu changed: No args.app->fds_to_ignore check since we are Android 10+ */ - if (logging::getfd() != -1) { - exempted_fds.push_back(logging::getfd()); - } + + update_mnt_ns(Clean, false); fork_pre(); if (pid == 0) { @@ -805,7 +821,6 @@ void hook_functions() { PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, fork); PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, unshare); PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, strdup); - PLT_HOOK_REGISTER_SYM(android_runtime_dev, android_runtime_inode, "__android_log_close", android_log_close); hook_commit(); // Remove unhooked methods diff --git a/loader/src/injector/module.hpp b/loader/src/injector/module.hpp index 24111fc..f02bd7d 100644 --- a/loader/src/injector/module.hpp +++ b/loader/src/injector/module.hpp @@ -126,13 +126,13 @@ namespace { PROCESS_GRANTED_ROOT = zygisk::StateFlag::PROCESS_GRANTED_ROOT, PROCESS_ON_DENYLIST = zygisk::StateFlag::PROCESS_ON_DENYLIST, - PROCESS_IS_MANAGER = (1u << 28), - PROCESS_ROOT_IS_APATCH = (1u << 27), + PROCESS_IS_MANAGER = (1u << 27), + PROCESS_ROOT_IS_APATCH = (1u << 28), PROCESS_ROOT_IS_KSU = (1u << 29), PROCESS_ROOT_IS_MAGISK = (1u << 30), - PROCESS_IS_SYS_UI = (1u << 31), + PROCESS_IS_FIRST_STARTED = (1u << 31), - PRIVATE_MASK = PROCESS_IS_SYS_UI + PRIVATE_MASK = PROCESS_IS_FIRST_STARTED }; struct api_abi_base { diff --git a/loader/src/injector/unmount.cpp b/loader/src/injector/unmount.cpp deleted file mode 100644 index a657467..0000000 --- a/loader/src/injector/unmount.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include -#include - -#include "files.hpp" -#include "logging.h" -#include "misc.hpp" -#include "zygisk.hpp" - -using namespace std::string_view_literals; - -namespace { - constexpr auto MODULE_DIR = "/data/adb/modules"; - constexpr auto KSU_OVERLAY_SOURCE = "KSU"; - constexpr auto AP_OVERLAY_SOURCE = "APatch"; - const std::vector DEVICE_PARTITIONS{"/system", "/vendor", "/product", "/system_ext", "/odm", "/oem"}; - - void lazy_unmount(const char* mountpoint) { - if (umount2(mountpoint, MNT_DETACH) != -1) { - LOGD("Unmounted (%s)", mountpoint); - } else { -#ifndef NDEBUG - PLOGE("Unmount (%s)", mountpoint); -#endif - } - } -} - -void revert_unmount_ksu() { - std::string ksu_loop; - std::vector targets; - - // Unmount ksu module dir last - targets.emplace_back(MODULE_DIR); - - for (auto& info: parse_mount_info("self")) { - if (info.target == MODULE_DIR) { - ksu_loop = info.source; - continue; - } - - // Unmount everything mounted to /data/adb - if (info.target.starts_with("/data/adb")) { - targets.emplace_back(info.target); - } - - // Unmount everything mounted to /data/adb - if (info.root.starts_with("/adb/modules")) { - targets.emplace_back(info.target); - } - - // Unmount ksu overlays - if (info.type == "overlay" - && info.source == KSU_OVERLAY_SOURCE - && std::find(DEVICE_PARTITIONS.begin(), DEVICE_PARTITIONS.end(), info.target) != DEVICE_PARTITIONS.end()) { - targets.emplace_back(info.target); - } - - // Unmount temp dir - if (info.type == "tmpfs" && info.source == KSU_OVERLAY_SOURCE) { - targets.emplace_back(info.target); - } - } - - for (auto& info: parse_mount_info("self")) { - // Unmount everything from ksu loop except ksu module dir - if (info.source == ksu_loop && info.target != MODULE_DIR) { - targets.emplace_back(info.target); - } - } - - // Do unmount - for (auto& s: reversed(targets)) { - lazy_unmount(s.data()); - } -} - -void revert_unmount_magisk() { - std::vector targets; - - // Unmount dummy skeletons and MAGISKTMP - // since mirror nodes are always mounted under skeleton, we don't have to specifically unmount - for (auto& info: parse_mount_info("self")) { - if (info.source == "magisk" || info.source == "worker" || // magisktmp tmpfs - info.root.starts_with("/adb/modules")) { // bind mount from data partition - targets.push_back(info.target); - } - // Unmount everything mounted to /data/adb - if (info.target.starts_with("/data/adb")) { - targets.emplace_back(info.target); - } - } - - for (auto& s: reversed(targets)) { - lazy_unmount(s.data()); - } -} - -void revert_unmount_apatch() { - std::string ap_loop; - std::vector targets; - - // Unmount ksu module dir last - targets.emplace_back(MODULE_DIR); - - for (auto& info: parse_mount_info("self")) { - if (info.target == MODULE_DIR) { - ap_loop = info.source; - continue; - } - - // Unmount everything mounted to /data/adb - if (info.target.starts_with("/data/adb")) { - targets.emplace_back(info.target); - } - - // Unmount everything mounted to /data/adb - if (info.root.starts_with("/adb/modules")) { - targets.emplace_back(info.target); - } - - // Unmount ksu overlays - if (info.type == "overlay" - && info.source == AP_OVERLAY_SOURCE - && std::find(DEVICE_PARTITIONS.begin(), DEVICE_PARTITIONS.end(), info.target) != DEVICE_PARTITIONS.end()) { - targets.emplace_back(info.target); - } - - // Unmount temp dir - if (info.type == "tmpfs" && info.source == AP_OVERLAY_SOURCE) { - targets.emplace_back(info.target); - } - } - - for (auto& info: parse_mount_info("self")) { - // Unmount everything from ksu loop except ksu module dir - if (info.source == ap_loop && info.target != MODULE_DIR) { - targets.emplace_back(info.target); - } - } - - // Do unmount - for (auto& s: reversed(targets)) { - lazy_unmount(s.data()); - } -} diff --git a/loader/src/injector/zygisk.hpp b/loader/src/injector/zygisk.hpp index 793ba78..d171890 100644 --- a/loader/src/injector/zygisk.hpp +++ b/loader/src/injector/zygisk.hpp @@ -8,9 +8,3 @@ extern size_t block_size; void hook_functions(); void clean_trace(const char* path, size_t load = 1, size_t unload = 0, bool spoof_maps = false); - -void revert_unmount_ksu(); - -void revert_unmount_magisk(); - -void revert_unmount_apatch(); diff --git a/module/src/sepolicy.rule b/module/src/sepolicy.rule index 48669a6..859f87f 100644 --- a/module/src/sepolicy.rule +++ b/module/src/sepolicy.rule @@ -1,21 +1,15 @@ -allow zygote tmpfs file * -allow zygote appdomain_tmpfs file * +type zygisk_file file_type +typeattribute zygisk_file mlstrustedobject +allow zygote zygisk_file sock_file {read write} -type magisk_file file_type -typeattribute magisk_file mlstrustedobject - -allow * magisk_file file * -allow * magisk_file dir * -allow * magisk_file fifo_file * -allow * magisk_file chr_file * -allow * magisk_file lnk_file * -allow * magisk_file sock_file * - -allow system_server system_server process execmem -allow zygote zygote process execmem +allow zygote magisk lnk_file read +allow zygote unlabeled file {read open} +allow zygote zygote capability sys_chroot +allow zygote su dir search +allow zygote su {lnk_file file} read allow zygote adb_data_file dir search -allow zygote mnt_vendor_file dir search -allow zygote system_file dir mounton -allow zygote labeledfs filesystem mount -allow zygote fs_type filesystem unmount +allow zygote zygote process execmem +allow system_server system_server process execmem +allow zygote tmpfs file * +allow zygote appdomain_tmpfs file * diff --git a/zygiskd/build.gradle.kts b/zygiskd/build.gradle.kts index b830189..a3a2984 100644 --- a/zygiskd/build.gradle.kts +++ b/zygiskd/build.gradle.kts @@ -42,7 +42,7 @@ val CFlagsRelease = arrayOf( ) val CFlagsDebug = arrayOf( - "-g", "-O0" + "-g", "-O0", "-DDEBUG" ) val Files = arrayOf( diff --git a/zygiskd/src/constants.h b/zygiskd/src/constants.h index 8342ebb..71e3f29 100644 --- a/zygiskd/src/constants.h +++ b/zygiskd/src/constants.h @@ -7,12 +7,6 @@ #define true 1 #define false 0 -#if DEBUG == false - #define MAX_LOG_LEVEL ANDROID_LOG_VERBOSE -#else - #define MAX_LOG_LEVEL ANDROID_LOG_INFO -#endif - #if (defined(__LP64__) || defined(_LP64)) #define lp_select(a, b) b #else @@ -26,25 +20,24 @@ enum DaemonSocketAction { PingHeartbeat = 0, - RequestLogcatFd = 1, - GetProcessFlags = 2, - GetInfo = 3, - ReadModules = 4, - RequestCompanionSocket = 5, - GetModuleDir = 6, - ZygoteRestart = 7, - SystemServerStarted = 8 + GetProcessFlags = 1, + GetInfo = 2, + ReadModules = 3, + RequestCompanionSocket = 4, + GetModuleDir = 5, + ZygoteRestart = 6, + SystemServerStarted = 7, + GetCleanNamespace = 8 }; enum ProcessFlags: uint32_t { PROCESS_GRANTED_ROOT = (1u << 0), PROCESS_ON_DENYLIST = (1u << 1), - PROCESS_IS_MANAGER = (1u << 28), - PROCESS_ROOT_IS_APATCH = (1u << 27), + PROCESS_IS_MANAGER = (1u << 27), + PROCESS_ROOT_IS_APATCH = (1u << 28), PROCESS_ROOT_IS_KSU = (1u << 29), PROCESS_ROOT_IS_MAGISK = (1u << 30), - PROCESS_IS_SYS_UI = (1u << 31), - PROCESS_IS_SYSUI = (1u << 31) + PROCESS_IS_FIRST_STARTED = (1u << 31) }; enum RootImplState { @@ -54,4 +47,10 @@ enum RootImplState { Abnormal }; +enum MountNamespaceState { + Clean, + Rooted, + Module +}; + #endif /* CONSTANTS_H */ diff --git a/zygiskd/src/root_impl/common.c b/zygiskd/src/root_impl/common.c index e679f55..2198bdc 100644 --- a/zygiskd/src/root_impl/common.c +++ b/zygiskd/src/root_impl/common.c @@ -1,6 +1,9 @@ #include +#include +#include #include +#include #include "../utils.h" #include "kernelsu.h" diff --git a/zygiskd/src/utils.c b/zygiskd/src/utils.c index d0e7eba..6922599 100644 --- a/zygiskd/src/utils.c +++ b/zygiskd/src/utils.c @@ -3,11 +3,13 @@ #include #include #include +#include #include #include #include #include -#include +#include +#include #include #include @@ -18,6 +20,11 @@ #include "utils.h" #include "root_impl/common.h" +#include "root_impl/magisk.h" + +int clean_namespace_fd = 0; +int rooted_namespace_fd = 0; +int module_namespace_fd = 0; bool switch_mount_namespace(pid_t pid) { char path[PATH_MAX]; @@ -184,7 +191,7 @@ int unix_listener_from_path(char *restrict path) { return -1; } - if (chcon(path, "u:object_r:magisk_file:s0") == -1) { + if (chcon(path, "u:object_r:zygisk_file:s0") == -1) { LOGE("chcon: %s\n", strerror(errno)); return -1; @@ -450,3 +457,381 @@ void stringify_root_impl_name(struct root_impl impl, char *restrict output) { } } } + +struct mountinfo { + unsigned int id; + unsigned int parent; + dev_t device; + const char *root; + const char *target; + const char *vfs_option; + struct { + unsigned int shared; + unsigned int master; + unsigned int propagate_from; + } optional; + const char *type; + const char *source; + const char *fs_option; +}; + +struct mountinfos { + struct mountinfo *mounts; + size_t length; +}; + +char *strndup(const char *restrict str, size_t length) { + char *restrict copy = malloc(length + 1); + if (copy == NULL) return NULL; + + memcpy(copy, str, length); + copy[length] = '\0'; + + return copy; +} + +void free_mounts(struct mountinfos *restrict mounts) { + for (size_t i = 0; i < mounts->length; i++) { + free((void *)mounts->mounts[i].root); + free((void *)mounts->mounts[i].target); + free((void *)mounts->mounts[i].vfs_option); + free((void *)mounts->mounts[i].type); + free((void *)mounts->mounts[i].source); + free((void *)mounts->mounts[i].fs_option); + } + + free((void *)mounts->mounts); +} + +bool parse_mountinfo(const char *restrict pid, struct mountinfos *restrict mounts) { + char path[PATH_MAX]; + snprintf(path, PATH_MAX, "/proc/%s/mountinfo", pid); + + FILE *mountinfo = fopen(path, "r"); + if (mountinfo == NULL) { + LOGE("fopen: %s\n", strerror(errno)); + + return false; + } + + char line[PATH_MAX]; + size_t i = 0; + + mounts->mounts = NULL; + mounts->length = 0; + + while (fgets(line, sizeof(line), mountinfo) != NULL) { + int root_start = 0, root_end = 0; + int target_start = 0, target_end = 0; + int vfs_option_start = 0, vfs_option_end = 0; + int type_start = 0, type_end = 0; + int source_start = 0, source_end = 0; + int fs_option_start = 0, fs_option_end = 0; + int optional_start = 0, optional_end = 0; + unsigned int id, parent, maj, min; + sscanf(line, + "%u " // (1) id + "%u " // (2) parent + "%u:%u " // (3) maj:min + "%n%*s%n " // (4) mountroot + "%n%*s%n " // (5) target + "%n%*s%n" // (6) vfs options (fs-independent) + "%n%*[^-]%n - " // (7) optional fields + "%n%*s%n " // (8) FS type + "%n%*s%n " // (9) source + "%n%*s%n", // (10) fs options (fs specific) + &id, &parent, &maj, &min, &root_start, &root_end, &target_start, + &target_end, &vfs_option_start, &vfs_option_end, + &optional_start, &optional_end, &type_start, &type_end, + &source_start, &source_end, &fs_option_start, &fs_option_end); + + mounts->mounts = (struct mountinfo *)realloc(mounts->mounts, (i + 1) * sizeof(struct mountinfo)); + if (!mounts->mounts) { + LOGE("Failed to allocate memory for mounts->mounts"); + + fclose(mountinfo); + free_mounts(mounts); + + return false; + } + + unsigned int shared = 0; + unsigned int master = 0; + unsigned int propagate_from = 0; + if (strstr(line + optional_start, "shared:")) { + shared = (unsigned int)atoi(strstr(line + optional_start, "shared:") + 7); + } + + if (strstr(line + optional_start, "master:")) { + master = (unsigned int)atoi(strstr(line + optional_start, "master:") + 7); + } + + if (strstr(line + optional_start, "propagate_from:")) { + propagate_from = (unsigned int)atoi(strstr(line + optional_start, "propagate_from:") + 15); + } + + mounts->mounts[i].id = id; + mounts->mounts[i].parent = parent; + mounts->mounts[i].device = (dev_t)(makedev(maj, min)); + mounts->mounts[i].root = strndup(line + root_start, (size_t)(root_end - root_start)); + mounts->mounts[i].target = strndup(line + target_start, (size_t)(target_end - target_start)); + mounts->mounts[i].vfs_option = strndup(line + vfs_option_start, (size_t)(vfs_option_end - vfs_option_start)); + mounts->mounts[i].optional.shared = shared; + mounts->mounts[i].optional.master = master; + mounts->mounts[i].optional.propagate_from = propagate_from; + mounts->mounts[i].type = strndup(line + type_start, (size_t)(type_end - type_start)); + mounts->mounts[i].source = strndup(line + source_start, (size_t)(source_end - source_start)); + mounts->mounts[i].fs_option = strndup(line + fs_option_start, (size_t)(fs_option_end - fs_option_start)); + + i++; + } + + fclose(mountinfo); + + mounts->length = i; + + return true; +} + +enum mns_umount_state { + Complete, + NotComplete, + Error +}; + +enum mns_umount_state unmount_root(bool modules_only, struct root_impl impl) { + /* INFO: We are already in the target pid mount namespace, so actually, + when we use self here, we meant its pid. + */ + struct mountinfos mounts; + if (!parse_mountinfo("self", &mounts)) { + LOGE("Failed to parse mountinfo\n"); + + return Error; + } + + /* INFO: Implementations like Magisk Kitsune will mount MagiskSU when boot is completed, + so if we cache the clean mount done before the boot is completed, it will get + it mounted later and hence it will leak mounts. To avoid that we will detect + if implementation is Kitsune, and if so, see if /system/bin... is mounted, + if not, it won't cache this namespace. */ + bool magiskSU_umounted = false; + + switch (impl.impl) { + case None: { break; } + case Multiple: { break; } + + case KernelSU: + case APatch: { + char source_name[LONGEST_ROOT_IMPL_NAME]; + if (impl.impl == KernelSU) strcpy(source_name, "KSU"); + else strcpy(source_name, "APatch"); + + const char **targets_to_unmount = NULL; + size_t num_targets = 0; + + for (size_t i = 0; i < mounts.length; i++) { + struct mountinfo mount = mounts.mounts[i]; + + bool should_unmount = false; + + if (modules_only) { + if (strncmp(mount.target, "/debug_ramdisk", strlen("/debug_ramdisk")) == 0) + should_unmount = true; + } else { + if (strcmp(mount.source, source_name) == 0) should_unmount = true; + if (strncmp(mount.root, "/adb/modules", strlen("/adb/modules")) == 0) should_unmount = true; + if (strncmp(mount.target, "/data/adb/modules", strlen("/data/adb/modules")) == 0) should_unmount = true; + } + + if (!should_unmount) continue; + + num_targets++; + targets_to_unmount = realloc(targets_to_unmount, num_targets * sizeof(char*)); + if (targets_to_unmount == NULL) { + LOGE("[%s] Failed to allocate memory for targets_to_unmount\n", source_name); + + free(targets_to_unmount); + free_mounts(&mounts); + + return Error; + } + + targets_to_unmount[num_targets - 1] = mount.target; + } + + for (size_t i = num_targets; i > 0; i--) { + const char *target = targets_to_unmount[i - 1]; + + if (umount2(target, MNT_DETACH) == -1) { + LOGE("[%s] Failed to unmount %s: %s\n", source_name, target, strerror(errno)); + } else { + LOGI("[%s] Unmounted %s\n", source_name, target); + } + } + free(targets_to_unmount); + + break; + } + case Magisk: { + LOGI("[Magisk] Unmounting root %s modules\n", modules_only ? "only" : "with"); + + const char **targets_to_unmount = NULL; + size_t num_targets = 0; + + for (size_t i = 0; i < mounts.length; i++) { + struct mountinfo mount = mounts.mounts[i]; + + bool should_unmount = false; + if ( + ( + modules_only && + ( + strcmp(mount.source, "magisk") == 0 || + strncmp(mount.target, "/debug_ramdisk", strlen("/debug_ramdisk")) == 0 || + strncmp(mount.target, "/system/bin", strlen("/system/bin")) == 0 + ) + ) || + ( + !modules_only && + ( + strcmp(mount.source, "magisk") == 0 || + strncmp(mount.target, "/debug_ramdisk", strlen("/debug_ramdisk")) == 0 || + strncmp(mount.target, "/data/adb/modules", strlen("/data/adb/modules")) == 0 || + strncmp(mount.root, "/adb/modules", strlen("/adb/modules")) == 0 || + strncmp(mount.target, "/system/bin", strlen("/system/bin")) == 0 + ) + ) + ) { + should_unmount = true; + } + + if (!should_unmount) continue; + + num_targets++; + targets_to_unmount = realloc(targets_to_unmount, num_targets * sizeof(char*)); + if (targets_to_unmount == NULL) { + LOGE("[Magisk] Failed to allocate memory for targets_to_unmount\n"); + + free(targets_to_unmount); + free_mounts(&mounts); + + return Error; + } + + targets_to_unmount[num_targets - 1] = mount.target; + + if (impl.impl == Magisk && strncmp(mount.target, "/system/bin", strlen("/system/bin")) == 0) + magiskSU_umounted = true; + } + + for (size_t i = num_targets; i > 0; i--) { + const char *target = targets_to_unmount[i - 1]; + if (umount2(target, MNT_DETACH) == -1) { + LOGE("[Magisk] Failed to unmount %s: %s\n", target, strerror(errno)); + } else { + LOGI("[Magisk] Unmounted %s\n", target); + } + } + free(targets_to_unmount); + + break; + } + } + + free_mounts(&mounts); + + return (impl.impl == Magisk && !magiskSU_umounted) ? NotComplete : Complete; +} + +int save_mns_fd(int pid, enum MountNamespaceState mns_state, struct root_impl impl) { + if (mns_state == Clean && clean_namespace_fd != 0) return clean_namespace_fd; + if (mns_state == Rooted && rooted_namespace_fd != 0) return rooted_namespace_fd; + if (mns_state == Module && module_namespace_fd != 0) return module_namespace_fd; + + int sockets[2]; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1) { + LOGE("socketpair: %s\n", strerror(errno)); + + return -1; + } + + int reader = sockets[0]; + int writer = sockets[1]; + + pid_t fork_pid = fork(); + if (fork_pid == 0) { + switch_mount_namespace(pid); + + enum mns_umount_state umount_state = Complete; + + if (mns_state != Rooted) { + unshare(CLONE_NEWNS); + umount_state = unmount_root(mns_state == Module, impl); + if (umount_state == Error) { + write_uint8_t(writer, (uint8_t)umount_state); + + _exit(1); + } + } + + uint32_t mypid = 0; + while (mypid != (uint32_t)getpid()) { + write_uint8_t(writer, (uint8_t)umount_state); + usleep(50); + read_uint32_t(reader, &mypid); + } + + _exit(0); + } else if (fork_pid > 0) { + enum mns_umount_state umount_state = (enum mns_umount_state)0; + read_uint8_t(reader, (uint8_t *)&umount_state); + + if (umount_state == Error) { + LOGE("Failed to unmount root\n"); + + return -1; + } + + char ns_path[PATH_MAX]; + snprintf(ns_path, PATH_MAX, "/proc/%d/ns/mnt", fork_pid); + + int ns_fd = open(ns_path, O_RDONLY); + if (ns_fd == -1) { + LOGE("open: %s\n", strerror(errno)); + + return -1; + } + + write_uint32_t(writer, (uint32_t)fork_pid); + + if (close(reader) == -1) { + LOGE("Failed to close reader: %s\n", strerror(errno)); + + return -1; + } + + if (close(writer) == -1) { + LOGE("Failed to close writer: %s\n", strerror(errno)); + + return -1; + } + + if (waitpid(fork_pid, NULL, 0) == -1) { + LOGE("waitpid: %s\n", strerror(errno)); + + return -1; + } + + if (mns_state == Rooted) return (rooted_namespace_fd = ns_fd); + else if (mns_state == Clean && umount_state == Complete) return (clean_namespace_fd = ns_fd); + else if (mns_state == Module && umount_state == Complete) return (module_namespace_fd = ns_fd); + else return ns_fd; + } else { + LOGE("fork: %s\n", strerror(errno)); + + return -1; + } + + return -1; +} diff --git a/zygiskd/src/utils.h b/zygiskd/src/utils.h index 7cc6bbf..1d8bebb 100644 --- a/zygiskd/src/utils.h +++ b/zygiskd/src/utils.h @@ -107,4 +107,6 @@ int non_blocking_execv(const char *restrict file, char *const argv[]); void stringify_root_impl_name(struct root_impl impl, char *restrict output); +int save_mns_fd(int pid, enum MountNamespaceState mns_state, struct root_impl impl); + #endif /* UTILS_H */ diff --git a/zygiskd/src/zygiskd.c b/zygiskd/src/zygiskd.c index 0c0d952..429c143 100644 --- a/zygiskd/src/zygiskd.c +++ b/zygiskd/src/zygiskd.c @@ -382,6 +382,7 @@ void zygiskd_start(char *restrict argv[]) { return; } + bool first_process = true; while (1) { int client_fd = accept(socket_fd, NULL, NULL); if (client_fd == -1) { @@ -437,51 +438,26 @@ void zygiskd_start(char *restrict argv[]) { break; } - /* TODO: Move to another thread and save client fds to an epoll list - so that we can, in a single-thread, deal with multiple logcats */ - case RequestLogcatFd: { - uint8_t level = 0; - ssize_t ret = read_uint8_t(client_fd, &level); - ASSURE_SIZE_READ_BREAK("RequestLogcatFd", "level", ret, sizeof(level)); - - char tag[128 + 1]; - ret = read_string(client_fd, tag, sizeof(tag)); - if (ret == -1) { - LOGE("Failed reading logcat tag.\n"); - - close(client_fd); - - break; - } - - char message[1024 + 1]; - ret = read_string(client_fd, message, sizeof(message)); - if (ret == -1) { - LOGE("Failed reading logcat message.\n"); - - close(client_fd); - - break; - } - - __android_log_print(level, tag, "%s", message); - - break; - } case GetProcessFlags: { uint32_t uid = 0; ssize_t ret = read_uint32_t(client_fd, &uid); ASSURE_SIZE_READ_BREAK("GetProcessFlags", "uid", ret, sizeof(uid)); uint32_t flags = 0; - if (uid_is_manager(uid)) { - flags |= PROCESS_IS_MANAGER; + if (first_process) { + flags |= PROCESS_IS_FIRST_STARTED; + + first_process = false; } else { - if (uid_granted_root(uid)) { - flags |= PROCESS_GRANTED_ROOT; - } - if (uid_should_umount(uid)) { - flags |= PROCESS_ON_DENYLIST; + if (uid_is_manager(uid)) { + flags |= PROCESS_IS_MANAGER; + } else { + if (uid_granted_root(uid)) { + flags |= PROCESS_GRANTED_ROOT; + } + if (uid_should_umount(uid)) { + flags |= PROCESS_ON_DENYLIST; + } } } @@ -671,11 +647,35 @@ void zygiskd_start(char *restrict argv[]) { break; } + break; + } + case GetCleanNamespace: { + pid_t pid = 0; + ssize_t ret = read_uint32_t(client_fd, (uint32_t *)&pid); + ASSURE_SIZE_READ_BREAK("GetCleanNamespace", "pid", ret, sizeof(pid)); + + uint8_t mns_state = 0; + ret = read_uint8_t(client_fd, &mns_state); + ASSURE_SIZE_READ_BREAK("GetCleanNamespace", "mns_state", ret, sizeof(mns_state)); + + uint32_t our_pid = (uint32_t)getpid(); + ret = write_uint32_t(client_fd, (uint32_t)our_pid); + ASSURE_SIZE_WRITE_BREAK("GetCleanNamespace", "our_pid", ret, sizeof(our_pid)); + + if ((enum MountNamespaceState)mns_state == Clean) { + save_mns_fd(pid, Rooted, impl); + save_mns_fd(pid, Module, impl); + } + + uint32_t clean_namespace_fd = (uint32_t)save_mns_fd(pid, (enum MountNamespaceState)mns_state, impl); + ret = write_uint32_t(client_fd, clean_namespace_fd); + ASSURE_SIZE_WRITE_BREAK("GetCleanNamespace", "clean_namespace_fd", ret, sizeof(clean_namespace_fd)); + break; } } - if (action != RequestCompanionSocket && action != RequestLogcatFd) close(client_fd); + if (action != RequestCompanionSocket) close(client_fd); continue; } From 52885faf8b1f8c0598a8b6b802c9cfb7aed27aad Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Sat, 5 Apr 2025 15:36:39 -0300 Subject: [PATCH 31/46] remove: `dl.cpp` file and replace with "dlopen" This commit replaces DlopenMem for dlopen, removing the need for "dl.cpp" file. --- loader/src/common/daemon.cpp | 5 +-- loader/src/common/dl.cpp | 77 ------------------------------------ loader/src/include/daemon.h | 5 ++- loader/src/include/dl.h | 7 ---- loader/src/injector/hook.cpp | 50 +++++++++++++---------- zygiskd/src/zygiskd.c | 22 +++++++++-- 6 files changed, 52 insertions(+), 114 deletions(-) delete mode 100644 loader/src/common/dl.cpp delete mode 100644 loader/src/include/dl.h diff --git a/loader/src/common/daemon.cpp b/loader/src/common/daemon.cpp index bd558ca..44c7660 100644 --- a/loader/src/common/daemon.cpp +++ b/loader/src/common/daemon.cpp @@ -7,7 +7,6 @@ #include #include "daemon.h" -#include "dl.h" #include "socket_utils.h" namespace zygiskd { @@ -93,9 +92,9 @@ namespace zygiskd { socket_utils::write_u8(fd, (uint8_t) SocketAction::ReadModules); size_t len = socket_utils::read_usize(fd); for (size_t i = 0; i < len; i++) { + std::string lib_path = socket_utils::read_string(fd); std::string name = socket_utils::read_string(fd); - int module_fd = socket_utils::recv_fd(fd); - modules.emplace_back(name, module_fd); + modules.emplace_back(lib_path, name); } close(fd); diff --git a/loader/src/common/dl.cpp b/loader/src/common/dl.cpp deleted file mode 100644 index 352b8f9..0000000 --- a/loader/src/common/dl.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "dl.h" -#include "files.hpp" -#include "logging.h" - -extern "C" [[gnu::weak]] struct android_namespace_t* -//NOLINTNEXTLINE -__loader_android_create_namespace([[maybe_unused]] const char* name, - [[maybe_unused]] const char* ld_library_path, - [[maybe_unused]] const char* default_library_path, - [[maybe_unused]] uint64_t type, - [[maybe_unused]] const char* permitted_when_isolated_path, - [[maybe_unused]] android_namespace_t* parent, - [[maybe_unused]] const void* caller_addr); - -void* DlopenExt(const char* path, int flags) { - auto info = android_dlextinfo{}; - auto* dir = dirname(path); - auto* ns = &__loader_android_create_namespace == nullptr ? nullptr : - __loader_android_create_namespace(path, dir, nullptr, - 2, /* ANDROID_NAMESPACE_TYPE_SHARED */ - nullptr, nullptr, - reinterpret_cast(&DlopenExt)); - if (ns) { - info.flags = ANDROID_DLEXT_USE_NAMESPACE; - info.library_namespace = ns; - - LOGD("Open %s with namespace %p", path, ns); - } else { - LOGD("Cannot create namespace for %s", path); - } - - auto* handle = android_dlopen_ext(path, flags, &info); - if (handle) { - LOGD("dlopen %s: %p", path, handle); - } else { - LOGE("dlopen %s: %s", path, dlerror()); - } - return handle; -} - -void* DlopenMem(int fd, int flags) { - auto info = android_dlextinfo { - .flags = ANDROID_DLEXT_USE_LIBRARY_FD, - .reserved_addr = NULL, - .reserved_size = 0, - .relro_fd = 0, - .library_fd = fd, - .library_fd_offset = 0, - .library_namespace = NULL - }; - - /* INFO: We need to find the path of the fd since passing "" to android_dlopen_ext - will not work and passing the original "jit-cache-zygisk" will cause a detection again. */ - char path[PATH_MAX]; - if (get_path_from_fd(fd, path, sizeof(path)) != 0) { - LOGE("Failed to get path for fd: %d", fd); - return NULL; - } - - LOGD("Path for fd %d: %s", fd, path); - - auto *handle = android_dlopen_ext(path, flags, &info); - if (handle) { - LOGV("dlopen fd %d: %p", fd, handle); - } else { - LOGE("dlopen fd %d: %s", fd, dlerror()); - } - - return handle; -} diff --git a/loader/src/include/daemon.h b/loader/src/include/daemon.h index dad3c18..9bc3617 100644 --- a/loader/src/include/daemon.h +++ b/loader/src/include/daemon.h @@ -70,10 +70,11 @@ enum mount_namespace_state { namespace zygiskd { struct ModuleInfo { + std::string path; + /* TODO: Perhaps we can also remove this and just send paths? */ std::string name; - UniqueFd memfd; - inline explicit ModuleInfo(std::string name, int memfd) : name(name), memfd(memfd) {} + inline explicit ModuleInfo(std::string path, std::string name) : path(path), name(name) {} }; enum class SocketAction { diff --git a/loader/src/include/dl.h b/loader/src/include/dl.h deleted file mode 100644 index 25dd6c6..0000000 --- a/loader/src/include/dl.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -void *DlopenExt(const char *path, int flags); - -void *DlopenMem(int memfd, int flags); diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index 5b77ba3..c3282c1 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -15,7 +15,6 @@ #include #include -#include "dl.h" #include "daemon.h" #include "zygisk.hpp" #include "module.hpp" @@ -573,24 +572,35 @@ void ZygiskContext::fork_post() { /* Zygisksu changed: Load module fds */ void ZygiskContext::run_modules_pre() { - auto ms = zygiskd::ReadModules(); - auto size = ms.size(); - for (size_t i = 0; i < size; i++) { - auto& m = ms[i]; - if (void* handle = DlopenMem(m.memfd, RTLD_NOW); - void* entry = handle ? dlsym(handle, "zygisk_module_entry") : nullptr) { - modules.emplace_back(i, handle, entry); - } + auto ms = zygiskd::ReadModules(); + auto size = ms.size(); + for (size_t i = 0; i < size; i++) { + auto &m = ms[i]; + + void *handle = dlopen(m.path.c_str(), RTLD_NOW); + if (!handle) { + LOGE("Failed to load module [%s]: %s", m.path.c_str(), dlerror()); + + continue; } - for (auto &m : modules) { - m.onLoad(env); - if (flags[APP_SPECIALIZE]) { - m.preAppSpecialize(args.app); - } else if (flags[SERVER_FORK_AND_SPECIALIZE]) { - m.preServerSpecialize(args.server); - } + void *entry = dlsym(handle, "zygisk_module_entry"); + if (!entry) { + LOGE("Failed to find entry point in module [%s]: %s", m.path.c_str(), dlerror()); + + dlclose(handle); + + continue; } + + modules.emplace_back(i, handle, entry); + } + + for (auto &m : modules) { + m.onLoad(env); + if (flags[APP_SPECIALIZE]) m.preAppSpecialize(args.app); + else if (flags[SERVER_FORK_AND_SPECIALIZE]) m.preServerSpecialize(args.server); + } } void ZygiskContext::run_modules_post() { @@ -598,11 +608,9 @@ void ZygiskContext::run_modules_post() { size_t modules_unloaded = 0; for (const auto &m : modules) { - if (flags[APP_SPECIALIZE]) { - m.postAppSpecialize(args.app); - } else if (flags[SERVER_FORK_AND_SPECIALIZE]) { - m.postServerSpecialize(args.server); - } + if (flags[APP_SPECIALIZE]) m.postAppSpecialize(args.app); + else if (flags[SERVER_FORK_AND_SPECIALIZE]) m.postServerSpecialize(args.server); + if (m.tryUnload()) modules_unloaded++; } diff --git a/zygiskd/src/zygiskd.c b/zygiskd/src/zygiskd.c index 429c143..44fa9fc 100644 --- a/zygiskd/src/zygiskd.c +++ b/zygiskd/src/zygiskd.c @@ -537,14 +537,28 @@ void zygiskd_start(char *restrict argv[]) { ssize_t ret = write_size_t(client_fd, clen); ASSURE_SIZE_WRITE_BREAK("ReadModules", "len", ret, sizeof(clen)); + enum Architecture arch = get_arch(); + + char arch_str[32]; + switch (arch) { + case ARM64: { strcpy(arch_str, "arm64-v8a"); break; } + case X86_64: { strcpy(arch_str, "x86_64"); break; } + case ARM32: { strcpy(arch_str, "armeabi-v7a"); break; } + case X86: { strcpy(arch_str, "x86"); break; } + } + for (size_t i = 0; i < clen; i++) { - if (write_string(client_fd, context.modules[i].name) == -1) { - LOGE("Failed writing module name.\n"); + char lib_path[PATH_MAX]; + snprintf(lib_path, PATH_MAX, "/data/adb/modules/%s/zygisk/%s.so", context.modules[i].name, arch_str); + + if (write_string(client_fd, lib_path) == -1) { + LOGE("Failed writing module path.\n"); break; } - if (write_fd(client_fd, context.modules[i].lib_fd) == -1) { - LOGE("Failed writing module fd.\n"); + + if (write_string(client_fd, context.modules[i].name) == -1) { + LOGE("Failed writing module name.\n"); break; } From 4625587ea9ff6d5af6c4212e8ad30aa8d67e6eab Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Mon, 31 Mar 2025 19:30:21 -0300 Subject: [PATCH 32/46] improve: ELF utils and SoList code This commit improves the code related to ELF and SoList, porting them to C. --- loader/src/common/elf_util.c | 396 +++++++++++++++++++++++++++++++++ loader/src/common/elf_util.cpp | 263 ---------------------- loader/src/include/elf_util.h | 184 +++++---------- loader/src/include/solist.h | 66 ++++++ loader/src/include/solist.hpp | 211 ------------------ loader/src/injector/hook.cpp | 11 +- loader/src/injector/solist.c | 236 ++++++++++++++++++++ 7 files changed, 759 insertions(+), 608 deletions(-) create mode 100644 loader/src/common/elf_util.c delete mode 100644 loader/src/common/elf_util.cpp create mode 100644 loader/src/include/solist.h delete mode 100644 loader/src/include/solist.hpp create mode 100644 loader/src/injector/solist.c diff --git a/loader/src/common/elf_util.c b/loader/src/common/elf_util.c new file mode 100644 index 0000000..bfe89ba --- /dev/null +++ b/loader/src/common/elf_util.c @@ -0,0 +1,396 @@ +/* INFO: This file is written in C99 */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "logging.h" + +#include "elf_util.h" + +#define SHT_GNU_HASH 0x6ffffff6 + +uint32_t ElfHash(const char *name) { + uint32_t h = 0, g = 0; + + while (*name) { + h = (h << 4) + (unsigned char)*name++; + g = h & 0xf0000000; + + if (g) { + h ^= g >> 24; + } + + h &= ~g; + } + + return h; +} + +uint32_t GnuHash(const char *name) { + uint32_t h = 5381; + + while (*name) { + h = (h << 5) + h + (unsigned char)(*name++); + } + + return h; +} + +ElfW(Shdr) *offsetOf_Shdr(ElfW(Ehdr) * head, ElfW(Off) off) { + return (ElfW(Shdr) *)(((uintptr_t)head) + off); +} + +char *offsetOf_char(ElfW(Ehdr) * head, ElfW(Off) off) { + return (char *)(((uintptr_t)head) + off); +} + +ElfW(Sym) *offsetOf_Sym(ElfW(Ehdr) * head, ElfW(Off) off) { + return (ElfW(Sym) *)(((uintptr_t)head) + off); +} + +ElfW(Word) *offsetOf_Word(ElfW(Ehdr) * head, ElfW(Off) off) { + return (ElfW(Word) *)(((uintptr_t)head) + off); +} + +int dl_cb(struct dl_phdr_info *info, size_t size, void *data) { + (void) size; + + if ((info)->dlpi_name == NULL) return 0; + + ElfImg *img = (ElfImg *)data; + + if (strstr(info->dlpi_name, img->elf)) { + img->elf = strdup(info->dlpi_name); + img->base = (void *)info->dlpi_addr; + + return 1; + } + + return 0; +} + +bool find_module_base(ElfImg *img) { + dl_iterate_phdr(dl_cb, img); + + return img->base != NULL; +} + +size_t calculate_valid_symtabs_amount(ElfImg *img) { + size_t count = 0; + + if (img->symtab_start == NULL || img->symstr_offset_for_symtab == 0) return count; + + for (ElfW(Off) i = 0; i < img->symtab_count; i++) { + unsigned int st_type = ELF_ST_TYPE(img->symtab_start[i].st_info); + + if ((st_type == STT_FUNC || st_type == STT_OBJECT) && img->symtab_start[i].st_size) + count++; + } + + return count; +} + +void ElfImg_destroy(ElfImg *img) { + if (img->elf) { + free(img->elf); + img->elf = NULL; + } + + if (img->symtabs_) { + size_t valid_symtabs_amount = calculate_valid_symtabs_amount(img); + if (valid_symtabs_amount == 0) goto finalize; + + for (size_t i = 0; i < valid_symtabs_amount; i++) { + free(img->symtabs_[i].name); + } + + free(img->symtabs_); + img->symtabs_ = NULL; + } + + if (img->header) { + munmap(img->header, img->size); + img->header = NULL; + } + + finalize: + free(img); + img = NULL; +} + +ElfImg *ElfImg_create(const char *elf) { + ElfImg *img = (ElfImg *)calloc(1, sizeof(ElfImg)); + if (!img) { + LOGE("Failed to allocate memory for ElfImg"); + + return NULL; + } + + img->bias = -4396; + img->elf = strdup(elf); + img->base = NULL; + + if (!find_module_base(img)) { + LOGE("Failed to find module base for %s", img->elf); + + ElfImg_destroy(img); + + return NULL; + } + + int fd = open(img->elf, O_RDONLY); + if (fd < 0) { + LOGE("failed to open %s", img->elf); + + ElfImg_destroy(img); + + return NULL; + } + + img->size = lseek(fd, 0, SEEK_END); + if (img->size <= 0) { + LOGE("lseek() failed for %s", img->elf); + + ElfImg_destroy(img); + + return NULL; + } + + img->header = (ElfW(Ehdr) *)mmap(NULL, img->size, PROT_READ, MAP_SHARED, fd, 0); + + close(fd); + + img->section_header = offsetOf_Shdr(img->header, img->header->e_shoff); + + uintptr_t shoff = (uintptr_t)img->section_header; + char *section_str = offsetOf_char(img->header, img->section_header[img->header->e_shstrndx].sh_offset); + + for (int i = 0; i < img->header->e_shnum; i++, shoff += img->header->e_shentsize) { + ElfW(Shdr) *section_h = (ElfW(Shdr *))shoff; + + char *sname = section_h->sh_name + section_str; + size_t entsize = section_h->sh_entsize; + + switch (section_h->sh_type) { + case SHT_DYNSYM: { + if (img->bias == -4396) { + img->dynsym = section_h; + img->dynsym_offset = section_h->sh_offset; + img->dynsym_start = offsetOf_Sym(img->header, img->dynsym_offset); + } + + break; + } + case SHT_SYMTAB: { + if (strcmp(sname, ".symtab") == 0) { + img->symtab = section_h; + img->symtab_offset = section_h->sh_offset; + img->symtab_size = section_h->sh_size; + img->symtab_count = img->symtab_size / entsize; + img->symtab_start = offsetOf_Sym(img->header, img->symtab_offset); + } + + break; + } + case SHT_STRTAB: { + if (img->bias == -4396) { + img->strtab = section_h; + img->symstr_offset = section_h->sh_offset; + img->strtab_start = offsetOf_Sym(img->header, img->symstr_offset); + } + + if (strcmp(sname, ".strtab") == 0) { + img->symstr_offset_for_symtab = section_h->sh_offset; + } + + break; + } + case SHT_PROGBITS: { + if (img->strtab == NULL || img->dynsym == NULL) + break; + + if (img->bias == -4396) { + img->bias = (off_t)section_h->sh_addr - (off_t)section_h->sh_offset; + } + + break; + } + case SHT_HASH: { + ElfW(Word) *d_un = offsetOf_Word(img->header, section_h->sh_offset); + img->nbucket_ = d_un[0]; + img->bucket_ = d_un + 2; + img->chain_ = img->bucket_ + img->nbucket_; + + break; + } + case SHT_GNU_HASH: { + ElfW(Word) *d_buf = (ElfW(Word) *)(((size_t)img->header) + section_h->sh_offset); + img->gnu_nbucket_ = d_buf[0]; + img->gnu_symndx_ = d_buf[1]; + img->gnu_bloom_size_ = d_buf[2]; + img->gnu_shift2_ = d_buf[3]; + img->gnu_bloom_filter_ = (uintptr_t *)(d_buf + 4); + img->gnu_bucket_ = (uint32_t *)(img->gnu_bloom_filter_ + img->gnu_bloom_size_); + img->gnu_chain_ = img->gnu_bucket_ + img->gnu_nbucket_ - img->gnu_symndx_; + + break; + } + } + } + + return img; +} + +ElfW(Addr) ElfLookup(ElfImg *restrict img, const char *restrict name, uint32_t hash) { + if (img->nbucket_ == 0) + return 0; + + char *strings = (char *)img->strtab_start; + + for (size_t n = img->bucket_[hash % img->nbucket_]; n != 0; n = img->chain_[n]) { + ElfW(Sym) *sym = img->dynsym_start + n; + + if (strncmp(name, strings + sym->st_name, strlen(name)) == 0) + return sym->st_value; + } + return 0; +} + +ElfW(Addr) GnuLookup(ElfImg *restrict img, const char *name, uint32_t hash) { + static size_t bloom_mask_bits = sizeof(ElfW(Addr)) * 8; + + if (img->gnu_nbucket_ == 0 || img->gnu_bloom_size_ == 0) + return 0; + + size_t bloom_word = + img->gnu_bloom_filter_[(hash / bloom_mask_bits) % img->gnu_bloom_size_]; + uintptr_t mask = 0 | (uintptr_t)1 << (hash % bloom_mask_bits) | + (uintptr_t)1 << ((hash >> img->gnu_shift2_) % bloom_mask_bits); + if ((mask & bloom_word) == mask) { + size_t sym_index = img->gnu_bucket_[hash % img->gnu_nbucket_]; + if (sym_index >= img->gnu_symndx_) { + char *strings = (char *)img->strtab_start; + do { + ElfW(Sym) *sym = img->dynsym_start + sym_index; + + if (((img->gnu_chain_[sym_index] ^ hash) >> 1) == 0 && + name == strings + sym->st_name) { + return sym->st_value; + } + } while ((img->gnu_chain_[sym_index++] & 1) == 0); + } + } + + return 0; +} + +ElfW(Addr) LinearLookup(ElfImg *img, const char *restrict name) { + size_t valid_symtabs_amount = calculate_valid_symtabs_amount(img); + if (valid_symtabs_amount == 0) return 0; + + if (!img->symtabs_) { + img->symtabs_ = (struct symtabs *)calloc(1, sizeof(struct symtabs) * valid_symtabs_amount); + if (!img->symtabs_) return 0; + + + if (img->symtab_start != NULL && img->symstr_offset_for_symtab != 0) { + ElfW(Off) i = 0; + for (ElfW(Off) pos = 0; pos < img->symtab_count; pos++) { + unsigned int st_type = ELF_ST_TYPE(img->symtab_start[pos].st_info); + const char *st_name = offsetOf_char(img->header, img->symstr_offset_for_symtab + img->symtab_start[pos].st_name); + + if ((st_type == STT_FUNC || st_type == STT_OBJECT) && img->symtab_start[pos].st_size) { + img->symtabs_[i].name = strdup(st_name); + img->symtabs_[i].sym = &img->symtab_start[pos]; + + i++; + } + } + } + } + + for (size_t i = 0; i < valid_symtabs_amount; i++) { + if (strcmp(name, img->symtabs_[i].name) != 0) continue; + + return img->symtabs_[i].sym->st_value; + } + + return 0; +} + +ElfW(Addr) LinearLookupByPrefix(ElfImg *img, const char *name) { + size_t valid_symtabs_amount = calculate_valid_symtabs_amount(img); + if (valid_symtabs_amount == 0) return 0; + + if (!img->symtabs_) { + img->symtabs_ = (struct symtabs *)malloc(sizeof(struct symtabs) * valid_symtabs_amount); + if (!img->symtabs_) return 0; + + if (img->symtab_start != NULL && img->symstr_offset_for_symtab != 0) { + ElfW(Off) i = 0; + for (ElfW(Off) pos = 0; pos < img->symtab_count; pos++) { + unsigned int st_type = ELF_ST_TYPE(img->symtab_start[pos].st_info); + const char *st_name = offsetOf_char(img->header, img->symstr_offset_for_symtab + img->symtab_start[pos].st_name); + + if ((st_type == STT_FUNC || st_type == STT_OBJECT) && img->symtab_start[pos].st_size) { + img->symtabs_[i].name = strdup(st_name); + img->symtabs_[i].sym = &img->symtab_start[pos]; + + i++; + } + } + } + } + + for (size_t i = 0; i < valid_symtabs_amount; i++) { + if (strlen(img->symtabs_[i].name) < strlen(name)) + continue; + + if (strncmp(img->symtabs_[i].name, name, strlen(name)) == 0) + return img->symtabs_[i].sym->st_value; + } + + return 0; +} + +ElfW(Addr) getSymbOffset(ElfImg *img, const char *name) { + ElfW(Addr) offset = GnuLookup(img, name, GnuHash(name)); + if (offset > 0) return offset; + + offset = ElfLookup(img, name, ElfHash(name)); + if (offset > 0) return offset; + + offset = LinearLookup(img, name); + if (offset > 0) return offset; + + return 0; +} + +ElfW(Addr) getSymbAddress(ElfImg *img, const char *name) { + ElfW(Addr) offset = getSymbOffset(img, name); + + if (offset < 0 || !img->base) return 0; + + return ((uintptr_t)img->base + offset - img->bias); +} + +ElfW(Addr) getSymbAddressByPrefix(ElfImg *img, const char *prefix) { + ElfW(Addr) offset = LinearLookupByPrefix(img, prefix); + + if (offset < 0 || !img->base) return 0; + + return (ElfW(Addr))((uintptr_t)img->base + offset - img->bias); +} + +void *getSymbValueByPrefix(ElfImg *img, const char *prefix) { + ElfW(Addr) address = getSymbAddressByPrefix(img, prefix); + + return address == 0 ? NULL : *((void **)address); +} diff --git a/loader/src/common/elf_util.cpp b/loader/src/common/elf_util.cpp deleted file mode 100644 index 2ce61b8..0000000 --- a/loader/src/common/elf_util.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* - * This file is part of LSPosed. - * - * LSPosed is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LSPosed is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LSPosed. If not, see . - * - * Copyright (C) 2019 Swift Gan - * Copyright (C) 2021 LSPosed Contributors - */ -#include -#include -#include -#include -#include -#include -#include -#include "elf_util.h" - -using namespace SandHook; - -template -inline constexpr auto offsetOf(ElfW(Ehdr) *head, ElfW(Off) off) { - return reinterpret_cast, T, T *>>( - reinterpret_cast(head) + off); -} - -ElfImg::ElfImg(std::string_view base_name) : elf(base_name) { - if (!findModuleBase()) { - base = nullptr; - return; - } - - //load elf - int fd = open(elf.data(), O_RDONLY); - if (fd < 0) { - // LOGE("failed to open %s", elf.data()); - return; - } - - size = lseek(fd, 0, SEEK_END); - if (size <= 0) { - // LOGE("lseek() failed for %s", elf.data()); - } - - header = reinterpret_cast(mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0)); - - close(fd); - - section_header = offsetOf(header, header->e_shoff); - - auto shoff = reinterpret_cast(section_header); - char *section_str = offsetOf(header, section_header[header->e_shstrndx].sh_offset); - - for (int i = 0; i < header->e_shnum; i++, shoff += header->e_shentsize) { - auto *section_h = (ElfW(Shdr) *) shoff; - char *sname = section_h->sh_name + section_str; - auto entsize = section_h->sh_entsize; - switch (section_h->sh_type) { - case SHT_DYNSYM: { - if (bias == -4396) { - dynsym = section_h; - dynsym_offset = section_h->sh_offset; - dynsym_start = offsetOf(header, dynsym_offset); - } - break; - } - case SHT_SYMTAB: { - if (strcmp(sname, ".symtab") == 0) { - symtab = section_h; - symtab_offset = section_h->sh_offset; - symtab_size = section_h->sh_size; - symtab_count = symtab_size / entsize; - symtab_start = offsetOf(header, symtab_offset); - } - break; - } - case SHT_STRTAB: { - if (bias == -4396) { - strtab = section_h; - symstr_offset = section_h->sh_offset; - strtab_start = offsetOf(header, symstr_offset); - } - if (strcmp(sname, ".strtab") == 0) { - symstr_offset_for_symtab = section_h->sh_offset; - } - break; - } - case SHT_PROGBITS: { - if (strtab == nullptr || dynsym == nullptr) break; - if (bias == -4396) { - bias = (off_t) section_h->sh_addr - (off_t) section_h->sh_offset; - } - break; - } - case SHT_HASH: { - auto *d_un = offsetOf(header, section_h->sh_offset); - nbucket_ = d_un[0]; - bucket_ = d_un + 2; - chain_ = bucket_ + nbucket_; - break; - } - case SHT_GNU_HASH: { - auto *d_buf = reinterpret_cast(((size_t) header) + - section_h->sh_offset); - gnu_nbucket_ = d_buf[0]; - gnu_symndx_ = d_buf[1]; - gnu_bloom_size_ = d_buf[2]; - gnu_shift2_ = d_buf[3]; - gnu_bloom_filter_ = reinterpret_cast(d_buf + 4); - gnu_bucket_ = reinterpret_cast(gnu_bloom_filter_ + - gnu_bloom_size_); - gnu_chain_ = gnu_bucket_ + gnu_nbucket_ - gnu_symndx_; - break; - } - } - } -} - -ElfW(Addr) ElfImg::ElfLookup(std::string_view name, uint32_t hash) const { - if (nbucket_ == 0) return 0; - - char *strings = (char *) strtab_start; - - for (auto n = bucket_[hash % nbucket_]; n != 0; n = chain_[n]) { - auto *sym = dynsym_start + n; - if (name == strings + sym->st_name) { - return sym->st_value; - } - } - return 0; -} - -ElfW(Addr) ElfImg::GnuLookup(std::string_view name, uint32_t hash) const { - static constexpr auto bloom_mask_bits = sizeof(ElfW(Addr)) * 8; - - if (gnu_nbucket_ == 0 || gnu_bloom_size_ == 0) return 0; - - auto bloom_word = gnu_bloom_filter_[(hash / bloom_mask_bits) % gnu_bloom_size_]; - uintptr_t mask = 0 - | (uintptr_t) 1 << (hash % bloom_mask_bits) - | (uintptr_t) 1 << ((hash >> gnu_shift2_) % bloom_mask_bits); - if ((mask & bloom_word) == mask) { - auto sym_index = gnu_bucket_[hash % gnu_nbucket_]; - if (sym_index >= gnu_symndx_) { - char *strings = (char *) strtab_start; - do { - auto *sym = dynsym_start + sym_index; - if (((gnu_chain_[sym_index] ^ hash) >> 1) == 0 - && name == strings + sym->st_name) { - return sym->st_value; - } - } while ((gnu_chain_[sym_index++] & 1) == 0); - } - } - return 0; -} - -ElfW(Addr) ElfImg::LinearLookup(std::string_view name) const { - if (symtabs_.empty()) { - symtabs_.reserve(symtab_count); - if (symtab_start != nullptr && symstr_offset_for_symtab != 0) { - for (ElfW(Off) i = 0; i < symtab_count; i++) { - unsigned int st_type = ELF_ST_TYPE(symtab_start[i].st_info); - const char *st_name = offsetOf(header, symstr_offset_for_symtab + - symtab_start[i].st_name); - if ((st_type == STT_FUNC || st_type == STT_OBJECT) && symtab_start[i].st_size) { - symtabs_.emplace(st_name, &symtab_start[i]); - } - } - } - } - - if (auto i = symtabs_.find(name); i != symtabs_.end()) { - return i->second->st_value; - } else { - return 0; - } -} - -ElfW(Addr) ElfImg::LinearLookupByPrefix(std::string_view name) const { - if (symtabs_.empty()) { - symtabs_.reserve(symtab_count); - if (symtab_start != nullptr && symstr_offset_for_symtab != 0) { - for (ElfW(Off) i = 0; i < symtab_count; i++) { - unsigned int st_type = ELF_ST_TYPE(symtab_start[i].st_info); - const char *st_name = offsetOf(header, symstr_offset_for_symtab + - symtab_start[i].st_name); - if ((st_type == STT_FUNC || st_type == STT_OBJECT) && symtab_start[i].st_size) { - symtabs_.emplace(st_name, &symtab_start[i]); - } - } - } - } - - auto size = name.size(); - for (auto symtab : symtabs_) { - if (symtab.first.size() < size) continue; - - if (symtab.first.substr(0, size) == name) { - return symtab.second->st_value; - } - } - - return 0; -} - - -ElfImg::~ElfImg() { - //open elf file local - if (buffer) { - free(buffer); - buffer = nullptr; - } - //use mmap - if (header) { - munmap(header, size); - } -} - -ElfW(Addr) ElfImg::getSymbOffset(std::string_view name, uint32_t gnu_hash, uint32_t elf_hash) const { - if (auto offset = GnuLookup(name, gnu_hash); offset > 0) { - // LOGD("found %s %p in %s in dynsym by gnuhash", name.data(), reinterpret_cast(offset), elf.data()); - return offset; - } else if (offset = ElfLookup(name, elf_hash); offset > 0) { - // LOGD("found %s %p in %s in dynsym by elfhash", name.data(), reinterpret_cast(offset), elf.data()); - return offset; - } else if (offset = LinearLookup(name); offset > 0) { - // LOGD("found %s %p in %s in symtab by linear lookup", name.data(), reinterpret_cast(offset), elf.data()); - return offset; - } else { - return 0; - } - -} - -bool ElfImg::findModuleBase() { - dl_iterate_phdr([](struct dl_phdr_info *info, size_t size, void *data) -> int { - (void) size; - - if ((info)->dlpi_name == nullptr) { - return 0; - } - - auto *self = reinterpret_cast(data); - if (strstr(info->dlpi_name, self->elf.data())) { - self->elf = info->dlpi_name; - self->base = reinterpret_cast(info->dlpi_addr); - return 1; - } - return 0; - }, this); - return base != 0; -} diff --git a/loader/src/include/elf_util.h b/loader/src/include/elf_util.h index 42a08c6..fd24ecd 100644 --- a/loader/src/include/elf_util.h +++ b/loader/src/include/elf_util.h @@ -1,152 +1,76 @@ -/* - * This file is part of LSPosed. - * - * LSPosed is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LSPosed is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LSPosed. If not, see . - * - * Copyright (C) 2019 Swift Gan - * Copyright (C) 2021 LSPosed Contributors - */ -#ifndef SANDHOOK_ELF_UTIL_H -#define SANDHOOK_ELF_UTIL_H +#ifndef ELF_UTIL_H +#define ELF_UTIL_H -#include -#include +#include +#include #include #include -#include -#include + +#define restrict /* INFO: Temporary measure */ #define SHT_GNU_HASH 0x6ffffff6 -namespace SandHook { - class ElfImg { - public: +struct symtabs { + char *name; + ElfW(Sym) *sym; +}; - ElfImg(std::string_view elf); +typedef struct { + char *elf; + void *base; + char *buffer; + off_t size; + off_t bias; + ElfW(Ehdr) *header; + ElfW(Shdr) *section_header; + ElfW(Shdr) *symtab; + ElfW(Shdr) *strtab; + ElfW(Shdr) *dynsym; + ElfW(Sym) *symtab_start; + ElfW(Sym) *dynsym_start; + ElfW(Sym) *strtab_start; + ElfW(Off) symtab_count; + ElfW(Off) symstr_offset; + ElfW(Off) symstr_offset_for_symtab; + ElfW(Off) symtab_offset; + ElfW(Off) dynsym_offset; + ElfW(Off) symtab_size; - constexpr ElfW(Addr) getSymbOffset(std::string_view name) const { - return getSymbOffset(name, GnuHash(name), ElfHash(name)); - } + uint32_t nbucket_; + uint32_t *bucket_; + uint32_t *chain_; - constexpr ElfW(Addr) getSymbAddress(std::string_view name) const { - ElfW(Addr) offset = getSymbOffset(name); - if (offset > 0 && base != nullptr) { - return static_cast((uintptr_t) base + offset - bias); - } else { - return 0; - } - } + uint32_t gnu_nbucket_; + uint32_t gnu_symndx_; + uint32_t gnu_bloom_size_; + uint32_t gnu_shift2_; + uintptr_t *gnu_bloom_filter_; + uint32_t *gnu_bucket_; + uint32_t *gnu_chain_; - constexpr ElfW(Addr) getSymbAddressByPrefix(std::string_view prefix) const { - ElfW(Addr) offset = LinearLookupByPrefix(prefix); - if (offset > 0 && base != nullptr) { - return static_cast((uintptr_t) base + offset - bias); - } else { - return 0; - } - } + struct symtabs *symtabs_; +} ElfImg; - template - constexpr T getSymbAddress(std::string_view name) const { - return reinterpret_cast(getSymbAddress(name)); - } +void ElfImg_destroy(ElfImg *img); - template - constexpr T getSymbAddressByPrefix(std::string_view prefix) const { - return reinterpret_cast(getSymbAddressByPrefix(prefix)); - } +ElfImg *ElfImg_create(const char *elf); - bool isValid() const { - return base != nullptr; - } +ElfW(Addr) ElfLookup(ElfImg *restrict img, const char *restrict name, uint32_t hash); - const std::string name() const { - return elf; - } +ElfW(Addr) GnuLookup(ElfImg *restrict img, const char *restrict name, uint32_t hash); - ~ElfImg(); +ElfW(Addr) LinearLookup(ElfImg *restrict img, const char *restrict name); - private: - ElfW(Addr) getSymbOffset(std::string_view name, uint32_t gnu_hash, uint32_t elf_hash) const; +ElfW(Addr) LinearLookupByPrefix(ElfImg *restrict img, const char *name); - ElfW(Addr) ElfLookup(std::string_view name, uint32_t hash) const; +int dl_cb(struct dl_phdr_info *info, size_t size, void *data); - ElfW(Addr) GnuLookup(std::string_view name, uint32_t hash) const; +ElfW(Addr) getSymbOffset(ElfImg *img, const char *name); - ElfW(Addr) LinearLookup(std::string_view name) const; +ElfW(Addr) getSymbAddress(ElfImg *img, const char *name); - ElfW(Addr) LinearLookupByPrefix(std::string_view name) const; +ElfW(Addr) getSymbAddressByPrefix(ElfImg *img, const char *prefix); - constexpr static uint32_t ElfHash(std::string_view name); +void *getSymbValueByPrefix(ElfImg *img, const char *prefix); - constexpr static uint32_t GnuHash(std::string_view name); - - bool findModuleBase(); - - std::string elf; - void *base = nullptr; - char *buffer = nullptr; - off_t size = 0; - off_t bias = -4396; - ElfW(Ehdr) *header = nullptr; - ElfW(Shdr) *section_header = nullptr; - ElfW(Shdr) *symtab = nullptr; - ElfW(Shdr) *strtab = nullptr; - ElfW(Shdr) *dynsym = nullptr; - ElfW(Sym) *symtab_start = nullptr; - ElfW(Sym) *dynsym_start = nullptr; - ElfW(Sym) *strtab_start = nullptr; - ElfW(Off) symtab_count = 0; - ElfW(Off) symstr_offset = 0; - ElfW(Off) symstr_offset_for_symtab = 0; - ElfW(Off) symtab_offset = 0; - ElfW(Off) dynsym_offset = 0; - ElfW(Off) symtab_size = 0; - - uint32_t nbucket_{}; - uint32_t *bucket_ = nullptr; - uint32_t *chain_ = nullptr; - - uint32_t gnu_nbucket_{}; - uint32_t gnu_symndx_{}; - uint32_t gnu_bloom_size_; - uint32_t gnu_shift2_; - uintptr_t *gnu_bloom_filter_; - uint32_t *gnu_bucket_; - uint32_t *gnu_chain_; - - mutable std::unordered_map symtabs_; - }; - - constexpr uint32_t ElfImg::ElfHash(std::string_view name) { - uint32_t h = 0, g = 0; - for (unsigned char p: name) { - h = (h << 4) + p; - g = h & 0xf0000000; - h ^= g; - h ^= g >> 24; - } - return h; - } - - constexpr uint32_t ElfImg::GnuHash(std::string_view name) { - uint32_t h = 5381; - for (unsigned char p: name) { - h += (h << 5) + p; - } - return h; - } -} - -#endif //SANDHOOK_ELF_UTIL_H \ No newline at end of file +#endif /* ELF_UTIL_H */ diff --git a/loader/src/include/solist.h b/loader/src/include/solist.h new file mode 100644 index 0000000..906b56f --- /dev/null +++ b/loader/src/include/solist.h @@ -0,0 +1,66 @@ +#ifndef SOLIST_H +#define SOLIST_H + +/* INFO: Temporary */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct SoInfo SoInfo; + +struct SoInfo { + char data[0]; +}; + +#define FuncType(name) void (*name) + +struct pdg { + void *(*ctor)(); + void *(*dtor)(); +}; + +/* + INFO: When dlopen'ing a library, the system will save information of the + opened library so a structure called soinfo, which contains another + called solist, a list with the information of opened objects. + + Due to special handling in ptracer, however, it won't heave gaps in the + memory of the list since we will close there, not loading a library creating + this gap. However, the previously loaded library would remain in the solist, + requiring ReZygisk to clean those up. + + To do that, we use 2 functions: soinfo_free, and set_size, which will + zero the region size, and then remove all traces of that library (libzygisk.so) + which was previously loaded. + + SOURCES: + - https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/linker/linker.cpp#1712 +*/ +bool solist_drop_so_path(const char *target_path); + +/* + INFO: When dlopen'ing a library, the system will increment 1 to a global + counter that tracks the amount of libraries ever loaded in that process, + the same happening in dlclose. + + This cannot directly be used to detect if ReZygisk is present, however, with + enough data about specific environments, this can be used to detect if any + other library (be it malicious or not) was loaded. To avoid future detections, + we patch that value to the original value. + + To do that, we retrieve the address of both "g_module_load_counter" and "g_module + _unload_counter" variables and force set them to the original value, based on + the modules dlopen'ed. + + SOURCES: + - https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/linker/linker.cpp#1874 + - https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/linker/linker.cpp#1944 + - https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/linker/linker.cpp#3413 +*/ +void solist_reset_counters(size_t load, size_t unload); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* SOLIST_H */ diff --git a/loader/src/include/solist.hpp b/loader/src/include/solist.hpp deleted file mode 100644 index 6835517..0000000 --- a/loader/src/include/solist.hpp +++ /dev/null @@ -1,211 +0,0 @@ -// -// Original from https://github.com/LSPosed/NativeDetector/blob/master/app/src/main/jni/solist.cpp -// -#pragma once - -#include -#include "elf_util.h" -#include "logging.h" - -namespace SoList { - class SoInfo { - public: - #ifdef __LP64__ - inline static size_t solist_size_offset = 0x18; - inline static size_t solist_next_offset = 0x28; - constexpr static size_t solist_realpath_offset = 0x1a8; - #else - inline static size_t solist_size_offset = 0x90; - inline static size_t solist_next_offset = 0xa4; - constexpr static size_t solist_realpath_offset = 0x174; - #endif - - inline static const char *(*get_realpath_sym)(SoInfo *) = NULL; - inline static void (*soinfo_free)(SoInfo *) = NULL; - - inline SoInfo *get_next() { - return *(SoInfo **) ((uintptr_t) this + solist_next_offset); - } - - inline size_t get_size() { - return *(size_t *) ((uintptr_t) this + solist_size_offset); - } - - inline const char *get_path() { - if (get_realpath_sym) return get_realpath_sym(this); - - return ((std::string *) ((uintptr_t) this + solist_realpath_offset))->c_str(); - } - - void set_next(SoInfo *si) { - *(SoInfo **) ((uintptr_t) this + solist_next_offset) = si; - } - - void set_size(size_t size) { - *(size_t *) ((uintptr_t) this + solist_size_offset) = size; - } - }; - - class ProtectedDataGuard { - public: - ProtectedDataGuard() { - if (ctor != nullptr) - (this->*ctor)(); - } - - ~ProtectedDataGuard() { - if (dtor != nullptr) - (this->*dtor)(); - } - - static bool setup(const SandHook::ElfImg &linker) { - ctor = MemFunc{.data = {.p = reinterpret_cast(linker.getSymbAddress( - "__dl__ZN18ProtectedDataGuardC2Ev")), .adj = 0}}.f; - dtor = MemFunc{.data = {.p = reinterpret_cast(linker.getSymbAddress( - "__dl__ZN18ProtectedDataGuardD2Ev")), .adj = 0}}.f; - return ctor != nullptr && dtor != nullptr; - } - - ProtectedDataGuard(const ProtectedDataGuard &) = delete; - - void operator=(const ProtectedDataGuard &) = delete; - - private: - using FuncType = void (ProtectedDataGuard::*)(); - - inline static FuncType ctor = NULL; - inline static FuncType dtor = NULL; - - union MemFunc { - FuncType f; - - struct { - void *p; - std::ptrdiff_t adj; - } data; - }; - }; - - - static SoInfo *solist = NULL; - static SoInfo *somain = NULL; - static SoInfo **sonext = NULL; - - static uint64_t *g_module_load_counter = NULL; - static uint64_t *g_module_unload_counter = NULL; - - static bool Initialize(); - - template - inline T *getStaticPointer(const SandHook::ElfImg &linker, const char *name) { - auto *addr = reinterpret_cast(linker.getSymbAddress(name)); - - return addr == NULL ? NULL : *addr; - } - - template - inline T *getStaticPointerByPrefix(const SandHook::ElfImg &linker, const char *name) { - auto *addr = reinterpret_cast(linker.getSymbAddressByPrefix(name)); - - return addr == NULL ? NULL : *addr; - } - - static bool DropSoPath(const char* target_path) { - bool path_found = false; - if (solist == NULL && !Initialize()) { - LOGE("Failed to initialize solist"); - return path_found; - } - for (auto iter = solist; iter; iter = iter->get_next()) { - if (iter->get_path() && strstr(iter->get_path(), target_path)) { - SoList::ProtectedDataGuard guard; - LOGV("dropping solist record loaded at %s with size %zu", iter->get_path(), iter->get_size()); - if (iter->get_size() > 0) { - iter->set_size(0); - SoInfo::soinfo_free(iter); - path_found = true; - } - } - } - return path_found; - } - - static void ResetCounters(size_t load, size_t unload) { - if (solist == NULL && !Initialize()) { - LOGE("Failed to initialize solist"); - return; - } - if (g_module_load_counter == NULL || g_module_unload_counter == NULL) { - LOGD("g_module counters not defined, skip reseting them"); - return; - } - auto loaded_modules = *g_module_load_counter; - auto unloaded_modules = *g_module_unload_counter; - if (loaded_modules >= load) { - *g_module_load_counter = loaded_modules - load; - LOGD("reset g_module_load_counter to %zu", (size_t) *g_module_load_counter); - } - if (unloaded_modules >= unload) { - *g_module_unload_counter = unloaded_modules - unload; - LOGD("reset g_module_unload_counter to %zu", (size_t) *g_module_unload_counter); - } - } - - static bool Initialize() { - SandHook::ElfImg linker("/linker"); - if (!ProtectedDataGuard::setup(linker)) return false; - LOGD("found symbol ProtectedDataGuard"); - - /* INFO: Since Android 15, the symbol names for the linker have a suffix, - this makes it impossible to hardcode the symbol names. To allow - this to work on all versions, we need to iterate over the loaded - symbols and find the correct ones. - - See #63 for more information. - */ - solist = getStaticPointerByPrefix(linker, "__dl__ZL6solist"); - if (solist == NULL) return false; - LOGD("found symbol solist"); - - somain = getStaticPointerByPrefix(linker, "__dl__ZL6somain"); - if (somain == NULL) return false; - LOGD("found symbol somain"); - - sonext = linker.getSymbAddressByPrefix("__dl__ZL6sonext"); - if (sonext == NULL) return false; - LOGD("found symbol sonext"); - - SoInfo *vdso = getStaticPointerByPrefix(linker, "__dl__ZL4vdso"); - if (vdso != NULL) LOGD("found symbol vdso"); - - SoInfo::get_realpath_sym = reinterpret_cast(linker.getSymbAddress("__dl__ZNK6soinfo12get_realpathEv")); - if (SoInfo::get_realpath_sym == NULL) return false; - LOGD("found symbol get_realpath_sym"); - - SoInfo::soinfo_free = reinterpret_cast(linker.getSymbAddressByPrefix("__dl__ZL11soinfo_freeP6soinfo")); - if (SoInfo::soinfo_free == NULL) return false; - LOGD("found symbol soinfo_free"); - - g_module_load_counter = reinterpret_cast(linker.getSymbAddress("__dl__ZL21g_module_load_counter")); - if (g_module_load_counter != NULL) LOGD("found symbol g_module_load_counter"); - - g_module_unload_counter = reinterpret_cast(linker.getSymbAddress("__dl__ZL23g_module_unload_counter")); - if (g_module_unload_counter != NULL) LOGD("found symbol g_module_unload_counter"); - - for (size_t i = 0; i < 1024 / sizeof(void *); i++) { - auto possible_field = (uintptr_t) solist + i * sizeof(void *); - auto possible_size_of_somain = *(size_t *)((uintptr_t) somain + i * sizeof(void *)); - if (possible_size_of_somain < 0x100000 && possible_size_of_somain > 0x100) { - SoInfo::solist_size_offset = i * sizeof(void *); - LOGD("solist_size_offset is %zu * %zu = %p", i, sizeof(void *), (void*) SoInfo::solist_size_offset); - } - if (*(void **)possible_field == somain || (vdso != NULL && *(void **)possible_field == vdso)) { - SoInfo::solist_next_offset = i * sizeof(void *); - LOGD("solist_next_offset is %zu * %zu = %p", i, sizeof(void *), (void*) SoInfo::solist_next_offset); - break; - } - } - - return true; - } -} diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index c3282c1..c3abc4c 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -21,7 +21,7 @@ #include "files.hpp" #include "misc.hpp" -#include "solist.hpp" +#include "solist.h" #include "art_method.hpp" @@ -616,7 +616,7 @@ void ZygiskContext::run_modules_post() { if (modules.size() > 0) { LOGD("modules unloaded: %zu/%zu", modules_unloaded, modules.size()); - clean_trace("/data/adb", modules.size(), modules_unloaded, true); + clean_trace("/data/adb/rezygisk", modules.size(), modules_unloaded, true); } } @@ -778,8 +778,11 @@ static void hook_register(dev_t dev, ino_t inode, const char *symbol, void *new_ void clean_trace(const char* path, size_t load, size_t unload, bool spoof_maps) { LOGD("cleaning trace for path %s", path); - if (load > 0 || unload >0) SoList::ResetCounters(load, unload); - bool path_found = SoList::DropSoPath(path); + if (load > 0 || unload > 0) solist_reset_counters(load, unload); + + LOGI("Dropping solist record for %s", path); + + bool path_found = solist_drop_so_path(path); if (!path_found || !spoof_maps) return; LOGD("spoofing virtual maps for %s", path); diff --git a/loader/src/injector/solist.c b/loader/src/injector/solist.c new file mode 100644 index 0000000..b338938 --- /dev/null +++ b/loader/src/injector/solist.c @@ -0,0 +1,236 @@ +/* INFO: This file is written in C99 */ + +#include +#include +#include + +#include "elf_util.h" +#include "logging.h" + +#include "solist.h" + +#ifdef __LP64__ + size_t solist_size_offset = 0x18; + size_t solist_next_offset = 0x30; + size_t solist_realpath_offset = 0x1a8; +#else + size_t solist_size_offset = 0x90; + size_t solist_next_offset = 0xa4; + size_t solist_realpath_offset = 0x174; +#endif + +static const char *(*get_realpath_sym)(SoInfo *) = NULL; +static void (*soinfo_free)(SoInfo *) = NULL; + +static inline SoInfo *get_next(SoInfo *self) { + return *(SoInfo **)((uintptr_t)self + solist_next_offset); +} + +static inline const char *get_path(SoInfo *self) { + if (get_realpath_sym) + return (*get_realpath_sym)(self); + + return ((const char *)((uintptr_t)self + solist_realpath_offset)); +} + +static inline void set_size(SoInfo *self, size_t size) { + *(size_t *) ((uintptr_t)self + solist_size_offset) = size; +} + +static inline size_t get_size(SoInfo *self) { + return *(size_t *) ((uintptr_t)self + solist_size_offset); +} + +struct pdg ppdg; + +static bool pdg_setup(ElfImg *img) { + ppdg.ctor = (void *(*)())getSymbAddress(img, "__dl__ZN18ProtectedDataGuardC2Ev"); + ppdg.dtor = (void *(*)())getSymbAddress(img, "__dl__ZN18ProtectedDataGuardD2Ev"); + + return ppdg.ctor != NULL && ppdg.dtor != NULL; +} + +static void pdg_protect() { + if (ppdg.ctor != NULL) + (*(ppdg.ctor))(); +} + +static void pdg_unprotect() { + if (ppdg.dtor != NULL) + (*(ppdg.dtor))(); +} + +static SoInfo *solist = NULL; +static SoInfo *somain = NULL; +static SoInfo **sonext = NULL; + +static uint64_t *g_module_load_counter = NULL; +static uint64_t *g_module_unload_counter = NULL; + +static bool solist_init() { + ElfImg *linker = ElfImg_create("/linker"); + if (linker == NULL) { + LOGE("Failed to load linker"); + + return false; + } + + ppdg = (struct pdg) { + .ctor = NULL, + .dtor = NULL + }; + if (!pdg_setup(linker)) { + LOGE("Failed to setup pdg"); + + ElfImg_destroy(linker); + + return false; + } + + /* INFO: Since Android 15, the symbol names for the linker have a suffix, + this makes it impossible to hardcode the symbol names. To allow + this to work on all versions, we need to iterate over the loaded + symbols and find the correct ones. + + See #63 for more information. + */ + solist = (SoInfo *)getSymbValueByPrefix(linker, "__dl__ZL6solist"); + if (solist == NULL) { + LOGE("Failed to find solist __dl__ZL6solist*"); + + ElfImg_destroy(linker); + + return false; + } + + somain = (SoInfo *)getSymbValueByPrefix(linker, "__dl__ZL6somain"); + LOGI("%p is somain", (void *)somain); + if (somain == NULL) { + LOGE("Failed to find somain __dl__ZL6somain*"); + + ElfImg_destroy(linker); + + return false; + } + + sonext = (SoInfo **)getSymbAddressByPrefix(linker, "__dl__ZL6sonext"); + if (sonext == NULL) { + LOGE("Failed to find sonext __dl__ZL6sonext*"); + + ElfImg_destroy(linker); + + return false; + } + + SoInfo *vdso = (SoInfo *)getSymbValueByPrefix(linker, "__dl__ZL4vdso"); + if (vdso == NULL) { + LOGE("Failed to find vsdo __dl__ZL4vdso*"); + + ElfImg_destroy(linker); + + return false; + } + + get_realpath_sym = (const char *(*)(SoInfo *))getSymbAddress(linker, "__dl__ZNK6soinfo12get_realpathEv"); + if (get_realpath_sym == NULL) { + LOGE("Failed to find get_realpath __dl__ZNK6soinfo12get_realpathEv"); + + ElfImg_destroy(linker); + + return false; + } + + soinfo_free = (void (*)(SoInfo *))getSymbAddressByPrefix(linker, "__dl__ZL11soinfo_freeP6soinfo"); + if (soinfo_free == NULL) { + LOGE("Failed to find soinfo_free __dl__ZL11soinfo_freeP6soinfo*"); + + ElfImg_destroy(linker); + + return false; + } + + g_module_load_counter = (uint64_t *)getSymbAddress(linker, "__dl__ZL21g_module_load_counter"); + if (g_module_load_counter != NULL) LOGD("found symbol g_module_load_counter"); + + g_module_unload_counter = (uint64_t *)getSymbAddress(linker, "__dl__ZL23g_module_unload_counter"); + if (g_module_unload_counter != NULL) LOGD("found symbol g_module_unload_counter"); + + for (size_t i = 0; i < 1024 / sizeof(void *); i++) { + uintptr_t possible_field = (uintptr_t)solist + i * sizeof(void *); + size_t possible_size_of_somain = *(size_t *)((uintptr_t)somain + i * sizeof(void *)); + + if (possible_size_of_somain < 0x100000 && possible_size_of_somain > 0x100) { + solist_size_offset = i * sizeof(void *); + + LOGD("solist_size_offset is %zu * %zu = %p", i, sizeof(void *), (void *)solist_size_offset); + } + + if (*(void **)possible_field == somain || (vdso != NULL && *(void **)possible_field == vdso)) { + solist_next_offset = i * sizeof(void *); + LOGD("solist_next_offset is %zu * %zu = %p", i, sizeof(void *), (void *)solist_next_offset); + + break; + } + } + + ElfImg_destroy(linker); + + return true; +} + +bool solist_drop_so_path(const char *target_path) { + if (solist == NULL && !solist_init()) { + LOGE("Failed to initialize solist"); + + return false; + } + + for (SoInfo *iter = solist; iter; iter = get_next(iter)) { + if (get_path(iter) && strstr(get_path(iter), target_path)) { + pdg_protect(); + + LOGV("dropping solist record loaded at %s with size %zu", get_path(iter), get_size(iter)); + if (get_size(iter) > 0) { + set_size(iter, 0); + soinfo_free(iter); + + pdg_unprotect(); + + return true; + } + + pdg_unprotect(); + } + } + + return false; +} + +void solist_reset_counters(size_t load, size_t unload) { + if (solist == NULL && !solist_init()) { + LOGE("Failed to initialize solist"); + + return; + } + + if (g_module_load_counter == NULL || g_module_unload_counter == NULL) { + LOGD("g_module counters not defined, skip reseting them"); + + return; + } + + uint64_t loaded_modules = *g_module_load_counter; + uint64_t unloaded_modules = *g_module_unload_counter; + + if (loaded_modules >= load) { + *g_module_load_counter = loaded_modules - load; + + LOGD("reset g_module_load_counter to %zu", (size_t) *g_module_load_counter); + } + + if (unloaded_modules >= unload) { + *g_module_unload_counter = unloaded_modules - unload; + + LOGD("reset g_module_unload_counter to %zu", (size_t) *g_module_unload_counter); + } +} From 5b3d9c75fdd26d3338f3585032fa8163c2291d93 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Sat, 12 Apr 2025 23:26:17 -0300 Subject: [PATCH 33/46] remove: open file helpers This commit remove the `open_...` and `xopen_...` helpers, making the code simpler and more direct. --- loader/src/common/files.cpp | 38 +++++++----------------- loader/src/include/files.hpp | 35 ---------------------- loader/src/injector/hook.cpp | 56 +++++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 79 deletions(-) diff --git a/loader/src/common/files.cpp b/loader/src/common/files.cpp index ade40de..e5950cc 100644 --- a/loader/src/common/files.cpp +++ b/loader/src/common/files.cpp @@ -25,12 +25,17 @@ void file_readline(bool trim, FILE *fp, const std::function &fn) { - if (auto fp = open_file(file, "re")) - file_readline(trim, fp.get(), fn); -} void file_readline(const char *file, const std::function &fn) { - file_readline(false, file, fn); + FILE *fp = fopen(file, "re"); + if (!fp) { + PLOGE("Failed to open file %s", file); + + return; + } + + file_readline(false, fp, fn); + + fclose(fp); } std::vector parse_mount_info(const char *pid) { @@ -112,26 +117,3 @@ std::vector parse_mount_info(const char *pid) { }); return result; } - -sDIR make_dir(DIR *dp) { - return sDIR(dp, [](DIR *dp){ return dp ? closedir(dp) : 1; }); -} - -sFILE make_file(FILE *fp) { - return sFILE(fp, [](FILE *fp){ return fp ? fclose(fp) : 1; }); -} - -int get_path_from_fd(int fd, char *buf, size_t size) { - if (fd < 0 || !buf || size == 0) return -1; - - /* NOTE: We assume that the path is always at /data/adb/modules/xxx - which should never be longer than 128 chars. */ - char proc_path[128]; - snprintf(proc_path, sizeof(proc_path), "/proc/self/fd/%d", fd); - - ssize_t len = readlink(proc_path, buf, size - 1); - if (len == -1) return -1; - - buf[len] = '\0'; - return 0; -} \ No newline at end of file diff --git a/loader/src/include/files.hpp b/loader/src/include/files.hpp index 4f16e0c..ce49e8f 100644 --- a/loader/src/include/files.hpp +++ b/loader/src/include/files.hpp @@ -21,39 +21,4 @@ struct mount_info { std::string fs_option; }; -void file_readline(bool trim, FILE *fp, const std::function &fn); -void file_readline(bool trim, const char *file, const std::function &fn); -void file_readline(const char *file, const std::function &fn); - std::vector parse_mount_info(const char *pid); - -int get_path_from_fd(int fd, char *buf, size_t size); - -using sFILE = std::unique_ptr; -using sDIR = std::unique_ptr; -sDIR make_dir(DIR *dp); -sFILE make_file(FILE *fp); - -static inline sDIR open_dir(const char *path) { - return make_dir(opendir(path)); -} - -static inline sDIR xopen_dir(const char *path) { - return make_dir(opendir(path)); -} - -static inline sDIR xopen_dir(int dirfd) { - return make_dir(fdopendir(dirfd)); -} - -static inline sFILE open_file(const char *path, const char *mode) { - return make_file(fopen(path, mode)); -} - -static inline sFILE xopen_file(const char *path, const char *mode) { - return make_file(fopen(path, mode)); -} - -static inline sFILE xopen_file(int fd, const char *mode) { - return make_file(fdopen(fd, mode)); -} diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index c3abc4c..6a63979 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -10,9 +9,12 @@ #include #include +#include +#include #include #include #include + #include #include "daemon.h" @@ -487,25 +489,38 @@ int sigmask(int how, int signum) { } void ZygiskContext::fork_pre() { - // Do our own fork before loading any 3rd party code - // First block SIGCHLD, unblock after original fork is done + /* INFO: Do our own fork before loading any 3rd party code. + First block SIGCHLD, unblock after original fork is done. + */ sigmask(SIG_BLOCK, SIGCHLD); pid = old_fork(); if (pid != 0 || flags[SKIP_FD_SANITIZATION]) return; - // Record all open fds - auto dir = xopen_dir("/proc/self/fd"); - for (dirent *entry; (entry = readdir(dir.get()));) { + /* INFO: Record all open fds */ + DIR *dir = opendir("/proc/self/fd"); + if (dir == nullptr) { + PLOGE("Failed to open /proc/self/fd"); + + return; + } + + struct dirent *entry; + while ((entry = readdir(dir))) { int fd = parse_int(entry->d_name); if (fd < 0 || fd >= MAX_FD_SIZE) { close(fd); + continue; } + allowed_fds[fd] = true; } - // The dirfd should not be allowed - allowed_fds[dirfd(dir.get())] = false; + + /* INFO: The dirfd should not be allowed */ + allowed_fds[dirfd(dir)] = false; + + closedir(dir); } void ZygiskContext::sanitize_fds() { @@ -554,14 +569,23 @@ void ZygiskContext::sanitize_fds() { return; // Close all forbidden fds to prevent crashing - auto dir = open_dir("/proc/self/fd"); - int dfd = dirfd(dir.get()); - for (dirent *entry; (entry = readdir(dir.get()));) { - int fd = parse_int(entry->d_name); - if ((fd < 0 || fd >= MAX_FD_SIZE || !allowed_fds[fd]) && fd != dfd) { - close(fd); - } + DIR *dir = opendir("/proc/self/fd"); + if (dir == nullptr) { + PLOGE("Failed to open /proc/self/fd"); + + return; } + + int dfd = dirfd(dir); + struct dirent *entry; + while ((entry = readdir(dir))) { + int fd = parse_int(entry->d_name); + if (fd == dfd || allowed_fds[fd] || fd < 0 || fd < MAX_FD_SIZE) continue; + + close(fd); + } + + closedir(dir); } void ZygiskContext::fork_post() { @@ -616,7 +640,7 @@ void ZygiskContext::run_modules_post() { if (modules.size() > 0) { LOGD("modules unloaded: %zu/%zu", modules_unloaded, modules.size()); - clean_trace("/data/adb/rezygisk", modules.size(), modules_unloaded, true); + clean_trace("/data/adb", modules.size(), modules_unloaded, true); } } From 2d80ce6935562637e156a42ea0636d9f2c5320f8 Mon Sep 17 00:00:00 2001 From: Stillhard Date: Sun, 13 Apr 2025 09:54:35 +0700 Subject: [PATCH 34/46] fix: SELinux rules (#130) This commit allows Zygote to access files in /data/adb, so that it can load the Zygisk modules. Signed-off-by: Stillhard --- module/src/sepolicy.rule | 1 + 1 file changed, 1 insertion(+) diff --git a/module/src/sepolicy.rule b/module/src/sepolicy.rule index 859f87f..76835a1 100644 --- a/module/src/sepolicy.rule +++ b/module/src/sepolicy.rule @@ -9,6 +9,7 @@ allow zygote su dir search allow zygote su {lnk_file file} read allow zygote adb_data_file dir search +allow zygote adb_data_file file * allow zygote zygote process execmem allow system_server system_server process execmem allow zygote tmpfs file * From c37a5b1c8e0cfa00d3cec3875e42c0281c600462 Mon Sep 17 00:00:00 2001 From: Breathleas <39123978+Breathleas@users.noreply.github.com> Date: Mon, 14 Apr 2025 06:12:08 +0800 Subject: [PATCH 35/46] fix: missing `status32` exit check (#128) This commit fixes the issue where 32-bit daemon wouldn't be checked for exits, as the macro hardcoded "status64". Signed-off-by: Breathleas <39123978+Breathleas@users.noreply.github.com> Co-authored-by: anyusec <145352653+anyusec@users.noreply.github.com> Co-authored-by: Pedro.js --- loader/src/ptracer/monitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader/src/ptracer/monitor.cpp b/loader/src/ptracer/monitor.cpp index af7f28c..d02e563 100644 --- a/loader/src/ptracer/monitor.cpp +++ b/loader/src/ptracer/monitor.cpp @@ -438,7 +438,7 @@ static bool ensure_daemon_created(bool is_64bit) { } #define CHECK_DAEMON_EXIT(abi) \ - if (status##abi.supported && pid == status64.daemon_pid) { \ + if (status##abi.supported && pid == status##abi.daemon_pid) { \ char status_str[64]; \ parse_status(status, status_str, sizeof(status_str)); \ \ From 1a3f497e1a2c5da5d79dc756b074c00d6d75c556 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Mon, 14 Apr 2025 00:54:24 -0300 Subject: [PATCH 36/46] improve: port `common` code to C This commit ports even more C++ code to C99, now, the codes available in the "common" folder. --- loader/src/common/daemon.c | 365 ++++++++++++++++++++++ loader/src/common/daemon.cpp | 279 ----------------- loader/src/common/files.cpp | 119 ------- loader/src/common/misc.c | 14 + loader/src/common/misc.cpp | 49 --- loader/src/common/socket_utils.c | 95 ++++++ loader/src/common/socket_utils.cpp | 137 -------- loader/src/include/daemon.h | 126 +++----- loader/src/include/elf_util.h | 2 - loader/src/include/files.hpp | 24 -- loader/src/include/misc.h | 17 + loader/src/include/misc.hpp | 98 ------ loader/src/include/socket_utils.h | 40 +-- loader/src/injector/art_method.hpp | 1 + loader/src/injector/entry.cpp | 5 +- loader/src/injector/hook.cpp | 67 ++-- loader/src/{include => injector}/solist.h | 1 - loader/src/ptracer/main.cpp | 18 +- loader/src/ptracer/monitor.cpp | 19 +- loader/src/ptracer/ptracer.cpp | 14 +- 20 files changed, 633 insertions(+), 857 deletions(-) create mode 100644 loader/src/common/daemon.c delete mode 100644 loader/src/common/daemon.cpp delete mode 100644 loader/src/common/files.cpp create mode 100644 loader/src/common/misc.c delete mode 100644 loader/src/common/misc.cpp create mode 100644 loader/src/common/socket_utils.c delete mode 100644 loader/src/common/socket_utils.cpp delete mode 100644 loader/src/include/files.hpp create mode 100644 loader/src/include/misc.h delete mode 100644 loader/src/include/misc.hpp rename loader/src/{include => injector}/solist.h (99%) diff --git a/loader/src/common/daemon.c b/loader/src/common/daemon.c new file mode 100644 index 0000000..4a4b836 --- /dev/null +++ b/loader/src/common/daemon.c @@ -0,0 +1,365 @@ +// #include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +#include + +#include "logging.h" +#include "socket_utils.h" + +#include "daemon.h" + +char daemon_path[PATH_MAX]; + +void rezygiskd_init(const char *path) { + snprintf(daemon_path, sizeof(daemon_path), "%s/%s", path, SOCKET_FILE_NAME); +} + +void rezygiskd_get_path(char *buf, size_t buf_size) { + size_t fileless_daemon_path = strlen(daemon_path) - strlen("/") - strlen(SOCKET_FILE_NAME); + + strncpy(buf, daemon_path, buf_size > fileless_daemon_path ? fileless_daemon_path : buf_size); + buf[fileless_daemon_path] = '\0'; +} + +int rezygiskd_connect(uint8_t retry) { + retry++; + + int fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + if (fd == -1) { + PLOGE("socket create"); + + return -1; + } + + struct sockaddr_un addr = { + .sun_family = AF_UNIX, + .sun_path = { 0 } + }; + + /* + INFO: Application must assume that sun_path can hold _POSIX_PATH_MAX characters. + + Sources: + - https://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/un.h.html + */ + strcpy(addr.sun_path, daemon_path); + socklen_t socklen = sizeof(addr); + + while (--retry) { + int ret = connect(fd, (struct sockaddr *)&addr, socklen); + if (ret == 0) return fd; + if (retry) { + PLOGE("Retrying to connect to ReZygiskd, sleep 1s"); + + sleep(1); + } + } + + close(fd); + + return -1; +} + +bool rezygiskd_ping() { + int fd = rezygiskd_connect(5); + if (fd == -1) { + PLOGE("connection to ReZygiskd"); + + return false; + } + + write_uint8_t(fd, (uint8_t)PingHeartbeat); + + close(fd); + + return true; +} + +uint32_t rezygiskd_get_process_flags(uid_t uid) { + int fd = rezygiskd_connect(1); + if (fd == -1) { + PLOGE("connection to ReZygiskd"); + + return 0; + } + + write_uint8_t(fd, (uint8_t)GetProcessFlags); + write_uint32_t(fd, (uint32_t)uid); + + uint32_t res = 0; + read_uint32_t(fd, &res); + + close(fd); + + return res; +} + +void rezygiskd_get_info(struct rezygisk_info *info) { + int fd = rezygiskd_connect(1); + if (fd == -1) { + PLOGE("connection to ReZygiskd"); + + info->running = false; + + return; + } + + info->running = true; + + write_uint8_t(fd, (uint8_t)GetInfo); + + uint32_t flags = 0; + read_uint32_t(fd, &flags); + + if (flags & (1 << 27)) info->root_impl = ROOT_IMPL_APATCH; + else if (flags & (1 << 29)) info->root_impl = ROOT_IMPL_KERNELSU; + else if (flags & (1 << 30)) info->root_impl = ROOT_IMPL_MAGISK; + else info->root_impl = ROOT_IMPL_NONE; + + read_uint32_t(fd, (uint32_t *)&info->pid); + + read_size_t(fd, &info->modules->modules_count); + if (info->modules->modules_count == 0) { + info->modules->modules = NULL; + + close(fd); + + return; + } + + info->modules->modules = (char **)malloc(sizeof(char *) * info->modules->modules_count); + if (info->modules->modules == NULL) { + PLOGE("allocating modules name memory"); + + free(info->modules); + info->modules = NULL; + info->modules->modules_count = 0; + + close(fd); + + return; + } + + for (size_t i = 0; i < info->modules->modules_count; i++) { + char *module_name = read_string(fd); + if (module_name == NULL) { + PLOGE("reading module name"); + + info->modules->modules_count = i; + + free_rezygisk_info(info); + + info->modules = NULL; + info->modules->modules_count = 0; + + close(fd); + + return; + } + + char module_path[PATH_MAX]; + snprintf(module_path, sizeof(module_path), "/data/adb/modules/%s/module.prop", module_name); + + FILE *module_prop = fopen(module_path, "r"); + if (!module_prop) { + PLOGE("failed to open module prop file %s", module_path); + + info->modules->modules_count = i; + + free_rezygisk_info(info); + + info->modules = NULL; + info->modules->modules_count = 0; + + close(fd); + + return; + } + + char line[1024]; + while (fgets(line, sizeof(line), module_prop) != NULL) { + if (strncmp(line, "name=", strlen("name=")) != 0) continue; + + info->modules->modules[i] = strndup(line + 5, strlen(line) - 6); + + break; + } + + fclose(module_prop); + } + + close(fd); +} + +void free_rezygisk_info(struct rezygisk_info *info) { + if (info->modules->modules) { + for (size_t i = 0; i < info->modules->modules_count; i++) { + free(info->modules->modules[i]); + } + + free(info->modules->modules); + } + + free(info->modules); +} + +bool rezygiskd_read_modules(struct zygisk_modules *modules) { + int fd = rezygiskd_connect(1); + if (fd == -1) { + PLOGE("connection to ReZygiskd"); + + return false; + } + + write_uint8_t(fd, (uint8_t)ReadModules); + + size_t len = 0; + read_size_t(fd, &len); + + modules->modules = malloc(len * sizeof(char *)); + if (!modules->modules) { + PLOGE("allocating modules name memory"); + + close(fd); + + return false; + } + modules->modules_count = len; + + for (size_t i = 0; i < len; i++) { + char *lib_path = read_string(fd); + if (!lib_path) { + PLOGE("reading module lib_path"); + + close(fd); + + return false; + } + + modules->modules[i] = lib_path; + } + + close(fd); + + return true; +} + +void free_modules(struct zygisk_modules *modules) { + if (modules->modules) { + for (size_t i = 0; i < modules->modules_count; i++) { + free(modules->modules[i]); + } + + free(modules->modules); + } +} + +int rezygiskd_connect_companion(size_t index) { + int fd = rezygiskd_connect(1); + if (fd == -1) { + PLOGE("connection to ReZygiskd"); + + return -1; + } + + write_uint8_t(fd, (uint8_t)RequestCompanionSocket); + write_size_t(fd, index); + + uint8_t res = 0; + read_uint8_t(fd, &res); + + if (res == 1) return fd; + else { + close(fd); + + return -1; + } +} + +int rezygiskd_get_module_dir(size_t index) { + int fd = rezygiskd_connect(1); + if (fd == -1) { + PLOGE("connection to ReZygiskd"); + + return -1; + } + + write_uint8_t(fd, (uint8_t)GetModuleDir); + write_size_t(fd, index); + + int dirfd = read_fd(fd); + + close(fd); + + return dirfd; +} + +void rezygiskd_zygote_restart() { + int fd = rezygiskd_connect(1); + if (fd == -1) { + if (errno == ENOENT) LOGD("Could not notify ZygoteRestart (maybe it hasn't been created)"); + else PLOGE("Could not notify ZygoteRestart"); + + return; + } + + if (!write_uint8_t(fd, (uint8_t)ZygoteRestart)) + PLOGE("Failed to request ZygoteRestart"); + + close(fd); +} + +void rezygiskd_system_server_started() { + int fd = rezygiskd_connect(1); + if (fd == -1) { + PLOGE("Failed to report system server started"); + + return; + } + + if (!write_uint8_t(fd, (uint8_t)SystemServerStarted)) + PLOGE("Failed to request SystemServerStarted"); + + close(fd); +} + +bool rezygiskd_update_mns(enum mount_namespace_state nms_state, char *buf, size_t buf_size) { + int fd = rezygiskd_connect(1); + if (fd == -1) { + PLOGE("connection to ReZygiskd"); + + return false; + } + + write_uint8_t(fd, (uint8_t)UpdateMountNamespace); + write_uint32_t(fd, (uint32_t)getpid()); + write_uint8_t(fd, (uint8_t)nms_state); + + uint32_t target_pid = 0; + read_uint32_t(fd, &target_pid); + if (target_pid == 0) { + close(fd); + + return false; + } + + int target_fd = read_fd(fd); + if (target_fd == -1) { + close(fd); + + return false; + } + + snprintf(buf, buf_size, "/proc/%u/fd/%u", target_pid, target_fd); + + close(fd); + + return true; +} diff --git a/loader/src/common/daemon.cpp b/loader/src/common/daemon.cpp deleted file mode 100644 index 44c7660..0000000 --- a/loader/src/common/daemon.cpp +++ /dev/null @@ -1,279 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "daemon.h" -#include "socket_utils.h" - -namespace zygiskd { - static std::string TMP_PATH; - void Init(const char *path) { - TMP_PATH = path; - } - - std::string GetTmpPath() { - return TMP_PATH; - } - - int Connect(uint8_t retry) { - retry++; - - int fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); - struct sockaddr_un addr = { - .sun_family = AF_UNIX, - .sun_path = { 0 } - }; - - auto socket_path = TMP_PATH + kCPSocketName; - strcpy(addr.sun_path, socket_path.c_str()); - socklen_t socklen = sizeof(addr); - - while (--retry) { - int r = connect(fd, (struct sockaddr *)&addr, socklen); - if (r == 0) return fd; - if (retry) { - PLOGE("Retrying to connect to zygiskd, sleep 1s"); - - sleep(1); - } - } - - close(fd); - - return -1; - } - - bool PingHeartbeat() { - int fd = Connect(5); - if (fd == -1) { - PLOGE("Connect to zygiskd"); - - return false; - } - - socket_utils::write_u8(fd, (uint8_t) SocketAction::PingHeartBeat); - - close(fd); - - return true; - } - - uint32_t GetProcessFlags(uid_t uid) { - int fd = Connect(1); - if (fd == -1) { - PLOGE("GetProcessFlags"); - - return 0; - } - - socket_utils::write_u8(fd, (uint8_t) SocketAction::GetProcessFlags); - socket_utils::write_u32(fd, uid); - - uint32_t res = socket_utils::read_u32(fd); - - close(fd); - - return res; - } - - std::vector ReadModules() { - std::vector modules; - int fd = Connect(1); - if (fd == -1) { - PLOGE("ReadModules"); - - return modules; - } - - socket_utils::write_u8(fd, (uint8_t) SocketAction::ReadModules); - size_t len = socket_utils::read_usize(fd); - for (size_t i = 0; i < len; i++) { - std::string lib_path = socket_utils::read_string(fd); - std::string name = socket_utils::read_string(fd); - modules.emplace_back(lib_path, name); - } - - close(fd); - - return modules; - } - - int ConnectCompanion(size_t index) { - int fd = Connect(1); - if (fd == -1) { - PLOGE("ConnectCompanion"); - - return -1; - } - - socket_utils::write_u8(fd, (uint8_t) SocketAction::RequestCompanionSocket); - socket_utils::write_usize(fd, index); - - uint8_t res = socket_utils::read_u8(fd); - - if (res == 1) return fd; - else { - close(fd); - - return -1; - } - } - - int GetModuleDir(size_t index) { - int fd = Connect(1); - if (fd == -1) { - PLOGE("GetModuleDir"); - - return -1; - } - - socket_utils::write_u8(fd, (uint8_t) SocketAction::GetModuleDir); - socket_utils::write_usize(fd, index); - int nfd = socket_utils::recv_fd(fd); - - close(fd); - - return nfd; - } - - void ZygoteRestart() { - int fd = Connect(1); - if (fd == -1) { - if (errno == ENOENT) LOGD("Could not notify ZygoteRestart (maybe it hasn't been created)"); - else PLOGE("Could not notify ZygoteRestart"); - - return; - } - - if (!socket_utils::write_u8(fd, (uint8_t) SocketAction::ZygoteRestart)) - PLOGE("Failed to request ZygoteRestart"); - - close(fd); - } - - void SystemServerStarted() { - int fd = Connect(1); - if (fd == -1) PLOGE("Failed to report system server started"); - else { - if (!socket_utils::write_u8(fd, (uint8_t) SocketAction::SystemServerStarted)) - PLOGE("Failed to report system server started"); - } - - close(fd); - } - - void GetInfo(struct zygote_info *info) { - /* TODO: Optimize and avoid re-connect twice here */ - int fd = Connect(1); - - if (fd != -1) { - info->running = true; - - socket_utils::write_u8(fd, (uint8_t) SocketAction::GetInfo); - - int flags = socket_utils::read_u32(fd); - - if (flags & (1 << 27)) { - info->root_impl = ZYGOTE_ROOT_IMPL_APATCH; - } else if (flags & (1 << 29)) { - info->root_impl = ZYGOTE_ROOT_IMPL_KERNELSU; - } else if (flags & (1 << 30)) { - info->root_impl = ZYGOTE_ROOT_IMPL_MAGISK; - } else { - info->root_impl = ZYGOTE_ROOT_IMPL_NONE; - } - - info->pid = socket_utils::read_u32(fd); - - info->modules = (struct zygote_modules *)malloc(sizeof(struct zygote_modules)); - if (info->modules == NULL) { - info->modules->modules_count = 0; - - close(fd); - - return; - } - - info->modules->modules_count = socket_utils::read_usize(fd); - - if (info->modules->modules_count == 0) { - info->modules->modules = NULL; - - close(fd); - - return; - } - - info->modules->modules = (char **)malloc(sizeof(char *) * info->modules->modules_count); - if (info->modules->modules == NULL) { - free(info->modules); - info->modules = NULL; - info->modules->modules_count = 0; - - close(fd); - - return; - } - - for (size_t i = 0; i < info->modules->modules_count; i++) { - /* INFO by ThePedroo: Ugly solution to read with std::string existance (temporary) */ - std::string name = socket_utils::read_string(fd); - - char module_path[PATH_MAX]; - snprintf(module_path, sizeof(module_path), "/data/adb/modules/%s/module.prop", name.c_str()); - - FILE *module_prop = fopen(module_path, "r"); - if (module_prop == NULL) { - info->modules->modules[i] = strdup(name.c_str()); - } else { - char line[1024]; - while (fgets(line, sizeof(line), module_prop) != NULL) { - if (strncmp(line, "name=", 5) == 0) { - info->modules->modules[i] = strndup(line + 5, strlen(line) - 6); - - break; - } - } - - fclose(module_prop); - } - } - - close(fd); - } else info->running = false; - } - - std::string UpdateMountNamespace(enum mount_namespace_state nms_state) { - int fd = Connect(1); - if (fd == -1) { - PLOGE("UpdateMountNamespace"); - - return ""; - } - - socket_utils::write_u8(fd, (uint8_t) SocketAction::UpdateMountNamespace); - socket_utils::write_u32(fd, getpid()); - socket_utils::write_u8(fd, (uint8_t)nms_state); - - uint32_t target_pid = socket_utils::read_u32(fd); - int target_fd = 0; - - if (target_pid == 0) goto error; - - target_fd = (int)socket_utils::read_u32(fd); - if (target_fd == 0) goto error; - - close(fd); - - return "/proc/" + std::to_string(target_pid) + "/fd/" + std::to_string(target_fd); - - error: - close(fd); - - return ""; - } -} diff --git a/loader/src/common/files.cpp b/loader/src/common/files.cpp deleted file mode 100644 index e5950cc..0000000 --- a/loader/src/common/files.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include - -#include "files.hpp" -#include "misc.hpp" - -using namespace std::string_view_literals; - -void file_readline(bool trim, FILE *fp, const std::function &fn) { - size_t len = 1024; - char *buf = (char *) malloc(len); - char *start; - ssize_t read; - while ((read = getline(&buf, &len, fp)) >= 0) { - start = buf; - if (trim) { - while (read && "\n\r "sv.find(buf[read - 1]) != std::string::npos) - --read; - buf[read] = '\0'; - while (*start == ' ') - ++start; - } - if (!fn(start)) - break; - } - free(buf); -} - -void file_readline(const char *file, const std::function &fn) { - FILE *fp = fopen(file, "re"); - if (!fp) { - PLOGE("Failed to open file %s", file); - - return; - } - - file_readline(false, fp, fn); - - fclose(fp); -} - -std::vector parse_mount_info(const char *pid) { - char buf[PATH_MAX] = {}; - snprintf(buf, sizeof(buf), "/proc/%s/mountinfo", pid); - std::vector result; - - file_readline(buf, [&result](std::string_view line) -> bool { - int root_start = 0, root_end = 0; - int target_start = 0, target_end = 0; - int vfs_option_start = 0, vfs_option_end = 0; - int type_start = 0, type_end = 0; - int source_start = 0, source_end = 0; - int fs_option_start = 0, fs_option_end = 0; - int optional_start = 0, optional_end = 0; - unsigned int id, parent, maj, min; - sscanf(line.data(), - "%u " // (1) id - "%u " // (2) parent - "%u:%u " // (3) maj:min - "%n%*s%n " // (4) mountroot - "%n%*s%n " // (5) target - "%n%*s%n" // (6) vfs options (fs-independent) - "%n%*[^-]%n - " // (7) optional fields - "%n%*s%n " // (8) FS type - "%n%*s%n " // (9) source - "%n%*s%n", // (10) fs options (fs specific) - &id, &parent, &maj, &min, &root_start, &root_end, &target_start, - &target_end, &vfs_option_start, &vfs_option_end, - &optional_start, &optional_end, &type_start, &type_end, - &source_start, &source_end, &fs_option_start, &fs_option_end); - - auto root = line.substr(root_start, root_end - root_start); - auto target = line.substr(target_start, target_end - target_start); - auto vfs_option = - line.substr(vfs_option_start, vfs_option_end - vfs_option_start); - ++optional_start; - --optional_end; - auto optional = line.substr( - optional_start, - optional_end - optional_start > 0 ? optional_end - optional_start : 0); - - auto type = line.substr(type_start, type_end - type_start); - auto source = line.substr(source_start, source_end - source_start); - auto fs_option = - line.substr(fs_option_start, fs_option_end - fs_option_start); - - unsigned int shared = 0; - unsigned int master = 0; - unsigned int propagate_from = 0; - if (auto pos = optional.find("shared:"); pos != std::string_view::npos) { - shared = parse_int(optional.substr(pos + 7)); - } - if (auto pos = optional.find("master:"); pos != std::string_view::npos) { - master = parse_int(optional.substr(pos + 7)); - } - if (auto pos = optional.find("propagate_from:"); - pos != std::string_view::npos) { - propagate_from = parse_int(optional.substr(pos + 15)); - } - - result.emplace_back(mount_info { - .id = id, - .parent = parent, - .device = static_cast(makedev(maj, min)), - .root {root}, - .target {target}, - .vfs_option {vfs_option}, - .optional { - .shared = shared, - .master = master, - .propagate_from = propagate_from, - }, - .type {type}, - .source {source}, - .fs_option {fs_option}, - }); - return true; - }); - return result; -} diff --git a/loader/src/common/misc.c b/loader/src/common/misc.c new file mode 100644 index 0000000..8d84de4 --- /dev/null +++ b/loader/src/common/misc.c @@ -0,0 +1,14 @@ +int parse_int(const char *str) { + int val = 0; + + char *c = (char *)str; + while (*c) { + if (*c > '9' || *c < '0') + return -1; + + val = val * 10 + *c - '0'; + c++; + } + + return val; +} diff --git a/loader/src/common/misc.cpp b/loader/src/common/misc.cpp deleted file mode 100644 index 0881664..0000000 --- a/loader/src/common/misc.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "misc.hpp" - -int new_daemon_thread(thread_entry entry, void *arg) { - pthread_t thread; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - errno = pthread_create(&thread, &attr, entry, arg); - if (errno) { - PLOGE("pthread_create"); - } - return errno; -} - -int parse_int(std::string_view s) { - int val = 0; - for (char c : s) { - if (!c) break; - if (c > '9' || c < '0') - return -1; - val = val * 10 + c - '0'; - } - return val; -} - -std::list split_str(std::string_view s, std::string_view delimiter) { - std::list ret; - size_t pos = 0; - while (pos < s.size()) { - auto next = s.find(delimiter, pos); - if (next == std::string_view::npos) { - ret.emplace_back(s.substr(pos)); - break; - } - ret.emplace_back(s.substr(pos, next - pos)); - pos = next + delimiter.size(); - } - return ret; -} - -std::string join_str(const std::list& list, std::string_view delimiter) { - std::string ret; - for (auto& s : list) { - if (!ret.empty()) - ret += delimiter; - ret += s; - } - return ret; -} diff --git a/loader/src/common/socket_utils.c b/loader/src/common/socket_utils.c new file mode 100644 index 0000000..24bddc0 --- /dev/null +++ b/loader/src/common/socket_utils.c @@ -0,0 +1,95 @@ +#include +#include +#include + +#include + +#include "logging.h" + +#include "socket_utils.h" + +/* TODO: Standardize how to log errors */ +int read_fd(int fd) { + char cmsgbuf[CMSG_SPACE(sizeof(int))]; + + int cnt = 1; + struct iovec iov = { + .iov_base = &cnt, + .iov_len = sizeof(cnt) + }; + + struct msghdr msg = { + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = cmsgbuf, + .msg_controllen = sizeof(cmsgbuf) + }; + + ssize_t ret = recvmsg(fd, &msg, MSG_WAITALL); + if (ret == -1) { + PLOGE("recvmsg"); + + return -1; + } + + struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); + if (cmsg == NULL) { + PLOGE("CMSG_FIRSTHDR"); + + return -1; + } + + int sendfd; + memcpy(&sendfd, CMSG_DATA(cmsg), sizeof(int)); + + return sendfd; +} + +char *read_string(int fd) { + size_t str_len = 0; + ssize_t read_bytes = read(fd, &str_len, sizeof(size_t)); + if (read_bytes != (ssize_t)sizeof(size_t)) { + LOGE("Failed to read string length: Not all bytes were read (%zd != %zu).\n", read_bytes, sizeof(size_t)); + + return NULL; + } + + char *buf = malloc(str_len + 1); + if (buf == NULL) { + PLOGE("allocate memory for string"); + + return NULL; + } + + read_bytes = read(fd, buf, str_len); + if (read_bytes != (ssize_t)str_len) { + LOGE("Failed to read string: Promised bytes doesn't exist (%zd != %zu).\n", read_bytes, str_len); + + free(buf); + + return NULL; + } + + if (str_len > 0) buf[str_len] = '\0'; + + return buf; +} + +#define write_func(type) \ + ssize_t write_## type(int fd, type val) { \ + return write(fd, &val, sizeof(type)); \ + } + +#define read_func(type) \ + ssize_t read_## type(int fd, type *val) { \ + return read(fd, val, sizeof(type)); \ + } + +write_func(uint8_t) +read_func(uint8_t) + +write_func(uint32_t) +read_func(uint32_t) + +write_func(size_t) +read_func(size_t) diff --git a/loader/src/common/socket_utils.cpp b/loader/src/common/socket_utils.cpp deleted file mode 100644 index 730d49d..0000000 --- a/loader/src/common/socket_utils.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include -#include -#include - -#include "socket_utils.h" - -namespace socket_utils { - ssize_t xread(int fd, void* buf, size_t count) { - size_t read_sz = 0; - ssize_t ret; - do { - ret = read(fd, (std::byte*) buf + read_sz, count - read_sz); - if (ret < 0) { - if (errno == EINTR) continue; - PLOGE("read"); - return ret; - } - read_sz += ret; - } while (read_sz != count && ret != 0); - if (read_sz != count) { - PLOGE("read (%zu != %zu)", count, read_sz); - } - return read_sz; - } - - size_t xwrite(int fd, const void* buf, size_t count) { - size_t write_sz = 0; - ssize_t ret; - do { - ret = write(fd, (std::byte*) buf + write_sz, count - write_sz); - if (ret < 0) { - if (errno == EINTR) continue; - PLOGE("write"); - return write_sz; - } - write_sz += ret; - } while (write_sz != count && ret != 0); - if (write_sz != count) { - PLOGE("write (%zu != %zu)", count, write_sz); - } - return write_sz; - } - - ssize_t xrecvmsg(int sockfd, struct msghdr* msg, int flags) { - int rec = recvmsg(sockfd, msg, flags); - if (rec < 0) PLOGE("recvmsg"); - return rec; - } - - template - inline T read_exact_or(int fd, T fail) { - T res; - return sizeof(T) == xread(fd, &res, sizeof(T)) ? res : fail; - } - - template - inline bool write_exact(int fd, T val) { - return sizeof(T) == xwrite(fd, &val, sizeof(T)); - } - - uint8_t read_u8(int fd) { - return read_exact_or(fd, 0); - } - - uint32_t read_u32(int fd) { - return read_exact_or(fd, 0); - } - - size_t read_usize(int fd) { - return read_exact_or(fd, 0); - } - - bool write_usize(int fd, size_t val) { - return write_exact(fd, val); - } - - std::string read_string(int fd) { - size_t len = read_usize(fd); - - char buf[len + 1]; - xread(fd, buf, len); - - buf[len] = '\0'; - - return buf; - } - - bool write_u8(int fd, uint8_t val) { - return write_exact(fd, val); - } - - void* recv_fds(int sockfd, char* cmsgbuf, size_t bufsz, int cnt) { - iovec iov = { - .iov_base = &cnt, - .iov_len = sizeof(cnt), - }; - msghdr msg = { - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = cmsgbuf, - .msg_controllen = bufsz - }; - - xrecvmsg(sockfd, &msg, MSG_WAITALL); - cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); - - if (msg.msg_controllen != bufsz || - cmsg == nullptr || - // TODO: pass from rust: 20, expected: 16 - // cmsg->cmsg_len != CMSG_LEN(sizeof(int) * cnt) || - cmsg->cmsg_level != SOL_SOCKET || - cmsg->cmsg_type != SCM_RIGHTS) { - return nullptr; - } - - return CMSG_DATA(cmsg); - } - - int recv_fd(int sockfd) { - char cmsgbuf[CMSG_SPACE(sizeof(int))]; - - void* data = recv_fds(sockfd, cmsgbuf, sizeof(cmsgbuf), 1); - if (data == nullptr) return -1; - - int result; - memcpy(&result, data, sizeof(int)); - return result; - } - - bool write_u32(int fd, uint32_t val) { - return write_exact(fd, val); - } - - bool write_string(int fd, std::string_view str) { - return write_usize(fd, str.size()) && str.size() == xwrite(fd, str.data(), str.size()); - } -} diff --git a/loader/src/include/daemon.h b/loader/src/include/daemon.h index 9bc3617..977eca5 100644 --- a/loader/src/include/daemon.h +++ b/loader/src/include/daemon.h @@ -1,113 +1,85 @@ -#pragma once +#ifndef DAEMON_H +#define DAEMON_H +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ -#include -#include #include -#include -#if defined(__LP64__) -# define LP_SELECT(lp32, lp64) lp64 +#ifdef __LP64__ + #define LP_SELECT(lp32, lp64) lp64 #else -# define LP_SELECT(lp32, lp64) lp32 + #define LP_SELECT(lp32, lp64) lp32 #endif -constexpr auto kCPSocketName = "/" LP_SELECT("cp32", "cp64") ".sock"; +#define SOCKET_FILE_NAME LP_SELECT("cp32", "cp64") ".sock" -class UniqueFd { - using Fd = int; -public: - UniqueFd() = default; - - UniqueFd(Fd fd) : fd_(fd) {} - - ~UniqueFd() { if (fd_ >= 0) close(fd_); } - - // Disallow copy - UniqueFd(const UniqueFd&) = delete; - - UniqueFd& operator=(const UniqueFd&) = delete; - - // Allow move - UniqueFd(UniqueFd&& other) { std::swap(fd_, other.fd_); } - - UniqueFd& operator=(UniqueFd&& other) { - std::swap(fd_, other.fd_); - return *this; - } - - // Implict cast to Fd - operator const Fd&() const { return fd_; } - -private: - Fd fd_ = -1; +enum rezygiskd_actions { + PingHeartbeat, + GetProcessFlags, + GetInfo, + ReadModules, + RequestCompanionSocket, + GetModuleDir, + ZygoteRestart, + SystemServerStarted, + UpdateMountNamespace }; -struct zygote_modules { +struct zygisk_modules { char **modules; size_t modules_count; }; -enum zygote_root_impl { - ZYGOTE_ROOT_IMPL_NONE, - ZYGOTE_ROOT_IMPL_APATCH, - ZYGOTE_ROOT_IMPL_KERNELSU, - ZYGOTE_ROOT_IMPL_MAGISK +enum root_impl { + ROOT_IMPL_NONE, + ROOT_IMPL_APATCH, + ROOT_IMPL_KERNELSU, + ROOT_IMPL_MAGISK }; -struct zygote_info { - struct zygote_modules *modules; - enum zygote_root_impl root_impl; +struct rezygisk_info { + struct zygisk_modules *modules; + enum root_impl root_impl; pid_t pid; bool running; }; enum mount_namespace_state { - Clean, - Rooted, - Module + Clean, + Rooted, + Module }; -namespace zygiskd { +void rezygiskd_init(const char *path); - struct ModuleInfo { - std::string path; - /* TODO: Perhaps we can also remove this and just send paths? */ - std::string name; +void rezygiskd_get_path(char *buf, size_t buf_size); - inline explicit ModuleInfo(std::string path, std::string name) : path(path), name(name) {} - }; +int rezygiskd_connect(uint8_t retry); - enum class SocketAction { - PingHeartBeat, - GetProcessFlags, - GetInfo, - ReadModules, - RequestCompanionSocket, - GetModuleDir, - ZygoteRestart, - SystemServerStarted, - UpdateMountNamespace - }; +bool rezygiskd_ping(); - void Init(const char *path); +uint32_t rezygiskd_get_process_flags(uid_t uid); - std::string GetTmpPath(); +void rezygiskd_get_info(struct rezygisk_info *info); - bool PingHeartbeat(); +void free_rezygisk_info(struct rezygisk_info *info); - std::vector ReadModules(); +bool rezygiskd_read_modules(struct zygisk_modules *modules); +void free_modules(struct zygisk_modules *modules); - uint32_t GetProcessFlags(uid_t uid); +int rezygiskd_connect_companion(size_t index); - int ConnectCompanion(size_t index); +int rezygiskd_get_module_dir(size_t index); - int GetModuleDir(size_t index); +void rezygiskd_zygote_restart(); - void ZygoteRestart(); +void rezygiskd_system_server_started(); - void SystemServerStarted(); +bool rezygiskd_update_mns(enum mount_namespace_state nms_state, char *buf, size_t buf_size); - void GetInfo(struct zygote_info *info); - - std::string UpdateMountNamespace(enum mount_namespace_state mns_state); +#ifdef __cplusplus } +#endif /* __cplusplus */ + +#endif /* DAEMON_H */ \ No newline at end of file diff --git a/loader/src/include/elf_util.h b/loader/src/include/elf_util.h index fd24ecd..e1c4949 100644 --- a/loader/src/include/elf_util.h +++ b/loader/src/include/elf_util.h @@ -6,8 +6,6 @@ #include #include -#define restrict /* INFO: Temporary measure */ - #define SHT_GNU_HASH 0x6ffffff6 struct symtabs { diff --git a/loader/src/include/files.hpp b/loader/src/include/files.hpp deleted file mode 100644 index ce49e8f..0000000 --- a/loader/src/include/files.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include -#include - -struct mount_info { - unsigned int id; - unsigned int parent; - dev_t device; - std::string root; - std::string target; - std::string vfs_option; - struct { - unsigned int shared; - unsigned int master; - unsigned int propagate_from; - } optional; - std::string type; - std::string source; - std::string fs_option; -}; - -std::vector parse_mount_info(const char *pid); diff --git a/loader/src/include/misc.h b/loader/src/include/misc.h new file mode 100644 index 0000000..168b9fb --- /dev/null +++ b/loader/src/include/misc.h @@ -0,0 +1,17 @@ +#ifndef MISC_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Bionic's atoi runs through strtol(). + * Use our own implementation for faster conversion. + */ +int parse_int(const char *str); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* MISC_H */ \ No newline at end of file diff --git a/loader/src/include/misc.hpp b/loader/src/include/misc.hpp deleted file mode 100644 index b526145..0000000 --- a/loader/src/include/misc.hpp +++ /dev/null @@ -1,98 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "logging.h" - -#define DISALLOW_COPY_AND_MOVE(clazz) \ -clazz(const clazz &) = delete; \ -clazz(clazz &&) = delete; - -class mutex_guard { - DISALLOW_COPY_AND_MOVE(mutex_guard) -public: - explicit mutex_guard(pthread_mutex_t &m): mutex(&m) { - pthread_mutex_lock(mutex); - } - void unlock() { - pthread_mutex_unlock(mutex); - mutex = nullptr; - } - ~mutex_guard() { - if (mutex) pthread_mutex_unlock(mutex); - } -private: - pthread_mutex_t *mutex; -}; - -using thread_entry = void *(*)(void *); -int new_daemon_thread(thread_entry entry, void *arg); - -static inline bool str_contains(std::string_view s, std::string_view ss) { - return s.find(ss) != std::string_view::npos; -} - -template -class stateless_allocator { -public: - using value_type = T; - T *allocate(size_t num) { return static_cast(Impl::allocate(sizeof(T) * num)); } - void deallocate(T *ptr, size_t num) { Impl::deallocate(ptr, sizeof(T) * num); } - stateless_allocator() = default; - stateless_allocator(const stateless_allocator&) = default; - stateless_allocator(stateless_allocator&&) = default; - template - stateless_allocator(const stateless_allocator&) {} - bool operator==(const stateless_allocator&) { return true; } - bool operator!=(const stateless_allocator&) { return false; } -}; - -template -class reversed_container { -public: - reversed_container(T &base) : base(base) {} - decltype(std::declval().rbegin()) begin() { return base.rbegin(); } - decltype(std::declval().crbegin()) begin() const { return base.crbegin(); } - decltype(std::declval().crbegin()) cbegin() const { return base.crbegin(); } - decltype(std::declval().rend()) end() { return base.rend(); } - decltype(std::declval().crend()) end() const { return base.crend(); } - decltype(std::declval().crend()) cend() const { return base.crend(); } -private: - T &base; -}; - -template -reversed_container reversed(T &base) { - return reversed_container(base); -} - -template -static inline void default_new(T *&p) { p = new T(); } - -template -static inline void default_new(std::unique_ptr &p) { p.reset(new T()); } - -struct StringCmp { - using is_transparent = void; - bool operator()(std::string_view a, std::string_view b) const { return a < b; } -}; - -/* - * Bionic's atoi runs through strtol(). - * Use our own implementation for faster conversion. - */ -int parse_int(std::string_view s); - -std::list split_str(std::string_view s, std::string_view delimiter); - -std::string join_str(const std::list& list, std::string_view delimiter); - -template -static inline T align_to(T v, int a) { - static_assert(std::is_integral::value); - return (v + a - 1) / a * a; -} diff --git a/loader/src/include/socket_utils.h b/loader/src/include/socket_utils.h index 09330de..4c40559 100644 --- a/loader/src/include/socket_utils.h +++ b/loader/src/include/socket_utils.h @@ -1,31 +1,25 @@ -#pragma once +#ifndef SOCKET_UTILS_H +#define SOCKET_UTILS_H -#include -#include +#include -#include "logging.h" +int read_fd(int fd); + +char *read_string(int fd); -namespace socket_utils { +#define write_func_def(type) \ + ssize_t write_## type(int fd, type val) - ssize_t xread(int fd, void *buf, size_t count); +#define read_func_def(type) \ + ssize_t read_## type(int fd, type *val) - size_t xwrite(int fd, const void *buf, size_t count); +write_func_def(uint8_t); +read_func_def(uint8_t); - uint8_t read_u8(int fd); +write_func_def(uint32_t); +read_func_def(uint32_t); - uint32_t read_u32(int fd); +write_func_def(size_t); +read_func_def(size_t); - size_t read_usize(int fd); - - std::string read_string(int fd); - - bool write_u8(int fd, uint8_t val); - - bool write_u32(int fd, uint32_t val); - - int recv_fd(int fd); - - bool write_usize(int fd, size_t val); - - bool write_string(int fd, std::string_view str); -} +#endif /* SOCKET_UTILS_H */ \ No newline at end of file diff --git a/loader/src/injector/art_method.hpp b/loader/src/injector/art_method.hpp index 461d9dc..271e01a 100644 --- a/loader/src/injector/art_method.hpp +++ b/loader/src/injector/art_method.hpp @@ -1,5 +1,6 @@ #pragma once +#include "logging.h" #include "jni_helper.hpp" template diff --git a/loader/src/injector/entry.cpp b/loader/src/injector/entry.cpp index fabe209..dbbe379 100644 --- a/loader/src/injector/entry.cpp +++ b/loader/src/injector/entry.cpp @@ -12,10 +12,11 @@ void entry(void* addr, size_t size, const char* path) { LOGD("Zygisk library injected, version %s", ZKSU_VERSION); start_addr = addr; block_size = size; - zygiskd::Init(path); + rezygiskd_init(path); - if (!zygiskd::PingHeartbeat()) { + if (!rezygiskd_ping()) { LOGE("Zygisk daemon is not running"); + return; } diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index 6a63979..a37b542 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -16,12 +17,12 @@ #include #include +#include #include "daemon.h" #include "zygisk.hpp" #include "module.hpp" -#include "files.hpp" -#include "misc.hpp" +#include "misc.h" #include "solist.h" @@ -121,7 +122,7 @@ struct ZygiskContext { // Global variables vector> *plt_hook_list; -map, StringCmp> *jni_hook_list; +map> *jni_hook_list; bool should_unmap_zygisk = false; std::vector cached_map_infos = {}; @@ -139,8 +140,8 @@ DCL_HOOK_FUNC(int, fork) { } bool update_mnt_ns(enum mount_namespace_state mns_state, bool dry_run) { - std::string ns_path = zygiskd::UpdateMountNamespace(mns_state); - if (ns_path.empty()) { + char ns_path[PATH_MAX]; + if (rezygiskd_update_mns(mns_state, ns_path, sizeof(ns_path)) == false) { PLOGE("Failed to update mount namespace"); return false; @@ -148,16 +149,16 @@ bool update_mnt_ns(enum mount_namespace_state mns_state, bool dry_run) { if (dry_run) return true; - int updated_ns = open(ns_path.data(), O_RDONLY); + int updated_ns = open(ns_path, O_RDONLY); if (updated_ns == -1) { - PLOGE("Failed to open mount namespace [%s]", ns_path.data()); + PLOGE("Failed to open mount namespace [%s]", ns_path); return false; } - LOGD("set mount namespace to [%s] fd=[%d]\n", ns_path.data(), updated_ns); + LOGD("set mount namespace to [%s] fd=[%d]\n", ns_path, updated_ns); if (setns(updated_ns, CLONE_NEWNS) == -1) { - PLOGE("Failed to set mount namespace [%s]", ns_path.data()); + PLOGE("Failed to set mount namespace [%s]", ns_path); close(updated_ns); return false; @@ -180,6 +181,8 @@ DCL_HOOK_FUNC(int, unshare, int flags) { update_mnt_ns(Rooted, false); } else if (!(g_ctx->flags[DO_REVERT_UNMOUNT])) { update_mnt_ns(Module, false); + } else { + LOGI("Process [%s] is on denylist, skipping unmount", g_ctx->process); } old_unshare(CLONE_NEWNS); @@ -389,8 +392,9 @@ void ZygiskContext::plt_hook_register(const char *regex, const char *symbol, voi regex_t re; if (regcomp(&re, regex, REG_NOSUB) != 0) return; - mutex_guard lock(hook_info_lock); + pthread_mutex_lock(&hook_info_lock); register_info.emplace_back(RegisterInfo{re, symbol, fn, backup}); + pthread_mutex_unlock(&hook_info_lock); } void ZygiskContext::plt_hook_exclude(const char *regex, const char *symbol) { @@ -398,8 +402,9 @@ void ZygiskContext::plt_hook_exclude(const char *regex, const char *symbol) { regex_t re; if (regcomp(&re, regex, REG_NOSUB) != 0) return; - mutex_guard lock(hook_info_lock); + pthread_mutex_lock(&hook_info_lock); ignore_info.emplace_back(IgnoreInfo{re, symbol ?: ""}); + pthread_mutex_unlock(&hook_info_lock); } void ZygiskContext::plt_hook_process_regex() { @@ -428,11 +433,13 @@ void ZygiskContext::plt_hook_process_regex() { bool ZygiskContext::plt_hook_commit() { { - mutex_guard lock(hook_info_lock); + pthread_mutex_lock(&hook_info_lock); plt_hook_process_regex(); register_info.clear(); ignore_info.clear(); + pthread_mutex_unlock(&hook_info_lock); } + return lsplt::CommitHook(cached_map_infos); } @@ -454,12 +461,12 @@ bool ZygiskModule::valid() const { /* Zygisksu changed: Use own zygiskd */ int ZygiskModule::connectCompanion() const { - return zygiskd::ConnectCompanion(id); + return rezygiskd_connect_companion(id); } /* Zygisksu changed: Use own zygiskd */ int ZygiskModule::getModuleDir() const { - return zygiskd::GetModuleDir(id); + return rezygiskd_get_module_dir(id); } void ZygiskModule::setOption(zygisk::Option opt) { @@ -596,21 +603,26 @@ void ZygiskContext::fork_post() { /* Zygisksu changed: Load module fds */ void ZygiskContext::run_modules_pre() { - auto ms = zygiskd::ReadModules(); - auto size = ms.size(); - for (size_t i = 0; i < size; i++) { - auto &m = ms[i]; + struct zygisk_modules ms; + if (rezygiskd_read_modules(&ms) == false) { + LOGE("Failed to read modules from zygiskd"); - void *handle = dlopen(m.path.c_str(), RTLD_NOW); + return; + } + + for (size_t i = 0; i < ms.modules_count; i++) { + char *lib_path = ms.modules[i]; + + void *handle = dlopen(lib_path, RTLD_NOW); if (!handle) { - LOGE("Failed to load module [%s]: %s", m.path.c_str(), dlerror()); + LOGE("Failed to load module [%s]: %s", lib_path, dlerror()); continue; } void *entry = dlsym(handle, "zygisk_module_entry"); if (!entry) { - LOGE("Failed to find entry point in module [%s]: %s", m.path.c_str(), dlerror()); + LOGE("Failed to find entry point in module [%s]: %s", lib_path, dlerror()); dlclose(handle); @@ -620,6 +632,8 @@ void ZygiskContext::run_modules_pre() { modules.emplace_back(i, handle, entry); } + free_modules(&ms); + for (auto &m : modules) { m.onLoad(env); if (flags[APP_SPECIALIZE]) m.preAppSpecialize(args.app); @@ -648,7 +662,7 @@ void ZygiskContext::run_modules_post() { void ZygiskContext::app_specialize_pre() { flags[APP_SPECIALIZE] = true; - info_flags = zygiskd::GetProcessFlags(g_ctx->args.app->uid); + info_flags = rezygiskd_get_process_flags(g_ctx->args.app->uid); if (info_flags & PROCESS_IS_FIRST_STARTED) { update_mnt_ns(Clean, true); } @@ -707,7 +721,7 @@ void ZygiskContext::nativeForkSystemServer_pre() { fork_pre(); if (is_child()) { run_modules_pre(); - zygiskd::SystemServerStarted(); + rezygiskd_system_server_started(); } sanitize_fds(); @@ -834,14 +848,11 @@ void clean_trace(const char* path, size_t load, size_t unload, bool spoof_maps) } void hook_functions() { - default_new(plt_hook_list); - default_new(jni_hook_list); + plt_hook_list = new vector>(); + jni_hook_list = new map>(); ino_t android_runtime_inode = 0; dev_t android_runtime_dev = 0; - /* TODO by ThePedroo: Implement injection via native bridge */ - // ino_t native_bridge_inode = 0; - // dev_t native_bridge_dev = 0; cached_map_infos = lsplt::MapInfo::Scan(); for (auto &map : cached_map_infos) { diff --git a/loader/src/include/solist.h b/loader/src/injector/solist.h similarity index 99% rename from loader/src/include/solist.h rename to loader/src/injector/solist.h index 906b56f..db726c1 100644 --- a/loader/src/include/solist.h +++ b/loader/src/injector/solist.h @@ -1,7 +1,6 @@ #ifndef SOLIST_H #define SOLIST_H -/* INFO: Temporary */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ diff --git a/loader/src/ptracer/main.cpp b/loader/src/ptracer/main.cpp index 3e833d6..9122f9c 100644 --- a/loader/src/ptracer/main.cpp +++ b/loader/src/ptracer/main.cpp @@ -5,7 +5,7 @@ #include "daemon.h" int main(int argc, char **argv) { - zygiskd::Init("/data/adb/rezygisk"); + rezygiskd_init("/data/adb/rezygisk"); printf("The ReZygisk Tracer %s\n\n", ZKSU_VERSION); @@ -16,7 +16,7 @@ int main(int argc, char **argv) { return 0; } else if (argc >= 3 && strcmp(argv[1], "trace") == 0) { - if (argc >= 4 && strcmp(argv[3], "--restart") == 0) zygiskd::ZygoteRestart(); + if (argc >= 4 && strcmp(argv[3], "--restart") == 0) rezygiskd_zygote_restart(); long pid = strtol(argv[2], 0, 0); if (!trace_zygote(pid)) { @@ -54,28 +54,28 @@ int main(int argc, char **argv) { return 0; } else if (argc >= 2 && strcmp(argv[1], "info") == 0) { - struct zygote_info info; - zygiskd::GetInfo(&info); + struct rezygisk_info info; + rezygiskd_get_info(&info); printf("Daemon process PID: %d\n", info.pid); switch (info.root_impl) { - case ZYGOTE_ROOT_IMPL_NONE: { + case ROOT_IMPL_NONE: { printf("Root implementation: none\n"); break; } - case ZYGOTE_ROOT_IMPL_APATCH: { + case ROOT_IMPL_APATCH: { printf("Root implementation: APatch\n"); - + break; } - case ZYGOTE_ROOT_IMPL_KERNELSU: { + case ROOT_IMPL_KERNELSU: { printf("Root implementation: KernelSU\n"); break; } - case ZYGOTE_ROOT_IMPL_MAGISK: { + case ROOT_IMPL_MAGISK: { printf("Root implementation: Magisk\n"); break; diff --git a/loader/src/ptracer/monitor.cpp b/loader/src/ptracer/monitor.cpp index af7f28c..5217ea5 100644 --- a/loader/src/ptracer/monitor.cpp +++ b/loader/src/ptracer/monitor.cpp @@ -14,8 +14,7 @@ #include "monitor.h" #include "utils.hpp" -#include "files.hpp" -#include "misc.hpp" +#include "misc.h" #define STOPPED_WITH(sig, event) WIFSTOPPED(status) && (status >> 8 == ((sig) | (event << 8))) @@ -140,7 +139,10 @@ struct SocketHandler : public EventHandler { .sun_path = { 0 } }; - size_t sun_path_len = sprintf(addr.sun_path, "%s/%s", zygiskd::GetTmpPath().c_str(), SOCKET_NAME); + char tmp_path[PATH_MAX]; + rezygiskd_get_path(tmp_path, sizeof(tmp_path)); + + size_t sun_path_len = sprintf(addr.sun_path, "%s/%s", tmp_path, SOCKET_NAME); socklen_t socklen = sizeof(sa_family_t) + sun_path_len; if (bind(sock_fd_, (struct sockaddr *)&addr, socklen) == -1) { @@ -747,7 +749,10 @@ static void updateStatus() { } static bool prepare_environment() { - strcat(prop_path, zygiskd::GetTmpPath().c_str()); + char tmp_path[PATH_MAX]; + rezygiskd_get_path(tmp_path, sizeof(tmp_path)); + + strcat(prop_path, tmp_path); strcat(prop_path, "/module.prop"); close(open(prop_path, O_WRONLY | O_CREAT | O_TRUNC, 0644)); @@ -817,7 +822,11 @@ int send_control_command(enum Command cmd) { .sun_path = { 0 } }; - size_t sun_path_len = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", zygiskd::GetTmpPath().c_str(), SOCKET_NAME); + char tmp_path[PATH_MAX]; + rezygiskd_get_path(tmp_path, sizeof(tmp_path)); + + size_t sun_path_len = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", tmp_path, SOCKET_NAME); + socklen_t socklen = sizeof(sa_family_t) + sun_path_len; ssize_t nsend = sendto(sockfd, (void *)&cmd, sizeof(cmd), 0, (sockaddr *)&addr, socklen); diff --git a/loader/src/ptracer/ptracer.cpp b/loader/src/ptracer/ptracer.cpp index f790f98..c8a7571 100644 --- a/loader/src/ptracer/ptracer.cpp +++ b/loader/src/ptracer/ptracer.cpp @@ -240,7 +240,11 @@ bool inject_on_main(int pid, const char *lib_path) { args.clear(); args.push_back((uintptr_t) start_addr); args.push_back(block_size); - str = push_string(pid, regs, zygiskd::GetTmpPath().c_str()); + + char tmp_path[PATH_MAX]; + rezygiskd_get_path(tmp_path, sizeof(tmp_path)); + + str = push_string(pid, regs, tmp_path); args.push_back((long) str); remote_call(pid, regs, injector_entry, (uintptr_t)libc_return_addr, args); @@ -287,10 +291,12 @@ bool trace_zygote(int pid) { if (STOPPED_WITH(SIGSTOP, PTRACE_EVENT_STOP)) { /* WARNING: C++ keyword */ - std::string lib_path = zygiskd::GetTmpPath(); - lib_path += "/lib" LP_SELECT("", "64") "/libzygisk.so"; + char lib_path[PATH_MAX]; + rezygiskd_get_path(lib_path, sizeof(lib_path)); - if (!inject_on_main(pid, lib_path.c_str())) { + strcat(lib_path,"/lib" LP_SELECT("", "64") "/libzygisk.so"); + + if (!inject_on_main(pid, lib_path)) { LOGE("failed to inject"); return false; From b94ea0c5f5ab3583bfca3c8a09d7e99fce830965 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Mon, 14 Apr 2025 19:32:49 -0300 Subject: [PATCH 37/46] improve: port ptracer to C This commit ports the C++ to C99 from zygisk-ptracer code, allowing a ~3x size reduce in its binary. --- loader/build.gradle.kts | 2 + loader/src/CMakeLists.txt | 5 +- loader/src/common/daemon.c | 31 +- loader/src/common/elf_util.c | 2 - loader/src/common/misc.c | 18 +- loader/src/include/daemon.h | 9 +- loader/src/include/native_bridge_callbacks.h | 33 - loader/src/injector/entry.cpp | 2 +- loader/src/injector/hook.cpp | 11 +- loader/src/injector/solist.c | 2 - loader/src/ptracer/{main.cpp => main.c} | 17 +- loader/src/ptracer/monitor.c | 892 ++++++++++++++++++ loader/src/ptracer/monitor.cpp | 838 ---------------- loader/src/ptracer/monitor.h | 10 +- loader/src/ptracer/{ptracer.cpp => ptracer.c} | 179 ++-- loader/src/ptracer/utils.c | 578 ++++++++++++ loader/src/ptracer/utils.cpp | 528 ----------- loader/src/ptracer/utils.h | 109 +++ loader/src/ptracer/utils.hpp | 125 --- zygiskd/src/utils.h | 2 +- zygiskd/src/zygiskd.c | 36 +- 21 files changed, 1739 insertions(+), 1690 deletions(-) delete mode 100644 loader/src/include/native_bridge_callbacks.h rename loader/src/ptracer/{main.cpp => main.c} (92%) create mode 100644 loader/src/ptracer/monitor.c delete mode 100644 loader/src/ptracer/monitor.cpp rename loader/src/ptracer/{ptracer.cpp => ptracer.c} (65%) create mode 100644 loader/src/ptracer/utils.c delete mode 100644 loader/src/ptracer/utils.cpp create mode 100644 loader/src/ptracer/utils.h delete mode 100644 loader/src/ptracer/utils.hpp diff --git a/loader/build.gradle.kts b/loader/build.gradle.kts index f9d9f8e..748350a 100644 --- a/loader/build.gradle.kts +++ b/loader/build.gradle.kts @@ -26,6 +26,8 @@ val ccachePath by lazy { } val defaultCFlags = arrayOf( + "-D_GNU_SOURCE", + "-Wall", "-Wextra", "-fno-rtti", "-fno-exceptions", "-fno-stack-protector", "-fomit-frame-pointer", diff --git a/loader/src/CMakeLists.txt b/loader/src/CMakeLists.txt index 84ba7b9..a0b60b5 100644 --- a/loader/src/CMakeLists.txt +++ b/loader/src/CMakeLists.txt @@ -10,7 +10,7 @@ add_definitions(-DZKSU_VERSION=\"${ZKSU_VERSION}\") aux_source_directory(common COMMON_SRC_LIST) add_library(common STATIC ${COMMON_SRC_LIST}) target_include_directories(common PRIVATE include) -target_link_libraries(common cxx::cxx log) +target_link_libraries(common log) aux_source_directory(injector INJECTOR_SRC_LIST) add_library(zygisk SHARED ${INJECTOR_SRC_LIST}) @@ -20,6 +20,5 @@ target_link_libraries(zygisk cxx::cxx log common lsplt_static phmap) aux_source_directory(ptracer PTRACER_SRC_LIST) add_executable(libzygisk_ptrace.so ${PTRACER_SRC_LIST}) target_include_directories(libzygisk_ptrace.so PRIVATE include) -target_link_libraries(libzygisk_ptrace.so cxx::cxx log common) - +target_link_libraries(libzygisk_ptrace.so log common) add_subdirectory(external) diff --git a/loader/src/common/daemon.c b/loader/src/common/daemon.c index 4a4b836..9910ef1 100644 --- a/loader/src/common/daemon.c +++ b/loader/src/common/daemon.c @@ -1,8 +1,3 @@ -// #include -// #include -// #include -// #include -// #include #include #include #include @@ -15,19 +10,6 @@ #include "daemon.h" -char daemon_path[PATH_MAX]; - -void rezygiskd_init(const char *path) { - snprintf(daemon_path, sizeof(daemon_path), "%s/%s", path, SOCKET_FILE_NAME); -} - -void rezygiskd_get_path(char *buf, size_t buf_size) { - size_t fileless_daemon_path = strlen(daemon_path) - strlen("/") - strlen(SOCKET_FILE_NAME); - - strncpy(buf, daemon_path, buf_size > fileless_daemon_path ? fileless_daemon_path : buf_size); - buf[fileless_daemon_path] = '\0'; -} - int rezygiskd_connect(uint8_t retry) { retry++; @@ -49,7 +31,7 @@ int rezygiskd_connect(uint8_t retry) { Sources: - https://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/un.h.html */ - strcpy(addr.sun_path, daemon_path); + strcpy(addr.sun_path, TMP_PATH "/" SOCKET_FILE_NAME); socklen_t socklen = sizeof(addr); while (--retry) { @@ -343,15 +325,18 @@ bool rezygiskd_update_mns(enum mount_namespace_state nms_state, char *buf, size_ write_uint8_t(fd, (uint8_t)nms_state); uint32_t target_pid = 0; - read_uint32_t(fd, &target_pid); - if (target_pid == 0) { + if (read_uint32_t(fd, &target_pid) < 0) { + PLOGE("Failed to read target pid"); + close(fd); return false; } - int target_fd = read_fd(fd); - if (target_fd == -1) { + uint32_t target_fd = 0; + if (read_uint32_t(fd, &target_fd) < 0) { + PLOGE("Failed to read target fd"); + close(fd); return false; diff --git a/loader/src/common/elf_util.c b/loader/src/common/elf_util.c index bfe89ba..bb4ee69 100644 --- a/loader/src/common/elf_util.c +++ b/loader/src/common/elf_util.c @@ -1,5 +1,3 @@ -/* INFO: This file is written in C99 */ - #include #include #include diff --git a/loader/src/common/misc.c b/loader/src/common/misc.c index 8d84de4..bf80144 100644 --- a/loader/src/common/misc.c +++ b/loader/src/common/misc.c @@ -1,14 +1,14 @@ int parse_int(const char *str) { - int val = 0; + int val = 0; - char *c = (char *)str; - while (*c) { - if (*c > '9' || *c < '0') - return -1; + char *c = (char *)str; + while (*c) { + if (*c > '9' || *c < '0') + return -1; - val = val * 10 + *c - '0'; - c++; - } + val = val * 10 + *c - '0'; + c++; + } - return val; + return val; } diff --git a/loader/src/include/daemon.h b/loader/src/include/daemon.h index 977eca5..c00dd7a 100644 --- a/loader/src/include/daemon.h +++ b/loader/src/include/daemon.h @@ -1,9 +1,12 @@ #ifndef DAEMON_H #define DAEMON_H + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ +#include + #include #ifdef __LP64__ @@ -51,9 +54,11 @@ enum mount_namespace_state { Module }; -void rezygiskd_init(const char *path); +#define TMP_PATH "/data/adb/rezygisk" -void rezygiskd_get_path(char *buf, size_t buf_size); +static inline const char *rezygiskd_get_path() { + return TMP_PATH; +} int rezygiskd_connect(uint8_t retry); diff --git a/loader/src/include/native_bridge_callbacks.h b/loader/src/include/native_bridge_callbacks.h deleted file mode 100644 index 60ff4be..0000000 --- a/loader/src/include/native_bridge_callbacks.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -template -struct NativeBridgeCallbacks; - -template<> -struct NativeBridgeCallbacks<__ANDROID_API_Q__> { - [[maybe_unused]] uint32_t version; - [[maybe_unused]] void *initialize; - [[maybe_unused]] void *loadLibrary; - [[maybe_unused]] void *getTrampoline; - [[maybe_unused]] void *isSupported; - [[maybe_unused]] void *getAppEnv; - [[maybe_unused]] void *isCompatibleWith; - [[maybe_unused]] void *getSignalHandler; - [[maybe_unused]] void *unloadLibrary; - [[maybe_unused]] void *getError; - [[maybe_unused]] void *isPathSupported; - [[maybe_unused]] void *initAnonymousNamespace; - [[maybe_unused]] void *createNamespace; - [[maybe_unused]] void *linkNamespaces; - [[maybe_unused]] void *loadLibraryExt; - [[maybe_unused]] void *getVendorNamespace; - [[maybe_unused]] void *getExportedNamespace; -}; - -template<> -struct NativeBridgeCallbacks<__ANDROID_API_R__> : NativeBridgeCallbacks<__ANDROID_API_Q__> { - [[maybe_unused]] void *preZygoteFork; -}; diff --git a/loader/src/injector/entry.cpp b/loader/src/injector/entry.cpp index dbbe379..543a374 100644 --- a/loader/src/injector/entry.cpp +++ b/loader/src/injector/entry.cpp @@ -10,9 +10,9 @@ size_t block_size = 0; extern "C" [[gnu::visibility("default")]] void entry(void* addr, size_t size, const char* path) { LOGD("Zygisk library injected, version %s", ZKSU_VERSION); + start_addr = addr; block_size = size; - rezygiskd_init(path); if (!rezygiskd_ping()) { LOGE("Zygisk daemon is not running"); diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index a37b542..c50af31 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -181,8 +181,6 @@ DCL_HOOK_FUNC(int, unshare, int flags) { update_mnt_ns(Rooted, false); } else if (!(g_ctx->flags[DO_REVERT_UNMOUNT])) { update_mnt_ns(Module, false); - } else { - LOGI("Process [%s] is on denylist, skipping unmount", g_ctx->process); } old_unshare(CLONE_NEWNS); @@ -636,6 +634,7 @@ void ZygiskContext::run_modules_pre() { for (auto &m : modules) { m.onLoad(env); + if (flags[APP_SPECIALIZE]) m.preAppSpecialize(args.app); else if (flags[SERVER_FORK_AND_SPECIALIZE]) m.preServerSpecialize(args.server); } @@ -674,6 +673,12 @@ void ZygiskContext::app_specialize_pre() { if ((info_flags & (PROCESS_IS_MANAGER | PROCESS_ROOT_IS_MAGISK)) == (PROCESS_IS_MANAGER | PROCESS_ROOT_IS_MAGISK)) { LOGD("Manager process detected. Notifying that Zygisk has been enabled."); + /* INFO: This environment variable is related to Magisk Zygisk/Manager. It + it used by Magisk's Zygisk to communicate to Magisk Manager whether + Zygisk is working or not. + + To allow Zygisk modules to both work properly and for the manager to + identify Zygisk, being it not built-in, as working, we also set it. */ setenv("ZYGISK_ENABLED", "1", 1); } else { run_modules_pre(); @@ -818,7 +823,7 @@ void clean_trace(const char* path, size_t load, size_t unload, bool spoof_maps) if (load > 0 || unload > 0) solist_reset_counters(load, unload); - LOGI("Dropping solist record for %s", path); + LOGD("Dropping solist record for %s", path); bool path_found = solist_drop_so_path(path); if (!path_found || !spoof_maps) return; diff --git a/loader/src/injector/solist.c b/loader/src/injector/solist.c index b338938..1e460a8 100644 --- a/loader/src/injector/solist.c +++ b/loader/src/injector/solist.c @@ -1,5 +1,3 @@ -/* INFO: This file is written in C99 */ - #include #include #include diff --git a/loader/src/ptracer/main.cpp b/loader/src/ptracer/main.c similarity index 92% rename from loader/src/ptracer/main.cpp rename to loader/src/ptracer/main.c index 9122f9c..2b76131 100644 --- a/loader/src/ptracer/main.cpp +++ b/loader/src/ptracer/main.c @@ -1,19 +1,22 @@ #include +#include + +#ifdef __LP64__ + #define LOG_TAG "zygisk-ptrace64" +#else + #define LOG_TAG "zygisk-ptrace32" +#endif #include "monitor.h" -#include "utils.hpp" +#include "utils.h" #include "daemon.h" int main(int argc, char **argv) { - rezygiskd_init("/data/adb/rezygisk"); - printf("The ReZygisk Tracer %s\n\n", ZKSU_VERSION); if (argc >= 2 && strcmp(argv[1], "monitor") == 0) { init_monitor(); - printf("[ReZygisk]: Started monitoring...\n"); - return 0; } else if (argc >= 3 && strcmp(argv[1], "trace") == 0) { if (argc >= 4 && strcmp(argv[3], "--restart") == 0) rezygiskd_zygote_restart(); @@ -25,11 +28,9 @@ int main(int argc, char **argv) { return 1; } - printf("[ReZygisk]: Tracing %ld...\n", pid); - return 0; } else if (argc >= 2 && strcmp(argv[1], "ctl") == 0) { - enum Command command; + enum rezygiskd_command command; if (strcmp(argv[2], "start") == 0) command = START; else if (strcmp(argv[2], "stop") == 0) command = STOP; diff --git a/loader/src/ptracer/monitor.c b/loader/src/ptracer/monitor.c new file mode 100644 index 0000000..8188e84 --- /dev/null +++ b/loader/src/ptracer/monitor.c @@ -0,0 +1,892 @@ +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "daemon.h" +#include "utils.h" +#include "misc.h" + +#include "monitor.h" + +#define PROP_PATH TMP_PATH "/module.prop" +#define SOCKET_NAME "init_monitor" + +#define STOPPED_WITH(sig, event) WIFSTOPPED(sigchld_status) && (sigchld_status >> 8 == ((sig) | (event << 8))) + +static bool update_status(const char *message); + +char monitor_stop_reason[32]; + +enum ptracer_tracing_state { + TRACING, + STOPPING, + STOPPED, + EXITING +}; + +enum ptracer_tracing_state tracing_state = TRACING; + +struct rezygiskd_status { + bool supported; + bool zygote_injected; + bool daemon_running; + pid_t daemon_pid; + char *daemon_info; + char *daemon_error_info; +}; + +struct rezygiskd_status status64 = { + .daemon_pid = -1 +}; +struct rezygiskd_status status32 = { + .daemon_pid = -1 +}; + +int monitor_epoll_fd; +bool monitor_events_running = true; + +bool monitor_events_init() { + monitor_epoll_fd = epoll_create(1); + if (monitor_epoll_fd == -1) { + PLOGE("epoll_create"); + + return false; + } + + return true; +} + +struct monitor_event_cbs { + void (*callback)(); + void (*stop_callback)(); +}; + +bool monitor_events_register_event(struct monitor_event_cbs *event_cbs, int fd, uint32_t events) { + struct epoll_event ev = { + .data.ptr = event_cbs, + .events = events + }; + + if (epoll_ctl(monitor_epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) { + PLOGE("epoll_ctl"); + + return false; + } + + return true; +} + +bool monitor_events_unregister_event(int fd) { + if (epoll_ctl(monitor_epoll_fd, EPOLL_CTL_DEL, fd, NULL) == -1) { + PLOGE("epoll_ctl"); + + return false; + } + + return true; +} + +void monitor_events_stop() { + monitor_events_running = false; +}; + +void monitor_events_loop() { + struct epoll_event events[2]; + while (monitor_events_running) { + int nfds = epoll_wait(monitor_epoll_fd, events, 2, -1); + if (nfds == -1) { + if (errno != EINTR) PLOGE("epoll_wait"); + + continue; + } + + for (int i = 0; i < nfds; i++) { + struct monitor_event_cbs *event_cbs = (struct monitor_event_cbs *)events[i].data.ptr; + event_cbs->callback(); + + if (!monitor_events_running) break; + } + } + + if (monitor_epoll_fd >= 0) close(monitor_epoll_fd); + monitor_epoll_fd = -1; + + for (int i = 0; i < (int)(sizeof(events) / sizeof(events[0])); i++) { + struct monitor_event_cbs *event_cbs = (struct monitor_event_cbs *)events[i].data.ptr; + event_cbs->stop_callback(); + } +} + +int monitor_sock_fd; + +bool rezygiskd_listener_init() { + monitor_sock_fd = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); + if (monitor_sock_fd == -1) { + PLOGE("socket create"); + + return false; + } + + struct sockaddr_un addr = { + .sun_family = AF_UNIX, + .sun_path = { 0 } + }; + + size_t sun_path_len = sprintf(addr.sun_path, "%s/%s", rezygiskd_get_path(), SOCKET_NAME); + + socklen_t socklen = sizeof(sa_family_t) + sun_path_len; + if (bind(monitor_sock_fd, (struct sockaddr *)&addr, socklen) == -1) { + PLOGE("bind socket"); + + return false; + } + + return true; +} + +void rezygiskd_listener_callback() { + struct [[gnu::packed]] MsgHead { + enum rezygiskd_command cmd; + int length; + char data[0]; + }; + + while (1) { + struct MsgHead *msg = (struct MsgHead *)malloc(sizeof(struct MsgHead)); + + ssize_t real_size; + ssize_t nread = recv(monitor_sock_fd, msg, sizeof(struct MsgHead), MSG_PEEK); + if (nread == -1) { + if (errno == EAGAIN) break; + + PLOGE("read socket"); + } + + if ((size_t)nread < sizeof(enum rezygiskd_command)) { + LOGE("read %zu < %zu", nread, sizeof(enum rezygiskd_command)); + continue; + } + + if (msg->cmd >= DAEMON64_SET_INFO && msg->cmd != SYSTEM_SERVER_STARTED) { + if (nread != sizeof(msg)) { + LOGE("cmd %d size %zu != %zu", msg->cmd, nread, sizeof(struct MsgHead)); + + continue; + } + + real_size = sizeof(struct MsgHead) + msg->length; + } else { + if (nread != sizeof(enum rezygiskd_command)) { + LOGE("cmd %d size %zu != %zu", msg->cmd, nread, sizeof(enum rezygiskd_command)); + + continue; + } + + real_size = sizeof(enum rezygiskd_command); + } + + msg = (struct MsgHead *)realloc(msg, real_size); + nread = recv(monitor_sock_fd, msg, real_size, 0); + + if (nread == -1) { + if (errno == EAGAIN) break; + + PLOGE("recv"); + continue; + } + + if (nread != real_size) { + LOGE("real size %zu != %zu", real_size, nread); + + continue; + } + + switch (msg->cmd) { + case START: { + if (tracing_state == STOPPING) tracing_state = TRACING; + else if (tracing_state == STOPPED) { + ptrace(PTRACE_SEIZE, 1, 0, PTRACE_O_TRACEFORK); + + LOGI("start tracing init"); + + tracing_state = TRACING; + } + + update_status(NULL); + + break; + } + case STOP: { + if (tracing_state == TRACING) { + LOGI("stop tracing requested"); + + tracing_state = STOPPING; + strcpy(monitor_stop_reason, "user requested"); + + ptrace(PTRACE_INTERRUPT, 1, 0, 0); + update_status(NULL); + } + + break; + } + case EXIT: { + LOGI("prepare for exit ..."); + + tracing_state = EXITING; + strcpy(monitor_stop_reason, "user requested"); + + update_status(NULL); + monitor_events_stop(); + + break; + } + case ZYGOTE64_INJECTED: { + status64.zygote_injected = true; + + update_status(NULL); + + break; + } + case ZYGOTE32_INJECTED: { + status32.zygote_injected = true; + + update_status(NULL); + + break; + } + case DAEMON64_SET_INFO: { + LOGD("received daemon64 info %s", msg->data); + + /* Will only happen if somehow the daemon restarts */ + if (status64.daemon_info) { + free(status64.daemon_info); + status64.daemon_info = NULL; + } + + status64.daemon_info = (char *)malloc(msg->length); + if (!status64.daemon_info) { + PLOGE("malloc daemon64 info"); + + break; + } + + strcpy(status64.daemon_info, msg->data); + + update_status(NULL); + + break; + } + case DAEMON32_SET_INFO: { + LOGD("received daemon32 info %s", msg->data); + + if (status32.daemon_info) { + free(status32.daemon_info); + status32.daemon_info = NULL; + } + + status32.daemon_info = (char *)malloc(msg->length); + if (!status32.daemon_info) { + PLOGE("malloc daemon32 info"); + + break; + } + + strcpy(status32.daemon_info, msg->data); + + update_status(NULL); + + break; + } + case DAEMON64_SET_ERROR_INFO: { + LOGD("received daemon64 error info %s", msg->data); + + status64.daemon_running = false; + + if (status64.daemon_error_info) { + free(status64.daemon_error_info); + status64.daemon_error_info = NULL; + } + + status64.daemon_error_info = (char *)malloc(msg->length); + if (!status64.daemon_error_info) { + PLOGE("malloc daemon64 error info"); + + break; + } + + strcpy(status64.daemon_error_info, msg->data); + + update_status(NULL); + + break; + } + case DAEMON32_SET_ERROR_INFO: { + LOGD("received daemon32 error info %s", msg->data); + + status32.daemon_running = false; + + if (status32.daemon_error_info) { + free(status32.daemon_error_info); + status32.daemon_error_info = NULL; + } + + status32.daemon_error_info = (char *)malloc(msg->length); + if (!status32.daemon_error_info) { + PLOGE("malloc daemon32 error info"); + + break; + } + + strcpy(status32.daemon_error_info, msg->data); + + update_status(NULL); + + break; + } + case SYSTEM_SERVER_STARTED: { + LOGD("system server started, mounting prop"); + + if (mount(PROP_PATH, "/data/adb/modules/zygisksu/module.prop", NULL, MS_BIND, NULL) == -1) { + PLOGE("failed to mount prop"); + } + + break; + } + } + + free(msg); + } +} + +void rezygiskd_listener_stop() { + if (monitor_sock_fd >= 0) close(monitor_sock_fd); + monitor_sock_fd = -1; +} + +#define MAX_RETRY_COUNT 5 + +#define CREATE_ZYGOTE_START_COUNTER(abi) \ + struct timespec last_zygote##abi = { \ + .tv_sec = 0, \ + .tv_nsec = 0 \ + }; \ + \ + int count_zygote ## abi = 0; \ + bool should_stop_inject ## abi() { \ + struct timespec now = {}; \ + clock_gettime(CLOCK_MONOTONIC, &now); \ + if (now.tv_sec - last_zygote ## abi.tv_sec < 30) \ + count_zygote ## abi++; \ + else \ + count_zygote ## abi = 0; \ + \ + last_zygote##abi = now; \ + \ + return count_zygote##abi >= MAX_RETRY_COUNT; \ + } + +CREATE_ZYGOTE_START_COUNTER(64) +CREATE_ZYGOTE_START_COUNTER(32) + +static bool ensure_daemon_created(bool is_64bit) { + struct rezygiskd_status *status = is_64bit ? &status64 : &status32; + if (is_64bit) { + LOGD("new zygote started."); + + umount2("/data/adb/modules/zygisksu/module.prop", MNT_DETACH); + } + + status->zygote_injected = false; + + if (status->daemon_pid == -1) { + pid_t pid = fork(); + if (pid < 0) { + PLOGE("create daemon%s", is_64bit ? "64" : "32"); + + return false; + } else if (pid == 0) { + char daemon_name[PATH_MAX] = "./bin/zygiskd"; + strcat(daemon_name, is_64bit ? "64" : "32"); + + execl(daemon_name, daemon_name, NULL); + + PLOGE("exec daemon %s failed", daemon_name); + + exit(1); + } else { + status->supported = true; + status->daemon_pid = pid; + status->daemon_running = true; + + return true; + } + } else { + return status->daemon_running; + } +} + +#define CHECK_DAEMON_EXIT(abi) \ + if (status##abi.supported && pid == status##abi.daemon_pid) { \ + char status_str[64]; \ + parse_status(sigchld_status, status_str, sizeof(status_str)); \ + \ + LOGW("daemon" #abi " pid %d exited: %s", pid, status_str); \ + status##abi.daemon_running = false; \ + \ + if (!status##abi.daemon_error_info) { \ + status##abi.daemon_error_info = (char *)malloc(strlen(status_str) + 1); \ + if (!status##abi.daemon_error_info) { \ + LOGE("malloc daemon" #abi " error info failed"); \ + \ + return; \ + } \ + \ + memcpy(status##abi.daemon_error_info, status_str, strlen(status_str) + 1); \ + } \ + \ + update_status(NULL); \ + continue; \ + } + +#define PRE_INJECT(abi, is_64) \ + if (strcmp(program, "/system/bin/app_process" # abi) == 0) { \ + tracer = "./bin/zygisk-ptrace" # abi; \ + \ + if (should_stop_inject ## abi()) { \ + LOGW("zygote" # abi " restart too much times, stop injecting"); \ + \ + tracing_state = STOPPING; \ + memcpy(monitor_stop_reason, "zygote crashed", sizeof("zygote crashed")); \ + ptrace(PTRACE_INTERRUPT, 1, 0, 0); \ + \ + break; \ + } \ + if (!ensure_daemon_created(is_64)) { \ + LOGW("daemon" #abi " not running, stop injecting"); \ + \ + tracing_state = STOPPING; \ + memcpy(monitor_stop_reason, "daemon not running", sizeof("daemon not running")); \ + ptrace(PTRACE_INTERRUPT, 1, 0, 0); \ + \ + break; \ + } \ + } + +int sigchld_signal_fd; +struct signalfd_siginfo sigchld_fdsi; +int sigchld_status; + +pid_t *sigchld_process; +size_t sigchld_process_count = 0; + +bool sigchld_listener_init() { + sigchld_process = NULL; + + sigset_t mask; + sigemptyset(&mask); + sigaddset(&mask, SIGCHLD); + + if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) { + PLOGE("set sigprocmask"); + + return false; + } + + sigchld_signal_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC); + if (sigchld_signal_fd == -1) { + PLOGE("create signalfd"); + + return false; + } + + ptrace(PTRACE_SEIZE, 1, 0, PTRACE_O_TRACEFORK); + + return true; +} + +void sigchld_listener_callback() { + while (1) { + ssize_t s = read(sigchld_signal_fd, &sigchld_fdsi, sizeof(sigchld_fdsi)); + if (s == -1) { + if (errno == EAGAIN) break; + + PLOGE("read signalfd"); + + continue; + } + + if (s != sizeof(sigchld_fdsi)) { + LOGW("read %zu != %zu", s, sizeof(sigchld_fdsi)); + + continue; + } + + if (sigchld_fdsi.ssi_signo != SIGCHLD) { + LOGW("no sigchld received"); + + continue; + } + + int pid; + while ((pid = waitpid(-1, &sigchld_status, __WALL | WNOHANG)) != 0) { + if (pid == -1) { + if (tracing_state == STOPPED && errno == ECHILD) break; + PLOGE("waitpid"); + } + + if (pid == 1) { + if (STOPPED_WITH(SIGTRAP, PTRACE_EVENT_FORK)) { + long child_pid; + + ptrace(PTRACE_GETEVENTMSG, pid, 0, &child_pid); + + LOGV("forked %ld", child_pid); + } else if (STOPPED_WITH(SIGTRAP, PTRACE_EVENT_STOP) && tracing_state == STOPPING) { + if (ptrace(PTRACE_DETACH, 1, 0, 0) == -1) PLOGE("failed to detach init"); + + tracing_state = STOPPED; + + LOGI("stop tracing init"); + + continue; + } + + if (WIFSTOPPED(sigchld_status)) { + if (WPTEVENT(sigchld_status) == 0) { + if (WSTOPSIG(sigchld_status) != SIGSTOP && WSTOPSIG(sigchld_status) != SIGTSTP && WSTOPSIG(sigchld_status) != SIGTTIN && WSTOPSIG(sigchld_status) != SIGTTOU) { + LOGW("inject signal sent to init: %s %d", sigabbrev_np(WSTOPSIG(sigchld_status)), WSTOPSIG(sigchld_status)); + + ptrace(PTRACE_CONT, pid, 0, WSTOPSIG(sigchld_status)); + + continue; + } else { + LOGW("suppress stopping signal sent to init: %s %d", sigabbrev_np(WSTOPSIG(sigchld_status)), WSTOPSIG(sigchld_status)); + } + } + + ptrace(PTRACE_CONT, pid, 0, 0); + } + + continue; + } + + CHECK_DAEMON_EXIT(64) + CHECK_DAEMON_EXIT(32) + + pid_t state = 0; + for (size_t i = 0; i < sigchld_process_count; i++) { + if (sigchld_process[i] != pid) continue; + + state = sigchld_process[i]; + + break; + } + + if (state == 0) { + LOGV("new process %d attached", pid); + + for (size_t i = 0; i < sigchld_process_count; i++) { + if (sigchld_process[i] != 0) continue; + + sigchld_process[i] = pid; + + goto ptrace_process; + } + + sigchld_process = (pid_t *)realloc(sigchld_process, sizeof(pid_t) * (sigchld_process_count + 1)); + if (sigchld_process == NULL) { + PLOGE("realloc sigchld_process"); + + continue; + } + + sigchld_process[sigchld_process_count] = pid; + sigchld_process_count++; + + ptrace_process: + + ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_TRACEEXEC); + ptrace(PTRACE_CONT, pid, 0, 0); + + continue; + } else { + if (STOPPED_WITH(SIGTRAP, PTRACE_EVENT_EXEC)) { + char program[PATH_MAX]; + if (get_program(pid, program, sizeof(program)) == -1) { + LOGW("failed to get program %d", pid); + + continue; + } + + LOGV("%d program %s", pid, program); + const char* tracer = NULL; + + do { + if (tracing_state != TRACING) { + LOGW("stop injecting %d because not tracing", pid); + + break; + } + + PRE_INJECT(64, true) + PRE_INJECT(32, false) + + if (tracer != NULL) { + LOGD("stopping %d", pid); + + kill(pid, SIGSTOP); + ptrace(PTRACE_CONT, pid, 0, 0); + waitpid(pid, &sigchld_status, __WALL); + + if (STOPPED_WITH(SIGSTOP, 0)) { + LOGD("detaching %d", pid); + + ptrace(PTRACE_DETACH, pid, 0, SIGSTOP); + sigchld_status = 0; + int p = fork_dont_care(); + + if (p == 0) { + char pid_str[32]; + sprintf(pid_str, "%d", pid); + + execl(tracer, basename(tracer), "trace", pid_str, "--restart", NULL); + + PLOGE("failed to exec, kill"); + + kill(pid, SIGKILL); + exit(1); + } else if (p == -1) { + PLOGE("failed to fork, kill"); + + kill(pid, SIGKILL); + } + } + } + } while (false); + + update_status(NULL); + } else { + char status_str[64]; + parse_status(sigchld_status, status_str, sizeof(status_str)); + + LOGW("process %d received unknown sigchld_status %s", pid, status_str); + } + + for (size_t i = 0; i < sigchld_process_count; i++) { + if (sigchld_process[i] != pid) continue; + + sigchld_process[i] = 0; + + break; + } + + if (WIFSTOPPED(sigchld_status)) { + LOGV("detach process %d", pid); + + ptrace(PTRACE_DETACH, pid, 0, 0); + } + } + } + } +} + +void sigchld_listener_stop() { + if (sigchld_signal_fd >= 0) close(sigchld_signal_fd); + sigchld_signal_fd = -1; + + if (sigchld_process != NULL) free(sigchld_process); + sigchld_process = NULL; + sigchld_process_count = 0; +} + +static char pre_section[1024]; +static char post_section[1024]; + +#define WRITE_STATUS_ABI(suffix) \ + if (status ## suffix.supported) { \ + strcat(status_text, " zygote" # suffix ": "); \ + if (tracing_state != TRACING) strcat(status_text, "❓ unknown, "); \ + else if (status ## suffix.zygote_injected) strcat(status_text, "😋 injected, "); \ + else strcat(status_text, "❌ not injected, "); \ + \ + strcat(status_text, "daemon" # suffix ": "); \ + if (status ## suffix.daemon_running) { \ + strcat(status_text, "😋 running "); \ + \ + if (status ## suffix.daemon_info != NULL) { \ + strcat(status_text, "("); \ + strcat(status_text, status ## suffix.daemon_info); \ + strcat(status_text, ")"); \ + } \ + } else { \ + strcat(status_text, "❌ crashed "); \ + \ + if (status ## suffix.daemon_error_info != NULL) { \ + strcat(status_text, "("); \ + strcat(status_text, status ## suffix.daemon_error_info); \ + strcat(status_text, ")"); \ + } \ + } \ + } + +static bool update_status(const char *message) { + FILE *prop = fopen(PROP_PATH, "w"); + if (prop == NULL) { + PLOGE("failed to open prop"); + + return false; + } + + if (message) { + fprintf(prop, "%s[%s] %s", pre_section, message, post_section); + fclose(prop); + + return true; + } + + char status_text[1024] = "monitor: "; + + switch (tracing_state) { + case TRACING: { + strcat(status_text, "😋 tracing"); + + break; + } + case STOPPING: [[fallthrough]]; + case STOPPED: { + strcat(status_text, "❌ stopped"); + + break; + } + case EXITING: { + strcat(status_text, "❌ exited"); + + break; + } + } + + if (tracing_state != TRACING && monitor_stop_reason[0] != '\0') { + strcat(status_text, " ("); + strcat(status_text, monitor_stop_reason); + strcat(status_text, ")"); + } + strcat(status_text, ","); + + WRITE_STATUS_ABI(64) + WRITE_STATUS_ABI(32) + + fprintf(prop, "%s[%s] %s", pre_section, status_text, post_section); + + fclose(prop); + + return true; +} + +static bool prepare_environment() { + /* INFO: We need to create the file first, otherwise the mount will fail */ + close(open(PROP_PATH, O_WRONLY | O_CREAT | O_TRUNC, 0644)); + + FILE *orig_prop = fopen("/data/adb/modules/zygisksu/module.prop", "r"); + if (orig_prop == NULL) { + PLOGE("failed to open orig prop"); + + return false; + } + + bool after_description = false; + + char line[1024]; + while (fgets(line, sizeof(line), orig_prop) != NULL) { + if (strncmp(line, "description=", strlen("description=")) == 0) { + strcat(pre_section, "description="); + strcat(post_section, line + strlen("description=")); + after_description = true; + + continue; + } + + if (after_description) strcat(post_section, line); + else strcat(pre_section, line); + } + + fclose(orig_prop); + + /* INFO: This environment variable is related to Magisk Zygisk/Manager. It + it used by Magisk's Zygisk to communicate to Magisk Manager whether + Zygisk is working or not. + + Because of that behavior, we can knowledge built-in Zygisk is being + used and stop the continuation of initialization of ReZygisk.*/ + if (getenv("ZYGISK_ENABLED")) { + update_status("❌ Disable Magisk's built-in Zygisk"); + + return false; + } + + return update_status(NULL); +} + +void init_monitor() { + LOGI("ReZygisk %s", ZKSU_VERSION); + + if (!prepare_environment()) exit(1); + + monitor_events_init(); + + rezygiskd_listener_init(); + + struct monitor_event_cbs listener_cbs = { + .callback = rezygiskd_listener_callback, + .stop_callback = rezygiskd_listener_stop + }; + monitor_events_register_event(&listener_cbs, monitor_sock_fd, EPOLLIN | EPOLLET); + + sigchld_listener_init(); + + struct monitor_event_cbs sigchld_cbs = { + .callback = sigchld_listener_callback, + .stop_callback = sigchld_listener_stop + }; + monitor_events_register_event(&sigchld_cbs, sigchld_signal_fd, EPOLLIN | EPOLLET); + + monitor_events_loop(); + + if (status64.daemon_info) free(status64.daemon_info); + if (status64.daemon_error_info) free(status64.daemon_error_info); + if (status32.daemon_info) free(status32.daemon_info); + if (status32.daemon_error_info) free(status32.daemon_error_info); + + LOGI("exit"); +} + +int send_control_command(enum rezygiskd_command cmd) { + int sockfd = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (sockfd == -1) return -1; + + struct sockaddr_un addr = { + .sun_family = AF_UNIX, + .sun_path = { 0 } + }; + + size_t sun_path_len = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", rezygiskd_get_path(), SOCKET_NAME); + + socklen_t socklen = sizeof(sa_family_t) + sun_path_len; + + ssize_t nsend = sendto(sockfd, (void *)&cmd, sizeof(cmd), 0, (struct sockaddr *)&addr, socklen); + + close(sockfd); + + return nsend != sizeof(cmd) ? -1 : 0; +} diff --git a/loader/src/ptracer/monitor.cpp b/loader/src/ptracer/monitor.cpp deleted file mode 100644 index 5217ea5..0000000 --- a/loader/src/ptracer/monitor.cpp +++ /dev/null @@ -1,838 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "monitor.h" -#include "utils.hpp" -#include "misc.h" - -#define STOPPED_WITH(sig, event) WIFSTOPPED(status) && (status >> 8 == ((sig) | (event << 8))) - -static void updateStatus(); - -char monitor_stop_reason[32]; - -constexpr char SOCKET_NAME[] = "init_monitor"; - -struct EventLoop; - -struct EventHandler { - virtual int GetFd() = 0; - virtual void HandleEvent(EventLoop& loop, uint32_t event) = 0; -}; - -struct EventLoop { - private: - int epoll_fd_; - bool running = false; - public: - bool Init() { - epoll_fd_ = epoll_create(1); - if (epoll_fd_ == -1) { - PLOGE("failed to create"); - - return false; - } - - return true; - } - - void Stop() { - running = false; - } - - void Loop() { - running = true; - - constexpr auto MAX_EVENTS = 2; - struct epoll_event events[MAX_EVENTS]; - - while (running) { - int nfds = epoll_wait(epoll_fd_, events, MAX_EVENTS, -1); - if (nfds == -1) { - if (errno != EINTR) PLOGE("epoll_wait"); - - continue; - } - - for (int i = 0; i < nfds; i++) { - reinterpret_cast(events[i].data.ptr)->HandleEvent(*this, - events[i].events); - if (!running) break; - } - } - } - - bool RegisterHandler(EventHandler &handler, uint32_t events) { - struct epoll_event ev{}; - ev.events = events; - ev.data.ptr = &handler; - if (epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, handler.GetFd(), &ev) == -1) { - PLOGE("failed to add event handler"); - - return false; - } - - return true; - } - - bool UnregisterHandler(EventHandler &handler) { - if (epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, handler.GetFd(), NULL) == -1) { - PLOGE("failed to del event handler"); - - return false; - } - - return true; - } - - ~EventLoop() { - if (epoll_fd_ >= 0) close(epoll_fd_); - } -}; - -enum TracingState { - TRACING = 1, - STOPPING, - STOPPED, - EXITING -}; - -TracingState tracing_state = TRACING; -static char prop_path[PATH_MAX]; - -struct Status { - bool supported = false; - bool zygote_injected = false; - bool daemon_running = false; - pid_t daemon_pid = -1; - char *daemon_info = NULL; - char *daemon_error_info = NULL; -}; - -Status status64; -Status status32; - -struct SocketHandler : public EventHandler { - int sock_fd_; - - bool Init() { - sock_fd_ = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); - if (sock_fd_ == -1) { - PLOGE("socket create"); - - return false; - } - - struct sockaddr_un addr = { - .sun_family = AF_UNIX, - .sun_path = { 0 } - }; - - char tmp_path[PATH_MAX]; - rezygiskd_get_path(tmp_path, sizeof(tmp_path)); - - size_t sun_path_len = sprintf(addr.sun_path, "%s/%s", tmp_path, SOCKET_NAME); - - socklen_t socklen = sizeof(sa_family_t) + sun_path_len; - if (bind(sock_fd_, (struct sockaddr *)&addr, socklen) == -1) { - PLOGE("bind socket"); - - return false; - } - - return true; - } - - int GetFd() override { - return sock_fd_; - } - - void HandleEvent(EventLoop &loop, uint32_t) override { - struct [[gnu::packed]] MsgHead { - enum Command cmd; - int length; - char data[0]; - }; - - while (1) { - struct MsgHead *msg = (struct MsgHead *)malloc(sizeof(struct MsgHead)); - - ssize_t real_size; - ssize_t nread = recv(sock_fd_, msg, sizeof(struct MsgHead), MSG_PEEK); - if (nread == -1) { - if (errno == EAGAIN) break; - - PLOGE("read socket"); - } - - if ((size_t)nread < sizeof(Command)) { - LOGE("read %zu < %zu", nread, sizeof(Command)); - continue; - } - - if (msg->cmd >= Command::DAEMON64_SET_INFO && msg->cmd != Command::SYSTEM_SERVER_STARTED) { - if (nread != sizeof(msg)) { - LOGE("cmd %d size %zu != %zu", msg->cmd, nread, sizeof(MsgHead)); - - continue; - } - - real_size = sizeof(MsgHead) + msg->length; - } else { - if (nread != sizeof(Command)) { - LOGE("cmd %d size %zu != %zu", msg->cmd, nread, sizeof(Command)); - - continue; - } - - real_size = sizeof(Command); - } - - msg = (struct MsgHead *)realloc(msg, real_size); - nread = recv(sock_fd_, msg, real_size, 0); - - if (nread == -1) { - if (errno == EAGAIN) break; - - PLOGE("recv"); - continue; - } - - if (nread != real_size) { - LOGE("real size %zu != %zu", real_size, nread); - - continue; - } - - switch (msg->cmd) { - case START: { - if (tracing_state == STOPPING) tracing_state = TRACING; - else if (tracing_state == STOPPED) { - ptrace(PTRACE_SEIZE, 1, 0, PTRACE_O_TRACEFORK); - - LOGI("start tracing init"); - - tracing_state = TRACING; - } - - updateStatus(); - - break; - } - case STOP: { - if (tracing_state == TRACING) { - LOGI("stop tracing requested"); - - tracing_state = STOPPING; - strcpy(monitor_stop_reason, "user requested"); - - ptrace(PTRACE_INTERRUPT, 1, 0, 0); - updateStatus(); - } - - break; - } - case EXIT: { - LOGI("prepare for exit ..."); - - tracing_state = EXITING; - strcpy(monitor_stop_reason, "user requested"); - - updateStatus(); - loop.Stop(); - - break; - } - case ZYGOTE64_INJECTED: { - status64.zygote_injected = true; - - updateStatus(); - - break; - } - case ZYGOTE32_INJECTED: { - status32.zygote_injected = true; - - updateStatus(); - - break; - } - case DAEMON64_SET_INFO: { - LOGD("received daemon64 info %s", msg->data); - - /* Will only happen if somehow the daemon restarts */ - if (status64.daemon_info) { - free(status64.daemon_info); - status64.daemon_info = NULL; - } - - status64.daemon_info = (char *)malloc(msg->length); - if (!status64.daemon_info) { - PLOGE("malloc daemon64 info"); - - break; - } - - strcpy(status64.daemon_info, msg->data); - - updateStatus(); - - break; - } - case DAEMON32_SET_INFO: { - LOGD("received daemon32 info %s", msg->data); - - if (status32.daemon_info) { - free(status32.daemon_info); - status32.daemon_info = NULL; - } - - status32.daemon_info = (char *)malloc(msg->length); - if (!status32.daemon_info) { - PLOGE("malloc daemon32 info"); - - break; - } - - strcpy(status32.daemon_info, msg->data); - - updateStatus(); - - break; - } - case DAEMON64_SET_ERROR_INFO: { - LOGD("received daemon64 error info %s", msg->data); - - status64.daemon_running = false; - - if (status64.daemon_error_info) { - free(status64.daemon_error_info); - status64.daemon_error_info = NULL; - } - - status64.daemon_error_info = (char *)malloc(msg->length); - if (!status64.daemon_error_info) { - PLOGE("malloc daemon64 error info"); - - break; - } - - strcpy(status64.daemon_error_info, msg->data); - - updateStatus(); - - break; - } - case DAEMON32_SET_ERROR_INFO: { - LOGD("received daemon32 error info %s", msg->data); - - status32.daemon_running = false; - - if (status32.daemon_error_info) { - free(status32.daemon_error_info); - status32.daemon_error_info = NULL; - } - - status32.daemon_error_info = (char *)malloc(msg->length); - if (!status32.daemon_error_info) { - PLOGE("malloc daemon32 error info"); - - break; - } - - strcpy(status32.daemon_error_info, msg->data); - - updateStatus(); - - break; - } - case SYSTEM_SERVER_STARTED: { - LOGD("system server started, mounting prop"); - - if (mount(prop_path, "/data/adb/modules/zygisksu/module.prop", NULL, MS_BIND, NULL) == -1) { - PLOGE("failed to mount prop"); - } - - break; - } - } - - free(msg); - } - } - - ~SocketHandler() { - if (sock_fd_ >= 0) close(sock_fd_); - } -}; - -constexpr int MAX_RETRY_COUNT = 5; - -#define CREATE_ZYGOTE_START_COUNTER(abi) \ - struct timespec last_zygote##abi = { \ - .tv_sec = 0, \ - .tv_nsec = 0 \ - }; \ - \ - int count_zygote ## abi = 0; \ - bool should_stop_inject ## abi() { \ - struct timespec now = {}; \ - clock_gettime(CLOCK_MONOTONIC, &now); \ - if (now.tv_sec - last_zygote ## abi.tv_sec < 30) \ - count_zygote ## abi++; \ - else \ - count_zygote ## abi = 0; \ - \ - last_zygote##abi = now; \ - \ - return count_zygote##abi >= MAX_RETRY_COUNT; \ - } - -CREATE_ZYGOTE_START_COUNTER(64) -CREATE_ZYGOTE_START_COUNTER(32) - -static bool ensure_daemon_created(bool is_64bit) { - Status *status = is_64bit ? &status64 : &status32; - if (is_64bit) { - LOGD("new zygote started."); - - umount2("/data/adb/modules/zygisksu/module.prop", MNT_DETACH); - } - - status->zygote_injected = false; - - if (status->daemon_pid == -1) { - pid_t pid = fork(); - if (pid < 0) { - PLOGE("create daemon%s", is_64bit ? "64" : "32"); - - return false; - } else if (pid == 0) { - char daemon_name[PATH_MAX] = "./bin/zygiskd"; - strcat(daemon_name, is_64bit ? "64" : "32"); - - execl(daemon_name, daemon_name, NULL); - - PLOGE("exec daemon %s failed", daemon_name); - - exit(1); - } else { - status->supported = true; - status->daemon_pid = pid; - status->daemon_running = true; - - return true; - } - } else { - return status->daemon_running; - } -} - -#define CHECK_DAEMON_EXIT(abi) \ - if (status##abi.supported && pid == status64.daemon_pid) { \ - char status_str[64]; \ - parse_status(status, status_str, sizeof(status_str)); \ - \ - LOGW("daemon" #abi " pid %d exited: %s", pid, status_str); \ - status##abi.daemon_running = false; \ - \ - if (!status##abi.daemon_error_info) { \ - status##abi.daemon_error_info = (char *)malloc(strlen(status_str) + 1); \ - if (!status##abi.daemon_error_info) { \ - LOGE("malloc daemon" #abi " error info failed"); \ - \ - return; \ - } \ - \ - memcpy(status##abi.daemon_error_info, status_str, strlen(status_str) + 1); \ - } \ - \ - updateStatus(); \ - continue; \ - } - -#define PRE_INJECT(abi, is_64) \ - if (strcmp(program, "/system/bin/app_process" # abi) == 0) { \ - tracer = "./bin/zygisk-ptrace" # abi; \ - \ - if (should_stop_inject ## abi()) { \ - LOGW("zygote" # abi " restart too much times, stop injecting"); \ - \ - tracing_state = STOPPING; \ - memcpy(monitor_stop_reason, "zygote crashed", sizeof("zygote crashed")); \ - ptrace(PTRACE_INTERRUPT, 1, 0, 0); \ - \ - break; \ - } \ - if (!ensure_daemon_created(is_64)) { \ - LOGW("daemon" #abi " not running, stop injecting"); \ - \ - tracing_state = STOPPING; \ - memcpy(monitor_stop_reason, "daemon not running", sizeof("daemon not running")); \ - ptrace(PTRACE_INTERRUPT, 1, 0, 0); \ - \ - break; \ - } \ - } - -struct SigChldHandler : public EventHandler { - private: - int signal_fd_; - struct signalfd_siginfo fdsi; - int status; - std::set process; - - public: - bool Init() { - sigset_t mask; - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); - - if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) { - PLOGE("set sigprocmask"); - - return false; - } - - signal_fd_ = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC); - if (signal_fd_ == -1) { - PLOGE("create signalfd"); - - return false; - } - - ptrace(PTRACE_SEIZE, 1, 0, PTRACE_O_TRACEFORK); - - return true; - } - - int GetFd() override { - return signal_fd_; - } - - void HandleEvent(EventLoop &, uint32_t) override { - while (1) { - ssize_t s = read(signal_fd_, &fdsi, sizeof(fdsi)); - if (s == -1) { - if (errno == EAGAIN) break; - - PLOGE("read signalfd"); - - continue; - } - - if (s != sizeof(fdsi)) { - LOGW("read %zu != %zu", s, sizeof(fdsi)); - - continue; - } - - if (fdsi.ssi_signo != SIGCHLD) { - LOGW("no sigchld received"); - - continue; - } - - int pid; - while ((pid = waitpid(-1, &status, __WALL | WNOHANG)) != 0) { - if (pid == -1) { - if (tracing_state == STOPPED && errno == ECHILD) break; - PLOGE("waitpid"); - } - - if (pid == 1) { - if (STOPPED_WITH(SIGTRAP, PTRACE_EVENT_FORK)) { - long child_pid; - - ptrace(PTRACE_GETEVENTMSG, pid, 0, &child_pid); - - LOGV("forked %ld", child_pid); - } else if (STOPPED_WITH(SIGTRAP, PTRACE_EVENT_STOP) && tracing_state == STOPPING) { - if (ptrace(PTRACE_DETACH, 1, 0, 0) == -1) PLOGE("failed to detach init"); - - tracing_state = STOPPED; - - LOGI("stop tracing init"); - - continue; - } - - if (WIFSTOPPED(status)) { - if (WPTEVENT(status) == 0) { - if (WSTOPSIG(status) != SIGSTOP && WSTOPSIG(status) != SIGTSTP && WSTOPSIG(status) != SIGTTIN && WSTOPSIG(status) != SIGTTOU) { - LOGW("inject signal sent to init: %s %d", sigabbrev_np(WSTOPSIG(status)), WSTOPSIG(status)); - - ptrace(PTRACE_CONT, pid, 0, WSTOPSIG(status)); - - continue; - } else { - LOGW("suppress stopping signal sent to init: %s %d", sigabbrev_np(WSTOPSIG(status)), WSTOPSIG(status)); - } - } - - ptrace(PTRACE_CONT, pid, 0, 0); - } - - continue; - } - - CHECK_DAEMON_EXIT(64) - CHECK_DAEMON_EXIT(32) - - auto state = process.find(pid); - - if (state == process.end()) { - LOGV("new process %d attached", pid); - - process.emplace(pid); - - ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_TRACEEXEC); - ptrace(PTRACE_CONT, pid, 0, 0); - - continue; - } else { - if (STOPPED_WITH(SIGTRAP, PTRACE_EVENT_EXEC)) { - char program[PATH_MAX]; - if (get_program(pid, program, sizeof(program)) == -1) { - LOGW("failed to get program %d", pid); - - continue; - } - - LOGV("%d program %s", pid, program); - const char* tracer = NULL; - - do { - if (tracing_state != TRACING) { - LOGW("stop injecting %d because not tracing", pid); - - break; - } - - PRE_INJECT(64, true) - PRE_INJECT(32, false) - - if (tracer != NULL) { - LOGD("stopping %d", pid); - - kill(pid, SIGSTOP); - ptrace(PTRACE_CONT, pid, 0, 0); - waitpid(pid, &status, __WALL); - - if (STOPPED_WITH(SIGSTOP, 0)) { - LOGD("detaching %d", pid); - - ptrace(PTRACE_DETACH, pid, 0, SIGSTOP); - status = 0; - auto p = fork_dont_care(); - - if (p == 0) { - char pid_str[32]; - sprintf(pid_str, "%d", pid); - - execl(tracer, basename(tracer), "trace", pid_str, "--restart", NULL); - - PLOGE("failed to exec, kill"); - - kill(pid, SIGKILL); - exit(1); - } else if (p == -1) { - PLOGE("failed to fork, kill"); - - kill(pid, SIGKILL); - } - } - } - } while (false); - - updateStatus(); - } else { - char status_str[64]; - parse_status(status, status_str, sizeof(status_str)); - - LOGW("process %d received unknown status %s", pid, status_str); - } - - process.erase(state); - if (WIFSTOPPED(status)) { - LOGV("detach process %d", pid); - - ptrace(PTRACE_DETACH, pid, 0, 0); - } - } - } - } - } - - ~SigChldHandler() { - if (signal_fd_ >= 0) close(signal_fd_); - } -}; - -static char pre_section[1024]; -static char post_section[1024]; - -#define WRITE_STATUS_ABI(suffix) \ - if (status ## suffix.supported) { \ - strcat(status_text, " zygote" # suffix ": "); \ - if (tracing_state != TRACING) strcat(status_text, "❓ unknown, "); \ - else if (status ## suffix.zygote_injected) strcat(status_text, "😋 injected, "); \ - else strcat(status_text, "❌ not injected, "); \ - \ - strcat(status_text, "daemon" # suffix ": "); \ - if (status ## suffix.daemon_running) { \ - strcat(status_text, "😋 running "); \ - \ - if (status ## suffix.daemon_info != NULL) { \ - strcat(status_text, "("); \ - strcat(status_text, status ## suffix.daemon_info); \ - strcat(status_text, ")"); \ - } \ - } else { \ - strcat(status_text, "❌ crashed "); \ - \ - if (status ## suffix.daemon_error_info != NULL) { \ - strcat(status_text, "("); \ - strcat(status_text, status ## suffix.daemon_error_info); \ - strcat(status_text, ")"); \ - } \ - } \ - } - -static void updateStatus() { - FILE *prop = fopen(prop_path, "w"); - char status_text[1024] = "monitor: "; - - switch (tracing_state) { - case TRACING: { - strcat(status_text, "😋 tracing"); - - break; - } - case STOPPING: [[fallthrough]]; - case STOPPED: { - strcat(status_text, "❌ stopped"); - - break; - } - case EXITING: { - strcat(status_text, "❌ exited"); - - break; - } - } - - if (tracing_state != TRACING && monitor_stop_reason[0] != '\0') { - strcat(status_text, " ("); - strcat(status_text, monitor_stop_reason); - strcat(status_text, ")"); - } - strcat(status_text, ","); - - WRITE_STATUS_ABI(64) - WRITE_STATUS_ABI(32) - - fprintf(prop, "%s[%s] %s", pre_section, status_text, post_section); - - fclose(prop); -} - -static bool prepare_environment() { - char tmp_path[PATH_MAX]; - rezygiskd_get_path(tmp_path, sizeof(tmp_path)); - - strcat(prop_path, tmp_path); - strcat(prop_path, "/module.prop"); - - close(open(prop_path, O_WRONLY | O_CREAT | O_TRUNC, 0644)); - - FILE *orig_prop = fopen("./module.prop", "r"); - if (orig_prop == NULL) { - PLOGE("failed to open orig prop"); - - return false; - } - - bool after_description = false; - - char line[1024]; - while (fgets(line, sizeof(line), orig_prop) != NULL) { - if (strncmp(line, "description=", strlen("description=")) == 0) { - strcat(pre_section, "description="); - strcat(post_section, line + strlen("description=")); - after_description = true; - - continue; - } - - if (after_description) strcat(post_section, line); - else strcat(pre_section, line); - } - - fclose(orig_prop); - - /* TODO: See if ZYGISK_ENABLED flag is already set, - if so, set a status saying to disable built-in Zygisk. */ - updateStatus(); - - return true; -} - -void init_monitor() { - LOGI("ReZygisk %s", ZKSU_VERSION); - - if (!prepare_environment()) exit(1); - - SocketHandler socketHandler{}; - socketHandler.Init(); - SigChldHandler ptraceHandler{}; - ptraceHandler.Init(); - EventLoop looper; - - looper.Init(); - looper.RegisterHandler(socketHandler, EPOLLIN | EPOLLET); - looper.RegisterHandler(ptraceHandler, EPOLLIN | EPOLLET); - looper.Loop(); - - if (status64.daemon_info) free(status64.daemon_info); - if (status64.daemon_error_info) free(status64.daemon_error_info); - if (status32.daemon_info) free(status32.daemon_info); - if (status32.daemon_error_info) free(status32.daemon_error_info); - - LOGI("exit"); -} - -int send_control_command(enum Command cmd) { - int sockfd = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); - if (sockfd == -1) return -1; - - struct sockaddr_un addr = { - .sun_family = AF_UNIX, - .sun_path = { 0 } - }; - - char tmp_path[PATH_MAX]; - rezygiskd_get_path(tmp_path, sizeof(tmp_path)); - - size_t sun_path_len = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", tmp_path, SOCKET_NAME); - - socklen_t socklen = sizeof(sa_family_t) + sun_path_len; - - ssize_t nsend = sendto(sockfd, (void *)&cmd, sizeof(cmd), 0, (sockaddr *)&addr, socklen); - - /* TODO: Should we close even when it fails? */ - close(sockfd); - - return nsend != sizeof(cmd) ? -1 : 0; -} diff --git a/loader/src/ptracer/monitor.h b/loader/src/ptracer/monitor.h index c7db0f3..99ed3be 100644 --- a/loader/src/ptracer/monitor.h +++ b/loader/src/ptracer/monitor.h @@ -1,5 +1,5 @@ -#ifndef MAIN_HPP -#define MAIN_HPP +#ifndef MONITOR_H +#define MONITOR_H #include @@ -7,7 +7,7 @@ void init_monitor(); bool trace_zygote(int pid); -enum Command { +enum rezygiskd_command { START = 1, STOP = 2, EXIT = 3, @@ -22,6 +22,6 @@ enum Command { SYSTEM_SERVER_STARTED = 10 }; -int send_control_command(enum Command cmd); +int send_control_command(enum rezygiskd_command cmd); -#endif /* MAIN_HPP */ \ No newline at end of file +#endif /* MONITOR_H */ \ No newline at end of file diff --git a/loader/src/ptracer/ptracer.cpp b/loader/src/ptracer/ptracer.c similarity index 65% rename from loader/src/ptracer/ptracer.cpp rename to loader/src/ptracer/ptracer.c index c8a7571..7ae1254 100644 --- a/loader/src/ptracer/ptracer.cpp +++ b/loader/src/ptracer/ptracer.c @@ -1,20 +1,18 @@ +#include +#include +#include + #include -#include -#include #include #include #include -#include -#include -#include #include #include #include -#include -#include -#include -#include "utils.hpp" +#include + +#include "utils.h" bool inject_on_main(int pid, const char *lib_path) { LOGI("injecting %s to zygote %d", lib_path, pid); @@ -25,16 +23,26 @@ bool inject_on_main(int pid, const char *lib_path) { https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/private/KernelArgumentBlock.h;l=30;drc=6d1ee77ee32220e4202c3066f7e1f69572967ad8 */ - struct user_regs_struct regs {}, - backup {}; + struct user_regs_struct regs = { 0 }; - /* WARNING: C++ keyword */ - std::vector map = MapInfo::Scan(std::to_string(pid)); - if (!get_regs(pid, regs)) return false; + char pid_maps[PATH_MAX]; + snprintf(pid_maps, sizeof(pid_maps), "/proc/%d/maps", pid); + + struct maps *map = parse_maps(pid_maps); + if (map == NULL) { + LOGE("failed to parse remote maps"); + + return false; + } + + if (!get_regs(pid, ®s)) return false; uintptr_t arg = (uintptr_t)regs.REG_SP; - LOGV("kernel argument %" PRIxPTR " %s", arg, get_addr_mem_region(map, arg).c_str()); + char addr_mem_region[1024]; + get_addr_mem_region(map, arg, addr_mem_region, sizeof(addr_mem_region)); + + LOGV("kernel argument %" PRIxPTR " %s", arg, addr_mem_region); int argc; char **argv = (char **)((uintptr_t *)arg + 1); @@ -43,18 +51,16 @@ bool inject_on_main(int pid, const char *lib_path) { read_proc(pid, arg, &argc, sizeof(argc)); LOGV("argc %d", argc); - /* WARNING: C++ keyword */ - auto envp = argv + argc + 1; + char **envp = argv + argc + 1; LOGV("envp %p", (void *)envp); - /* WARNING: C++ keyword */ - auto p = envp; + char **p = envp; while (1) { uintptr_t *buf; read_proc(pid, (uintptr_t)p, &buf, sizeof(buf)); if (buf == NULL) break; - + /* TODO: Why ++p? */ p++; } @@ -63,7 +69,9 @@ bool inject_on_main(int pid, const char *lib_path) { p++; ElfW(auxv_t) *auxv = (ElfW(auxv_t) *)p; - LOGV("auxv %p %s", auxv, get_addr_mem_region(map, (uintptr_t) auxv).c_str()); + + get_addr_mem_region(map, (uintptr_t)auxv, addr_mem_region, sizeof(addr_mem_region)); + LOGV("auxv %p %s", auxv, addr_mem_region); ElfW(auxv_t) *v = auxv; uintptr_t entry_addr = 0; @@ -78,8 +86,9 @@ bool inject_on_main(int pid, const char *lib_path) { entry_addr = (uintptr_t)buf.a_un.a_val; addr_of_entry_addr = (uintptr_t)v + offsetof(ElfW(auxv_t), a_un); + get_addr_mem_region(map, entry_addr, addr_mem_region, sizeof(addr_mem_region)); LOGV("entry address %" PRIxPTR " %s (entry=%" PRIxPTR ", entry_addr=%" PRIxPTR ")", entry_addr, - get_addr_mem_region(map, entry_addr).c_str(), (uintptr_t)v, addr_of_entry_addr); + addr_mem_region, (uintptr_t)v, addr_of_entry_addr); break; } @@ -113,7 +122,7 @@ bool inject_on_main(int pid, const char *lib_path) { int status; wait_for_trace(pid, &status, __WALL); if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGSEGV) { - if (!get_regs(pid, regs)) return false; + if (!get_regs(pid, ®s)) return false; if (((int)regs.REG_IP & ~1) != ((int)break_addr & ~1)) { LOGE("stopped at unknown addr %p", (void *) regs.REG_IP); @@ -128,13 +137,25 @@ bool inject_on_main(int pid, const char *lib_path) { if (!write_proc(pid, (uintptr_t) addr_of_entry_addr, &entry_addr, sizeof(entry_addr))) return false; /* backup registers */ + struct user_regs_struct backup; memcpy(&backup, ®s, sizeof(regs)); - /* WARNING: C++ keyword */ - map = MapInfo::Scan(std::to_string(pid)); + free_maps(map); + + map = parse_maps(pid_maps); + if (!map) { + LOGE("failed to parse remote maps"); + + return false; + } + + struct maps *local_map = parse_maps("/proc/self/maps"); + if (!local_map) { + LOGE("failed to parse local maps"); + + return false; + } - /* WARNING: C++ keyword */ - std::vector local_map = MapInfo::Scan(); void *libc_return_addr = find_module_return_addr(map, "libc.so"); LOGD("libc return addr %p", libc_return_addr); @@ -142,17 +163,19 @@ bool inject_on_main(int pid, const char *lib_path) { void *dlopen_addr = find_func_addr(local_map, map, "libdl.so", "dlopen"); if (dlopen_addr == NULL) return false; - /* WARNING: C++ keyword */ - std::vector args; + long *args = (long *)malloc(3 * sizeof(long)); + if (args == NULL) { + LOGE("malloc args"); - /* WARNING: C++ keyword */ - uintptr_t str = push_string(pid, regs, lib_path); + return false; + } - args.clear(); - args.push_back((long) str); - args.push_back((long) RTLD_NOW); + uintptr_t str = push_string(pid, ®s, lib_path); - uintptr_t remote_handle = remote_call(pid, regs, (uintptr_t)dlopen_addr, (uintptr_t)libc_return_addr, args); + args[0] = (long) str; + args[1] = (long) RTLD_NOW; + + uintptr_t remote_handle = remote_call(pid, ®s, (uintptr_t)dlopen_addr, (uintptr_t)libc_return_addr, args, 2); LOGD("remote handle %p", (void *)remote_handle); if (remote_handle == 0) { LOGE("handle is null"); @@ -162,37 +185,47 @@ bool inject_on_main(int pid, const char *lib_path) { if (dlerror_addr == NULL) { LOGE("find dlerror"); + free(args); + return false; } - args.clear(); + uintptr_t dlerror_str_addr = remote_call(pid, ®s, (uintptr_t)dlerror_addr, (uintptr_t)libc_return_addr, args, 0); + LOGD("dlerror str %p", (void *)dlerror_str_addr); + if (dlerror_str_addr == 0) { + LOGE("dlerror str is null"); - uintptr_t dlerror_str_addr = remote_call(pid, regs, (uintptr_t)dlerror_addr, (uintptr_t)libc_return_addr, args); - LOGD("dlerror str %p", (void*) dlerror_str_addr); - if (dlerror_str_addr == 0) return false; + free(args); + + return false; + } void *strlen_addr = find_func_addr(local_map, map, "libc.so", "strlen"); if (strlen_addr == NULL) { LOGE("find strlen"); + free(args); + return false; } - args.clear(); - args.push_back(dlerror_str_addr); + args[0] = (long) dlerror_str_addr; - uintptr_t dlerror_len = remote_call(pid, regs, (uintptr_t)strlen_addr, (uintptr_t)libc_return_addr, args); + uintptr_t dlerror_len = remote_call(pid, ®s, (uintptr_t)strlen_addr, (uintptr_t)libc_return_addr, args, 1); if (dlerror_len <= 0) { LOGE("dlerror len <= 0"); + free(args); + return false; } - /* NOTICE: C++ -> C */ char *err = (char *)malloc((dlerror_len + 1) * sizeof(char)); if (err == NULL) { LOGE("malloc err"); + free(args); + return false; } @@ -201,6 +234,7 @@ bool inject_on_main(int pid, const char *lib_path) { LOGE("dlerror info %s", err); free(err); + free(args); return false; } @@ -209,12 +243,13 @@ bool inject_on_main(int pid, const char *lib_path) { void *dlsym_addr = find_func_addr(local_map, map, "libdl.so", "dlsym"); if (dlsym_addr == NULL) return false; - args.clear(); - str = push_string(pid, regs, "entry"); - args.push_back(remote_handle); - args.push_back((long) str); + free_maps(local_map); - uintptr_t injector_entry = remote_call(pid, regs, (uintptr_t)dlsym_addr, (uintptr_t)libc_return_addr, args); + str = push_string(pid, ®s, "entry"); + args[0] = remote_handle; + args[1] = (long) str; + + uintptr_t injector_entry = remote_call(pid, ®s, (uintptr_t)dlsym_addr, (uintptr_t)libc_return_addr, args, 2); LOGD("injector entry %p", (void *)injector_entry); if (injector_entry == 0) { LOGE("injector entry is null"); @@ -223,38 +258,41 @@ bool inject_on_main(int pid, const char *lib_path) { } /* record the address range of libzygisk.so */ - map = MapInfo::Scan(std::to_string(pid)); - void *start_addr = nullptr; + map = parse_maps(pid_maps); + + void *start_addr = NULL; size_t block_size = 0; - for (auto &info : map) { - if (strstr(info.path.c_str(), "libzygisk.so")) { - void *addr = (void *)info.start; - if (start_addr == nullptr) start_addr = addr; - size_t size = info.end - info.start; - block_size += size; - LOGD("found block %s: [%p-%p] with size %zu", info.path.c_str(), addr, (void *)info.end, size); - } + + for (size_t i = 0; i < map->size; i++) { + if (!strstr(map->maps[i].path, "libzygisk.so")) continue; + + if (start_addr == NULL) start_addr = (void *)map->maps[i].start; + + size_t size = map->maps[i].end - map->maps[i].start; + block_size += size; + + LOGD("found block %s: [%p-%p] with size %zu", map->maps[i].path, (void *)map->maps[i].start, + (void *)map->maps[i].end, size); } + free_maps(map); + /* call injector entry(start_addr, block_size, path) */ - args.clear(); - args.push_back((uintptr_t) start_addr); - args.push_back(block_size); + args[0] = (uintptr_t)start_addr; + args[1] = block_size; + str = push_string(pid, ®s, rezygiskd_get_path()); + args[2] = (uintptr_t)str; - char tmp_path[PATH_MAX]; - rezygiskd_get_path(tmp_path, sizeof(tmp_path)); + remote_call(pid, ®s, injector_entry, (uintptr_t)libc_return_addr, args, 3); - str = push_string(pid, regs, tmp_path); - args.push_back((long) str); - - remote_call(pid, regs, injector_entry, (uintptr_t)libc_return_addr, args); + free(args); /* reset pc to entry */ backup.REG_IP = (long) entry_addr; LOGD("invoke entry"); /* restore registers */ - if (!set_regs(pid, backup)) return false; + if (!set_regs(pid, &backup)) return false; return true; } else { @@ -290,11 +328,8 @@ bool trace_zygote(int pid) { WAIT_OR_DIE if (STOPPED_WITH(SIGSTOP, PTRACE_EVENT_STOP)) { - /* WARNING: C++ keyword */ char lib_path[PATH_MAX]; - rezygiskd_get_path(lib_path, sizeof(lib_path)); - - strcat(lib_path,"/lib" LP_SELECT("", "64") "/libzygisk.so"); + snprintf(lib_path, sizeof(lib_path), "%s/lib" LP_SELECT("", "64") "/libzygisk.so", rezygiskd_get_path()); if (!inject_on_main(pid, lib_path)) { LOGE("failed to inject"); diff --git a/loader/src/ptracer/utils.c b/loader/src/ptracer/utils.c new file mode 100644 index 0000000..5aa9a35 --- /dev/null +++ b/loader/src/ptracer/utils.c @@ -0,0 +1,578 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "logging.h" + +#include "utils.h" + +bool switch_mnt_ns(int pid, int *fd) { + int nsfd, old_nsfd = -1; + + char path[PATH_MAX]; + if (pid == 0) { + if (fd != NULL) { + nsfd = *fd; + *fd = -1; + } else return false; + + snprintf(path, sizeof(path), "/proc/self/fd/%d", nsfd); + } else { + if (fd != NULL) { + old_nsfd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC); + if (old_nsfd == -1) { + PLOGE("get old nsfd"); + + return false; + } + + *fd = old_nsfd; + } + + snprintf(path, sizeof(path), "/proc/%d/ns/mnt", pid); + + nsfd = open(path, O_RDONLY | O_CLOEXEC); + if (nsfd == -1) { + PLOGE("open nsfd %s", path); + + close(old_nsfd); + + return false; + } + } + + if (setns(nsfd, CLONE_NEWNS) == -1) { + PLOGE("set ns to %s", path); + + close(nsfd); + close(old_nsfd); + + return false; + } + + close(nsfd); + + return true; +} + +struct maps *parse_maps(const char *filename) { + FILE *fp = fopen(filename, "r"); + if (!fp) { + LOGE("Failed to open %s", filename); + + return NULL; + } + + struct maps *maps = (struct maps *)malloc(sizeof(struct maps)); + if (!maps) { + LOGE("Failed to allocate memory for maps"); + + fclose(fp); + + return NULL; + } + + char line[4096 * 2]; + size_t i = 0; + + while (fgets(line, sizeof(line), fp) != NULL) { + /* INFO: Remove line ending at the end */ + line[strlen(line) - 1] = '\0'; + + uintptr_t addr_start; + uintptr_t addr_end; + uintptr_t addr_offset; + ino_t inode; + unsigned int dev_major; + unsigned int dev_minor; + char permissions[5] = ""; + int path_offset; + + sscanf(line, + "%" PRIxPTR "-%" PRIxPTR " %4s %" PRIxPTR " %x:%x %lu %n%*s", + &addr_start, &addr_end, permissions, &addr_offset, &dev_major, &dev_minor, + &inode, &path_offset); + + while (isspace(line[path_offset])) { + path_offset++; + } + + maps->maps = (struct map *)realloc(maps->maps, (i + 1) * sizeof(struct map)); + if (!maps->maps) { + LOGE("Failed to allocate memory for maps->maps"); + + maps->size = i; + + fclose(fp); + free_maps(maps); + + return NULL; + } + + maps->maps[i].start = addr_start; + maps->maps[i].end = addr_end; + maps->maps[i].offset = addr_offset; + + maps->maps[i].perms = 0; + if (permissions[0] == 'r') maps->maps[i].perms |= PROT_READ; + if (permissions[1] == 'w') maps->maps[i].perms |= PROT_WRITE; + if (permissions[2] == 'x') maps->maps[i].perms |= PROT_EXEC; + + maps->maps[i].is_private = permissions[3] == 'p'; + maps->maps[i].dev = makedev(dev_major, dev_minor); + maps->maps[i].inode = inode; + maps->maps[i].path = strdup(line + path_offset); + if (!maps->maps[i].path) { + LOGE("Failed to allocate memory for maps->maps[%zu].path", i); + + maps->size = i; + + fclose(fp); + free_maps(maps); + + return NULL; + } + + i++; + } + + fclose(fp); + + maps->size = i; + + return maps; +} + +void free_maps(struct maps *maps) { + if (!maps) { + return; + } + + for (size_t i = 0; i < maps->size; i++) { + free((void *)maps->maps[i].path); + } + + free(maps->maps); + free(maps); +} + +ssize_t write_proc(int pid, uintptr_t remote_addr, const void *buf, size_t len) { + LOGV("write to remote addr %" PRIxPTR " size %zu", remote_addr, len); + + struct iovec local = { + .iov_base = (void *)buf, + .iov_len = len + }; + + struct iovec remote = { + .iov_base = (void *)remote_addr, + .iov_len = len + }; + + ssize_t l = process_vm_writev(pid, &local, 1, &remote, 1, 0); + if (l == -1) PLOGE("process_vm_writev"); + else if ((size_t)l != len) LOGW("not fully written: %zu, excepted %zu", l, len); + + return l; +} + +ssize_t read_proc(int pid, uintptr_t remote_addr, void *buf, size_t len) { + struct iovec local = { + .iov_base = (void *)buf, + .iov_len = len + }; + + struct iovec remote = { + .iov_base = (void *)remote_addr, + .iov_len = len + }; + + ssize_t l = process_vm_readv(pid, &local, 1, &remote, 1, 0); + if (l == -1) PLOGE("process_vm_readv"); + else if ((size_t)l != len) LOGW("not fully read: %zu, excepted %zu", l, len); + + return l; +} + +bool get_regs(int pid, struct user_regs_struct *regs) { + #if defined(__x86_64__) || defined(__i386__) + if (ptrace(PTRACE_GETREGS, pid, 0, regs) == -1) { + PLOGE("getregs"); + + return false; + } + #elif defined(__aarch64__) || defined(__arm__) + struct iovec iov = { + .iov_base = regs, + .iov_len = sizeof(struct user_regs_struct), + }; + + if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov) == -1) { + PLOGE("getregs"); + + return false; + } + #endif + + return true; +} + +bool set_regs(int pid, struct user_regs_struct *regs) { + #if defined(__x86_64__) || defined(__i386__) + if (ptrace(PTRACE_SETREGS, pid, 0, regs) == -1) { + PLOGE("setregs"); + + return false; + } + #elif defined(__aarch64__) || defined(__arm__) + struct iovec iov = { + .iov_base = regs, + .iov_len = sizeof(struct user_regs_struct), + }; + + if (ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov) == -1) { + PLOGE("setregs"); + + return false; + } + #endif + + return true; +} + +void get_addr_mem_region(struct maps *info, uintptr_t addr, char *buf, size_t buf_size) { + for (size_t i = 0; i < info->size; i++) { + /* TODO: Early "leave" */ + if (info->maps[i].start <= addr && info->maps[i].end > addr) { + snprintf(buf, buf_size, "%s %s%s%s", + info->maps[i].path, + info->maps[i].perms & PROT_READ ? "r" : "-", + info->maps[i].perms & PROT_WRITE ? "w" : "-", + info->maps[i].perms & PROT_EXEC ? "x" : "-"); + + return; + } + } + + snprintf(buf, buf_size, ""); +} + +/* INFO: strrchr but without modifying the string */ +const char *position_after(const char *str, const char needle) { + const char *positioned = str + strlen(str); + + int i = strlen(str); + while (i != 0) { + i--; + if (str[i] == needle) { + positioned = str + i + 1; + + break; + } + } + + return positioned; +} + +void *find_module_return_addr(struct maps *map, const char *suffix) { + for (size_t i = 0; i < map->size; i++) { + /* TODO: Make it NULL in 1 length path */ + if (map->maps[i].path == NULL) continue; + + const char *file_name = position_after(map->maps[i].path, '/'); + if (!file_name) continue; + + if (strlen(file_name) < strlen(suffix) || (map->maps[i].perms & PROT_EXEC) != 0 || strncmp(file_name, suffix, strlen(suffix)) != 0) continue; + + return (void *)map->maps[i].start; + } + + return NULL; +} + +void *find_module_base(struct maps *map, const char *suffix) { + for (size_t i = 0; i < map->size; i++) { + /* TODO: Make it NULL in 1 length path */ + if (map->maps[i].path == NULL) continue; + + const char *file_name = position_after(map->maps[i].path, '/'); + if (!file_name) continue; + + if (strlen(file_name) < strlen(suffix) || map->maps[i].offset != 0 || strncmp(file_name, suffix, strlen(suffix)) != 0) continue; + + return (void *)map->maps[i].start; + } + + return NULL; +} + +void *find_func_addr(struct maps *local_info, struct maps *remote_info, const char *module, const char *func) { + void *lib = dlopen(module, RTLD_NOW); + if (lib == NULL) { + LOGE("failed to open lib %s: %s", module, dlerror()); + + return NULL; + } + + uint8_t *sym = (uint8_t *)dlsym(lib, func); + if (sym == NULL) { + LOGE("failed to find sym %s in %s: %s", func, module, dlerror()); + + dlclose(lib); + + return NULL; + } + + LOGD("sym %s: %p", func, sym); + + dlclose(lib); + + uint8_t *local_base = (uint8_t *)find_module_base(local_info, module); + if (local_base == NULL) { + LOGE("failed to find local base for module %s", module); + + return NULL; + } + + uint8_t *remote_base = (uint8_t *)find_module_base(remote_info, module); + if (remote_base == NULL) { + LOGE("failed to find remote base for module %s", module); + + return NULL; + } + + LOGD("found local base %p remote base %p", local_base, remote_base); + + uint8_t *addr = (sym - local_base) + remote_base; + LOGD("addr %p", addr); + + return addr; +} + +void align_stack(struct user_regs_struct *regs, long preserve) { + /* INFO: ~0xf is a negative value, and REG_SP is unsigned, + so we must cast REG_SP to signed type before subtracting + then cast back to unsigned type. + */ + regs->REG_SP = (uintptr_t)((intptr_t)(regs->REG_SP - preserve) & ~0xf); +} + +uintptr_t push_string(int pid, struct user_regs_struct *regs, const char *str) { + size_t len = strlen(str) + 1; + + regs->REG_SP -= len; + + align_stack(regs, 0); + + uintptr_t addr = (uintptr_t)regs->REG_SP; + if (!write_proc(pid, addr, str, len)) LOGE("failed to write string %s", str); + + LOGD("pushed string %" PRIxPTR, addr); + + return addr; +} + +uintptr_t remote_call(int pid, struct user_regs_struct *regs, uintptr_t func_addr, uintptr_t return_addr, long *args, size_t args_size) { + align_stack(regs, 0); + + LOGV("calling remote function %" PRIxPTR " args %zu", func_addr, args_size); + + for (size_t i = 0; i < args_size; i++) { + LOGV("arg %p", (void *)args[i]); + } + + #if defined(__x86_64__) + if (args_size >= 1) regs->rdi = args[0]; + if (args_size >= 2) regs->rsi = args[1]; + if (args_size >= 3) regs->rdx = args[2]; + if (args_size >= 4) regs->rcx = args[3]; + if (args_size >= 5) regs->r8 = args[4]; + if (args_size >= 6) regs->r9 = args[5]; + if (args_size > 6) { + long remain = (args_size - 6L) * sizeof(long); + align_stack(regs, remain); + + if (!write_proc(pid, (uintptr_t) regs->REG_SP, args, remain)) LOGE("failed to push arguments"); + } + + regs->REG_SP -= sizeof(long); + + if (!write_proc(pid, (uintptr_t) regs->REG_SP, &return_addr, sizeof(return_addr))) LOGE("failed to write return addr"); + + regs->REG_IP = func_addr; + #elif defined(__i386__) + if (args_size > 0) { + long remain = (args_size) * sizeof(long); + align_stack(regs, remain); + + if (!write_proc(pid, (uintptr_t) regs->REG_SP, args, remain)) LOGE("failed to push arguments"); + } + + regs->REG_SP -= sizeof(long); + + if (!write_proc(pid, (uintptr_t) regs->REG_SP, &return_addr, sizeof(return_addr))) LOGE("failed to write return addr"); + + regs->REG_IP = func_addr; + #elif defined(__aarch64__) + for (size_t i = 0; i < args_size && i < 8; i++) { + regs->regs[i] = args[i]; + } + + if (args_size > 8) { + long remain = (args_size - 8) * sizeof(long); + align_stack(regs, remain); + + write_proc(pid, (uintptr_t)regs->REG_SP, args, remain); + } + + regs->regs[30] = return_addr; + regs->REG_IP = func_addr; + #elif defined(__arm__) + for (size_t i = 0; i < args_size && i < 4; i++) { + regs->uregs[i] = args[i]; + } + + if (args_size > 4) { + long remain = (args_size - 4) * sizeof(long); + align_stack(regs, remain); + + write_proc(pid, (uintptr_t)regs->REG_SP, args, remain); + } + + regs->uregs[14] = return_addr; + regs->REG_IP = func_addr; + + unsigned long CPSR_T_MASK = 1lu << 5; + + if ((regs->REG_IP & 1) != 0) { + regs->REG_IP = regs->REG_IP & ~1; + regs->uregs[16] = regs->uregs[16] | CPSR_T_MASK; + } else { + regs->uregs[16] = regs->uregs[16] & ~CPSR_T_MASK; + } + #endif + + if (!set_regs(pid, regs)) { + LOGE("failed to set regs"); + + return 0; + } + + ptrace(PTRACE_CONT, pid, 0, 0); + + int status; + wait_for_trace(pid, &status, __WALL); + if (!get_regs(pid, regs)) { + LOGE("failed to get regs after call"); + + return 0; + } + + if (WSTOPSIG(status) == SIGSEGV) { + if ((uintptr_t)regs->REG_IP != return_addr) { + LOGE("wrong return addr %p", (void *) regs->REG_IP); + + return 0; + } + + return regs->REG_RET; + } else { + char status_str[64]; + parse_status(status, status_str, sizeof(status_str)); + + LOGE("stopped by other reason %s at addr %p", status_str, (void *)regs->REG_IP); + } + + return 0; +} + +int fork_dont_care() { + pid_t pid = fork(); + + if (pid < 0) PLOGE("fork 1"); + else if (pid == 0) { + pid = fork(); + if (pid < 0) PLOGE("fork 2"); + else if (pid > 0) exit(0); + } else { + int status; + waitpid(pid, &status, __WALL); + } + + return pid; +} + +void wait_for_trace(int pid, int *status, int flags) { + while (1) { + pid_t result = waitpid(pid, status, flags); + if (result == -1) { + if (errno == EINTR) continue; + + PLOGE("wait %d failed", pid); + exit(1); + } + + if (!WIFSTOPPED(*status)) { + char status_str[64]; + parse_status(*status, status_str, sizeof(status_str)); + + LOGE("process %d not stopped for trace: %s, exit", pid, status_str); + + exit(1); + } + + return; + } +} + +void parse_status(int status, char *buf, size_t len) { + snprintf(buf, len, "0x%x ", status); + + if (WIFEXITED(status)) { + snprintf(buf + strlen(buf), len - strlen(buf), "exited with %d", WEXITSTATUS(status)); + } else if (WIFSIGNALED(status)) { + snprintf(buf + strlen(buf), len - strlen(buf), "signaled with %s(%d)", sigabbrev_np(WTERMSIG(status)), WTERMSIG(status)); + } else if (WIFSTOPPED(status)) { + snprintf(buf + strlen(buf), len - strlen(buf), "stopped by "); + + int stop_sig = WSTOPSIG(status); + snprintf(buf + strlen(buf), len - strlen(buf), "signal=%s(%d),", sigabbrev_np(stop_sig), stop_sig); + snprintf(buf + strlen(buf), len - strlen(buf), "event=%s", parse_ptrace_event(status)); + } else { + snprintf(buf + strlen(buf), len - strlen(buf), "unknown"); + } +} + +int get_program(int pid, char *buf, size_t size) { + char path[PATH_MAX]; + snprintf(path, sizeof(path), "/proc/%d/exe", pid); + + ssize_t sz = readlink(path, buf, size); + + if (sz == -1) { + PLOGE("readlink /proc/%d/exe", pid); + + return -1; + } + + buf[sz] = '\0'; + + return 0; +} diff --git a/loader/src/ptracer/utils.cpp b/loader/src/ptracer/utils.cpp deleted file mode 100644 index 1acc32c..0000000 --- a/loader/src/ptracer/utils.cpp +++ /dev/null @@ -1,528 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "utils.hpp" -#include "logging.h" - -bool switch_mnt_ns(int pid, int *fd) { - int nsfd, old_nsfd = -1; - - /* WARNING: C++ keyword */ - char path[PATH_MAX]; - if (pid == 0) { - if (fd != NULL) { - nsfd = *fd; - *fd = -1; - } else return false; - - snprintf(path, sizeof(path), "/proc/self/fd/%d", nsfd); - } else { - if (fd != NULL) { - old_nsfd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC); - if (old_nsfd == -1) { - PLOGE("get old nsfd"); - - return false; - } - - *fd = old_nsfd; - } - - snprintf(path, sizeof(path), "/proc/%d/ns/mnt", pid); - - nsfd = open(path, O_RDONLY | O_CLOEXEC); - if (nsfd == -1) { - PLOGE("open nsfd %s", path); - - close(old_nsfd); - - return false; - } - } - - if (setns(nsfd, CLONE_NEWNS) == -1) { - PLOGE("set ns to %s", path); - - close(nsfd); - close(old_nsfd); - - return false; - } - - close(nsfd); - - return true; -} - -/* WARNING: C++ keyword */ -std::vector MapInfo::Scan(const std::string &pid) { - constexpr static auto kPermLength = 5; - constexpr static auto kMapEntry = 7; - - /* WARNING: C++ keyword */ - std::vector info; - char file_name[NAME_MAX]; - snprintf(file_name, sizeof(file_name), "/proc/%s/maps", pid.c_str()); - - /* WARNING: C++ keyword */ - auto maps = std::unique_ptr{fopen(file_name, "r"), &fclose}; - if (maps) { - char *line = NULL; - size_t len = 0; - ssize_t read; - - /* WARNING: C++ keyword */ - while ((read = getline(&line, &len, maps.get())) > 0) { - line[read - 1] = '\0'; - - uintptr_t start = 0; - uintptr_t end = 0; - uintptr_t off = 0; - ino_t inode = 0; - unsigned int dev_major = 0; - unsigned int dev_minor = 0; - - /* WARNING: C++ keyword */ - std::array perm {'\0'}; - - int path_off; - if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %4s %" PRIxPTR " %x:%x %lu %n%*s", &start, - &end, perm.data(), &off, &dev_major, &dev_minor, &inode, - &path_off) != kMapEntry) continue; - - while (path_off < read && isspace(line[path_off])) path_off++; - - /* WARNING: C++ keyword */ - MapInfo &ref = info.emplace_back(MapInfo{ - start, - end, - 0, - perm[3] == 'p', - off, - static_cast(makedev(dev_major, dev_minor)), - inode, - line + path_off - }); - - if (perm[0] == 'r') ref.perms |= PROT_READ; - if (perm[1] == 'w') ref.perms |= PROT_WRITE; - if (perm[2] == 'x') ref.perms |= PROT_EXEC; - } - - free(line); - } - - return info; -} - -ssize_t write_proc(int pid, uintptr_t remote_addr, const void *buf, size_t len) { - LOGV("write to remote addr %" PRIxPTR " size %zu", remote_addr, len); - - struct iovec local = { - .iov_base = (void *)buf, - .iov_len = len - }; - - struct iovec remote = { - .iov_base = (void *)remote_addr, - .iov_len = len - }; - - ssize_t l = process_vm_writev(pid, &local, 1, &remote, 1, 0); - if (l == -1) PLOGE("process_vm_writev"); - else if ((size_t)l != len) LOGW("not fully written: %zu, excepted %zu", l, len); - - return l; -} - -ssize_t read_proc(int pid, uintptr_t remote_addr, void *buf, size_t len) { - struct iovec local = { - .iov_base = (void *)buf, - .iov_len = len - }; - - struct iovec remote = { - .iov_base = (void *)remote_addr, - .iov_len = len - }; - - ssize_t l = process_vm_readv(pid, &local, 1, &remote, 1, 0); - if (l == -1) PLOGE("process_vm_readv"); - else if ((size_t)l != len) LOGW("not fully read: %zu, excepted %zu", l, len); - - return l; -} - -bool get_regs(int pid, struct user_regs_struct ®s) { - #if defined(__x86_64__) || defined(__i386__) - if (ptrace(PTRACE_GETREGS, pid, 0, ®s) == -1) { - PLOGE("getregs"); - - return false; - } - #elif defined(__aarch64__) || defined(__arm__) - struct iovec iov = { - .iov_base = ®s, - .iov_len = sizeof(struct user_regs_struct), - }; - - if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov) == -1) { - PLOGE("getregs"); - - return false; - } - #endif - - return true; -} - -bool set_regs(int pid, struct user_regs_struct ®s) { - #if defined(__x86_64__) || defined(__i386__) - if (ptrace(PTRACE_SETREGS, pid, 0, ®s) == -1) { - PLOGE("setregs"); - - return false; - } - #elif defined(__aarch64__) || defined(__arm__) - struct iovec iov = { - .iov_base = ®s, - .iov_len = sizeof(struct user_regs_struct), - }; - - if (ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov) == -1) { - PLOGE("setregs"); - - return false; - } - #endif - - return true; -} - -/* WARNING: C++ keyword */ -std::string get_addr_mem_region(std::vector &info, uintptr_t addr) { - /* WARNING: C++ keyword */ - for (auto &map: info) { - if (map.start <= addr && map.end > addr) { - /* WARNING: C++ keyword */ - auto s = std::string(map.path); - - s += ' '; - s += map.perms & PROT_READ ? 'r' : '-'; - s += map.perms & PROT_WRITE ? 'w' : '-'; - s += map.perms & PROT_EXEC ? 'x' : '-'; - - return s; - } - } - - return ""; -} - -/* WARNING: C++ keyword */ -void *find_module_return_addr(std::vector &info, std::string_view suffix) { - /* WARNING: C++ keyword */ - for (auto &map: info) { - /* WARNING: C++ keyword */ - if ((map.perms & PROT_EXEC) == 0 && map.path.ends_with(suffix)) return (void *)map.start; - } - - return NULL; -} - -/* WARNING: C++ keyword */ -void *find_module_base(std::vector &info, std::string_view suffix) { - /* WARNING: C++ keyword */ - for (auto &map: info) { - /* WARNING: C++ keyword */ - if (map.offset == 0 && map.path.ends_with(suffix)) return (void *)map.start; - } - - return NULL; -} - -/* WARNING: C++ keyword */ -void *find_func_addr(std::vector &local_info, std::vector &remote_info, std::string_view module, std::string_view func) { - void *lib = dlopen(module.data(), RTLD_NOW); - if (lib == NULL) { - LOGE("failed to open lib %s: %s", module.data(), dlerror()); - - return NULL; - } - - uint8_t *sym = (uint8_t *)dlsym(lib, func.data()); - if (sym == NULL) { - LOGE("failed to find sym %s in %s: %s", func.data(), module.data(), dlerror()); - - dlclose(lib); - - return NULL; - } - - LOGD("sym %s: %p", func.data(), sym); - - dlclose(lib); - - uint8_t *local_base = (uint8_t *)find_module_base(local_info, module); - if (local_base == NULL) { - LOGE("failed to find local base for module %s", module.data()); - - return NULL; - } - - uint8_t *remote_base = (uint8_t *)find_module_base(remote_info, module); - if (remote_base == NULL) { - LOGE("failed to find remote base for module %s", module.data()); - - return NULL; - } - - LOGD("found local base %p remote base %p", local_base, remote_base); - - uint8_t *addr = (sym - local_base) + remote_base; - LOGD("addr %p", addr); - - return addr; -} - -/* WARNING: C++ keyword */ -void align_stack(struct user_regs_struct ®s, long preserve) { - /* INFO: ~0xf is a negative value, and REG_SP is unsigned, - so we must cast REG_SP to signed type before subtracting - then cast back to unsigned type. - */ - regs.REG_SP = (uintptr_t)((intptr_t)(regs.REG_SP - preserve) & ~0xf); -} - -/* WARNING: C++ keyword */ -uintptr_t push_string(int pid, struct user_regs_struct ®s, const char *str) { - size_t len = strlen(str) + 1; - - regs.REG_SP -= len; - - align_stack(regs); - - uintptr_t addr = (uintptr_t)regs.REG_SP; - if (!write_proc(pid, addr, str, len)) LOGE("failed to write string %s", str); - - LOGD("pushed string %" PRIxPTR, addr); - - return addr; -} - -/* WARNING: C++ keyword */ -uintptr_t remote_call(int pid, struct user_regs_struct ®s, uintptr_t func_addr, uintptr_t return_addr, std::vector &args) { - align_stack(regs); - - /* WARNING: C++ keyword */ - LOGV("calling remote function %" PRIxPTR " args %zu", func_addr, args.size()); - - /* WARNING: C++ keyword */ - for (auto &a: args) { - LOGV("arg %p", (void *) a); - } - - #if defined(__x86_64__) - if (args.size() >= 1) regs.rdi = args[0]; - if (args.size() >= 2) regs.rsi = args[1]; - if (args.size() >= 3) regs.rdx = args[2]; - if (args.size() >= 4) regs.rcx = args[3]; - if (args.size() >= 5) regs.r8 = args[4]; - if (args.size() >= 6) regs.r9 = args[5]; - if (args.size() > 6) { - long remain = (args.size() - 6L) * sizeof(long); - align_stack(regs, remain); - - if (!write_proc(pid, (uintptr_t) regs.REG_SP, args.data(), remain)) LOGE("failed to push arguments"); - } - - regs.REG_SP -= sizeof(long); - - if (!write_proc(pid, (uintptr_t) regs.REG_SP, &return_addr, sizeof(return_addr))) LOGE("failed to write return addr"); - - regs.REG_IP = func_addr; - #elif defined(__i386__) - if (args.size() > 0) { - long remain = (args.size()) * sizeof(long); - align_stack(regs, remain); - - if (!write_proc(pid, (uintptr_t) regs.REG_SP, args.data(), remain)) LOGE("failed to push arguments"); - } - - regs.REG_SP -= sizeof(long); - - if (!write_proc(pid, (uintptr_t) regs.REG_SP, &return_addr, sizeof(return_addr))) LOGE("failed to write return addr"); - - regs.REG_IP = func_addr; - #elif defined(__aarch64__) - for (size_t i = 0; i < args.size() && i < 8; i++) { - regs.regs[i] = args[i]; - } - - if (args.size() > 8) { - long remain = (args.size() - 8) * sizeof(long); - align_stack(regs, remain); - - write_proc(pid, (uintptr_t)regs.REG_SP, args.data(), remain); - } - - regs.regs[30] = return_addr; - regs.REG_IP = func_addr; - #elif defined(__arm__) - for (size_t i = 0; i < args.size() && i < 4; i++) { - regs.uregs[i] = args[i]; - } - - if (args.size() > 4) { - long remain = (args.size() - 4) * sizeof(long); - align_stack(regs, remain); - - write_proc(pid, (uintptr_t)regs.REG_SP, args.data(), remain); - } - - regs.uregs[14] = return_addr; - regs.REG_IP = func_addr; - - constexpr auto CPSR_T_MASK = 1lu << 5; - - if ((regs.REG_IP & 1) != 0) { - regs.REG_IP = regs.REG_IP & ~1; - regs.uregs[16] = regs.uregs[16] | CPSR_T_MASK; - } else { - regs.uregs[16] = regs.uregs[16] & ~CPSR_T_MASK; - } - #endif - - if (!set_regs(pid, regs)) { - LOGE("failed to set regs"); - - return 0; - } - - ptrace(PTRACE_CONT, pid, 0, 0); - - int status; - wait_for_trace(pid, &status, __WALL); - if (!get_regs(pid, regs)) { - LOGE("failed to get regs after call"); - - return 0; - } - - if (WSTOPSIG(status) == SIGSEGV) { - if ((uintptr_t)regs.REG_IP != return_addr) { - LOGE("wrong return addr %p", (void *) regs.REG_IP); - - return 0; - } - - return regs.REG_RET; - } else { - char status_str[64]; - parse_status(status, status_str, sizeof(status_str)); - - LOGE("stopped by other reason %s at addr %p", status_str, (void *)regs.REG_IP); - } - - return 0; -} - -int fork_dont_care() { - pid_t pid = fork(); - - if (pid < 0) PLOGE("fork 1"); - else if (pid == 0) { - pid = fork(); - if (pid < 0) PLOGE("fork 2"); - else if (pid > 0) exit(0); - } else { - int status; - waitpid(pid, &status, __WALL); - } - - return pid; -} - -void wait_for_trace(int pid, int *status, int flags) { - while (1) { - pid_t result = waitpid(pid, status, flags); - if (result == -1) { - if (errno == EINTR) continue; - - PLOGE("wait %d failed", pid); - exit(1); - } - - if (!WIFSTOPPED(*status)) { - char status_str[64]; - parse_status(*status, status_str, sizeof(status_str)); - - LOGE("process %d not stopped for trace: %s, exit", pid, status_str); - - exit(1); - } - - return; - } -} - -void parse_status(int status, char *buf, size_t len) { - snprintf(buf, len, "0x%x ", status); - - if (WIFEXITED(status)) { - snprintf(buf + strlen(buf), len - strlen(buf), "exited with %d", WEXITSTATUS(status)); - } else if (WIFSIGNALED(status)) { - snprintf(buf + strlen(buf), len - strlen(buf), "signaled with %s(%d)", sigabbrev_np(WTERMSIG(status)), WTERMSIG(status)); - } else if (WIFSTOPPED(status)) { - snprintf(buf + strlen(buf), len - strlen(buf), "stopped by "); - - int stop_sig = WSTOPSIG(status); - snprintf(buf + strlen(buf), len - strlen(buf), "signal=%s(%d),", sigabbrev_np(stop_sig), stop_sig); - snprintf(buf + strlen(buf), len - strlen(buf), "event=%s", parse_ptrace_event(status)); - } else { - snprintf(buf + strlen(buf), len - strlen(buf), "unknown"); - } -} - -int get_program(int pid, char *buf, size_t size) { - char path[PATH_MAX]; - snprintf(path, sizeof(path), "/proc/%d/exe", pid); - - ssize_t sz = readlink(path, buf, size); - - if (sz == -1) { - PLOGE("readlink /proc/%d/exe", pid); - - return -1; - } - - buf[sz] = 0; - - return 0; -} diff --git a/loader/src/ptracer/utils.h b/loader/src/ptracer/utils.h new file mode 100644 index 0000000..02b37ac --- /dev/null +++ b/loader/src/ptracer/utils.h @@ -0,0 +1,109 @@ +#ifndef UTILS_H +#define UTILS_H + +#include + +#include "daemon.h" + +#include "logging.h" + +struct map { + uintptr_t start; + uintptr_t end; + uint8_t perms; + bool is_private; + uintptr_t offset; + dev_t dev; + ino_t inode; + const char *path; +}; + +struct maps { + struct map *maps; + size_t size; +}; + +struct maps *parse_maps(const char *filename); + +void free_maps(struct maps *maps); + +#if defined(__x86_64__) + #define REG_SP rsp + #define REG_IP rip + #define REG_RET rax +#elif defined(__i386__) + #define REG_SP esp + #define REG_IP eip + #define REG_RET eax +#elif defined(__aarch64__) + #define REG_SP sp + #define REG_IP pc + #define REG_RET regs[0] +#elif defined(__arm__) + #define REG_SP uregs[13] + #define REG_IP uregs[15] + #define REG_RET uregs[0] + #define user_regs_struct user_regs +#endif + +ssize_t write_proc(int pid, uintptr_t remote_addr, const void *buf, size_t len); + +ssize_t read_proc(int pid, uintptr_t remote_addr, void *buf, size_t len); + +bool get_regs(int pid, struct user_regs_struct *regs); + +bool set_regs(int pid, struct user_regs_struct *regs); + +void get_addr_mem_region(struct maps *map, uintptr_t addr, char *buf, size_t buf_size); + +void *find_module_return_addr(struct maps *map, const char *suffix); + +void *find_func_addr(struct maps *local_info, struct maps *remote_info, const char *module, const char *func); + +void align_stack(struct user_regs_struct *regs, long preserve); + +uintptr_t push_string(int pid, struct user_regs_struct *regs, const char *str); + +uintptr_t remote_call(int pid, struct user_regs_struct *regs, uintptr_t func_addr, uintptr_t return_addr, long *args, size_t args_size); + +int fork_dont_care(); + +void wait_for_trace(int pid, int* status, int flags); + +void parse_status(int status, char *buf, size_t len); + +#define WPTEVENT(x) (x >> 16) + +#define CASE_CONST_RETURN(x) case x: return #x; + +static inline const char *parse_ptrace_event(int status) { + status = status >> 16; + + switch (status) { + CASE_CONST_RETURN(PTRACE_EVENT_FORK) + CASE_CONST_RETURN(PTRACE_EVENT_VFORK) + CASE_CONST_RETURN(PTRACE_EVENT_CLONE) + CASE_CONST_RETURN(PTRACE_EVENT_EXEC) + CASE_CONST_RETURN(PTRACE_EVENT_VFORK_DONE) + CASE_CONST_RETURN(PTRACE_EVENT_EXIT) + CASE_CONST_RETURN(PTRACE_EVENT_SECCOMP) + CASE_CONST_RETURN(PTRACE_EVENT_STOP) + default: + return "(no event)"; + } +} + +static inline const char *sigabbrev_np(int sig) { + if (sig > 0 && sig < NSIG) return sys_signame[sig]; + + return "(unknown)"; +} + +int get_program(int pid, char *buf, size_t size); + +/* INFO: pid = 0, fd != nullptr -> set to fd + pid != 0, fd != nullptr -> set to pid ns, give orig ns in fd +*/ +bool switch_mnt_ns(int pid, int *fd); + +#endif /* UTILS_H */ \ No newline at end of file diff --git a/loader/src/ptracer/utils.hpp b/loader/src/ptracer/utils.hpp deleted file mode 100644 index 83858b3..0000000 --- a/loader/src/ptracer/utils.hpp +++ /dev/null @@ -1,125 +0,0 @@ -#pragma once -#include -#include -#include - -#include "daemon.h" - -#ifdef __LP64__ -#define LOG_TAG "zygisk-ptrace64" -#else -#define LOG_TAG "zygisk-ptrace32" -#endif - -#include "logging.h" - -struct MapInfo { - /// \brief The start address of the memory region. - uintptr_t start; - /// \brief The end address of the memory region. - uintptr_t end; - /// \brief The permissions of the memory region. This is a bit mask of the following values: - /// - PROT_READ - /// - PROT_WRITE - /// - PROT_EXEC - uint8_t perms; - /// \brief Whether the memory region is private. - bool is_private; - /// \brief The offset of the memory region. - uintptr_t offset; - /// \brief The device number of the memory region. - /// Major can be obtained by #major() - /// Minor can be obtained by #minor() - dev_t dev; - /// \brief The inode number of the memory region. - ino_t inode; - /// \brief The path of the memory region. - std::string path; - - /// \brief Scans /proc/self/maps and returns a list of \ref MapInfo entries. - /// This is useful to find out the inode of the library to hook. - /// \return A list of \ref MapInfo entries. - static std::vector Scan(const std::string& pid = "self"); -}; - -#if defined(__x86_64__) -#define REG_SP rsp -#define REG_IP rip -#define REG_RET rax -#elif defined(__i386__) -#define REG_SP esp -#define REG_IP eip -#define REG_RET eax -#elif defined(__aarch64__) -#define REG_SP sp -#define REG_IP pc -#define REG_RET regs[0] -#elif defined(__arm__) -#define REG_SP uregs[13] -#define REG_IP uregs[15] -#define REG_RET uregs[0] -#define user_regs_struct user_regs -#endif - -ssize_t write_proc(int pid, uintptr_t remote_addr, const void *buf, size_t len); - -ssize_t read_proc(int pid, uintptr_t remote_addr, void *buf, size_t len); - -bool get_regs(int pid, struct user_regs_struct ®s); - -bool set_regs(int pid, struct user_regs_struct ®s); - -std::string get_addr_mem_region(std::vector &info, uintptr_t addr); - -void *find_module_base(std::vector &info, std::string_view suffix); - -void *find_func_addr( - std::vector &local_info, - std::vector &remote_info, - std::string_view module, - std::string_view func); - -void align_stack(struct user_regs_struct ®s, long preserve = 0); - -uintptr_t push_string(int pid, struct user_regs_struct ®s, const char *str); - -uintptr_t remote_call(int pid, struct user_regs_struct ®s, uintptr_t func_addr, uintptr_t return_addr, - std::vector &args); - -int fork_dont_care(); - -void wait_for_trace(int pid, int* status, int flags); - -void parse_status(int status, char *buf, size_t len); - -#define WPTEVENT(x) (x >> 16) - -#define CASE_CONST_RETURN(x) case x: return #x; - -inline const char* parse_ptrace_event(int status) { - status = status >> 16; - switch (status) { - CASE_CONST_RETURN(PTRACE_EVENT_FORK) - CASE_CONST_RETURN(PTRACE_EVENT_VFORK) - CASE_CONST_RETURN(PTRACE_EVENT_CLONE) - CASE_CONST_RETURN(PTRACE_EVENT_EXEC) - CASE_CONST_RETURN(PTRACE_EVENT_VFORK_DONE) - CASE_CONST_RETURN(PTRACE_EVENT_EXIT) - CASE_CONST_RETURN(PTRACE_EVENT_SECCOMP) - CASE_CONST_RETURN(PTRACE_EVENT_STOP) - default: - return "(no event)"; - } -} - -inline const char* sigabbrev_np(int sig) { - if (sig > 0 && sig < NSIG) return sys_signame[sig]; - return "(unknown)"; -} - -int get_program(int pid, char *buf, size_t size); -void *find_module_return_addr(std::vector &info, std::string_view suffix); - -// pid = 0, fd != nullptr -> set to fd -// pid != 0, fd != nullptr -> set to pid ns, give orig ns in fd -bool switch_mnt_ns(int pid, int *fd); diff --git a/zygiskd/src/utils.h b/zygiskd/src/utils.h index 1d8bebb..d3946c9 100644 --- a/zygiskd/src/utils.h +++ b/zygiskd/src/utils.h @@ -65,7 +65,7 @@ return -1; \ } -#define write_func_def(type) \ +#define write_func_def(type) \ ssize_t write_## type(int fd, type val) #define read_func_def(type) \ diff --git a/zygiskd/src/zygiskd.c b/zygiskd/src/zygiskd.c index 44fa9fc..eb9bc29 100644 --- a/zygiskd/src/zygiskd.c +++ b/zygiskd/src/zygiskd.c @@ -58,34 +58,6 @@ static enum Architecture get_arch(void) { exit(1); } -int create_library_fd(const char *restrict so_path) { - int so_fd = open(so_path, O_RDONLY); - if (so_fd == -1) { - LOGE("Failed opening so file: %s\n", strerror(errno)); - - return -1; - } - - off_t so_size = lseek(so_fd, 0, SEEK_END); - if (so_size == -1) { - LOGE("Failed getting so file size: %s\n", strerror(errno)); - - close(so_fd); - - return -1; - } - - if (lseek(so_fd, 0, SEEK_SET) == -1) { - LOGE("Failed seeking so file: %s\n", strerror(errno)); - - close(so_fd); - - return -1; - } - - return so_fd; -} - /* WARNING: Dynamic memory based */ static void load_modules(enum Architecture arch, struct Context *restrict context) { context->len = 0; @@ -138,7 +110,7 @@ static void load_modules(enum Architecture arch, struct Context *restrict contex errno = 0; } else continue; - int lib_fd = create_library_fd(so_path); + int lib_fd = open(so_path, O_RDONLY | O_CLOEXEC); if (lib_fd == -1) { LOGE("Failed loading module `%s`\n", name); @@ -556,12 +528,6 @@ void zygiskd_start(char *restrict argv[]) { break; } - - if (write_string(client_fd, context.modules[i].name) == -1) { - LOGE("Failed writing module name.\n"); - - break; - } } break; From db24c1c4396056ca659233e9422e1e536d13cc3c Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Wed, 16 Apr 2025 02:04:40 -0300 Subject: [PATCH 38/46] improve: not umount modules `/system` mounts This commit creates a new behavior in ReZygisk umounting system where it now ignores "/system/..." mounts, as umounting them generally leads to unbootable system. --- zygiskd/src/utils.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/zygiskd/src/utils.c b/zygiskd/src/utils.c index 6922599..8c2d00b 100644 --- a/zygiskd/src/utils.c +++ b/zygiskd/src/utils.c @@ -358,7 +358,7 @@ bool exec_command(char *restrict buf, size_t len, const char *restrict file, cha dup2(link[1], STDOUT_FILENO); close(link[0]); close(link[1]); - + execv(file, argv); LOGE("execv failed: %s\n", strerror(errno)); @@ -626,7 +626,7 @@ enum mns_umount_state unmount_root(bool modules_only, struct root_impl impl) { char source_name[LONGEST_ROOT_IMPL_NAME]; if (impl.impl == KernelSU) strcpy(source_name, "KSU"); else strcpy(source_name, "APatch"); - + const char **targets_to_unmount = NULL; size_t num_targets = 0; @@ -639,6 +639,8 @@ enum mns_umount_state unmount_root(bool modules_only, struct root_impl impl) { if (strncmp(mount.target, "/debug_ramdisk", strlen("/debug_ramdisk")) == 0) should_unmount = true; } else { + if (strncmp(mount.target, "/system/", strlen("/system/")) == 0) continue; + if (strcmp(mount.source, source_name) == 0) should_unmount = true; if (strncmp(mount.root, "/adb/modules", strlen("/adb/modules")) == 0) should_unmount = true; if (strncmp(mount.target, "/data/adb/modules", strlen("/data/adb/modules")) == 0) should_unmount = true; @@ -675,7 +677,7 @@ enum mns_umount_state unmount_root(bool modules_only, struct root_impl impl) { } case Magisk: { LOGI("[Magisk] Unmounting root %s modules\n", modules_only ? "only" : "with"); - + const char **targets_to_unmount = NULL; size_t num_targets = 0; @@ -683,27 +685,18 @@ enum mns_umount_state unmount_root(bool modules_only, struct root_impl impl) { struct mountinfo mount = mounts.mounts[i]; bool should_unmount = false; - if ( - ( - modules_only && - ( - strcmp(mount.source, "magisk") == 0 || - strncmp(mount.target, "/debug_ramdisk", strlen("/debug_ramdisk")) == 0 || - strncmp(mount.target, "/system/bin", strlen("/system/bin")) == 0 - ) - ) || - ( - !modules_only && - ( - strcmp(mount.source, "magisk") == 0 || - strncmp(mount.target, "/debug_ramdisk", strlen("/debug_ramdisk")) == 0 || - strncmp(mount.target, "/data/adb/modules", strlen("/data/adb/modules")) == 0 || - strncmp(mount.root, "/adb/modules", strlen("/adb/modules")) == 0 || - strncmp(mount.target, "/system/bin", strlen("/system/bin")) == 0 - ) - ) - ) { - should_unmount = true; + if (modules_only) { + if (strcmp(mount.source, "magisk") == 0) should_unmount = true; + if (strncmp(mount.target, "/debug_ramdisk", strlen("/debug_ramdisk")) == 0) should_unmount = true; + if (strncmp(mount.target, "/system/bin", strlen("/system/bin")) == 0) should_unmount = true; + } else { + if (strncmp(mount.target, "/system/", strlen("/system/")) == 0) continue; + + if (strcmp(mount.source, "magisk") == 0) should_unmount = true; + if (strncmp(mount.target, "/debug_ramdisk", strlen("/debug_ramdisk")) == 0) should_unmount = true; + if (strncmp(mount.target, "/data/adb/modules", strlen("/data/adb/modules")) == 0) should_unmount = true; + if (strncmp(mount.root, "/adb/modules", strlen("/adb/modules")) == 0) should_unmount = true; + if (strncmp(mount.target, "/system/bin", strlen("/system/bin")) == 0) should_unmount = true; } if (!should_unmount) continue; From 8f70a1a451aaefbb92aa869f96a86c357d22b892 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Wed, 16 Apr 2025 02:07:59 -0300 Subject: [PATCH 39/46] remove: unused `mazoku` file This commit removes the "mazoku" file, which is only used by Zygisk Next/Shamiko for module integrity and signing, and is not used in ReZygisk. --- module/build.gradle.kts | 4 +--- module/src/customize.sh | 1 - module/src/mazoku | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 module/src/mazoku diff --git a/module/build.gradle.kts b/module/build.gradle.kts index a9c52fb..5a5f184 100644 --- a/module/build.gradle.kts +++ b/module/build.gradle.kts @@ -53,7 +53,7 @@ androidComponents.onVariants { variant -> into(moduleDir) from("${rootProject.projectDir}/README.md") from("$projectDir/src") { - exclude("module.prop", "customize.sh", "post-fs-data.sh", "service.sh", "uninstall.sh", "mazoku") + exclude("module.prop", "customize.sh", "post-fs-data.sh", "service.sh", "uninstall.sh") filter("eol" to FixCrLfFilter.CrLf.newInstance("lf")) } from("$projectDir/src") { @@ -65,7 +65,6 @@ androidComponents.onVariants { variant -> "versionCode" to verCode ) } - from("$projectDir/src/mazoku") from("$projectDir/src") { include("customize.sh", "post-fs-data.sh", "service.sh", "uninstall.sh") val tokens = mapOf( @@ -122,7 +121,6 @@ androidComponents.onVariants { variant -> set.add(Pair(root.file("sepolicy.rule").asFile, null)) set.add(Pair(root.file("post-fs-data.sh").asFile, null)) set.add(Pair(root.file("service.sh").asFile, null)) - set.add(Pair(root.file("mazoku").asFile, null)) set.add( Pair( root.file("lib/libzygisk.so").asFile, diff --git a/module/src/customize.sh b/module/src/customize.sh index 741581f..649b707 100644 --- a/module/src/customize.sh +++ b/module/src/customize.sh @@ -104,7 +104,6 @@ extract "$ZIPFILE" 'module.prop' "$MODPATH" extract "$ZIPFILE" 'post-fs-data.sh' "$MODPATH" extract "$ZIPFILE" 'service.sh' "$MODPATH" extract "$ZIPFILE" 'uninstall.sh' "$MODPATH" -extract "$ZIPFILE" 'mazoku' "$MODPATH" mv "$TMPDIR/sepolicy.rule" "$MODPATH" mkdir "$MODPATH/bin" diff --git a/module/src/mazoku b/module/src/mazoku deleted file mode 100644 index a7cd563..0000000 --- a/module/src/mazoku +++ /dev/null @@ -1 +0,0 @@ -c] [{ڭBu5=rEUZʿ<5_oMLlQ#C} efjق/7(g Date: Wed, 16 Apr 2025 02:15:08 -0300 Subject: [PATCH 40/46] improve: `magisk` binary check code This commit improves and simplifies the code that checks in which path the "magisk" binary is by using loops instead of hardcoded "if"s. --- zygiskd/src/root_impl/magisk.c | 59 ++++++++++++---------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/zygiskd/src/root_impl/magisk.c b/zygiskd/src/root_impl/magisk.c index 9f4e364..ee5d48b 100644 --- a/zygiskd/src/root_impl/magisk.c +++ b/zygiskd/src/root_impl/magisk.c @@ -30,53 +30,36 @@ char *magisk_managers[] = { enum magisk_variants variant = Official; /* INFO: Longest path */ -static char path_to_magisk[sizeof(DEBUG_RAMDISK_MAGISK)]; +static char path_to_magisk[sizeof(DEBUG_RAMDISK_MAGISK)] = { 0 }; bool is_using_sulist = false; void magisk_get_existence(struct root_impl_state *state) { - struct stat s; - if (stat(SBIN_MAGISK, &s) != 0) { - if (errno != ENOENT) { - LOGE("Failed to stat Magisk /sbin/magisk binary: %s\n", strerror(errno)); - } - errno = 0; + const char *magisk_files[] = { + SBIN_MAGISK, + BITLESS_SBIN_MAGISK, + DEBUG_RAMDISK_MAGISK, + BITLESS_DEBUG_RAMDISK_MAGISK + }; - if (stat(BITLESS_SBIN_MAGISK, &s) != 0) { + for (size_t i = 0; i < sizeof(magisk_files) / sizeof(magisk_files[0]); i++) { + if (access(magisk_files[i], F_OK) != 0) { if (errno != ENOENT) { - LOGE("Failed to stat Magisk %s binary: %s\n", BITLESS_SBIN_MAGISK, strerror(errno)); + LOGE("Failed to access Magisk binary: %s\n", strerror(errno)); } errno = 0; - if (stat(DEBUG_RAMDISK_MAGISK, &s) != 0) { - if (errno != ENOENT) { - LOGE("Failed to stat Magisk %s binary: %s\n", DEBUG_RAMDISK_MAGISK, strerror(errno)); - } - errno = 0; - - if (stat(BITLESS_DEBUG_RAMDISK_MAGISK, &s) != 0) { - if (errno != ENOENT) { - LOGE("Failed to stat Magisk /debug_ramdisk/magisk binary: %s\n", strerror(errno)); - } - errno = 0; - - state->state = Inexistent; - - return; - } - - /* INFO: /debug_ramdisk/magisk64 (or 32) doesn't exist but /debug_ramdisk/magisk does */ - strcpy(path_to_magisk, BITLESS_DEBUG_RAMDISK_MAGISK); - } else { - /* INFO: /sbin/magisk doesn't exist but /debug_ramdisk/magisk does */ - strcpy(path_to_magisk, DEBUG_RAMDISK_MAGISK); - } - } else { - /* INFO: /sbin/magisk64 (or 32) doesn't exist but /sbin/magisk does */ - strcpy(path_to_magisk, BITLESS_SBIN_MAGISK); + continue; } - } else { - /* INFO: /sbin/magisk64 (or 32) exists */ - strcpy(path_to_magisk, SBIN_MAGISK); + + strcpy(path_to_magisk, magisk_files[i]); + + break; + } + + if (path_to_magisk[0] == '\0') { + state->state = Inexistent; + + return; } char *argv[4] = { "magisk", "-v", NULL, NULL }; From 622e23e7ecf0c87b36c678c3c1babd73a4c955ab Mon Sep 17 00:00:00 2001 From: Md Arif <111168803+sabamdarif@users.noreply.github.com> Date: Thu, 17 Apr 2025 21:16:09 +0530 Subject: [PATCH 41/46] fix: wrong JNI function signature for GrapheneOS (#99) This commit fixes the wrong signature for JNI functions of GrapheneOS's Zygote, leading to it not working on GrapheneOS. --- loader/src/injector/gen_jni_hooks.py | 3 +-- loader/src/injector/jni_hooks.hpp | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/loader/src/injector/gen_jni_hooks.py b/loader/src/injector/gen_jni_hooks.py index a3adbf6..bdf0eeb 100644 --- a/loader/src/injector/gen_jni_hooks.py +++ b/loader/src/injector/gen_jni_hooks.py @@ -212,8 +212,7 @@ server_samsung_q = ForkServer('samsung_q', [uid, gid, gids, runtime_flags, Anon( permitted_capabilities, effective_capabilities]) # GrapheneOS Android 14 Support -server_grapheneos_u = ForkServer('grapheneos_u', [uid, gid, gids, runtime_flags, Anon(jint), Anon(jint), rlimits, - permitted_capabilities, effective_capabilities]) +server_grapheneos_u = ForkServer('grapheneos_u', [uid, gid, gids, runtime_flags, rlimits, permitted_capabilities, effective_capabilities]) fas_grapheneos_u = ForkAndSpec('grapheneos_u', [uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir, diff --git a/loader/src/injector/jni_hooks.hpp b/loader/src/injector/jni_hooks.hpp index b31a7fd..177b139 100644 --- a/loader/src/injector/jni_hooks.hpp +++ b/loader/src/injector/jni_hooks.hpp @@ -127,7 +127,7 @@ void *nativeForkAndSpecialize_orig = nullptr; ctx.nativeForkAndSpecialize_post(); return ctx.pid; } -[[clang::no_stack_protector]] jint nativeForkAndSpecialize_grapheneos_u(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jlongArray _15) { +[[clang::no_stack_protector]] jint nativeForkAndSpecialize_grapheneos_u(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jlongArray _13) { AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir); args.fds_to_ignore = &fds_to_ignore; args.is_child_zygote = &is_child_zygote; @@ -140,7 +140,7 @@ void *nativeForkAndSpecialize_orig = nullptr; ZygiskContext ctx(env, &args); ctx.nativeForkAndSpecialize_pre(); reinterpret_cast(nativeForkAndSpecialize_orig)( - env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _15 + env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _13 ); ctx.nativeForkAndSpecialize_post(); return ctx.pid; @@ -266,7 +266,7 @@ void *nativeSpecializeAppProcess_orig = nullptr; ); ctx.nativeSpecializeAppProcess_post(); } -[[clang::no_stack_protector]] void nativeSpecializeAppProcess_grapheneos_u(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jlongArray _16) { +[[clang::no_stack_protector]] void nativeSpecializeAppProcess_grapheneos_u(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jlongArray _14) { AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir); args.is_child_zygote = &is_child_zygote; args.is_top_app = &is_top_app; @@ -278,7 +278,7 @@ void *nativeSpecializeAppProcess_orig = nullptr; ZygiskContext ctx(env, &args); ctx.nativeSpecializeAppProcess_pre(); reinterpret_cast(nativeSpecializeAppProcess_orig)( - env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _16 + env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _14 ); ctx.nativeSpecializeAppProcess_post(); } @@ -336,12 +336,12 @@ void *nativeForkSystemServer_orig = nullptr; ctx.nativeForkSystemServer_post(); return ctx.pid; } -[[clang::no_stack_protector]] jint nativeForkSystemServer_grapheneos_u(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _13, jint _14, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities) { +[[clang::no_stack_protector]] jint nativeForkSystemServer_grapheneos_u(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities) { ServerSpecializeArgs_v1 args(uid, gid, gids, runtime_flags, permitted_capabilities, effective_capabilities); ZygiskContext ctx(env, &args); ctx.nativeForkSystemServer_pre(); reinterpret_cast(nativeForkSystemServer_orig)( - env, clazz, uid, gid, gids, runtime_flags, _13, _14, rlimits, permitted_capabilities, effective_capabilities + env, clazz, uid, gid, gids, runtime_flags, rlimits, permitted_capabilities, effective_capabilities ); ctx.nativeForkSystemServer_post(); return ctx.pid; @@ -359,7 +359,7 @@ std::array nativeForkSystemServer_methods = { }, JNINativeMethod { "nativeForkSystemServer", - "(II[IIII[[IJJ)I", + "(II[II[[IJJ)I", (void *) &nativeForkSystemServer_grapheneos_u }, }; From 221b4fc9973f4744efcef5766581ad36cb810b15 Mon Sep 17 00:00:00 2001 From: GhostFRR Date: Thu, 17 Apr 2025 19:07:37 +0200 Subject: [PATCH 42/46] add: French README.md translations (#129) This commit adds the translations for French of the "README.md" file. Signed-off-by: GhostFRR --- README.md | 2 +- READMEs/README_fr-FR.md | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 READMEs/README_fr-FR.md diff --git a/README.md b/README.md index 92b4a6c..082e8f8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ReZygisk -[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md)|[Bahasa Indonesia](/READMEs/README_id-ID.md)|[Tiếng Việt](/READMEs/README_vi-VN.md)|[Português Brasileiro](/READMEs/README_pt-BR.md)|[Türkçe](/READMEs/README_tr-TR.md) +[简体中文](/READMEs/README_zh-CN.md)|[繁體中文](/READMEs/README_zh-TW.md)|[Bahasa Indonesia](/READMEs/README_id-ID.md)|[Tiếng Việt](/READMEs/README_vi-VN.md)|[Português Brasileiro](/READMEs/README_pt-BR.md)|[Türkçe](/READMEs/README_tr-TR.md)|[French](/READMEs/README_fr-FR.md) ReZygisk is a fork of Zygisk Next, a standalone implementation of Zygisk, providing Zygisk API support for KernelSU, Magisk (besides built-in), and APatch (Work In Progress). diff --git a/READMEs/README_fr-FR.md b/READMEs/README_fr-FR.md new file mode 100644 index 0000000..a9c96da --- /dev/null +++ b/READMEs/README_fr-FR.md @@ -0,0 +1,61 @@ +# ReZygisk + +[English](../README.md) + +ReZygisk est un fork de Zygisk Next, une implémentation autonome de Zygisk. Il vise à fournir un support de l'API Zygisk pour KernelSU, Magisk (en plus de l'intégration existante), et pour Apatch (encore en cours de développement). + +L'objectif est de moderniser et de réécrire la base du code, initialement en C, vers du C++ et du Rust. Cela permettra une meilleure efficacité et une implémentation plus rapide de l'API Zygisk, le tout sous une licence plus permissive. + +> [!NOTE] +> Ce module/fork est en cours de développement ; n'utilisez que les fichiers .zip provenant des 'Releases'. +> +>Bien que vous puissiez installer les fichiers .zip provenant de la page [Actions](https://github.com/PerformanC/ReZygisk/actions), cela vous regarde et peut faire entrer votre téléphone en boucle de redémarrage (bootloop). +## Pourquoi ? + +La dernière release de Zygisk Next n'est pas open source, le code est donc accessible uniquement à ses développeurs. Non seulement cela limite notre capacité à contribuer au projet, mais cela rend également impossible la vérification du code, ce qui constitue une préoccupation majeure en matière de sécurité. Zygisk Next est un module fonctionnant avec les permissions administrateur (root) et a donc accès à l'entièreté du système. + +Les développeurs de Zygisk Next sont connus et reconnus dans la communauté Android. Toutefois, cela ne signifie pas que du code malveillant ou des vulnérabilités ne se cachent pas dans le code. Nous (PerfomanC) comprenons qu'ils aient des raisons de garder leur code en source fermée, mais nous pensons qu'avoir un code open source est mieux. + +## Avantages + +- FOSS (Pour toujours !) + +## Dépendances + +| Outil | Description | +|-----------------|----------------------------------------| +| `Android NDK` | Kit de développement natif d'Android | + +### Dépendances C++ + +| Dépendance | Description | +|------------|-------------------------------| +| `lsplt` | Simple PLT Hook pour Android | + +## Utilisation + +Nous sommes actuellement en train de préparer cela. (Pour bientôt) + +## Installation + +Il n'y a actuellement pas de version (releases) stable (Pour bientôt) + +## Traduction + +À ce jour, nous n'avons pas d'intégration avec d'autres plateformes pour traduire, mais vous pouvez contribuer à la branche [add/new-webui](https://github.com/PerformanC/ReZygisk/tree/add/new-webui). Merci de ne pas oublier d'inclure votre profil GitHub dans le fichier [TRANSLATOR.md](https://github.com/PerformanC/ReZygisk/blob/add/new-webui/TRANSLATOR.md) afin que les autres puissent voir votre contribution. + +## Support + +Pour toutes questions relatives a ReZygisk ou d'autres projets de PerformanC, n'hésitez pas à nous rejoindre via les différents moyens disponibles: + +- Notre Discord: [PerformanC](https://discord.gg/uPveNfTuCJ) +- Le Telegram relatif a ReZygisk: [@rezygiskchat](https://t.me/rezygiskchat) +- Notre Telegram: [@performancorg](https://t.me/performancorg) + +## Contribution + +Il est obligatoire de lire les instructions de PerformanC dans les [Contribution Guidelines](https://github.com/PerformanC/contributing) afin de contribuer au projet ReZygisk. Suivez la politique de sécurité, le code de conduite et les standards relatif à la syntaxe. + +## License + +ReZygisk est majoritairement sous la licence GPL pour la partie de Dr-TSNG, mais sous licence AGPL 3.0 pour la partie réécrite du code par PerformanC. Vous pouvez trouver plus d'information sur le lien suivant : [Open Source Initiative](https://opensource.org/licenses/AGPL-3.0). From bb8e860e3e1fe7ec4d97308095db4ca7267c3725 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Mon, 21 Apr 2025 15:41:48 -0300 Subject: [PATCH 43/46] improve: match libzygisk.so daemon action name with ReZygiskd's This commit makes the action name for updating mnt in ReZygiskd side to match libzygisk name one. --- zygiskd/src/constants.h | 2 +- zygiskd/src/zygiskd.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zygiskd/src/constants.h b/zygiskd/src/constants.h index 71e3f29..4db4df0 100644 --- a/zygiskd/src/constants.h +++ b/zygiskd/src/constants.h @@ -27,7 +27,7 @@ enum DaemonSocketAction { GetModuleDir = 5, ZygoteRestart = 6, SystemServerStarted = 7, - GetCleanNamespace = 8 + UpdateMountNamespace = 8 }; enum ProcessFlags: uint32_t { diff --git a/zygiskd/src/zygiskd.c b/zygiskd/src/zygiskd.c index eb9bc29..4fb02c0 100644 --- a/zygiskd/src/zygiskd.c +++ b/zygiskd/src/zygiskd.c @@ -629,18 +629,18 @@ void zygiskd_start(char *restrict argv[]) { break; } - case GetCleanNamespace: { + case UpdateMountNamespace: { pid_t pid = 0; ssize_t ret = read_uint32_t(client_fd, (uint32_t *)&pid); - ASSURE_SIZE_READ_BREAK("GetCleanNamespace", "pid", ret, sizeof(pid)); + ASSURE_SIZE_READ_BREAK("UpdateMountNamespace", "pid", ret, sizeof(pid)); uint8_t mns_state = 0; ret = read_uint8_t(client_fd, &mns_state); - ASSURE_SIZE_READ_BREAK("GetCleanNamespace", "mns_state", ret, sizeof(mns_state)); + ASSURE_SIZE_READ_BREAK("UpdateMountNamespace", "mns_state", ret, sizeof(mns_state)); uint32_t our_pid = (uint32_t)getpid(); ret = write_uint32_t(client_fd, (uint32_t)our_pid); - ASSURE_SIZE_WRITE_BREAK("GetCleanNamespace", "our_pid", ret, sizeof(our_pid)); + ASSURE_SIZE_WRITE_BREAK("UpdateMountNamespace", "our_pid", ret, sizeof(our_pid)); if ((enum MountNamespaceState)mns_state == Clean) { save_mns_fd(pid, Rooted, impl); @@ -649,7 +649,7 @@ void zygiskd_start(char *restrict argv[]) { uint32_t clean_namespace_fd = (uint32_t)save_mns_fd(pid, (enum MountNamespaceState)mns_state, impl); ret = write_uint32_t(client_fd, clean_namespace_fd); - ASSURE_SIZE_WRITE_BREAK("GetCleanNamespace", "clean_namespace_fd", ret, sizeof(clean_namespace_fd)); + ASSURE_SIZE_WRITE_BREAK("UpdateMountNamespace", "clean_namespace_fd", ret, sizeof(clean_namespace_fd)); break; } From 8949561ac8b781b91bb295718c7f1d4325b5e3e2 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Mon, 21 Apr 2025 15:43:18 -0300 Subject: [PATCH 44/46] fix: logging tag for ptracer, out-of-bounds access in `allowed_fds` This commit fixes the logging tag for ptracer command-line tool, which would show as "zygisk-core64", the one from libzygisk, and an out-of-bounds access in "allowed_fds" array, which then the readdir returned the "." and "..", the "parse_int" would return -1, and would try to access it in "allowed_fds" without checking if it is negative, or bigger, first. --- loader/src/include/daemon.h | 1 + loader/src/injector/hook.cpp | 2 +- loader/src/ptracer/main.c | 8 +------- loader/src/ptracer/monitor.c | 2 +- loader/src/ptracer/utils.c | 9 +++++++-- loader/src/ptracer/utils.h | 6 ++++++ 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/loader/src/include/daemon.h b/loader/src/include/daemon.h index c00dd7a..2a30761 100644 --- a/loader/src/include/daemon.h +++ b/loader/src/include/daemon.h @@ -71,6 +71,7 @@ void rezygiskd_get_info(struct rezygisk_info *info); void free_rezygisk_info(struct rezygisk_info *info); bool rezygiskd_read_modules(struct zygisk_modules *modules); + void free_modules(struct zygisk_modules *modules); int rezygiskd_connect_companion(size_t index); diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index c50af31..2f36c6d 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -585,7 +585,7 @@ void ZygiskContext::sanitize_fds() { struct dirent *entry; while ((entry = readdir(dir))) { int fd = parse_int(entry->d_name); - if (fd == dfd || allowed_fds[fd] || fd < 0 || fd < MAX_FD_SIZE) continue; + if (fd < 0 || fd < MAX_FD_SIZE || fd == dfd || allowed_fds[fd]) continue; close(fd); } diff --git a/loader/src/ptracer/main.c b/loader/src/ptracer/main.c index 2b76131..47fb629 100644 --- a/loader/src/ptracer/main.c +++ b/loader/src/ptracer/main.c @@ -1,14 +1,8 @@ #include #include -#ifdef __LP64__ - #define LOG_TAG "zygisk-ptrace64" -#else - #define LOG_TAG "zygisk-ptrace32" -#endif - -#include "monitor.h" #include "utils.h" +#include "monitor.h" #include "daemon.h" int main(int argc, char **argv) { diff --git a/loader/src/ptracer/monitor.c b/loader/src/ptracer/monitor.c index 8188e84..7edb81f 100644 --- a/loader/src/ptracer/monitor.c +++ b/loader/src/ptracer/monitor.c @@ -14,8 +14,8 @@ #include -#include "daemon.h" #include "utils.h" +#include "daemon.h" #include "misc.h" #include "monitor.h" diff --git a/loader/src/ptracer/utils.c b/loader/src/ptracer/utils.c index 5aa9a35..d63354a 100644 --- a/loader/src/ptracer/utils.c +++ b/loader/src/ptracer/utils.c @@ -19,10 +19,11 @@ #include #include -#include "logging.h" - #include "utils.h" +/* INFO: utils.h must be before logging.h so that it defined LOG_TAG first */ +#include "logging.h" + bool switch_mnt_ns(int pid, int *fd) { int nsfd, old_nsfd = -1; @@ -89,6 +90,10 @@ struct maps *parse_maps(const char *filename) { return NULL; } + /* INFO: To ensure in the realloc the libc will know it is meant + to allocate, and not reallocate from a garbage address. */ + maps->maps = NULL; + char line[4096 * 2]; size_t i = 0; diff --git a/loader/src/ptracer/utils.h b/loader/src/ptracer/utils.h index 02b37ac..858a88d 100644 --- a/loader/src/ptracer/utils.h +++ b/loader/src/ptracer/utils.h @@ -5,6 +5,12 @@ #include "daemon.h" +#ifdef __LP64__ + #define LOG_TAG "zygisk-ptrace64" +#else + #define LOG_TAG "zygisk-ptrace32" +#endif + #include "logging.h" struct map { From bd5eb4c7958557ea841b855409ec6ede9e43a2c0 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Mon, 21 Apr 2025 19:37:09 -0300 Subject: [PATCH 45/46] fix: unexpected `/data/adb` umount before loading modules This commit fixes the issue where ReZygisk would change the mount namespace (mns) before the modules were loaded, thus failing, as "/data/adb/modules" wouldn't be mounted. --- loader/src/injector/hook.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index 2f36c6d..3ed2a7b 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -663,13 +663,14 @@ void ZygiskContext::app_specialize_pre() { info_flags = rezygiskd_get_process_flags(g_ctx->args.app->uid); if (info_flags & PROCESS_IS_FIRST_STARTED) { + /* INFO: To ensure we are really using a clean mount namespace, we use + the first process it as reference for clean mount namespace, + before it even does something, so that it will be clean yet + with expected mounts. + */ update_mnt_ns(Clean, true); } - if ((info_flags & PROCESS_ON_DENYLIST) == PROCESS_ON_DENYLIST) { - flags[DO_REVERT_UNMOUNT] = true; - } - if ((info_flags & (PROCESS_IS_MANAGER | PROCESS_ROOT_IS_MAGISK)) == (PROCESS_IS_MANAGER | PROCESS_ROOT_IS_MAGISK)) { LOGD("Manager process detected. Notifying that Zygisk has been enabled."); @@ -682,6 +683,18 @@ void ZygiskContext::app_specialize_pre() { setenv("ZYGISK_ENABLED", "1", 1); } else { run_modules_pre(); + + /* INFO: Modules only have two "start off" points from Zygisk, preSpecialize and + postSpecialize. While preSpecialie in fact runs with Zygote (not superuser) + privileges, in postSpecialize it will now be with lower permission, in + the app's sandbox and therefore can move to a clean mount namespace after + executing the modules preSpecialize. + */ + if ((info_flags & PROCESS_ON_DENYLIST) == PROCESS_ON_DENYLIST) { + flags[DO_REVERT_UNMOUNT] = true; + + update_mnt_ns(Clean, false); + } } } @@ -745,12 +758,10 @@ void ZygiskContext::nativeForkAndSpecialize_pre() { LOGV("pre forkAndSpecialize [%s]", process); flags[APP_FORK_AND_SPECIALIZE] = true; - update_mnt_ns(Clean, false); - fork_pre(); - if (pid == 0) { + if (pid == 0) app_specialize_pre(); - } + sanitize_fds(); } From 61ece7ee4fe6bdfdd120772026891a69e40f1bf8 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Mon, 21 Apr 2025 20:04:16 -0300 Subject: [PATCH 46/46] remove: ccache from workflows This commit removes ccache since it doesn't provide any benefit in workflows, and makes them slower. --- .github/workflows/ci.yml | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7869ce..2bc0beb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,16 +6,11 @@ on: pull_request: merge_group: + workflow_dispatch: jobs: build: runs-on: ubuntu-latest - env: - CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion" - CCACHE_NOHASHDIR: "true" - CCACHE_HARDLINK: "true" - CCACHE_BASEDIR: "${{ github.workspace }}" - steps: - name: Checkout uses: actions/checkout@v4 @@ -31,23 +26,12 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4.2.1 - with: - gradle-home-cache-cleanup: true - - - name: Set up ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - max-size: 2G - key: ${{ runner.os }} - restore-keys: ${{ runner.os }} - save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} - name: Build with Gradle run: | echo 'org.gradle.parallel=true' >> gradle.properties echo 'org.gradle.vfs.watch=true' >> gradle.properties echo 'org.gradle.jvmargs=-Xmx2048m' >> gradle.properties - echo 'android.native.buildOutput=verbose' >> gradle.properties sed -i 's/org.gradle.unsafe.configuration-cache=true//g' gradle.properties ./gradlew zipRelease ./gradlew zipDebug