mirror of
https://github.com/kdrag0n/safetynet-fix.git
synced 2024-10-04 13:49:51 +00:00
riru: Import Riru module template
commit 7d4155e4463eeadfe83a9475d69bca3de9000bcd Author: RikkaW <rikka@shizuku.moe> Date: Mon Jul 19 09:27:29 2021 +0800 Fix push task commit e76aa44cfb7c48ba6b875423d4cd6e175afd190c Author: RikkaW <rikka@shizuku.moe> Date: Mon Jul 19 00:06:20 2021 +0800 Update README commit 8fc3c0675e206380214b400f325f48c87bc2cd2c Author: RikkaW <rikka@shizuku.moe> Date: Sun Jul 18 17:14:18 2021 +0800 Changes for Riru v26 commit 8cf6eec5282c286c5b517bca6d102ba068617c95 Author: RikkaW <rikka@shizuku.moe> Date: Sat Jul 17 12:14:17 2021 +0800 Remove more pre-24 support commit 254ebfe8a7420aeb83e462cf4a4eb8aefd344bcf Author: RikkaW <rikka@shizuku.moe> Date: Sat Jul 17 11:28:31 2021 +0800 Add GitHub Actions commit a4840a9f53b6187789e8fdcd07379d1dff86db61 Author: RikkaW <rikka@shizuku.moe> Date: Sat Jul 17 11:24:14 2021 +0800 Strip .comment section commit 9faec484a8c3d516dd92d8d52c06c09033675a94 Author: RikkaW <rikka@shizuku.moe> Date: Sat Jul 17 11:21:34 2021 +0800 Use CMake configure_file commit 944fe620911af2c6dd5ec98a4a4c36ed3339627e Author: RikkaW <rikka@shizuku.moe> Date: Sat Jul 17 11:12:36 2021 +0800 Remove pre-24 support since next major version of Riru will do this as well commit af0c7759c2a2ab6d01b7e19ed7159dc7afdd8b1e Author: RikkaW <rikka@shizuku.moe> Date: Sat Jul 17 11:02:40 2021 +0800 Cleanup gradle codes commit e2a4ddabcd7ece769205c85c0c9f2e0017d0eb9a Author: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Sat Jul 17 11:02:20 2021 +0800 Update update-binary & Fix typo (#10) * Update update-binary * Fix typo commit 3d3f92a4f561433cf2dc8f7188d1f6618e195b83 Author: RikkaW <rikka@shizuku.moe> Date: Fri May 21 18:42:05 2021 +0800 Refuse to install if Riru is disabled or will be removed commit f7e2af8cdf7b864e0cf47be727c466c4bef5c214 Author: RikkaW <rikka@shizuku.moe> Date: Fri May 21 18:22:20 2021 +0800 Fix check Riru commit 36b82ca3b5ee4b975a755b27461f634d933b73b6 Author: Rikka <rikka@shizuku.moe> Date: Fri Apr 16 13:00:06 2021 +0800 Fix typo commit 73c7588f75c9566bd43ebb830e5be4b7ef062bc5 Author: RikkaW <rikka@shizuku.moe> Date: Fri Apr 2 17:28:37 2021 +0800 Add note for module id commit a701bc9c2c7a2c2a220aa4a6cec2474011387882 Author: RikkaW <rikka@shizuku.moe> Date: Tue Mar 30 11:49:25 2021 +0800 Add empty new line to scripts commit ce576cc23ab16ad22182b7fb708407f9712e758f Author: RikkaW <rikka@shizuku.moe> Date: Mon Mar 29 20:40:26 2021 +0800 Update CMakeLists.txt commit b4b1ec5b3231cef7a0a46b93f10a9aa4c6195eac Author: RikkaW <rikka@shizuku.moe> Date: Mon Mar 29 11:41:41 2021 +0800 Change "equals to Release" to "not equals to Debug" since the latest canary AGP has different build type commit c6cacf4c13184fb8539ce4b52751373ed7f09687 Author: RikkaW <rikka@shizuku.moe> Date: Mon Mar 29 10:47:08 2021 +0800 Update tasks commit 78013af879c1515e681f69b639198f021b7f003e Author: RikkaW <rikka@shizuku.moe> Date: Mon Mar 29 10:37:00 2021 +0800 Don't extract riru.sh to MODPATH commit 1337d948efdae9190eb1fad0f4eb9a2682519a3d Author: RikkaW <rikka@shizuku.moe> Date: Sun Mar 28 13:33:11 2021 +0800 Delete out dir in clean task commit 17cb1eebc7ec734a263a263d9b73ccf64dcfd137 Author: RikkaW <rikka@shizuku.moe> Date: Sun Mar 28 12:39:58 2021 +0800 Update template commit 6cb995e9f8607eaf695d0fb468a2b46355c5686c Author: RikkaW <rikka@shizuku.moe> Date: Mon Mar 22 16:34:21 2021 +0800 Update build.gradle commit 3857b8b599027bfdc2df4c4dd8feb94c4b7e7011 Author: RikkaW <rikka@shizuku.moe> Date: Wed Mar 17 02:51:51 2021 +0800 Update main.cpp commit 49868e17dfcd8d4c292a4b9e35aa96279977952a Author: RikkaW <rikka@shizuku.moe> Date: Wed Mar 17 02:40:36 2021 +0800 Update README commit 00abd3beeeca97b814ca2afb0e78e62d9c2aeca3 Author: RikkaW <rikka@shizuku.moe> Date: Wed Mar 17 02:34:13 2021 +0800 Fix typo commit ce677f7de75fcd9d0a65a7839983c263a04a746f Author: RikkaW <rikka@shizuku.moe> Date: Tue Mar 16 17:56:51 2021 +0800 Changes for Riru v25 commit 443ab95c2333c6a5006a0a520a9a5b29aa10a9e6 Author: RikkaW <rikka@shizuku.moe> Date: Fri Mar 12 00:07:28 2021 +0800 Fix main.cpp commit 551b2e6189476ecffb2cfd6aeda08f5550deb15a Author: RikkaW <rikka@shizuku.moe> Date: Thu Mar 11 22:58:19 2021 +0800 Update riru.sh commit f9794cbe205d3c2b37a423bc723b1922589c26f7 Author: RikkaW <rikka@shizuku.moe> Date: Thu Mar 11 22:55:26 2021 +0800 Use magisk --path commit 90d7adc75a06f70978f24b8341e1e702de978422 Author: RikkaW <rikka@shizuku.moe> Date: Thu Mar 11 18:01:22 2021 +0800 Update README commit 81c1e564f83459bbf0024a52a45e77b5b860055c Author: RikkaW <rikka@shizuku.moe> Date: Thu Mar 11 17:44:28 2021 +0800 Fix typo commit ddd5fbf8db1a30d08a030f7048041a1453828cfc Author: RikkaW <rikka@shizuku.moe> Date: Thu Mar 11 17:44:08 2021 +0800 Update main.cpp commit f9999fd1a234fe8bd099a909dff07d3ba77f511d Author: RikkaW <rikka@shizuku.moe> Date: Thu Mar 11 17:13:49 2021 +0800 Minor changes commit a16bd42029bf61909893cef8d89451c82a827748 Author: RikkaW <rikka@shizuku.moe> Date: Thu Mar 11 03:21:47 2021 +0800 Changes for Riru v24 again commit ed2ee5d3e4238c34fe18774cbd21837756e47270 Author: RikkaW <rikka@shizuku.moe> Date: Wed Mar 10 12:56:46 2021 +0800 Changes for Riru v24 commit faf4fcc3c17d743a8aec303d666a266548c1ee3d Author: RikkaW <rikka@shizuku.moe> Date: Fri Mar 5 15:08:06 2021 +0800 Lib moved to maven central commit 56fdbe82840b3b1c2bbefea89403c5ff838068f7 Author: RikkaW <rikka@shizuku.moe> Date: Thu Mar 4 16:51:25 2021 +0800 Update .gitattributes commit 9ace98fc53fc5aac43d1f0c87a3097658503969f Author: RikkaW <rikka@shizuku.moe> Date: Thu Mar 4 14:15:15 2021 +0800 Change lib path commit cf186db98da1660c6dbebe07b001606e1c0fac77 Author: RikkaW <rikka@shizuku.moe> Date: Sat Feb 27 22:02:19 2021 +0800 Fix check_riru_version commit d96a11f03cfb59cf1c8ed6f5d4156c9f0e23ed1b Author: RikkaW <rikka@shizuku.moe> Date: Tue Feb 23 12:37:49 2021 +0800 Update comment for shouldSkipUid commit fbe327ea4fb94c9b4a9e68dbfada3b84e51ce3dd Author: RikkaW <rikka@shizuku.moe> Date: Tue Feb 23 12:32:41 2021 +0800 Remove "_" commit a4316fab79151f4488a8d50480f73b2a0260004f Author: RikkaW <rikka@shizuku.moe> Date: Tue Feb 23 12:25:03 2021 +0800 Fix typo commit cd03c4561b32b093d22b32ebbd8275f9e2f78799 Author: RikkaW <rikka@shizuku.moe> Date: Sun Jan 3 13:39:45 2021 +0800 Fix install on x86 commit 530e7bc4c2b1fd3da9d94fb884fd2ccfbeb765da Author: RikkaW <rikka@shizuku.moe> Date: Sat Jan 2 15:08:50 2021 +0800 Use /data/adb/riru/util_functions.sh commit 3bdc01c04311eb51ab8520f00b72b8196c0efe55 Author: RikkaW <rikka@xing.moe> Date: Wed Dec 2 21:55:44 2020 +0800 Add comment about prefab 1.1.2 commit a60279ee147f9e24c37df5da53ae7db5f33f9201 Author: RikkaW <rikka@xing.moe> Date: Tue Dec 1 17:05:46 2020 +0800 Update README commit cd6669ebe4dc7d9ca92562ede48cfeb066132d70 Author: RikkaW <rikka@xing.moe> Date: Tue Dec 1 16:44:02 2020 +0800 Update README commit d3f00eab36d1076b2cdd217a08c16a9931bea542 Author: RikkaW <rikka@xing.moe> Date: Tue Dec 1 16:39:36 2020 +0800 Update exmaple commit 853279e9bf47a0e98fbe5f21998fc8c98cf1a738 Author: RikkaW <rikka@xing.moe> Date: Tue Dec 1 15:51:24 2020 +0800 Update for readdir through rirud commit a73dde129b303074bc834b26e6f313348c6a32af Author: RikkaW <rikka@xing.moe> Date: Mon Nov 30 15:48:54 2020 +0800 Update README commit 0587881cfe3b3426b7e1ecfc27c71c8bce3806c5 Author: RikkaW <rikka@xing.moe> Date: Mon Nov 30 15:47:45 2020 +0800 Update riru.h location commit 8a485e19e37358523ae7e97e0869cfc7c41a4f0b Author: RikkaW <rikka@xing.moe> Date: Mon Nov 30 15:41:31 2020 +0800 Update for API v10 commit 1561b5c6a9ba84504b0966a90c2c2a5d1c2d03c7 Author: RikkaW <rikka@xing.moe> Date: Sun Nov 15 15:54:51 2020 +0800 Update module.example.gradle commit 4c9579c3a90c31e092ade77fe54e438688ad1222 Author: RikkaW <rikka@xing.moe> Date: Sat Nov 14 21:04:23 2020 +0800 Update AGP to 4.1.1 commit 7e3ee55957680ab75b0b5c3af2fa42b582665ffe Author: RikkaW <rikka@xing.moe> Date: Sat Nov 14 21:04:03 2020 +0800 Min SDK version should be 23 commit 6f11ef88befeca5ca61b3e36bbd3e0d64be91e3e Author: RikkaW <rikka@xing.moe> Date: Sat Nov 14 14:32:58 2020 +0800 Change check riru version text commit 8f72889ffb9eff6ea30ca576446f0a30d4cd7505 Author: RikkaW <rikka@xing.moe> Date: Wed Oct 28 16:54:19 2020 +0800 Use u:object_r:magisk_file:s0 commit 899dbabe978dfa5a45a375e868514191c2893eb3 Author: RikkaW <rikka@xing.moe> Date: Sat Oct 24 22:05:53 2020 +0800 Update README commit 4e0ffdfe04cb23f89e6117ac690395c00fae1fcf Author: RikkaW <rikka@xing.moe> Date: Sat Oct 24 18:57:03 2020 +0800 Update README commit 36b254fd5c409b4d137f3dddd0b5875df94363bf Author: RikkaW <rikka@xing.moe> Date: Sat Oct 24 18:39:31 2020 +0800 Update README commit 7858d6d543073c5db66136aa3480a661a64ea9b7 Author: RikkaW <rikka@xing.moe> Date: Sat Oct 24 17:18:53 2020 +0800 use stable version AGP commit 18fed7b26067ab76017ed900f47438ffbeb47264 Author: Rikka <rikka@xing.moe> Date: Sat Oct 24 14:45:18 2020 +0800 Add LICENSE commit 52d4966bea7dea293559f72dd6d85af391fe32a8 Author: RikkaW <rikka@xing.moe> Date: Tue Oct 13 14:21:34 2020 +0800 update dependency commit 69d0e07f7f5e2ab9d6af680cfe7da87f80f910cd Author: RikkaW <rikka@xing.moe> Date: Sun Oct 11 22:15:18 2020 +0800 add missing supportHide commit 4e108b0d0fe52e6460cb235bd18b141b5cb41af4 Author: RikkaW <rikka@xing.moe> Date: Sun Oct 11 22:14:48 2020 +0800 add missing version/versionName commit 4a98de054a9a3b54550562be7c3e2d443d514567 Author: RikkaW <rikka@xing.moe> Date: Sun Oct 11 21:55:48 2020 +0800 pass api version from gradle commit b0143d1e7ab9a80a60671e69f7bd78056b4ba536 Author: RikkaW <rikka@xing.moe> Date: Sun Oct 11 20:56:28 2020 +0800 update for api 9 commit bc19061bb0b205ec879e75cb4286e98b8a622bd2 Author: RikkaW <rikka@xing.moe> Date: Fri Oct 9 23:26:16 2020 +0800 update AGP to make prefab happy commit 890f50f643b607ede1303dc54057fe2d0639519a Author: RikkaW <rikka@xing.moe> Date: Fri Oct 9 23:21:53 2020 +0800 update for api 8 commit 044de559aac06fb312ea52c6625fda62f03f7c87 Author: RikkaW <rikka@shizuku.moe> Date: Mon May 11 12:59:04 2020 +0800 remove "abort_clean" commit 1efe42f60aab6536a8d85ebc272dd4ad34f299e2 Author: RikkaW <rikka@shizuku.moe> Date: Sat May 9 11:05:31 2020 +0800 update for api 7 commit 155d2ed8af52838da9153df7b375059393b3e153 Author: RikkaW <rikka@shizuku.moe> Date: Fri Apr 24 14:02:35 2020 +0800 show required Riru version name commit 989b733ff52b5f052f33bbdafe1eb1543aff3a4a Author: RikkaW <rikka@shizuku.moe> Date: Fri Apr 24 13:29:46 2020 +0800 update for api 6 commit 65afd5a278c93b3828c48984092ed6ffa1d82202 Author: RikkaW <rikka@shizuku.moe> Date: Sun Apr 19 16:27:09 2020 +0800 update for api 5 commit a1c359f2ac374c74a2be63e36aa8351972838ae0 Author: RikkaW <rikka@shizuku.moe> Date: Wed Mar 18 16:35:03 2020 +0800 move module info to a stand-alone file fix #3 commit d768c52ec0740ad423508447fc5ddb1afab84e5b Author: RikkaW <rikka@shizuku.moe> Date: Fri Feb 28 01:17:47 2020 +0800 allow installed after new installation of Riru fix RikkaApps/Riru#86 commit 77bc46c73b130b42da24c498e44080b54e185fa5 Author: RikkaW <rikka@shizuku.moe> Date: Wed Feb 26 16:44:55 2020 +0800 update installation scripts commit 322576c630974fadbf73cc7e95fe7e0ce405534b Author: RikkaW <rikka@shizuku.moe> Date: Mon Feb 24 18:44:50 2020 +0800 fix bug commit 4638ccd2434e412a633ceae1c57289e1820074a5 Author: RikkaW <rikka@shizuku.moe> Date: Wed Feb 5 23:40:05 2020 +0800 fix #2 commit 85a565c0788339b393da347847eb6896e7b4f5bc Author: RikkaW <rikka@shizuku.moe> Date: Wed Feb 5 20:02:01 2020 +0800 no longer requires to modify the name "template" everywhere commit a2ae8d3f1a76c2aa7a3ecbedee51e3e8d9cdac9a Author: RikkaW <rikka@shizuku.moe> Date: Sat Jan 25 22:07:52 2020 +0800 update installation scripts commit 9729cd9b48e6d2d1940a340eaddec7bc0373c152 Author: RikkaW <rikka@shizuku.moe> Date: Sat Jan 25 00:30:00 2020 +0800 fix .gitattributes commit 1cb568d8d0f00fa580a325e1b9e9b4fdbd2f8538 Author: RikkaW <rikka@shizuku.moe> Date: Tue Jan 21 22:38:24 2020 +0800 format changes commit 9f362b94c17423c63ef373bceac635fb05085c08 Author: RikkaW <rikka@shizuku.moe> Date: Tue Jan 21 22:36:38 2020 +0800 format changes commit 09478e75cde4a0fe5af44495e5a530abfaa0ced6 Author: RikkaW <rikka@shizuku.moe> Date: Tue Jan 21 22:36:32 2020 +0800 fix bug commit 4e543b9e13bf8980f308410a3a2d533722ca6f94 Author: RikkaW <rikka@shizuku.moe> Date: Sun Jan 19 12:52:46 2020 +0800 add missing settings.gradle close #1 commit 96eb129abe88b940a9c9e3a774023729673da788 Author: RikkaW <rikka@shizuku.moe> Date: Fri Jan 10 17:17:46 2020 +0800 remove zip verification commit 4072c60339b56865a59a72e33acf497d52a5824a Author: RikkaW <rikka@shizuku.moe> Date: Wed Jan 8 15:37:07 2020 +0800 add missing uninstall.sh commit d99fd3a4413b0de2029a7a2b0e34c7563094613e Author: RikkaW <rikka@shizuku.moe> Date: Wed Jan 8 00:24:07 2020 +0800 initial commit
This commit is contained in:
parent
0b67454acf
commit
1282960dbf
4
riru/.gitattributes
vendored
Normal file
4
riru/.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
* text=auto eol=lf
|
||||
|
||||
*.bat text eol=crlf
|
||||
*.jar binary
|
15
riru/.gitignore
vendored
Normal file
15
riru/.gitignore
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
.idea
|
||||
/.idea/caches/build_file_checksums.ser
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
/out
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
module.gradle
|
21
riru/LICENSE
Normal file
21
riru/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Rikka
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
141
riru/README.md
Normal file
141
riru/README.md
Normal file
@ -0,0 +1,141 @@
|
||||
# Riru - Template
|
||||
|
||||
[Riru](https://github.com/RikkaApps/Riru) module template.
|
||||
|
||||
## Build
|
||||
|
||||
1. Rename `module.example.gradle` to `module.gradle`
|
||||
2. Replace module info in `module.gradle` (all lines end with "replace with yours")
|
||||
3. Write your codes
|
||||
4. Run gradle task `:module:assembleRelease` task from Android Studio or command line, zip will be saved in `out`.
|
||||
|
||||
## File structure
|
||||
|
||||
A Riru module is a Magisk module, please read [Magisk module document](https://topjohnwu.github.io/Magisk/guides.html#magisk-modules) first.
|
||||
|
||||
If the folder `$MODPATH/riru` exists, the module is considered as a Riru module. All files in `$MODPATH/riru/lib(64)` will be loaded by Riru.
|
||||
|
||||
## API changes
|
||||
|
||||
### API 26 (Riru v26)
|
||||
|
||||
- Remove the support of pre-24 modules
|
||||
- `/data/adb/dev_random` is planned to be moved to another place in the next major version
|
||||
- Libraries in `/dev` do not have stacktrace, developers have to put so file into `/system`, Riru v26 makes this simpler
|
||||
|
||||
Create an empty file, `libxxx` (no `.so` suffix), at `$MODPATH/riru/lib(64)`, Riru will try to load `/system/lib(64)/libxxx.so`
|
||||
|
||||
### API 25 (Riru v25)
|
||||
|
||||
- Modules can be unloaded (see `main.cpp`)
|
||||
- `shouldSkipUid` is removed for API 25 modules
|
||||
|
||||
### API 24 (Riru v24)
|
||||
|
||||
- The Riru API version is unified with Riru version, now the API version is 24
|
||||
- The `/data/adb/riru/modules/<name>` folder is deprecated, modules only need to place library files in `$MODPATH/riru/lib(64)` (see `customize.sh` `post-fs-data.sh`)
|
||||
- The `init` function is called only once (see `main.cpp`)
|
||||
- It's recommended to place modules files in the Magisk module folder, zygote has permission read this folder directly (the path is passed through `init` function, see `main.cpp`)
|
||||
|
||||
### API 10 (Riru v23)
|
||||
|
||||
<details>
|
||||
<summary><b>Background of rirud:</b></summary>
|
||||
|
||||
Riru v22.0 move config files to `/data/adb`, this makes patch SELinux rules a must. However Magisk's `sepolicy.rule` actually not work for maybe lots of devices. As the release of Riru v22.0, these people "suddenly" appears.
|
||||
|
||||
`sepolicy.rule` support was added from Magisk v20.2, a long time ago, no one report to Magisk 😒.
|
||||
|
||||
To workaround this "problem", "rirud" is introduced. It will be started by `post-fs-data.sh` and run a socket runs under `u:r:zygote:s0` context. All file operations can be done through this socket.
|
||||
</details>
|
||||
|
||||
|
||||
From Riru v23, "read file" and "read dir" function are added for "rirud". Modules can use this to read files that zygote itself has not permission to access. Note, for hide purpose, "rirud" socket is only available before system_server is started.
|
||||
|
||||
In order to give the module enough freedom (like how to allocate memory), there is no "API". The module needs to implement socket codes by itself.
|
||||
|
||||
<details>
|
||||
|
||||
<summary><b>Pseudocode of read file:</b></summary>
|
||||
|
||||
```
|
||||
socket(PF_UNIX, SOCK_STREAM)
|
||||
setup_sockaddr("rirud")
|
||||
|
||||
write(ACTION_READ_FILE /* 4 */, sizeof(uint32))
|
||||
write(path_size, sizeof(uint32))
|
||||
write(path, path_size)
|
||||
|
||||
errno = read(sizeof(int32_t)) // errno of "open" in "rirud"
|
||||
if (errno != 0) return
|
||||
|
||||
bytes_count = read(sizeof(int32_t))
|
||||
|
||||
if (bytes_count > 0) {
|
||||
// file has size
|
||||
// read total "bytes_count" bytes
|
||||
} else if (bytes_count == 0) {
|
||||
// file has no size, read until 0
|
||||
// read until 0
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary><b>Pseudocode of read dir:</b></summary>
|
||||
|
||||
```
|
||||
socket(PF_UNIX, SOCK_STREAM)
|
||||
setup_sockaddr("rirud")
|
||||
|
||||
write(ACTION_READ_DIR /* 5 */, sizeof(uint32))
|
||||
write(path_size, sizeof(uint32))
|
||||
write(path, path_size)
|
||||
|
||||
errno = read(sizeof(int32_t)) // errno of "opendir" in "rirud"
|
||||
if (errno != 0) return
|
||||
|
||||
while (true) {
|
||||
write(1 /* continue */, sizeof(uint8))
|
||||
|
||||
reply = read(sizeof(int32))
|
||||
if (reply == -1) break // end
|
||||
if (reply != 0) continue // reply is errno of "readdir" in "rirud"
|
||||
|
||||
d_type = read(sizeof(uchar))
|
||||
d_name = read(256)
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
Example implementation: <https://github.com/RikkaApps/Riru-LocationReportEnabler/commit/89b2e396efcd928121ba3d254b96af1560cfaf4d>
|
||||
|
||||
### API 9 (Riru v22)
|
||||
|
||||
#### API
|
||||
|
||||
Functions like `nativeForkAnd...` do not need to be exported directly. The only function to export is `void *init(void *)`. See the comment of `init` and template's implementation for more.
|
||||
|
||||
This has these advantages:
|
||||
|
||||
* Module can support different Riru versions
|
||||
* Riru itself will not relay on ".prop" file (unreliable) to get module information
|
||||
|
||||
#### Riru
|
||||
|
||||
Starting v22.0, Riru has switched to "native bridge" (`ro.dalvik.vm.native.bridge`) to inject zygote, this will lead Riru and modules be loaded later ([`LoadNativeBridge`](https://cs.android.com/android/platform/superproject/+/android-11.0.0_r1:art/libnativebridge/native_bridge.cc;l=227) vs `__attribute__((constructor))`).
|
||||
|
||||
For most modules, this should have no problem, but modules like Xposed frameworks may have to make changes.
|
||||
|
||||
> Magisk may provider Riru-like features in the far future, and of course, it will have more strict restrictions, module codes will not be run in zygote. Maybe Xposed framework modules should prepare for this?
|
||||
|
||||
Riru v22 also provides hide function to make the memory of the module to anonymous memory ([see the implementation](https://github.com/RikkaApps/Riru/blob/master/core/src/main/cpp/hide.cpp)). This is an opt-in behavior (`module->supportHide`) and Riru itself also has a global toggle (`/data/adb/riru/enable_hide`).
|
||||
|
||||
#### Module installer
|
||||
|
||||
`RIRU_PATH` has been changed to `/data/adb/riru` for hide purpose. If you have other files in `/data/misc/riru`, move them here (or anywhere else if you want).
|
||||
|
||||
Note `/data/adb/riru` have the same SELinux like other Magisk files (set by Riru in post-fs-data), `u:object_r:magisk_file:s0`. DO NOT reset the context to something else.
|
35
riru/build.gradle
Normal file
35
riru/build.gradle
Normal file
@ -0,0 +1,35 @@
|
||||
apply plugin: 'idea'
|
||||
|
||||
idea.module {
|
||||
excludeDirs += file('out')
|
||||
resourceDirs += file('template')
|
||||
resourceDirs += file('scripts')
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.2.2'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
}
|
||||
|
||||
ext {
|
||||
minSdkVersion = 23
|
||||
targetSdkVersion = 30
|
||||
|
||||
outDir = file("$rootDir/out")
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir, outDir
|
||||
}
|
22
riru/gradle.properties
Normal file
22
riru/gradle.properties
Normal file
@ -0,0 +1,22 @@
|
||||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app's APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Automatically convert third-party libraries to use AndroidX
|
||||
android.enableJetifier=true
|
||||
# https://github.com/google/prefab/issues/122
|
||||
# Remove this until AGP update prefab version
|
||||
android.prefabVersion=1.1.3
|
BIN
riru/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
riru/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
riru/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
riru/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#Mon Jul 12 21:05:17 CST 2021
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
172
riru/gradlew
vendored
Executable file
172
riru/gradlew
vendored
Executable file
@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# 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
|
||||
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=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 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
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
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"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
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.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
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, switch paths to Windows format before running java
|
||||
if $cygwin ; 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=$((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" ;;
|
||||
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, 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"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
84
riru/gradlew.bat
vendored
Normal file
84
riru/gradlew.bat
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
@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 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=
|
||||
|
||||
@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 init
|
||||
|
||||
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 init
|
||||
|
||||
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
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
: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 %CMD_LINE_ARGS%
|
||||
|
||||
: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
|
30
riru/module.example.gradle
Normal file
30
riru/module.example.gradle
Normal file
@ -0,0 +1,30 @@
|
||||
ext {
|
||||
/*
|
||||
This name will be used in the name of the so file ("lib${moduleLibraryName}.so").
|
||||
*/
|
||||
moduleLibraryName = "template"
|
||||
|
||||
/* Minimal supported Riru API version, used in the version check of riru.sh */
|
||||
moduleMinRiruApiVersion = 24
|
||||
|
||||
/* The version name of minimal supported Riru, used in the version check of riru.sh */
|
||||
moduleMinRiruVersionName = "v24.0.0"
|
||||
|
||||
/* Maximum supported Riru API version, used in the version check of riru.sh */
|
||||
moduleRiruApiVersion = 26
|
||||
|
||||
/*
|
||||
Magisk module ID
|
||||
Since Magisk use it to distinguish different modules, you should never change it.
|
||||
|
||||
Note, the older version of the template uses '-' instead of '_', if your are upgrading from
|
||||
the older version, please pay attention.
|
||||
*/
|
||||
magiskModuleId = "riru_template"
|
||||
|
||||
moduleName = "Template"
|
||||
moduleAuthor = "Template"
|
||||
moduleDescription = "Riru module template. Requires Riru $moduleMinRiruVersionName or above."
|
||||
moduleVersion = "v26.0.0"
|
||||
moduleVersionCode = 26
|
||||
}
|
3
riru/module/.gitignore
vendored
Normal file
3
riru/module/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/.externalNativeBuild
|
||||
/build
|
||||
/release
|
136
riru/module/build.gradle
Normal file
136
riru/module/build.gradle
Normal file
@ -0,0 +1,136 @@
|
||||
import org.apache.tools.ant.filters.FixCrLfFilter
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
import java.security.MessageDigest
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply from: file(rootProject.file('module.gradle'))
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.targetSdkVersion
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments "-DMODULE_NAME:STRING=$moduleLibraryName",
|
||||
"-DRIRU_MODULE_API_VERSION=$moduleRiruApiVersion",
|
||||
"-DRIRU_MODULE_VERSION=$moduleVersionCode",
|
||||
"-DRIRU_MODULE_VERSION_NAME:STRING=$moduleVersion",
|
||||
"-DRIRU_MODULE_MIN_API_VERSION=$moduleMinRiruApiVersion"
|
||||
}
|
||||
}
|
||||
}
|
||||
buildFeatures {
|
||||
prefab true
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/cpp/CMakeLists.txt"
|
||||
version "3.10.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// This is prefab aar which contains "riru.h"
|
||||
// If you want to use older versions of AGP,
|
||||
// you can copy this file from https://github.com/RikkaApps/Riru/blob/master/riru/src/main/cpp/include_riru/riru.h
|
||||
|
||||
// The default version of prefab in AGP has problem to process header only package,
|
||||
// you may have to add "android.prefabVersion" in your gradle.properties.
|
||||
// See https://github.com/google/prefab/issues/122
|
||||
|
||||
implementation 'dev.rikka.ndk:riru:26.0.0'
|
||||
}
|
||||
|
||||
|
||||
afterEvaluate {
|
||||
android.libraryVariants.forEach { variant ->
|
||||
def variantCapped = variant.name.capitalize()
|
||||
def variantLowered = variant.name.toLowerCase()
|
||||
|
||||
def zipName = "${magiskModuleId.replace('_', '-')}-${moduleVersion}-${variantLowered}.zip"
|
||||
def magiskDir = file("$outDir/magisk_module_$variantLowered")
|
||||
|
||||
task("prepareMagiskFiles${variantCapped}", type: Sync) {
|
||||
dependsOn("assemble$variantCapped")
|
||||
|
||||
def templatePath = "$rootDir/template/magisk_module"
|
||||
|
||||
into magiskDir
|
||||
from(templatePath) {
|
||||
exclude 'riru.sh', 'module.prop'
|
||||
}
|
||||
from(templatePath) {
|
||||
include 'riru.sh'
|
||||
filter(ReplaceTokens.class, tokens: [
|
||||
"RIRU_MODULE_LIB_NAME" : moduleLibraryName,
|
||||
"RIRU_MODULE_API_VERSION" : moduleRiruApiVersion.toString(),
|
||||
"RIRU_MODULE_MIN_API_VERSION" : moduleMinRiruApiVersion.toString(),
|
||||
"RIRU_MODULE_MIN_RIRU_VERSION_NAME": moduleMinRiruVersionName,
|
||||
])
|
||||
filter(FixCrLfFilter.class,
|
||||
eol: FixCrLfFilter.CrLf.newInstance("lf"))
|
||||
}
|
||||
from(templatePath) {
|
||||
include 'module.prop'
|
||||
expand([
|
||||
id : magiskModuleId,
|
||||
name : moduleName,
|
||||
version : moduleVersion,
|
||||
versionCode: moduleVersionCode.toString(),
|
||||
author : moduleAuthor,
|
||||
description: moduleDescription,
|
||||
])
|
||||
filter(FixCrLfFilter.class,
|
||||
eol: FixCrLfFilter.CrLf.newInstance("lf"))
|
||||
}
|
||||
from("$buildDir/intermediates/stripped_native_libs/$variantLowered/out/lib") {
|
||||
into 'lib'
|
||||
}
|
||||
doLast {
|
||||
fileTree("$magiskDir").visit { f ->
|
||||
if (f.directory) return
|
||||
if (f.file.name == '.gitattributes') return
|
||||
|
||||
def md = MessageDigest.getInstance("SHA-256")
|
||||
f.file.eachByte 4096, { bytes, size ->
|
||||
md.update(bytes, 0, size)
|
||||
}
|
||||
file(f.file.path + ".sha256sum").text = md.digest().encodeHex()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task("zip${variantCapped}", type: Zip) {
|
||||
dependsOn("prepareMagiskFiles${variantCapped}")
|
||||
from magiskDir
|
||||
archiveName zipName
|
||||
destinationDir outDir
|
||||
}
|
||||
|
||||
task("push${variantCapped}", type: Exec) {
|
||||
dependsOn("zip${variantCapped}")
|
||||
workingDir outDir
|
||||
commandLine android.adbExecutable, "push", zipName, "/data/local/tmp/"
|
||||
}
|
||||
|
||||
task("flash${variantCapped}", type: Exec) {
|
||||
dependsOn("push${variantCapped}")
|
||||
commandLine android.adbExecutable, "shell", "su", "-c",
|
||||
"magisk --install-module /data/local/tmp/${zipName}"
|
||||
}
|
||||
|
||||
task("flashAndReboot${variantCapped}", type: Exec) {
|
||||
dependsOn("flash${variantCapped}")
|
||||
commandLine android.adbExecutable, "shell", "reboot"
|
||||
}
|
||||
|
||||
variant.assembleProvider.get().finalizedBy("zip${variantCapped}")
|
||||
}
|
||||
}
|
1
riru/module/src/main/AndroidManifest.xml
Normal file
1
riru/module/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
||||
<manifest package="riru.template" />
|
44
riru/module/src/main/cpp/CMakeLists.txt
Normal file
44
riru/module/src/main/cpp/CMakeLists.txt
Normal file
@ -0,0 +1,44 @@
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
|
||||
if (NOT DEFINED MODULE_NAME)
|
||||
message(FATAL_ERROR "MODULE_NAME is not set")
|
||||
else ()
|
||||
project(${MODULE_NAME})
|
||||
endif ()
|
||||
|
||||
add_definitions(-DRIRU_MODULE)
|
||||
|
||||
configure_file(template/config.cpp config.cpp)
|
||||
|
||||
message("Build type: ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
set(LINKER_FLAGS "-ffixed-x18 -Wl,--hash-style=both")
|
||||
set(C_FLAGS "-Werror=format -fdata-sections -ffunction-sections")
|
||||
set(CXX_FLAGS "${CXX_FLAGS} -fno-exceptions -fno-rtti")
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(C_FLAGS "${C_FLAGS} -O2 -fvisibility=hidden -fvisibility-inlines-hidden")
|
||||
set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,-exclude-libs,ALL -Wl,--gc-sections -Wl,--strip-all")
|
||||
else ()
|
||||
set(C_FLAGS "${C_FLAGS} -O0")
|
||||
endif ()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_FLAGS} ${CXX_FLAGS}")
|
||||
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
|
||||
|
||||
find_package(riru REQUIRED CONFIG)
|
||||
|
||||
include_directories(include)
|
||||
|
||||
add_library(${MODULE_NAME} SHARED main.cpp ${CMAKE_CURRENT_BINARY_DIR}/config.cpp)
|
||||
target_link_libraries(${MODULE_NAME} log riru::riru)
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
add_custom_command(TARGET ${MODULE_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_STRIP} --strip-all --remove-section=.comment "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${MODULE_NAME}.so")
|
||||
endif ()
|
8
riru/module/src/main/cpp/include/config.h
Normal file
8
riru/module/src/main/cpp/include/config.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
namespace riru {
|
||||
extern const int moduleVersionCode;
|
||||
extern const char* const moduleVersionName;
|
||||
extern const int moduleApiVersion;
|
||||
extern const int moduleMinApiVersion;
|
||||
}
|
115
riru/module/src/main/cpp/main.cpp
Normal file
115
riru/module/src/main/cpp/main.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
#include <jni.h>
|
||||
#include <sys/types.h>
|
||||
#include <riru.h>
|
||||
#include <malloc.h>
|
||||
#include <cstring>
|
||||
#include <config.h>
|
||||
|
||||
static void forkAndSpecializePre(
|
||||
JNIEnv *env, jclass clazz, jint *uid, jint *gid, jintArray *gids, jint *runtimeFlags,
|
||||
jobjectArray *rlimits, jint *mountExternal, jstring *seInfo, jstring *niceName,
|
||||
jintArray *fdsToClose, jintArray *fdsToIgnore, jboolean *is_child_zygote,
|
||||
jstring *instructionSet, jstring *appDataDir, jboolean *isTopApp, jobjectArray *pkgDataInfoList,
|
||||
jobjectArray *whitelistedDataInfoList, jboolean *bindMountAppDataDirs, jboolean *bindMountAppStorageDirs) {
|
||||
// Called "before" com_android_internal_os_Zygote_nativeForkAndSpecialize in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
|
||||
// Parameters are pointers, you can change the value of them if you want
|
||||
// Some parameters are not exist is older Android versions, in this case, they are null or 0
|
||||
}
|
||||
|
||||
static void forkAndSpecializePost(JNIEnv *env, jclass clazz, jint res) {
|
||||
// Called "after" com_android_internal_os_Zygote_nativeForkAndSpecialize in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
|
||||
// "res" is the return value of com_android_internal_os_Zygote_nativeForkAndSpecialize
|
||||
|
||||
if (res == 0) {
|
||||
// In app process
|
||||
|
||||
// When unload allowed is true, the module will be unloaded (dlclose) by Riru
|
||||
// If this modules has hooks installed, DONOT set it to true, or there will be SIGSEGV
|
||||
// This value will be automatically reset to false before the "pre" function is called
|
||||
riru_set_unload_allowed(true);
|
||||
} else {
|
||||
// In zygote process
|
||||
}
|
||||
}
|
||||
|
||||
static void specializeAppProcessPre(
|
||||
JNIEnv *env, jclass clazz, jint *uid, jint *gid, jintArray *gids, jint *runtimeFlags,
|
||||
jobjectArray *rlimits, jint *mountExternal, jstring *seInfo, jstring *niceName,
|
||||
jboolean *startChildZygote, jstring *instructionSet, jstring *appDataDir,
|
||||
jboolean *isTopApp, jobjectArray *pkgDataInfoList, jobjectArray *whitelistedDataInfoList,
|
||||
jboolean *bindMountAppDataDirs, jboolean *bindMountAppStorageDirs) {
|
||||
// Called "before" com_android_internal_os_Zygote_nativeSpecializeAppProcess in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
|
||||
// Parameters are pointers, you can change the value of them if you want
|
||||
// Some parameters are not exist is older Android versions, in this case, they are null or 0
|
||||
}
|
||||
|
||||
static void specializeAppProcessPost(
|
||||
JNIEnv *env, jclass clazz) {
|
||||
// Called "after" com_android_internal_os_Zygote_nativeSpecializeAppProcess in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
|
||||
|
||||
// When unload allowed is true, the module will be unloaded (dlclose) by Riru
|
||||
// If this modules has hooks installed, DONOT set it to true, or there will be SIGSEGV
|
||||
// This value will be automatically reset to false before the "pre" function is called
|
||||
riru_set_unload_allowed(true);
|
||||
}
|
||||
|
||||
static void forkSystemServerPre(
|
||||
JNIEnv *env, jclass clazz, uid_t *uid, gid_t *gid, jintArray *gids, jint *runtimeFlags,
|
||||
jobjectArray *rlimits, jlong *permittedCapabilities, jlong *effectiveCapabilities) {
|
||||
// Called "before" com_android_internal_os_Zygote_forkSystemServer in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
|
||||
// Parameters are pointers, you can change the value of them if you want
|
||||
// Some parameters are not exist is older Android versions, in this case, they are null or 0
|
||||
}
|
||||
|
||||
static void forkSystemServerPost(JNIEnv *env, jclass clazz, jint res) {
|
||||
// Called "after" com_android_internal_os_Zygote_forkSystemServer in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
|
||||
|
||||
if (res == 0) {
|
||||
// In system server process
|
||||
} else {
|
||||
// In zygote process
|
||||
}
|
||||
}
|
||||
|
||||
static void onModuleLoaded() {
|
||||
// Called when this library is loaded and "hidden" by Riru (see Riru's hide.cpp)
|
||||
|
||||
// If you want to use threads, start them here rather than the constructors
|
||||
// __attribute__((constructor)) or constructors of static variables,
|
||||
// or the "hide" will cause SIGSEGV
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
int riru_api_version;
|
||||
const char *riru_magisk_module_path = nullptr;
|
||||
int *riru_allow_unload = nullptr;
|
||||
|
||||
static auto module = RiruVersionedModuleInfo{
|
||||
.moduleApiVersion = riru::moduleApiVersion,
|
||||
.moduleInfo= RiruModuleInfo{
|
||||
.supportHide = true,
|
||||
.version = riru::moduleVersionCode,
|
||||
.versionName = riru::moduleVersionName,
|
||||
.onModuleLoaded = onModuleLoaded,
|
||||
.forkAndSpecializePre = forkAndSpecializePre,
|
||||
.forkAndSpecializePost = forkAndSpecializePost,
|
||||
.forkSystemServerPre = forkSystemServerPre,
|
||||
.forkSystemServerPost = forkSystemServerPost,
|
||||
.specializeAppProcessPre = specializeAppProcessPre,
|
||||
.specializeAppProcessPost = specializeAppProcessPost
|
||||
}
|
||||
};
|
||||
|
||||
RiruVersionedModuleInfo *init(Riru *riru) {
|
||||
auto core_max_api_version = riru->riruApiVersion;
|
||||
riru_api_version = core_max_api_version <= riru::moduleApiVersion ? core_max_api_version : riru::moduleApiVersion;
|
||||
module.moduleApiVersion = riru_api_version;
|
||||
|
||||
riru_magisk_module_path = strdup(riru->magiskModulePath);
|
||||
if (riru_api_version >= 25) {
|
||||
riru_allow_unload = riru->allowUnload;
|
||||
}
|
||||
return &module;
|
||||
}
|
||||
}
|
8
riru/module/src/main/cpp/template/config.cpp
Normal file
8
riru/module/src/main/cpp/template/config.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "config.h"
|
||||
|
||||
namespace riru {
|
||||
const int moduleVersionCode = ${RIRU_MODULE_VERSION};
|
||||
const char* const moduleVersionName = "${RIRU_MODULE_VERSION_NAME}";
|
||||
const int moduleApiVersion = ${RIRU_MODULE_API_VERSION};
|
||||
const int moduleMinApiVersion = ${RIRU_MODULE_MIN_API_VERSION};
|
||||
}
|
5
riru/settings.gradle
Normal file
5
riru/settings.gradle
Normal file
@ -0,0 +1,5 @@
|
||||
include ':module'
|
||||
|
||||
import org.apache.tools.ant.DirectoryScanner
|
||||
|
||||
DirectoryScanner.removeDefaultExclude('**/.gitattributes')
|
10
riru/template/magisk_module/.gitattributes
vendored
Normal file
10
riru/template/magisk_module/.gitattributes
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
# Declare files that will always have LF line endings on checkout.
|
||||
META-INF/** text eol=lf
|
||||
*.prop text eol=lf
|
||||
*.sh text eol=lf
|
||||
*.md text eol=lf
|
||||
sepolicy.rule text eol=lf
|
||||
|
||||
# Denote all files that are truly binary and should not be modified.
|
||||
system/** binary
|
||||
system_x86/** binary
|
@ -0,0 +1,33 @@
|
||||
#!/sbin/sh
|
||||
|
||||
#################
|
||||
# Initialization
|
||||
#################
|
||||
|
||||
umask 022
|
||||
|
||||
# echo before loading util_functions
|
||||
ui_print() { echo "$1"; }
|
||||
|
||||
require_new_magisk() {
|
||||
ui_print "*******************************"
|
||||
ui_print " Please install Magisk v20.4+! "
|
||||
ui_print "*******************************"
|
||||
exit 1
|
||||
}
|
||||
|
||||
#########################
|
||||
# Load util_functions.sh
|
||||
#########################
|
||||
|
||||
OUTFD=$2
|
||||
ZIPFILE=$3
|
||||
|
||||
mount /data 2>/dev/null
|
||||
|
||||
[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk
|
||||
. /data/adb/magisk/util_functions.sh
|
||||
[ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk
|
||||
|
||||
install_module
|
||||
exit 0
|
@ -0,0 +1 @@
|
||||
#MAGISK
|
1
riru/template/magisk_module/README.md
Normal file
1
riru/template/magisk_module/README.md
Normal file
@ -0,0 +1 @@
|
||||
# Riru - Template
|
70
riru/template/magisk_module/customize.sh
Normal file
70
riru/template/magisk_module/customize.sh
Normal file
@ -0,0 +1,70 @@
|
||||
SKIPUNZIP=1
|
||||
|
||||
# Extract verify.sh
|
||||
ui_print "- Extracting verify.sh"
|
||||
unzip -o "$ZIPFILE" 'verify.sh' -d "$TMPDIR" >&2
|
||||
if [ ! -f "$TMPDIR/verify.sh" ]; then
|
||||
ui_print "*********************************************************"
|
||||
ui_print "! Unable to extract verify.sh!"
|
||||
ui_print "! This zip may be corrupted, please try downloading again"
|
||||
abort "*********************************************************"
|
||||
fi
|
||||
. $TMPDIR/verify.sh
|
||||
|
||||
# Extract riru.sh
|
||||
|
||||
# Variables provided by riru.sh:
|
||||
#
|
||||
# RIRU_API: API version of installed Riru, 0 if not installed
|
||||
# RIRU_MIN_COMPATIBLE_API: minimal supported API version by installed Riru, 0 if not installed or version < v23.2
|
||||
# RIRU_VERSION_CODE: version code of installed Riru, 0 if not installed or version < v23.2
|
||||
# RIRU_VERSION_NAME: version name of installed Riru, "" if not installed or version < v23.2
|
||||
|
||||
extract "$ZIPFILE" 'riru.sh' "$TMPDIR"
|
||||
. $TMPDIR/riru.sh
|
||||
|
||||
# Functions from util_functions.sh (it will be loaded by riru.sh)
|
||||
check_riru_version
|
||||
enforce_install_from_magisk_app
|
||||
|
||||
# Check architecture
|
||||
if [ "$ARCH" != "arm" ] && [ "$ARCH" != "arm64" ] && [ "$ARCH" != "x86" ] && [ "$ARCH" != "x64" ]; then
|
||||
abort "! Unsupported platform: $ARCH"
|
||||
else
|
||||
ui_print "- Device platform: $ARCH"
|
||||
fi
|
||||
|
||||
# Extract libs
|
||||
ui_print "- Extracting module files"
|
||||
|
||||
extract "$ZIPFILE" 'module.prop' "$MODPATH"
|
||||
extract "$ZIPFILE" 'uninstall.sh' "$MODPATH"
|
||||
|
||||
# Riru v24+ load files from the "riru" folder in the Magisk module folder
|
||||
# This "riru" folder is also used to determine if a Magisk module is a Riru module
|
||||
|
||||
mkdir "$MODPATH/riru"
|
||||
mkdir "$MODPATH/riru/lib"
|
||||
mkdir "$MODPATH/riru/lib64"
|
||||
|
||||
if [ "$ARCH" = "arm" ] || [ "$ARCH" = "arm64" ]; then
|
||||
ui_print "- Extracting arm libraries"
|
||||
extract "$ZIPFILE" "lib/armeabi-v7a/lib$RIRU_MODULE_LIB_NAME.so" "$MODPATH/riru/lib" true
|
||||
|
||||
if [ "$IS64BIT" = true ]; then
|
||||
ui_print "- Extracting arm64 libraries"
|
||||
extract "$ZIPFILE" "lib/arm64-v8a/lib$RIRU_MODULE_LIB_NAME.so" "$MODPATH/riru/lib64" true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$ARCH" = "x86" ] || [ "$ARCH" = "x64" ]; then
|
||||
ui_print "- Extracting x86 libraries"
|
||||
extract "$ZIPFILE" "lib/x86/lib$RIRU_MODULE_LIB_NAME.so" "$MODPATH/riru/lib" true
|
||||
|
||||
if [ "$IS64BIT" = true ]; then
|
||||
ui_print "- Extracting x64 libraries"
|
||||
extract "$ZIPFILE" "lib/x86_64/lib$RIRU_MODULE_LIB_NAME.so" "$MODPATH/riru/lib64" true
|
||||
fi
|
||||
fi
|
||||
|
||||
set_perm_recursive "$MODPATH" 0 0 0755 0644
|
6
riru/template/magisk_module/module.prop
Normal file
6
riru/template/magisk_module/module.prop
Normal file
@ -0,0 +1,6 @@
|
||||
id=${id}
|
||||
name=${name}
|
||||
version=${version}
|
||||
versionCode=${versionCode}
|
||||
author=${author}
|
||||
description=${description}
|
44
riru/template/magisk_module/riru.sh
Normal file
44
riru/template/magisk_module/riru.sh
Normal file
@ -0,0 +1,44 @@
|
||||
#!/sbin/sh
|
||||
RIRU_MODULE_LIB_NAME="@RIRU_MODULE_LIB_NAME@"
|
||||
|
||||
# Variables for customize.sh
|
||||
RIRU_API=0
|
||||
RIRU_MIN_COMPATIBLE_API=0
|
||||
RIRU_VERSION_CODE=0
|
||||
RIRU_VERSION_NAME=""
|
||||
|
||||
# Used by util_functions.sh
|
||||
RIRU_MODULE_API_VERSION=@RIRU_MODULE_API_VERSION@
|
||||
RIRU_MODULE_MIN_API_VERSION=@RIRU_MODULE_MIN_API_VERSION@
|
||||
RIRU_MODULE_MIN_RIRU_VERSION_NAME="@RIRU_MODULE_MIN_RIRU_VERSION_NAME@"
|
||||
|
||||
if [ "$MAGISK_VER_CODE" -ge 21000 ]; then
|
||||
MAGISK_CURRENT_RIRU_MODULE_PATH=$(magisk --path)/.magisk/modules/riru-core
|
||||
else
|
||||
MAGISK_CURRENT_RIRU_MODULE_PATH=/sbin/.magisk/modules/riru-core
|
||||
fi
|
||||
|
||||
if [ ! -d $MAGISK_CURRENT_RIRU_MODULE_PATH ]; then
|
||||
ui_print "*********************************************************"
|
||||
ui_print "! Riru is not installed"
|
||||
ui_print "! Please install Riru from Magisk Manager or https://github.com/RikkaApps/Riru/releases"
|
||||
abort "*********************************************************"
|
||||
fi
|
||||
|
||||
if [ -f "$MAGISK_CURRENT_RIRU_MODULE_PATH/disable" ] || [ -f "$MAGISK_CURRENT_RIRU_MODULE_PATH/remove" ]; then
|
||||
ui_print "*********************************************************"
|
||||
ui_print "! Riru is not enabled or will be removed"
|
||||
ui_print "! Please enable Riru in Magisk first"
|
||||
abort "*********************************************************"
|
||||
fi
|
||||
|
||||
if [ -f $MAGISK_CURRENT_RIRU_MODULE_PATH/util_functions.sh ]; then
|
||||
ui_print "- Load $MAGISK_CURRENT_RIRU_MODULE_PATH/util_functions.sh"
|
||||
# shellcheck disable=SC1090
|
||||
. $MAGISK_CURRENT_RIRU_MODULE_PATH/util_functions.sh
|
||||
else
|
||||
ui_print "*********************************************************"
|
||||
ui_print "! Riru $RIRU_MODULE_MIN_RIRU_VERSION_NAME or above is required"
|
||||
ui_print "! Please upgrade Riru from Magisk Manager or https://github.com/RikkaApps/Riru/releases"
|
||||
abort "*********************************************************"
|
||||
fi
|
2
riru/template/magisk_module/uninstall.sh
Normal file
2
riru/template/magisk_module/uninstall.sh
Normal file
@ -0,0 +1,2 @@
|
||||
#!/sbin/sh
|
||||
MODDIR=${0%/*}
|
39
riru/template/magisk_module/verify.sh
Normal file
39
riru/template/magisk_module/verify.sh
Normal file
@ -0,0 +1,39 @@
|
||||
TMPDIR_FOR_VERIFY="$TMPDIR/.vunzip"
|
||||
mkdir "$TMPDIR_FOR_VERIFY"
|
||||
|
||||
abort_verify() {
|
||||
ui_print "*********************************************************"
|
||||
ui_print "! $1"
|
||||
ui_print "! This zip may be corrupted, please try downloading again"
|
||||
abort "*********************************************************"
|
||||
}
|
||||
|
||||
# extract <zip> <file> <target dir> <junk paths>
|
||||
extract() {
|
||||
zip=$1
|
||||
file=$2
|
||||
dir=$3
|
||||
junk_paths=$4
|
||||
[ -z "$junk_paths" ] && junk_paths=false
|
||||
opts="-o"
|
||||
[ $junk_paths = true ] && opts="-oj"
|
||||
|
||||
file_path=""
|
||||
hash_path=""
|
||||
if [ $junk_paths = true ]; then
|
||||
file_path="$dir/$(basename "$file")"
|
||||
hash_path="$TMPDIR_FOR_VERIFY/$(basename "$file").sha256sum"
|
||||
else
|
||||
file_path="$dir/$file"
|
||||
hash_path="$TMPDIR_FOR_VERIFY/$file.sha256sum"
|
||||
fi
|
||||
|
||||
unzip $opts "$zip" "$file" -d "$dir" >&2
|
||||
[ -f "$file_path" ] || abort_verify "$file not exists"
|
||||
|
||||
unzip $opts "$zip" "$file.sha256sum" -d "$TMPDIR_FOR_VERIFY" >&2
|
||||
[ -f "$hash_path" ] || abort_verify "$file.sha256sum not exists"
|
||||
|
||||
(echo "$(cat "$hash_path") $file_path" | sha256sum -c -s -) || abort_verify "Failed to verify $file"
|
||||
ui_print "- Verified $file" >&1
|
||||
}
|
Loading…
Reference in New Issue
Block a user