diff --git a/native/jni/magiskboot/ramdisk.c b/native/jni/magiskboot/ramdisk.c index 88dabf1ce..cb9c37c85 100644 --- a/native/jni/magiskboot/ramdisk.c +++ b/native/jni/magiskboot/ramdisk.c @@ -34,18 +34,22 @@ static void cpio_patch(struct vector *v, int keepverity, int keepforceencrypt) { #define STOCK_BOOT 0x0 #define MAGISK_PATCH 0x1 -#define OTHER_PATCH 0x2 +#define HIGH_COMPRESS 0x2 +#define OTHER_PATCH 0x3 static int cpio_test(struct vector *v) { const char *OTHER_LIST[] = { "sbin/launch_daemonsu.sh", "sbin/su", "init.xposed.rc", "boot/sbin/launch_daemonsu.sh", NULL }; const char *MAGISK_LIST[] = { ".backup/.magisk", "init.magisk.rc", "overlay/init.magisk.rc", NULL }; for (int i = 0; OTHER_LIST[i]; ++i) - if (cpio_find(v, OTHER_LIST[i]) > 0) + if (cpio_find(v, OTHER_LIST[i]) >= 0) return OTHER_PATCH; + if (cpio_find(v, "ramdisk.cpio.xz") >= 0) + return HIGH_COMPRESS; + for (int i = 0; MAGISK_LIST[i]; ++i) - if (cpio_find(v, MAGISK_LIST[i]) > 0) + if (cpio_find(v, MAGISK_LIST[i]) >= 0) return MAGISK_PATCH; return STOCK_BOOT; diff --git a/scripts/boot_patch.sh b/scripts/boot_patch.sh index 72e1a8f04..971da273b 100644 --- a/scripts/boot_patch.sh +++ b/scripts/boot_patch.sh @@ -91,9 +91,7 @@ case $? in abort "! Unable to unpack boot image" ;; 2 ) - ui_print "! Insufficient boot partition size detected" HIGHCOMP=true - ui_print "- Enable high compression mode" ;; 3 ) ui_print "- ChromeOS boot image detected" @@ -114,6 +112,7 @@ esac # Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist ui_print "- Checking ramdisk status" +MAGISK_PATCHED=false ./magiskboot --cpio ramdisk.cpio test case $? in 0 ) # Stock boot @@ -125,18 +124,32 @@ case $? in cp -af ramdisk.cpio ramdisk.cpio.orig ;; 1 ) # Magisk patched - ui_print "- Magisk patched image detected" - # Find SHA1 of stock boot image - [ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null` - ./magiskboot --cpio ramdisk.cpio restore - cp -af ramdisk.cpio ramdisk.cpio.orig + MAGISK_PATCHED=true + HIGHCOMP=false ;; - 2 ) # Other patched + 2 ) # High compression mode + MAGISK_PATCHED=true + HIGHCOMP=true + ;; + 3 ) # Other patched ui_print "! Boot image patched by other programs" abort "! Please restore stock boot image" ;; esac +if $MAGISK_PATCHED; then + ui_print "- Magisk patched image detected" + # Find SHA1 of stock boot image + [ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null` + ./magiskboot --cpio ramdisk.cpio restore + cp -af ramdisk.cpio ramdisk.cpio.orig +fi + +if $HIGHCOMP; then + ui_print "! Insufficient boot partition size detected" + ui_print "- Enable high compression mode" +fi + ########################################################################################## # Ramdisk patches ########################################################################################## diff --git a/scripts/magisk_uninstaller.sh b/scripts/magisk_uninstaller.sh index b9142bd59..31d357a30 100644 --- a/scripts/magisk_uninstaller.sh +++ b/scripts/magisk_uninstaller.sh @@ -73,7 +73,7 @@ case $? in ui_print "- Stock boot image detected" abort "! Magisk is not installed!" ;; - 1 ) # Magisk patched + 1|2 ) # Magisk patched ui_print "- Magisk patched image detected" # Find SHA1 of stock boot image [ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null` @@ -89,7 +89,7 @@ case $? in flash_boot_image new-boot.img "$BOOTIMAGE" fi ;; - 2 ) # Other patched + 3 ) # Other patched ui_print "! Boot image patched by other programs" abort "! Cannot uninstall" ;;