Simplify ramdisk test

This commit is contained in:
topjohnwu 2024-08-21 01:08:07 -07:00
parent c2eb603957
commit 7cf56b4406
2 changed files with 11 additions and 11 deletions

View File

@ -175,9 +175,8 @@ Supported commands:
extract [ENTRY OUT] extract [ENTRY OUT]
Extract ENTRY to OUT, or extract all entries to current directory Extract ENTRY to OUT, or extract all entries to current directory
test test
Test the cpio's status Test the cpio's status. Return values:
Return value is 0 or bitwise or-ed of following values: 0:stock 1:Magisk 2:unsupported
0x1:Magisk 0x2:unsupported
patch patch
Apply ramdisk patches Apply ramdisk patches
Configure with env variables: KEEPVERITY KEEPFORCEENCRYPT Configure with env variables: KEEPVERITY KEEPFORCEENCRYPT
@ -544,7 +543,6 @@ impl Cpio {
} }
fn test(&self) -> i32 { fn test(&self) -> i32 {
let mut ret = 0;
for file in [ for file in [
"sbin/launch_daemonsu.sh", "sbin/launch_daemonsu.sh",
"sbin/su", "sbin/su",
@ -561,11 +559,10 @@ impl Cpio {
"overlay/init.magisk.rc", "overlay/init.magisk.rc",
] { ] {
if self.exists(file) { if self.exists(file) {
ret |= MAGISK_PATCHED; return MAGISK_PATCHED;
break;
} }
} }
ret 0
} }
fn restore(&mut self) -> LoggedResult<()> { fn restore(&mut self) -> LoggedResult<()> {

View File

@ -119,14 +119,16 @@ else
STATUS=0 STATUS=0
SKIP_BACKUP="#" SKIP_BACKUP="#"
fi fi
case $((STATUS & 3)) in case $STATUS in
0 ) # Stock boot 0 )
# Stock boot
ui_print "- Stock boot image detected" ui_print "- Stock boot image detected"
SHA1=$(./magiskboot sha1 "$BOOTIMAGE" 2>/dev/null) SHA1=$(./magiskboot sha1 "$BOOTIMAGE" 2>/dev/null)
cat $BOOTIMAGE > stock_boot.img cat $BOOTIMAGE > stock_boot.img
cp -af ramdisk.cpio ramdisk.cpio.orig 2>/dev/null cp -af ramdisk.cpio ramdisk.cpio.orig 2>/dev/null
;; ;;
1 ) # Magisk patched 1 )
# Magisk patched
ui_print "- Magisk patched boot image detected" ui_print "- Magisk patched boot image detected"
./magiskboot cpio ramdisk.cpio \ ./magiskboot cpio ramdisk.cpio \
"extract .backup/.magisk config.orig" \ "extract .backup/.magisk config.orig" \
@ -134,7 +136,8 @@ case $((STATUS & 3)) in
cp -af ramdisk.cpio ramdisk.cpio.orig cp -af ramdisk.cpio ramdisk.cpio.orig
rm -f stock_boot.img rm -f stock_boot.img
;; ;;
2 ) # Unsupported 2 )
# Unsupported
ui_print "! Boot image patched by unsupported programs" ui_print "! Boot image patched by unsupported programs"
abort "! Please restore back to stock boot image" abort "! Please restore back to stock boot image"
;; ;;