Skip to content

Commit d17904b

Browse files
authored
Large changes.
Removed recovery part, removed update json, refactored most of the code.
1 parent 83ed08e commit d17904b

File tree

9 files changed

+84
-205
lines changed

9 files changed

+84
-205
lines changed

README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
# Magisk BootloopSaver
22

3+
34
## About
4-
Protect your system from bootloop caused by Magisk modules. In case the data partition is encrypted and you cannot access `/data/adb/modules`, or you don't want to turn off **force encryption** to protect your private data.
5+
Protect your system from bootloop caused by Magisk modules.
6+
In case the data partition is encrypted and you cannot access `/data/adb/modules`, or you don't want to turn off **force encryption** to protect your private data.
7+
58

69
## Requirements
710
- Magisk 20.4+ is installed
811

12+
913
## Installation
1014
It's Magisk module, flash it in **Magisk** app
1115

16+
1217
## Usage
1318

1419
### Auto detect
15-
Usually, bootloop occurs because zygote doesn't start properly or stuck at restarting. The script run in `late_start` mode. It will check Zygote's Process ID 3 times every 15 seconds. And if Zygote's Process ID doesn't match for 3 times, check the Process ID for next 15 seconds to make sure and if it's different again, the script will disable all modules and reboot the your device.
16-
17-
### Disable from Custom Recovery
18-
20+
Usually, bootloop occurs because zygote doesn't start properly or stuck at restarting.
21+
The script run in `late_start` mode. It will check Zygote's Process ID 3 times every 15 seconds.
22+
And if Zygote's Process ID doesn't match for 3 times, check the Process ID for next 15 seconds to make sure and if it's different again, the script will disable all modules and reboot the your device.
1923

20-
You can boot into **TWRP** and create a dummy file named `disable_magisk` in one of these location and then reboot to system to boot into Safe Mode (if **Auto detect** is not working):
21-
- /cache
22-
- /data/unencrypted
23-
- /metadata
24-
- /persist
25-
- /mnt/vendor/persist
2624

27-
How to create a file in TWRP? Open Terminal Emulator in TWRP and type:
25+
## Known issues
26+
It may be too eager to Disable all modules and Reboot.
2827

29-
```
30-
touch /cache/disable_magisk
31-
```
3228

33-
**NOTE: MAKE SURE ALL PARTITIONS ARE MOUNTED**
29+
## Attribution
30+
Module originally made by HuskyDG, but I didn't like how large it was for something that looked like it could be done in less code, so I forked it and made it into just one script.
31+
This involved removing the custom recovery parts, but for me the AutoDetect has worked.

changelog.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

customize.sh

Lines changed: 0 additions & 52 deletions
This file was deleted.

module.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

module.prop

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
id=huskydg_bootloopsaver
1+
id=simple_bootloopsaver
22
name=Magisk Bootloop Protector
3-
version=v1.6
4-
versionCode=10008
5-
author=HuskyDG
3+
version=v1
4+
versionCode=1
5+
author=ez-me
66
description=Protect your system from bootloop caused by Magisk modules by turning off all your modules and restart your system if bootloop is detected.
7-
updateJson=https://raw.githubusercontent.com/Magisk-Modules-Alt-Repo/HuskyDG_BootloopSaver/master/module.json
8-
changeBoot=true
7+
changeBoot=false
98
needRamdisk=false

post-fs-data.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

service.sh

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,82 @@
11
#!/system/bin/sh
2-
#Bootloop saver by HuskyDG
2+
#Bootloop saver by HuskyDG, modified by ez-me
33

4-
MODDIR=${0%/*}
5-
. "$MODDIR/utils.sh"
4+
# Get variables
5+
MODPATH=${0%/*}
6+
MESSAGE="$(cat "$MODPATH"/msg.txt | head -c100)"
67

8+
if [ -n "$(getprop ro.product.cpu.abi | grep 64)" ]
9+
then
10+
ZYGOTE_NAME=zygote64
11+
else
12+
ZYGOTE_NAME=zygote
13+
fi
714

8-
rm -rf /cache/bootloop_saver.log.bak
9-
mv -f /cache/bootloop_saver.log /cache/bootloop_saver.log.bak 2>/dev/null
10-
write_log "bootloop saver started"
11-
MAIN_ZYGOTE_NICENAME=zygote
12-
CPU_ABI=$(getprop ro.product.cpu.api)
13-
[ "$CPU_ABI" = "arm64-v8a" -o "$CPU_ABI" = "x86_64" ] && MAIN_ZYGOTE_NICENAME=zygote64
15+
# Log
16+
log(){
17+
TEXT=$@; echo "[`date -Is`]: $TEXT" >> $MODPATH/log.txt
18+
}
1419

15-
check(){
16-
TEXT1="$1"
17-
TEXT2="$2"
18-
result=false
19-
for i in $TEXT1; do
20-
for j in $TEXT2; do
21-
[ "$i" == "$j" ] && result=true
22-
done
23-
done
24-
$result
20+
log "Started"
21+
22+
# Modify description
23+
cp "$MODPATH/module.prop" "$MODPATH/temp.prop"
24+
sed -Ei "s/^description=(\[.*][[:space:]]*)?/description=[Working. $MESSAGE] /g" "$MODPATH/temp.prop"
25+
mv "$MODPATH/temp.prop" "$MODPATH/module.prop"
26+
27+
# Define the function
28+
disable_modules(){
29+
log "Disabling modules..."
30+
list="$(find /data/adb/modules/* -prune -type d)"
31+
for module in $list
32+
do
33+
touch $module/disable
34+
done
35+
rm -rf "$MODPATH/disable"
36+
echo "Disabled modules at $(date -Is)" > "$MODPATH/msg.txt"
37+
rm -rf /cache/.system_booting /data/unencrypted/.system_booting /metadata/.system_booting /persist/.system_booting /mnt/vendor/persist/.system_booting
38+
log "Rebooting"
39+
reboot
40+
exit
2541
}
2642

2743

28-
# Wait for zygote starts
44+
# Gather PIDs
2945
sleep 5
46+
ZYGOTE_PID1=$(pidof "$ZYGOTE_NAME")
47+
log "PID1: $ZYGOTE_PID1"
3048

31-
ZYGOTE_PID1=$(pidof "$MAIN_ZYGOTE_NICENAME")
32-
write_log "pid of zygote stage 1: $ZYGOTE_PID1"
33-
sleep 15
34-
ZYGOTE_PID2=$(pidof "$MAIN_ZYGOTE_NICENAME")
35-
write_log "pid of zygote stage 2: $ZYGOTE_PID2"
3649
sleep 15
37-
ZYGOTE_PID3=$(pidof "$MAIN_ZYGOTE_NICENAME")
38-
write_log "pid of zygote stage 3: $ZYGOTE_PID3"
50+
ZYGOTE_PID2=$(pidof "$ZYGOTE_NAME")
51+
log "PID2: $ZYGOTE_PID2"
3952

53+
sleep 15
54+
ZYGOTE_PID3=$(pidof "$ZYGOTE_NAME")
55+
log "PID3: $ZYGOTE_PID3"
4056

41-
if check "$ZYGOTE_PID1" "$ZYGOTE_PID2" && check "$ZYGOTE_PID2" "$ZYGOTE_PID3"; then
42-
if [ -z "$ZYGOTE_PID1" ]; then
43-
write_log "maybe zygote not start :("
44-
write_log "zygote meets the trouble, disable all modules and restart"
57+
# Check for BootLoop
58+
log "Checking..."
4559

46-
disable_modules
47-
else
48-
exit_log "pid of 3 stage zygote is the same"
49-
fi
50-
else
51-
write_log "pid of 3 stage zygote is different, continue check to make sure... "
60+
if [ -z "$ZYGOTE_PID1" ]
61+
then
62+
log "Zygote didn't start?"
63+
disable_modules
5264
fi
5365

66+
if [ "$ZYGOTE_PID1" != "$ZYGOTE_PID2" -o "$ZYGOTE_PID2" != "$ZYGOTE_PID3" ]
67+
then
68+
log "PID mismatch, checking again"
69+
sleep 15
70+
ZYGOTE_PID4=$(pidof "$ZYGOTE_NAME")
71+
log "PID4: $ZYGOTE_PID4"
72+
73+
if [ "$ZYGOTE_PID3" != "$ZYGOTE_PID4" ]
74+
then
75+
log "They don't match..."
76+
disable_modules
77+
fi
78+
fi
5479

55-
56-
57-
sleep 15
58-
ZYGOTE_PID4=$(pidof "$MAIN_ZYGOTE_NICENAME")
59-
write_log "pid of zygote stage 4: $ZYGOTE_PID4"
60-
check "$ZYGOTE_PID3" "$ZYGOTE_PID4" && exit_log "pid of zygote stage 3 and 4 is the same."
61-
62-
write_log "zygote meets the trouble, disable all modules and restart"
63-
64-
disable_modules
65-
80+
# If we reached this section we should be fine
81+
log "looks good to me!"
82+
exit

uninstall.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

utils.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)