-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapku
executable file
·766 lines (736 loc) · 21.2 KB
/
apku
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
#!/bin/bash
# ===== Variables
PROJECT_NAME="Apk Utility"
VERSION="$PROJECT_NAME v2.4"
DESCRIPTION="An APK & JAR Manipulation Utility"
BASE=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
INPUT_DIR=$BASE/input
OUTPUT_DIR=$BASE/output
TOOLS_DIR=$BASE/tools
TAG_LIST=$TOOLS_DIR/tag_list
WORK_DIR=$TOOLS_DIR/work_temp
DECOMPILED_DIR=$BASE/decompiled
APKTOOL=$TOOLS_DIR/apktool
ZIPALIGN=$TOOLS_DIR/zipalign
FRAMEWORKS_DIR=$TOOLS_DIR/frameworks
ZIPALIGN_DIR=$BASE/zipalign
SIGN_JAR=$TOOLS_DIR/sign.jar
APKTOOL_JAR=$TOOLS_DIR/apktool.jar
TOOL_7ZA=$TOOLS_DIR/7za
THIS_SCRIPT=$BASE/$(basename $0)
DESKTOP_SHORTCUT=/home/$(whoami)/.local/share/applications/apk-utility.desktop
ICON=$TOOLS_DIR/icon.png
UPDATE_URL="https://techstop.github.io/apk-utility/"
REPO_URL="https://github.com/GameTheory-/apk-utility"
# ===== ANSI color code variables
BOLD="\e[1m"
CYAN="\e[96m"
BLUEBG="\e[104m"
GREEN="\e[0;32m"
HRED="\e[0;91m"
WHITE="\e[97m"
NC="\e[0m"
EXPND="\e[K"
# ===== make sure files have exec perms
if [[ ! -x "$APKTOOL" ]]; then
chmod +x "$APKTOOL"
fi
if [[ ! -x "$ZIPALIGN" ]]; then
chmod +x "$ZIPALIGN"
fi
if [[ ! -x "$APKTOOL_JAR" ]]; then
chmod +x "$APKTOOL_JAR"
fi
if [[ ! -x "$SIGN_JAR" ]]; then
chmod +x "$SIGN_JAR"
fi
if [[ ! -x "$TOOL_7ZA" ]]; then
chmod +x "$TOOL_7ZA"
fi
# ===== for centering strings
ECHO_CENTER() {
printf "%*s\n" $((( ${#1} + $(tput cols) ) / 2)) "$1"
}
# ===== ECHO_CENTER variables go here
NAME_TXT=$(ECHO_CENTER "$PROJECT_NAME")
# ===== continue
PRESS_ENTER() {
echo ""
echo -n -e " ${GREEN}Press Enter to continue${NC} "
read
clear
}
# ===== incorrect selection
INCORRECT_SELECTION() {
echo -e "${HRED}Incorrect selection! Try again.${NC}"
}
# ===== Create temp folder for zipaligning
WorkDir() {
if [ ! -d "$WORK_DIR" ]; then
mkdir "$WORK_DIR"
fi
}
# ===== Create frameworks dir
FrameWorkDir() {
if [ ! -d "$FRAMEWORKS_DIR" ]; then
mkdir "$FRAMEWORKS_DIR"
fi
}
# ===== Create decompiled dir
DecompiledDir() {
if [ ! -d "$DECOMPILED_DIR" ]; then
mkdir "$DECOMPILED_DIR"
fi
}
# ===== Create output dir
OutputDir() {
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir "$OUTPUT_DIR"
fi
}
# ===== Decompile apk
Decomp() {
if ls "$INPUT_DIR"/*.apk > /dev/null 2>&1 || ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
DecompiledDir
cd "$INPUT_DIR"
echo -e "${GREEN}Make selection to decompile.${NC}"
PROMPT="
Enter selection:"
if ! ls "$INPUT_DIR"/*.apk > /dev/null 2>&1; then
OPTIONS=( *.jar )
elif ! ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
OPTIONS=( *.apk )
else
OPTIONS=( *.apk *.jar )
fi
QUIT=$(echo -e "${HRED}Quit${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
"$APKTOOL" d -f $OPT -p "$FRAMEWORKS_DIR" -o "$DECOMPILED_DIR"/${OPT%.*}
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There are no valid apk or jar files in the input folder.${NC}"
fi
}
# ===== Decompile apk without dex(smali)
DecompD() {
if ls "$INPUT_DIR"/*.apk > /dev/null 2>&1 || ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
DecompiledDir
cd "$INPUT_DIR"
echo -e "${GREEN}Make selection to decompile.${NC}"
PROMPT="
Enter selection:"
if ! ls "$INPUT_DIR"/*.apk > /dev/null 2>&1; then
OPTIONS=( *.jar )
elif ! ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
OPTIONS=( *.apk )
else
OPTIONS=( *.apk *.jar )
fi
QUIT=$(echo -e "${HRED}Quit${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
"$APKTOOL" d -f -s $OPT -p "$FRAMEWORKS_DIR" -o "$DECOMPILED_DIR"/${OPT%.*}
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There are no valid apk or jar files in the input folder.${NC}"
fi
}
# ===== Decompile tagged apk
DecompTag() {
if ls "$INPUT_DIR"/*.apk > /dev/null 2>&1 || ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
DecompiledDir
cd "$INPUT_DIR"
echo -e "${GREEN}Make selection to decompile.${NC}"
PROMPT="
Enter selection:"
if ! ls "$INPUT_DIR"/*.apk > /dev/null 2>&1; then
OPTIONS=( *.jar )
elif ! ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
OPTIONS=( *.apk )
else
OPTIONS=( *.apk *.jar )
fi
QUIT=$(echo -e "${HRED}Quit${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
if [[ -f "$TAG_LIST" && -s "$TAG_LIST" ]]; then
echo -e "${GREEN}Choose a tag from the list.${NC}"
echo ""
PS3="
Enter selection: "
readarray -t options < "$TAG_LIST"
select TAG in "${options[@]}" "$QUIT"; do
if (( REPLY == 1 + ${#options[@]} )); then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#options[@]} )); then
clear
"$APKTOOL" d -f $OPT -t $TAG -p "$FRAMEWORKS_DIR" -o "$DECOMPILED_DIR"/${OPT%.*}
break
fi
done
else
echo -e "${HRED}You do not have any installed tagged framework files.${NC}"
fi
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There are no valid apk or jar files in the input folder.${NC}"
fi
}
# ===== Decompile tagged apk without dex(smali)
DecompTagD() {
if ls "$INPUT_DIR"/*.apk > /dev/null 2>&1 || ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
DecompiledDir
cd "$INPUT_DIR"
echo -e "${GREEN}Make selection to decompile.${NC}"
PROMPT="
Enter selection:"
if ! ls "$INPUT_DIR"/*.apk > /dev/null 2>&1; then
OPTIONS=( *.jar )
elif ! ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
OPTIONS=( *.apk )
else
OPTIONS=( *.apk *.jar )
fi
QUIT=$(echo -e "${HRED}Quit${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
if [[ -f "$TAG_LIST" && -s "$TAG_LIST" ]]; then
echo -e "${GREEN}Choose a tag from the list.${NC}"
echo ""
PS3="
Enter selection: "
readarray -t options < "$TAG_LIST"
select TAG in "${options[@]}" "$QUIT"; do
if (( REPLY == 1 + ${#options[@]} )); then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#options[@]} )); then
clear
"$APKTOOL" d -f -s $OPT -t $TAG -p "$FRAMEWORKS_DIR" -o "$DECOMPILED_DIR"/${OPT%.*}
break
fi
done
else
echo -e "${HRED}You do not have any installed tagged framework files.${NC}"
fi
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There are no valid apk or jar files in the input folder.${NC}"
fi
}
# ===== Build apk
Compile() {
if ls -d "$DECOMPILED_DIR"/* > /dev/null 2>&1; then
OutputDir
cd "$DECOMPILED_DIR"
echo -e "${GREEN}Make selection to compile.${NC}"
PROMPT="
Enter selection:"
OPTIONS=( $(ls -d "$DECOMPILED_DIR"/* | xargs -d '\n' -n 1 basename) )
QUIT=$(echo -e "${HRED}Quit${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
"$APKTOOL" b --use-aapt2 -f "$OPT" -p "$FRAMEWORKS_DIR"
if [ -f "$OPT"/dist/*.apk ] || [ -f "$OPT"/dist/*.jar ]; then
FILE=$(find "$OPT"/dist -type f -name "*.*")
if [ ! -z "$FILE" ]; then
WorkDir
files=
for files in $FILE ; do
"$ZIPALIGN" -c 4 "$files"
ZIPCHECK=$?
if [ "$ZIPCHECK" = "1" ]; then
"$ZIPALIGN" -f 4 "$files" "$WORK_DIR"/$(basename "$files")
if [ -f "$WORK_DIR"/$(basename "$files") ]; then
mv -f "$WORK_DIR"/$(basename "$files") "$OUTPUT_DIR"/
rm -f "$files"
echo ""
echo Zipaligned $(basename "$files")
else
echo -e "${HRED}Zipalign Failed!${NC}"
fi
else
mv -f "$files" "$OUTPUT_DIR"/
echo ""
echo Zipaligned $(basename "$files")
fi
done
fi
else
echo ""
echo -e "${HRED}Failed to compile apk or jar file.${NC}"
fi
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There is no valid decompiled apk or jar file in the decompiled folder.${NC}"
fi
}
# ===== Build signed apk
CompileSign() {
if ls -d "$DECOMPILED_DIR"/* > /dev/null 2>&1; then
OutputDir
cd "$DECOMPILED_DIR"
echo -e "${GREEN}This option uses the original ${HRED}META-INF${NC} ${GREEN}and${NC} ${HRED}AndroidManifest.xml${NC}"
echo -e "${GREEN}for proper signing. If you made changes to the AndroidManifest.xml"
echo "those changes will be lost. Use option 5 instead from the main menu"
echo "to keep those changes."
echo ""
echo -e "Make selection to compile:${NC}"
PROMPT="
Enter selection:"
OPTIONS=( $(ls -d "$DECOMPILED_DIR"/* | xargs -d '\n' -n 1 basename) )
QUIT=$(echo -e "${HRED}Quit${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
"$APKTOOL" b --use-aapt2 -f "$OPT" -p "$FRAMEWORKS_DIR"
if [ -d $OPT/dist ]; then
if [ -f $OPT/dist/*.apk ]; then
LS_APK=$("$TOOL_7ZA" l "$INPUT_DIR"/$(basename $OPT).apk)
if [[ "$LS_APK" == *"AndroidManifest.xml"* ]]; then
"$TOOL_7ZA" x -aoa "$INPUT_DIR"/$(basename $OPT).apk AndroidManifest.xml
"$TOOL_7ZA" a -tzip $OPT/dist/$(basename $OPT).apk "$DECOMPILED_DIR"/AndroidManifest.xml
rm -f "$DECOMPILED_DIR"/AndroidManifest.xml
fi
if [[ "$LS_APK" == *"META-INF"* ]]; then
"$TOOL_7ZA" x -aoa "$INPUT_DIR"/$(basename $OPT).apk META-INF/*
"$TOOL_7ZA" a -tzip $OPT/dist/$(basename $OPT).apk "$DECOMPILED_DIR"/META-INF
rm -rf "$DECOMPILED_DIR"/META-INF
fi
elif [ -f $OPT/dist/*.jar ]; then
LS_JAR=$("$TOOL_7ZA" l "$INPUT_DIR"/$(basename $OPT).jar)
if [[ "$LS_JAR" == *"AndroidManifest.xml"* ]]; then
"$TOOL_7ZA" x -aoa "$INPUT_DIR"/$(basename $OPT).jar AndroidManifest.xml
"$TOOL_7ZA" a -tzip $OPT/dist/$(basename $OPT).jar "$DECOMPILED_DIR"/AndroidManifest.xml
rm -f "$DECOMPILED_DIR"/AndroidManifest.xml
fi
if [[ "$LS_JAR" == *"META-INF"* ]]; then
"$TOOL_7ZA" x -aoa "$INPUT_DIR"/$(basename $OPT).jar META-INF/*
"$TOOL_7ZA" a -tzip $OPT/dist/$(basename $OPT).jar "$DECOMPILED_DIR"/META-INF
rm -rf "$DECOMPILED_DIR"/META-INF
fi
fi
fi
if [ -f "$OPT"/dist/*.apk ] || [ -f "$OPT"/dist/*.jar ]; then
FILE=$(find "$OPT"/dist -type f -name "*.*")
if [ ! -z "$FILE" ]; then
WorkDir
files=
for files in $FILE ; do
"$ZIPALIGN" -c 4 "$files"
ZIPCHECK=$?
if [ "$ZIPCHECK" = "1" ]; then
"$ZIPALIGN" -f 4 "$files" "$WORK_DIR"/$(basename "$files")
if [ -f "$WORK_DIR"/$(basename "$files") ]; then
mv -f "$WORK_DIR"/$(basename "$files") "$OUTPUT_DIR"/
rm -f "$files"
echo ""
echo Zipaligned $(basename "$files")
else
echo -e "${HRED}Zipalign Failed!${NC}"
fi
else
mv -f "$files" "$OUTPUT_DIR"/
echo ""
echo Zipaligned $(basename "$files")
fi
done
fi
else
echo ""
echo -e "${HRED}Failed to compile apk or jar file.${NC}"
fi
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There is no valid decompiled apk or jar file in the decompiled folder.${NC}"
fi
}
# ===== Install framework
FrameInst() {
if ls "$INPUT_DIR"/*.apk > /dev/null 2>&1; then
FrameWorkDir
cd "$INPUT_DIR"
echo -e "${GREEN}Choose a framework apk.${NC}"
PROMPT="
Enter selection:"
OPTIONS=( *.apk )
QUIT=$(echo -e "${HRED}Quit${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
"$APKTOOL" if $OPT -p "$FRAMEWORKS_DIR"
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There are no valid framework apk file in the input folder.${NC}"
fi
}
# ===== Install tagged framework
FrameInstTag() {
if ls "$INPUT_DIR"/*.apk > /dev/null 2>&1; then
FrameWorkDir
cd "$INPUT_DIR"
echo -e "${GREEN}Choose a framework apk.${NC}"
PROMPT="
Enter selection:"
OPTIONS=( *.apk )
QUIT=$(echo -e "${HRED}Quit${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
echo -e "${GREEN}Adding tags(labels) to your framework files allows"
echo "you to work with multiple devices without confusion."
echo "Enter a tag with no spaces or special characters."
echo "If your device has multiple framework files, repeat this"
echo -e "step using the same tag. Example tag: ${HRED}SamsungS22${NC}"
echo ""
read -e -p "Enter a framework tag: " TAG
echo ""
if [[ ! -z "$TAG" ]]; then
if ! grep -w "$TAG" "$TAG_LIST" > /dev/null 2>&1; then
echo $TAG >> "$TAG_LIST"
fi
"$APKTOOL" if $OPT -t $TAG -p "$FRAMEWORKS_DIR"
else
echo -e "${HRED}Aborted!${NC}"
fi
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There are no valid framework apk files in the input folder.${NC}"
fi
}
# ===== Zipalign APKs
ZipFile() {
if ls "$ZIPALIGN_DIR"/*.apk > /dev/null 2>&1; then
WorkDir
cd "$ZIPALIGN_DIR"
echo -e "${GREEN}Choose one or all files for zipaligning.${NC}"
PROMPT="
Enter selection:"
if ! ls "$ZIPALIGN_DIR"/*.apk > /dev/null 2>&1; then
OPTIONS=( *.jar )
elif ! ls "$ZIPALIGN_DIR"/*.jar > /dev/null 2>&1; then
OPTIONS=( *.apk )
else
OPTIONS=( *.apk *.jar )
fi
QUIT=$(echo -e "${HRED}Quit${NC}")
ZIPALL=$(echo -e "${GREEN}Zipalign all${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$ZIPALL" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
APK=$(find -type f \( -name "*.apk" -or -name "*.jar" \))
apk1=
for apk1 in $APK ; do
"$ZIPALIGN" -c 4 $apk1
ZIPCHECK=$?
if [ $ZIPCHECK -eq 1 ]; then
echo ZipAligned $(basename $apk1)
"$ZIPALIGN" -f 4 $apk1 "$WORK_DIR"/$(basename $apk1)
if [ -e "$WORK_DIR"/$(basename $apk1) ]; then
mv -f "$WORK_DIR"/$(basename $apk1) $apk1
else
echo ZipAligning $(basename $apk1) Failed
fi
else
echo ZipAlign was already completed on $(basename $apk1)
fi
done
break
elif (( REPLY == 2 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
"$ZIPALIGN" -c 4 $OPT
ZIPCHECK=$?
if [ $ZIPCHECK -eq 1 ]; then
echo ZipAligned $(basename $OPT)
"$ZIPALIGN" -f 4 $OPT "$WORK_DIR"/$(basename $OPT)
if [ -e "$WORK_DIR"/$(basename $OPT) ]; then
mv -f "$WORK_DIR"/$(basename $OPT) $OPT
else
echo ZipAligning $(basename $OPT) Failed
fi
else
echo ZipAlign was already completed on $(basename $OPT)
fi
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There are no valid apk files in the zipalign folder.${NC}"
fi
}
# ===== manage tags
MANAGE_TAGS() {
if [[ -f "$TAG_LIST" && -s "$TAG_LIST" ]]; then
echo -e "${GREEN}Choose one or all tags to remove.${NC}"
echo ""
QUIT=$(echo -e "${HRED}Quit${NC}")
RMOVEALL=$(echo -e "${GREEN}Remove all${NC}")
PS3="
Enter selection: "
readarray -t options < "$TAG_LIST"
select opt in "${options[@]}" "$RMOVEALL" "$QUIT"; do
if (( REPLY == 1 + ${#options[@]} )); then
if [[ -f "$TAG_LIST" ]]; then
rm -f "$TAG_LIST"
rm -f "$FRAMEWORKS_DIR"/*-*.apk
fi
clear
echo -e "${GREEN}Done!${NC}"
break
elif (( REPLY == 2 + ${#options[@]} )); then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#options[@]} )); then
if grep -w "$opt" "$TAG_LIST" > /dev/null 2>&1; then
sed -i "s/\<$opt\>//g" "$TAG_LIST"
sed -i "/^$/d" "$TAG_LIST"
rm -f "$FRAMEWORKS_DIR"/*-$opt.apk
fi
clear
echo -e "${GREEN}Done!${NC}"
break
fi
done
else
echo -e "${RED}You do not have any installed tagged frameworks.${NC}"
fi
}
# ===== Change original signature of apk/s
SignK() {
if ls "$INPUT_DIR"/*.apk > /dev/null 2>&1 || ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
cd "$INPUT_DIR"
echo -e "${GREEN}Make selection to sign or change to a generic signature."
echo "This will add or change the signature of the original file"
echo -e "in the input folder to a generic signature.${NC}"
PROMPT="
Enter selection:"
if ! ls "$INPUT_DIR"/*.apk > /dev/null 2>&1; then
OPTIONS=( *.jar )
elif ! ls "$INPUT_DIR"/*.jar > /dev/null 2>&1; then
OPTIONS=( *.apk )
else
OPTIONS=( *.apk *.jar )
fi
QUIT=$(echo -e "${HRED}Quit${NC}")
PS3="$PROMPT "
echo ""
select OPT in "${OPTIONS[@]}" "$QUIT" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
clear
echo -e "${HRED}Aborted!${NC}"
break
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
clear
java -jar "$SIGN_JAR" $OPT
mv -f ${OPT%.*}.s.* "$OUTPUT_DIR"/$OPT
echo -e "${GREEN}Done!${NC}"
break
else
echo -e "${HRED}Invalid selection. Try again.${NC}"
fi
done
cd "$BASE"
else
echo -e "${HRED}There are no valid apk or jar files in the input folder.${NC}"
fi
}
# ===== check for update
VISIT_ITG() {
echo ""
echo -e "${GREEN}Visit website?${NC}"
read -e -p "(Y/n) $ " VISIT
if [[ -z $VISIT || $VISIT =~ ^([yY]|[yY][eE][sS]) ]]; then
if command -v xdg-open > /dev/null; then
xdg-open "$UPDATE_URL" > /dev/null 2>&1
elif command -v gnome-open > /dev/null; then
gnome-open "$UPDATE_URL" > /dev/null 2>&1
fi
fi
clear
}
CHECK_FOR_UPDATE() {
echo -e "${GREEN}Please wait...${NC}"
echo ""
SITE_VERSION=$(wget -q "$REPO_URL" -O - | grep -m 1 -o -P '.{0,0}APK Utility v.{0,3}')
clear
if [ "$VERSION" = "$SITE_VERSION" ]; then
echo -e "${GREEN}$VERSION"
echo "No update available. Check again later."
echo ""
echo -e "For more info visit:${NC}"
echo -e "${CYAN}$UPDATE_URL${NC}"
VISIT_ITG
else
echo -e "${GREEN}Update available!"
echo ""
echo -e "To download the latest version go to:${NC}"
echo -e "${CYAN}$UPDATE_URL${NC}"
VISIT_ITG
fi
}
# ===== create desktop shortcut
DESKTOP_SHORTCUT() {
echo "[Desktop Entry]" > "$DESKTOP_SHORTCUT"
echo "Type=Application" >> "$DESKTOP_SHORTCUT"
echo "Name=$PROJECT_NAME" >> "$DESKTOP_SHORTCUT"
echo "Comment=$DESCRIPTION" >> "$DESKTOP_SHORTCUT"
echo "Exec=\"$THIS_SCRIPT\"" >> "$DESKTOP_SHORTCUT"
echo "Icon=$ICON" >> "$DESKTOP_SHORTCUT"
echo "Categories=Development;" >> "$DESKTOP_SHORTCUT"
echo "Terminal=true" >> "$DESKTOP_SHORTCUT"
if [ -f "$DESKTOP_SHORTCUT" ]; then
echo -e "${GREEN}Desktop entry added for ${CYAN}${BOLD}$(whoami)${NC}"
echo -e "${GREEN}Check your apps menu for the shortcut.${NC}"
else
echo -e "${HRED}oops! Shortcut failed. Please try again.${NC}"
fi
}
# ===== Menu
SELECTION=
until [ "$SELECTION" = "0" ]; do
clear
echo -e "${BLUEBG}${EXPND}${WHITE}${BOLD}$NAME_TXT${NC}"
echo ""
echo " 1 - Install Framework"
echo " 2 - Install Framework + Tag"
echo " 3 - Decompile"
echo " 4 - Decompile without dex files"
echo " 5 - Decompile + Tag"
echo " 6 - Decompile + Tag without dex files"
echo " 7 - Compile"
echo " 8 - Compile + Sign with original signature"
echo " 9 - Zipalign"
echo " 10 - Sign apk or jar with generic signature"
echo " 11 - Manage Tags"
echo " 12 - Check For Update"
echo " 13 - Add Desktop Shortcut"
echo " 0 - Exit"
echo ""
echo -n " Enter selection: "
read SELECTION
echo ""
case $SELECTION in
1 ) clear ; FrameInst ; PRESS_ENTER ;;
2 ) clear ; FrameInstTag ; PRESS_ENTER ;;
3 ) clear ; Decomp ; PRESS_ENTER ;;
4 ) clear ; DecompD ; PRESS_ENTER ;;
5 ) clear ; DecompTag ; PRESS_ENTER ;;
6 ) clear ; DecompTagD ; PRESS_ENTER ;;
7 ) clear ; Compile ; PRESS_ENTER ;;
8 ) clear ; CompileSign ; PRESS_ENTER ;;
9 ) clear ; WorkDir ; ZipFile ; PRESS_ENTER ;;
10 ) clear ; SignK ; PRESS_ENTER ;;
11 ) clear ; MANAGE_TAGS ; PRESS_ENTER ;;
12 ) clear ; CHECK_FOR_UPDATE ; PRESS_ENTER ;;
13 ) clear ; DESKTOP_SHORTCUT ; PRESS_ENTER ;;
0 ) clear ; exit ;;
* ) clear ; INCORRECT_SELECTION ; PRESS_ENTER ;;
esac
done