Legacy-iOS-Kit/resources/downgrade.sh

193 lines
6.5 KiB
Bash
Raw Normal View History

#!/bin/bash
FRBaseband() {
local BasebandSHA1L
if [[ $DeviceProc == 7 ]]; then
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
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
mv $Baseband saved/baseband
mv BuildManifest.plist saved/$ProductType
BuildManifest="saved/$ProductType/BuildManifest.plist"
elif [[ $DeviceProc != 7 ]]; then
BuildManifest="saved/$ProductType/BuildManifest.plist"
fi
2021-11-07 15:57:20 +01: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
fi
}
2022-05-28 12:21:26 +02:00
FutureRestore() {
local ExtraArgs=("--use-pwndfu")
2021-10-25 08:57:24 +02:00
Log "Proceeding to futurerestore..."
[[ $platform == "linux" ]] && Echo "* Enter your user password when prompted"
if [[ $platform != "win" ]]; then
cd resources
$SimpleHTTPServer &
ServerPID=$!
cd ..
fi
if [[ $DeviceProc == 7 && $platform != "win" ]]; then
# Send dummy file for device detection
$irecovery -f README.md
2021-10-26 05:32:59 +02:00
sleep 2
ExtraArgs+=("-s" "$IPSWRestore/Firmware/all_flash/$SEP" "-m" "$BuildManifest")
2022-05-28 12:21:26 +02:00
elif [[ $SendiBSS != 1 ]]; then
ExtraArgs+=("--no-ibss")
2021-10-26 05:32:59 +02:00
fi
if [[ $Baseband == 0 ]]; then
Log "Device $ProductType has no baseband"
2021-11-07 15:57:20 +01:00
ExtraArgs+=("--no-baseband")
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
fi
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"
if [[ $? != 0 ]]; then
Log "An error seems to have occurred in futurerestore."
Echo "* Please read the \"Troubleshooting\" wiki page in GitHub before opening any issue!"
Echo "* Your problem may have already been addressed within the wiki page."
Echo "* If opening an issue in GitHub, please provide a FULL log. Otherwise, your issue may be dismissed."
else
echo
Log "Restoring done!"
fi
Log "Downgrade script done!"
}
2022-05-28 12:21:26 +02:00
DowngradeOther() {
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"
if [[ ! -e resources/firmware/$ProductType/$BuildVer/index.html ]]; then
unzip -o -j "$IPSW.ipsw" Restore.plist -d tmp
BuildVer=$(cat tmp/Restore.plist | grep -i ProductBuildVersion -A 1 | grep -oPm1 "(?<=<string>)[^<]+")
Log "Getting firmware keys for $ProductType-$BuildVer"
mkdir -p resources/firmware/$ProductType/$BuildVer 2>/dev/null
curl -L https://github.com/LukeZGD/iOS-OTA-Downgrader-Keys/raw/master/$ProductType/$BuildVer/index.html -o tmp/index.html
mv tmp/index.html resources/firmware/$ProductType/$BuildVer
fi
kDFU
IPSWSetExtract
FutureRestore
}
DowngradeOTA() {
[[ $DeviceProc != 7 ]] && JailbreakOption
SaveOTABlobs
IPSWFindVerify
kDFU
[[ $Jailbreak == 1 ]] && IPSW32
IPSWSetExtract
FutureRestore
}
DowngradeOTAWin() {
IPSWCustom="${IPSWType}_${OSVer}_${BuildVer}_CustomWin"
if [[ $DeviceProc != 7 ]]; then
JailbreakOption
SaveOTABlobs
fi
IPSWFindVerify
if [[ $DeviceProc == 7 ]]; then
IPSWSetExtract extract
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-05-28 12:21:26 +02:00
Downgrade() {
Log "Select your options when asked. If unsure, go for the defaults (press Enter/Return)."
echo
if [[ $platform == "win" ]]; then
DowngradeOTAWin
return
elif [[ $OSVer == "Other" ]]; then
2022-05-28 12:21:26 +02:00
DowngradeOther
return
fi
DowngradeOTA
}
iDeviceRestore() {
mkdir shsh
cp $SHSH shsh/${UniqueChipID}-${ProductType}-${OSVer}.shsh
Log "Proceeding to idevicerestore..."
Echo "* Enter your user password when prompted"
[[ $platform == "macos" ]] && sudo codesign --sign - --force --deep $idevicerestore
[[ $1 == "latest" ]] && ExtraArgs="-ey" || ExtraArgs="-ewy"
$idevicerestore $ExtraArgs "$IPSWRestore.ipsw"
if [[ $platform == "macos" && $? != 0 ]]; then
Log "An error seems to have occurred in idevicerestore."
Echo "* If this is the \"Killed: 9\" error or similar, try these steps:"
Echo "* Using Terminal, cd to where the script is located, then run"
Echo "* sudo codesign --sign - --force --deep resources/tools/idevicerestore_macos"
elif [[ $platform == "win" && $? != 0 ]]; then
Log "An error seems to have occurred in idevicerestore."
Echo "* Windows users may encounter errors like \"Unable to send APTicket\" or \"Unable to send iBEC\" in the restore process."
Echo "* To fix this, follow troubleshooting steps here: https://github.com/LukeZGD/iOS-OTA-Downgrader/wiki/Troubleshooting#windows"
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
else
IPSWFindVerify 712
fi
IPSW4
IPSWSetExtract
iDeviceRestore
}