-
Notifications
You must be signed in to change notification settings - Fork 4
/
adb push extracted apps-root.sh
59 lines (52 loc) · 1.57 KB
/
adb push extracted apps-root.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
#!/usr/bin/env bash
## Based on https://www.semipol.de/2016/07/30/android-restoring-apps-from-twrp-backup.html
## and my own findings on the ADB backup structure
export adb="~/bin/platform-tools/adb"
export packages=`ls apps`
# restore APK
for i in $packages; do
if [ -d "apps/$i/a" ]; then
$adb install -r "apps/$i/a/base.apk"
fi
done
# restore data
for i in $packages; do
if [ -d "apps/$i/f" ]; then
$adb push "apps/$i/f" "/sdcard/tmpdata/$i/files"
fi
if [ -d "apps/$i/db" ]; then
$adb push "apps/$i/db" "/sdcard/tmpdata/$i/databases"
fi
if [ -d "apps/$i/sp" ]; then
$adb push "apps/$i/sp" "/sdcard/tmpdata/$i/shared_prefs"
fi
if [ -d "apps/$i/r" ]; then
$adb push "apps/$i/r" "/sdcard/tmpdata/$i"
fi
if $adb shell [ -d "/sdcard/tmpdata/$i" ]; then
$adb shell su -c cp -r -F "/sdcard/tmpdata/$i" "/data/data/$i"
fi
if [ -d "apps/$i/ef" ]; then
$adb push "apps/$i/ef" "/sdcard/Android/data/$i/files"
fi
if [ -d "apps/$i/obb" ]; then
$adb push "apps/$i/obb" "/sdcard/Android/obb/$i"
fi
done
# restore data permissions
## set owner
for i in $packages; do
id=$($adb shell dumpsys package $i | grep userId)
# trim ` userId=`
id=${id:11}
# take first line only (some packages report ` userId=*\n userId=*`)
id=${id%%$'\n'*}
# if id is not empty
if [ ! -z $id ]; then
$adb shell chown -R $id:$id "/data/data/$i"
fi
done
## reset SELinux perms
for i in $packages; do
$adb shell restorecon -Rv "/data/data/$i"
done