From 9b5eb1bac766831a450ab03fa5effaaae28c1eb6 Mon Sep 17 00:00:00 2001 From: Nullptr Date: Fri, 17 Feb 2023 21:08:19 +0800 Subject: [PATCH] Support Magisk out of box --- README.md | 13 +--------- module/build.gradle.kts | 2 +- module/src/customize.sh | 51 +++++++++++++++++++++++--------------- module/src/post-fs-data.sh | 18 +++++++++++++- module/src/service.sh | 21 ++++++++++++++++ 5 files changed, 71 insertions(+), 34 deletions(-) create mode 100644 module/src/service.sh diff --git a/README.md b/README.md index aa9194c..cbc6c9d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Zygisk loader for KernelSU, allowing Zygisk modules to run without Magisk environment. -Also works as standalone loader for Magisk on purpose of getting rid of LD_PRELOAD. (Coming soon) +Also works as standalone loader for Magisk on purpose of getting rid of LD_PRELOAD. ## Requirements @@ -13,14 +13,3 @@ Also works as standalone loader for Magisk on purpose of getting rid of LD_PRELO ## Compatibility Should work with everything except those rely on Magisk internal behaviors. - -## Development road map - -- [x] [Inject] Basic Zygisk loader -- [x] [Inject] Stabilize injector -- [x] [Inject] Unload -- [x] [Daemon] Linker namespace -- [x] [Daemon] Separate zygiskd process -- [x] [Daemon] Handle 64 bit only devices -- [x] [Daemon] Handle zygote death -- [ ] [ Misc ] Support Magisk out of box diff --git a/module/build.gradle.kts b/module/build.gradle.kts index 67652dd..7a39072 100644 --- a/module/build.gradle.kts +++ b/module/build.gradle.kts @@ -106,7 +106,7 @@ androidComponents.onVariants { variant -> val installMagiskTask = task("installMagisk$variantCapped") { group = "module" dependsOn(pushTask) - commandLine("adb", "shell", "su", "-c", "KSU=true magisk --install-module /data/local/tmp/$zipFileName") + commandLine("adb", "shell", "su", "-c", "magisk --install-module /data/local/tmp/$zipFileName") } task("installKsuAndReboot$variantCapped") { diff --git a/module/src/customize.sh b/module/src/customize.sh index a9dea3a..9ed74a2 100644 --- a/module/src/customize.sh +++ b/module/src/customize.sh @@ -3,27 +3,33 @@ SKIPUNZIP=1 DEBUG=@DEBUG@ -if [ $BOOTMODE ] && [ "$KSU" == "true" ]; then +if [ "$BOOTMODE" ] && [ "$KSU" ]; then ui_print "- Installing from KernelSU app" + ui_print "- KernelSU version: $KSU_KERNEL_VER_CODE (kernel) + $KSU_VER_CODE (ksud)" + if [ "$KSU_KERNEL_VER_CODE" ] && [ "$KSU_KERNEL_VER_CODE" -lt 10575 ]; then + ui_print "*********************************************************" + ui_print "! KernelSU version is too old!" + ui_print "! Please update KernelSU to latest version" + abort "*********************************************************" + fi +elif [ "$BOOTMODE" ] && [ "$MAGISK_VER_CODE" ]; then + ui_print "- Installing from Magisk app" + if [ "$MAGISK_VER_CODE" -lt 25000 ]; then + ui_print "*********************************************************" + ui_print "! Magisk version is too old!" + ui_print "! Please update Magisk to latest version" + abort "*********************************************************" + fi else ui_print "*********************************************************" - ui_print "! Install from recovery or Magisk is NOT supported" - ui_print "! Please install from KernelSU app" - abort "*********************************************************" + ui_print "! Install from recovery is not supported" + ui_print "! Please install from KernelSU or Magisk app" + abort "*********************************************************" fi VERSION=$(grep_prop version "${TMPDIR}/module.prop") ui_print "- Installing Zygisksu $VERSION" -# check KernelSU -ui_print "- KernelSU version: $KSU_KERNEL_VER_CODE (kernel) + $KSU_VER_CODE (ksud)" -if [ "$KSU_KERNEL_VER_CODE" -lt 10575 ]; then - ui_print "*********************************************************" - ui_print "! KernelSU version is too old!" - ui_print "! Please update KernelSU to latest version" - abort "*********************************************************" -fi - # check android if [ "$API" -lt 29 ]; then ui_print "! Unsupported sdk: $API" @@ -52,19 +58,24 @@ extract "$ZIPFILE" 'customize.sh' "$TMPDIR/.vunzip" extract "$ZIPFILE" 'verify.sh' "$TMPDIR/.vunzip" extract "$ZIPFILE" 'sepolicy.rule' "$TMPDIR" -ui_print "- Checking SELinux patches" -if ! check_sepolicy "$TMPDIR/sepolicy.rule"; then - ui_print "*********************************************************" - ui_print "! Unable to apply SELinux patches!" - ui_print "! Your kernel may not support SELinux patch fully" - abort "*********************************************************" +if [ "$KSU" ]; then + ui_print "- Checking SELinux patches" + if ! check_sepolicy "$TMPDIR/sepolicy.rule"; then + ui_print "*********************************************************" + ui_print "! Unable to apply SELinux patches!" + ui_print "! Your kernel may not support SELinux patch fully" + abort "*********************************************************" + fi fi ui_print "- Extracting module files" extract "$ZIPFILE" 'daemon.sh' "$MODPATH" extract "$ZIPFILE" 'module.prop' "$MODPATH" extract "$ZIPFILE" 'post-fs-data.sh' "$MODPATH" -extract "$ZIPFILE" 'sepolicy.rule' "$MODPATH" +extract "$ZIPFILE" 'service.sh' "$MODPATH" +if [ "$KSU" ]; then + extract "$ZIPFILE" 'sepolicy.rule' "$MODPATH" +fi HAS32BIT=false && [ -d "/system/lib" ] && HAS32BIT=true HAS64BIT=false && [ -d "/system/lib64" ] && HAS64BIT=true diff --git a/module/src/post-fs-data.sh b/module/src/post-fs-data.sh index 95563b0..dd9beee 100644 --- a/module/src/post-fs-data.sh +++ b/module/src/post-fs-data.sh @@ -1,8 +1,24 @@ #!/system/bin/sh MODDIR=${0%/*} +if [ "$ZYGISK_ENABLED" ]; then + exit 0 +fi -cd $MODDIR +cd "$MODDIR" export NATIVE_BRIDGE=$(getprop ro.dalvik.vm.native.bridge) +if [ $(which magisk) ] && [ ".." -ef "/data/adb/modules" ]; then + for file in ../*; do + if [ -d "$file" ] && [ -d "$file/zygisk" ] && ! [ -f "$file/disable" ]; then + if [ -f "$file/post-fs-data.sh" ]; then + cd "$file" + log -p i -t "zygisksu" "Manually trigger post-fs-data.sh for $file" + sh "$(realpath ./post-fs-data.sh)" + cd "$MODDIR" + fi + fi + done +fi + unshare -m sh -c "./daemon.sh $@&" diff --git a/module/src/service.sh b/module/src/service.sh new file mode 100644 index 0000000..2819816 --- /dev/null +++ b/module/src/service.sh @@ -0,0 +1,21 @@ +#!/system/bin/sh + +MODDIR=${0%/*} +if [ "$ZYGISK_ENABLED" ]; then + exit 0 +fi + +cd "$MODDIR" + +if [ $(which magisk) ] && [ ".." -ef "/data/adb/modules" ]; then + for file in ../*; do + if [ -d "$file" ] && [ -d "$file/zygisk" ] && ! [ -f "$file/disable" ]; then + if [ -f "$file/service.sh" ]; then + cd "$file" + log -p i -t "zygisksu" "Manually trigger service.sh for $file" + sh "$(realpath ./service.sh)" + cd "$MODDIR" + fi + fi + done +fi