-
Notifications
You must be signed in to change notification settings - Fork 0
/
apkget
executable file
·116 lines (96 loc) · 3.14 KB
/
apkget
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
#!/usr/bin/env bash
# DTF Core Content
# Copyright 2013-2015 Jake Valletta (@jake_valletta)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#@About: Pull or search for a package on a device.
#@Author: Jake Valletta (jakev)
#@Health: stable
#@Version: 1.1.0
. $DTF_CORE
. $DTF_LOG
usage()
{
echo "Usage: apkget OPTIONS <package_name>"
echo " OPTIONS:"
echo " -o Pull package's ODEX"
echo " -s Search for package"
echo " -p Pull package"
echo " -h Prints this menu"
exit 1
}
if [ $# -lt 1 ] ; then
usage
fi
package=""
search=""
odex=""
#Process the arguments
while getopts hdeo:p:s: opt
do
case "$opt" in
h) usage;;
o) odex=$OPTARG;;
p) package=$OPTARG;;
s) search=$OPTARG;;
\?) usage;;
esac
done
adb wait-for-device
cd "${LAUNCH_DIR}"
if [ $search ]; then
echo "Searching for \"${search}\"..."
adb shell "pm list packages"|grep -i "$search"|awk '{print $1}'
exit 0
elif [ $package ]; then
log_i "Attempting to pull APK for \"${package}\"..."
package_path=$(adb shell pm path ${package} | tr -d '\r' |awk -F":" '{print $2}')
if [ -z $package_path ]; then
log_e "No packages match the string \"${package}\""
exit 1
else
log_i "Found match for \"${package}\""
adb pull $package_path > /dev/null 2>&1
exit 0
fi
elif [ $odex ]; then
log_i "Attempting to pull ODEX for \"${odex}\"..."
apk_path=$(adb shell pm path ${odex} | tr -d '\r' |awk -F":" '{print $2}')
if [ $apk_path ]; then
log_i "Found match for \"${odex}\""
package_path=$(dirname $apk_path)
odex_name=$(basename $apk_path| sed 's/\.apk$/.odex/')
# Need to act differently depending on Dalvik/ART
vm_type=$(dtf prop get Info vmtype)
# Device is using ART/ART64
if [[ "$vm_type" == "ART"* ]]; then
# It's not with checking the bits, as both can exist.
log_i "Attempting to pull 32-bit ODEX..."
adb pull ${package_path}/arm/${odex_name} > /dev/null 2>&1
log_i "Attempting to pull 64-bit ODEX..."
adb pull ${package_path}/arm64/${odex_name} > /dev/null 2>&1
# Dalvik, so path is easy.
else
package_path=$(dirname $apk_path)
odex_name=$(basename $apk_path| sed 's/\.apk$/.odex/')
log_i "Attempting to pull 32-bit ODEX..."
adb pull ${package_path}/${odex_name} > /dev/null 2>&1
fi
else
log_e "No packages match the string \"${odex}\""
exit 1
fi
else
echo "[ERROR] You must specify -p or -s!"
usage
fi