New uninstaller
This commit is contained in:
parent
c8216f9bc5
commit
3283439fd4
2
app
2
app
@ -1 +1 @@
|
||||
Subproject commit 4ff39f88172ce7da33ad0a5063a7c75894f6e48c
|
||||
Subproject commit e86015badc0d6aa3b633bd9cb50620bbf05819b6
|
22
build.py
22
build.py
@ -106,7 +106,7 @@ def build_binary(args):
|
||||
header('* Building binaries: ' + ' '.join(targets))
|
||||
|
||||
# Force update logging.h timestamp to trigger recompilation for the flags to make a difference
|
||||
os.utime(os.path.join('native', 'jni', 'include', 'logging.h'))
|
||||
|
||||
|
||||
# Basic flags
|
||||
base_flags = 'MAGISK_VERSION=\"{}\" MAGISK_VER_CODE={} MAGISK_DEBUG={}'.format(config['version'], config['versionCode'],
|
||||
@ -196,10 +196,9 @@ def build_apk(args):
|
||||
header('* Building Magisk Manager')
|
||||
|
||||
mkdir(os.path.join('app', 'src', 'full', 'assets'))
|
||||
for script in ['magisk_uninstaller.sh', 'util_functions.sh']:
|
||||
source = os.path.join('scripts', script)
|
||||
target = os.path.join('app', 'src', 'full', 'assets', script)
|
||||
cp(source, target)
|
||||
source = os.path.join('scripts', 'util_functions.sh')
|
||||
target = os.path.join('app', 'src', 'full', 'assets', 'util_functions.sh')
|
||||
cp(source, target)
|
||||
|
||||
if args.release:
|
||||
if not os.path.exists('release-key.jks'):
|
||||
@ -354,19 +353,16 @@ def zip_uninstaller(args):
|
||||
print('zip: ' + target)
|
||||
zipf.writestr(target, gen_update_binary())
|
||||
# updater-script
|
||||
source = os.path.join('scripts', 'uninstaller_loader.sh')
|
||||
source = os.path.join('scripts', 'magisk_uninstaller.sh')
|
||||
target = os.path.join('META-INF', 'com', 'google', 'android', 'updater-script')
|
||||
zip_with_msg(zipf, source, target)
|
||||
|
||||
# Binaries
|
||||
for lib_dir, zip_dir in [('armeabi-v7a', 'arm'), ('x86', 'x86')]:
|
||||
source = os.path.join('native', 'out', lib_dir, 'magiskboot')
|
||||
target = os.path.join(zip_dir, 'magiskboot')
|
||||
zip_with_msg(zipf, source, target)
|
||||
|
||||
source = os.path.join('scripts', 'magisk_uninstaller.sh')
|
||||
target = 'magisk_uninstaller.sh'
|
||||
zip_with_msg(zipf, source, target)
|
||||
for bin in ['magisk', 'magiskboot']:
|
||||
source = os.path.join('native', 'out', lib_dir, bin)
|
||||
target = os.path.join(zip_dir, bin)
|
||||
zip_with_msg(zipf, source, target)
|
||||
|
||||
# Scripts
|
||||
# util_functions.sh
|
||||
|
@ -1,45 +1,62 @@
|
||||
#!/system/bin/sh
|
||||
#MAGISK
|
||||
##########################################################################################
|
||||
#
|
||||
# Magisk Uninstaller
|
||||
# Magisk Uninstaller (used in recovery)
|
||||
# by topjohnwu
|
||||
#
|
||||
# This script can be placed in /cache/magisk_uninstaller.sh
|
||||
# The Magisk main binary will pick up the script, and uninstall itself, following a reboot
|
||||
# This script can also be used in flashable zip with the uninstaller_loader.sh
|
||||
#
|
||||
# This script will try to do restoration with the following:
|
||||
# 1-1. Find and restore the original stock boot image dump (OTA proof)
|
||||
# 1-2. If 1-1 fails, restore ramdisk from the internal backup
|
||||
# (ramdisk fully restored, not OTA friendly)
|
||||
# 1-3. If 1-2 fails, it will remove added files in ramdisk, however modified files
|
||||
# are remained modified, because we have no backups. By doing so, Magisk will
|
||||
# not be started at boot, but this isn't actually 100% cleaned up
|
||||
# 2. Remove all Magisk related files
|
||||
# (The list is LARGE, most likely due to bad decision in early versions
|
||||
# the latest versions has much less bloat to cleanup)
|
||||
# This script will load the real uninstaller in a flashable zip
|
||||
#
|
||||
##########################################################################################
|
||||
|
||||
[ -z $BOOTMODE ] && BOOTMODE=false
|
||||
##########################################################################################
|
||||
# Preparation
|
||||
##########################################################################################
|
||||
|
||||
[ -d /data/adb/magisk ] && MAGISKBIN=/data/adb/magisk || MAGISKBIN=/data/magisk
|
||||
CHROMEDIR=$MAGISKBIN/chromeos
|
||||
# This path should work in any cases
|
||||
TMPDIR=/dev/tmp
|
||||
|
||||
if [ ! -f $MAGISKBIN/magiskboot -o ! -f $MAGISKBIN/util_functions.sh ]; then
|
||||
echo "! Cannot find $MAGISKBIN"
|
||||
INSTALLER=$TMPDIR/install
|
||||
CHROMEDIR=$INSTALLER/chromeos
|
||||
|
||||
# Default permissions
|
||||
umask 022
|
||||
|
||||
OUTFD=$2
|
||||
ZIP=$3
|
||||
|
||||
if [ ! -f $INSTALLER/util_functions.sh ]; then
|
||||
echo "! Unable to extract zip file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if $BOOTMODE; then
|
||||
# Load utility functions
|
||||
. $MAGISKBIN/util_functions.sh
|
||||
BOOTMODE=true
|
||||
boot_actions
|
||||
fi
|
||||
# Load utility functions
|
||||
. $INSTALLER/util_functions.sh
|
||||
|
||||
get_outfd
|
||||
|
||||
ui_print "************************"
|
||||
ui_print " Magisk Uninstaller "
|
||||
ui_print "************************"
|
||||
|
||||
is_mounted /data || mount /data || abort "! Unable to mount partitions"
|
||||
is_mounted /cache || mount /cache 2>/dev/null
|
||||
mount_partitions
|
||||
|
||||
api_level_arch_detect
|
||||
|
||||
ui_print "- Device platform: $ARCH"
|
||||
MAGISKBIN=$INSTALLER/$ARCH32
|
||||
mv $CHROMEDIR $MAGISKBIN
|
||||
chmod -R 755 $MAGISKBIN
|
||||
|
||||
check_data
|
||||
$DATA_DE || abort "! Cannot access /data, please uninstall with Magisk Manager"
|
||||
$BOOTMODE || recovery_actions
|
||||
|
||||
##########################################################################################
|
||||
# Uninstall
|
||||
##########################################################################################
|
||||
|
||||
find_boot_image
|
||||
find_dtbo_image
|
||||
|
||||
@ -64,7 +81,7 @@ case $? in
|
||||
;;
|
||||
4 )
|
||||
ui_print "! Sony ELF32 format detected"
|
||||
abort "! Please use BootBridge from @AdrianDC to flash Magisk"
|
||||
abort "! Please use BootBridge from @AdrianDC"
|
||||
;;
|
||||
5 )
|
||||
ui_print "! Sony ELF64 format detected"
|
||||
@ -80,18 +97,26 @@ case $? in
|
||||
;;
|
||||
1|2 ) # Magisk patched
|
||||
ui_print "- Magisk patched image detected"
|
||||
./magisk --unlock-blocks 2>/dev/null
|
||||
# Find SHA1 of stock boot image
|
||||
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
|
||||
OK=false
|
||||
[ ! -z $SHA1 ] && restore_imgs $SHA1 && OK=true
|
||||
if ! $OK; then
|
||||
STOCKBOOT=/data/stock_boot_${SHA1}.img.gz
|
||||
STOCKDTBO=/data/stock_dtbo.img.gz
|
||||
if [ -f $STOCKBOOT ]; then
|
||||
ui_print "- Restoring stock boot image"
|
||||
gzip -d < $STOCKBOOT | cat - /dev/zero > $BOOTIMAGE 2>/dev/null
|
||||
if [ -f $DTBOIMAGE -a -f $STOCKDTBO ]; then
|
||||
ui_print "- Restoring stock dtbo image"
|
||||
gzip -d < $STOCKDTBO > $DTBOIMAGE
|
||||
fi
|
||||
else
|
||||
ui_print "! Boot image backup unavailable"
|
||||
ui_print "- Restoring ramdisk with internal backup"
|
||||
./magiskboot --cpio ramdisk.cpio restore
|
||||
./magiskboot --repack $BOOTIMAGE
|
||||
# Sign chromeos boot
|
||||
$CHROMEOS && sign_chromeos
|
||||
flash_boot_image new-boot.img "$BOOTIMAGE"
|
||||
flash_boot_image new-boot.img $BOOTIMAGE
|
||||
fi
|
||||
;;
|
||||
3 ) # Other patched
|
||||
@ -100,17 +125,33 @@ case $? in
|
||||
;;
|
||||
esac
|
||||
|
||||
cd /
|
||||
|
||||
ui_print "- Removing Magisk files"
|
||||
rm -rf /cache/*magisk* /cache/unblock /data/*magisk* /data/cache/*magisk* /data/property/*magisk* \
|
||||
/data/Magisk.apk /data/busybox /data/custom_ramdisk_patch.sh /data/app/com.topjohnwu.magisk* \
|
||||
/data/user*/*/magisk.db /data/user*/*/com.topjohnwu.magisk /data/user*/*/.tmp.magisk.config \
|
||||
/data/adb/*magisk* 2>/dev/null
|
||||
/data/Magisk.apk /data/busybox /data/custom_ramdisk_patch.sh /data/adb/*magisk* 2>/dev/null
|
||||
|
||||
if [ -f /system/addon.d/99-magisk.sh ]; then
|
||||
mount -o rw,remount /system
|
||||
rm -f /system/addon.d/99-magisk.sh
|
||||
fi
|
||||
|
||||
$BOOTMODE && /system/bin/reboot
|
||||
# Remove persist props (for Android P+ using protobuf)
|
||||
for prop in `./magisk resetprop -p | grep -E 'persist.*magisk' | grep -oE '^\[[a-zA-Z0-9.@:_-]+\]' | tr -d '[]'`; do
|
||||
./magisk resetprop -p --delete $prop
|
||||
done
|
||||
|
||||
cd /
|
||||
|
||||
if $BOOTMODE; then
|
||||
ui_print "**********************************************"
|
||||
ui_print "* Magisk Manager will uninstall itself, and *"
|
||||
ui_print "* the device will reboot after a few seconds *"
|
||||
ui_print "**********************************************"
|
||||
(sleep 8; /system/bin/reboot)&
|
||||
else
|
||||
rm -rf /data/user*/*/*magisk* /data/app/*magisk*
|
||||
recovery_cleanup
|
||||
ui_print "- Done"
|
||||
fi
|
||||
|
||||
rm -rf $TMPDIR
|
||||
exit 0
|
||||
|
@ -1,82 +0,0 @@
|
||||
#!/sbin/sh
|
||||
##########################################################################################
|
||||
#
|
||||
# Magisk Uninstaller (used in recovery)
|
||||
# by topjohnwu
|
||||
#
|
||||
# This script will load the real uninstaller in a flashable zip
|
||||
#
|
||||
##########################################################################################
|
||||
|
||||
##########################################################################################
|
||||
# Preparation
|
||||
##########################################################################################
|
||||
|
||||
# This path should work in any cases
|
||||
TMPDIR=/dev/tmp
|
||||
|
||||
INSTALLER=$TMPDIR/install
|
||||
CHROMEDIR=$INSTALLER/chromeos
|
||||
|
||||
# Default permissions
|
||||
umask 022
|
||||
|
||||
OUTFD=$2
|
||||
ZIP=$3
|
||||
|
||||
if [ ! -f $INSTALLER/util_functions.sh ]; then
|
||||
echo "! Unable to extract zip file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load utility functions
|
||||
. $INSTALLER/util_functions.sh
|
||||
|
||||
get_outfd
|
||||
|
||||
##########################################################################################
|
||||
# Main
|
||||
##########################################################################################
|
||||
|
||||
ui_print "************************"
|
||||
ui_print " Magisk Uninstaller "
|
||||
ui_print "************************"
|
||||
|
||||
is_mounted /data || mount /data || abort "! Unable to mount partitions"
|
||||
is_mounted /cache || mount /cache 2>/dev/null
|
||||
|
||||
api_level_arch_detect
|
||||
|
||||
ui_print "- Device platform: $ARCH"
|
||||
BINDIR=$INSTALLER/$ARCH32
|
||||
chmod -R 755 $CHROMEDIR $BINDIR
|
||||
|
||||
##########################################################################################
|
||||
# Detection all done, start installing
|
||||
##########################################################################################
|
||||
|
||||
check_data
|
||||
|
||||
if $DATA_DE; then
|
||||
recovery_actions
|
||||
# Save our stock boot image dump before removing it
|
||||
mv $MAGISKBIN/stock_boot* /data 2>/dev/null
|
||||
rm -rf $MAGISKBIN 2>/dev/null
|
||||
mkdir -p $MAGISKBIN
|
||||
cp -af $BINDIR/. $CHROMEDIR $TMPDIR/bin/busybox $INSTALLER/util_functions.sh $MAGISKBIN
|
||||
chmod -R 755 $MAGISKBIN
|
||||
# Run the actual uninstallation
|
||||
. $INSTALLER/magisk_uninstaller.sh
|
||||
recovery_cleanup
|
||||
else
|
||||
ui_print "! Data unavailable"
|
||||
ui_print "! Placing uninstall script to /cache"
|
||||
ui_print "! The device might reboot multiple times"
|
||||
cp -af $INSTALLER/magisk_uninstaller.sh /cache/magisk_uninstaller.sh
|
||||
ui_print "- Rebooting....."
|
||||
sleep 5
|
||||
reboot
|
||||
fi
|
||||
|
||||
ui_print "- Done"
|
||||
exit 0
|
@ -34,7 +34,7 @@ case "$1" in
|
||||
;;
|
||||
*)
|
||||
TMPDIR=/dev/tmp; rm -rf $TMPDIR 2>/dev/null; setup_bb
|
||||
INSTALLER=$TMPDIR/install; mkdir -p $INSTALLER; unzip -o "$3" -d $INSTALLER
|
||||
INSTALLER=$TMPDIR/install; mkdir -p $INSTALLER; unzip -o "$3" -d $INSTALLER >&2
|
||||
exec sh $INSTALLER/META-INF/com/google/android/updater-script $@
|
||||
;;
|
||||
esac
|
||||
|
@ -217,27 +217,6 @@ patch_dtbo_image() {
|
||||
return 1
|
||||
}
|
||||
|
||||
restore_imgs() {
|
||||
STOCKBOOT=/data/stock_boot_${1}.img.gz
|
||||
STOCKDTBO=/data/stock_dtbo.img.gz
|
||||
|
||||
# Make sure all blocks are writable
|
||||
$MAGISKBIN/magisk --unlock-blocks 2>/dev/null
|
||||
find_dtbo_image
|
||||
if [ ! -z "$DTBOIMAGE" -a -f "$STOCKDTBO" ]; then
|
||||
ui_print "- Restoring stock dtbo image"
|
||||
gzip -d < $STOCKDTBO | dd of=$DTBOIMAGE
|
||||
fi
|
||||
BOOTSIGNED=false
|
||||
find_boot_image
|
||||
if [ ! -z "$BOOTIMAGE" -a -f "$STOCKBOOT" ]; then
|
||||
ui_print "- Restoring stock boot image"
|
||||
gzip -d < $STOCKBOOT | cat - /dev/zero 2>/dev/null | dd of="$BOOTIMAGE" bs=4096 2>/dev/null
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
sign_chromeos() {
|
||||
ui_print "- Signing ChromeOS boot image"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user