forked from APK-Multi-Tool/APK-Multi-Tool-Linux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScript.sh
306 lines (284 loc) · 7.43 KB
/
Script.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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#! /bin/sh
# Apk Multi-Tool Alpha (C) 2010 by Daneshm90
# Ported to Linux by farmatito 2010
# Changelog for linux version:
# v 0.1 Initial version
# v 0.2 added "other" dir to PATH
# v 0.3 removed "function" bashism
# v 0.4 removed more bashisms
# v 0.5 added ogg batch optimization and quoted some vars
ap () {
echo "Where do you want adb to pull the apk from? "
echo "Example of input : /system/app/launcher.apk"
read INPUT
APK_FILE=`basename $INPUT`
adb pull "$INPUT" "place-apk-here-for-modding/$APK_FILE"
if [ "$?" -ne "0" ] ; then
echo "Error: while pulling $APK_FILE"
fi
}
ex () {
cd other
rm -f "../place-apk-here-for-modding/repackaged.apk"
rm -f "../place-apk-here-for-modding/repackaged-signed.apk"
rm -f "../place-apk-here-for-modding/repackaged-unsigned.apk"
rm -rf "../out"
if [ ! -d "../out" ] ; then
mkdir "../out"
fi
clear
# Must be -o"../out" and not -o "../out"
7za x -o"../out" ../place-apk-here-for-modding/*.apk
cd ..
}
opt () {
cd other
find "../out/res" -name *.png | while read PNG_FILE ;
do
if [ `echo "$PNG_FILE" | grep -c "\.9\.png$"` -eq 0 ] ; then
optipng -o99 "$PNG_FILE"
fi
done
cd ..
}
sys () {
cd other
7za a -tzip "../place-apk-here-for-modding/repackaged-unsigned.apk" ../out/* -mx9
cd ..
}
oa () {
rm -rf "out/META-INF"
sys
}
zip () {
clear
echo "1 System apk "
echo "2 Regular apk "
printf "%s" "Please make your decision: "
read RETVAL
if [ "x$RETVAL" = "x1" ] ; then
sys
elif [ "x$RETVAL" = "x2" ] ; then
oa
fi
}
si () {
cd other
INFILE="../place-apk-here-for-modding/repackaged-unsigned.apk"
OUTFILE="../place-apk-here-for-modding/repackaged-signed.apk"
if [ -e "$INFILE" ] ; then
java -jar signapk.jar -w testkey.x509.pem testkey.pk8 "$INFILE" "$OUTFILE"
if [ "x$?" = "x0" ] ; then
rm "$INFILE"
echo
fi
else
echo "Warning: cannot find file '$INFILE'"
fi
cd ..
}
zipa () {
for STRING in "signed" "unsigned"
do
if [ -e "place-apk-here-for-modding/repackaged-$STRING.apk" ] ; then
zipalign -fv 4 "place-apk-here-for-modding/repackaged-$STRING.apk" "place-apk-here-for-modding/repackaged-$STRING-aligned.apk"
if [ "x$?" = "x0" ] ; then
mv -f "place-apk-here-for-modding/repackaged-$STRING-aligned.apk" "place-apk-here-for-modding/repackaged-$STRING.apk"
fi
else
echo "zipalign: cannot find file 'place-apk-here-for-modding/repackaged-$STRING.apk'"
fi
done
}
ins () {
sudo adb devices
printf "%s" "Hit Enter to continue "
read DUMMY
adb install -r "place-apk-here-for-modding/repackaged-signed.apk"
}
alli () {
clear
echo "1 System apk "
echo "2 Regular apk "
printf "%s" "Please make your decision: "
read RETVAL
if [ "x$RETVAL" = "x1" ] ; then
sys
si
ins
elif [ "x$RETVAL" = "x2" ] ; then
oa
si
ins
fi
}
apu () {
echo "Where do you want adb to push to and as what name: "
echo "Example of input : /system/app/launcher.apk "
read INPUT
sudo adb devices
printf "%s" "Hit Enter to continue "
read DUMMY
adb remount
adb push "place-apk-here-for-modding/repackaged-unsigned.apk" "$INPUT"
}
de () {
cd other
rm -f "../place-apk-here-for-modding/repackaged.apk"
rm -f "../place-apk-here-for-modding/repackaged-signed.apk"
rm -f "../place-apk-here-for-modding/repackaged-unsigned.apk"
rm -rf "../out"
rm -rf "out.out"
clear
java -jar apktool.jar d ../place-apk-here-for-modding/*.apk "../out"
cd ..
}
co () {
cd other
java -jar apktool.jar b "../out" "../place-apk-here-for-modding/repackaged-unsigned.apk"
cd ..
}
all () {
co
si
ins
}
bopt () {
cd other
mkdir -p "../place-apk-here-to-batch-optimize/original"
find "../place-apk-here-to-batch-optimize" -name *.apk | while read APK_FILE ;
do
echo "Optimizing $APK_FILE"
# Extract
7za x -o"../place-apk-here-to-batch-optimize/original" "../place-apk-here-to-batch-optimize/$APK_FILE"
# PNG
find "../place-apk-here-to-batch-optimize/original" -name *.png | while read PNG_FILE ;
do
if [ `echo "$PNG_FILE" | grep -c "\.9\.png$"` -eq 0 ] ; then
optipng -o99 "$PNG_FILE"
fi
done
# TODO optimize .ogg files
# Re-compress
7za a -tzip "../place-apk-here-to-batch-optimize/temp.zip" ../place-apk-here-to-batch-optimize/original/* -mx9
FILE=`basename "$APK_FILE"`
DIR=`dirname "$APK_FILE"`
mv -f "../place-apk-here-to-batch-optimize/temp.zip" "$DIR/optimized-$FILE"
rm -rf ../place-apk-here-to-batch-optimize/original/*
done
rm -rf "../place-apk-here-to-batch-optimize/original"
cd ..
}
asi () {
cd other
rm -f "../place-apk-here-for-signing/signed.apk"
java -jar signapk.jar -w testkey.x509.pem testkey.pk8 ../place-apk-here-for-signing/*.apk "../place-apk-here-for-signing/signed.apk"
#clear
cd ..
}
ogg () {
cd other
find "../place-ogg-here/" -name *.ogg | while read OGG_FILE ;
do
FILE=`basename "$OGG_FILE"`
DIR=`dirname "$OGG_FILE"`
printf "%s" "Optimizing: $FILE"
sox "$OGG_FILE" -C 0 "$DIR/optimized-$FILE"
if [ "x$?" = "x0" ] ; then
printf "\n"
else
printf "...%s\n" "Failed"
fi
done
}
quit () {
exit 0
}
restart () {
echo
echo "****************************** Apk Multi-Tool *******************************"
echo "------------------Simple Tasks Such As Image Editing----------------------"
echo " 0 Adb pull"
echo " 1 Extract apk"
echo " 2 Optimize images inside (Only if \"Extract Apk\" was selected)"
echo " 3 Zip apk"
echo " 4 Sign apk (Dont do this if its a system apk)"
echo " 5 Zipalign apk (Do once apk is created/signed)"
echo " 6 Install apk (Dont do this if system apk, do adb push)"
echo " 7 Zip / Sign / Install apk (All in one step)"
echo " 8 Adb push (Only for system apk)"
echo "-----------------Advanced Tasks Such As Code Editing-----------------------"
echo " 9 Decompile apk"
echo " 10 Compile apk"
echo " 11 Sign apk"
echo " 12 Install apk"
echo " 13 Compile apk / Sign apk / Install apk (All in one step)"
echo "---------------------------------------------------------------------------"
echo " 14 Batch Optimize Apk (inside place-apk-here-to-batch-optimize only)"
echo " 15 Sign an apk (inside place-apk-here-for-signing folder only)"
echo " 16 Batch optimize ogg files (inside place-ogg-here only)"
echo " 17 Quit"
echo "****************************************************************************"
echo
printf "%s" "Please make your decision: "
read ANSWER
case "$ANSWER" in
0) ap ;;
1) ex ;;
2) opt ;;
3) zip ;;
4) si ;;
5) zipa ;;
6) ins ;;
7) alli ;;
8) apu ;;
9) de ;;
10) co ;;
11) si ;;
12) ins ;;
13) all ;;
14) bopt ;;
15) asi ;;
16) ogg ;;
17) quit ;;
*)
echo "Unknown command: '$ANSWER'"
;;
esac
}
# Start
PATH="$PATH:$PWD/other"
export PATH
#echo $PATH
# Test for needed programs and warn if missing
ERROR="0"
for PROGRAM in "optipng" "7za" "java" "sudo" "adb" "aapt" "sox"
do
which "$PROGRAM" > /dev/null
if [ "x$?" = "x1" ] ; then
ERROR="1"
echo "The program $PROGRAM is missing or is not in your PATH,"
echo "please install it or fix your PATH variable"
fi
done
if [ "x$ERROR" = "x1" ] ; then
exit 1
fi
clear
printf "%s" "Do you want to clean out all your current projects (y/N)? "
read INPUT
if [ "x$INPUT" = "xy" ] || [ "x$INPUT" = "xY" ] ; then
rm -rf place-apk-here-for-modding
rm -rf place-apk-here-for-signing
rm -rf place-apk-here-to-batch-optimize
rm -rf out
rm -rf $HOME/apktool
mkdir place-apk-here-for-modding
mkdir place-apk-here-for-signing
mkdir place-apk-here-to-batch-optimize
fi
while [ "1" = "1" ] ;
do
restart
done
exit 0