forked from Al4ise/Azule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazule
executable file
·1016 lines (877 loc) · 34.4 KB
/
azule
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
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# ENABLE EXTGLOB
shopt -s extglob
# SAVE INITIAL DIRECTORY
rootdir="$PWD"
# UNIVERSAL FUNCTIONS
Announce () {
unset mute_verbose
if [ -n "$silent_run" ]; then mute_verbose=1; fi
for p in "$@"; do
if [ "$p" == "-v" ] && [ -z "$verbose" ]; then mute_verbose=1; fi
done
if [ -z "$mute_verbose" ]; then
echo "[*] $1"
fi
for p in "$@"; do
if [[ $p =~ ^[0-9]+$ ]]; then
exit_code="$p"
cleanup
fi
done
}
Verbose () {
tv="$?"
unset mute_verbose
if [ -n "$silent_run" ]; then mute_verbose=1; fi
for p in "$@"; do
if [ "$p" == "-v" ] && [ -z "$verbose" ]; then mute_verbose=1; fi
if [ "$p" == "-x" ]; then tv="$status" && unset status; fi
done
if [ -z "$tv" ]; then tv=0; fi
if [ "$tv" != 0 ]; then
echo "[*] $2"
for p in "$@"; do
if [[ $p =~ ^[0-9]+$ ]]; then
exit_code="$p"
cleanup
fi
done
elif [ -z "$mute_verbose" ]; then
echo "[*] $1"
fi
}
lib_basename () {
if [[ "$1" == *.framework/* ]]; then
echo "$(basename "$(dirname "$1")")/$(basename "$1")"
else
basename "$1"
fi
}
idpath () {
if [[ "$1" =~ ${rpath#"$dir"/"$tweakid"/} ]]; then
echo "@rpath/$(lib_basename "$1")"
else
echo "@executable_path/${1#Payload/"$appname"/}"
fi
}
checkvar () {
if [[ "$1" ]]; then
return 0
else
return 1
fi
}
split_array () {
if [ "$1" = "-d" ]; then
delim="$2"
shift 2
else
delim=" "
fi
newarr="$1"
shift
IFS="$delim" read -ra "${newarr?}" <<< "$*"
export "${newarr?}"
}
cleanup () {
rm -rf "$dir"
cd "$rootdir" || exit
if [ -z "$exit_code" ]; then exit_code=0; fi
if [ -n "$ignore_errors" ]; then
exit_code=0
else
exit "$exit_code"
fi
}
decompress () {
if [ -z "$full_unzipped" ]; then
if [ -z "$1" ] || [ "$2" != "-n" ]; then
unzip -qq -n "$ipadir" "$1" -d "$dir/"
else
unzip -qq -o "$ipadir" "$1" -d "$dir/"
fi
fi
}
network_check(){
if [ -z "$net" ]; then
if curl -I --connect-timeout 5 google.com &>/dev/null; then
net=0
else
net=1
fi
export net
fi
return $net
}
verlt() {
if [ "$1" = "$2" ]; then
return 1
else
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
fi
}
help () {
echo "Usage: azule [essential arguements] [modifiers]"
echo
echo "Examples:"
if [ "$os" == "iOS" ] || [ -n "$unsafe_help" ]; then
echo " azule -n Foo -i com.example.foo -x appleid@example.com password123 -o ~/Foo/ -f com.alaise.example ~/Foo.bundle -a -m"
fi
echo " azule -n Foo -i ~/Foo.ipa -o ~/Foo/ -f com.bar.foo"
echo " azule -n Foo -i ~/Foo.ipa -o ~/Foo/ -f ~/Foo.framework com.bar.foo"
echo
echo "Essential Arguements:"
echo " -i [Path/BundleID] Specify the the IPA to patch"
echo " -o [Path] Specify an output directory"
echo
echo "Modifiers:"
echo " -f [Paths/Bundle IDs] Specify the files or tweak Bundle IDs to import"
echo " -c [Version] Set custom version for output ipa"
echo " -b [BundleId] Set custom BundleID for output ipa"
echo " -p [Name] Set custom Display Name for output ipa"
echo " -u Remove UISupportedDevices from app"
echo " -S Fakesigns IPA for use with AppSync"
echo " -e Removes App Extensions"
if [ "$os" == "iOS" ] || [ -n "$unsafe_help" ]; then
echo
echo "APT Module:"
echo " -A [Source URL/Repo List] Specify custom sources to get packages from"
echo " -L Ignore packages from Canister"
echo " -k Ignore packages from APT Sources"
echo " -d Don't install package dependencies"
echo " -D Disable refreshing Procursus/Elcubratus repos"
fi
if [ "$os" == "iOS" ] || [ -n "$unsafe_help" ]; then
echo
echo "Decrypt Module:"
echo " -x [Apple ID] [Password] Fetch and decrypt IPA with specified Apple ID"
echo " -C [Country Code] Specify country code for ipatool"
echo " -g Force Update Apps"
echo " -l Don't Update Outdated Apps"
fi
echo
echo "Others:"
echo " -n [Name] Specify a name for the Output IPA"
echo " -y Don't remove watch app"
echo " -m Don't inject a hooking library"
if [[ "$os" == @(Linux_x86|Linux_ARM) ]]; then
echo " -R Redownload the latest substrate, substitute, and toolchain"
else
echo " -R Redownload the latest substrate and substitute"
fi
echo " -v Enable Verbose Mode"
echo " -s Silence Everything But Important Errors"
echo " -w Insert dylibs as weak"
echo " -r Skip Encryption Check"
if [ -n "$unsafe_help" ]; then
echo " -q Ignore errors [Discouraged]"
echo " -j Allow for Azule to be ran as root [Discouraged]"
fi
echo " -z Use Legacy Compression (outputs smaller .ipa files, but runs slower)"
echo " -Z Don't compress output .ipa; Output .app"
echo " -h Print the help menu"
echo " -H Print the complete help menu (incl. unsupported options)"
if [ "$os" != "iOS" ]; then
echo
echo "MacOS/Linux Only:"
echo " -U Don't Update Azule on run"
echo " -F Forcefully update Azule"
fi
echo
cleanup
}
# SET PLATFORM
case "$(uname -s)" in
"Linux")
if [[ "$(lscpu | cut -d ":" -f2 | head -1 | xargs)" == "x86_64" ]]; then
os="Linux_x86"
else
os="Linux_ARM"
fi
;;
"Darwin")
if [[ "$(sw_vers -productName)" =~ ^(Mac OS X|macOS|macOS Server)$ ]]; then
os="MacOS"
else
os="iOS"
fi
;;
esac
# PLIST MANAGEMENT
case "$os" in
iOS)
RemovePlistKey () {
plutil -remove -key "$1" "$2" &>/dev/null
}
ReplacePlistValue () {
plutil -value "$1" -key "$2" "$3" &>/dev/null
}
ExtractPlistKey(){
plutil -key "$1" "$2" >> tmp 2>/dev/null || status=1
plutil -convert xml1 tmp &>/dev/null || status=1
sed -n "s/.*<key>\(.*\)<\/key>.*/\1/p" tmp || status=1
rm tmp &>/dev/null || status=1
}
ExtractPlistValue () {
plutil -key "$1" "$2" 2>/dev/null
}
;;
MacOS)
RemovePlistKey () {
plutil -remove "$1" "$2" &>/dev/null
}
ReplacePlistValue () {
plutil -replace "$2" -string "$1" "$3" &>/dev/null
}
ExtractPlistKey(){
value="$(plutil -extract "$1" xml1 -o - "$2" | sed -n "s/.*<key>\(.*\)<\/key>.*/\1/p" 2>/dev/null)"
if [ -n "$value" ]; then
echo "$value"
else
return 1
fi
}
ExtractPlistValue () {
value="$(plutil -extract "$1" xml1 -o - "$2" | sed -n "s/.*<string>\(.*\)<\/string>.*/\1/p" 2>/dev/null)"
if [ -n "$value" ]; then
echo "$value"
else
return 1
fi
}
convert_to_plist () {
plutil -convert binary1 "$1"
}
;;
Linux_ARM|Linux_x86)
RemovePlistKey () {
plistutil -i "$2" -o tmp -f xml
xmlstarlet ed -d "//key[text()='$1']" tmp > "$2"
plistutil -i "$2" -o "$2" -f binary
}
ReplacePlistValue () {
plistutil -i "$3" -o tmp -f xml
xmlstarlet ed -u "//key[text()='$2']/following-sibling::string[1]/text()" -v "$1" tmp > "$3"
plistutil -i "$3" -o "$3" -f binary
}
ExtractPlistKey(){
plistutil -i "$2" -o tmp -f xml
value="$(xmllint --xpath "string(//plist/dict/dict/key)" tmp 2>/dev/null)"
rm tmp
if [ -n "$value" ]; then
echo "$value"
else
return 1
fi
}
ExtractPlistValue () {
plistutil -i "$2" -o tmp -f xml
value="$(xmllint --xpath "//key[text()='$1']/following-sibling::string[1]/text()" tmp 2>/dev/null)"
rm tmp
if [ -n "$value" ]; then
echo "$value"
else
return 1
fi
}
convert_to_plist() {
local input_file="$1"
local xml_output="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
xml_output+="<plist version=\"1.0\">\n"
xml_output+="<dict>\n"
while IFS="=" read -r key value; do
if [[ -n "$key" && -n "$value" ]]; then
key="$(echo "$key" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
value="$(echo "$value" | sed 's/^ *"\{0,1\}//;s/"\{0,1\} *$//')"
xml_output+=" <key>$key</key>\n"
xml_output+=" <string>$value</string>\n"
fi
done < "$input_file"
xml_output+="</dict>\n"
xml_output+="</plist>\n"
local tmp_plist="$(mktemp)"
printf "%b" "$xml_output" > "$tmp_plist"
plistutil -i "$tmp_plist" -o "$input_file" -f binary
rm "$tmp_plist"
}
;;
esac
# DEB EXTRACTION
if [[ "$os" == @(Linux_ARM|Linux_x86|MacOS) ]]; then
ExtractDEB () {
origin_dir="$PWD"
mkdir -p "$dir/debtemp/$1"
cd "$dir/debtemp/$1" || exit
Announce "Extracting $(basename "$1")..." -v
ar -x "$1" || status=1
tar -C "$dir/Tweak" -xf data.tar.* || status=1
Verbose "Extracted $(basename "$1")" "Couldn't extract $(basename "$1")" 5 -x
cd "$origin_dir" || exit
rm -rf "$dir/debtemp/$1"
return $status
}
else
ExtractDEB () {
Announce "Extracting $(basename "$1")..."
dpkg -x "$1" "$dir/Tweak"
Verbose "Extracted $(basename "$1")" "Couldn't extract $(basename "$1")" 3
}
fi
# PLATFORM-SPECIFIC VARIABLES
case "$os" in
MacOS)
azule="$(dirname "$(realpath "$0")")"
PATH="$azule/bin/darwin:$PATH"
;;
iOS)
PATH="/usr/lib/Azule/bin:$PATH"
azule="/usr/lib/Azule"
;;
Linux_x86|Linux_ARM)
azule="$(dirname "$(realpath "$0")")"
PATH="$azule/bin/linux:$PATH"
PATH="$azule/toolchain/bin:$PATH"
;;
esac
# CLEAN ON EXIT
trap "cleanup" SIGINT
trap "cleanup" EXIT
# CLI ARGUEMENTS
while getopts n:i:o:c:b:x:f:p:C:huSewsrDHqAdjRyUzgmFZLklv args; do
# STUFF WITH PARAMETERS
if [[ "$args" == @(x|n|b|p|i|o|c|f|A|z|C) ]]; then
tmp=( "$OPTARG" )
until [[ "$(eval "echo \${$OPTIND}")" =~ ^-.* ]] || [ -z "$(eval "echo \${$OPTIND}")" ]; do
tmp+=( "$(eval "echo \${$OPTIND}")" )
OPTIND=$((OPTIND + 1))
done
fi
# PLATFORM SPECIFIC
if [ "$os" == "iOS" ]; then
if [[ "$args" == @(U|F) ]]; then
Announce "-$args is not supported on your platform" 6
fi
elif [[ "$args" == @(x|C|y|g|k|l) ]]; then
Announce "-$args is not supported on your platform" 6
fi
case "$args" in
# STUFF WITH PARAMETERS
A) split_array repos "${tmp[*]}" ;;
b) bundle="${tmp[*]}" && run=1 ;;
c) custom_version="${tmp[*]}" && run=1 ;;
f) split_array files "${tmp[*]}" && run=1 ;;
i) ipadir="$(realpath -q "${tmp[*]}")" && [[ -z "$ipadir" && "$os" == "iOS" ]] && ipadir="${tmp[*]}" && run=1 ;;
n) name="${tmp[*]}" ;;
o) outdir="$(realpath -q "${tmp[*]}")" && [[ -z "$outdir" && "${tmp[*]}" != /* ]] && outdir="$(pwd)/${tmp[*]}" ;;
p) displayname="${tmp[*]}" && run=1 ;;
x) IPATOOL_EMAIL="${tmp[0]}" && unset "tmp[0]" && IPATOOL_PASSWORD="${tmp[*]}" ;;
C) country_code="${tmp[*]}" ;;
# SWITCHES
d) no_recurse=1 ;;
e) remove_extensions=1 && run=1 ;;
j) allow_root_run=1 ;;
m) no_inject_hl=1 ;;
q) ignore_errors=1 ;;
r) ignore_encrypted=1 ;;
s) silent_run=1 ;;
S) fakesign=1 && run=1 ;;
u) remove_uisd=1 && run=1 ;;
v) verbose=1 ;;
y) no_remove_watchapp=1 ;;
w) weak=1 ;;
L) ignore_canister=1 ;;
D) disable_dists=1 ;;
z) legacy_compression=1 ;;
Z) output_unzipped=1 && legacy_compression=1 ;;
# MACOS/LINUX ONLY SWITCHES
U) no_update_azule=1 ;;
F) force_update_azule=1 ;;
R) redownload_resources=1 ;;
# iOS ONLY SWITCHES // DECRYPT MODULE
g) outdated=1 ;;
k) no_apt_update=1 ;;
l) ignore_outdated=1 ;;
h) help ;;
H) unsafe_help=1 && help;;
*) Announce "Invalid option: $*. Run 'azule -h' for help" 6 ;;
esac
done
# ANNOUNCE PLATFORM
Announce "Platform is $os" -v
# USER CHECK
if [ "$(id -u)" == "0" ] && [ -z "$allow_root_run" ]; then
Announce "Azule should not be run as root. Use '-j' to overwrite" 36
fi
if [ -n "$no_update_azule" ]; then
unset force_update_azule
fi
# INTEGRITY CHECKS, AND UPDATE CHECKS
if [ ! -e "$azule/lib" ] || [ ! "$(ls -A "$azule/toolchain" &>/dev/null)" ] || [ -z "$no_update_azule" ]; then
if network_check; then
cd "$azule" || exit
if [[ "$os" == @(MacOS|Linux_x86|Linux_ARM) ]]; then
if [ -n "$force_update_azule" ]; then
git reset --hard HEAD >> /dev/null
fi
if [ -z "$no_update_azule" ] || [ -n "$force_update_azule" ]; then
Announce "Checking for Updates..." -v
git fetch -q
if [ "$(git rev-list HEAD...origin/main --count)" != "0" ]; then
Announce "Updating Azule..." -v
git pull -q
Verbose "Updated Azule" "Couldn't Update Azule" 29
exec "$(realpath "$0")" -U "$@"
else
Announce "Azule is Up to Date" -v
fi
fi
fi
if [ -n "$redownload_resources" ]; then
rm -rf lib toolchain
fi
if [ "$os" == "MacOS" ]; then
if ! xcode-select -p 1>/dev/null; then
xcode-select --install
fi
elif [[ "$os" == @(Linux_x86|Linux_ARM) ]]; then
source "$azule/modules/dependency_check"
if [ "$os" == "Linux_x86" ]; then
toolchain_url=https://github.com/kabiroberai/darwin-tools-linux/releases/download/v2.2.1/darwin-tools-ubuntu18.04.tar.gz
else
toolchain_url=https://github.com/kabiroberai/darwin-tools-linux/releases/download/v2.2.1/darwin-tools-ubuntu20.04-aarch64.tar.gz
fi
mkdir -p "$azule/toolchain"
if [ ! "$(ls -A "$azule/toolchain")" ]; then
Announce "Fetching toolchain..."
TMP=$(mktemp -d)
cd "$TMP" || exit
curl -LOk "$toolchain_url"
Announce "Fetched Toolchain"
Announce "Setting Up Toolchain..."
tar -xf *.tar.gz
mv "$TMP"/linux/iphone/* "$azule"/toolchain
cd "$azule" || exit
rm -rf "$TMP"
Announce "Set Up Toolchain"
fi
fi
(if [ ! -d "$azule/lib/CydiaSubstrate.framework" ]; then
mkdir -p "$azule/lib"
Announce "Downloading CydiaSubstrate.framework..."
TMP=$(mktemp -d)
cd "$TMP" || exit
curl -Lk https://apt.bingner.com/debs/1443.00/mobilesubstrate_0.9.7113_iphoneos-arm.deb -o substrate.deb
ar -x "substrate.deb"
tar --lzma --strip-components 3 -xf data.tar.lzma "./Library/Frameworks/CydiaSubstrate.framework" "./usr/lib" "./usr/include"
rm CydiaSubstrate.framework/CydiaSubstrate CydiaSubstrate.framework/Headers/CydiaSubstrate.h
mv "$TMP"/libsubstrate.dylib CydiaSubstrate.framework/CydiaSubstrate
mv substrate.h CydiaSubstrate.framework/Headers/CydiaSubstrate.h
mv CydiaSubstrate.framework "$azule"/lib/CydiaSubstrate.framework
convert_to_plist "$azule"/lib/CydiaSubstrate.framework/Info.plist
cd "$azule" || exit
rm -rf "$TMP"
Announce "Downloaded CydiaSubstrate.framework"
fi) &
(if [ ! -e "$azule/lib/libsubstitute.dylib" ]; then
TMP="$(mktemp -d)"
cd "$TMP" || exit
cd "$TMP" || exit
cd "$TMP" || exit
cd "$TMP" || exit
cd "$TMP" || exit
cd "$TMP" || exit
cd "$TMP" || exit
Announce "Downloading Substitute..."
curl -k https://apt.bingner.com/debs/1443.00/com.ex.substitute_2.2.3_iphoneos-arm.deb -o substitute.deb
ar -x "substitute.deb"
tar --lzma --strip-components 2 -xf data.tar.lzma "usr/lib"
mv libsubstitute.dylib "$azule/lib/libsubstitute.dylib"
Announce "Downloaded Substitute"
fi) &
wait
cd "$rootdir" || exit
fi
fi
# VARIABLE CHECK
if [ -z "$outdir" ]; then
Announce "No Output Directory Specified. Run 'azule -h' for help" 27
elif [ -z "$ipadir" ]; then
Announce "No IPA Specified. Run 'azule -h' for help" 27
elif [ -z "$run" ]; then
Announce "No Modifiers Specified. Run 'azule -h' for help" 27
fi
# CREATING .TMP DIRECTORIES
dir="$(mktemp -d)"
tweakid="$RANDOM"
mkdir -p "$dir/Tweak"
Verbose "Temporary Directory has been created" "Couldn't create Temporary Directory" 10 -v
cd "$dir" || exit
if [ -e "$ipadir" ]; then
if [ "${ipadir: -4}" == ".app" ]; then
# COPYING APP CONTENTS
mkdir -p "$dir/Payload"
cp -R "$ipadir" "$dir/Payload" &>/dev/null
Verbose "Copied App to Work Directory" "Couldn't Copy App to Work Directory" 11
full_unzipped=1
elif [ "${ipadir: -4}" == ".ipa" ] && [ -n "$legacy_compression" ]; then
# EXTRACTING IPA
Announce "Extracting IPA..."
unzip -q "$ipadir" -d "$dir"
Verbose "IPA extracted" "Couldn't extract IPA" 11
full_unzipped=1
fi
# REMOVING EXTENSIONS
if [ -n "$full_unzipped" ] && [ -n "$remove_extensions" ]; then
rm -rf $dir/Payload/*.app/PlugIns
Verbose "Removed Extensions" "Couldn't Remove Extensions" -x
fi
else
if [ "$os" == "iOS" ]; then
source "$azule"/modules/azule_decrypt
fi
if [ ! -e Payload ]; then
Announce "Invalid App" 8
fi
fi
# SETTING OUTPUT DIRECTORY AND NAME
if [ -n "$run" ] || [ -n "$foul_plist" ]; then
if [[ "$outdir" != *".ipa" ]]; then
if [ -z "$name" ]; then
name="$(basename "$ipadir" .ipa)"
custom_name=1
else
outdir="$outdir/$name.ipa"
fi
fi
fi
# SETTING APP VARIABLES
if [ -n "$run" ]; then
decompress Payload/*.app/Info.plist
appname="$(basename Payload/*.app)"
exec_name="$(ExtractPlistValue CFBundleExecutable Payload/"$appname"/Info.plist)"
executable="Payload/$appname/$exec_name"
decompress "$executable"
checkvar "$exec_name"
Verbose "App executable is ${executable//*.app/@executable_path}" "Couldn't set app executable" 12 -v
ldid -e "$executable" > "$dir/exec_entitlements" || rm -f "$dir/exec_entitlements"
ldid -r "$executable" || status=1
Verbose "Stripped codesign from app executable" "Couldn't strip codesign from app executable" 33 -v
rpath="$(otool -l "$executable" | grep RPATH -A2 | sed 's/.*path \(.*\)/\1/' | grep -o '^\S*' | grep "^@executable_path*" | tail -1 | sed "s|@executable_path|Payload/$appname|g")"
if ! checkvar "$rpath"; then
rpath="Payload/$appname/Frameworks"
install_name_tool -add_rpath "${rpath//*.app/@executable_path}" "$executable" 2>/dev/null
Verbose "New App rpath is ${rpath//*.app/@executable_path}" "Couldn't set new app rpath" 13 -v
else
checkvar "$rpath"
Verbose "App rpath is ${rpath//*.app/@executable_path}" "Couldn't set app rpath" 13 -v
fi
mkdir -p "$rpath"
# ENCRYPTION CHECK
if [ -z "$ignore_encrypted" ] && otool -l "$executable" | grep -q 'cryptid 1'; then Announce "Fatal Error: $executable is encrypted" 14; fi
fi
# PROCESSING FILES
if [ -n "${files[*]}" ]; then
max="${#files[@]}"
for i in "${!files[@]}"; do
x="$i"
unset string
unset "indexes[@]"
while [[ "$x" -le "$max" ]]; do
indexes+=( "$x" )
if [ -n "$string" ]; then
string+=" ${files[x]}"
else
string+="${files[x]}"
fi
if [ -e "$string" ]; then
e_string="$(cd "$rootdir" && realpath "$string")"
else
e_string="$string"
fi
if [ -e "$e_string" ] && [[ -z "${files[x+1]}" || ! -e "$e_string ${files[x+1]}" ]]; then
Announce "$(basename "$string" | xargs) will be imported" -v
case "$e_string" in
*.deb)
ExtractDEB "$e_string"
debs+=( "$e_string" )
;;
*.dylib|*.framework)
cp -a "$e_string" "$dir/Tweak"
Verbose "Copied $(basename "$e_string") to work directory" "Couldn't Copy $(basename "$i") to work directory" 15 -v
;;
*)
merge=1
mkdir -p "$dir/Custom"
cp -a "$e_string" "$dir/Custom"
Verbose "Copied $(basename "$e_string") to work directory" "Couldn't Copy $(basename "$i") to work directory" 16
;;
esac
if [ -n "$custom_name" ]; then
name+="+$(basename "$e_string")"
fi
unset string
for g in "${indexes[@]}"; do
unset "files[$g]"
done
unset "indexes[@]"
fi
x=$((x + 1))
done
done
if [ "${#files[@]}" -ne 0 ] && [ -e "$azule/modules/azule_apt" ]; then
source "$azule/modules/azule_apt"
fi
# DYLIB SELECTION
while read -r i; do
if [[ "$i" =~ $dir/Custom ]]; then
copy_path="Payload/$appname/${i#"$dir"/"$tweakid"/Custom/}"
mkdir -p "$(dirname "$copy_path")"
else
copy_path="${rpath#"$dir"/"$tweakid"/Tweak/}/$(basename "$i")"
fi
if ! [ -e "${i%.dylib}.plist" ]; then
inject+=( "$copy_path" )
lib_dylibs+=( "$copy_path" )
cp -a "$i" "$copy_path"
Verbose "Copied $(basename "$i") to app directory" "$(basename "$i") couldn't be copied to app directory" 16 -v
else
identifier="$(ExtractPlistValue Filter "${i%.*}".plist)"
if ! [[ "$identifier" =~ ^[0-9a-zA-Z]+$ ]]; then
inject+=( "$copy_path" )
lib_dylibs+=( "$copy_path" )
cp -a "$i" "$copy_path"
Verbose "Copied $(basename "$i") to app directory" "$(basename "$i") couldn't be copied to app directory" 16 -v
else
split_array idtypes "$(ExtractPlistKey Filter "${i%.*}".plist)"
for idtype in "${idtypes[@]}"; do
case "$idtype" in
Bundles)
if [[ "$identifier" =~ $(ExtractPlistValue CFBundleIdentifier Payload/"$appname"/Info.plist) ]]; then
inject+=( "$copy_path" )
cp -a "$i" "$copy_path"
Verbose "Copied $(basename "$i") to app directory" "$(basename "$i") couldn't be copied to app directory" 16 -v
break
fi
;;
Executables)
if [[ "$identifier" =~ $(basename "$executable") ]]; then
inject+=( "$copy_path" )
cp -a "$i" "$copy_path"
Verbose "Copied $(basename "$i") to app directory" "$(basename "$i") couldn't be copied to app directory" 16 -v
break
fi
;;
esac
done
fi
fi
done < <(find "$dir/Tweak" "$dir/Custom" ! -type l -iname '*.dylib' 2>/dev/null)
# MOVING FRAMEWORKS TO APP DIRECTORY
while read -r i; do
if [[ "$i" == *.bundle/* ]]; then
remove="$(echo "$i" | sed 's/.bundle.*//')"
new_rpath="$(dirname "@executable_path/${i//$remove/$(basename "$remove")}")"
install_name_tool -add_rpath "$new_rpath" "$executable" 2>/dev/null
if [[ "$new_rpath" != "${rpaths[*]}" ]]; then
rpaths+=( "$new_rpath" )
Verbose "Added $new_rpath as new rpath" "Couldn't add $new_rpath as new rpath" -v
fi
else
if [[ "$i" =~ $dir/Custom ]]; then
copy_path="Payload/$appname/${i#"$dir"/"$tweakid"/Custom/}"
else
copy_path="${rpath#"$dir"/"$tweakid"/Tweak/}/$(basename "$i")"
fi
mkdir -p "$(dirname "$copy_path")"
if [ ! -e "$copy_path" ]; then
if [ -e "$i/Info.plist" ]; then
cp -a "$i" "$copy_path"
Verbose "Copied $(basename "$i") to app directory" "$(basename "$i") couldn't be copied to app directory" 16 -v
inject+=( "$copy_path/$(ExtractPlistValue CFBundleExecutable "$i/Info.plist")" )
lib_dylibs+=( "$copy_path/$(ExtractPlistValue CFBundleExecutable "$i/Info.plist")" )
fi
fi
fi
done < <(find "$dir/Tweak" "$dir/Custom" ! -type l -iname '*.framework' ! -path '*PreferenceBundles/*' ! -path '*.framework/*' 2>/dev/null)
# MOVING BUNDLES
while read -r i; do
rm -rf "Payload/$appname/$(basename "$i")"
mv "$i" "Payload/$appname/"
Verbose "Copied $(basename "$i") to app directory" "$(basename "$i") couldn't be copied to app directory" 16 -v
done < <(find "$dir/Tweak/Library/Application Support" ! -type l -iname '*.bundle' ! -path '*.appex/*' ! -path '*.bundle/*' ! -path '*.framework/*' 2>/dev/null)
# MERGING APPLICATION SUPPORT
while read -r i; do
rm -rf "Payload/$appname/$(basename "$i")"
mv "$i" "Payload/$appname/"
Verbose "Copied $(basename "$i") to app directory" "$(basename "$i") couldn't be copied to app directory" 16 -v
done < <(find "$dir/Tweak/Library/Application Support" -mindepth 2 -maxdepth 2 ! -type l ! -path '*.appex/*' ! -path '*.bundle/*' ! -path '*.framework/*' 2>/dev/null)
# MOVING EXTENSIONS
while read -r i; do
mkdir -p "Payload/$appname/PlugIns"
rm -rf "Payload/$appname/PlugIns/$(basename "$i")"
mv "$i" "Payload/$appname/PlugIns/"
Verbose "Copied $(basename "$i") to app directory" "$(basename "$i") couldn't be copied to app directory" 16 -v
done < <(find "$dir/Tweak" "$dir/Custom" ! -type l -iname '*.appex' ! -path '*.appex/*' ! -path '*.bundle/*' ! -path '*.framework/*' 2>/dev/null)
# FIXING LINKS
for i in "${inject[@]}"; do
ldid -r -M "$i" &>/dev/null
Verbose "Codesign stripped from $(lib_basename "$i")" "Couldn't strip codesign from $(lib_basename "$i")" 19 -v
for l in $(otool -L "$i" | cut -d ' ' -f1); do
for x in "${inject[@]}"; do
if [[ "$l" =~ $(lib_basename "$x") ]]; then
if [[ "$l" =~ $(lib_basename "$i") ]]; then
install_name_tool -id "$(idpath "$i")" "$i" &>/dev/null
tid=$(( tid + $? ))
break
else
install_name_tool -change "$l" "$(idpath "$x")" "$i" &>/dev/null
tlnk=$(( tlnk + $? ))
if ! [[ "${linked[*]}" =~ $x ]]; then linked+=( "$x" ); fi
break
fi
fi
done
done
done
# VERBOSE
status="$tid"
if [ -n "$tid" ]; then
Verbose "ID Successful" "$tid file(s) failed to ID" 20 -x
fi
status="$tlnk"
if [ -n "$tlnk" ]; then
Verbose "Re-Link Successful" "$tlnk Re-Links failed" 21 -x
fi
# INJECT HOOKING LIBRARY
if [ -n "${inject[*]}" ] && [ -z "$no_inject_hl" ]; then
for hookinglibrary in "CydiaSubstrate.framework/CydiaSubstrate" "libsubstitute.dylib"; do
hl="$hookinglibrary"
if [[ "$hl" =~ .framework ]]; then
hl_files+=( "$(dirname "$hl")" )
else
hl_files+=( "$hl" )
fi
for hl_file in "${hl_files[@]}"; do
decompress "$rpath/$(lib_basename "$hl_file")" &>/dev/null
done
for i in "${inject[@]}"; do
for l in $(otool -L "$i" | cut -d ' ' -f1); do
if [[ "$l" =~ $hookinglibrary ]]; then
for hl_file in "${hl_files[@]}"; do
if [ ! -e "$rpath/$(lib_basename "$hl_file")" ]; then
cp -a "$azule/lib/$hl_file" "$rpath" &>/dev/null
Verbose "Copied $(lib_basename "$hl_file") to app directory" "Couldn't copy $(lib_basename "$hl_file") to app directory" 22
fi
done
install_name_tool -change "$l" @rpath/"$hl" "$i" &>/dev/null
status=$(( status + $? ))
break
fi
done
done
if [ -n "$status" ]; then
Verbose "Linked $hl" "Failed injecting $hl in $status file(s)" 23 -x
fi
done
fi
# INJECTING LIBRARIES
for i in "${inject[@]}"; do
id_path="$(idpath "$i")"
if ! { [[ "${linked[*]}" =~ $i && "${lib_dylibs[*]}" =~ $i ]] || [[ "$(otool -L "$executable" | cut -d ' ' -f1 | xargs)" =~ $id_path ]]; }; then
if [ -n "$weak" ]; then
insert_dylib --inplace --weak --no-strip-codesig "$id_path" "$executable" &>/dev/null
if ! [[ "$(otool -L "$executable" | cut -d ' ' -f1 | xargs)" =~ $id_path ]]; then status="1"; fi
Verbose "Injected $(lib_basename "$i") as weak" "Couldn't inject $(lib_basename "$i")" 24 -x
else
insert_dylib --inplace --no-strip-codesig "$id_path" "$executable" &>/dev/null
if ! [[ "$(otool -L "$executable")" =~ $id_path ]]; then status="1"; fi
Verbose "Injected $(lib_basename "$i")" "Couldn't inject $(lib_basename "$i")" 24 -x
fi
lib_dylibs+=( "$i" )
fi
done
# MERGING FOLDERS
if [ -n "$merge" ]; then
cp -R "$dir"/Custom/* "Payload/$appname"
fi
fi
source "$azule/modules/plist_editing"
# FAKESIGNING
if [ -n "$fakesign" ]; then
decompress "*.framework/" "*.dylib"
Announce "Fakesigning IPA..."
while read -r i; do
ldid -S -M "$i" &>/dev/null
status="$?"
lstat=$(( lstat + status ))
Verbose "Fakesigned $(basename "$i")" "Couldn't Fakesign $(basename "$i")" -v -x
done < <(find Payload -name "*.framework" -o -name "*.dylib" && echo "$executable")
status="$lstat"
Verbose "Finished Fakesigning" "Couldn't Fakesign App" -x
fi
# RESTORING ENTITLEMENTS
if [ -n "$run" ] && [ -f "$dir/exec_entitlements" ]; then
ldid -S"$dir/exec_entitlements" "$executable"
Verbose "Restored App Entitlements" "Couldn't Restore App Entitlements" -v
fi
# GENERATING IPA
if [ -n "$run" ] || [ -n "$foul_plist" ]; then
if [ -n "$custom_name" ]; then
outdir="$outdir/$name.ipa"
fi
# SHORTEN OUTPUT NAME IF NEEDED
if [[ ${#outdir} -gt 264 ]]; then
outdir="${outdir::${#outdir}-4}"
characters_to_remove=$(( ${#outdir} - 264 ))
outdir="${outdir::${#outdir}-$characters_to_remove}.ipa"
Announce "Shortened File Name"
fi
# OUTPUT .APP
if [ -n "$output_unzipped" ]; then
outdir="${outdir%???}app"
fi
# CREATING OUTPUT DIRECTORY
mkdir -p "$(dirname "$outdir")"
if [[ -e "$outdir" && "$outdir" == @(*.ipa|*.ipa) ]]; then rm -rf "$outdir"; fi
if [ -n "$full_unzipped" ]; then
if [ -n "$output_unzipped" ]; then
mv "Payload/$appname" "$outdir"
else
zip -r -qq "$outdir" Payload
status="$?"
fi
else
Announce "Generating IPA..."
cp "$ipadir" "$outdir"
# REMOVING EXTENSIONS
if [ -n "$remove_extensions" ]; then
zip -qq -d "$outdir" "Payload/*.app/PlugIns/*" &>/dev/null
stat="$?"
if [ "$stat" != "12" ]; then status="$stat"; fi
Verbose "Removed Extensions" "Couldn't Remove Extensions" -x
fi
while read -r k; do
ziparr+=( "$k" )
done < <(find Payload)
zip -qq -u "$outdir" "${ziparr[@]}"
status="$?"
fi
# REMOVING WATCH APP
if [ -z "$no_remove_watchapp" ]; then
decompress "*Info.plist*" -n