2021-05-29 13:26:08 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
FRBaseband() {
|
|
|
|
local BasebandSHA1L
|
|
|
|
|
2021-11-28 07:04:07 +01:00
|
|
|
if [[ $DeviceProc == 7 ]]; then
|
2021-05-29 13:26:08 +02:00
|
|
|
mkdir -p saved/baseband 2>/dev/null
|
2021-06-06 14:32:29 +02:00
|
|
|
cp -f $IPSWRestore/Firmware/$Baseband saved/baseband
|
2021-10-26 05:41:09 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -e saved/baseband/$Baseband ]]; then
|
2021-05-29 13:26:08 +02:00
|
|
|
Log "Downloading baseband..."
|
|
|
|
$partialzip $BasebandURL Firmware/$Baseband $Baseband
|
|
|
|
$partialzip $BasebandURL BuildManifest.plist BuildManifest.plist
|
2021-06-19 09:31:20 +02:00
|
|
|
mkdir -p saved/$ProductType saved/baseband 2>/dev/null
|
2021-05-29 13:26:08 +02:00
|
|
|
mv $Baseband saved/baseband
|
|
|
|
mv BuildManifest.plist saved/$ProductType
|
|
|
|
BuildManifest="saved/$ProductType/BuildManifest.plist"
|
2021-11-28 07:04:07 +01:00
|
|
|
elif [[ $DeviceProc != 7 ]]; then
|
2021-05-29 13:26:08 +02:00
|
|
|
BuildManifest="saved/$ProductType/BuildManifest.plist"
|
|
|
|
fi
|
2021-11-07 15:57:20 +01:00
|
|
|
|
2021-05-29 13:26:08 +02:00
|
|
|
BasebandSHA1L=$(shasum saved/baseband/$Baseband | awk '{print $1}')
|
|
|
|
if [[ ! -e $(ls saved/baseband/$Baseband) || $BasebandSHA1L != $BasebandSHA1 ]]; then
|
|
|
|
rm -f saved/baseband/$Baseband saved/$ProductType/BuildManifest.plist
|
2021-11-07 15:57:20 +01:00
|
|
|
if [[ $DeviceProc == 7 ]]; then
|
|
|
|
Error "Downloading/verifying baseband failed. Please run the script again"
|
|
|
|
else
|
|
|
|
Log "Downloading/verifying baseband failed, will proceed with --latest-baseband flag"
|
|
|
|
return 1
|
|
|
|
fi
|
2021-05-29 13:26:08 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-28 12:21:26 +02:00
|
|
|
FutureRestore() {
|
2022-05-30 16:17:56 +02:00
|
|
|
local ExtraArgs=()
|
2021-10-25 08:57:24 +02:00
|
|
|
|
2021-11-06 15:10:04 +01:00
|
|
|
Log "Proceeding to futurerestore..."
|
2022-07-02 06:54:18 +02:00
|
|
|
if [[ $IPSWA7 != 1 ]]; then
|
2022-05-30 16:17:56 +02:00
|
|
|
ExtraArgs+=("--use-pwndfu")
|
2022-05-29 16:57:53 +02:00
|
|
|
cd resources
|
|
|
|
$SimpleHTTPServer &
|
|
|
|
ServerPID=$!
|
|
|
|
cd ..
|
|
|
|
fi
|
2021-11-06 15:10:04 +01:00
|
|
|
|
2022-05-31 06:35:00 +02:00
|
|
|
if [[ $DeviceProc == 7 ]]; then
|
2021-11-06 15:10:04 +01:00
|
|
|
ExtraArgs+=("-s" "$IPSWRestore/Firmware/all_flash/$SEP" "-m" "$BuildManifest")
|
2022-07-02 06:54:18 +02:00
|
|
|
if [[ $IPSWA7 != 1 ]]; then
|
2022-05-31 06:35:00 +02:00
|
|
|
# Send dummy file for device detection
|
|
|
|
$irecovery -f README.md
|
|
|
|
sleep 2
|
|
|
|
fi
|
2022-05-28 12:21:26 +02:00
|
|
|
elif [[ $SendiBSS != 1 ]]; then
|
2021-11-06 15:10:04 +01:00
|
|
|
ExtraArgs+=("--no-ibss")
|
2021-10-26 05:32:59 +02:00
|
|
|
fi
|
|
|
|
|
2021-11-06 15:10:04 +01:00
|
|
|
if [[ $Baseband == 0 ]]; then
|
|
|
|
Log "Device $ProductType has no baseband"
|
2021-11-07 15:57:20 +01:00
|
|
|
ExtraArgs+=("--no-baseband")
|
2021-11-06 15:10:04 +01:00
|
|
|
else
|
|
|
|
FRBaseband
|
2021-11-07 15:57:20 +01:00
|
|
|
if [[ $? == 1 ]]; then
|
|
|
|
ExtraArgs+=("--latest-baseband")
|
|
|
|
else
|
|
|
|
ExtraArgs+=("-b" "saved/baseband/$Baseband" "-p" "$BuildManifest")
|
|
|
|
fi
|
2021-11-06 15:10:04 +01:00
|
|
|
fi
|
2022-04-20 04:39:57 +02:00
|
|
|
|
2022-03-16 05:07:12 +01:00
|
|
|
Log "Running futurerestore with command: $futurerestore -t \"$SHSH\" ${ExtraArgs[*]} \"$IPSWRestore.ipsw\""
|
2021-11-07 15:57:20 +01:00
|
|
|
$futurerestore -t "$SHSH" "${ExtraArgs[@]}" "$IPSWRestore.ipsw"
|
2022-04-20 04:39:57 +02:00
|
|
|
if [[ $? != 0 ]]; then
|
2022-03-16 04:59:01 +01:00
|
|
|
Log "An error seems to have occurred in futurerestore."
|
|
|
|
Echo "* Please read the \"Troubleshooting\" wiki page in GitHub before opening any issue!"
|
2022-04-20 04:39:57 +02:00
|
|
|
Echo "* Your problem may have already been addressed within the wiki page."
|
2022-03-16 04:59:01 +01:00
|
|
|
Echo "* If opening an issue in GitHub, please provide a FULL log. Otherwise, your issue may be dismissed."
|
|
|
|
else
|
2022-04-20 04:39:57 +02:00
|
|
|
echo
|
2022-03-16 04:59:01 +01:00
|
|
|
Log "Restoring done!"
|
|
|
|
fi
|
2021-05-29 13:26:08 +02:00
|
|
|
Log "Downgrade script done!"
|
|
|
|
}
|
2022-05-28 12:21:26 +02:00
|
|
|
|
|
|
|
DowngradeOther() {
|
2022-07-10 10:38:52 +02:00
|
|
|
local FWKeys
|
|
|
|
local NoMove
|
|
|
|
|
2022-05-28 12:21:26 +02:00
|
|
|
Input "Select your IPSW file in the file selection window."
|
|
|
|
IPSW="$($zenity --file-selection --file-filter='IPSW | *.ipsw' --title="Select IPSW file")"
|
|
|
|
[[ ! -s "$IPSW" ]] && Error "No IPSW selected, or IPSW file not found."
|
|
|
|
IPSW="${IPSW%?????}"
|
|
|
|
Log "Selected IPSW file: $IPSW.ipsw"
|
|
|
|
Input "Select your SHSH file in the file selection window."
|
|
|
|
SHSH="$($zenity --file-selection --file-filter='SHSH | *.shsh *.shsh2' --title="Select SHSH file")"
|
|
|
|
[[ ! -s "$SHSH" ]] && Error "No SHSH selected, or SHSH file not found."
|
|
|
|
Log "Selected SHSH file: $SHSH"
|
|
|
|
|
2022-07-10 10:38:52 +02:00
|
|
|
Log "Getting build version from IPSW"
|
2022-07-02 14:19:33 +02:00
|
|
|
unzip -o -j "$IPSW.ipsw" Restore.plist -d tmp
|
2022-07-10 10:38:52 +02:00
|
|
|
if [[ $platform == "macos" ]]; then
|
|
|
|
plutil -extract 'ProductBuildVersion' xml1 tmp/Restore.plist -o tmp/BuildVer
|
|
|
|
BuildVer=$(cat tmp/BuildVer | sed -ne '/<string>/,/<\/string>/p' | sed -e "s/<string>//" | sed "s/<\/string>//" | sed '2d')
|
|
|
|
else
|
|
|
|
BuildVer=$(cat tmp/Restore.plist | grep -i ProductBuildVersion -A 1 | grep -oPm1 "(?<=<string>)[^<]+")
|
|
|
|
fi
|
|
|
|
|
|
|
|
FWKeys="./resources/firmware/$ProductType/$BuildVer"
|
|
|
|
Log "Checking firmware keys in $FWKeys"
|
|
|
|
if [[ -e $FWKeys/index.html ]]; then
|
|
|
|
if [[ $(cat $FWKeys/index.html | grep -c "$BuildVer") != 1 ]]; then
|
|
|
|
Log "Existing firmware keys are not valid. Deleting"
|
|
|
|
rm $FWKeys/index.html
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -e $FWKeys/index.html ]]; then
|
2022-07-02 14:19:33 +02:00
|
|
|
Log "Getting firmware keys for $ProductType-$BuildVer"
|
2022-07-10 10:38:52 +02:00
|
|
|
mkdir -p $FWKeys 2>/dev/null
|
2022-05-28 12:21:26 +02:00
|
|
|
curl -L https://github.com/LukeZGD/iOS-OTA-Downgrader-Keys/raw/master/$ProductType/$BuildVer/index.html -o tmp/index.html
|
2022-07-07 08:21:53 +02:00
|
|
|
if [[ $(cat tmp/index.html | grep -c "$BuildVer") != 1 ]]; then
|
|
|
|
curl -L https://api.m1sta.xyz/wikiproxy/$ProductType/$BuildVer -o tmp/index.html
|
2022-07-10 10:38:52 +02:00
|
|
|
if [[ $(cat tmp/index.html | grep -c "$BuildVer") != 1 ]]; then
|
|
|
|
Log "Warning - Failed to download firmware keys."
|
|
|
|
NoMove=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ $NoMove == 1 ]]; then
|
2022-07-10 10:48:53 +02:00
|
|
|
rm $FWKeys
|
2022-07-10 10:38:52 +02:00
|
|
|
elif [[ -s tmp/index.html ]]; then
|
2022-07-10 10:48:53 +02:00
|
|
|
mv tmp/index.html $FWKeys
|
2022-07-07 08:21:53 +02:00
|
|
|
fi
|
2022-05-28 12:21:26 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
kDFU
|
|
|
|
IPSWSetExtract
|
|
|
|
FutureRestore
|
|
|
|
}
|
|
|
|
|
|
|
|
DowngradeOTA() {
|
2022-05-31 09:43:24 +02:00
|
|
|
if [[ $DeviceProc != 7 ]]; then
|
|
|
|
JailbreakOption
|
|
|
|
fi
|
2022-05-28 12:21:26 +02:00
|
|
|
SaveOTABlobs
|
|
|
|
IPSWFindVerify
|
|
|
|
kDFU
|
2022-07-03 03:51:54 +02:00
|
|
|
if [[ $Jailbreak == 1 || $ProductType == "iPad2,3" ]]; then
|
2022-05-31 09:43:24 +02:00
|
|
|
IPSW32
|
2022-06-08 17:04:56 +02:00
|
|
|
else
|
|
|
|
IPSWCustom=0
|
2022-05-31 09:43:24 +02:00
|
|
|
fi
|
2022-05-28 12:21:26 +02:00
|
|
|
IPSWSetExtract
|
|
|
|
FutureRestore
|
|
|
|
}
|
|
|
|
|
2022-05-29 16:57:53 +02:00
|
|
|
DowngradeOTAWin() {
|
|
|
|
IPSWCustom="${IPSWType}_${OSVer}_${BuildVer}_CustomWin"
|
|
|
|
if [[ $DeviceProc != 7 ]]; then
|
|
|
|
JailbreakOption
|
|
|
|
SaveOTABlobs
|
|
|
|
fi
|
|
|
|
IPSWFindVerify
|
|
|
|
if [[ $DeviceProc == 7 ]]; then
|
2022-07-02 14:19:33 +02:00
|
|
|
IPSWA7=1
|
2022-05-30 16:17:56 +02:00
|
|
|
IPSWSetExtract
|
2022-05-29 16:57:53 +02:00
|
|
|
IPSW64
|
|
|
|
EnterPwnREC
|
|
|
|
local APNonce=$($irecovery -q | grep "NONC" | cut -c 7-)
|
|
|
|
Log "APNONCE: $APNonce"
|
|
|
|
SaveOTABlobs $APNonce
|
|
|
|
IPSWSetExtract set
|
|
|
|
FutureRestore
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
kDFU
|
|
|
|
IPSW32
|
|
|
|
IPSWSetExtract
|
|
|
|
iDeviceRestore
|
|
|
|
}
|
|
|
|
|
2022-07-02 06:54:18 +02:00
|
|
|
IPSWCustomA7() {
|
2022-07-10 10:38:52 +02:00
|
|
|
local fr194=()
|
2022-07-02 06:54:18 +02:00
|
|
|
if [[ $platform == "macos" ]]; then
|
|
|
|
fr194=("https://github.com/futurerestore/futurerestore/releases/download/194/futurerestore-v194-macOS.tar.xz" "d279423dd9a12d3a7eceaeb7e01beb332c306aaa")
|
|
|
|
elif [[ $platform == "linux" ]]; then
|
|
|
|
fr194=("https://github.com/futurerestore/futurerestore/releases/download/194/futurerestore-v194-ubuntu_20.04.2.tar.xz" "9f2b4b6cc6710d1d68880711001d2dc5b4cb9407")
|
|
|
|
fi
|
|
|
|
Input "Custom IPSW Option"
|
|
|
|
Echo "* When this option is enabled, a custom IPSW will be created/used for restoring."
|
|
|
|
Echo "* Only enable this when you encounter problems with futurerestore."
|
|
|
|
Echo "* This option is disabled by default (N)."
|
|
|
|
read -p "$(Input 'Enable this option? (y/N):')" IPSWA7
|
|
|
|
if [[ $IPSWA7 != 'Y' && $IPSWA7 != 'y' ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
IPSWA7=1
|
|
|
|
Log "Custom IPSW option enabled by user."
|
|
|
|
futurerestore="./resources/tools/futurerestore194_$platform"
|
|
|
|
if [[ ! -e $futurerestore ]]; then
|
|
|
|
cd tmp
|
|
|
|
SaveFile ${fr194[0]} futurerestore.tar.xz ${fr194[1]}
|
|
|
|
7z x futurerestore.tar.xz
|
|
|
|
tar -xf futurerestore*.tar
|
|
|
|
chmod +x futurerestore-v194
|
|
|
|
mv futurerestore-v194 ../$futurerestore
|
|
|
|
cd ..
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-28 12:21:26 +02:00
|
|
|
Downgrade() {
|
|
|
|
Log "Select your options when asked. If unsure, go for the defaults (press Enter/Return)."
|
|
|
|
echo
|
2022-07-02 06:54:18 +02:00
|
|
|
|
|
|
|
if [[ $DeviceProc == 7 && $platform != "win" ]]; then
|
|
|
|
IPSWCustomA7
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $platform == "win" || $IPSWA7 == 1 ]]; then
|
2022-05-29 16:57:53 +02:00
|
|
|
DowngradeOTAWin
|
|
|
|
return
|
|
|
|
elif [[ $OSVer == "Other" ]]; then
|
2022-05-28 12:21:26 +02:00
|
|
|
DowngradeOther
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
DowngradeOTA
|
|
|
|
}
|
2022-05-28 12:56:10 +02:00
|
|
|
|
|
|
|
iDeviceRestore() {
|
2022-05-29 16:57:53 +02:00
|
|
|
mkdir shsh
|
|
|
|
cp $SHSH shsh/${UniqueChipID}-${ProductType}-${OSVer}.shsh
|
2022-05-28 12:56:10 +02:00
|
|
|
Log "Proceeding to idevicerestore..."
|
|
|
|
[[ $platform == "macos" ]] && sudo codesign --sign - --force --deep $idevicerestore
|
2022-07-17 04:24:12 +02:00
|
|
|
[[ $1 == "latest" ]] && ExtraArgs="-e" || ExtraArgs="-e -w"
|
|
|
|
[[ $platform == "win" ]] && ExtraArgs="-ewy"
|
2022-05-28 12:56:10 +02:00
|
|
|
$idevicerestore $ExtraArgs "$IPSWRestore.ipsw"
|
|
|
|
if [[ $platform == "macos" && $? != 0 ]]; then
|
2022-06-16 18:13:54 +02:00
|
|
|
Log "Restoring done! Read the message below if any error has occurred:"
|
2022-06-05 03:14:07 +02:00
|
|
|
Echo "* If the \"Killed: 9\" or other similar error pops up, try these steps:"
|
2022-05-28 12:56:10 +02:00
|
|
|
Echo "* Using Terminal, cd to where the script is located, then run"
|
|
|
|
Echo "* sudo codesign --sign - --force --deep resources/tools/idevicerestore_macos"
|
2022-06-05 03:14:07 +02:00
|
|
|
Echo "* For more details, read the \"Troubleshooting\" wiki page in GitHub"
|
2022-05-29 16:57:53 +02:00
|
|
|
elif [[ $platform == "win" && $? != 0 ]]; then
|
2022-06-16 18:13:54 +02:00
|
|
|
Log "Restoring done! Read the message below if any error has occurred:"
|
2022-05-29 16:57:53 +02:00
|
|
|
Echo "* Windows users may encounter errors like \"Unable to send APTicket\" or \"Unable to send iBEC\" in the restore process."
|
2022-06-05 03:14:07 +02:00
|
|
|
Echo "* To fix this, follow troubleshooting steps from here: https://github.com/LukeZGD/iOS-OTA-Downgrader/wiki/Troubleshooting#windows"
|
2022-05-28 12:56:10 +02:00
|
|
|
else
|
|
|
|
echo
|
|
|
|
Log "Restoring done!"
|
|
|
|
fi
|
|
|
|
Log "Downgrade script done!"
|
|
|
|
}
|
|
|
|
|
|
|
|
Downgrade4() {
|
|
|
|
JailbreakOption
|
|
|
|
IPSWFindVerify
|
|
|
|
Save712Blobs
|
|
|
|
if [[ $OSVer == "7.1.2" && $Jailbreak != 1 ]]; then
|
|
|
|
IPSWSetExtract
|
|
|
|
iDeviceRestore latest
|
|
|
|
return
|
2022-07-03 03:51:54 +02:00
|
|
|
elif [[ $OSVer != "7.1.2" ]]; then
|
2022-05-28 12:56:10 +02:00
|
|
|
IPSWFindVerify 712
|
|
|
|
fi
|
|
|
|
IPSW4
|
|
|
|
IPSWSetExtract
|
|
|
|
iDeviceRestore
|
|
|
|
}
|