diff --git a/build.gradle.kts b/build.gradle.kts index f4e20f5..e2496cd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,30 +4,8 @@ plugins { alias(libs.plugins.agp.lib) apply false } -fun String.execute(currentWorkingDir: File = file("./")): String { - val byteOut = ByteArrayOutputStream() - project.exec { - workingDir = currentWorkingDir - commandLine = split("\\s".toRegex()) - standardOutput = byteOut - } - return String(byteOut.toByteArray()).trim() -} - val moduleId by extra("qingyue") val moduleName by extra("Zygisk Qingyue") val verName by extra("v1.0.0") val verCode by extra(100) -val abiList by extra(listOf("arm64-v8a")) - -val androidMinSdkVersion by extra(29) -val androidTargetSdkVersion by extra(34) -val androidCompileSdkVersion by extra(34) -val androidBuildToolsVersion by extra("34.0.0") -val androidCompileNdkVersion by extra("26.0.10792818") -val androidSourceCompatibility by extra(JavaVersion.VERSION_11) -val androidTargetCompatibility by extra(JavaVersion.VERSION_11) - -tasks.register("Delete", Delete::class) { - delete(rootProject.buildDir) -} +val abiList by extra(listOf("armeabi-v7a","arm64-v8a","x86","x86_64")) diff --git a/module/build.gradle.kts b/module/build.gradle.kts index 1b5b263..baf18fa 100644 --- a/module/build.gradle.kts +++ b/module/build.gradle.kts @@ -1,7 +1,4 @@ import android.databinding.tool.ext.capitalizeUS -import org.apache.tools.ant.filters.FixCrLfFilter -import org.apache.tools.ant.filters.ReplaceTokens -import java.security.MessageDigest plugins { alias(libs.plugins.agp.lib) @@ -22,7 +19,7 @@ android { } externalNativeBuild { ndkBuild { - arguments("MODULE_NAME=$moduleId") + arguments("-j${Runtime.getRuntime().availableProcessors()}") } } } @@ -37,25 +34,16 @@ androidComponents.onVariants { variant -> val variantLowered = variant.name.lowercase() val variantCapped = variant.name.capitalizeUS() val buildTypeLowered = variant.buildType?.lowercase() - val supportedAbis = abiList.map { - when (it) { - "arm64-v8a" -> "arm64" - else -> error("unsupported abi $it") - } - }.joinToString(" ") - val moduleDir = "$buildDir/outputs/module/$variantLowered" + val libOutDir = layout.buildDirectory.dir("intermediates/stripped_native_libs/$variantLowered/out/lib").get() + val moduleDir = layout.buildDirectory.dir("outputs/module/$variantLowered").get() + val zipOutDir = layout.buildDirectory.dir("outputs/release").get() val zipFileName = "$moduleName-$verName-$verCode-$buildTypeLowered.zip".replace(' ', '-') val prepareModuleFilesTask = task("prepareModuleFiles$variantCapped") { group = "module" dependsOn("assemble$variantCapped") into(moduleDir) - from("${rootProject.projectDir}/README.md") - from("$projectDir/template") { - exclude("module.prop", "customize.sh", "post-fs-data.sh", "service.sh") - filter("eol" to FixCrLfFilter.CrLf.newInstance("lf")) - } from("$projectDir/template") { include("module.prop") expand( @@ -65,77 +53,24 @@ androidComponents.onVariants { variant -> "versionCode" to verCode ) } - from("$projectDir/template") { - include("customize.sh", "post-fs-data.sh", "service.sh") - val tokens = mapOf( - "DEBUG" to if (buildTypeLowered == "debug") "true" else "false", - "SONAME" to moduleId, - "SUPPORTED_ABIS" to supportedAbis - ) - filter("tokens" to tokens) - filter("eol" to FixCrLfFilter.CrLf.newInstance("lf")) + from(libOutDir) { + into("zygisk") } - from("$buildDir/intermediates/stripped_native_libs/$variantLowered/out/lib") { - into("lib") - } - doLast { - fileTree(moduleDir).visit { - if (isDirectory) return@visit - val md = MessageDigest.getInstance("SHA-256") - file.forEachBlock(4096) { bytes, size -> - md.update(bytes, 0, size) - } - file(file.path + ".sha256").writeText(org.apache.commons.codec.binary.Hex.encodeHexString(md.digest())) + moduleDir.dir("zygisk").asFile.listFiles { f -> f.isDirectory }?.forEach { sourceDir -> + val srcFile = file("$sourceDir/libzygisk.so") + val dstFile = moduleDir.file("zygisk/${sourceDir.name}.so") + srcFile.copyTo(dstFile.asFile, overwrite=true) + delete(sourceDir) } } } - val zipTask = task("zip$variantCapped") { + task("zip$variantCapped") { group = "module" dependsOn(prepareModuleFilesTask) archiveFileName.set(zipFileName) - destinationDirectory.set(file("$buildDir/outputs/release")) + destinationDirectory.set(zipOutDir) from(moduleDir) } - - val pushTask = task("push$variantCapped") { - group = "module" - dependsOn(zipTask) - commandLine("adb", "push", zipTask.outputs.files.singleFile.path, "/data/local/tmp") - } - - val installKsuTask = task("installKsu$variantCapped") { - group = "module" - dependsOn(pushTask) - doLast { - exec { - commandLine( - "adb", "shell", "echo", - "/data/adb/ksud module install /data/local/tmp/$zipFileName", - "> /data/local/tmp/install.sh" - ) - } - exec { commandLine("adb", "shell", "chmod", "755", "/data/local/tmp/install.sh") } - exec { commandLine("adb", "shell", "su", "-c", "/data/local/tmp/install.sh") } - } - } - - val installMagiskTask = task("installMagisk$variantCapped") { - group = "module" - dependsOn(pushTask) - commandLine("adb", "shell", "su", "-c", "magisk --install-module /data/local/tmp/$zipFileName") - } - - task("installKsuAndReboot$variantCapped") { - group = "module" - dependsOn(installKsuTask) - commandLine("adb", "reboot") - } - - task("installMagiskAndReboot$variantCapped") { - group = "module" - dependsOn(installMagiskTask) - commandLine("adb", "reboot") - } } diff --git a/module/jni/Android.mk b/module/jni/Android.mk index e2731c1..746588e 100644 --- a/module/jni/Android.mk +++ b/module/jni/Android.mk @@ -1,8 +1,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_MODULE := qingyue -LOCAL_SRC_FILES := qingyue.cpp +LOCAL_MODULE := zygisk +LOCAL_SRC_FILES := main.cpp LOCAL_STATIC_LIBRARIES := libcxx LOCAL_LDLIBS := -llog include $(BUILD_SHARED_LIBRARY) diff --git a/module/jni/Application.mk b/module/jni/Application.mk index 8214ad2..fc0f7c8 100644 --- a/module/jni/Application.mk +++ b/module/jni/Application.mk @@ -1,4 +1,4 @@ -APP_ABI := arm64-v8a +APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 APP_CPPFLAGS := -std=c++17 -fno-exceptions -fno-rtti -fvisibility=hidden -fvisibility-inlines-hidden APP_STL := none APP_PLATFORM := android-29 diff --git a/module/jni/qingyue.cpp b/module/jni/main.cpp similarity index 94% rename from module/jni/qingyue.cpp rename to module/jni/main.cpp index 9ea34f2..bc0e312 100644 --- a/module/jni/qingyue.cpp +++ b/module/jni/main.cpp @@ -23,7 +23,7 @@ using zygisk::Api; using zygisk::AppSpecializeArgs; using zygisk::ServerSpecializeArgs; -class Qingyue : public zygisk::ModuleBase { +class ZygiskModule : public zygisk::ModuleBase { public: void onLoad(Api *api, JNIEnv *env) override { this->api = api; @@ -54,4 +54,4 @@ private: }; -REGISTER_ZYGISK_MODULE(Qingyue) +REGISTER_ZYGISK_MODULE(ZygiskModule) diff --git a/module/template/boot-completed.sh b/module/template/boot-completed.sh deleted file mode 100644 index e0e74a6..0000000 --- a/module/template/boot-completed.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh - -resetprop sys.oem_unlock_allowed 0 -resetprop init.svc.adbd stopped diff --git a/module/template/credits b/module/template/credits deleted file mode 100644 index 546d5fd..0000000 --- a/module/template/credits +++ /dev/null @@ -1 +0,0 @@ -samurai for boot-completed \ No newline at end of file diff --git a/module/template/customize.sh b/module/template/customize.sh deleted file mode 100644 index 61ca2f5..0000000 --- a/module/template/customize.sh +++ /dev/null @@ -1,31 +0,0 @@ -SKIPUNZIP=1 - -SONAME=@SONAME@ - -VERSION=$(grep_prop version "${TMPDIR}/module.prop") -ui_print "- Installing $SONAME $VERSION" - -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 "$ZIPFILE" 'customize.sh' "$TMPDIR/.vunzip" -extract "$ZIPFILE" 'verify.sh' "$TMPDIR/.vunzip" - -ui_print "- Extracting module files" -extract "$ZIPFILE" 'module.prop' "$MODPATH" -extract "$ZIPFILE" "credits" "$MODPATH" -extract "$ZIPFILE" "boot-completed.sh" "$MODPATH" - -chmod -R 755 "$MODPATH/*" - -mkdir "$MODPATH/zygisk" - -ui_print "- Extracting arm64 libraries" -extract "$ZIPFILE" "lib/arm64-v8a/lib$SONAME.so" "$MODPATH/zygisk" true -mv "$MODPATH/zygisk/lib$SONAME.so" "$MODPATH/zygisk/arm64-v8a.so" \ No newline at end of file diff --git a/module/template/verify.sh b/module/template/verify.sh deleted file mode 100644 index 45e0521..0000000 --- a/module/template/verify.sh +++ /dev/null @@ -1,51 +0,0 @@ -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 -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").sha256" - else - file_path="$dir/$file" - hash_path="$TMPDIR_FOR_VERIFY/$file.sha256" - fi - - unzip $opts "$zip" "$file" -d "$dir" >&2 - [ -f "$file_path" ] || abort_verify "$file not exists" - - unzip $opts "$zip" "$file.sha256" -d "$TMPDIR_FOR_VERIFY" >&2 - [ -f "$hash_path" ] || abort_verify "$file.sha256 not exists" - - (echo "$(cat "$hash_path") $file_path" | sha256sum -c -s -) || abort_verify "Failed to verify $file" - ui_print "- Verified $file" >&1 -} - -file="META-INF/com/google/android/update-binary" -file_path="$TMPDIR_FOR_VERIFY/$file" -hash_path="$file_path.sha256" -unzip -o "$ZIPFILE" "META-INF/com/google/android/*" -d "$TMPDIR_FOR_VERIFY" >&2 -[ -f "$file_path" ] || abort_verify "$file not exists" -if [ -f "$hash_path" ]; then - (echo "$(cat "$hash_path") $file_path" | sha256sum -c -s -) || abort_verify "Failed to verify $file" - ui_print "- Verified $file" >&1 -else - ui_print "- Download from Magisk app" -fi diff --git a/settings.gradle.kts b/settings.gradle.kts index 17b704e..9bf84ad 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -14,7 +14,6 @@ dependencyResolutionManagement { } } -rootProject.name = "qingyue" include( ":module" )