Update high compression mode detection logic

This commit is contained in:
topjohnwu 2018-03-10 15:55:55 +08:00
parent 0b3192c4d5
commit 9e737df534
3 changed files with 30 additions and 13 deletions

View File

@ -34,18 +34,22 @@ static void cpio_patch(struct vector *v, int keepverity, int keepforceencrypt) {
#define STOCK_BOOT 0x0 #define STOCK_BOOT 0x0
#define MAGISK_PATCH 0x1 #define MAGISK_PATCH 0x1
#define OTHER_PATCH 0x2 #define HIGH_COMPRESS 0x2
#define OTHER_PATCH 0x3
static int cpio_test(struct vector *v) { 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 *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 }; const char *MAGISK_LIST[] = { ".backup/.magisk", "init.magisk.rc", "overlay/init.magisk.rc", NULL };
for (int i = 0; OTHER_LIST[i]; ++i) 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; return OTHER_PATCH;
if (cpio_find(v, "ramdisk.cpio.xz") >= 0)
return HIGH_COMPRESS;
for (int i = 0; MAGISK_LIST[i]; ++i) 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 MAGISK_PATCH;
return STOCK_BOOT; return STOCK_BOOT;

View File

@ -91,9 +91,7 @@ case $? in
abort "! Unable to unpack boot image" abort "! Unable to unpack boot image"
;; ;;
2 ) 2 )
ui_print "! Insufficient boot partition size detected"
HIGHCOMP=true HIGHCOMP=true
ui_print "- Enable high compression mode"
;; ;;
3 ) 3 )
ui_print "- ChromeOS boot image detected" 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 # Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
ui_print "- Checking ramdisk status" ui_print "- Checking ramdisk status"
MAGISK_PATCHED=false
./magiskboot --cpio ramdisk.cpio test ./magiskboot --cpio ramdisk.cpio test
case $? in case $? in
0 ) # Stock boot 0 ) # Stock boot
@ -125,18 +124,32 @@ case $? in
cp -af ramdisk.cpio ramdisk.cpio.orig cp -af ramdisk.cpio ramdisk.cpio.orig
;; ;;
1 ) # Magisk patched 1 ) # Magisk patched
ui_print "- Magisk patched image detected" MAGISK_PATCHED=true
# Find SHA1 of stock boot image HIGHCOMP=false
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
./magiskboot --cpio ramdisk.cpio restore
cp -af ramdisk.cpio ramdisk.cpio.orig
;; ;;
2 ) # Other patched 2 ) # High compression mode
MAGISK_PATCHED=true
HIGHCOMP=true
;;
3 ) # Other patched
ui_print "! Boot image patched by other programs" ui_print "! Boot image patched by other programs"
abort "! Please restore stock boot image" abort "! Please restore stock boot image"
;; ;;
esac 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 # Ramdisk patches
########################################################################################## ##########################################################################################

View File

@ -73,7 +73,7 @@ case $? in
ui_print "- Stock boot image detected" ui_print "- Stock boot image detected"
abort "! Magisk is not installed!" abort "! Magisk is not installed!"
;; ;;
1 ) # Magisk patched 1|2 ) # Magisk patched
ui_print "- Magisk patched image detected" ui_print "- Magisk patched image detected"
# Find SHA1 of stock boot image # Find SHA1 of stock boot image
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null` [ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
@ -89,7 +89,7 @@ case $? in
flash_boot_image new-boot.img "$BOOTIMAGE" flash_boot_image new-boot.img "$BOOTIMAGE"
fi fi
;; ;;
2 ) # Other patched 3 ) # Other patched
ui_print "! Boot image patched by other programs" ui_print "! Boot image patched by other programs"
abort "! Cannot uninstall" abort "! Cannot uninstall"
;; ;;