├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── module.example.gradle ├── module ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── cpp │ ├── CMakeLists.txt │ ├── include │ └── config.h │ ├── main.cpp │ └── template │ └── config.cpp ├── settings.gradle └── template └── magisk_module ├── .gitattributes ├── META-INF └── com │ └── google │ └── android │ ├── update-binary │ └── updater-script ├── README.md ├── customize.sh ├── module.prop ├── riru.sh ├── uninstall.sh └── verify.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | *.bat text eol=crlf 4 | *.jar binary -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Module 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | paths-ignore: 8 | - '**/README.md' 9 | jobs: 10 | build: 11 | runs-on: ubuntu-20.04 12 | if: ${{ !startsWith(github.event.head_commit.message, '[skip ci]') }} 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2 17 | with: 18 | submodules: 'recursive' 19 | fetch-depth: 0 20 | - name: set up JDK 11 21 | uses: actions/setup-java@v1 22 | with: 23 | java-version: 11 24 | - name: Cache Gradle Dependencies 25 | uses: actions/cache@v2 26 | with: 27 | path: | 28 | ~/.gradle/caches 29 | ~/.gradle/wrapper 30 | !~/.gradle/caches/build-cache-* 31 | key: gradle-deps-core-${{ hashFiles('**/build.gradle') }} 32 | restore-keys: | 33 | gradle-deps 34 | - name: Cache Gradle Build 35 | uses: actions/cache@v2 36 | with: 37 | path: | 38 | ~/.gradle/caches/build-cache-* 39 | key: gradle-builds-core-${{ github.sha }} 40 | restore-keys: | 41 | gradle-builds 42 | - name: Build with Gradle 43 | run: | 44 | mkdir -p ~/.gradle/wrapper 45 | mkdir -p ~/.gradle/caches 46 | [ $(du -s ~/.gradle/wrapper | awk '{ print $1 }') -gt 250000 ] && rm -rf ~/.gradle/wrapper/* || true 47 | find ~/.gradle/caches -exec touch -d "2 days ago" {} + || true 48 | echo 'org.gradle.caching=true' >> gradle.properties 49 | echo 'org.gradle.parallel=true' >> gradle.properties 50 | echo 'org.gradle.vfs.watch=true' >> gradle.properties 51 | echo 'org.gradle.jvmargs=-Xmx2048m' >> gradle.properties 52 | cp module.example.gradle module.gradle 53 | ./gradlew zipDebug zipRelease 54 | - name: Prepare artifact 55 | if: success() 56 | id: prepareArtifact 57 | run: | 58 | releaseName=`ls out/riru-template-*-release.zip | awk -F '(/|.zip)' '{print $2}'` && echo "::set-output name=releaseName::$releaseName" 59 | debugName=`ls out/riru-template-*-debug.zip | awk -F '(/|.zip)' '{print $2}'` && echo "::set-output name=debugName::$debugName" 60 | unzip out/riru-template-*-release.zip -d riru-template-release 61 | unzip out/riru-template-*-debug.zip -d riru-template-debug 62 | - name: Upload release 63 | uses: actions/upload-artifact@v2 64 | with: 65 | name: ${{ steps.prepareArtifact.outputs.releaseName }} 66 | path: './riru-template-release/*' 67 | - name: Upload debug 68 | uses: actions/upload-artifact@v2 69 | with: 70 | name: ${{ steps.prepareArtifact.outputs.debugName }} 71 | path: './riru-template-debug/*' 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea 5 | /.idea/caches/build_file_checksums.ser 6 | /.idea/libraries 7 | /.idea/modules.xml 8 | /.idea/workspace.xml 9 | .DS_Store 10 | /build 11 | /captures 12 | /out 13 | .externalNativeBuild 14 | .cxx 15 | module.gradle -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Rikka 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Riru - Template 2 | 3 | [Riru](https://github.com/RikkaApps/Riru) module template. 4 | 5 | ## Build 6 | 7 | 1. Rename `module.example.gradle` to `module.gradle` 8 | 2. Replace module info in `module.gradle` (all lines end with "replace with yours") 9 | 3. Write your codes 10 | 4. Run gradle task `:module:assembleRelease` task from Android Studio or command line, zip will be saved in `out`. 11 | 12 | ## File structure 13 | 14 | A Riru module is a Magisk module, please read [Magisk module document](https://topjohnwu.github.io/Magisk/guides.html#magisk-modules) first. 15 | 16 | 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. 17 | 18 | ## API changes 19 | 20 | ### API 26 (Riru v26) 21 | 22 | - Remove the support of pre-24 modules 23 | - `/data/adb/dev_random` is planned to be moved to another place in the next major version 24 | - Libraries in `/dev` do not have stacktrace, developers have to put so file into `/system`, Riru v26 makes this simpler 25 | 26 | Create an empty file, `libxxx` (no `.so` suffix), at `$MODPATH/riru/lib(64)`, Riru will try to load `/system/lib(64)/libxxx.so` 27 | 28 | ### API 25 (Riru v25) 29 | 30 | - Modules can be unloaded (see `main.cpp`) 31 | - `shouldSkipUid` is removed for API 25 modules 32 | 33 | ### API 24 (Riru v24) 34 | 35 | - The Riru API version is unified with Riru version, now the API version is 24 36 | - The `/data/adb/riru/modules/` folder is deprecated, modules only need to place library files in `$MODPATH/riru/lib(64)` (see `customize.sh` `post-fs-data.sh`) 37 | - The `init` function is called only once (see `main.cpp`) 38 | - 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`) 39 | 40 | ### API 10 (Riru v23) 41 | 42 |
43 | Background of rirud: 44 | 45 | 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. 46 | 47 | `sepolicy.rule` support was added from Magisk v20.2, a long time ago, no one report to Magisk 😒. 48 | 49 | 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. 50 |
51 | 52 | 53 | 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. 54 | 55 | 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. 56 | 57 |
58 | 59 | Pseudocode of read file: 60 | 61 | ``` 62 | socket(PF_UNIX, SOCK_STREAM) 63 | setup_sockaddr("rirud") 64 | 65 | write(ACTION_READ_FILE /* 4 */, sizeof(uint32)) 66 | write(path_size, sizeof(uint32)) 67 | write(path, path_size) 68 | 69 | errno = read(sizeof(int32_t)) // errno of "open" in "rirud" 70 | if (errno != 0) return 71 | 72 | bytes_count = read(sizeof(int32_t)) 73 | 74 | if (bytes_count > 0) { 75 | // file has size 76 | // read total "bytes_count" bytes 77 | } else if (bytes_count == 0) { 78 | // file has no size, read until 0 79 | // read until 0 80 | } 81 | ``` 82 | 83 |
84 | 85 |
86 | 87 | Pseudocode of read dir: 88 | 89 | ``` 90 | socket(PF_UNIX, SOCK_STREAM) 91 | setup_sockaddr("rirud") 92 | 93 | write(ACTION_READ_DIR /* 5 */, sizeof(uint32)) 94 | write(path_size, sizeof(uint32)) 95 | write(path, path_size) 96 | 97 | errno = read(sizeof(int32_t)) // errno of "opendir" in "rirud" 98 | if (errno != 0) return 99 | 100 | while (true) { 101 | write(1 /* continue */, sizeof(uint8)) 102 | 103 | reply = read(sizeof(int32)) 104 | if (reply == -1) break // end 105 | if (reply != 0) continue // reply is errno of "readdir" in "rirud" 106 | 107 | d_type = read(sizeof(uchar)) 108 | d_name = read(256) 109 | } 110 | ``` 111 | 112 |
113 | 114 | Example implementation: 115 | 116 | ### API 9 (Riru v22) 117 | 118 | #### API 119 | 120 | 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. 121 | 122 | This has these advantages: 123 | 124 | * Module can support different Riru versions 125 | * Riru itself will not relay on ".prop" file (unreliable) to get module information 126 | 127 | #### Riru 128 | 129 | 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))`). 130 | 131 | For most modules, this should have no problem, but modules like Xposed frameworks may have to make changes. 132 | 133 | > 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? 134 | 135 | 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`). 136 | 137 | #### Module installer 138 | 139 | `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). 140 | 141 | 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. 142 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'idea' 3 | } 4 | 5 | idea.module { 6 | excludeDirs += file('out') 7 | resourceDirs += file('template') 8 | resourceDirs += file('scripts') 9 | } 10 | 11 | ext { 12 | min_sdk = 23 13 | target_sdk = 31 14 | 15 | outDir = file("$rootDir/out") 16 | } 17 | 18 | task clean(type: Delete) { 19 | delete rootProject.buildDir, outDir 20 | } 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | # org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RikkaApps/Riru-ModuleTemplate/98a1203492fe56258fa15e06d5239333f3b342d0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jul 12 21:05:17 CST 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /module.example.gradle: -------------------------------------------------------------------------------- 1 | ext { 2 | /* 3 | This name will be used in the name of the so file ("lib${moduleLibraryName}.so"). 4 | */ 5 | moduleLibraryName = "template" 6 | 7 | /* Minimal supported Riru API version, used in the version check of riru.sh */ 8 | moduleMinRiruApiVersion = 24 9 | 10 | /* The version name of minimal supported Riru, used in the version check of riru.sh */ 11 | moduleMinRiruVersionName = "v24.0.0" 12 | 13 | /* Maximum supported Riru API version, used in the version check of riru.sh */ 14 | moduleRiruApiVersion = 26 15 | 16 | /* 17 | Magisk module ID 18 | Since Magisk use it to distinguish different modules, you should never change it. 19 | 20 | Note, the older version of the template uses '-' instead of '_', if your are upgrading from 21 | the older version, please pay attention. 22 | */ 23 | magiskModuleId = "riru_template" 24 | 25 | moduleName = "Template" 26 | moduleAuthor = "Template" 27 | moduleDescription = "Riru module template. Requires Riru $moduleMinRiruVersionName or above." 28 | moduleVersion = "v26.0.0" 29 | moduleVersionCode = 26 30 | } 31 | -------------------------------------------------------------------------------- /module/.gitignore: -------------------------------------------------------------------------------- 1 | /.externalNativeBuild 2 | /build 3 | /release -------------------------------------------------------------------------------- /module/build.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.filters.FixCrLfFilter 2 | import org.apache.tools.ant.filters.ReplaceTokens 3 | 4 | import java.security.MessageDigest 5 | 6 | plugins { 7 | id 'com.android.library' 8 | } 9 | 10 | apply from: file(rootProject.file('module.gradle')) 11 | 12 | android { 13 | compileSdk target_sdk 14 | defaultConfig { 15 | minSdk min_sdk 16 | targetSdk target_sdk 17 | externalNativeBuild { 18 | cmake { 19 | arguments "-DMODULE_NAME:STRING=$moduleLibraryName", 20 | "-DRIRU_MODULE_API_VERSION=$moduleRiruApiVersion", 21 | "-DRIRU_MODULE_VERSION=$moduleVersionCode", 22 | "-DRIRU_MODULE_VERSION_NAME:STRING=$moduleVersion", 23 | "-DRIRU_MODULE_MIN_API_VERSION=$moduleMinRiruApiVersion" 24 | } 25 | } 26 | } 27 | buildFeatures { 28 | prefab true 29 | } 30 | externalNativeBuild { 31 | cmake { 32 | path "src/main/cpp/CMakeLists.txt" 33 | version "3.10.2" 34 | } 35 | } 36 | } 37 | 38 | dependencies { 39 | // This is prefab aar which contains "riru.h" 40 | // If you want to use older versions of AGP, 41 | // you can copy this file from https://github.com/RikkaApps/Riru/blob/master/riru/src/main/cpp/include_riru/riru.h 42 | implementation 'dev.rikka.ndk:riru:26.0.0' 43 | } 44 | 45 | afterEvaluate { 46 | android.libraryVariants.forEach { variant -> 47 | def variantCapped = variant.name.capitalize() 48 | def variantLowered = variant.name.toLowerCase() 49 | 50 | def zipName = "${magiskModuleId.replace('_', '-')}-${moduleVersion}-${variantLowered}.zip" 51 | def magiskDir = file("$outDir/magisk_module_$variantLowered") 52 | 53 | task("prepareMagiskFiles${variantCapped}", type: Sync) { 54 | dependsOn("assemble$variantCapped") 55 | 56 | def templatePath = "$rootDir/template/magisk_module" 57 | 58 | into magiskDir 59 | from(templatePath) { 60 | exclude 'riru.sh', 'module.prop' 61 | } 62 | from(templatePath) { 63 | include 'riru.sh' 64 | filter(ReplaceTokens.class, tokens: [ 65 | "RIRU_MODULE_LIB_NAME" : moduleLibraryName, 66 | "RIRU_MODULE_API_VERSION" : moduleRiruApiVersion.toString(), 67 | "RIRU_MODULE_MIN_API_VERSION" : moduleMinRiruApiVersion.toString(), 68 | "RIRU_MODULE_MIN_RIRU_VERSION_NAME": moduleMinRiruVersionName, 69 | ]) 70 | filter(FixCrLfFilter.class, 71 | eol: FixCrLfFilter.CrLf.newInstance("lf")) 72 | } 73 | from(templatePath) { 74 | include 'module.prop' 75 | expand([ 76 | id : magiskModuleId, 77 | name : moduleName, 78 | version : moduleVersion, 79 | versionCode: moduleVersionCode.toString(), 80 | author : moduleAuthor, 81 | description: moduleDescription, 82 | ]) 83 | filter(FixCrLfFilter.class, 84 | eol: FixCrLfFilter.CrLf.newInstance("lf")) 85 | } 86 | from("$buildDir/intermediates/stripped_native_libs/$variantLowered/out/lib") { 87 | into 'lib' 88 | } 89 | doLast { 90 | fileTree("$magiskDir").visit { f -> 91 | if (f.directory) return 92 | if (f.file.name == '.gitattributes') return 93 | 94 | def md = MessageDigest.getInstance("SHA-256") 95 | f.file.eachByte 4096, { bytes, size -> 96 | md.update(bytes, 0, size) 97 | } 98 | file(f.file.path + ".sha256sum").text = md.digest().encodeHex() 99 | } 100 | } 101 | } 102 | 103 | task("zip${variantCapped}", type: Zip) { 104 | dependsOn("prepareMagiskFiles${variantCapped}") 105 | from magiskDir 106 | archiveName zipName 107 | destinationDir outDir 108 | } 109 | 110 | task("push${variantCapped}", type: Exec) { 111 | dependsOn("zip${variantCapped}") 112 | workingDir outDir 113 | commandLine android.adbExecutable, "push", zipName, "/data/local/tmp/" 114 | } 115 | 116 | task("flash${variantCapped}", type: Exec) { 117 | dependsOn("push${variantCapped}") 118 | commandLine android.adbExecutable, "shell", "su", "-c", 119 | "magisk --install-module /data/local/tmp/${zipName}" 120 | } 121 | 122 | task("flashAndReboot${variantCapped}", type: Exec) { 123 | dependsOn("flash${variantCapped}") 124 | commandLine android.adbExecutable, "shell", "reboot" 125 | } 126 | 127 | variant.assembleProvider.get().finalizedBy("zip${variantCapped}") 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /module/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /module/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | if (NOT DEFINED MODULE_NAME) 4 | message(FATAL_ERROR "MODULE_NAME is not set") 5 | else () 6 | project(${MODULE_NAME}) 7 | endif () 8 | 9 | add_definitions(-DRIRU_MODULE) 10 | 11 | configure_file(template/config.cpp config.cpp) 12 | 13 | message("Build type: ${CMAKE_BUILD_TYPE}") 14 | 15 | set(CMAKE_CXX_STANDARD 11) 16 | 17 | set(LINKER_FLAGS "-ffixed-x18 -Wl,--hash-style=both") 18 | set(C_FLAGS "-Werror=format -fdata-sections -ffunction-sections") 19 | set(CXX_FLAGS "${CXX_FLAGS} -fno-exceptions -fno-rtti") 20 | 21 | if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") 22 | set(C_FLAGS "${C_FLAGS} -O2 -fvisibility=hidden -fvisibility-inlines-hidden") 23 | set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,-exclude-libs,ALL -Wl,--gc-sections -Wl,--strip-all") 24 | else () 25 | set(C_FLAGS "${C_FLAGS} -O0") 26 | endif () 27 | 28 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS}") 29 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_FLAGS} ${CXX_FLAGS}") 30 | 31 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}") 32 | set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}") 33 | 34 | find_package(riru REQUIRED CONFIG) 35 | 36 | include_directories(include) 37 | 38 | add_library(${MODULE_NAME} SHARED main.cpp ${CMAKE_CURRENT_BINARY_DIR}/config.cpp) 39 | target_link_libraries(${MODULE_NAME} log riru::riru) 40 | 41 | if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") 42 | add_custom_command(TARGET ${MODULE_NAME} POST_BUILD 43 | COMMAND ${CMAKE_STRIP} --strip-all --remove-section=.comment "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${MODULE_NAME}.so") 44 | endif () 45 | -------------------------------------------------------------------------------- /module/src/main/cpp/include/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace riru { 4 | extern const int moduleVersionCode; 5 | extern const char* const moduleVersionName; 6 | extern const int moduleApiVersion; 7 | extern const int moduleMinApiVersion; 8 | } 9 | -------------------------------------------------------------------------------- /module/src/main/cpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | static void forkAndSpecializePre( 9 | JNIEnv *env, jclass clazz, jint *uid, jint *gid, jintArray *gids, jint *runtimeFlags, 10 | jobjectArray *rlimits, jint *mountExternal, jstring *seInfo, jstring *niceName, 11 | jintArray *fdsToClose, jintArray *fdsToIgnore, jboolean *is_child_zygote, 12 | jstring *instructionSet, jstring *appDataDir, jboolean *isTopApp, jobjectArray *pkgDataInfoList, 13 | jobjectArray *whitelistedDataInfoList, jboolean *bindMountAppDataDirs, jboolean *bindMountAppStorageDirs) { 14 | // Called "before" com_android_internal_os_Zygote_nativeForkAndSpecialize in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp 15 | // Parameters are pointers, you can change the value of them if you want 16 | // Some parameters are not exist is older Android versions, in this case, they are null or 0 17 | } 18 | 19 | static void forkAndSpecializePost(JNIEnv *env, jclass clazz, jint res) { 20 | // Called "after" com_android_internal_os_Zygote_nativeForkAndSpecialize in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp 21 | // "res" is the return value of com_android_internal_os_Zygote_nativeForkAndSpecialize 22 | 23 | if (res == 0) { 24 | // In app process 25 | 26 | // When unload allowed is true, the module will be unloaded (dlclose) by Riru 27 | // If this modules has hooks installed, DONOT set it to true, or there will be SIGSEGV 28 | // This value will be automatically reset to false before the "pre" function is called 29 | riru_set_unload_allowed(true); 30 | } else { 31 | // In zygote process 32 | } 33 | } 34 | 35 | static void specializeAppProcessPre( 36 | JNIEnv *env, jclass clazz, jint *uid, jint *gid, jintArray *gids, jint *runtimeFlags, 37 | jobjectArray *rlimits, jint *mountExternal, jstring *seInfo, jstring *niceName, 38 | jboolean *startChildZygote, jstring *instructionSet, jstring *appDataDir, 39 | jboolean *isTopApp, jobjectArray *pkgDataInfoList, jobjectArray *whitelistedDataInfoList, 40 | jboolean *bindMountAppDataDirs, jboolean *bindMountAppStorageDirs) { 41 | // Called "before" com_android_internal_os_Zygote_nativeSpecializeAppProcess in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp 42 | // Parameters are pointers, you can change the value of them if you want 43 | // Some parameters are not exist is older Android versions, in this case, they are null or 0 44 | } 45 | 46 | static void specializeAppProcessPost( 47 | JNIEnv *env, jclass clazz) { 48 | // Called "after" com_android_internal_os_Zygote_nativeSpecializeAppProcess in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp 49 | 50 | // When unload allowed is true, the module will be unloaded (dlclose) by Riru 51 | // If this modules has hooks installed, DONOT set it to true, or there will be SIGSEGV 52 | // This value will be automatically reset to false before the "pre" function is called 53 | riru_set_unload_allowed(true); 54 | } 55 | 56 | static void forkSystemServerPre( 57 | JNIEnv *env, jclass clazz, uid_t *uid, gid_t *gid, jintArray *gids, jint *runtimeFlags, 58 | jobjectArray *rlimits, jlong *permittedCapabilities, jlong *effectiveCapabilities) { 59 | // Called "before" com_android_internal_os_Zygote_forkSystemServer in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp 60 | // Parameters are pointers, you can change the value of them if you want 61 | // Some parameters are not exist is older Android versions, in this case, they are null or 0 62 | } 63 | 64 | static void forkSystemServerPost(JNIEnv *env, jclass clazz, jint res) { 65 | // Called "after" com_android_internal_os_Zygote_forkSystemServer in frameworks/base/core/jni/com_android_internal_os_Zygote.cpp 66 | 67 | if (res == 0) { 68 | // In system server process 69 | } else { 70 | // In zygote process 71 | } 72 | } 73 | 74 | static void onModuleLoaded() { 75 | // Called when this library is loaded and "hidden" by Riru (see Riru's hide.cpp) 76 | 77 | // If you want to use threads, start them here rather than the constructors 78 | // __attribute__((constructor)) or constructors of static variables, 79 | // or the "hide" will cause SIGSEGV 80 | } 81 | 82 | extern "C" { 83 | 84 | int riru_api_version; 85 | const char *riru_magisk_module_path = nullptr; 86 | int *riru_allow_unload = nullptr; 87 | 88 | static auto module = RiruVersionedModuleInfo{ 89 | .moduleApiVersion = riru::moduleApiVersion, 90 | .moduleInfo= RiruModuleInfo{ 91 | .supportHide = true, 92 | .version = riru::moduleVersionCode, 93 | .versionName = riru::moduleVersionName, 94 | .onModuleLoaded = onModuleLoaded, 95 | .forkAndSpecializePre = forkAndSpecializePre, 96 | .forkAndSpecializePost = forkAndSpecializePost, 97 | .forkSystemServerPre = forkSystemServerPre, 98 | .forkSystemServerPost = forkSystemServerPost, 99 | .specializeAppProcessPre = specializeAppProcessPre, 100 | .specializeAppProcessPost = specializeAppProcessPost 101 | } 102 | }; 103 | 104 | RiruVersionedModuleInfo *init(Riru *riru) { 105 | auto core_max_api_version = riru->riruApiVersion; 106 | riru_api_version = core_max_api_version <= riru::moduleApiVersion ? core_max_api_version : riru::moduleApiVersion; 107 | module.moduleApiVersion = riru_api_version; 108 | 109 | riru_magisk_module_path = strdup(riru->magiskModulePath); 110 | if (riru_api_version >= 25) { 111 | riru_allow_unload = riru->allowUnload; 112 | } 113 | return &module; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /module/src/main/cpp/template/config.cpp: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | namespace riru { 4 | const int moduleVersionCode = ${RIRU_MODULE_VERSION}; 5 | const char* const moduleVersionName = "${RIRU_MODULE_VERSION_NAME}"; 6 | const int moduleApiVersion = ${RIRU_MODULE_API_VERSION}; 7 | const int moduleMinApiVersion = ${RIRU_MODULE_MIN_API_VERSION}; 8 | } 9 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.DirectoryScanner 2 | 3 | pluginManagement { 4 | repositories { 5 | gradlePluginPortal() 6 | google() 7 | mavenCentral() 8 | } 9 | plugins { 10 | id 'com.android.application' version '7.0.2' 11 | id 'com.android.library' version '7.0.2' 12 | } 13 | } 14 | dependencyResolutionManagement { 15 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 16 | repositories { 17 | mavenLocal() 18 | google() 19 | mavenCentral() 20 | } 21 | } 22 | 23 | DirectoryScanner.removeDefaultExclude('**/.gitattributes') 24 | 25 | include ':module' 26 | -------------------------------------------------------------------------------- /template/magisk_module/.gitattributes: -------------------------------------------------------------------------------- 1 | # Declare files that will always have LF line endings on checkout. 2 | META-INF/** text eol=lf 3 | *.prop text eol=lf 4 | *.sh text eol=lf 5 | *.md text eol=lf 6 | sepolicy.rule text eol=lf 7 | 8 | # Denote all files that are truly binary and should not be modified. 9 | system/** binary 10 | system_x86/** binary -------------------------------------------------------------------------------- /template/magisk_module/META-INF/com/google/android/update-binary: -------------------------------------------------------------------------------- 1 | #!/sbin/sh 2 | 3 | ################# 4 | # Initialization 5 | ################# 6 | 7 | umask 022 8 | 9 | # echo before loading util_functions 10 | ui_print() { echo "$1"; } 11 | 12 | require_new_magisk() { 13 | ui_print "*******************************" 14 | ui_print " Please install Magisk v20.4+! " 15 | ui_print "*******************************" 16 | exit 1 17 | } 18 | 19 | ######################### 20 | # Load util_functions.sh 21 | ######################### 22 | 23 | OUTFD=$2 24 | ZIPFILE=$3 25 | 26 | mount /data 2>/dev/null 27 | 28 | [ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk 29 | . /data/adb/magisk/util_functions.sh 30 | [ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk 31 | 32 | install_module 33 | exit 0 34 | -------------------------------------------------------------------------------- /template/magisk_module/META-INF/com/google/android/updater-script: -------------------------------------------------------------------------------- 1 | #MAGISK 2 | -------------------------------------------------------------------------------- /template/magisk_module/README.md: -------------------------------------------------------------------------------- 1 | # Riru - Template -------------------------------------------------------------------------------- /template/magisk_module/customize.sh: -------------------------------------------------------------------------------- 1 | SKIPUNZIP=1 2 | 3 | # Extract verify.sh 4 | ui_print "- Extracting verify.sh" 5 | unzip -o "$ZIPFILE" 'verify.sh' -d "$TMPDIR" >&2 6 | if [ ! -f "$TMPDIR/verify.sh" ]; then 7 | ui_print "*********************************************************" 8 | ui_print "! Unable to extract verify.sh!" 9 | ui_print "! This zip may be corrupted, please try downloading again" 10 | abort "*********************************************************" 11 | fi 12 | . $TMPDIR/verify.sh 13 | 14 | # Extract riru.sh 15 | 16 | # Variables provided by riru.sh: 17 | # 18 | # RIRU_API: API version of installed Riru, 0 if not installed 19 | # RIRU_MIN_COMPATIBLE_API: minimal supported API version by installed Riru, 0 if not installed or version < v23.2 20 | # RIRU_VERSION_CODE: version code of installed Riru, 0 if not installed or version < v23.2 21 | # RIRU_VERSION_NAME: version name of installed Riru, "" if not installed or version < v23.2 22 | 23 | extract "$ZIPFILE" 'riru.sh' "$TMPDIR" 24 | . $TMPDIR/riru.sh 25 | 26 | # Functions from util_functions.sh (it will be loaded by riru.sh) 27 | check_riru_version 28 | enforce_install_from_magisk_app 29 | 30 | # Check architecture 31 | if [ "$ARCH" != "arm" ] && [ "$ARCH" != "arm64" ] && [ "$ARCH" != "x86" ] && [ "$ARCH" != "x64" ]; then 32 | abort "! Unsupported platform: $ARCH" 33 | else 34 | ui_print "- Device platform: $ARCH" 35 | fi 36 | 37 | # Extract libs 38 | ui_print "- Extracting module files" 39 | 40 | extract "$ZIPFILE" 'module.prop' "$MODPATH" 41 | extract "$ZIPFILE" 'uninstall.sh' "$MODPATH" 42 | 43 | # Riru v24+ load files from the "riru" folder in the Magisk module folder 44 | # This "riru" folder is also used to determine if a Magisk module is a Riru module 45 | 46 | mkdir "$MODPATH/riru" 47 | mkdir "$MODPATH/riru/lib" 48 | mkdir "$MODPATH/riru/lib64" 49 | 50 | if [ "$ARCH" = "arm" ] || [ "$ARCH" = "arm64" ]; then 51 | ui_print "- Extracting arm libraries" 52 | extract "$ZIPFILE" "lib/armeabi-v7a/lib$RIRU_MODULE_LIB_NAME.so" "$MODPATH/riru/lib" true 53 | 54 | if [ "$IS64BIT" = true ]; then 55 | ui_print "- Extracting arm64 libraries" 56 | extract "$ZIPFILE" "lib/arm64-v8a/lib$RIRU_MODULE_LIB_NAME.so" "$MODPATH/riru/lib64" true 57 | fi 58 | fi 59 | 60 | if [ "$ARCH" = "x86" ] || [ "$ARCH" = "x64" ]; then 61 | ui_print "- Extracting x86 libraries" 62 | extract "$ZIPFILE" "lib/x86/lib$RIRU_MODULE_LIB_NAME.so" "$MODPATH/riru/lib" true 63 | 64 | if [ "$IS64BIT" = true ]; then 65 | ui_print "- Extracting x64 libraries" 66 | extract "$ZIPFILE" "lib/x86_64/lib$RIRU_MODULE_LIB_NAME.so" "$MODPATH/riru/lib64" true 67 | fi 68 | fi 69 | 70 | set_perm_recursive "$MODPATH" 0 0 0755 0644 71 | -------------------------------------------------------------------------------- /template/magisk_module/module.prop: -------------------------------------------------------------------------------- 1 | id=${id} 2 | name=${name} 3 | version=${version} 4 | versionCode=${versionCode} 5 | author=${author} 6 | description=${description} 7 | -------------------------------------------------------------------------------- /template/magisk_module/riru.sh: -------------------------------------------------------------------------------- 1 | #!/sbin/sh 2 | RIRU_MODULE_LIB_NAME="@RIRU_MODULE_LIB_NAME@" 3 | 4 | # Variables for customize.sh 5 | RIRU_API=0 6 | RIRU_MIN_COMPATIBLE_API=0 7 | RIRU_VERSION_CODE=0 8 | RIRU_VERSION_NAME="" 9 | 10 | # Used by util_functions.sh 11 | RIRU_MODULE_API_VERSION=@RIRU_MODULE_API_VERSION@ 12 | RIRU_MODULE_MIN_API_VERSION=@RIRU_MODULE_MIN_API_VERSION@ 13 | RIRU_MODULE_MIN_RIRU_VERSION_NAME="@RIRU_MODULE_MIN_RIRU_VERSION_NAME@" 14 | 15 | if [ "$MAGISK_VER_CODE" -ge 21000 ]; then 16 | MAGISK_CURRENT_RIRU_MODULE_PATH=$(magisk --path)/.magisk/modules/riru-core 17 | else 18 | MAGISK_CURRENT_RIRU_MODULE_PATH=/sbin/.magisk/modules/riru-core 19 | fi 20 | 21 | if [ ! -d $MAGISK_CURRENT_RIRU_MODULE_PATH ]; then 22 | ui_print "*********************************************************" 23 | ui_print "! Riru is not installed" 24 | ui_print "! Please install Riru from Magisk Manager or https://github.com/RikkaApps/Riru/releases" 25 | abort "*********************************************************" 26 | fi 27 | 28 | if [ -f "$MAGISK_CURRENT_RIRU_MODULE_PATH/disable" ] || [ -f "$MAGISK_CURRENT_RIRU_MODULE_PATH/remove" ]; then 29 | ui_print "*********************************************************" 30 | ui_print "! Riru is not enabled or will be removed" 31 | ui_print "! Please enable Riru in Magisk first" 32 | abort "*********************************************************" 33 | fi 34 | 35 | if [ -f $MAGISK_CURRENT_RIRU_MODULE_PATH/util_functions.sh ]; then 36 | ui_print "- Load $MAGISK_CURRENT_RIRU_MODULE_PATH/util_functions.sh" 37 | # shellcheck disable=SC1090 38 | . $MAGISK_CURRENT_RIRU_MODULE_PATH/util_functions.sh 39 | else 40 | ui_print "*********************************************************" 41 | ui_print "! Riru $RIRU_MODULE_MIN_RIRU_VERSION_NAME or above is required" 42 | ui_print "! Please upgrade Riru from Magisk Manager or https://github.com/RikkaApps/Riru/releases" 43 | abort "*********************************************************" 44 | fi 45 | -------------------------------------------------------------------------------- /template/magisk_module/uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/sbin/sh 2 | MODDIR=${0%/*} 3 | -------------------------------------------------------------------------------- /template/magisk_module/verify.sh: -------------------------------------------------------------------------------- 1 | TMPDIR_FOR_VERIFY="$TMPDIR/.vunzip" 2 | mkdir "$TMPDIR_FOR_VERIFY" 3 | 4 | abort_verify() { 5 | ui_print "*********************************************************" 6 | ui_print "! $1" 7 | ui_print "! This zip may be corrupted, please try downloading again" 8 | abort "*********************************************************" 9 | } 10 | 11 | # extract 12 | extract() { 13 | zip=$1 14 | file=$2 15 | dir=$3 16 | junk_paths=$4 17 | [ -z "$junk_paths" ] && junk_paths=false 18 | opts="-o" 19 | [ $junk_paths = true ] && opts="-oj" 20 | 21 | file_path="" 22 | hash_path="" 23 | if [ $junk_paths = true ]; then 24 | file_path="$dir/$(basename "$file")" 25 | hash_path="$TMPDIR_FOR_VERIFY/$(basename "$file").sha256sum" 26 | else 27 | file_path="$dir/$file" 28 | hash_path="$TMPDIR_FOR_VERIFY/$file.sha256sum" 29 | fi 30 | 31 | unzip $opts "$zip" "$file" -d "$dir" >&2 32 | [ -f "$file_path" ] || abort_verify "$file not exists" 33 | 34 | unzip $opts "$zip" "$file.sha256sum" -d "$TMPDIR_FOR_VERIFY" >&2 35 | [ -f "$hash_path" ] || abort_verify "$file.sha256sum not exists" 36 | 37 | (echo "$(cat "$hash_path") $file_path" | sha256sum -c -s -) || abort_verify "Failed to verify $file" 38 | ui_print "- Verified $file" >&1 39 | } 40 | --------------------------------------------------------------------------------