-
Notifications
You must be signed in to change notification settings - Fork 2
/
59MAD
321 lines (296 loc) · 13.6 KB
/
59MAD
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/system/bin/sh
#This is for update_mad version
uver="9.0.6"
#This is for pingreboot version
pver="2.0"
# mad rom version
madver="0.9.9"
# Last file created by POGOROM so we don't interfere and run too early
last_pogorom_file="/sdcard/.curlrc"
logfile="/data/local/59MAD.log"
rgcconf="/data/data/de.grennith.rgc.remotegpscontroller/shared_prefs/de.grennith.rgc.remotegpscontroller_preferences.xml"
pdconf="/data/data/com.mad.pogodroid/shared_prefs/com.mad.pogodroid_preferences.xml"
useragent='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0'
ip="$(ifconfig 'eth0'|awk '/inet addr/{print $2}'|cut -d ':' -f 2)"
touch "$logfile"
exec >>"$logfile" 2>&1
log() {
line="`date +'[%Y-%m-%dT%H:%M:%S %Z]'` $@"
echo "$line"
/system/bin/log -p v -t "MAD-ATV" "$@"
}
download(){
# $1 = url
# $2 = local path
# lets see that curl exits successfully
until /system/bin/curl -s -k -L -A "$useragent" -o "$2" "$1" ;do
sleep 15
done
}
log_msg() {
# $1 = severity
# $2 = msg
if [[ "$session_id" ]] ;then
echo "$msg"
/system/bin/curl -s -k -L -d "$1,$2" --user "$pdauth" -H 'Content-Type: text/html' "${pdserver}/autoconfig/${session_id}/log"
fi
}
execute_autoupdates(){
if ! grep -q "version $uver" /system/bin/update_mad_a9.sh; then
log "Wrong version of /system/bin/update_mad_a9.sh [looking for $uver], downloading new one"
download https://raw.githubusercontent.com/JabLuszko/MAD-ATV_dev/main/update_mad_a9.sh /system/bin/update_mad_a9.sh
chmod 755 /system/bin/update_mad_a9.sh
fi
if ! grep -q "version $pver" /system/bin/pingreboot.sh; then
log "Wrong version of /system/bin/pingreboot [looking for $pver], downloading new one"
download https://raw.githubusercontent.com/Map-A-Droid/MAD-ATV/master/pingreboot.sh /system/bin/pingreboot.sh
chmod 755 /system/bin/pingreboot.sh
fi
! [[ -f /sdcard/disableautopogoupdate ]] && sh -x /system/bin/update_mad_a9.sh -p
! [[ -f /sdcard/disableautopogodroidupdate ]] && sh -x /system/bin/update_mad_a9.sh -wd
! [[ -f /sdcard/disableautorgcupdate ]] && sh -x /system/bin/update_mad_a9.sh -wr
}
set_mac(){
echo 1 > /sys/class/unifykeys/lock
echo mac > /sys/class/unifykeys/name
echo "$1" >/sys/class/unifykeys/write
cat /sys/class/unifykeys/read
echo 0 > /sys/class/unifykeys/lock
}
getmadminmac(){
all_macs="$(/system/bin/curl -s -k -L --user "$pdauth" -H "origin: $origin" "${pdserver}/autoconfig/mymac")"
interface="$(sed -n 1p <<< "$all_macs")"
mac="$(sed -n 2p <<< "$all_macs")"
}
setmadminmac(){
if [[ "$current_mac" == "00:15:18:01:81:31" ]] ;then
current_mac=$(xxd -l 6 -p /dev/urandom |sed 's/../&:/g;s/:$//')
ifconfig eth0 down
until ifconfig eth0 hw ether "$current_mac" 2>/dev/null; do
current_mac=$(xxd -l 6 -p /dev/urandom |sed 's/../&:/g;s/:$//')
done
ifconfig eth0 up
sleep 3
fi
/system/bin/curl -s -k -L --user "$pdauth" -H 'Content-Type: text/html' -H "origin: $origin" "${pdserver}/autoconfig/mymac" -d "$current_mac"
getmadminmac
while [[ "$mac" == "" ]] ;do
# if that mac was not accepted
current_mac=$(xxd -l 6 -p /dev/urandom |sed 's/../&:/g;s/:$//')
ifconfig eth0 down
until ifconfig eth0 hw ether "$current_mac" 2>/dev/null; do
current_mac=$(xxd -l 6 -p /dev/urandom |sed 's/../&:/g;s/:$//')
done
ifconfig eth0 up
sleep 3
# set a new one
/system/bin/curl -s -k -L --user "$pdauth" -H 'Content-Type: text/html' -H "origin: $origin" "${pdserver}/autoconfig/mymac" -d "$current_mac"
# check again
getmadminmac
done
}
checkmac(){
if [[ "$(/system/bin/curl -s -k -L -o /dev/null -w "%{http_code}" --user "$pdauth" -H "origin: $origin" "${pdserver}/autoconfig/mymac")" == "200" ]] ;then
if ifconfig|grep -A5 wlan0|grep -q inet ;then
current_mac=$(ifconfig wlan0|awk '/HWaddr/{print $5}')
elif ifconfig|grep -A5 eth0|grep -q inet ;then
current_mac=$(ifconfig eth0|awk '/HWaddr/{print $5}')
getmadminmac
log "MAD-assigned MAC: \"$mac\""
log "Current MAC: \"$current_mac\""
if [[ "$mac" == "" ]] ;then
# use our current mac for now on
setmadminmac
set_mac "$current_mac"
elif [[ "$mac" != "$current_mac" ]] ;then
#use the mac suppplied from madmin
set_mac "$mac"
fi
fi
else
log "Maybe the origin $origin does not exist in madmin or something?"
fi
}
is_pogorom_done(){
log "Waiting for pogorom"
until [[ -f "$last_pogorom_file" ]]; do
log "Pogorom still not done, sleeping 30 seconds"
sleep 30
done
log "pogorom configured, let's do MAD stuff"
}
wait_for_network(){
log "Waiting for network"
until ping -c1 8.8.8.8 >/dev/null 2>/dev/null; do
log "No network detected. Sleeping 10s"
sleep 10
done
log "Network connection detected"
}
test_session(){
[[ "$session_id" ]] || return 5
case "$(/system/bin/curl -s -k -L -o /dev/null -w "%{http_code}" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/status")" in
406) sleep 15 && test_session
;;
40*) return 3
;;
200) return 0
;;
"") return 2
;;
*) log "unexpected status $(/system/bin/curl -s -k -L -o /dev/null -w "%{http_code}" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/status") from madmin" && return 4
;;
esac
}
make_session(){
until test_session ;do
log "Trying to register session"
session_id=$(/system/bin/curl -s -k -L -X POST --user "$pdauth" "${pdserver}/autoconfig/register")
sleep 15
done
echo "$session_id" > /sdcard/reg_session
}
check_session(){
if ! [[ -f /sdcard/reg_session ]] ;then
make_session
else
session_id="$(cat /sdcard/reg_session)"
if ! test_session ;then
rm -f /sdcard/reg_session
make_session
fi
fi
}
firefox_ptc_access(){
firefox_configfile="/data/data/org.mozilla.firefox/databases/login_exceptions"
if [ -f "$firefox_configfile" ]; then
rule_count=$(sqlite3 "$firefox_configfile" 'SELECT count(1) FROM `logins_exceptions` WHERE `origin`="https://access.pokemon.com"')
if [[ "$rule_count" == "0" ]]; then
sqlite3 "$firefox_configfile" 'INSERT INTO `logins_exceptions`(`origin`) VALUES("https://access.pokemon.com")'
fi
fi
}
################ start of execution
log "/etc/init.d/59MAD starting"
wait_for_network
is_pogorom_done
if [[ -f "$pdconf" ]] ;then
log "Found $pdconf, using it"
origin="$(awk -F'>' '/post_origin/{print $2}' "$pdconf"|awk -F'<' '{print $1}')"
pdserver="$(grep -v raw "$pdconf"|awk -F'>' '/post_destination/{print $2}'|awk -F'<' '{print $1}')"
pduser="$(grep -v raw "$pdconf"|awk -F'>' '/auth_username/{print $2}'|awk -F'<' '{print $1}')"
pdpass="$(grep -v raw "$pdconf"|awk -F'>' '/auth_password/{print $2}'|awk -F'<' '{print $1}')"
pdauth="$pduser:$pdpass"
[[ -f /sdcard/reg_session ]] && check_session
elif [[ -f /data/local/pdconf ]] ;then
log "Found /data/local/pdconf, using it"
origin="$(awk -F'>' '/post_origin/{print $2}' /data/local/pdconf|awk -F'<' '{print $1}')"
pdserver="$(grep -v raw /data/local/pdconf|awk -F'>' '/post_destination/{print $2}'|awk -F'<' '{print $1}')"
pduser="$(grep -v raw /data/local/pdconf|awk -F'>' '/auth_username/{print $2}'|awk -F'<' '{print $1}')"
pdpass="$(grep -v raw /data/local/pdconf|awk -F'>' '/auth_password/{print $2}'|awk -F'<' '{print $1}')"
pdauth="$pduser:$pdpass"
check_session
else
usbfile="$(find /mnt/media_rw/ -name mad_autoconf.txt|head -n1)"
if [[ "$usbfile" ]] ;then
log "Found $usbfile, using it"
pdserver="$(awk 'NR==1{print $1}' "$usbfile")"
log "pdserver: $pdserver"
pdauth="$(awk 'NR==2{print $1}' "$usbfile")"
log "pdauth: $pdauth"
check_session
origin=$(/system/bin/curl -s -k -L --user "$pdauth" "${pdserver}/autoconfig/${session_id}/origin")
log "Got origin from MAD: $origin"
log_msg 2 "Hello, this is 59MAD from $origin! My current IP is $ip"
/system/bin/curl -s -k -L -o "/data/local/pdconf" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/pd"
log_msg 2 "PD configuration downloaded to /data/local/pdconf"
checkmac
wait_for_network
ip="$(ifconfig 'eth0'|awk '/inet addr/{print $2}'|cut -d ':' -f 2)"
log_msg 2 "Check for the need to MAC adress change completed! This may have caused an IP change. My current IP is $ip "
log "Installing the apps from the wizard"
if ! grep -q "version $uver" /system/bin/update_mad_a9.sh; then
log "Wrong version of /system/bin/update_mad_a9.sh [looking for $uver], downloading new one"
download https://raw.githubusercontent.com/JabLuszko/MAD-ATV_dev/main/update_mad_a9.sh /system/bin/update_mad_a9.sh
chmod 755 /system/bin/update_mad_a9.sh
log_msg 2 "Installed /system/bin/update_mad_a9.sh"
fi
log_msg 2 "Starting install of RGC, PoGo and PD from your madmin wizard"
sh -x /system/bin/update_mad_a9.sh -pdc -wa
fi
fi
mount -o remount,rw /
settings put global policy_control immersive.full=com.nianticlabs.pokemongo
# Force Firefox to stop trying to save login/password for access.pokemon.com
firefox_ptc_access
# Disable blue LED on supported A9 devices
[[ -f /sdcard/disableblueled ]] && echo 0 > /sys/class/leds/sys_led/brightness
# Disable system animations aka change time to 0.0
[[ $(settings get global transition_animation_scale) != "0.0" ]] && settings put global transition_animation_scale 0.0
[[ $(settings get global window_animation_scale) != "0.0" ]] && settings put global window_animation_scale 0.0
[[ $(settings get global animator_duration_scale) != "0.0" ]] && settings put global animator_duration_scale 0.0
# Disable rotation of apps - seems like Firefox on TX9S liked to go landscape mode
[[ $(settings get system accelerometer_rotation) != "1" ]] && settings put system accelerometer_rotation 1
[[ $(settings get system user_rotation) != "0" ]] && settings put system user_rotation 0
[[ $(settings get secure show_rotation_suggestions) != "0" ]] && settings put secure show_rotation_suggestions 0
[[ $(settings get global private_dns_mode) != "off" ]] && settings put global private_dns_mode off
[[ $(settings get global heads_up_notifications_enabled) != "0" ]] && settings put global heads_up_notifications_enabled 0
[[ $(settings get global hdmi_control_enabled) != "0" ]] && settings put global hdmi_control_enabled 0
[[ $(settings get global stay_on_while_plugged_in) != 3 ]] && settings put global stay_on_while_plugged_in 3
[[ "$(/system/bin/appops get de.grennith.rgc.remotegpscontroller android:mock_location)" = "No operations." ]] && /system/bin/appops set de.grennith.rgc.remotegpscontroller android:mock_location allow
! settings get secure location_providers_allowed|grep -q gps && settings put secure location_providers_allowed +gps
echo "$madver" > /sdcard/madversion
log_msg 2 "Configuring RGC and PD, setting permissions"
pdir="/data/data/com.mad.pogodroid/"
puser="$(stat -c %u "$pdir")"
rgcdir="/data/data/de.grennith.rgc.remotegpscontroller/"
ruser="$(stat -c %u "$rgcdir")"
if [[ "$puser" ]] && [[ "$pdauth" ]] && [[ -d "$pdir" ]] && ! [[ -f "$pdconf" ]] && [[ "$session_id" ]] ;then
if [[ ! -d "$pdir/shared_prefs" ]] ;then
mkdir -p "$pdir/shared_prefs"
chmod 771 "$pdir/shared_prefs"
chown "$puser":"$puser" "$pdir/shared_prefs"
fi
/system/bin/curl -s -k -L -o "$pdconf" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/pd"
chmod 660 "$pdconf" && chown "$puser":"$puser" "$pdconf"
rm -f /data/local/pdconf
log_msg 2 "PD configuration downloaded and installed"
fi
if [[ "$puser" ]] && [[ "$pdauth" ]] && [[ -d "$rgcdir" ]] && ! [[ -f "$rgcconf" ]] ;then
if [[ ! -d "$rgcdir/shared_prefs" ]] ;then
mkdir -p "$rgcdir/shared_prefs"
chmod 771 "$rgcdir/shared_prefs"
chown "$ruser":"$ruser" "$rgcdir/shared_prefs"
fi
/system/bin/curl -s -k -L -o "$rgcconf" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/rgc"
chmod 660 "$rgcconf" && chown "$ruser":"$ruser" "$rgcconf"
log_msg 2 "RGC configuration downloaded and installed"
fi
if [[ "$(pm list packages com.mad.pogodroid)" ]] && ! dumpsys package com.mad.pogodroid |grep READ_EXTERNAL_STORAGE|grep granted|grep -q 'granted=true'; then
pm grant com.mad.pogodroid android.permission.READ_EXTERNAL_STORAGE
pm grant com.mad.pogodroid android.permission.WRITE_EXTERNAL_STORAGE
fi
if [[ "$(pm list packages com.nianticlabs.pokemongo)" ]] && ! dumpsys package com.nianticlabs.pokemongo|grep ACCESS_FINE_LOCATION|grep granted|grep -q 'granted=true'; then
pm grant com.nianticlabs.pokemongo android.permission.ACCESS_FINE_LOCATION
pm grant com.nianticlabs.pokemongo android.permission.ACCESS_COARSE_LOCATION
pm grant com.nianticlabs.pokemongo android.permission.CAMERA
pm grant com.nianticlabs.pokemongo android.permission.GET_ACCOUNTS
fi
if [[ "$(pm list packages de.grennith.rgc.remotegpscontroller)" ]] && ! dumpsys package de.grennith.rgc.remotegpscontroller|grep ACCESS_FINE_LOCATION|grep granted|grep -q 'granted=true'; then
pm grant de.grennith.rgc.remotegpscontroller android.permission.ACCESS_FINE_LOCATION
pm grant de.grennith.rgc.remotegpscontroller android.permission.READ_EXTERNAL_STORAGE
pm grant de.grennith.rgc.remotegpscontroller android.permission.ACCESS_COARSE_LOCATION
pm grant de.grennith.rgc.remotegpscontroller android.permission.WRITE_EXTERNAL_STORAGE
fi
if [[ -f /sdcard/reg_session ]] && [[ -f "$pdconf" ]] && [[ -f "$rgcconf" ]] ;then
/system/bin/curl -s -k -L -X DELETE --user "$pdauth" "${pdserver}/autoconfig/${session_id}/complete"
rm -f /sdcard/reg_session
monkey -p com.mad.pogodroid 1
sleep 10
monkey -p de.grennith.rgc.remotegpscontroller 1
sleep 10
reboot
fi
execute_autoupdates
mount -o remount,ro /
# initdebug