forked from LukeZGD/Legacy-iOS-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore.sh
executable file
·434 lines (386 loc) · 16.3 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
#!/bin/bash
trap "Clean" EXIT
trap "Clean; exit 1" INT TERM
cd "$(dirname $0)"
. ./resources/blobs.sh
. ./resources/depends.sh
. ./resources/device.sh
. ./resources/downgrade.sh
. ./resources/ipsw.sh
for i in "$@"; do
if [[ $i == "EntryDevice" ]]; then
EntryDevice=1
elif [[ $i == "NoColor" ]]; then
NoColor=1
elif [[ $i == "NoDevice" ]]; then
NoDevice=1
elif [[ $i == "NoVersionCheck" ]]; then
NoVersionCheck=1
elif [[ $i == "PwnedDevice" ]]; then
PwnedDevice=1
fi
done
if [[ $NoColor != 1 ]]; then
TERM=xterm-256color
Color_R=$(tput setaf 9)
Color_G=$(tput setaf 10)
Color_B=$(tput setaf 12)
Color_Y=$(tput setaf 11)
Color_N=$(tput sgr0)
fi
Clean() {
rm -rf iP*/ shsh/ tmp/ *.im4p *.bbfw *.plist *.tmp version.xml
kill $iproxyPID $ServerPID 2>/dev/null
}
Echo() {
echo "${Color_B}$1 ${Color_N}"
}
Error() {
echo -e "\n${Color_R}[Error] $1 ${Color_N}"
[[ -n $2 ]] && echo "${Color_R}* $2 ${Color_N}"
echo
ExitWin 1
}
Input() {
echo "${Color_Y}[Input] $1 ${Color_N}"
}
Log() {
echo "${Color_G}[Log] $1 ${Color_N}"
}
ExitWin() {
if [[ $platform == "win" ]]; then
echo
Input "Press Enter/Return to exit."
read -s
fi
exit $1
}
Main() {
local Selection=()
clear
Echo "******* iOS-OTA-Downgrader *******"
Echo " - Downgrader script by LukeZGD - "
echo
if [[ $EUID == 0 ]]; then
Error "Running the script as root is not allowed."
fi
if [[ ! -d ./resources ]]; then
Error "resources folder cannot be found. Replace resources folder and try again." \
"If resources folder is present try removing spaces from path/folder name"
fi
SetToolPaths
if [[ $? != 0 ]]; then
Error "Setting tool paths failed. Your copy of iOS-OTA-Downgrader seems to be incomplete."
fi
if [[ ! $platform ]]; then
Error "Platform unknown/not supported."
fi
if [[ -d .git ]]; then
if [[ $platform == "macos" ]]; then
CurrentVersion="$(date -r $(git log -1 --format="%at") +%Y-%m-%d)-$(git rev-parse HEAD | cut -c -7)"
else
CurrentVersion="$(date -d @$(git log -1 --format="%at") --rfc-3339=date)-$(git rev-parse HEAD | cut -c -7)"
fi
elif [[ -e resources/git_hash ]]; then
CurrentVersion="$(cat resources/git_hash)"
else
Log ".git directory and git_hash file not found, cannot determine version."
if [[ $NoVersionCheck != 1 ]]; then
Error "Your copy of iOS-OTA-Downgrader is downloaded incorrectly. Do not use the \"Code\" button in GitHub." \
"Please download iOS-OTA-Downgrader using git clone or from GitHub releases: https://github.com/LukeZGD/iOS-OTA-Downgrader/releases"
fi
fi
[[ -n $CurrentVersion ]] && Echo "* Version: $CurrentVersion"
chmod +x ./resources/*.sh ./resources/tools/*
if [[ $? != 0 ]]; then
Error "A problem with file permissions has been detected, cannot proceed."
fi
Log "Checking Internet connection..."
$ping 208.67.222.222 >/dev/null
if [[ $? != 0 ]]; then
Error "Please check your Internet connection before proceeding."
fi
if [[ $NoVersionCheck == 1 ]]; then
Log "WARNING - NoVersionCheck detected, update check will be disabled and no support may be provided."
else
Log "Checking for updates..."
LatestVersion=$(curl https://api.github.com/repos/LukeZGD/iOS-OTA-Downgrader/releases/latest 2>/dev/null | grep "latest/iOS-OTA-Downgrader_complete" | cut -c 131- | cut -c -18)
if [[ -z $LatestVersion ]]; then
Log "WARNING - Failed to check for updates. GitHub may be down or blocked by your network."
elif [[ $LatestVersion != $CurrentVersion ]]; then
if (( $(echo $CurrentVersion | cut -c -10 | sed -e 's/-//g') > $(echo $LatestVersion | cut -c -10 | sed -e 's/-//g') )); then
Log "WARNING - Current version is newer than remote ($LatestVersion)"
elif [[ $(echo $CurrentVersion | cut -c -12) != $(echo $LatestVersion | cut -c -12) ]]; then
Echo "* A newer version of iOS-OTA-Downgrader is available."
Echo "* Current version: $CurrentVersion"
Echo "* Latest version: $LatestVersion"
Echo "* Please download/pull the latest version before continuing."
ExitWin 0
fi
fi
fi
if [[ $platform == "macos" && $(uname -m) != "x86_64" ]]; then
Log "Apple Silicon Mac detected. Support may be limited, proceed at your own risk."
elif [[ $(uname -m) != "x86_64" ]]; then
Error "Only 64-bit (x86_64) distributions are supported."
fi
if [[ $1 == "Install" || -z $bspatch || ! -e $ideviceinfo || ! -e $irecoverychk ||
! -e $ideviceenterrecovery || ! -e $iproxy || -z $python ||
! -e ./resources/first_run ]]; then
if [[ ! -e $ideviceinfo || ! -e $irecoverychk ||
! -e $ideviceenterrecovery || ! -e $iproxy ]]; then
rm -rf ./resources/libimobiledevice_$platform
fi
Clean
InstallDepends
fi
GetDeviceValues
Clean
mkdir tmp
if [[ -n $1 && $1 != "No"* && $1 != *"Device" ]]; then
Mode="$1"
else
[[ $NoDevice != 1 ]] && Selection+=("Downgrade Device")
[[ $DeviceProc != 4 ]] && Selection+=("Save OTA Blobs")
if [[ $ProductType == "iPhone3"* && $NoDevice != 1 ]]; then
Selection+=("Restore to 7.1.2")
[[ $ProductType != "iPhone3,2" ]] && Selection+=("Disable/Enable Exploit")
[[ $ProductType == "iPhone3,1" ]] && Selection+=("SSH Ramdisk")
fi
if [[ $DeviceProc != 7 ]]; then
Selection+=("Create Custom IPSW")
[[ $DeviceState == "Normal" ]] && Selection+=("Put Device in kDFU Mode")
fi
Selection+=("(Re-)Install Dependencies" "(Any other key to exit)")
Echo "*** Main Menu ***"
Input "Select an option:"
select opt in "${Selection[@]}"; do
case $opt in
"Downgrade Device" ) Mode="Downgrade"; break;;
"Save OTA Blobs" ) Mode="SaveOTABlobs"; break;;
"Create Custom IPSW" ) Mode="IPSW32"; break;;
"Put Device in kDFU Mode" ) Mode="kDFU"; break;;
"Disable/Enable Exploit" ) Mode="Remove4"; break;;
"Restore to 7.1.2" ) Mode="Restore712"; break;;
"SSH Ramdisk" ) Mode="Ramdisk4"; break;;
"(Re-)Install Dependencies" ) InstallDepends;;
* ) exit 0;;
esac
done
fi
SelectVersion
if [[ $Mode == "IPSW32" ]]; then
echo
[[ $platform == "win" ]] && IPSWCustom="${IPSWType}_${OSVer}_${BuildVer}_CustomW"
JailbreakOption
if [[ -e "$IPSWCustom.ipsw" ]]; then
Log "Found existing Custom IPSW, stopping here."
Echo "* If you want to re-create the custom IPSW, move/delete the existing one first."
ExitWin 0
elif [[ $Jailbreak != 1 && $platform != "win" ]]; then
if [[ $DeviceProc == 4 && $OSVer == "7.1.2" ]]; then
Log "Creating custom IPSW is not needed for non-jailbroken 7.1.2 restores."
ExitWin 0
elif [[ $ProductType != "iPhone3"* && $ProductType != "$DisableBBUpdate" ]]; then
Log "Creating custom IPSW is not needed for non-jailbroken restores on your device."
ExitWin 0
fi
fi
IPSWFindVerify
if [[ $DeviceProc == 4 ]]; then
[[ $OSVer != "7.1.2" ]] && IPSWFindVerify 712
IPSW4
else
IPSW32
fi
Log "Custom IPSW has been created: $IPSWCustom.ipsw"
[[ $Jailbreak == 1 ]] && Echo "* This custom IPSW has a jailbreak built in ($JBName)"
Echo "* Run the script again and select Downgrade Device to use the custom IPSW."
if [[ $DeviceProc != 4 && $platform != "win" ]]; then
Echo "* You may also use futurerestore manually (make sure to use the latest beta)"
fi
ExitWin 0
elif [[ $Mode != "Downgrade"* && $Mode != *"4" ]]; then
$Mode
ExitWin 0
fi
if [[ $DeviceProc == 7 && $platform == "win" ]]; then
local Message="If you want to restore your A7 device on Windows, put the device in pwnDFU mode."
if [[ $DeviceState == "Normal" ]]; then
Error "$Message"
elif [[ $DeviceState == "Recovery" ]]; then
Log "A7 device detected in recovery mode."
Log "$Message"
RecoveryExit
elif [[ $DeviceState == "DFU" ]]; then
Log "A7 device detected in DFU mode."
Echo "* Make sure that your device is already in pwnDFU mode with signature checks disabled."
Echo "* If your device is not in pwnDFU mode, the restore will not proceed!"
Echo "* Entering pwnDFU mode is not supported on Windows. You need to use a Mac/Linux machine or another iOS device to do so."
Input "Press Enter/Return to continue (or press Ctrl+C to cancel)"
read -s
fi
elif [[ $Mode == *"4" || $DeviceProc == 7 ]]; then
if [[ $DeviceState == "Normal" && $OSVer == "7.1.2" ]]; then
kDFU
elif [[ $DeviceState == "DFU" && $OSVer == "7.1.2" ]]; then
Input "Select the mode that your device is currently in:"
Selection=("kDFU mode" "DFU/pwnDFU mode")
select opt in "${Selection[@]}"; do
case $opt in
"kDFU mode" ) break;;
"DFU/pwnDFU mode" ) EnterPwnDFU; break;;
* ) exit 0;;
esac
done
elif [[ $DeviceState == "Normal" ]]; then
Echo "* The device needs to be in recovery/DFU mode before proceeding."
read -p "$(Input 'Send device to recovery mode? (y/N):')" Selection
[[ $Selection == 'Y' || $Selection == 'y' ]] && Recovery || exit
elif [[ $DeviceState == "Recovery" ]]; then
Recovery
elif [[ $DeviceState == "DFU" ]]; then
EnterPwnDFU
fi
if [[ $Mode == *"4" ]]; then
$Mode
ExitWin 0
fi
elif [[ $DeviceState == "DFU" ]]; then
if [[ $PwnedDevice != 1 ]]; then
echo -e "\n${Color_R}[Error] 32-bit A${DeviceProc} device detected in DFU mode. ${Color_N}"
echo "${Color_Y}* Please put the device in normal mode and jailbroken before proceeding. ${Color_N}"
echo "${Color_Y}* Exit DFU mode by holding the TOP and HOME buttons for 15 seconds. ${Color_N}"
echo "${Color_Y}* For usage of the DFU Advanced Menu, add PwnedDevice as an argument. ${Color_N}"
echo "${Color_Y}* For more details, read the \"Troubleshooting\" wiki page in GitHub ${Color_N}"
ExitWin 1
fi
echo
Echo "* DFU Advanced Menu"
Echo "* If you do not know what you are doing, exit now and restart your device in normal mode before retrying."
Input "Select the mode that your device is currently in:"
Selection=("kDFU mode")
if [[ $platform != "win" ]]; then
[[ $DeviceProc == 5 ]] && Selection+=("pwnDFU mode (A5)") || Selection+=("DFU mode (A4/A6)")
fi
Selection+=("Any other key to exit")
select opt in "${Selection[@]}"; do
case $opt in
"kDFU mode" ) break;;
"DFU mode (A4/A6)" ) EnterPwnDFU; break;;
"pwnDFU mode (A5)" ) SendPwnediBSSA5; break;;
* ) exit 0;;
esac
done
Log "Downgrading $ProductType in kDFU/pwnDFU mode..."
elif [[ $DeviceState == "Recovery" ]]; then
if [[ $DeviceProc == 4 || $DeviceProc == 6 ]] && [[ $platform != "win" ]]; then
Recovery
else
Log "32-bit A${DeviceProc} device detected in recovery mode."
Echo "* Please put the device in normal mode and jailbroken before proceeding."
Echo "* For usage of the DFU Advanced Menu, put the device in kDFU or pwnDFU mode"
RecoveryExit
fi
Log "Downgrading $ProductType in pwnDFU mode..."
fi
Downgrade
Log "Downgrade script done!"
ExitWin 0
}
SelectVersion() {
if [[ $DeviceProc == 7 ]]; then
OSVer="10.3.3"
BuildVer="14G60"
return
elif [[ $Mode == "kDFU" || $Mode == *"4" ]]; then
return
fi
if [[ $ProductType == "iPhone5,3" || $ProductType == "iPhone5,4" || $ProductType == "iPhone3"* ]]; then
Selection=()
else
Selection=("iOS 8.4.1")
fi
if [[ $ProductType == "iPad2,1" || $ProductType == "iPad2,2" ||
$ProductType == "iPad2,3" || $ProductType == "iPhone4,1" ]]; then
Selection+=("iOS 6.1.3")
fi
if [[ $ProductType == "iPhone3"* ]]; then
[[ $Mode == "IPSW32" ]] && Selection+=("7.1.2")
[[ $ProductType != "iPhone3,2" ]] && Selection+=("6.1.3")
if [[ $platform == "macos" ]]; then
Echo "* WARNING - Using iPhone4Down on macOS is not recommended for downgrading."
Echo "* Please use powdersn0w or cherryflowerJB from dora2ios instead."
fi
if [[ $ProductType == "iPhone3,1" ]]; then
Selection+=("5.1.1 (9B208)" "5.1.1 (9B206)")
Selection2=("6.1.2" "6.1" "6.0.1" "6.0" "5.1" "5.0.1" "5.0")
if [[ $platform != "linux" ]]; then
Echo "* iOS 4.3.x downgrades are supported on Linux only"
Echo "* For macOS users, use cherryflowerJB instead"
fi
if [[ $platform != "win" ]]; then
Selection+=("4.3.5")
Selection2+=("4.3.3" "4.3")
fi
Selection+=("More versions")
elif [[ $ProductType == "iPhone3,3" && $platform != "macos" && $Mode != "Restore712" ]]; then
Echo "* WARNING - iPhone3,3 support is not well tested. Please use powdersn0w from dora2ios instead."
Echo "* For creating 6.1.3 custom IPSW, make sure to have darling installed: https://github.com/darlinghq/darling"
Echo "* For Ubuntu/Debian, you may install the .deb from releases."
Echo "* For Arch, you may install darling-bin from AUR."
Echo "* For other distros, you might need to build darling yourself."
fi
if [[ $Mode == "Restore712" ]]; then
Echo "* Make sure to disable the exploit first! See the README and wiki for more details."
Input "Press Enter/Return to continue (or press Ctrl+C to cancel)"
read -s
OSVer="7.1.2"
BuildVer="11D257"
Mode="Downgrade4"
return
fi
if [[ $Mode == "Downgrade" ]]; then
Mode="Downgrade4"
fi
fi
if [[ $platform != "win" && $Mode == "Downgrade"* ]]; then
Selection+=("Other (use SHSH blobs)")
fi
Selection+=("(Any other key to exit)")
echo
Input "Select iOS version:"
select opt in "${Selection[@]}"; do
case $opt in
"iOS 8.4.1" ) OSVer="8.4.1"; BuildVer="12H321"; break;;
"iOS 6.1.3" ) OSVer="6.1.3"; BuildVer="10B329"; break;;
"Other (use SHSH blobs)" ) OSVer="Other"; break;;
"7.1.2" ) OSVer="7.1.2"; BuildVer="11D257"; break;;
"6.1.3" ) OSVer="6.1.3"; BuildVer="10B329"; break;;
"5.1.1 (9B208)" ) OSVer="5.1.1"; BuildVer="9B208"; break;;
"5.1.1 (9B206)" ) OSVer="5.1.1"; BuildVer="9B206"; break;;
"4.3.5" ) OSVer="4.3.5"; BuildVer="8L1"; break;;
"More versions" ) OSVer="More"; break;;
* ) exit 0;;
esac
done
if [[ $OSVer == "Other" ]]; then
Mode="Downgrade"
elif [[ $OSVer == "More" ]]; then
select opt in "${Selection2[@]}"; do
case $opt in
"6.1.2" ) OSVer="6.1.2"; BuildVer="10B146"; break;;
"6.1" ) OSVer="6.1"; BuildVer="10B144"; break;;
"6.0.1" ) OSVer="6.0.1"; BuildVer="10A523"; break;;
"6.0" ) OSVer="6.0"; BuildVer="10A403"; break;;
"5.1" ) OSVer="5.1"; BuildVer="9B176"; break;;
"5.0.1" ) OSVer="5.0.1"; BuildVer="9A405"; break;;
"5.0" ) OSVer="5.0"; BuildVer="9A334"; break;;
"4.3.3" ) OSVer="4.3.3"; BuildVer="8J2"; break;;
"4.3" ) OSVer="4.3"; BuildVer="8F190"; break;;
* ) exit 0;;
esac
done
fi
}
Main $1