-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtractor.sh
More file actions
121 lines (110 loc) · 2.86 KB
/
Extractor.sh
File metadata and controls
121 lines (110 loc) · 2.86 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
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
#!/bin/bash
usemsg(){
echo 'IMPORTANT!'
echo 'Before running this script, please ensure the following:'
echo '1. Developer Options is enabled on your device'
echo '2. USB Debugging is enabled on your device'
echo '3. Your device is connected via USB'
echo '4. Target app is running and focused'
echo '5. Ensure that /path/to/extract/to/appName exists'
echo
echo
echo 'Parameters:'
echo '-h Help menu'
echo '-e Start extraction process. Must provide destination path'
echo
echo 'Use:'
echo 'Extractor.sh -h'
echo 'Extractor.sh -e /path/to/extract/to/appName'
}
apkExtraction(){
echo 'Initiating APK extractions from device...'
deviceApkPaths=$(adb shell pm path "$1" | sed -E 's/package://')
while IFS= read -r line; do
trimmedLine=$(echo "$line" | xargs | sed 's/\r$//')
if [ "$trimmedLine" == '' ]
then
continue
fi
IFS='/' read -r -a pathSections <<< "$trimmedLine"
apkName="${pathSections[-1]}"
adb pull "$trimmedLine"
mv "$apkName" "$2"
echo "Complete."
done <<< "$deviceApkPaths"
echo 'Extraction complete.'
echo 'Initiating APK decompilation...'
localApkPaths=$(find "$2" -maxdepth 1 -name '*.apk')
echo "$localApkPaths"
while IFS= read -r line; do
apktool d "$line"
done <<< "$localApkPaths"
echo 'Decompilation complete.'
echo "Decompiled files can be found in directory:"
echo "$2"
}
dataExtraction(){
abFile="$2/$1.ab"
tarFile="$2/$1.tar"
echo 'Creating backup of app data...'
adb backup -f "$abFile" "$1"
echo 'Backup complete.'
echo 'Initiating data extraction...'
dd if="$abFile" bs=1 skip=24 | python3 -c "import zlib,sys;sys.stdout.buffer.write(zlib.decompress(sys.stdin.buffer.read()))" > "$tarFile"
tar -xf "$tarFile" -C "$2"
rm "$abFile" -f
rm "$tarFile" -f
echo 'Extraction complete.'
echo "Data files can be found in directory:"
echo "$2"
}
initiateExtraction(){
deviceId=$(adb devices | sed '1d' | grep -v '^[[:space:]]*$' | awk '{print $1}')
if [ "$deviceId" == '' ]
then
usemsg
exit 1
fi
deviceModel=$(adb -s "$deviceId" shell getprop ro.product.model)
appPackage=$(adb shell dumpsys window windows | grep -E 'mCurrentFocus' | awk '{print $3}' | sed 's/\/.*//')
if [ "$appPackage" == '' ]
then
echo 'App not found.'
exit 1
fi
if [ ! -d "$1" ]
then
mkdir "$1"
fi
echo "Target device: $deviceModel"
echo "Targeting package: $appPackage"
decompiledDirectory="$1/decompiled"
if [ ! -d "$decompiledDirectory" ]
then
mkdir "$decompiledDirectory"
fi
apkExtraction "$appPackage" "$decompiledDirectory"
dataExtractionDirectory="$1/data"
if [ ! -d "$dataExtractionDirectory" ]
then
mkdir "$dataExtractionDirectory"
fi
dataExtraction "$appPackage" "$dataExtractionDirectory"
}
while getopts ":e:h" OPTION
do
case "$OPTION" in
h)
usemsg
exit 0
;;
e)
initiateExtraction $2
exit 0
;;
*)
usemsg
exit 1
;;
esac
done