-
Notifications
You must be signed in to change notification settings - Fork 2
/
apkpull
executable file
·60 lines (56 loc) · 1.2 KB
/
apkpull
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
#!/bin/bash
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/apkpull
#
PROG="${0##*/}"
#adb devices
usage() {
echo "search and retrieve an apk:"
echo "${PROG} [-l] [name]"
echo " -l list-only (no download)"
echo ""
exit 1
}
if [ "$1" = "-l" ]
then
if [ -n "$2" ]
then
ARG=$2
LIST=1
else
usage
fi
elif [ -n "$1" ]
then
ARG=$1
else
usage
fi
pkgs=$(adb shell pm list packages -f | grep -i -- "${ARG}")
count=$(wc -w <<< "$pkgs")
if [ ${count} -eq 1 -a ${LIST:-0} -eq 0 ]
then
path=${pkgs%=*}
adb pull ${path//package:/} >/dev/null 2>&1
path=${path%%-*}
path=${path##*/}
ver=$(adb shell pm dump ${path} | grep versionName | cut -f2 -d=)
abi=$(adb shell pm dump ${path} | grep primaryCpuAbi | cut -f2 -d=)
echo "retrieved apk:"
fn="${path}-${ver}-${abi}.apk"
fn=${fn//$'\n'/}
fn=${fn//$'\r'/}
mv base.apk "${fn}"
ls -alF "${fn}"
else
[[ ${LIST:-0} -eq 0 ]] && echo "too many pkgs, refine search"
echo "Found packages:"
for pkg in ${pkgs}
do
pkg=${pkg//package:/}
pkg=${pkg%=*}
echo " ${pkg}"
done
fi