-
Notifications
You must be signed in to change notification settings - Fork 16
/
update-binary
511 lines (459 loc) · 15.8 KB
/
update-binary
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
#!/sbin/sh
#
# SuperSU installer ZIP
# Copyright (c) 2012-2017 - Chainfire, CCMT
#
OUTFD=$2
ZIP=$3
# Detect whether in boot mode
if ps | grep zygote | grep -qv grep; then BOOTMODE=true; else BOOTMODE=false; fi
if ! $BOOTMODE; then
ps -A 2>/dev/null | grep zygote | grep -qv grep && BOOTMODE=true
fi
ui_print() {
if $BOOTMODE; then
echo "$1"
else
echo -e "ui_print $1\nui_print" > /proc/self/fd/$OUTFD
fi
}
is_mounted() {
test "$(mount | grep " $1 " | grep "rw[ ,]")"
return $?
}
mount_() {
is_mounted $1 || mount $1 2>/dev/null || mount -o rw,remount $1 2>/dev/null || abort "Aborting..Unable to mount $1"
}
unmount() {
umount "$1" 2>/dev/null
}
abort() {
ui_print "$*"
exit 1
}
ch_con() {
LD_LIBRARY_PATH=$SYSTEMLIB /system/bin/toybox chcon -h u:object_r:system_file:s0 $1 >/dev/null 2>/dev/null
LD_LIBRARY_PATH=$SYSTEMLIB /system/toolbox chcon -h u:object_r:system_file:s0 $1 >/dev/null 2>/dev/null
LD_LIBRARY_PATH=$SYSTEMLIB /system/bin/toolbox chcon -h u:object_r:system_file:s0 $1 >/dev/null 2>/dev/null
chcon -h u:object_r:system_file:s0 $1 >/dev/null 2>/dev/null
LD_LIBRARY_PATH=$SYSTEMLIB /system/bin/toybox chcon u:object_r:system_file:s0 $1 >/dev/null 2>/dev/null
LD_LIBRARY_PATH=$SYSTEMLIB /system/toolbox chcon u:object_r:system_file:s0 $1 >/dev/null 2>/dev/null
LD_LIBRARY_PATH=$SYSTEMLIB /system/bin/toolbox chcon u:object_r:system_file:s0 $1 >/dev/null 2>/dev/null
chcon u:object_r:system_file:s0 $1 >/dev/null 2>/dev/null
}
ch_con_ext() {
LD_LIBRARY_PATH=$SYSTEMLIB /system/bin/toybox chcon $2 $1 >/dev/null 2>/dev/null
LD_LIBRARY_PATH=$SYSTEMLIB /system/toolbox chcon $2 $1 >/dev/null 2>/dev/null
LD_LIBRARY_PATH=$SYSTEMLIB /system/bin/toolbox chcon $2 $1 >/dev/null 2>/dev/null
chcon $2 $1 >/dev/null 2>/dev/null
}
ln_con() {
LD_LIBRARY_PATH=$SYSTEMLIB /system/bin/toybox ln -s $1 $2 >/dev/null 2>/dev/null
LD_LIBRARY_PATH=$SYSTEMLIB /system/toolbox ln -s $1 $2 >/dev/null 2>/dev/null
LD_LIBRARY_PATH=$SYSTEMLIB /system/bin/toolbox ln -s $1 $2 >/dev/null 2>/dev/null
ln -s $1 $2 >/dev/null 2>/dev/null
ch_con $2 >/dev/null 2>/dev/null
}
set_perm() {
chown $1:$2 $4 || chown $1.$2 $4
chmod $3 $4
if [ -z "$5" ]; then
ch_con $4
else
ch_con_ext $4 $5
fi
}
cp_perm() {
rm -f $5
if [ -f "$4" ]; then
cat $4 > $5
set_perm $1 $2 $3 $5 $6
fi
}
chattri() {
if ! [ -f "$1" ]; then return; fi
LD_LIBRARY_PATH=$SYSTEMLIBTOOLS $BINTOOLS/chattr$PIE -ia $1 >/dev/null 2>/dev/null
}
wipe_system_files_if_present() {
SYSTEMFILES="
/system/xbin/daemonsu
/system/xbin/sugote
/system/xbin/sugote-mksh
/system/xbin/supolicy
/system/xbin/ku.sud
/system/xbin/.ku
/system/xbin/.su
/system/lib/libsupol.so
/system/lib64/libsupol.so
/system/bin/.ext/.su
/system/etc/init.d/99SuperSUDaemon
/system/etc/.installed_su_daemon
/system/app/Superuser.apk
/system/app/Superuser.odex
/system/app/Superuser
/system/app/SuperUser.apk
/system/app/SuperUser.odex
/system/app/SuperUser
/system/app/superuser.apk
/system/app/superuser.odex
/system/app/superuser
/system/app/Supersu.apk
/system/app/Supersu.odex
/system/app/Supersu
/system/app/SuperSU.apk
/system/app/SuperSU.odex
/system/app/SuperSU
/system/app/supersu.apk
/system/app/supersu.odex
/system/app/supersu
/system/app/VenomSuperUser.apk
/system/app/VenomSuperUser.odex
/system/app/VenomSuperUser
"
for FILE in $SYSTEMFILES; do
if [ -d "$FILE" ]; then rm -rf $FILE; fi
if [ -f "$FILE" ]; then rm -f $FILE; fi
done
rm -f /system/xbin/su
if [ -f "/system/etc/install-recovery_original.sh" ]; then
rm -f /system/etc/install-recovery.sh
mv /system/etc/install-recovery_original.sh /system/etc/install-recovery.sh
fi
if [ -f "/system/bin/install-recovery_original.sh" ]; then
rm -f /system/bin/install-recovery.sh
mv /system/bin/install-recovery_original.sh /system/bin/install-recovery.sh
fi
if [ -f "/system/bin/app_process64_original" ]; then
rm -f /system/bin/app_process64
if [ -f "/system/bin/app_process64_xposed" ]; then
ln -s /system/bin/app_process64_xposed /system/bin/app_process64
else
mv /system/bin/app_process64_original /system/bin/app_process64
fi
fi
if [ -f "/system/bin/app_process32_original" ]; then
rm -f /system/bin/app_process32
if [ -f "/system/bin/app_process32_xposed" ]; then
ln -s /system/bin/app_process32_xposed /system/bin/app_process32
else
mv /system/bin/app_process32_original /system/bin/app_process32
fi
fi
if [ -f "/system/bin/app_process64" ]; then
rm /system/bin/app_process
ln -s /system/bin/app_process64 /system/bin/app_process
elif [ -f "/system/bin/app_process32" ]; then
rm /system/bin/app_process
ln -s /system/bin/app_process32 /system/bin/app_process
fi
rm -f /system/bin/app_process_init
}
wipe_data_competitors_and_cache() {
rm -f /data/dalvik-cache/*com.noshufou.android.su*
rm -f /data/dalvik-cache/*/*com.noshufou.android.su*
rm -f /data/dalvik-cache/*com.koushikdutta.superuser*
rm -f /data/dalvik-cache/*/*com.koushikdutta.superuser*
rm -f /data/dalvik-cache/*com.mgyun.shua.su*
rm -f /data/dalvik-cache/*/*com.mgyun.shua.su*
rm -f /data/dalvik-cache/*com.m0narx.su*
rm -f /data/dalvik-cache/*/*com.m0narx.su*
rm -f /data/dalvik-cache/*com.kingroot.kinguser*
rm -f /data/dalvik-cache/*/*com.kingroot.kinguser*
rm -f /data/dalvik-cache/*com.kingroot.master*
rm -f /data/dalvik-cache/*/*com.kingroot.master*
rm -f /data/dalvik-cache/*me.phh.superuser*
rm -f /data/dalvik-cache/*/*me.phh.superuser*
rm -f /data/dalvik-cache/*Superuser.apk*
rm -f /data/dalvik-cache/*/*Superuser.apk*
rm -f /data/dalvik-cache/*SuperUser.apk*
rm -f /data/dalvik-cache/*/*SuperUser.apk*
rm -f /data/dalvik-cache/*superuser.apk*
rm -f /data/dalvik-cache/*/*superuser.apk*
rm -f /data/dalvik-cache/*VenomSuperUser.apk*
rm -f /data/dalvik-cache/*/*VenomSuperUser.apk*
rm -f /data/dalvik-cache/*eu.chainfire.supersu*
rm -f /data/dalvik-cache/*/*eu.chainfire.supersu*
rm -f /data/dalvik-cache/*Supersu.apk*
rm -f /data/dalvik-cache/*/*Supersu.apk*
rm -f /data/dalvik-cache/*SuperSU.apk*
rm -f /data/dalvik-cache/*/*SuperSU.apk*
rm -f /data/dalvik-cache/*supersu.apk*
rm -f /data/dalvik-cache/*/*supersu.apk*
rm -f /data/dalvik-cache/*.oat
rm -rf /data/app/com.noshufou.android.su*
rm -rf /data/app/com.koushikdutta.superuser*
rm -rf /data/app/com.mgyun.shua.su*
rm -rf /data/app/com.m0narx.su*
rm -rf /data/app/com.kingroot.kinguser*
rm -rf /data/app/com.kingroot.master*
rm -rf /data/app/me.phh.superuser*
}
ui_print " "
ui_print "*****************"
ui_print "SuperSU installer"
ui_print "*****************"
ui_print "- Remounting system"
mount_ /data
mount_ /system
mount_ /
mount -o rw,remount / /
API=$(cat /system/build.prop | grep "ro.build.version.sdk=" | dd bs=1 skip=21 count=2 2>/dev/null)
ABI=$(cat /system/build.prop /default.prop | grep -m 1 "ro.product.cpu.abi=" | dd bs=1 skip=19 count=3 2>/dev/null)
ABILONG=$(cat /system/build.prop /default.prop | grep -m 1 "ro.product.cpu.abi=" | dd bs=1 skip=19 2>/dev/null)
ABI2=$(cat /system/build.prop /default.prop | grep -m 1 "ro.product.cpu.abi2=" | dd bs=1 skip=20 count=3 2>/dev/null)
MKSH=/system/bin/mksh
SUMOD=06755
SUGOTE=false
SUPOLICY=false
INSTALL_RECOVERY_CONTEXT=u:object_r:system_file:s0
PIE=
SU=su
ARCH=arm
ARCHTOOLS=arm_tools
APKFOLDER=false
APKNAME=/system/app/Superuser.apk
APPPROCESS=false
APPPROCESS64=false
SYSTEMLIB=/system/lib:/vendor/lib
SYSTEMLIBTOOLS=/system/lib:/vendor/lib
SYSTEMLIBPATH=/system/lib
if [ "$API" -le "21" ]; then
# needed for some intermediate AOSP verions
cat /system/bin/toolbox > /system/toolbox
chmod 0755 /system/toolbox
ch_con /system/toolbox
fi
if [ "$ABI" = "x86" ]; then ARCH=x86; ARCHTOOLS=x86_tools; fi;
if [ "$ABI2" = "x86" ]; then ARCH=x86; ARCHTOOLS=x86_tools; fi;
if [ "$API" -eq "$API" ]; then
if [ "$API" -ge "17" ]; then
PIE=.pie
if unzip -l "$3" | grep -q "su.pie"; then
if [ "$ARCH" = "x86" ]; then SU=su.pie; fi;
fi
if [ "$ABILONG" = "armeabi-v7a" ]; then ARCH=armv7; ARCHTOOLS=arm_tools; fi;
if [ "$ABI" = "mip" ]; then ARCH=mips; ARCHTOOLS=mips_tools; fi;
if [ "$ABILONG" = "mips" ]; then ARCH=mips; ARCHTOOLS=mips_tools; fi;
fi
if [ "$API" -ge "18" ]; then
SUMOD=0755
fi
if [ "$API" -ge "20" ]; then
if [ "$ABILONG" = "arm64-v8a" ]; then ARCH=arm64; ARCHTOOLS=arm_tools; SYSTEMLIB=/system/lib64:/vendor/lib64; SYSTEMLIBTOOLS=/system/lib:/vendor/lib; SYSTEMLIBPATH=/system/lib64; APPPROCESS64=true; fi;
if [ "$ABILONG" = "mips64" ]; then ARCH=mips64; ARCHTOOLS=mips_tools; SYSTEMLIB=/system/lib64:/vendor/lib64; SYSTEMLIBTOOLS=/system/lib:/vendor/lib; SYSTEMLIBPATH=/system/lib64; APPPROCESS64=true; fi;
if [ "$ABILONG" = "x86_64" ]; then SU=su; ARCH=x64; ARCHTOOLS=x86_tools; SYSTEMLIB=/system/lib64:/vendor/lib64; SYSTEMLIBTOOLS=/system/lib:/vendor/lib; SYSTEMLIBPATH=/system/lib64; APPPROCESS64=true; fi;
APKFOLDER=true
APKNAME=/system/app/SuperSU/SuperSU.apk
fi
if [ "$API" -ge "19" ]; then
SUPOLICY=true
if ! [ -f "/system/toolbox" ]; then tbin="/bin"; else tbin=""; fi
if [ "$(LD_LIBRARY_PATH=$SYSTEMLIB /system${tbin}/toolbox ls -lZ /system/bin/toolbox | grep toolbox_exec > /dev/null; echo $?)" -eq "0" ]; then
INSTALL_RECOVERY_CONTEXT=u:object_r:toolbox_exec:s0
fi
fi
if [ "$API" -ge "21" ]; then
APPPROCESS=true
fi
fi
if [ ! -f $MKSH ]; then
MKSH=/system/bin/sh
fi
if [ -z "$BIN" ] || [ -z "$BINTOOLS" ]; then
ui_print "- Extracting files"
mkdir /dev/tmp 2>/dev/null
cd /dev/tmp
mkdir supersu
cd supersu
unzip -oq "$ZIP"
if [ $? -ne 0 ]; then
abort "Unzip failed. Aborting..."
fi
BIN=/dev/tmp/supersu/$ARCH
if [ ! -d "/dev/tmp/supersu/arm_tools" ]; then
if [ "$ARCH" = "armv7" ] || [ "$ARCH" = "arm64" ]; then ARCHTOOLS=arm; fi
if [ "$ARCH" = "x86" ] || [ "$ARCH" = "x64" ]; then ARCHTOOLS=x86; fi
if [ "$ARCH" = "mips" ] || [ "$ARCH" = "mips64" ]; then ARCHTOOLS=mips; fi
fi
BINTOOLS=/dev/tmp/supersu/$ARCHTOOLS; echo "TOOLS---$BINTOOLS" >&2
COM=/dev/tmp/supersu/common
fi
if grep -q SUGOTE "/dev/tmp/supersu/META-INF/com/google/android/update-binary"; then
if [ "$API" -ge "17" ] && [ "$API" -lt "22" ]; then
SUGOTE=true
fi
fi
# execute binaries from ramdisk
chmod -R 0755 $BIN/*
chmod -R 0755 $BINTOOLS/*
RAMDISKLIB=$BIN:$SYSTEMLIB
RAMDISKLIBTOOLS=$BINTOOLS:$SYSTEMLIBTOOLS
if [ "$API" -ge "19" ]; then
# 4.4+: permissive all teh things
LD_LIBRARY_PATH=$RAMDISKLIB $BIN/supolicy --live "permissive *" >/dev/null
fi
ui_print "- System mode"
ui_print "- Disabling OTA survival"
chmod 0755 $BINTOOLS/chattr$PIE
chattri /system/bin/su
chattri /system/xbin/su
chattri /system/bin/.ext/.su
chattri /system/sbin/su
chattri /vendor/sbin/su
chattri /vendor/bin/su
chattri /vendor/xbin/su
chattri /system/xbin/daemonsu
chattri /system/xbin/sugote
chattri /system/xbin/sugote_mksh
chattri /system/xbin/supolicy
chattri /system/xbin/ku.sud
chattri /system/xbin/.ku
chattri /system/xbin/.su
chattri /system/lib/libsupol.so
chattri /system/lib64/libsupol.so
chattri /system/etc/install-recovery.sh
chattri /system/bin/install-recovery.sh
ui_print "- Removing old files"
if [ -f "/system/bin/install-recovery.sh" ]; then
if [ ! -f "/system/bin/install-recovery_original.sh" ]; then
mv /system/bin/install-recovery.sh /system/bin/install-recovery_original.sh
ch_con /system/bin/install-recovery_original.sh
fi
fi
if [ -f "/system/etc/install-recovery.sh" ]; then
if [ ! -f "/system/etc/install-recovery_original.sh" ]; then
mv /system/etc/install-recovery.sh /system/etc/install-recovery_original.sh
ch_con /system/etc/install-recovery_original.sh
fi
fi
# only wipe these files in /system install, so not part of the wipe_ functions
rm -f /system/bin/install-recovery.sh
rm -f /system/etc/install-recovery.sh
rm -f /system/bin/su
rm -f /system/xbin/su
rm -f /system/sbin/su
rm -f /vendor/sbin/su
rm -f /vendor/bin/su
rm -f /vendor/xbin/su
rm -rf /data/app/eu.chainfire.supersu-*
rm -rf /data/app/eu.chainfire.supersu.apk
wipe_system_files_if_present
wipe_data_competitors_and_cache
rm -f /data/su.img
rm -f /cache/su.img
ui_print "- Creating space"
if ($APKFOLDER); then
if [ -f "/system/app/Maps/Maps.apk" ]; then
cp /system/app/Maps/Maps.apk /Maps.apk
rm /system/app/Maps/Maps.apk
fi
if [ -f "/system/app/GMS_Maps/GMS_Maps.apk" ]; then
cp /system/app/GMS_Maps/GMS_Maps.apk /GMS_Maps.apk
rm /system/app/GMS_Maps/GMS_Maps.apk
fi
if [ -f "/system/app/YouTube/YouTube.apk" ]; then
cp /system/app/YouTube/YouTube.apk /YouTube.apk
rm /system/app/YouTube/YouTube.apk
fi
else
if [ -f "/system/app/Maps.apk" ]; then
cp /system/app/Maps.apk /Maps.apk
rm /system/app/Maps.apk
fi
if [ -f "/system/app/GMS_Maps.apk" ]; then
cp /system/app/GMS_Maps.apk /GMS_Maps.apk
rm /system/app/GMS_Maps.apk
fi
if [ -f "/system/app/YouTube.apk" ]; then
cp /system/app/YouTube.apk /YouTube.apk
rm /system/app/YouTube.apk
fi
fi
ui_print "- Placing files"
mkdir /system/bin/.ext
set_perm 0 0 0777 /system/bin/.ext
cp_perm 0 0 $SUMOD $BIN/$SU /system/bin/.ext/.su
cp_perm 0 0 $SUMOD $BIN/$SU /system/xbin/su
cp_perm 0 0 0755 $BIN/$SU /system/xbin/daemonsu
if ($SUGOTE); then
cp_perm 0 0 0755 $BIN/$SU /system/xbin/sugote u:object_r:zygote_exec:s0
cp_perm 0 0 0755 $MKSH /system/xbin/sugote-mksh
fi
if ($SUPOLICY); then
cp_perm 0 0 0755 $BIN/supolicy /system/xbin/supolicy
cp_perm 0 0 0644 $BIN/libsupol.so $SYSTEMLIBPATH/libsupol.so
fi
if ($APKFOLDER); then
mkdir /system/app/SuperSU
set_perm 0 0 0755 /system/app/SuperSU
fi
cp_perm 0 0 0644 $COM/Superuser.apk $APKNAME
cp_perm 0 0 0755 $COM/install-recovery.sh /system/etc/install-recovery.sh
ln_con /system/etc/install-recovery.sh /system/bin/install-recovery.sh
if ($APPPROCESS); then
rm /system/bin/app_process
ln_con /system/xbin/daemonsu /system/bin/app_process
if ($APPPROCESS64); then
if [ ! -f "/system/bin/app_process64_original" ]; then
mv /system/bin/app_process64 /system/bin/app_process64_original
else
rm /system/bin/app_process64
fi
ln_con /system/xbin/daemonsu /system/bin/app_process64
if [ ! -f "/system/bin/app_process_init" ]; then
cp_perm 0 2000 0755 /system/bin/app_process64_original /system/bin/app_process_init
fi
else
if [ ! -f "/system/bin/app_process32_original" ]; then
mv /system/bin/app_process32 /system/bin/app_process32_original
else
rm /system/bin/app_process32
fi
ln_con /system/xbin/daemonsu /system/bin/app_process32
if [ ! -f "/system/bin/app_process_init" ]; then
cp_perm 0 2000 0755 /system/bin/app_process32_original /system/bin/app_process_init
fi
fi
fi
if [ -d "/system/etc/init.d" ]; then
cp_perm 0 0 0744 $COM/99SuperSUDaemon /system/etc/init.d/99SuperSUDaemon
fi
echo 1 > /system/etc/.installed_su_daemon
set_perm 0 0 0644 /system/etc/.installed_su_daemon
ui_print "- Restoring files"
if ($APKFOLDER); then
if [ -f "/Maps.apk" ]; then
cp_perm 0 0 0644 /Maps.apk /system/app/Maps/Maps.apk
rm /Maps.apk
fi
if [ -f "/GMS_Maps.apk" ]; then
cp_perm 0 0 0644 /GMS_Maps.apk /system/app/GMS_Maps/GMS_Maps.apk
rm /GMS_Maps.apk
fi
if [ -f "/YouTube.apk" ]; then
cp_perm 0 0 0644 /YouTube.apk /system/app/YouTube/YouTube.apk
rm /YouTube.apk
fi
else
if [ -f "/Maps.apk" ]; then
cp_perm 0 0 0644 /Maps.apk /system/app/Maps.apk
rm /Maps.apk
fi
if [ -f "/GMS_Maps.apk" ]; then
cp_perm 0 0 0644 /GMS_Maps.apk /system/app/GMS_Maps.apk
rm /GMS_Maps.apk
fi
if [ -f "/YouTube.apk" ]; then
cp_perm 0 0 0644 /YouTube.apk /system/app/YouTube.apk
rm /YouTube.apk
fi
fi
ui_print "- Post-installation script"
rm -f /system/toolbox
LD_LIBRARY_PATH=$SYSTEMLIB /system/xbin/su --install
ui_print "- Unmounting /system"
unmount /system
unmount /data
rm -rf /dev/tmp
ui_print "- Done !"
exit 0