-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart
More file actions
executable file
·271 lines (249 loc) · 7.84 KB
/
start
File metadata and controls
executable file
·271 lines (249 loc) · 7.84 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
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
#!/bin/bash
#
# Copyright 2015 Matthew Booth
#
# 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.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
ROOT="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$ROOT/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
ROOT="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
ADB="$ROOT"/tools/adb
SIGNAPK="$ROOT"/tools/signapk.jar
APKTOOL="$ROOT"/tools/apktool
ZIPALIGN="$ROOT"/tools/zipalign
CERTIFICATE="$ROOT"/tools/certificate.pem
KEY="$ROOT"/tools/key.pk8
FRAMEWORKS="$ROOT"/frameworks
WORKING="$ROOT"/working
OUT="$ROOT"/out
startOptions() {
echo " "
echo "What would you like to do?"
select start in "Compile" "Decompile" "Sign" "Zipalign" "Framework Options" "Delete Files Options" "Exit"; do
case $start in
"Compile" ) compileOptions; break;;
"Decompile" ) decompileOptions; break;;
"Sign" ) signOptions; break;;
"Zipalign" ) zipalignOptions; break;;
"Framework Options" ) frameworkOptions; break;;
"Delete Files Options" ) deleteOptions; break;;
"Exit" ) exit 0; break;;
esac
done
}
compileOptions() {
echo " "
echo "What would you like to do?"
select compile in "Compile all APKs in working" "Compile a single APK" "Compile all JARs in working" "Compile a single JAR" "Go back"; do
case $compile in
"Compile all APKs in working" ) compile all apk; break;;
"Compile a single APK" ) compile single apk; break;;
"Compile all JARs in working" ) compile all jar; break;;
"Compile a single JAR" ) compile single jar; break;;
"Go back" ) startOptions; break;;
esac
done
}
compile() {
if [ $1 == "all" ]; then
cd "$WORKING"
for f in *."$2"; do "$APKTOOL" b -c "$WORKING"/"$f" -o "$OUT"/"$f"; done
cd ..
else
cd "$WORKING"
i=1
for f in *."$2"; do compList[i++]="${f%/}"; done
for((i=1;i<=${#compList[@]};i++)); do echo $i")" "${compList[i]}"; done
echo "which $2 do you want?"
echo -n "> "
read i
"$APKTOOL" b -c "$WORKING"/"${compList[$i]}" -o "$OUT"/"${compList[$i]}"
cd "$ROOT"
fi
compileOptions
}
decompileOptions() {
echo " "
echo "What would you like to do?"
select decompile in "Decompile all APKs" "Decompile a single APK" "Decompile all JARs" "Decompile a single JAR" "Go back"; do
case $decompile in
"Decompile all APKs" ) decompile all apk; break;;
"Decompile a single APK" ) decompile single apk; break;;
"Decompile all JARs" ) decompile all jar; break;;
"Decompile a single JAR" ) decompile single jar; break;;
"Go back" ) startOptions; break;;
esac
done
}
decompile() {
if [ $1 == "all" ]; then
cd "$2"
for f in *."$2"; do "$APKTOOL" d -b "$f" -o "$WORKING"/"$f"; done
cd ..
else
cd "$2"
i=1
for f in *."$2"; do decompList[i++]="${f%/}"; done
for((i=1;i<=${#decompList[@]};i++)); do echo $i")" "${decompList[i]}"; done
echo "which $2 do you want?"
echo -n "> "
read i
"$APKTOOL" d -b "${decompList[$i]}" -o "$WORKING"/"${decompList[$i]}"
cd "$ROOT"
fi
decompileOptions
}
signOptions() {
echo " "
echo "What would you like to do?"
select sign in "Sign all in out" "Sign a single file in out" "Go back"; do
case $sign in
"Sign all in out" )sign all; break;;
"Sign a single file in out" ) sign single; break;;
"Go back" ) startOptions; break;;
esac
done
}
sign() {
if [ $1 == "all" ]; then
cd "$OUT"
for f in "$OUT"/*.apk; do cp "$f" copy_"$f"; java -jar "$SIGNAPK" "$CERTIFICATE" "$KEY" copy_"$f" "$f"; rm copy_"$f"; done
cd ..
else
cd "$OUT"
i=1
for f in "$OUT"/*.apk; do signList[i++]="${f%/}"; done
for((i=1;i<=${#signList[@]};i++)); do echo $i")" "${signList[i]}"; done
echo "which apk do you want?"
echo -n "> "
read i
cp "${signList[$i]}" copy_"${signList[$i]}"
java -jar "$SIGNAPK" "$CERTIFICATE" "$KEY" copy_"${signList[$i]}" "${signList[$i]}"
rm copy_"${signList[$i]}"
cd "$ROOT"
fi
signOptions
}
zipalignOptions() {
echo " "
echo "What would you like to do?"
select zipalign in "Zipalign all in out" "Zipalign a single file in out" "Go back"; do
case $zipalign in
"Zipalign all in out" ) break;;
"Zipalign a single file in out" ) break;;
"Go back" ) startOptions; break;;
esac
done
}
zipalign() {
if [ $1 == "all" ]; then
cd "$OUT"
for f in "$OUT"/*.apk; do cp "$f" copy_"$f"; java -jar "$ZIPALIGN" -f 4 copy_"$f" "$f"; rm copy_"$f"; done
cd ..
else
cd "$OUT"
i=1
for f in "$OUT"/*.apk; do zipList[i++]="${f%/}"; done
for((i=1;i<=${#zipList[@]};i++)); do echo $i")" "${zipList[i]}"; done
echo "which apk do you want?"
echo -n "> "
read i
cp "${zipList[$i]}" copy_"${zipList[$i]}"
java -jar "$ZIPALIGN" -f 4 copy_"${zipList[$i]}" "${zipList[$i]}"
rm copy_"${zipList[$i]}"
cd "$ROOT"
fi
zipalignOptions
}
frameworkOptions() {
echo " "
echo "What would you like to do?"
select framework in "Pull and set framework from phone" "Set existing framework" "Go back"; do
case $framework in
"Pull and set framework from phone" ) framework ;break;;
"Set existing framework" ) framework existing; break;;
"Go back" ) startOptions; break;;
esac
done
}
framework() {
if [ "$1" == "existing" ]; then
cd "$FRAMEWORKS"
i=1
for f in *.apk; do frameList[i++]="${f%/}"; done
for((i=1;i<=${#frameList[@]};i++)); do echo $i")" "${frameList[i]}"; done
echo "which framework do you want?"
echo -n "> "
read i
"$APKTOOL" if "${frameList[$i]}"
cd "$ROOT"
else
if "$ADB" devices 2>&1 | (tail -n2) | grep "device" >> /dev/null; then
echo "Device present"
"$ADB" pull /system/framework/framework-res.apk "$FRAMEWORKS"/temp.apk
echo -e "\e[1;91mChoose a new descriptive name for this framework. For instance \"S6_TouchWiz_5.1.1\", or \"CM_M9_5.1.1\". Do not add \"framework-res\", as this is added automatically"
echo -e "\e[0m "
read newName
mv "$FRAMEWORKS"/temp.apk "$FRAMEWORKS"/framework-res_"$newName".apk
"$APKTOOL" if "$FRAMEWORKS"/framework-res_"$newName".apk
else
echo "Device not present, found or ADB debugging not enabled"
fi
fi
frameworkOptions
}
deleteOptions() {
echo " "
echo "What would you like to do?"
select delete in "Delete all in apk" "Delete all in jar" "Delete all in working" "Delete all in out" "Delete all" "Go back"; do
case $delete in
"Delete all in apk" ) delete apk ;break;;
"Delete all in jar" ) delete jar; break;;
"Delete all in working" ) delete working; break;;
"Delete all in out" ) delete out; break;;
"Delete all" ) delete all; break;;
"Go back" ) startOptions; break;;
esac
done
}
delete() {
echo " "
echo "What would you like to do?"
select sure in "Yes" "No"; do
case $sure in
"Yes" ) AREYOUSURE=1 ;break;;
"No" ) AREYOUSURE=0; break;;
esac
done
if [ "$AREYOUSURE" == "1" ]; then
if [ "$1" == "all" ]; then
ls -1 "$ROOT"/apk | grep -E -v '.keep' | xargs rm -f
ls -1 "$ROOT"/jar | grep -E -v '.keep' | xargs rm -f
ls -1 "$ROOT"/out | grep -E -v '.keep' | xargs rm -f
ls -1 "$ROOT"/working | grep -E -v '.keep' | xargs rm -f
else
ls -1 "$ROOT"/"$1" | grep -E -v '.keep' | xargs rm -f
fi
fi
deleteOptions
}
echo " "
echo -e "\e[1;91mMatt Booth's apktool script"
echo -e "\e[0m "
echo -e "\e[1;91mPlease make your selections carefully"
echo -e "\e[0m "
startOptions
exit 0