This commit is contained in:
LukeeGD 2020-07-30 23:09:34 +08:00
parent 64e143db0e
commit e9613200d9
5 changed files with 30 additions and 53 deletions

View File

@ -6,8 +6,9 @@ function Clean {
} }
function Error { function Error {
echo "[Error] $1" echo -e "\n[Error] $1"
[[ ! -z $2 ]] && echo "* $2" [[ ! -z $2 ]] && echo "* $2"
echo
exit exit
} }
@ -20,27 +21,18 @@ function Main {
echo "******* iOS-OTA-Downgrader *******" echo "******* iOS-OTA-Downgrader *******"
echo " Downgrader script by LukeZGD " echo " Downgrader script by LukeZGD "
echo echo
if [[ $OSTYPE == "linux-gnu" ]]; then [[ $OSTYPE == "linux-gnu" ]] && platform='linux'
platform='linux' [[ $OSTYPE == "darwin"* ]] && platform='macos'
elif [[ $OSTYPE == "darwin"* ]]; then [[ ! $platform ]] && Error "OSTYPE unknown/not supported." "Supports Linux and macOS only"
platform='macos'
else
Error "OSTYPE unknown/not supported." "Supports Linux and macOS only"
fi
[[ ! $(ping -c1 google.com 2>/dev/null) ]] && Error "Please check your Internet connection before proceeding." [[ ! $(ping -c1 google.com 2>/dev/null) ]] && Error "Please check your Internet connection before proceeding."
[[ $(uname -m) != 'x86_64' ]] && Error "Only x86_64 distributions are supported. Use a 64-bit distro and try again" [[ $(uname -m) != 'x86_64' ]] && Error "Only x86_64 distributions are supported. Use a 64-bit distro and try again"
futurerestore152="sudo LD_PRELOAD=libcurl.so.3 resources/tools/futurerestore152_$platform" futurerestore1="sudo LD_PRELOAD=libcurl.so.3 resources/tools/futurerestore1_$platform"
futurerestore249="sudo LD_LIBRARY_PATH=/usr/local/lib resources/tools/futurerestore249_$platform" futurerestore2="sudo LD_LIBRARY_PATH=/usr/local/lib resources/tools/futurerestore2_$platform"
irecovery="sudo LD_LIBRARY_PATH=/usr/local/lib irecovery" irecovery="sudo LD_LIBRARY_PATH=/usr/local/lib irecovery"
pzb="resources/tools/pzb_$platform" pzb="resources/tools/pzb_$platform"
tsschecker="env LD_LIBRARY_PATH=/usr/local/lib resources/tools/tsschecker_$platform" tsschecker="env LD_LIBRARY_PATH=/usr/local/lib resources/tools/tsschecker_$platform"
chmod +x resources/tools/*
mkdir tmp
SaveExternal iOS-OTA-Downgrader-Keys
SaveExternal ipwndfu
DFUDevice=$(lsusb | grep -c '1227') DFUDevice=$(lsusb | grep -c '1227')
RecoveryDevice=$(lsusb | grep -c '1281') RecoveryDevice=$(lsusb | grep -c '1281')
if [[ $1 == InstallDependencies ]] || [ ! $(which bspatch) ] || [ ! $(which ideviceinfo) ] || if [[ $1 == InstallDependencies ]] || [ ! $(which bspatch) ] || [ ! $(which ideviceinfo) ] ||
@ -65,8 +57,11 @@ function Main {
BasebandDetect BasebandDetect
Clean Clean
mkdir tmp mkdir tmp
chmod +x resources/tools/*
SaveExternal iOS-OTA-Downgrader-Keys
SaveExternal ipwndfu
if [ $DFUDevice == 1 ] && [[ $A7Device != 1 ]]; then if [[ $DFUDevice == 1 ]] && [[ $A7Device != 1 ]]; then
Log "Device in DFU mode detected." Log "Device in DFU mode detected."
read -p "[Input] Is this a 32-bit device in kDFU mode? (y/N) " DFUManual read -p "[Input] Is this a 32-bit device in kDFU mode? (y/N) " DFUManual
if [[ $DFUManual == y ]] || [[ $DFUManual == Y ]]; then if [[ $DFUManual == y ]] || [[ $DFUManual == Y ]]; then
@ -76,10 +71,11 @@ function Main {
else else
Error "Please put the device in normal mode (and jailbroken for 32-bit) before proceeding." "Recovery or DFU mode is also applicable for A7 devices" Error "Please put the device in normal mode (and jailbroken for 32-bit) before proceeding." "Recovery or DFU mode is also applicable for A7 devices"
fi fi
elif [ $RecoveryDevice == 1 ] && [[ $A7Device != 1 ]]; then elif [[ $RecoveryDevice == 1 ]] && [[ $A7Device != 1 ]]; then
Error "Non-A7 device detected in recovery mode. Please put the device in normal mode and jailbroken before proceeding" Error "Non-A7 device detected in recovery mode. Please put the device in normal mode and jailbroken before proceeding"
fi fi
echo "* Platform: $platform"
echo "* HardwareModel: ${HWModel}ap" echo "* HardwareModel: ${HWModel}ap"
echo "* ProductType: $ProductType" echo "* ProductType: $ProductType"
echo "* ProductVersion: $ProductVer" echo "* ProductVersion: $ProductVer"
@ -98,7 +94,7 @@ function Main {
"Downgrade device" ) Mode='Downgrade'; break;; "Downgrade device" ) Mode='Downgrade'; break;;
"Save OTA blobs" ) Mode='SaveOTABlobs'; break;; "Save OTA blobs" ) Mode='SaveOTABlobs'; break;;
"Just put device in kDFU mode" ) Mode='kDFU'; break;; "Just put device in kDFU mode" ) Mode='kDFU'; break;;
"(Re-)Install Dependencies" ) InstallDependencies; exit;; "(Re-)Install Dependencies" ) InstallDependencies;;
* ) exit;; * ) exit;;
esac esac
done done
@ -142,11 +138,7 @@ function Action {
IPSW="$(basename $IPSW .ipsw)" IPSW="$(basename $IPSW .ipsw)"
read -p "[Input] Path to SHSH (drag SHSH to terminal window): " SHSH read -p "[Input] Path to SHSH (drag SHSH to terminal window): " SHSH
elif [[ $A7Device == 1 ]] && [[ $pwnDFUDevice != 1 ]]; then elif [[ $A7Device == 1 ]] && [[ $pwnDFUDevice != 1 ]]; then
if [[ $DFUDevice == 1 ]]; then [[ $DFUDevice == 1 ]] && CheckM8 || Recovery
CheckM8
else
Recovery
fi
fi fi
if [ $ProductType == iPod5,1 ]; then if [ $ProductType == iPod5,1 ]; then
@ -209,13 +201,9 @@ function kDFU {
bspatch tmp/iBSS.dec tmp/pwnediBSS resources/patches/$iBSS.patch bspatch tmp/iBSS.dec tmp/pwnediBSS resources/patches/$iBSS.patch
# Regular kloader only works on iOS 6 to 9, so other versions are provided for iOS 5 and 10 # Regular kloader only works on iOS 6 to 9, so other versions are provided for iOS 5 and 10
if [[ $VersionDetect == 1 ]]; then [[ $VersionDetect == 1 ]] && kloader='kloader_hgsp'
kloader='kloader_hgsp' [[ $VersionDetect == 5 ]] && kloader='kloader5'
elif [[ $VersionDetect == 5 ]]; then [[ ! $kloader ]] && kloader='kloader'
kloader='kloader5'
else
kloader='kloader'
fi
if [[ $VersionDetect == 1 ]]; then if [[ $VersionDetect == 1 ]]; then
# ifuse+MTerminal is used instead of SSH for devices on iOS 10 # ifuse+MTerminal is used instead of SSH for devices on iOS 10
@ -224,7 +212,6 @@ function kDFU {
WifiAddrDecr=$(echo $(printf "%x\n" $(expr $(printf "%d\n" 0x$(echo "${WifiAddr}" | tr -d ':')) - 1)) | sed 's/\(..\)/\1:/g;s/:$//') WifiAddrDecr=$(echo $(printf "%x\n" $(expr $(printf "%d\n" 0x$(echo "${WifiAddr}" | tr -d ':')) - 1)) | sed 's/\(..\)/\1:/g;s/:$//')
echo '#!/bin/bash' > tmp/pwn.sh echo '#!/bin/bash' > tmp/pwn.sh
echo "nvram wifiaddr=$WifiAddrDecr echo "nvram wifiaddr=$WifiAddrDecr
chmod 755 kloader_hgsp
./kloader_hgsp pwnediBSS" >> tmp/pwn.sh ./kloader_hgsp pwnediBSS" >> tmp/pwn.sh
Log "Mounting device with ifuse..." Log "Mounting device with ifuse..."
mkdir mount mkdir mount
@ -240,7 +227,6 @@ function kDFU {
echo '$ su' echo '$ su'
echo "* (Enter root password of your iOS device, default is 'alpine')" echo "* (Enter root password of your iOS device, default is 'alpine')"
echo "# cd Media" echo "# cd Media"
echo "# chmod +x pwn.sh"
echo "# ./pwn.sh" echo "# ./pwn.sh"
else else
# SSH kloader and pwnediBSS # SSH kloader and pwnediBSS
@ -254,7 +240,7 @@ function kDFU {
scp resources/tools/$kloader tmp/pwnediBSS root@$IPAddress:/ scp resources/tools/$kloader tmp/pwnediBSS root@$IPAddress:/
[ $? == 1 ] && Error "Cannot connect to device via SSH." "Please check your ~/.ssh/known_hosts file and try again" [ $? == 1 ] && Error "Cannot connect to device via SSH." "Please check your ~/.ssh/known_hosts file and try again"
Log "Entering kDFU mode..." Log "Entering kDFU mode..."
ssh root@$IPAddress "chmod 755 /$kloader && /$kloader /pwnediBSS" & ssh root@$IPAddress "/$kloader /pwnediBSS" &
fi fi
echo echo
echo "* Press POWER or HOME button when screen goes black on the device" echo "* Press POWER or HOME button when screen goes black on the device"
@ -296,8 +282,7 @@ function Recovery {
[[ $DFUDevice == 1 ]] && CheckM8 [[ $DFUDevice == 1 ]] && CheckM8
sleep 1 sleep 1
done done
echo -e "\n[Error] Failed to detect device in DFU mode. Please run the script again" Error "Failed to detect device in DFU mode. Please run the script again"
exit
} }
function CheckM8 { function CheckM8 {
@ -321,14 +306,9 @@ function CheckM8 {
function Downgrade { function Downgrade {
if [[ $OSVer != 'Other' ]]; then if [[ $OSVer != 'Other' ]]; then
if [[ $ProductType == iPad4* ]]; then [[ $ProductType == iPad4* ]] && IPSW="iPad_64bit"
IPSW="iPad_64bit" [[ $ProductType == iPhone6* ]] && IPSW="iPhone_64bit"
elif [[ $ProductType == iPhone6* ]]; then [[ ! $IPSW ]] && IPSW="$ProductType" && SaveOTABlobs
IPSW="iPhone_64bit"
else
IPSW="$ProductType"
SaveOTABlobs
fi
IPSW="${IPSW}_${OSVer}_${BuildVer}_Restore" IPSW="${IPSW}_${OSVer}_${BuildVer}_Restore"
IPSWCustom="${ProductType}_${OSVer}_${BuildVer}_Custom" IPSWCustom="${ProductType}_${OSVer}_${BuildVer}_Custom"
if [ ! -e $IPSW.ipsw ]; then if [ ! -e $IPSW.ipsw ]; then
@ -378,10 +358,7 @@ function Downgrade {
$irecovery -f $iBEC.im4p $irecovery -f $iBEC.im4p
sleep 5 sleep 5
RecoveryDevice=$(lsusb | grep -c '1281') RecoveryDevice=$(lsusb | grep -c '1281')
if [[ $RecoveryDevice != 1 ]]; then [[ $RecoveryDevice != 1 ]] && Error "Failed to detect device in PWNREC mode. Please try again"
echo -e "\n[Error] Failed to detect device in PWNREC mode. Please try again"
exit
fi
SaveOTABlobs SaveOTABlobs
fi fi
@ -394,9 +371,9 @@ function Downgrade {
Log "Device $ProductType has no baseband" Log "Device $ProductType has no baseband"
Log "Proceeding to futurerestore..." Log "Proceeding to futurerestore..."
if [[ $A7Device == 1 ]]; then if [[ $A7Device == 1 ]]; then
$futurerestore249 -t $SHSH -s $SEP -m $BuildManifest --no-baseband $IPSW.ipsw $futurerestore2 -t $SHSH -s $SEP -m $BuildManifest --no-baseband $IPSW.ipsw
else else
$futurerestore152 -t $SHSH --no-baseband --use-pwndfu $IPSW.ipsw $futurerestore1 -t $SHSH --no-baseband --use-pwndfu $IPSW.ipsw
fi fi
else else
if [[ $A7Device == 1 ]]; then if [[ $A7Device == 1 ]]; then
@ -420,14 +397,14 @@ function Downgrade {
echo "* Proceeding to futurerestore in 10 seconds (Press Ctrl+C to cancel)" echo "* Proceeding to futurerestore in 10 seconds (Press Ctrl+C to cancel)"
sleep 10 sleep 10
if [[ $A7Device == 1 ]]; then if [[ $A7Device == 1 ]]; then
$futurerestore249 -t $SHSH -s $SEP -m $BuildManifest --latest-baseband $IPSW.ipsw $futurerestore2 -t $SHSH -s $SEP -m $BuildManifest --latest-baseband $IPSW.ipsw
else else
$futurerestore152 -t $SHSH --latest-baseband --use-pwndfu $IPSW.ipsw $futurerestore1 -t $SHSH --latest-baseband --use-pwndfu $IPSW.ipsw
fi fi
elif [[ $A7Device == 1 ]]; then elif [[ $A7Device == 1 ]]; then
$futurerestore249 -t $SHSH -s $SEP -m $BuildManifest -b $Baseband -p $BuildManifest $IPSW.ipsw $futurerestore2 -t $SHSH -s $SEP -m $BuildManifest -b $Baseband -p $BuildManifest $IPSW.ipsw
else else
$futurerestore152 -t $SHSH -b $Baseband -p BuildManifest.plist --use-pwndfu $IPSW.ipsw $futurerestore1 -t $SHSH -b $Baseband -p BuildManifest.plist --use-pwndfu $IPSW.ipsw
fi fi
fi fi