diff --git a/native/src/base/files.hpp b/native/src/base/files.hpp index 2aa81a055..3d5a53c80 100644 --- a/native/src/base/files.hpp +++ b/native/src/base/files.hpp @@ -66,7 +66,7 @@ struct heap_data : public byte_data { MOVE_ONLY(heap_data) explicit heap_data(size_t sz) { this->sz = sz; buf = new uint8_t[sz]; } - ~heap_data() { free(buf); } + ~heap_data() { delete[] buf; } }; struct mmap_data : public byte_data { diff --git a/native/src/boot/cpio.cpp b/native/src/boot/cpio.cpp index 079cb1088..f0c0b72f7 100644 --- a/native/src/boot/cpio.cpp +++ b/native/src/boot/cpio.cpp @@ -76,7 +76,7 @@ void cpio::rm(const char *name, bool r) { } } -void cpio::extract_entry(const entry_map::value_type &e, const char *file) { +static void extract_entry(const cpio::entry_map::value_type &e, const char *file) { fprintf(stderr, "Extract [%s] to [%s]\n", e.first.data(), file); unlink(file); rmdir(file); diff --git a/native/src/boot/cpio.hpp b/native/src/boot/cpio.hpp index 3feb9fb46..3a0f2d255 100644 --- a/native/src/boot/cpio.hpp +++ b/native/src/boot/cpio.hpp @@ -44,7 +44,6 @@ public: protected: entry_map entries; - static void extract_entry(const entry_map::value_type &e, const char *file); void rm(entry_map::iterator it); void mv(entry_map::iterator it, const char *name); diff --git a/native/src/boot/main.cpp b/native/src/boot/main.cpp index f7d274024..2cdbc36d5 100644 --- a/native/src/boot/main.cpp +++ b/native/src/boot/main.cpp @@ -85,8 +85,6 @@ Supported actions: Create ramdisk backups from ORIG restore Restore ramdisk from ramdisk backup stored within incpio - sha1 - Print stock boot SHA1 if previously backed up in ramdisk dtb [args...] Do dtb related actions to diff --git a/native/src/boot/ramdisk.cpp b/native/src/boot/ramdisk.cpp index c94c0a833..72ac8b327 100644 --- a/native/src/boot/ramdisk.cpp +++ b/native/src/boot/ramdisk.cpp @@ -18,7 +18,6 @@ class magisk_cpio : public cpio { public: void patch(); int test(); - char *sha1(); void restore(); void backup(const char *orig); }; @@ -81,35 +80,6 @@ int magisk_cpio::test() { return ret; } -#define for_each_line(line, buf, size) \ -for (char *line = (char *) buf; line < (char *) buf + size && line[0]; line = strchr(line + 1, '\n') + 1) - -char *magisk_cpio::sha1() { - char sha1[41]; - for (auto &e : entries) { - if (e.first == "init.magisk.rc" || e.first == "overlay/init.magisk.rc") { - for_each_line(line, e.second->data, e.second->filesize) { - if (strncmp(line, "#STOCKSHA1=", 11) == 0) { - strncpy(sha1, line + 12, 40); - sha1[40] = '\0'; - return strdup(sha1); - } - } - } else if (e.first == ".backup/.magisk") { - for_each_line(line, e.second->data, e.second->filesize) { - if (str_starts(line, "SHA1=")) { - strncpy(sha1, line + 5, 40); - sha1[40] = '\0'; - return strdup(sha1); - } - } - } else if (e.first == ".backup/.sha1") { - return (char *) e.second->data; - } - } - return nullptr; -} - #define for_each_str(str, buf, size) \ for (char *str = (char *) buf; str < (char *) buf + size; str += strlen(str) + 1) @@ -263,10 +233,6 @@ int cpio_commands(int argc, char *argv[]) { exit(cpio.test()); } else if (cmdv[0] == "restore"sv) { cpio.restore(); - } else if (cmdv[0] == "sha1"sv) { - char *sha1 = cpio.sha1(); - if (sha1) printf("%s\n", sha1); - return 0; } else if (cmdv[0] == "patch"sv) { cpio.patch(); } else if (cmdc == 2 && cmdv[0] == "exists"sv) { diff --git a/scripts/boot_patch.sh b/scripts/boot_patch.sh index d5322b4d7..004f6781b 100644 --- a/scripts/boot_patch.sh +++ b/scripts/boot_patch.sh @@ -125,9 +125,9 @@ case $((STATUS & 3)) in ;; 1 ) # Magisk patched ui_print "- Magisk patched boot image detected" - # Find SHA1 of stock boot image - [ -z $SHA1 ] && SHA1=$(./magiskboot cpio ramdisk.cpio sha1 2>/dev/null) - ./magiskboot cpio ramdisk.cpio restore + ./magiskboot cpio ramdisk.cpio \ + "extract .backup/.magisk config.orig" \ + "restore" cp -af ramdisk.cpio ramdisk.cpio.orig rm -f stock_boot.img ;; @@ -143,6 +143,17 @@ if [ $((STATUS & 4)) -ne 0 ]; then INIT=init.real fi +if [ -f config.orig ]; then + # Read existing configs + chmod 0644 config.orig + SHA1=$(grep_prop SHA1 config.orig) + if ! $BOOTMODE; then + # Do not inherit config if not in recovery + PREINITDEVICE=$(grep_prop PREINITDEVICE config.orig) + fi + rm config.orig +fi + ################## # Ramdisk Patches ################## @@ -169,7 +180,7 @@ echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config echo "PATCHVBMETAFLAG=$PATCHVBMETAFLAG" >> config echo "RECOVERYMODE=$RECOVERYMODE" >> config if [ -n "$PREINITDEVICE" ]; then - ui_print "- Pre-init storage partition device ID: $PREINITDEVICE" + ui_print "- Pre-init storage partition: $PREINITDEVICE" echo "PREINITDEVICE=$PREINITDEVICE" >> config fi [ -n "$SHA1" ] && echo "SHA1=$SHA1" >> config diff --git a/scripts/uninstaller.sh b/scripts/uninstaller.sh index 3fa6c1fb9..aa8780164 100644 --- a/scripts/uninstaller.sh +++ b/scripts/uninstaller.sh @@ -104,7 +104,12 @@ case $((STATUS & 3)) in 1 ) # Magisk patched ui_print "- Magisk patched image detected" # Find SHA1 of stock boot image - SHA1=$(./magiskboot cpio ramdisk.cpio sha1 2>/dev/null) + ./magiskboot cpio ramdisk.cpio "extract .backup/.magisk config.orig" + if [ -f config.orig ]; then + chmod 0644 config.orig + SHA1=$(grep_prop SHA1 config.orig) + rm config.orig + fi BACKUPDIR=/data/magisk_backup_$SHA1 if [ -d $BACKUPDIR ]; then ui_print "- Restoring stock boot image"