This repository has been archived by the owner on Jul 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ubuntu.sh
148 lines (132 loc) · 3.39 KB
/
ubuntu.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
. "util/logging.sh"
. "util/try-catch.sh"
info "We're inside of Ubuntu! Starting the patching process..."
sleep 1
info "Installing Java..."
try {
apt update
apt upgrade
apt install openjdk-8-jre-headless
} catch {
error "installing OpenJDK 8 JRE"
exit 17
}
info "Downloading smali/baksmali and Magisk's update-binary"
try {
curl -Lo smali.jar "https://bitbucket.org/JesusFreke/smali/downloads/smali-2.5.2.jar"
curl -Lo baksmali.jar "https://bitbucket.org/JesusFreke/smali/downloads/baksmali-2.5.2.jar"
curl -Lo update-binary "https://raw.githubusercontent.com/topjohnwu/Magisk/master/scripts/module_installer.sh"
} catch {
error "downloading required tools"
exit 18
}
info "Fetching services.jar..."
try {
cp "/system/framework/services.jar" "."
} catch {
error "copying /system/framework/services.jar"
exit 19
}
info "Unzipping services.jar..."
try {
unzip "services.jar"
} catch {
error "unzipping services.jar"
exit 20
}
info "Baksmaling classes*.dex..."
try {
for dex in $(ls classes*.dex); do
java -Xmx500M -jar baksmali.jar d -j 12 $dex -o ${dex%.dex}
done
} catch {
error "baksmaling classes*.dex"
exit 21
}
req_bool="setIsFromMockProvider"
info "Finding the required file..."
try {
req_file="$(find classes* -name 'MockProvider.smali')"
if [[ -z "${req_file}" ]]; then
exit ${RANDOM}
else
echo "${req_file}" > required_file_path
fi
} catch {
error "finding the required file"
exit 22
}
info "Checking if ${req_bool} is already patched..."
try {
mapfile -t lines < "$(cat required_file_path)"
for idx in "${!lines[@]}"; do
if [[ "${lines[idx]}" == *"${req_bool}"* ]]; then
line=$(printf '%s\n' "${lines[@]:0:idx}" | grep "0x0")
[[ "${line}" == *"0x0"* ]] && exit ${RANDOM}
fi
break
done
} catch {
info "${req_bool} is already patched! Exitting..."
exit 127
}
info "Patching the required file..."
try {
mapfile -t lines < "$(cat required_file_path)"
for idx in "${!lines[@]}"; do
if [[ "${lines[idx]}" == *"${req_bool}"* ]]; then
req_line=$(printf '%s\n' "${lines[@]:0:idx}" | grep -q "0x1")
req_idx=$idx
break
fi
done
mod_line="$(echo "${req_line}" | sed 's/0x1/0x0/g')"
lines[$req_idx]="${mod_line}"
printf "%s\n" "${lines[@]}" > "$(cat required_file_path)"
} catch {
error "patching ${req_bool} defined at $(cat required_file_path)"
exit 23
}
info "Re-smaling to classes*.dex..."
try {
rm -f classes*.dex
for smalidir in classes*; do
java -Xmx500M -jar smali.jar a -j 12 $smalidir -o "${smalidir}.dex"
done
} catch {
error "smaling classes folder back to classes.dex"
exit 24
}
info "Zipping everything back to services.jar..."
try {
zip services.jar classes*.dex
} catch {
error "zipping the files to services.jar"
exit 25
}
info "Creating a Magisk module..."
try {
mkdir -p module/META-INF/com/google/android
cd module
mv ../update-binary META-INF/com/google/android
echo "#MAGISK" > META-INF/com/google/android/updater-script
cat <<EOF >> module.prop
name=Hide Mock Locations
id=hidemocklocations
version=v1
versionCode=1
description=Hide mock location updates from apps that detect them like Pokemon GO.
author=Me!
EOF
mkdir -p system/framework
mv ../services.jar system/framework
zip -r HML.zip META-INF system module.prop
mv HML.zip ../
cd ../
} catch {
error "creating the Magisk module"
exit 26
}
success "All done! Exiting Ubuntu..."
exit 0