-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
restore.sh
executable file
·9545 lines (9080 loc) · 388 KB
/
restore.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
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
#!/usr/bin/env bash
ipsw_openssh=1 # OpenSSH will be added to jailbreak/custom IPSW if set to 1.
device_rd_build="" # You can change the version of SSH Ramdisk and Pwned iBSS/iBEC here. (default is 10B329 for most devices)
jelbrek="../resources/jailbreak"
ssh_port=6414
bash_test=$(echo -n 0)
(( bash_test += 1 ))
if [ "$bash_test" != "1" ] || [ -z $BASH_VERSION ]; then
echo "[Error] Detected that script is not running with bash on runtime. Please run the script properly using bash."
exit 1
fi
bash_ver=$(/usr/bin/env bash -c 'echo ${BASH_VERSINFO[0]}')
if (( bash_ver > 3 )); then
shopt -s compat32
fi
print() {
echo "${color_B}${1}${color_N}"
}
input() {
echo "${color_Y}[Input] ${1}${color_N}"
}
log() {
echo "${color_G}[Log] ${1}${color_N}"
}
warn() {
echo "${color_Y}[WARNING] ${1}${color_N}"
}
error() {
echo -e "${color_R}[Error] ${1}\n${color_Y}${*:2}${color_N}"
echo
print "* Save the terminal output now if needed. (macOS: Cmd+S, Linux: Ctrl+Shift+S)"
if [[ -n $version_current && -n $git_hash ]]; then
print "* Legacy iOS Kit $version_current ($git_hash)"
else
print "* Legacy iOS Kit"
fi
if [[ -n $platform ]]; then
print "* Platform: $platform ($platform_ver - $platform_arch) $live_cdusb_str"
fi
exit 1
}
pause() {
input "Press Enter/Return to continue (or press Ctrl+C to cancel)"
read -s
}
clean() {
kill $httpserver_pid $iproxy_pid $anisette_pid 2>/dev/null
popd &>/dev/null
rm -rf "$(dirname "$0")/tmp$$/"* "$(dirname "$0")/iP"*/ "$(dirname "$0")/tmp$$/" 2>/dev/null
if [[ $platform == "macos" && $(ls "$(dirname "$0")" | grep -v tmp$$ | grep -c tmp) == 0 ]]; then
killall -CONT AMPDevicesAgent AMPDeviceDiscoveryAgent MobileDeviceUpdater
fi
}
clean_sudo() {
clean
sudo rm -rf /tmp/futurerestore /tmp/*.json "$(dirname "$0")/tmp$$/"* "$(dirname "$0")/iP"*/ "$(dirname "$0")/tmp$$/"
sudo kill $sudoloop_pid
}
clean_usbmuxd() {
clean_sudo
if [[ $(ls "$(dirname "$0")" | grep -v tmp$$ | grep -c tmp) != 0 ]]; then
return
fi
sudo killall usbmuxd usbmuxd2 2>/dev/null
if [[ $(command -v systemctl) ]]; then
sleep 1
sudo systemctl restart usbmuxd
fi
}
display_help() {
echo ' *** Legacy iOS Kit ***
- Script by LukeZGD -
Usage: ./restore.sh [Options]
List of options:
--debug For script debugging (set -x and debug mode)
--device=<type> Specify device type
--dfuhelper Launch to DFU Mode Helper only
--disable-sudoloop Disable running tools as root for Linux
--ecid=<ecid> Specify device ECID
--entry-device Enable manual device type and ECID entry
--exit-recovery Attempt to exit recovery mode
--help Display this help message
--no-color Disable colors for script output
--no-device Enable no device mode
--no-version-check Disable script version checking
--pwn Pwn the connected device
For 32-bit devices compatible with restores/downgrades (see README):
--activation-records Enable dumping/stitching activation records
--dead-bb Disable bbupdate completely without dumping/stitching baseband
--disable-bbupdate Disable bbupdate and enable dumping/stitching baseband
--gasgauge-patch Enable multipatch to get past "gas gauge" error (aka error 29 in iTunes)
--ipsw-hacktivate Enable hacktivation for creating IPSW (iPhone 2G/3G/3GS only)
--ipsw-verbose Enable verbose boot option (3GS and powdersn0w only)
--jailbreak Enable jailbreak option
--just-boot Tether boot the device (requires additional arguments)
--memory Enable memory option for creating IPSW
--pwned-recovery Assume that device is in pwned recovery mode (experimental)
--skip-first Skip first restore and flash NOR IPSW only for powdersn0w 4.2.x and lower
--skip-ibss Assume that pwned iBSS has already been sent to the device
For 64-bit checkm8 devices compatible with pwned restores:
--skip-blob Enable futurerestore skip blob option for OTA/onboard/factory blobs
--use-pwndfu Enable futurerestore pwned restore option
* Default IPSW path: <script location>/<name of IPSW file>.ipsw
* Default SHSH path: <script location>/saved/shsh/<name of SHSH file>.shsh(2)
'
}
unzip2="$(command -v unzip)"
zip2="$(command -v zip)"
unzip() {
$unzip2 "$@" || error "An error occurred with the unzip operation: $*"
}
zip() {
$zip2 "$@" || error "An error occurred with the zip operation: $*"
}
set_tool_paths() {
: '
sets variables: platform, platform_ver, dir
also checks architecture (linux) and macos version
also set distro, debian_ver, ubuntu_ver, fedora_ver variables for linux
list of tools set here:
bspatch, jq, scp, ssh, sha1sum (for macos: shasum -a 1), zenity
these ones "need" sudo for linux arm, not for others:
futurerestore, gaster, idevicerestore, ipwnder, irecovery
tools set here will be executed using:
$name_of_tool
the rest of the tools not listed here will be executed using:
"$dir/$name_of_tool"
'
if [[ $OSTYPE == "linux"* ]]; then
source /etc/os-release
platform="linux"
platform_ver="$PRETTY_NAME"
dir="../bin/linux/"
# architecture check
if [[ $(uname -m) == "a"* && $(getconf LONG_BIT) == 64 ]]; then
platform_arch="arm64"
elif [[ $(uname -m) == "a"* ]]; then
platform_arch="armhf"
elif [[ $(uname -m) == "x86_64" ]]; then
platform_arch="x86_64"
else
error "Your architecture ($(uname -m)) is not supported."
fi
dir+="$platform_arch"
# version check
if [[ -n $UBUNTU_CODENAME ]]; then
case $UBUNTU_CODENAME in
"jammy" | "kinetic" ) ubuntu_ver=22;;
"lunar" | "mantic" ) ubuntu_ver=23;;
"noble" | "oracular" ) ubuntu_ver=24;;
"plucky" ) ubuntu_ver=25;;
esac
if [[ -z $ubuntu_ver ]]; then
source /etc/upstream-release/lsb-release 2>/dev/null
ubuntu_ver="$(echo "$DISTRIB_RELEASE" | cut -c -2)"
fi
if [[ -z $ubuntu_ver ]]; then
ubuntu_ver="$(echo "$VERSION_ID" | cut -c -2)"
fi
elif [[ -e /etc/debian_version ]]; then
debian_ver=$(cat /etc/debian_version)
case $debian_ver in
*"sid" | "kali"* ) debian_ver="sid";;
* ) debian_ver="$(echo "$debian_ver" | cut -c -2)";;
esac
elif [[ $ID == "fedora" || $ID_LIKE == "fedora" || $ID == "nobara" ]]; then
fedora_ver=$VERSION_ID
fi
# distro check
if [[ $ID == "arch" || $ID_LIKE == "arch" || $ID == "artix" ]]; then
distro="arch"
elif (( ubuntu_ver >= 22 )) || (( debian_ver >= 12 )) || [[ $debian_ver == "sid" ]]; then
distro="debian"
elif (( fedora_ver >= 37 )); then
distro="fedora"
if [[ $(command -v rpm-ostree) ]]; then
distro="fedora-atomic"
fi
elif [[ $ID == "opensuse-tumbleweed" ]]; then
distro="opensuse"
elif [[ $ID == "gentoo" || $ID_LIKE == "gentoo" || $ID == "pentoo" ]]; then
distro="gentoo"
elif [[ $ID == "void" ]]; then
distro="void"
elif [[ -n $ubuntu_ver || -n $debian_ver || -n $fedora_ver ]]; then
error "Your distro version ($platform_ver - $platform_arch) is not supported. See the repo README for supported OS versions/distros"
else
warn "Your distro ($platform_ver - $platform_arch) is not detected/supported. See the repo README for supported OS versions/distros"
print "* You may still continue, but you need to install required packages and libraries manually as needed."
sleep 5
pause
fi
bspatch="$dir/bspatch"
if [[ $platform_arch != "armhf" ]]; then
dir_env="env LD_LIBRARY_PATH=$dir/lib "
ideviceactivation="$dir_env"
idevicediagnostics="$dir_env"
ideviceinstaller="$dir_env"
fi
PlistBuddy="$dir/PlistBuddy"
sha1sum="$(command -v sha1sum)"
tsschecker="$dir/tsschecker"
zenity="$(command -v zenity)"
scp2="$dir/scp"
ssh2="$dir/ssh"
cp $ssh2 .
chmod +x ssh
# live cd/usb check
if [[ $(id -u $USER) == 999 || $USER == "liveuser" ]]; then
live_cdusb=1
live_cdusb_str="Live session"
log "Linux Live session detected."
if [[ $(pwd) == "/home"* ]]; then
df . -h
if [[ $(lsblk -o label | grep -c "casper-rw") == 1 || $(lsblk -o label | grep -c "persistence") == 1 ]]; then
log "Detected Legacy iOS Kit running on persistent storage."
live_cdusb_str+=" - Persistent storage"
else
warn "Detected Legacy iOS Kit running on temporary storage."
print "* You may run out of space and get errors during the restore process."
print "* Please move Legacy iOS Kit to a drive that is NOT used for the live USB."
print "* This may mean using another external HDD/flash drive to store Legacy iOS Kit on."
print "* To use one USB drive only, create the live USB using Rufus with Persistent Storage enabled."
sleep 5
pause
live_cdusb_str+=" - Temporary storage"
fi
fi
fi
# if "/media" is detected in pwd, warn user of possible permission issues
if [[ $(pwd) == *"/media"* ]]; then
warn "You might get permission errors like \"Permission denied\" on getting device info."
print "* If this is the case, try moving Legacy iOS Kit to the Desktop or Documents folder."
fi
if [[ -z $device_disable_sudoloop ]]; then
device_sudoloop=1 # Run some tools as root for device detection if set to 1. (for Linux)
trap "clean_sudo" EXIT
fi
if [[ $(uname -m) == "a"* || $device_sudoloop == 1 || $live_cdusb == 1 ]]; then
if [[ $live_cdusb != 1 ]]; then
print "* Enter your user password when prompted"
fi
sudo -v
(while true; do sudo -v; sleep 60; done) &
sudoloop_pid=$!
futurerestore="sudo "
gaster="sudo "
idevicerestore="sudo "
ipwnder="sudo "
irecovery="sudo "
irecovery2="sudo "
irecovery3="sudo "
if [[ ! -d $dir && $(ls ../bin/linux) ]]; then
log "Running on platform: $platform ($platform_ver - $platform_arch)"
error "Failed to find bin directory for $platform_arch, found $(ls -x ../bin/linux) instead." \
"* Download the \"linux_$platform_arch\" or \"complete\" version to continue (or do a git clone)"
fi
trap "clean_usbmuxd" EXIT
if [[ $othertmp == 0 ]]; then
if [[ $(command -v systemctl) ]]; then
sudo systemctl stop usbmuxd
fi
#sudo killall usbmuxd 2>/dev/null
#sleep 1
if [[ $platform_arch == "armhf" ]]; then
log "Running usbmuxd"
sudo -b $dir/usbmuxd -pf &>../saved/usbmuxd.log
else
log "Running usbmuxd2"
sudo -b $dir/usbmuxd2 &>../saved/usbmuxd2.log
fi
elif [[ $othertmp != 0 ]]; then
log "Detected existing tmp folder(s), there might be other Legacy iOS Kit instance(s) running"
log "Not running usbmuxd"
fi
fi
gaster+="$dir/gaster"
elif [[ $(uname -m) == "iP"* ]]; then
error "Running Legacy iOS Kit on iOS is not supported (yet)" "* Supported platforms: Linux, macOS"
elif [[ $OSTYPE == "darwin"* ]]; then
platform="macos"
platform_ver="${1:-$(sw_vers -productVersion)}"
dir="../bin/macos"
platform_arch="$(uname -m)"
if [[ $platform_arch == "arm64" ]]; then
dir+="/arm64"
fi
# macos version check
mac_majver="${platform_ver:0:2}"
if [[ $mac_majver == 10 ]]; then
mac_minver=${platform_ver:3}
mac_minver=${mac_minver%.*}
if (( mac_minver < 11 )); then
warn "Your macOS version ($platform_ver - $platform_arch) is not supported. Expect features to not work properly."
print "* Supported versions are macOS 10.11 and newer. (10.13/10.15 and newer recommended)"
pause
fi
if (( mac_minver <= 11 )); then
mac_cocoa=1
if [[ -z $(command -v cocoadialog) ]]; then
local error_msg="* You need to install cocoadialog from MacPorts."
error_msg+=$'\n* Please read the wiki and install the requirements needed in MacPorts: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/How-to-Use'
error_msg+=$'\n* Also make sure that /opt/local/bin (or /usr/local/bin) is in your $PATH.'
error_msg+=$'\n* You may try running this command: export PATH="/opt/local/bin:$PATH"'
error "Cannot find cocoadialog, cannot continue." "$error_msg"
fi
fi
if [[ $(command -v curl) == "/usr/bin/curl" ]] && (( mac_minver < 15 )); then
local error_msg="* You need to install curl from MacPorts."
error_msg+=$'\n* Please read the wiki and install the requirements needed in MacPorts: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/How-to-Use'
error_msg+=$'\n* Also make sure that /opt/local/bin (or /usr/local/bin) is in your $PATH.'
error_msg+=$'\n* You may try running this command: export PATH="/opt/local/bin:$PATH"'
error "Outdated curl detected, cannot continue." "$error_msg"
fi
fi
bspatch="$(command -v bspatch)"
cocoadialog="$(command -v cocoadialog)"
gaster+="../bin/macos/gaster"
ipwnder32="$dir/ipwnder32"
PlistBuddy="/usr/libexec/PlistBuddy"
sha1sum="$(command -v shasum) -a 1"
tsschecker="../bin/macos/tsschecker"
zenity="../bin/macos/zenity"
scp2="/usr/bin/scp"
ssh2="/usr/bin/ssh"
# kill macos daemons
killall -STOP AMPDevicesAgent AMPDeviceDiscoveryAgent MobileDeviceUpdater
else
error "Your platform ($OSTYPE) is not supported." "* Supported platforms: Linux, macOS"
fi
log "Running on platform: $platform ($platform_ver - $platform_arch)"
if [[ ! -d $dir ]]; then
error "Failed to find bin directory ($dir), cannot continue." \
"* Re-download Legacy iOS Kit from releases (or do a git clone/reset)"
fi
if [[ $device_sudoloop == 1 ]]; then
sudo chmod +x $dir/*
if [[ $? != 0 ]]; then
error "Failed to set up execute permissions of binaries, cannot continue. Try to move Legacy iOS Kit somewhere else."
fi
else
chmod +x $dir/*
fi
futurerestore+="$dir/futurerestore"
ideviceactivation+="$dir/ideviceactivation"
idevicediagnostics+="$dir/idevicediagnostics"
ideviceinfo="$dir/ideviceinfo"
ideviceinstaller+="$dir/ideviceinstaller"
idevicerestore+="$dir/idevicerestore"
ifuse="$(command -v ifuse)"
ipwnder+="$dir/ipwnder"
irecovery+="$dir/irecovery"
irecovery2+="$dir/irecovery2"
irecovery3+="../$dir/irecovery"
jq="$dir/jq"
cp ../resources/ssh_config .
if [[ $(ssh -V 2>&1 | grep -c SSH_8.8) == 1 || $(ssh -V 2>&1 | grep -c SSH_8.9) == 1 ||
$(ssh -V 2>&1 | grep -c SSH_9.) == 1 || $(ssh -V 2>&1 | grep -c SSH_1) == 1 ]]; then
echo " PubkeyAcceptedAlgorithms +ssh-rsa" >> ssh_config
elif [[ $(ssh -V 2>&1 | grep -c SSH_6) == 1 ]]; then
cat ../resources/ssh_config | sed "s,Add,#Add,g" | sed "s,HostKeyA,#HostKeyA,g" > ssh_config
fi
scp2+=" -F ./ssh_config"
ssh2+=" -F ./ssh_config"
}
prepare_udev_rules() {
local owner="$1"
local group="$2"
echo "ACTION==\"add\", SUBSYSTEM==\"usb\", ATTR{idVendor}==\"05ac\", ATTR{idProduct}==\"122[27]|128[0-3]|1338\", OWNER=\"$owner\", GROUP=\"$group\", MODE=\"0660\" TAG+=\"uaccess\"" > 39-libirecovery.rules
}
install_depends() {
log "Installing dependencies..."
rm -f "../resources/firstrun"
if [[ $platform == "linux" ]]; then
print "* Legacy iOS Kit will be installing dependencies from your distribution's package manager"
print "* Enter your user password when prompted"
if [[ $distro != "debian" && $distro != "fedora-atomic" ]]; then
echo
warn "Before continuing, make sure that your system is fully updated first!"
echo "${color_Y}* This operation can result in a partial upgrade and may cause breakage if your system is not updated${color_N}"
echo
fi
pause
prepare_udev_rules usbmux plugdev
fi
if [[ $distro == "arch" ]]; then
sudo pacman -Sy --noconfirm --needed base-devel ca-certificates ca-certificates-mozilla curl git ifuse libimobiledevice libxml2 openssh pyenv python udev unzip usbmuxd usbutils vim zenity zip zstd
prepare_udev_rules root storage
elif [[ $distro == "debian" ]]; then
if [[ -n $ubuntu_ver ]]; then
sudo add-apt-repository -y universe
fi
sudo apt update
sudo apt install -m -y build-essential ca-certificates curl git ifuse libimobiledevice6 libssl3 libssl-dev libxml2 libzstd1 openssh-client patch python3 unzip usbmuxd usbutils xxd zenity zip zlib1g-dev
if [[ $(command -v systemctl 2>/dev/null) ]]; then
sudo systemctl enable --now udev systemd-udevd usbmuxd 2>/dev/null
fi
elif [[ $distro == "fedora" ]]; then
sudo dnf install -y ca-certificates git ifuse libimobiledevice libxml2 libzstd openssl openssl-devel patch python3 systemd udev usbmuxd vim-common zenity zip zlib-devel
sudo dnf group install -y c-development
sudo ln -sf /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-certificates.crt
prepare_udev_rules root usbmuxd
elif [[ $distro == "fedora-atomic" ]]; then
rpm-ostree install patch vim-common zenity
print "* You may need to reboot to apply changes with rpm-ostree. Perform a reboot after this before running the script again."
elif [[ $distro == "opensuse" ]]; then
sudo zypper -n install ca-certificates curl git ifuse libimobiledevice-1_0-6 libopenssl-3-devel libxml2 libzstd1 openssl-3 patch pyenv python3 usbmuxd unzip vim zenity zip zlib-devel
sudo zypper -n install -t pattern devel_basis
prepare_udev_rules usbmux usbmux # idk if this is right
elif [[ $distro == "gentoo" ]]; then
sudo emerge -av --noreplace app-arch/zstd app-misc/ca-certificates app-pda/ifuse dev-libs/libxml2 libimobiledevice net-misc/curl openssh python udev unzip usbmuxd usbutils vim zenity zip
elif [[ $distro == "void" ]]; then
sudo xbps-install curl git patch openssh python3 unzip xxd zenity zip base-devel libffi-devel bzip2-devel openssl openssl-devel readline readline-devel sqlite-devel xz liblzma-devel zlib zlib-devel
elif [[ $platform == "macos" ]]; then
print "* Legacy iOS Kit will be installing dependencies and setting up permissions of tools"
xattr -cr ../bin/macos
log "Installing Xcode Command Line Tools"
xcode-select --install
print "* Make sure to install requirements from Homebrew/MacPorts: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/How-to-Use"
pause
fi
echo "$platform_ver" > "../resources/firstrun"
if [[ $platform == "linux" && $distro != "fedora-atomic" ]]; then
# from linux_fix and libirecovery-rules by Cryptiiiic
if [[ $(command -v systemctl) ]]; then
sudo systemctl enable --now systemd-udevd usbmuxd 2>/dev/null
fi
sudo cp 39-libirecovery.rules /etc/udev/rules.d/39-libirecovery.rules
sudo chown root:root /etc/udev/rules.d/39-libirecovery.rules
sudo chmod 0644 /etc/udev/rules.d/39-libirecovery.rules
sudo udevadm control --reload-rules
sudo udevadm trigger -s usb
fi
log "Install script done! Please run the script again to proceed"
log "If your iOS device is plugged in, unplug and replug your device"
exit
}
version_update_check() {
pushd "$(dirname "$0")/tmp$$" >/dev/null
if [[ $platform == "macos" && ! -e ../resources/firstrun ]]; then
xattr -cr ../bin/macos
fi
log "Checking for updates..."
github_api=$(curl https://api.github.com/repos/LukeZGD/Legacy-iOS-Kit/releases/latest 2>/dev/null)
version_latest=$(echo "$github_api" | $jq -r '.assets[] | select(.name|test("complete")) | .name' | cut -c 25- | cut -c -9)
git_hash_latest=$(echo "$github_api" | $jq -r '.assets[] | select(.name|test("git-hash")) | .name' | cut -c 21- | cut -c -7)
popd >/dev/null
}
version_update() {
local url
local req
read -p "$(input 'Do you want to update now? (Y/n): ')" opt
if [[ $opt == 'n' || $opt == 'N' ]]; then
log "User selected N, cannot continue. Exiting."
exit
fi
if [[ -d .git ]]; then
log "Running git pull..."
print "* If this fails for some reason, run: git reset --hard"
print "* To clean more files if needed, run: git clean -df"
git pull
pushd "$(dirname "$0")/tmp$$" >/dev/null
log "Done! Please run the script again"
exit
elif (( $(ls bin | wc -l) > 1 )); then
req=".assets[] | select (.name|test(\"complete\")) | .browser_download_url"
elif [[ $platform == "linux" ]]; then
req=".assets[] | select (.name|test(\"${platform}_$platform_arch\")) | .browser_download_url"
else
req=".assets[] | select (.name|test(\"${platform}\")) | .browser_download_url"
fi
pushd "$(dirname "$0")/tmp$$" >/dev/null
url="$(echo "$github_api" | $jq -r "$req")"
log "Downloading: $url"
curl -L $url -o latest.zip
if [[ ! -s latest.zip ]]; then
error "Download failed. Please run the script again"
fi
popd >/dev/null
log "Updating..."
cp resources/firstrun tmp$$ 2>/dev/null
rm -r bin/ LICENSE README.md restore.sh
if [[ $device_sudoloop == 1 ]]; then
sudo rm -rf resources/
fi
rm -r resources/ saved/ipwndfu/ 2>/dev/null
unzip -q tmp$$/latest.zip -d .
cp tmp$$/firstrun resources 2>/dev/null
pushd "$(dirname "$0")/tmp$$" >/dev/null
log "Done! Please run the script again"
exit
}
version_get() {
pushd .. >/dev/null
if [[ -d .git ]]; then
if [[ -e .git/shallow ]]; then
log "Shallow git repository detected. Unshallowing..."
git fetch --unshallow
fi
git_hash=$(git rev-parse HEAD | cut -c -7)
local dm=$(git log -1 --format=%ci | cut -c 3- | cut -c -5)
version_current=v${dm//-/.}.
dm="20$dm"
if [[ $(uname) == "Darwin" ]]; then
dm="$(date -j -f "%Y-%m-%d %H:%M:%S" "${dm}-01 00:00:00" +%s)"
else
dm="$(date --date="${dm}-01" +%s)"
fi
dm=$((dm-1))
version_current+=$(git rev-list --count HEAD --since=$dm | xargs printf "%02d")
elif [[ -e ./resources/git_hash ]]; then
version_current="$(cat ./resources/version)"
git_hash="$(cat ./resources/git_hash)"
else
log ".git directory and git_hash file not found, cannot determine version."
if [[ $no_version_check != 1 ]]; then
warn "Your copy of Legacy iOS Kit is downloaded incorrectly. Do not use the \"Code\" button in GitHub."
print "* Please download Legacy iOS Kit using git clone or from GitHub releases: https://github.com/LukeZGD/Legacy-iOS-Kit/releases"
fi
fi
if [[ -n $version_current ]]; then
print "* Version: $version_current ($git_hash)"
fi
popd >/dev/null
}
version_check() {
if [[ $no_version_check == 1 ]]; then
warn "No version check flag detected, update check is disabled and no support will be provided."
return
fi
pushd .. >/dev/null
version_update_check
if [[ -z $version_latest ]]; then
warn "Failed to check for updates. GitHub may be down or blocked by your network."
elif [[ $git_hash_latest != "$git_hash" ]]; then
if [[ -z $version_current ]]; then
print "* Latest version: $version_latest ($git_hash_latest)"
print "* Please download/pull the latest version before proceeding."
version_update
elif (( $(echo $version_current | cut -c 2- | sed -e 's/\.//g') >= $(echo $version_latest | cut -c 2- | sed -e 's/\.//g') )); then
warn "Current version is newer/different than remote: $version_latest ($git_hash_latest)"
else
print "* A newer version of Legacy iOS Kit is available."
print "* Current version: $version_current ($git_hash)"
print "* Latest version: $version_latest ($git_hash_latest)"
print "* Please download/pull the latest version before proceeding."
version_update
fi
fi
popd >/dev/null
}
device_entry() {
# enable manual entry
log "Manual device/ECID entry is enabled."
until [[ -n $device_type ]]; do
read -p "$(input 'Enter device type (eg. iPad2,1): ')" device_type
done
if [[ $main_argmode == "device_justboot" ]]; then
:
elif [[ $device_type != "iPhone1"* && $device_type != "iPod1,1" ]]; then
until [[ -n $device_ecid ]] && [ "$device_ecid" -eq "$device_ecid" ]; do
read -p "$(input 'Enter device ECID (must be decimal): ')" device_ecid
done
fi
}
device_get_name() {
# all devices that run iOS/iPhoneOS/iPadOS
device_name=$device_type
case $device_type in
"iPhone1,1") device_name="iPhone 2G";;
"iPhone1,2") device_name="iPhone 3G";;
"iPhone2,1") device_name="iPhone 3GS";;
"iPhone3,1") device_name="iPhone 4 (GSM)";;
"iPhone3,2") device_name="iPhone 4 (GSM, Rev A)";;
"iPhone3,3") device_name="iPhone 4 (CDMA)";;
"iPhone4,1") device_name="iPhone 4S";;
"iPhone5,1") device_name="iPhone 5 (GSM)";;
"iPhone5,2") device_name="iPhone 5 (Global)";;
"iPhone5,3") device_name="iPhone 5C (GSM)";;
"iPhone5,4") device_name="iPhone 5C (Global)";;
"iPhone6,1") device_name="iPhone 5S (GSM)";;
"iPhone6,2") device_name="iPhone 5S (Global)";;
"iPhone7,1") device_name="iPhone 6 Plus";;
"iPhone7,2") device_name="iPhone 6";;
"iPhone8,1") device_name="iPhone 6S";;
"iPhone8,2") device_name="iPhone 6S Plus";;
"iPhone8,4") device_name="iPhone SE 2016";;
"iPhone9,1") device_name="iPhone 7 (Global)";;
"iPhone9,2") device_name="iPhone 7 Plus (Global)";;
"iPhone9,3") device_name="iPhone 7 (GSM)";;
"iPhone9,4") device_name="iPhone 7 Plus (GSM)";;
"iPhone10,1") device_name="iPhone 8 (Global)";;
"iPhone10,2") device_name="iPhone 8 Plus (Global)";;
"iPhone10,3") device_name="iPhone X (Global)";;
"iPhone10,4") device_name="iPhone 8 (GSM)";;
"iPhone10,5") device_name="iPhone 8 Plus (GSM)";;
"iPhone10,6") device_name="iPhone X (GSM)";;
"iPhone11,2") device_name="iPhone XS";;
"iPhone11,4") device_name="iPhone XS Max (China)";;
"iPhone11,6") device_name="iPhone XS Max";;
"iPhone11,8") device_name="iPhone XR";;
"iPhone12,1") device_name="iPhone 11";;
"iPhone12,3") device_name="iPhone 11 Pro";;
"iPhone12,5") device_name="iPhone 11 Pro Max";;
"iPhone12,8") device_name="iPhone SE 2020";;
"iPhone13,1") device_name="iPhone 12 mini";;
"iPhone13,2") device_name="iPhone 12";;
"iPhone13,3") device_name="iPhone 12 Pro";;
"iPhone13,4") device_name="iPhone 12 Pro Max";;
"iPhone14,2") device_name="iPhone 13 Pro";;
"iPhone14,3") device_name="iPhone 13 Pro Max";;
"iPhone14,4") device_name="iPhone 13 mini";;
"iPhone14,5") device_name="iPhone 13";;
"iPhone14,6") device_name="iPhone SE 2022";;
"iPhone14,7") device_name="iPhone 14";;
"iPhone14,8") device_name="iPhone 14 Plus";;
"iPhone15,2") device_name="iPhone 14 Pro";;
"iPhone15,3") device_name="iPhone 14 Pro Max";;
"iPhone15,4") device_name="iPhone 15";;
"iPhone15,5") device_name="iPhone 15 Plus";;
"iPhone16,1") device_name="iPhone 15 Pro";;
"iPhone16,2") device_name="iPhone 15 Pro Max";;
"iPhone17,1") device_name="iPhone 16 Pro";;
"iPhone17,2") device_name="iPhone 16 Pro Max";;
"iPhone17,3") device_name="iPhone 16";;
"iPhone17,4") device_name="iPhone 16 Plus";;
"iPad1,1") device_name="iPad 1";;
"iPad2,1") device_name="iPad 2 (Wi-Fi)";;
"iPad2,2") device_name="iPad 2 (GSM)";;
"iPad2,3") device_name="iPad 2 (CDMA)";;
"iPad2,4") device_name="iPad 2 (Wi-Fi, Rev A)";;
"iPad2,5") device_name="iPad mini 1 (Wi-Fi)";;
"iPad2,6") device_name="iPad mini 1 (GSM)";;
"iPad2,7") device_name="iPad mini 1 (Global)";;
"iPad3,1") device_name="iPad 3 (Wi-Fi)";;
"iPad3,2") device_name="iPad 3 (CDMA)";;
"iPad3,3") device_name="iPad 3 (GSM)";;
"iPad3,4") device_name="iPad 4 (Wi-Fi)";;
"iPad3,5") device_name="iPad 4 (GSM)";;
"iPad3,6") device_name="iPad 4 (Global)";;
"iPad4,1") device_name="iPad Air 1 (Wi-Fi)";;
"iPad4,2") device_name="iPad Air 1 (Cellular)";;
"iPad4,3") device_name="iPad Air 1 (China)";;
"iPad4,4") device_name="iPad mini 2 (Wi-Fi)";;
"iPad4,5") device_name="iPad mini 2 (Cellular)";;
"iPad4,6") device_name="iPad mini 2 (China)";;
"iPad4,7") device_name="iPad mini 3 (Wi-Fi)";;
"iPad4,8") device_name="iPad mini 3 (Cellular)";;
"iPad4,9") device_name="iPad mini 3 (China)";;
"iPad5,1") device_name="iPad mini 4 (Wi-Fi)";;
"iPad5,2") device_name="iPad mini 4 (Cellular)";;
"iPad5,3") device_name="iPad Air 2 (Wi-Fi)";;
"iPad5,4") device_name="iPad Air 2 (Cellular)";;
"iPad6,3") device_name="iPad Pro 9.7\" (Wi-Fi)";;
"iPad6,4") device_name="iPad Pro 9.7\" (Cellular)";;
"iPad6,7") device_name="iPad Pro 12.9\" (Wi-Fi)";;
"iPad6,8") device_name="iPad Pro 12.9\" (Cellular)";;
"iPad6,11") device_name="iPad 5 (Wi-Fi)";;
"iPad6,12") device_name="iPad 5 (Cellular)";;
"iPad7,1") device_name="iPad Pro 12.9\" (2nd gen, Wi-Fi)";;
"iPad7,2") device_name="iPad Pro 12.9\" (2nd gen, Cellular)";;
"iPad7,3") device_name="iPad Pro 10.5\" (Wi-Fi)";;
"iPad7,4") device_name="iPad Pro 10.5\" (Cellular)";;
"iPad7,5") device_name="iPad 6 (Wi-Fi)";;
"iPad7,6") device_name="iPad 6 (Cellular)";;
"iPad7,11") device_name="iPad 7 (Wi-Fi)";;
"iPad7,12") device_name="iPad 7 (Cellular)";;
"iPad8,1") device_name="iPad Pro 11\" (Wi-Fi)";;
"iPad8,2") device_name="iPad Pro 11\" (Wi-Fi, 6GB RAM)";;
"iPad8,3") device_name="iPad Pro 11\" (Cellular)";;
"iPad8,4") device_name="iPad Pro 11\" (Cellular, 6GB RAM)";;
"iPad8,5") device_name="iPad Pro 12.9\" (3rd gen, Wi-Fi)";;
"iPad8,6") device_name="iPad Pro 12.9\" (3rd gen, Wi-Fi, 6GB RAM)";;
"iPad8,7") device_name="iPad Pro 12.9\" (3rd gen, Cellular)";;
"iPad8,8") device_name="iPad Pro 12.9\" (3rd gen, Cellular, 6GB RAM)";;
"iPad8,9") device_name="iPad Pro 11\" (2nd gen, Wi-Fi)";;
"iPad8,10") device_name="iPad Pro 11\" (2nd gen, Cellular)";;
"iPad8,11") device_name="iPad Pro 12.9\" (4th gen, Wi-Fi)";;
"iPad8,12") device_name="iPad Pro 12.9\" (4th gen, Cellular)";;
"iPad11,1") device_name="iPad mini 5 (Wi-Fi)";;
"iPad11,2") device_name="iPad mini 5 (Cellular)";;
"iPad11,3") device_name="iPad Air 3 (Wi-Fi)";;
"iPad11,4") device_name="iPad Air 3 (Cellular)";;
"iPad11,6") device_name="iPad 8 (Wi-Fi)";;
"iPad11,7") device_name="iPad 8 (Cellular)";;
"iPad12,1") device_name="iPad 9 (Wi-Fi)";;
"iPad12,2") device_name="iPad 9 (Cellular)";;
"iPad13,1") device_name="iPad Air 4 (Wi-Fi)";;
"iPad13,2") device_name="iPad Air 4 (Cellular)";;
"iPad13,4") device_name="iPad Pro 11\" (3rd gen, Wi-Fi)";;
"iPad13,5") device_name="iPad Pro 11\" (3rd gen, Wi-Fi, 16GB RAM)";;
"iPad13,6") device_name="iPad Pro 11\" (3rd gen, Cellular)";;
"iPad13,7") device_name="iPad Pro 11\" (3rd gen, Cellular, 16GB RAM)";;
"iPad13,8") device_name="iPad Pro 12.9\" (5th gen, Wi-Fi)";;
"iPad13,9") device_name="iPad Pro 12.9\" (5th gen, Wi-Fi, 16GB RAM)";;
"iPad13,10") device_name="iPad Pro 12.9\" (5th gen, Cellular)";;
"iPad13,11") device_name="iPad Pro 12.9\" (5th gen, Cellular, 16GB RAM)";;
"iPad13,16") device_name="iPad Air 5 (Wi-Fi)";;
"iPad13,17") device_name="iPad Air 5 (Cellular)";;
"iPad13,18") device_name="iPad 10 (Wi-Fi)";;
"iPad13,19") device_name="iPad 10 (Cellular)";;
"iPad14,1") device_name="iPad mini 6 (Wi-Fi)";;
"iPad14,2") device_name="iPad mini 6 (Cellular)";;
"iPad14,3") device_name="iPad Pro 11\" (4th gen, Wi-Fi)";;
"iPad14,4") device_name="iPad Pro 11\" (4th gen, Cellular)";;
"iPad14,5") device_name="iPad Pro 12.9\" (6th gen, Wi-Fi)";;
"iPad14,6") device_name="iPad Pro 12.9\" (6th gen, Cellular)";;
"iPad14,8") device_name="iPad Air 11\" (M2, Wi-Fi)";;
"iPad14,9") device_name="iPad Air 11\" (M2, Cellular)";;
"iPad14,10") device_name="iPad Air 13\" (M2, Wi-Fi)";;
"iPad14,11") device_name="iPad Air 13\" (M2, Cellular)";;
"iPad16,1") device_name="iPad mini (A17 Pro, Wi-Fi)";;
"iPad16,2") device_name="iPad mini (A17 Pro, Cellular)";;
"iPad16,3") device_name="iPad Pro 11\" (M4, Wi-Fi)";;
"iPad16,4") device_name="iPad Pro 11\" (M4, Cellular)";;
"iPad16,5") device_name="iPad Pro 12.9\" (M4, Wi-Fi)";;
"iPad16,6") device_name="iPad Pro 12.9\" (M4, Cellular)";;
"iPod1,1") device_name="iPod touch 1";;
"iPod2,1") device_name="iPod touch 2";;
"iPod3,1") device_name="iPod touch 3";;
"iPod4,1") device_name="iPod touch 4";;
"iPod5,1") device_name="iPod touch 5";;
"iPod7,1") device_name="iPod touch 6";;
"iPod9,1") device_name="iPod touch 7";;
esac
}
device_manufacturing() {
if [[ $device_type != "iPhone2,1" && $device_type != "iPod2,1" ]] || [[ $device_argmode == "none" ]]; then
return
fi
if [[ $device_type == "iPhone2,1" && $device_mode != "DFU" ]]; then
local week=$(echo "$device_serial" | cut -c 2-)
local year=$(echo "$device_serial" | cut -c 1)
case $year in
9 ) year="2009";;
0 ) year="2010";;
1 ) year="2011";;
2 ) year="2012";;
esac
if [[ $year != "2009" ]] || (( week >= 46 )); then
device_newbr=1
elif [[ $year == "2009" ]] && (( week >= 40 )); then
device_newbr=2 # gray area
else
device_newbr=0
fi
elif [[ $device_type == "iPod2,1" && $device_mode == "Recovery" ]]; then
device_newbr=2
return
fi
case $device_newbr in
0 ) print "* This $device_name is an old bootrom model";;
1 ) print "* This $device_name is a new bootrom model";;
2 ) print "* This $device_name bootrom model cannot be determined. Enter DFU mode to get bootrom model";;
esac
if [[ $device_type == "iPhone2,1" && $device_mode == "DFU" ]]; then
print "* Cannot check for manufacturing date in DFU mode"
elif [[ $device_type == "iPhone2,1" ]]; then
print "* Manufactured in Week $week $year"
fi
}
device_s5l8900xall() {
local wtf_sha="cb96954185a91712c47f20adb519db45a318c30f"
local wtf_saved="../saved/WTF.s5l8900xall.RELEASE.dfu"
local wtf_patched="$wtf_saved.patched"
local wtf_patch="../resources/patch/WTF.s5l8900xall.RELEASE.patch"
local wtf_sha_local="$($sha1sum "$wtf_saved" 2>/dev/null | awk '{print $1}')"
mkdir ../saved 2>/dev/null
if [[ $wtf_sha_local != "$wtf_sha" ]]; then
log "Downloading WTF.s5l8900xall"
"$dir/pzb" -g "Firmware/dfu/WTF.s5l8900xall.RELEASE.dfu" -o WTF.s5l8900xall.RELEASE.dfu "http://appldnld.apple.com/iPhone/061-7481.20100202.4orot/iPhone1,1_3.1.3_7E18_Restore.ipsw"
rm -f "$wtf_saved"
mv WTF.s5l8900xall.RELEASE.dfu $wtf_saved
fi
wtf_sha_local="$($sha1sum "$wtf_saved" | awk '{print $1}')"
if [[ $wtf_sha_local != "$wtf_sha" ]]; then
error "SHA1sum mismatch. Expected $wtf_sha, got $wtf_sha_local. Please run the script again"
fi
rm -f "$wtf_patched"
log "Patching WTF.s5l8900xall"
$bspatch $wtf_saved $wtf_patched $wtf_patch
log "Sending patched WTF.s5l8900xall (Pwnage)"
$irecovery -f "$wtf_patched"
device_find_mode DFUreal
sleep 1
}
device_get_info() {
: '
usage: device_get_info (no arguments)
sets the variables: device_mode, device_type, device_ecid, device_vers, device_udid, device_model, device_fw_dir,
device_use_vers, device_use_build, device_use_bb, device_use_bb_sha1, device_latest_vers, device_latest_build,
device_latest_bb, device_latest_bb_sha1, device_proc
'
if [[ $device_argmode == "none" ]]; then
log "No device mode is enabled."
device_mode="none"
device_vers="Unknown"
else
log "Finding device in Normal mode..."
if [[ $platform == "linux" ]]; then
print "* If it gets stuck here, try to restart your PC"
if [[ $othertmp != 0 ]]; then
print "* If it fails to detect devices, try to delete all \"tmp\" folders in your Legacy iOS Kit folder"
fi
fi
fi
$ideviceinfo -s >/dev/null
if [[ $? == 0 ]]; then
device_mode="Normal"
else
$ideviceinfo >/dev/null
if [[ $? == 0 ]]; then
device_mode="Normal"
fi
fi
if [[ -z $device_mode ]]; then
log "Finding device in Recovery/DFU mode..."
device_mode="$($irecovery -q | grep -w "MODE" | cut -c 7-)"
fi
if [[ $device_mode == "Recovery" && $device_pwnrec == 1 ]]; then
device_mode="DFU"
fi
if [[ -z $device_mode ]]; then
local error_msg=$'* Make sure to trust this computer by selecting "Trust" at the pop-up.'
if [[ $platform == "macos" ]]; then
error_msg+=$'\n* Make sure to have the initial setup dependencies installed before retrying.'
error_msg+=$'\n* Double-check if the device is being detected by iTunes/Finder.'
else
error_msg+=$'\n* If your device in normal mode is not being detected, this is likely a usbmuxd issue.'
error_msg+=$'\n* You may also try again in a live USB.'
fi
error_msg+=$'\n* Try restarting your PC/Mac as well as using different USB ports/cables.'
error_msg+=$'\n* For more details, read the "Troubleshooting" wiki page in GitHub.\n* Troubleshooting link: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Troubleshooting'
error "No device found! Please connect the iOS device to proceed." "$error_msg"
fi
log "Getting device info..."
if [[ $device_mode == "WTF" ]]; then
device_proc=1
device_wtfexit=1
device_s5l8900xall
fi
case $device_mode in
"DFU" | "Recovery" )
if [[ -n $device_argmode ]]; then
device_entry
else
device_type=$($irecovery -q | grep "PRODUCT" | cut -c 10-)
device_ecid=$(printf "%d" $($irecovery -q | grep "ECID" | cut -c 7-)) # converts hex ecid to dec
fi
if [[ $device_type == "iPhone1,1" && -z $device_argmode ]]; then
print "* Device Type Option"
print "* Select Y if the device is an iPhone 2G, or N if it is an iPod touch 1"
read -p "$(input 'Is this device an iPhone 2G? (Y/n): ')" opt
if [[ $opt == 'n' || $opt == 'N' ]]; then
device_type="iPod1,1"
fi
fi
device_model=$($irecovery -q | grep "MODEL" | cut -c 8-)
device_vers=$(echo "/exit" | $irecovery -s | grep -a "iBoot-")
if [[ -z $device_vers ]]; then
device_vers="Unknown"
if [[ $device_mode == "Recovery" ]]; then
device_vers+=". Re-enter recovery mode to get iBoot version"
fi
fi
device_serial="$($irecovery -q | grep "SRNM" | cut -c 7- | cut -c 3- | cut -c -3)"
device_get_name
print "* Device: $device_name (${device_type} - ${device_model}) in $device_mode mode"
print "* iOS Version: $device_vers"
print "* ECID: $device_ecid"
device_manufacturing
if [[ $device_type == "iPod2,1" && $device_newbr != 2 ]]; then
device_newbr="$($irecovery -q | grep -c '240.5.1')"
elif [[ $device_type == "iPhone2,1" ]]; then
device_newbr="$($irecovery -q | grep -c '359.3.2')"
fi
device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
;;
"Normal" )
if [[ -n $device_argmode ]]; then
device_entry
else
device_type=$($ideviceinfo -s -k ProductType)
[[ -z $device_type ]] && device_type=$($ideviceinfo -k ProductType)
device_ecid=$($ideviceinfo -s -k UniqueChipID)
fi
device_model=$($ideviceinfo -s -k HardwareModel)
device_vers=$($ideviceinfo -s -k ProductVersion)
device_det=$(echo "$device_vers" | cut -c 1)
device_det2=$(echo "$device_vers" | cut -c -2)
device_build=$($ideviceinfo -s -k BuildVersion)
device_udid=$($ideviceinfo -s -k UniqueDeviceID)
[[ -z $device_udid ]] && device_udid=$($ideviceinfo -k UniqueDeviceID)
if [[ $device_type == "iPod2,1" ]]; then
device_newbr="$($ideviceinfo -k ModelNumber | grep -c 'C')"
elif [[ $device_type == "iPhone2,1" ]]; then
device_serial="$($ideviceinfo -k SerialNumber | cut -c 3- | cut -c -3)"
fi
device_unactivated=$($ideviceactivation state | grep -c "Unactivated")
;;
esac
if [[ $device_argmode == "none" ]]; then
device_entry
fi
device_model="$(echo $device_model | tr '[:upper:]' '[:lower:]')"
device_model="${device_model%??}" # remove "ap" from the end
if [[ -z $device_type && -n $device_model ]]; then
# device_model fallback (this will be up to checkm8 devices only)
case $device_model in
k48 ) device_type="iPad1,1";;
k93 ) device_type="iPad2,1";;
k94 ) device_type="iPad2,2";;
k95 ) device_type="iPad2,3";;
k93a ) device_type="iPad2,4";;
p105 ) device_type="iPad2,5";;
p106 ) device_type="iPad2,6";;
p107 ) device_type="iPad2,7";;
j1 ) device_type="iPad3,1";;
j2 ) device_type="iPad3,2";;
j2a ) device_type="iPad3,3";;
p101 ) device_type="iPad3,4";;
p102 ) device_type="iPad3,5";;
p103 ) device_type="iPad3,6";;
j71 ) device_type="iPad4,1";;
j72 ) device_type="iPad4,2";;
j73 ) device_type="iPad4,3";;
j85 ) device_type="iPad4,4";;
j86 ) device_type="iPad4,5";;