-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlive_patch.sh
More file actions
executable file
·77 lines (64 loc) · 2.64 KB
/
Copy pathlive_patch.sh
File metadata and controls
executable file
·77 lines (64 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TOOL="$SCRIPT_DIR/imei_tool.py"
IMEI_PATH="/mnt/vendor/nvdata/md/NVRAM/NVD_IMEI/LD0B_001"
DEVICE_TMP="/data/local/tmp"
WORK="$(pwd)/tmp"
mkdir -p "$WORK"
BACKUP="$WORK/backup_LD0B_001.bin"
PATCHED="$WORK/patched_LD0B_001.bin"
die() { echo "Error: $1" >&2; exit 1; }
push_replace() {
local src="$1" name="$2" dest="$3" group="$4"
adb push "$src" "$DEVICE_TMP/$name" > /dev/null </dev/null || die "adb push $name failed"
adb shell su -c "mount -o remount,rw /mnt/vendor/nvdata" </dev/null >/dev/null 2>&1
adb shell su -c "mount -o remount,rw /" </dev/null >/dev/null 2>&1
adb shell su -c "cp $DEVICE_TMP/$name $dest" </dev/null || die "cp $name to $dest failed"
adb shell su -c "chmod 660 $dest" </dev/null
adb shell su -c "chown root:$group $dest" </dev/null
adb shell su -c "rm $DEVICE_TMP/$name" </dev/null
}
adb devices 2>/dev/null | grep -q "device$" || die "No ADB device connected"
adb shell su -c id </dev/null 2>/dev/null | grep -q "uid=0" \
|| die "su -c failed: device must be rooted and root must be granted to adb shell"
echo "Device is rooted, continuing..."
echo "Reading current IMEIs from device..."
PULL_STAGE=/sdcard/LD0B_001_pull
adb shell su -c "cp $IMEI_PATH $PULL_STAGE && chmod 644 $PULL_STAGE" </dev/null \
|| die "Cannot stage $IMEI_PATH at $PULL_STAGE"
adb pull "$PULL_STAGE" "$BACKUP" >/dev/null 2>&1 \
|| die "adb pull of $PULL_STAGE failed"
adb shell su -c "rm $PULL_STAGE" </dev/null >/dev/null 2>&1
file_size=$(wc -c < "$BACKUP")
[ "$file_size" -eq 384 ] || die "LD0B_001 is $file_size bytes (expected 384) - pull may have corrupted the file"
echo ""
read_output=$(python3 "$TOOL" read "$BACKUP") || die "Read failed (imei_tool.py error above)"
echo "$read_output" | sed 's/^/ /'
echo ""
populated=$(echo "$read_output" | grep -cv '(empty)')
if [ "$populated" -ge 2 ]; then
read -p "Change which IMEI? [1/2/n] " choice
case "$choice" in
1|2) slot="$choice" ;;
*) echo "No changes made."; exit 0 ;;
esac
else
slot=1
read -p "Change IMEI? [y/N] " ans
case "$ans" in
y|Y) ;;
*) echo "No changes made."; exit 0 ;;
esac
fi
read -p " New IMEI $slot (15 digits): " new_imei
echo "$new_imei" | grep -qE '^[0-9]{15}$' || die "IMEI must be exactly 15 digits"
echo " Patching IMEI $slot..."
python3 "$TOOL" write "$BACKUP" "$new_imei" -s "$slot" -o "$PATCHED" \
|| die "Patch failed (imei_tool.py error above)"
push_replace "$PATCHED" LD0B_001 "$IMEI_PATH" system
echo " IMEI $slot updated."
echo ""
read -p "Reboot device now? [y/N] " ans
if [ "$ans" = "y" ] || [ "$ans" = "Y" ]; then
adb reboot
fi