├── module ├── .gitignore ├── template │ ├── sepolicy.rule │ ├── META-INF │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ ├── updater-script │ │ │ └── update-binary │ ├── module.prop │ ├── service.sh │ ├── verify.sh │ └── customize.sh ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── cpp │ │ ├── CMakeLists.txt │ │ └── hook.c └── build.gradle.kts ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── libs.versions.toml ├── CHANGELOG.md ├── .gitignore ├── update.json ├── README.md ├── .gitmodules ├── settings.gradle.kts ├── gradle.properties ├── .github └── workflows │ └── build.yml ├── gradlew.bat └── gradlew /module/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /libs 3 | /obj 4 | /release 5 | -------------------------------------------------------------------------------- /module/template/sepolicy.rule: -------------------------------------------------------------------------------- 1 | allow logd logd process execmem 2 | -------------------------------------------------------------------------------- /module/template/META-INF/com/google/android/updater-script: -------------------------------------------------------------------------------- 1 | #MAGISK 2 | -------------------------------------------------------------------------------- /module/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VD171/AuditPatch/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## AuditPatch v0.2-vd_priv8 2 | 3 | - Fix **Find Root File In Sniff** by Hunter and **SELinux context leak** by Disclosure. 4 | - Add 32bits support. 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | agp = "8.6.1" 3 | 4 | [plugins] 5 | agp-app = { id = "com.android.application", version.ref = "agp" } 6 | 7 | [libraries] 8 | cxx = { module = "org.lsposed.libcxx:libcxx", version = "27.0.12077973" } 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Dec 31 12:28:57 CST 2023 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /module/template/module.prop: -------------------------------------------------------------------------------- 1 | id=${moduleId} 2 | name=${moduleName} 3 | version=${versionName} 4 | versionCode=${versionCode} 5 | author=@VD_Priv8 & brunoanc 6 | description=Remove sensitive context in audit log. 7 | updateJson=https://raw.githubusercontent.com/VD171/AuditPatch/refs/heads/master/update.json 8 | -------------------------------------------------------------------------------- /update.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v0.2-vd_priv8", 3 | "versionCode": 11, 4 | "zipUrl": "https://github.com/VD171/AuditPatch/releases/download/v0.2-vd_priv8/Audit.Patch.by.@VD_Priv8.v0.2-vd_priv8.zip", 5 | "changelog": "https://raw.githubusercontent.com/VD171/AuditPatch/refs/heads/master/CHANGELOG.md" 6 | } 7 | -------------------------------------------------------------------------------- /module/template/service.sh: -------------------------------------------------------------------------------- 1 | resetprop -w sys.boot_completed 0 2 | setprop ctl.restart logd 3 | 4 | MODDIR=${0%/*} 5 | INJECTOR_PATH="${MODDIR}/bin/Injector" 6 | LIB_PATH="/system/lib64/libauditpatch.so" 7 | TARGET_PROC="/system/bin/logd" 8 | 9 | chmod +x $INJECTOR_PATH 10 | $INJECTOR_PATH -p $TARGET_PROC -l $LIB_PATH 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Check https://android-review.googlesource.com/c/platform/system/logging/+/3725346 for details. 2 | 3 | Unlike other implementations, this fork allows fixing AVC log leak detection for users without SusFS or ZygiskNext. 4 | 5 | Also see https://github.com/brunoanc/AuditPatch-KPM for a more discrete version for APatch, SukiSU users. 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "module/src/main/cpp/third_party/Dobby"] 2 | path = module/src/main/cpp/third_party/Dobby 3 | url = https://github.com/JingMatrix/Dobby 4 | [submodule "module/src/main/cpp/third_party/Android-Ptrace-Injector"] 5 | path = module/src/main/cpp/third_party/Android-Ptrace-Injector 6 | url = https://github.com/reveny/Android-Ptrace-Injector 7 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | gradlePluginPortal() 6 | } 7 | } 8 | 9 | dependencyResolutionManagement { 10 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 11 | repositories { 12 | google() 13 | mavenCentral() 14 | } 15 | } 16 | 17 | rootProject.name = "auditpatch" 18 | include( 19 | ":module" 20 | ) 21 | -------------------------------------------------------------------------------- /module/template/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1) 2 | project(auditpatch) 3 | 4 | set(C_FLAGS "${C_FLAGS} -fvisibility=hidden") 5 | set(CXX_FLAGS "${CXX_FLAGS} -fno-exceptions -fno-rtti -fvisibility=hidden -fvisibility-inlines-hidden") 6 | 7 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS}") 8 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS}") 9 | 10 | find_package(cxx REQUIRED CONFIG) 11 | link_libraries(cxx::cxx) 12 | 13 | add_subdirectory(third_party/Dobby) 14 | 15 | add_library(${MODULE_NAME} SHARED hook.c) 16 | 17 | target_link_libraries(${MODULE_NAME} PRIVATE log dobby_static) 18 | 19 | add_custom_target( 20 | ptrace_injector ALL 21 | COMMAND ${ANDROID_NDK}/ndk-build -C ${CMAKE_CURRENT_SOURCE_DIR}/third_party/Android-Ptrace-Injector 22 | ) 23 | 24 | add_dependencies(${MODULE_NAME} ptrace_injector) 25 | -------------------------------------------------------------------------------- /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=-Xmx2048m -Dfile.encoding=UTF-8 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 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v4 14 | with: 15 | submodules: "recursive" 16 | fetch-depth: 0 17 | 18 | - name: Setup Java 19 | uses: actions/setup-java@v4 20 | with: 21 | distribution: "temurin" 22 | java-version: 17 23 | 24 | - name: Setup Gradle 25 | uses: gradle/actions/setup-gradle@v4 26 | 27 | - name: Build debug 28 | run: | 29 | ./gradlew clean zipDebug 30 | mkdir debug 31 | unzip module/release/Audit-Patch-*-debug.zip -d debug 32 | 33 | - name: Upload debug 34 | uses: actions/upload-artifact@v4 35 | with: 36 | name: Audit-Patch-debug 37 | path: "./debug/*" 38 | 39 | - name: Build release 40 | run: | 41 | ./gradlew clean zipRelease 42 | mkdir release 43 | unzip module/release/Audit-Patch-*-release.zip -d release 44 | 45 | - name: Upload release 46 | uses: actions/upload-artifact@v4 47 | with: 48 | name: Audit-Patch-release 49 | path: "./release/*" 50 | -------------------------------------------------------------------------------- /module/template/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").sha256" 26 | else 27 | file_path="$dir/$file" 28 | hash_path="$TMPDIR_FOR_VERIFY/$file.sha256" 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.sha256" -d "$TMPDIR_FOR_VERIFY" >&2 35 | [ -f "$hash_path" ] || abort_verify "$file.sha256 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 | 41 | file="META-INF/com/google/android/update-binary" 42 | file_path="$TMPDIR_FOR_VERIFY/$file" 43 | hash_path="$file_path.sha256" 44 | unzip -o "$ZIPFILE" "META-INF/com/google/android/*" -d "$TMPDIR_FOR_VERIFY" >&2 45 | [ -f "$file_path" ] || abort_verify "$file not exists" 46 | if [ -f "$hash_path" ]; then 47 | (echo "$(cat "$hash_path") $file_path" | sha256sum -c -s -) || abort_verify "Failed to verify $file" 48 | ui_print "- Verified $file" >&1 49 | else 50 | ui_print "- Download from Magisk app" 51 | fi 52 | -------------------------------------------------------------------------------- /module/src/main/cpp/hook.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "dobby.h" 6 | 7 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "auditpatch", __VA_ARGS__) 8 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "auditpatch", __VA_ARGS__) 9 | 10 | static int (*old_vasprintf)(char **strp, const char *fmt, va_list ap) = NULL; 11 | 12 | static bool is_in_quotes(const char *str, const char *pos) { 13 | bool in_quote = false; 14 | for (const char *p = str; p < pos; p++) { 15 | if (*p == '"') { 16 | in_quote = !in_quote; 17 | } 18 | } 19 | return in_quote; 20 | } 21 | 22 | static int my_vasprintf(char **strp, const char *fmt, va_list ap) { 23 | // https://cs.android.com/android/platform/superproject/main/+/main:system/logging/logd/LogAudit.cpp;l=210 24 | int result = old_vasprintf(strp, fmt, ap); 25 | 26 | if (result > 0 && *strp) { 27 | 28 | const char *source_contexts[] = { 29 | "tcontext=u:r:su:s0", 30 | "tcontext=u:r:magisk:s0", 31 | "tcontext=u:object_r:proc_modules:s0" 32 | }; 33 | 34 | size_t source_contexts_len = sizeof(source_contexts) / sizeof(source_contexts[0]); 35 | 36 | for (size_t i = 0; i < source_contexts_len; i++) { 37 | const char *source = source_contexts[i]; 38 | char *pos = strstr(*strp, source); 39 | 40 | if (pos && !is_in_quotes(*strp, pos)) { 41 | char *line_start = pos; 42 | while (line_start > *strp && *(line_start - 1) != '\n') line_start--; 43 | char *line_end = strchr(pos, '\n'); 44 | if (line_end) line_end++; 45 | else line_end = *strp + strlen(*strp); 46 | size_t new_len = strlen(*strp) - (line_end - line_start); 47 | char *new_str = malloc(new_len + 1); 48 | strncpy(new_str, *strp, line_start - *strp); 49 | strcpy(new_str + (line_start - *strp), line_end); 50 | 51 | free(*strp); 52 | *strp = new_str; 53 | return (int)new_len; 54 | } 55 | } 56 | } 57 | 58 | return result; 59 | } 60 | 61 | __attribute__((constructor)) 62 | void init(void) { 63 | void *addr = DobbySymbolResolver("libc.so", "vasprintf"); 64 | if (!addr) { 65 | LOGE("Failed to find vasprintf symbol"); 66 | return; 67 | } 68 | 69 | if (DobbyHook(addr, (void*)my_vasprintf, (void**)&old_vasprintf) == 0) { 70 | LOGI("vasprintf hooked successfully in logd!"); 71 | } else { 72 | LOGE("vasprintf hook failed in logd"); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /module/template/customize.sh: -------------------------------------------------------------------------------- 1 | # shellcheck disable=SC2034 2 | SKIPUNZIP=1 3 | 4 | DEBUG=@DEBUG@ 5 | SONAME=@SONAME@ 6 | SUPPORTED_ABIS="@SUPPORTED_ABIS@" 7 | 8 | if [ "$BOOTMODE" ] && [ "$KSU" ]; then 9 | ui_print "- Installing from KernelSU app" 10 | ui_print "- KernelSU version: $KSU_KERNEL_VER_CODE (kernel) + $KSU_VER_CODE (ksud)" 11 | if [ "$(which magisk)" ]; then 12 | ui_print "*********************************************************" 13 | ui_print "! Multiple root implementation is NOT supported!" 14 | ui_print "! Please uninstall Magisk before installing $SONAME" 15 | abort "*********************************************************" 16 | fi 17 | elif [ "$BOOTMODE" ] && [ "$MAGISK_VER_CODE" ]; then 18 | ui_print "- Installing from Magisk app" 19 | else 20 | ui_print "*********************************************************" 21 | ui_print "! Install from recovery is not supported" 22 | ui_print "! Please install from KernelSU or Magisk app" 23 | abort "*********************************************************" 24 | fi 25 | 26 | VERSION=$(grep_prop version "${TMPDIR}/module.prop") 27 | ui_print "- Installing $SONAME $VERSION" 28 | 29 | # check architecture 30 | support=false 31 | for abi in $SUPPORTED_ABIS 32 | do 33 | if [ "$ARCH" == "$abi" ]; then 34 | support=true 35 | fi 36 | done 37 | if [ "$support" == "false" ]; then 38 | abort "! Unsupported platform: $ARCH" 39 | else 40 | ui_print "- Device platform: $ARCH" 41 | fi 42 | 43 | ui_print "- Extracting verify.sh" 44 | unzip -o "$ZIPFILE" 'verify.sh' -d "$TMPDIR" >&2 45 | if [ ! -f "$TMPDIR/verify.sh" ]; then 46 | ui_print "*********************************************************" 47 | ui_print "! Unable to extract verify.sh!" 48 | ui_print "! This zip may be corrupted, please try downloading again" 49 | abort "*********************************************************" 50 | fi 51 | . "$TMPDIR/verify.sh" 52 | extract "$ZIPFILE" 'customize.sh' "$TMPDIR/.vunzip" 53 | extract "$ZIPFILE" 'verify.sh' "$TMPDIR/.vunzip" 54 | extract "$ZIPFILE" 'sepolicy.rule' "$TMPDIR" 55 | 56 | ui_print "- Extracting module files" 57 | extract "$ZIPFILE" 'module.prop' "$MODPATH" 58 | extract "$ZIPFILE" 'service.sh' "$MODPATH" 59 | mv "$TMPDIR/sepolicy.rule" "$MODPATH" 60 | 61 | mkdir -p "$MODPATH/system/lib64" 62 | mkdir "$MODPATH/bin" 63 | 64 | ui_print "- Extracting $ARCH libraries" 65 | if [ "$ARCH" = "x86" ] || [ "$ARCH" = "x64" ]; then 66 | extract "$ZIPFILE" "lib/x64/lib$SONAME.so" "$MODPATH/system/lib64" true 67 | extract "$ZIPFILE" "bin/x64/Injector" "$MODPATH/bin" true 68 | else 69 | extract "$ZIPFILE" "lib/arm64/lib$SONAME.so" "$MODPATH/system/lib64" true 70 | extract "$ZIPFILE" "bin/arm64/Injector" "$MODPATH/bin" true 71 | fi 72 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /module/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import android.databinding.tool.ext.capitalizeUS 2 | import org.apache.tools.ant.filters.FixCrLfFilter 3 | import org.apache.tools.ant.filters.ReplaceTokens 4 | import java.security.MessageDigest 5 | 6 | plugins { 7 | alias(libs.plugins.agp.app) 8 | } 9 | 10 | val moduleId: String by rootProject.extra 11 | val moduleName: String by rootProject.extra 12 | val verCode: Int by rootProject.extra 13 | val verName: String by rootProject.extra 14 | val commitHash: String by rootProject.extra 15 | val abiList: List by rootProject.extra 16 | 17 | android { 18 | buildFeatures { 19 | prefab = true 20 | } 21 | defaultConfig { 22 | ndk { 23 | abiFilters.addAll(abiList) 24 | } 25 | externalNativeBuild { 26 | cmake { 27 | cppFlags("-std=c++20") 28 | arguments( 29 | "-DANDROID_STL=none", 30 | "-DMODULE_NAME=$moduleId" 31 | ) 32 | } 33 | } 34 | } 35 | externalNativeBuild { 36 | cmake { 37 | path("src/main/cpp/CMakeLists.txt") 38 | } 39 | } 40 | } 41 | 42 | val abiMap = mapOf( 43 | "arm64-v8a" to "arm64", 44 | "armeabi-v7a" to "arm", 45 | "x86" to "x86", 46 | "x86_64" to "x64" 47 | ) 48 | 49 | androidComponents.onVariants { variant -> 50 | afterEvaluate { 51 | val variantLowered = variant.name.lowercase() 52 | val variantCapped = variant.name.capitalizeUS() 53 | val buildTypeLowered = variant.buildType?.lowercase() 54 | val supportedAbis = abiList.map { 55 | abiMap[it] ?: error("unsupported abi $it") 56 | }.joinToString(" ") 57 | 58 | val moduleDir = layout.buildDirectory.file("outputs/module/$variantLowered") 59 | val zipFileName = 60 | "$moduleName-$verName-$verCode-$commitHash-$buildTypeLowered.zip".replace(' ', '-') 61 | 62 | val prepareModuleFilesTask = task("prepareModuleFiles$variantCapped") { 63 | group = "module" 64 | dependsOn("assemble$variantCapped") 65 | into(moduleDir) 66 | from(rootProject.layout.projectDirectory.file("README.md")) 67 | from(layout.projectDirectory.file("template")) { 68 | exclude("module.prop", "customize.sh", "service.sh") 69 | filter("eol" to FixCrLfFilter.CrLf.newInstance("lf")) 70 | } 71 | from(layout.projectDirectory.file("template")) { 72 | include("module.prop") 73 | expand( 74 | "moduleId" to moduleId, 75 | "moduleName" to moduleName, 76 | "versionName" to "$verName ($verCode-$commitHash-$variantLowered)", 77 | "versionCode" to verCode 78 | ) 79 | } 80 | from(layout.projectDirectory.file("template")) { 81 | include("customize.sh", "service.sh") 82 | val tokens = mapOf( 83 | "DEBUG" to if (buildTypeLowered == "debug") "true" else "false", 84 | "SONAME" to moduleId, 85 | "SUPPORTED_ABIS" to supportedAbis 86 | ) 87 | filter("tokens" to tokens) 88 | filter("eol" to FixCrLfFilter.CrLf.newInstance("lf")) 89 | } 90 | abiList.forEach { abi -> 91 | val arch = abiMap[abi] 92 | from(layout.buildDirectory.file("intermediates/stripped_native_libs/$variantLowered/strip${variantCapped}DebugSymbols/out/lib/$abi")) { 93 | into("lib/$arch") 94 | exclude("**/libdobby.so") 95 | } 96 | from(layout.projectDirectory.file("src/main/cpp/third_party/Android-Ptrace-Injector/libs/$abi/Injector")) { 97 | into("bin/$arch") 98 | } 99 | } 100 | 101 | doLast { 102 | fileTree(moduleDir).visit { 103 | if (isDirectory) return@visit 104 | val md = MessageDigest.getInstance("SHA-256") 105 | file.forEachBlock(4096) { bytes, size -> 106 | md.update(bytes, 0, size) 107 | } 108 | file(file.path + ".sha256").writeText( 109 | org.apache.commons.codec.binary.Hex.encodeHexString( 110 | md.digest() 111 | ) 112 | ) 113 | } 114 | } 115 | } 116 | 117 | val zipTask = task("zip$variantCapped") { 118 | group = "module" 119 | dependsOn(prepareModuleFilesTask) 120 | archiveFileName.set(zipFileName) 121 | destinationDirectory.set(layout.projectDirectory.file("release").asFile) 122 | from(moduleDir) 123 | } 124 | 125 | val pushTask = task("push$variantCapped") { 126 | group = "module" 127 | dependsOn(zipTask) 128 | commandLine("adb", "push", zipTask.outputs.files.singleFile.path, "/data/local/tmp") 129 | } 130 | 131 | val installKsuTask = task("installKsu$variantCapped") { 132 | group = "module" 133 | dependsOn(pushTask) 134 | commandLine( 135 | "adb", "shell", "su", "-c", 136 | "/data/adb/ksud module install /data/local/tmp/$zipFileName" 137 | ) 138 | } 139 | 140 | val installMagiskTask = task("installMagisk$variantCapped") { 141 | group = "module" 142 | dependsOn(pushTask) 143 | commandLine( 144 | "adb", 145 | "shell", 146 | "su", 147 | "-M", 148 | "-c", 149 | "magisk --install-module /data/local/tmp/$zipFileName" 150 | ) 151 | } 152 | 153 | task("installKsuAndReboot$variantCapped") { 154 | group = "module" 155 | dependsOn(installKsuTask) 156 | commandLine("adb", "reboot") 157 | } 158 | 159 | task("installMagiskAndReboot$variantCapped") { 160 | group = "module" 161 | dependsOn(installMagiskTask) 162 | commandLine("adb", "reboot") 163 | } 164 | } 165 | } 166 | 167 | dependencies { 168 | implementation(libs.cxx) 169 | } 170 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | --------------------------------------------------------------------------------