2019-11-22 11:48:41 +01:00
#!/bin/bash
2020-07-23 02:47:36 +02:00
trap 'Clean; exit' INT TERM EXIT
2020-09-01 04:25:27 +02:00
if [ [ $1 != 'NoColor' ] ] ; then
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
2019-11-22 11:48:41 +01:00
2020-07-23 02:47:36 +02:00
function Clean {
2020-09-17 05:04:34 +02:00
rm -rf iP*/ shsh/ tmp/ ${ UniqueChipID } _${ ProductType } _*.shsh2 ${ UniqueChipID } _${ ProductType } _${ HWModel } ap_*.shsh *.im4p *.bbfw BuildManifest.plist
2020-03-09 02:30:19 +01:00
}
2020-09-01 04:25:27 +02:00
function Echo {
echo " ${ Color_B } $1 ${ Color_N } "
}
2020-07-23 02:47:36 +02:00
function Error {
2020-09-01 04:25:27 +02:00
echo -e " \n ${ Color_R } [Error] $1 ${ Color_N } "
[ [ ! -z $2 ] ] && echo " ${ Color_R } * $2 ${ Color_N } "
2020-07-30 17:09:34 +02:00
echo
2020-07-23 02:47:36 +02:00
exit
2020-03-09 02:30:19 +01:00
}
2020-09-01 04:25:27 +02:00
function Input {
echo " ${ Color_Y } [Input] $1 ${ Color_N } "
}
2020-04-01 04:49:55 +02:00
function Log {
2020-09-01 04:25:27 +02:00
echo " ${ Color_G } [Log] $1 ${ Color_N } "
2020-04-01 04:49:55 +02:00
}
2020-07-23 02:47:36 +02:00
function Main {
clear
2020-09-01 04:25:27 +02:00
Echo "******* iOS-OTA-Downgrader *******"
Echo " Downgrader script by LukeZGD "
2020-07-23 02:47:36 +02:00
echo
2020-07-27 15:42:41 +02:00
2020-08-14 05:57:20 +02:00
if [ [ $OSTYPE = = "linux-gnu" ] ] ; then
2020-10-06 11:12:16 +02:00
. /etc/os-release 2>/dev/null
2020-09-07 09:55:38 +02:00
platform = "linux"
2020-08-14 05:57:20 +02:00
bspatch = "bspatch"
ideviceenterrecovery = "ideviceenterrecovery"
ideviceinfo = "ideviceinfo"
2020-09-15 12:25:37 +02:00
idevicerestore = "sudo LD_LIBRARY_PATH=resources/lib resources/tools/idevicerestore_linux"
2020-08-14 05:57:20 +02:00
iproxy = "iproxy"
2020-09-16 16:13:48 +02:00
ipsw = "env LD_LIBRARY_PATH=lib tools/ipsw_linux"
irecoverychk = "resources/libirecovery/bin/irecovery"
irecovery = " sudo LD_LIBRARY_PATH=resources/lib $irecoverychk "
2020-09-15 12:25:37 +02:00
pwnedDFU = "sudo LD_LIBRARY_PATH=resources/lib resources/tools/pwnedDFU_linux"
2020-08-14 05:57:20 +02:00
python = "python2"
2020-08-16 09:09:55 +02:00
futurerestore1 = "sudo LD_PRELOAD=resources/lib/libcurl.so.3 LD_LIBRARY_PATH=resources/lib resources/tools/futurerestore1_linux"
futurerestore2 = "sudo LD_LIBRARY_PATH=resources/lib resources/tools/futurerestore2_linux"
tsschecker = "env LD_LIBRARY_PATH=resources/lib resources/tools/tsschecker_linux"
2020-10-06 04:47:44 +02:00
if [ [ $UBUNTU_CODENAME = = "bionic" ] ] ; then
futurerestore2 = " ${ futurerestore2 } _bionic "
idevicerestore = " ${ idevicerestore } _bionic "
2020-10-19 06:17:49 +02:00
elif [ [ $UBUNTU_CODENAME = = "xenial" ] ] ; then
futurerestore2 = " ${ futurerestore2 } _xenial "
idevicerestore = " ${ idevicerestore } _xenial "
partialzip = " ${ partialzip } _xenial "
tsschecker = " ${ tsschecker } _xenial "
2020-10-06 04:47:44 +02:00
fi
2020-09-02 16:14:36 +02:00
2020-09-02 07:46:55 +02:00
elif [ [ $OSTYPE = = "darwin" * ] ] ; then
2020-10-08 10:00:18 +02:00
macver = ${ 1 :- $( sw_vers -productVersion) }
2020-09-07 09:55:38 +02:00
platform = "macos"
2020-08-25 08:42:57 +02:00
bspatch = " resources/tools/bspatch_ $platform "
ideviceenterrecovery = " resources/libimobiledevice_ $platform /ideviceenterrecovery "
ideviceinfo = " resources/libimobiledevice_ $platform /ideviceinfo "
2020-09-15 12:25:37 +02:00
idevicerestore = " resources/tools/idevicerestore_ $platform "
2020-08-25 08:42:57 +02:00
iproxy = " resources/libimobiledevice_ $platform /iproxy "
2020-09-15 12:25:37 +02:00
ipsw = " tools/ipsw_ $platform "
2020-08-25 08:42:57 +02:00
irecovery = " resources/libimobiledevice_ $platform /irecovery "
2020-09-16 16:13:48 +02:00
irecoverychk = $irecovery
2020-09-13 14:51:26 +02:00
pwnedDFU = " resources/tools/pwnedDFU_ $platform "
2020-08-14 05:57:20 +02:00
python = "python"
2020-08-25 08:42:57 +02:00
futurerestore1 = " resources/tools/futurerestore1_ $platform "
futurerestore2 = " resources/tools/futurerestore2_ $platform "
tsschecker = " resources/tools/tsschecker_ $platform "
2020-08-14 05:57:20 +02:00
fi
2020-08-16 13:25:32 +02:00
partialzip = " resources/tools/partialzip_ $platform "
2020-07-27 13:27:46 +02:00
2020-09-16 16:13:48 +02:00
[ [ ! -d resources ] ] && Error "resources folder cannot be found. Replace resources folder and try again" "If resources folder is present try removing spaces from path/folder name"
2020-08-25 08:42:57 +02:00
[ [ ! $platform ] ] && Error "Platform unknown/not supported."
2020-09-16 16:13:48 +02:00
chmod +x resources/tools/*
[ $? = = 1 ] && Log "An error occurred in chmod. This might cause problems..."
2020-10-19 05:39:30 +02:00
[ [ ! $( ping -c1 8.8.8.8 2>/dev/null) ] ] && Error "Please check your Internet connection before proceeding."
2020-08-14 05:57:20 +02:00
[ [ $( uname -m) != 'x86_64' ] ] && Error "Only x86_64 distributions are supported. Use a 64-bit distro and try again"
2020-09-16 16:13:48 +02:00
if [ [ $1 = = Install ] ] || [ ! $( which $irecoverychk ) ] || [ ! $( which $ideviceinfo ) ] ||
[ ! $( which git) ] || [ ! $( which $bspatch ) ] || [ ! $( which $python ) ] ; then
2020-09-17 05:04:34 +02:00
cd resources
rm -rf firmware ipwndfu libimobiledevice_$platform libirecovery
cd ..
2020-07-23 02:47:36 +02:00
InstallDependencies
2020-09-10 11:20:46 +02:00
fi
SaveExternal iOS-OTA-Downgrader-Keys
SaveExternal ipwndfu
2020-09-16 10:43:31 +02:00
Log "Finding device in normal mode..."
2020-09-10 11:37:53 +02:00
ideviceinfo2 = $( $ideviceinfo -s)
2020-09-16 10:46:46 +02:00
if [ [ $? != 0 ] ] ; then
Log "Finding device in DFU/recovery mode..."
irecovery2 = $( $irecovery -q 2>/dev/null | grep 'MODE' | cut -c 7-)
fi
2020-09-10 11:20:46 +02:00
[ [ $irecovery2 = = "DFU" ] ] && DFUDevice = 1
[ [ $irecovery2 = = "Recovery" ] ] && RecoveryDevice = 1
if [ [ $DFUDevice = = 1 ] ] || [ [ $RecoveryDevice = = 1 ] ] ; then
2020-09-06 09:57:01 +02:00
ProductType = $( $irecovery -q | grep 'PTYP' | cut -c 7-)
2020-07-23 14:08:16 +02:00
[ ! $ProductType ] && read -p "[Input] Enter ProductType (eg. iPad2,1): " ProductType
2020-08-30 15:42:24 +02:00
UniqueChipID = $(( 16# $( echo $( $irecovery -q | grep 'ECID' | cut -c 7-) | cut -c 3-) ))
2020-07-23 04:08:46 +02:00
ProductVer = 'Unknown'
2020-07-23 02:47:36 +02:00
else
2020-08-14 05:57:20 +02:00
ProductType = $( echo " $ideviceinfo2 " | grep 'ProductType' | cut -c 14-)
[ ! $ProductType ] && ProductType = $( $ideviceinfo | grep 'ProductType' | cut -c 14-)
ProductVer = $( echo " $ideviceinfo2 " | grep 'ProductVer' | cut -c 17-)
2020-07-23 02:47:36 +02:00
VersionDetect = $( echo $ProductVer | cut -c 1)
2020-08-14 05:57:20 +02:00
UniqueChipID = $( echo " $ideviceinfo2 " | grep 'UniqueChipID' | cut -c 15-)
UniqueDeviceID = $( echo " $ideviceinfo2 " | grep 'UniqueDeviceID' | cut -c 17-)
2020-07-23 02:47:36 +02:00
fi
2020-07-27 15:42:41 +02:00
[ ! $ProductType ] && ProductType = 0
2020-07-23 04:08:46 +02:00
BasebandDetect
2020-07-27 15:42:41 +02:00
Clean
mkdir tmp
2020-07-23 02:47:36 +02:00
2020-10-08 10:00:18 +02:00
Echo " * Platform: $platform $macver "
2020-09-01 04:25:27 +02:00
Echo " * HardwareModel: ${ HWModel } ap "
Echo " * ProductType: $ProductType "
Echo " * ProductVersion: $ProductVer "
Echo " * UniqueChipID (ECID): $UniqueChipID "
2020-08-22 03:52:58 +02:00
echo
2020-09-02 07:46:55 +02:00
if [ [ $DFUDevice = = 1 ] ] && [ [ $A7Device != 1 ] ] ; then
2020-08-16 06:23:07 +02:00
DFUManual = 1
2020-08-12 16:05:51 +02:00
Mode = 'Downgrade'
Log "32-bit device in DFU mode detected."
2020-09-01 04:25:27 +02:00
Echo "* Advanced options menu - use at your own risk"
Echo "* Warning: A6 devices won't have activation error workaround yet when using this method"
Input "This device is in:"
2020-08-16 06:23:07 +02:00
select opt in "kDFU mode" "DFU mode (ipwndfu A6)" "pwnDFU mode (checkm8 A5)" "(Any other key to exit)" ; do
2020-08-12 16:05:51 +02:00
case $opt in
2020-08-22 03:52:58 +02:00
"kDFU mode" ) break; ;
2020-08-16 06:23:07 +02:00
"DFU mode (ipwndfu A6)" ) CheckM8; break; ;
"pwnDFU mode (checkm8 A5)" ) kDFU iBSS; break; ;
2020-08-12 16:05:51 +02:00
* ) exit; ;
esac
done
2020-08-22 03:52:58 +02:00
Log " Downgrading $ProductType in kDFU/pwnDFU mode... "
2020-08-12 16:05:51 +02:00
SelectVersion
2020-07-30 17:09:34 +02:00
elif [ [ $RecoveryDevice = = 1 ] ] && [ [ $A7Device != 1 ] ] ; then
2020-09-07 09:55:38 +02:00
read -p " $( Input 'Is this an A6 device in recovery mode? (y/N) ' ) " DFUManual
if [ [ $DFUManual = = y ] ] || [ [ $DFUManual = = Y ] ] ; then
Recovery
else
Error "32-bit device detected in recovery mode. Please put the device in normal mode and jailbroken before proceeding" "For usage of 32-bit ipwndfu, put the device in Recovery/DFU mode (A6) or pwnDFU mode (A5 using Arduino)"
fi
2020-03-05 12:48:41 +01:00
fi
2020-03-10 03:55:04 +01:00
2020-09-01 04:25:27 +02:00
if [ [ $1 ] ] && [ [ $1 != 'NoColor' ] ] ; then
2020-07-23 04:08:46 +02:00
Mode = " $1 "
else
Selection = ( "Downgrade device" )
[ [ $A7Device != 1 ] ] && Selection += ( "Save OTA blobs" "Just put device in kDFU mode" )
Selection += ( "(Re-)Install Dependencies" "(Any other key to exit)" )
2020-09-01 04:25:27 +02:00
Echo "*** Main Menu ***"
Input "Select an option:"
2020-07-23 04:08:46 +02:00
select opt in " ${ Selection [@] } " ; do
case $opt in
"Downgrade device" ) Mode = 'Downgrade' ; break; ;
"Save OTA blobs" ) Mode = 'SaveOTABlobs' ; break; ;
"Just put device in kDFU mode" ) Mode = 'kDFU' ; break; ;
2020-07-30 17:09:34 +02:00
"(Re-)Install Dependencies" ) InstallDependencies; ;
2020-07-23 04:08:46 +02:00
* ) exit; ;
esac
done
fi
2020-03-31 07:46:59 +02:00
SelectVersion
2020-03-05 12:48:41 +01:00
}
function SelectVersion {
2020-07-23 02:47:36 +02:00
if [ [ $ProductType = = iPad4* ] ] || [ [ $ProductType = = iPhone6* ] ] ; then
OSVer = '10.3.3'
BuildVer = '14G60'
2020-06-14 07:39:26 +02:00
Action
2020-07-27 14:07:21 +02:00
elif [ [ $Mode = = 'kDFU' ] ] ; then
Action
2020-07-23 02:47:36 +02:00
fi
2020-09-23 06:46:35 +02:00
Selection = ( "iOS 8.4.1" )
2020-07-23 02:47:36 +02:00
if [ $ProductType = = iPad2,1 ] || [ $ProductType = = iPad2,2 ] ||
[ $ProductType = = iPad2,3 ] || [ $ProductType = = iPhone4,1 ] ; then
2020-09-16 08:50:12 +02:00
Selection += ( "iOS 6.1.3" )
2020-03-05 12:48:41 +01:00
fi
2020-04-01 04:16:29 +02:00
[ [ $Mode = = 'Downgrade' ] ] && Selection += ( "Other" )
2020-07-27 13:27:46 +02:00
Selection += ( "(Any other key to exit)" )
2020-09-01 04:25:27 +02:00
Input "Select iOS version:"
2020-04-01 04:16:29 +02:00
select opt in " ${ Selection [@] } " ; do
case $opt in
2020-06-14 07:39:26 +02:00
"iOS 8.4.1" ) OSVer = '8.4.1' ; BuildVer = '12H321' ; break; ;
"iOS 6.1.3" ) OSVer = '6.1.3' ; BuildVer = '10B329' ; break; ;
"Other" ) OSVer = 'Other' ; break; ;
2020-07-23 02:47:36 +02:00
*) exit; ;
2020-04-01 04:16:29 +02:00
esac
done
2020-03-05 12:48:41 +01:00
Action
}
2020-09-17 05:04:34 +02:00
function Action {
2020-07-07 05:50:26 +02:00
Log " Option: $Mode "
if [ [ $OSVer = = 'Other' ] ] ; then
2020-09-01 04:25:27 +02:00
Echo "* Move/copy the IPSW and SHSH to the directory where the script is located"
2020-10-22 14:28:31 +02:00
Echo "* Remember to create a backup of the SHSH"
2020-09-01 04:25:27 +02:00
read -p " $( Input 'Path to IPSW (drag IPSW to terminal window): ' ) " IPSW
2020-07-13 15:27:43 +02:00
IPSW = " $( basename $IPSW .ipsw) "
2020-09-01 04:25:27 +02:00
read -p " $( Input 'Path to SHSH (drag SHSH to terminal window): ' ) " SHSH
2020-09-19 16:41:16 +02:00
elif [ [ $Mode = = 'Downgrade' ] ] && [ [ $A7Device != 1 ] ] ; then
read -p " $( Input 'Jailbreak the selected iOS version? (y/N): ' ) " Jailbreak
[ [ $Jailbreak = = y ] ] || [ [ $Jailbreak = = Y ] ] && Jailbreak = 1
2020-09-10 10:28:52 +02:00
elif [ [ $A7Device = = 1 ] ] && [ [ $pwnDFUDevice != 0 ] ] ; then
2020-07-30 17:09:34 +02:00
[ [ $DFUDevice = = 1 ] ] && CheckM8 || Recovery
2020-06-14 07:39:26 +02:00
fi
2020-10-22 07:16:51 +02:00
if [ [ $Mode = = 'Downgrade' ] ] && [ [ $ProductType = = iPhone5,1 ] ] && [ [ $Jailbreak != 1 ] ] ; then
2020-10-22 14:28:31 +02:00
Echo "By default, iOS-OTA-Downgrader now flashes the iOS 8.4.1 baseband to iPhone5,1"
2020-10-22 07:16:51 +02:00
Echo "Flashing the latest baseband is still available as an option but beware of problems it may cause"
Echo "There are potential network issues that with the latest baseband when used on iOS 8.4.1"
read -p " $( Input 'Flash the latest baseband? (y/N) (press ENTER when unsure): ' ) " Baseband5
if [ [ $Baseband5 = = y ] ] || [ [ $Baseband5 = = Y ] ] ; then
Baseband5 = 0
else
BasebandURL = $( cat $Firmware /12H321/url)
Baseband = Mav5-8.02.00.Release.bbfw
BasebandSHA1 = db71823841ffab5bb41341576e7adaaeceddef1c
fi
fi
2020-07-27 15:42:41 +02:00
[ [ $Mode = = 'Downgrade' ] ] && Downgrade
[ [ $Mode = = 'SaveOTABlobs' ] ] && SaveOTABlobs
[ [ $Mode = = 'kDFU' ] ] && kDFU
2020-04-01 05:17:19 +02:00
exit
2019-11-22 11:48:41 +01:00
}
2019-11-23 05:15:35 +01:00
function SaveOTABlobs {
2020-05-05 09:05:49 +02:00
Log " Saving $OSVer blobs with tsschecker... "
2020-07-23 02:47:36 +02:00
BuildManifest = " resources/manifests/BuildManifest_ ${ ProductType } _ ${ OSVer } .plist "
2020-07-25 05:23:31 +02:00
if [ [ $A7Device = = 1 ] ] ; then
2020-07-27 13:27:46 +02:00
APNonce = $( $irecovery -q | grep 'NONC' | cut -c 7-)
2020-09-01 04:25:27 +02:00
Echo " * APNonce: $APNonce "
2020-07-27 13:27:46 +02:00
$tsschecker -d $ProductType -B ${ HWModel } ap -i $OSVer -e $UniqueChipID -m $BuildManifest --apnonce $APNonce -o -s
2020-09-17 05:04:34 +02:00
SHSHChk = ${ UniqueChipID } _${ ProductType } _${ HWModel } ap_${ OSVer } -${ BuildVer } _${ APNonce } .shsh
2020-07-23 02:47:36 +02:00
else
2020-07-27 13:27:46 +02:00
$tsschecker -d $ProductType -i $OSVer -e $UniqueChipID -m $BuildManifest -o -s
2020-09-17 05:04:34 +02:00
SHSHChk = ${ UniqueChipID } _${ ProductType } _${ OSVer } -${ BuildVer } _*.shsh2
2020-07-23 02:47:36 +02:00
fi
2020-09-17 05:04:34 +02:00
SHSH = $( ls $SHSHChk )
2020-07-23 02:47:36 +02:00
[ ! $SHSH ] && Error " Saving $OSVer blobs failed. Please run the script again " " It is also possible that $OSVer for $ProductType is no longer signed "
2020-03-29 05:53:53 +02:00
mkdir -p saved/shsh 2>/dev/null
2020-09-17 05:04:34 +02:00
[ [ ! $( ls saved/shsh/$SHSHChk 2>/dev/null) ] ] && cp " $SHSH " saved/shsh
2020-05-05 09:05:49 +02:00
Log " Successfully saved $OSVer blobs. "
2019-11-23 05:15:35 +01:00
}
2020-03-05 12:48:41 +01:00
function kDFU {
2020-03-29 07:05:45 +02:00
if [ ! -e saved/$ProductType /$iBSS .dfu ] ; then
2020-04-01 04:49:55 +02:00
Log "Downloading iBSS..."
2020-08-16 13:25:32 +02:00
$partialzip $( cat $Firmware /$iBSSBuildVer /url) Firmware/dfu/$iBSS .dfu $iBSS .dfu
2020-03-29 05:53:53 +02:00
mkdir -p saved/$ProductType 2>/dev/null
mv $iBSS .dfu saved/$ProductType
2020-03-10 03:55:04 +01:00
fi
2020-08-05 05:07:28 +02:00
[ [ ! -e saved/$ProductType /$iBSS .dfu ] ] && Error "Failed to save iBSS. Please run the script again"
2020-04-01 04:49:55 +02:00
Log "Patching iBSS..."
2020-08-14 05:57:20 +02:00
$bspatch saved/$ProductType /$iBSS .dfu tmp/pwnediBSS resources/patches/$iBSS .patch
2020-03-13 05:12:49 +01:00
2020-08-12 16:05:51 +02:00
if [ [ $1 = = iBSS ] ] ; then
2020-10-30 01:46:33 +01:00
cd resources/ipwndfu
2020-08-12 16:05:51 +02:00
Log "Booting iBSS..."
2020-08-14 05:57:20 +02:00
sudo $python ipwndfu -l ../../tmp/pwnediBSS
2020-10-22 14:28:31 +02:00
ret = $?
2020-08-12 16:08:14 +02:00
cd ../..
2020-10-22 14:28:31 +02:00
return $ret
2020-08-12 16:05:51 +02:00
fi
2020-07-30 17:09:34 +02:00
[ [ $VersionDetect = = 1 ] ] && kloader = 'kloader_hgsp'
[ [ $VersionDetect = = 5 ] ] && kloader = 'kloader5'
[ [ ! $kloader ] ] && kloader = 'kloader'
2020-07-31 12:04:16 +02:00
2020-08-14 07:34:48 +02:00
[ ! $( which $iproxy ) ] && Error "iproxy cannot be found. Please re-install dependencies and try again" "./restore.sh Install"
2020-08-14 06:05:43 +02:00
$iproxy 2222 22 &
2020-07-31 03:06:21 +02:00
iproxyPID = $!
2020-08-14 05:57:20 +02:00
WifiAddr = $( echo " $ideviceinfo2 " | grep 'WiFiAddress' | cut -c 14-)
2020-07-31 12:04:16 +02:00
WifiAddrDecr = $( echo $( printf "%x\n" $( expr $( printf "%d\n" 0x$( echo " ${ WifiAddr } " | tr -d ':' ) ) - 1) ) | sed 's/\(..\)/\1:/g;s/:$//' )
2020-10-19 05:39:30 +02:00
echo '#!/bin/sh' > tmp/pwn.sh
echo " /usr/sbin/nvram wifiaddr= $WifiAddrDecr " >> tmp/pwn.sh
2020-07-31 12:04:16 +02:00
chmod +x tmp/pwn.sh
2020-07-31 03:06:21 +02:00
Log "Copying stuff to device via SSH..."
2020-09-09 02:33:22 +02:00
Echo "* Make sure OpenSSH/Dropbear is installed on the device!"
Echo "* Enter root password of your iOS device when prompted, default is 'alpine'"
2020-07-31 12:04:16 +02:00
scp -P 2222 resources/tools/$kloader tmp/pwnediBSS tmp/pwn.sh root@127.0.0.1:/
2020-08-27 12:50:47 +02:00
[ $? = = 1 ] && Error "Cannot connect to device via SSH. Please check your ~/.ssh/known_hosts file and try again" "You may also run: rm ~/.ssh/known_hosts"
2020-07-31 03:06:21 +02:00
Log "Entering kDFU mode..."
2020-07-31 12:04:16 +02:00
if [ [ $VersionDetect = = 1 ] ] ; then
ssh -p 2222 root@127.0.0.1 " /pwn.sh; / $kloader /pwnediBSS " &
else
ssh -p 2222 root@127.0.0.1 " / $kloader /pwnediBSS " &
fi
2020-01-08 00:17:00 +01:00
echo
2020-09-01 04:25:27 +02:00
Echo "* Press POWER or HOME button when screen goes black on the device"
2020-04-01 04:49:55 +02:00
Log "Finding device in DFU mode..."
2019-12-15 04:52:10 +01:00
while [ [ $DFUDevice != 1 ] ] ; do
2020-09-18 04:17:57 +02:00
[ [ $platform = = linux ] ] && DFUDevice = $( lsusb | grep -c '1227' )
2020-09-17 14:51:04 +02:00
[ [ $platform = = macos ] ] && [ [ $( $irecovery -q 2>/dev/null | grep 'MODE' | cut -c 7-) = = "DFU" ] ] && DFUDevice = 1
sleep 1
2019-11-22 11:48:41 +01:00
done
2020-04-01 04:49:55 +02:00
Log "Found device in DFU mode."
2020-07-31 03:06:21 +02:00
kill $iproxyPID
2019-11-22 11:48:41 +01:00
}
2020-07-23 02:47:36 +02:00
function Recovery {
2020-09-10 11:20:46 +02:00
[ [ $( $irecovery -q 2>/dev/null | grep 'MODE' | cut -c 7-) = = "Recovery" ] ] && RecoveryDevice = 1
2020-07-23 02:47:36 +02:00
if [ [ $RecoveryDevice != 1 ] ] ; then
Log "Entering recovery mode..."
2020-08-14 06:05:43 +02:00
$ideviceenterrecovery $UniqueDeviceID >/dev/null
2020-07-23 02:47:36 +02:00
while [ [ $RecoveryDevice != 1 ] ] ; do
2020-09-10 11:20:46 +02:00
[ [ $( $irecovery -q 2>/dev/null | grep 'MODE' | cut -c 7-) = = "Recovery" ] ] && RecoveryDevice = 1
2020-07-23 02:47:36 +02:00
done
fi
2020-09-07 09:55:38 +02:00
Log "Device in recovery mode detected. Get ready to enter DFU mode"
2020-09-01 04:25:27 +02:00
read -p " $( Input 'Select Y to continue, N to exit recovery (Y/n) ' ) " RecoveryDFU
2020-07-23 02:47:36 +02:00
if [ [ $RecoveryDFU = = n ] ] || [ [ $RecoveryDFU = = N ] ] ; then
Log "Exiting recovery mode."
2020-07-27 13:27:46 +02:00
$irecovery -n
2020-07-23 02:47:36 +02:00
exit
fi
2020-09-10 10:28:52 +02:00
Echo "* Hold POWER and HOME button for 8 seconds."
for i in { 08..01} ; do
2020-07-23 02:47:36 +02:00
echo -n " $i "
sleep 1
done
2020-09-10 10:28:52 +02:00
echo -e " \n $( Echo '* Release POWER and hold HOME button for 8 seconds.' ) "
for i in { 08..01} ; do
2020-07-23 02:47:36 +02:00
echo -n " $i "
sleep 1
done
2020-09-10 11:20:46 +02:00
sleep 2
[ [ $( $irecovery -q 2>/dev/null | grep 'MODE' | cut -c 7-) = = "DFU" ] ] && DFUDevice = 1
2020-09-10 10:28:52 +02:00
[ [ $DFUDevice = = 1 ] ] && CheckM8
2020-07-30 17:09:34 +02:00
Error "Failed to detect device in DFU mode. Please run the script again"
2020-07-23 02:47:36 +02:00
}
function CheckM8 {
2020-08-16 06:23:07 +02:00
DFUManual = 1
2020-09-01 04:25:27 +02:00
[ [ $A7Device = = 1 ] ] && echo -e " \n $( Log 'Device in DFU mode detected.' ) "
2020-09-15 00:49:27 +02:00
if [ [ $platform = = macos ] ] ; then
Selection = ( "iPwnder32" "ipwndfu" )
Input "Select pwnDFU tool to use (press ENTER when unsure):"
select opt in " ${ Selection [@] } " ; do
case $opt in
"ipwndfu" ) pwnDFUTool = "ipwndfu" ; break; ;
"iPwnder32" ) pwnDFUTool = "iPwnder32" ; break; ;
*) pwnDFUTool = " ${ Selection [0] } " ; break; ;
esac
done
else
pwnDFUTool = "ipwndfu"
fi
2020-09-13 14:51:26 +02:00
Log " Entering pwnDFU mode with $pwnDFUTool ... "
if [ [ $pwnDFUTool = = "ipwndfu" ] ] ; then
cd resources/ipwndfu
sudo $python ipwndfu -p
pwnDFUDevice = $?
elif [ [ $pwnDFUTool = = "iPwnder32" ] ] ; then
$pwnedDFU -p -f
pwnDFUDevice = $?
cd resources/ipwndfu
fi
2020-09-10 10:28:52 +02:00
if [ [ $pwnDFUDevice = = 0 ] ] ; then
2020-08-12 16:05:51 +02:00
Log "Device in pwnDFU mode detected."
if [ [ $A7Device = = 1 ] ] ; then
Log "Running rmsigchks.py..."
2020-08-14 05:57:20 +02:00
sudo $python rmsigchks.py
2020-08-12 16:05:51 +02:00
cd ../..
else
2020-10-30 01:46:33 +01:00
cd ../..
2020-08-12 16:05:51 +02:00
kDFU iBSS
fi
2020-07-23 02:47:36 +02:00
Log " Downgrading device $ProductType in pwnDFU mode... "
Mode = 'Downgrade'
SelectVersion
else
2020-09-10 10:28:52 +02:00
Error "Failed to enter pwnDFU mode. Please run the script again" "./restore.sh Downgrade"
2020-07-23 02:47:36 +02:00
fi
}
2020-03-31 08:05:29 +02:00
function Downgrade {
2020-07-23 02:47:36 +02:00
if [ [ $OSVer != 'Other' ] ] ; then
2020-09-08 07:50:27 +02:00
[ [ $ProductType = = iPad4* ] ] && IPSWType = "iPad_64bit"
2020-09-11 12:54:06 +02:00
[ [ $ProductType = = iPhone6* ] ] && IPSWType = "iPhone_4.0_64bit"
2020-09-08 07:50:27 +02:00
[ [ ! $IPSWType ] ] && IPSWType = " $ProductType " && SaveOTABlobs
IPSW = " ${ IPSWType } _ ${ OSVer } _ ${ BuildVer } _Restore "
IPSWCustom = " ${ IPSWType } _ ${ OSVer } _ ${ BuildVer } _Custom "
if [ ! -e $IPSW .ipsw ] && [ ! -e $IPSWCustom .ipsw ] ; then
2020-08-10 16:08:15 +02:00
Log " iOS $OSVer IPSW cannot be found. "
2020-09-01 04:25:27 +02:00
Echo "* If you already downloaded the IPSW, did you put it in the same directory as the script?"
Echo "* Do NOT rename the IPSW as the script will fail to detect it"
2020-08-10 16:08:15 +02:00
Log "Downloading IPSW... (Press Ctrl+C to cancel)"
2020-05-05 09:05:49 +02:00
curl -L $( cat $Firmware /$BuildVer /url) -o tmp/$IPSW .ipsw
2020-03-13 05:12:49 +01:00
mv tmp/$IPSW .ipsw .
2020-03-05 12:48:41 +01:00
fi
2020-07-23 02:47:36 +02:00
if [ ! -e $IPSWCustom .ipsw ] ; then
Log "Verifying IPSW..."
IPSWSHA1 = $( cat $Firmware /$BuildVer /sha1sum)
2020-08-11 02:57:18 +02:00
IPSWSHA1L = $( shasum $IPSW .ipsw | awk '{print $1}' )
2020-07-23 02:47:36 +02:00
[ [ $IPSWSHA1L != $IPSWSHA1 ] ] && Error "Verifying IPSW failed. Delete/replace the IPSW and run the script again"
else
IPSW = $IPSWCustom
fi
2020-07-25 05:23:31 +02:00
if [ ! $DFUManual ] && [ [ $iBSSBuildVer = = $BuildVer ] ] ; then
2020-04-08 14:01:21 +02:00
Log "Extracting iBSS from IPSW..."
mkdir -p saved/$ProductType 2>/dev/null
2020-07-23 02:47:36 +02:00
unzip -o -j $IPSW .ipsw Firmware/dfu/$iBSS .dfu -d saved/$ProductType
2020-04-08 14:01:21 +02:00
fi
2019-11-22 11:48:41 +01:00
fi
2020-03-05 12:48:41 +01:00
2020-07-23 02:47:36 +02:00
[ ! $DFUManual ] && kDFU
2020-03-05 12:48:41 +01:00
2020-09-16 08:50:12 +02:00
# uses ipsw tool from OdysseusOTA/2 to create custom IPSW with jailbreak
if [ [ $Jailbreak = = 1 ] ] ; then
if [ [ $OSVer = = 8.4.1 ] ] ; then
JBFiles = ( fstab.tar etasonJB-untether.tar Cydia8.tar)
2020-10-22 14:28:31 +02:00
JBSHA1 = 6459dbcbfe871056e6244d23b33c9b99aaeca970
2020-09-17 05:04:34 +02:00
JBS = 2305
2020-09-16 08:50:12 +02:00
else
JBFiles = ( fstab_rw.tar p0sixspwn.tar Cydia6.tar)
2020-10-22 14:28:31 +02:00
JBSHA1 = 1d5a351016d2546aa9558bc86ce39186054dc281
2020-09-16 08:50:12 +02:00
JBS = 1260
fi
2020-09-17 05:04:34 +02:00
if [ [ ! -e resources/jailbreak/${ JBFiles [2] } ] ] ; then
2020-09-15 12:25:37 +02:00
cd tmp
Log "Downloading jailbreak files..."
2020-10-22 14:28:31 +02:00
SaveFile https://github.com/LukeZGD/iOS-OTA-Downgrader-Keys/releases/download/jailbreak/${ JBFiles [2] } ${ JBFiles [2] } $JBSHA1
2020-09-17 05:04:34 +02:00
cp ${ JBFiles [2] } ../resources/jailbreak
2020-09-15 12:25:37 +02:00
cd ..
fi
for i in { 0..2} ; do
JBFiles[ $i ] = jailbreak/${ JBFiles [ $i ] }
done
if [ ! -e $IPSWCustom .ipsw ] ; then
2020-09-16 08:50:12 +02:00
Echo "* By default, memory option is set to Y, you may select N later if you encounter problems"
Echo "* If it doesn't work with both, you might not have enough RAM or tmp storage"
read -p " $( Input 'Memory option? (press ENTER if unsure) (Y/n): ' ) " JBMemory
[ [ $JBMemory != n ] ] && [ [ $JBMemory != N ] ] && JBMemory = "-memory" || JBMemory =
2020-09-15 12:25:37 +02:00
Log "Preparing custom IPSW..."
cd resources
2020-09-16 08:50:12 +02:00
ln -sf firmware/FirmwareBundles FirmwareBundles
$ipsw ../$IPSW .ipsw ../$IPSWCustom .ipsw $JBMemory -bbupdate -s $JBS ${ JBFiles [@] }
2020-09-15 12:25:37 +02:00
cd ..
fi
2020-09-16 08:50:12 +02:00
[ ! -e $IPSWCustom .ipsw ] && Error "Failed to find custom IPSW. Please run the script again" "You may try selecting N for memory option"
2020-09-15 12:25:37 +02:00
IPSW = $IPSWCustom
fi
2020-04-01 04:49:55 +02:00
Log "Extracting IPSW..."
2020-07-23 02:47:36 +02:00
unzip -q $IPSW .ipsw -d $IPSW /
2020-09-23 06:46:35 +02:00
# create custom IPSW for 10.3.3
2020-07-25 05:23:31 +02:00
if [ [ $A7Device = = 1 ] ] ; then
2020-07-23 02:47:36 +02:00
if [ ! -e $IPSWCustom .ipsw ] ; then
Log "Preparing custom IPSW..."
cp $IPSW /Firmware/all_flash/$SEP .
2020-08-14 05:57:20 +02:00
$bspatch $IPSW /Firmware/dfu/$iBSS .im4p $iBSS .im4p resources/patches/$iBSS .patch
$bspatch $IPSW /Firmware/dfu/$iBEC .im4p $iBEC .im4p resources/patches/$iBEC .patch
2020-09-11 16:38:51 +02:00
if [ [ $ProductType = = iPad4* ] ] ; then
$bspatch $IPSW /Firmware/dfu/$iBSSb .im4p $iBSSb .im4p resources/patches/$iBSSb .patch
$bspatch $IPSW /Firmware/dfu/$iBECb .im4p $iBECb .im4p resources/patches/$iBECb .patch
2020-09-15 00:49:27 +02:00
cp -f $iBSSb .im4p $iBECb .im4p $IPSW /Firmware/dfu
2020-09-11 16:38:51 +02:00
fi
2020-09-15 00:49:27 +02:00
cp -f $iBSS .im4p $iBEC .im4p $IPSW /Firmware/dfu
2020-07-23 02:47:36 +02:00
cd $IPSW
2020-07-27 13:27:46 +02:00
zip ../$IPSWCustom .ipsw -rq0 *
2020-07-23 02:47:36 +02:00
cd ..
mv $IPSW $IPSWCustom
IPSW = $IPSWCustom
else
2020-09-08 07:50:27 +02:00
cp $IPSW /Firmware/dfu/$iBSS .im4p $IPSW /Firmware/dfu/$iBEC .im4p .
2020-09-11 16:38:51 +02:00
[ [ $ProductType = = iPad4* ] ] && cp $IPSW /Firmware/dfu/$iBSSb .im4p $IPSW /Firmware/dfu/$iBECb .im4p .
2020-07-23 02:47:36 +02:00
cp $IPSW /Firmware/all_flash/$SEP .
fi
2020-09-16 14:59:09 +02:00
[ ! -e $IPSW .ipsw ] && Error "Failed to create custom IPSW. Please run the script again"
2020-09-11 16:38:51 +02:00
if [ [ $ProductType = = iPad4,4 ] ] || [ [ $ProductType = = iPad4,5 ] ] ; then
2020-09-08 07:50:27 +02:00
iBEC = $iBECb
iBSS = $iBSSb
fi
2020-08-01 07:31:37 +02:00
Log "Entering pwnREC mode..."
2020-07-27 13:27:46 +02:00
$irecovery -f $iBSS .im4p
$irecovery -f $iBEC .im4p
2020-07-23 02:47:36 +02:00
sleep 5
2020-09-10 11:20:46 +02:00
[ [ $( $irecovery -q 2>/dev/null | grep 'MODE' | cut -c 7-) = = "Recovery" ] ] && RecoveryDevice = 1
2020-08-01 07:31:37 +02:00
if [ [ $RecoveryDevice != 1 ] ] ; then
2020-09-08 07:50:27 +02:00
echo -e " \n $( Log 'Failed to detect device in pwnREC mode.' ) "
2020-09-01 04:25:27 +02:00
Echo "* If you device has backlight turned on, you may try re-plugging in your device and attempt to continue"
2020-09-11 12:54:06 +02:00
Input "Press ENTER to continue anyway (or press Ctrl+C to cancel)"
2020-08-04 11:48:10 +02:00
read -s
2020-09-11 12:54:06 +02:00
else
Log "Found device in pwnREC mode."
2020-08-01 07:31:37 +02:00
fi
2020-07-23 02:47:36 +02:00
SaveOTABlobs
fi
2020-03-10 03:55:04 +01:00
2020-09-23 06:46:35 +02:00
if [ [ $Jailbreak != 1 ] ] && [ [ $A7Device != 1 ] ] && [ [ $OSVer != 'Other' ] ] ; then
2020-09-15 12:25:37 +02:00
Log "Preparing for futurerestore... (Enter root password of your PC/Mac when prompted)"
cd resources
sudo bash -c " $python -m SimpleHTTPServer 80 & "
cd ..
fi
2020-03-05 12:48:41 +01:00
2020-09-16 08:50:12 +02:00
if [ [ $Jailbreak = = 1 ] ] ; then
2020-09-15 12:25:37 +02:00
Log "Proceeding to idevicerestore..."
mkdir shsh
mv $SHSH shsh/${ UniqueChipID } -${ ProductType } -${ OSVer } .shsh
2020-10-08 10:00:18 +02:00
$idevicerestore -y -e -w $IPSW .ipsw
2020-09-15 12:25:37 +02:00
elif [ $Baseband = = 0 ] ; then
2020-04-01 04:49:55 +02:00
Log " Device $ProductType has no baseband "
Log "Proceeding to futurerestore..."
2020-07-25 05:23:31 +02:00
if [ [ $A7Device = = 1 ] ] ; then
2020-07-30 17:09:34 +02:00
$futurerestore2 -t $SHSH -s $SEP -m $BuildManifest --no-baseband $IPSW .ipsw
2020-07-23 02:47:36 +02:00
else
2020-07-30 17:09:34 +02:00
$futurerestore1 -t $SHSH --no-baseband --use-pwndfu $IPSW .ipsw
2020-07-23 02:47:36 +02:00
fi
2020-03-29 05:53:53 +02:00
else
2020-07-25 05:23:31 +02:00
if [ [ $A7Device = = 1 ] ] ; then
2020-07-23 02:47:36 +02:00
cp $IPSW /Firmware/$Baseband .
2020-10-22 07:16:51 +02:00
elif [ $ProductType = = iPhone5,1 ] && [ [ $Baseband5 != 0 ] ] ; then
2020-11-15 12:15:09 +01:00
[ ! -e saved/$ProductType /*.bbfw ] && unzip -o -j $IPSW .ipsw Firmware/$Baseband -d saved/$ProductType
cp saved/$ProductType /*.bbfw $BuildManifest .
2020-07-25 07:19:19 +02:00
elif [ ! -e saved/$ProductType /*.bbfw ] ; then
2020-04-01 04:49:55 +02:00
Log "Downloading baseband..."
2020-11-15 12:15:09 +01:00
$partialzip $BasebandURL Firmware/$Baseband $Baseband
2020-08-16 13:25:32 +02:00
$partialzip $BasebandURL BuildManifest.plist BuildManifest.plist
2020-03-29 05:53:53 +02:00
mkdir -p saved/$ProductType 2>/dev/null
2020-07-23 02:47:36 +02:00
cp $Baseband BuildManifest.plist saved/$ProductType
2020-03-05 12:48:41 +01:00
else
2020-03-29 05:53:53 +02:00
cp saved/$ProductType /*.bbfw saved/$ProductType /BuildManifest.plist .
2020-03-05 12:48:41 +01:00
fi
2020-08-11 02:57:18 +02:00
BasebandSHA1L = $( shasum $Baseband | awk '{print $1}' )
2020-07-27 13:27:46 +02:00
Log "Proceeding to futurerestore..."
2020-07-25 07:19:19 +02:00
if [ ! -e *.bbfw ] || [ [ $BasebandSHA1L != $BasebandSHA1 ] ] ; then
2020-07-23 02:47:36 +02:00
rm -f saved/$ProductType /*.bbfw saved/$ProductType /BuildManifest.plist
2020-09-01 04:25:27 +02:00
Log "Downloading/verifying baseband failed."
Echo "* Your device is still in kDFU mode and you may run the script again"
Echo "* You can also continue and futurerestore can attempt to download the baseband again"
Input "Press ENTER to continue (or press Ctrl+C to cancel)"
2020-08-04 11:48:10 +02:00
read -s
2020-10-22 14:28:31 +02:00
$futurerestore1 -t $SHSH --latest-baseband --use-pwndfu $IPSW .ipsw
2020-07-25 05:23:31 +02:00
elif [ [ $A7Device = = 1 ] ] ; then
2020-07-30 17:09:34 +02:00
$futurerestore2 -t $SHSH -s $SEP -m $BuildManifest -b $Baseband -p $BuildManifest $IPSW .ipsw
2020-06-14 07:39:26 +02:00
else
2020-07-30 17:09:34 +02:00
$futurerestore1 -t $SHSH -b $Baseband -p BuildManifest.plist --use-pwndfu $IPSW .ipsw
2020-03-29 05:53:53 +02:00
fi
fi
2020-10-22 14:28:31 +02:00
2020-03-29 05:53:53 +02:00
echo
2020-09-15 12:25:37 +02:00
Log "Restoring done!"
2020-09-23 06:46:35 +02:00
if [ [ $Jailbreak != 1 ] ] && [ [ $A7Device != 1 ] ] && [ [ $OSVer != 'Other' ] ] ; then
2020-09-15 12:25:37 +02:00
Log "Stopping local server... (Enter root password of your PC/Mac when prompted)"
ps aux | awk '/python/ {print "sudo kill -9 "$2" 2>/dev/null"}' | bash
fi
2020-04-01 04:49:55 +02:00
Log "Downgrade script done!"
2020-03-05 12:48:41 +01:00
}
2020-01-08 00:17:00 +01:00
function InstallDependencies {
2020-07-29 12:41:01 +02:00
mkdir tmp 2>/dev/null
2020-07-23 02:47:36 +02:00
cd tmp
2020-05-08 03:46:30 +02:00
2020-07-23 02:47:36 +02:00
Log "Installing dependencies..."
2020-07-23 16:35:52 +02:00
if [ [ $ID = = "arch" ] ] || [ [ $ID_LIKE = = "arch" ] ] ; then
2020-09-07 09:55:38 +02:00
# Arch
2020-10-30 01:47:49 +01:00
sudo pacman -Sy --noconfirm --needed base-devel bsdiff curl libcurl-compat libpng12 libimobiledevice libusbmuxd libzip openssh openssl-1.0 python2 unzip usbmuxd usbutils
2020-08-16 09:09:55 +02:00
ln -sf /usr/lib/libcurl.so.3 ../resources/lib/libcurl.so.3
ln -sf /usr/lib/libzip.so.5 ../resources/lib/libzip.so.4
2020-07-06 10:08:13 +02:00
2020-10-19 06:17:49 +02:00
elif [ [ $UBUNTU_CODENAME = = "xenial" ] ] || [ [ $UBUNTU_CODENAME = = "bionic" ] ] ||
[ [ $UBUNTU_CODENAME = = "focal" ] ] || [ [ $UBUNTU_CODENAME = = "groovy" ] ] ; then
2020-09-07 09:55:38 +02:00
# Ubuntu
2020-07-23 16:35:52 +02:00
sudo add-apt-repository universe
2020-05-08 03:46:30 +02:00
sudo apt update
2020-09-10 11:20:46 +02:00
sudo apt install -y autoconf automake bsdiff build-essential checkinstall curl git libglib2.0-dev libimobiledevice-utils libreadline-dev libtool-bin libusb-1.0-0-dev libusbmuxd-tools openssh-client usbmuxd usbutils
2020-08-11 02:57:18 +02:00
SavePkg
2020-09-07 09:55:38 +02:00
cp libcurl.so.4.5.0 ../resources/lib/libcurl.so.3
2020-08-14 10:07:14 +02:00
if [ [ $UBUNTU_CODENAME = = "bionic" ] ] ; then
sudo apt install -y libzip4 python
2020-09-06 09:57:01 +02:00
sudo dpkg -i libpng12_bionic.deb libzip5.deb
2020-10-06 04:47:44 +02:00
SaveFile https://github.com/LukeZGD/iOS-OTA-Downgrader-Keys/releases/download/tools/tools_linux_bionic.zip tools_linux_bionic.zip 959abbafacfdaddf87dd07683127da1dab6c835f
2020-08-14 10:07:14 +02:00
unzip tools_linux_bionic.zip -d ../resources/tools
2020-10-19 06:17:49 +02:00
elif [ [ $UBUNTU_CODENAME = = "xenial" ] ] ; then
2020-10-19 06:59:45 +02:00
sudo apt install -y libzip4 python libpng12-0
2020-10-19 06:17:49 +02:00
SaveFile https://github.com/LukeZGD/iOS-OTA-Downgrader-Keys/releases/download/tools/tools_linux_xenial.zip tools_linux_xenial.zip b74861fd87511a92e36e27bf2ec3e1e83b6e8200
unzip tools_linux_xenial.zip -d ../resources/tools
2020-08-14 10:07:14 +02:00
else
2020-09-09 02:33:22 +02:00
sudo apt install -y libzip5 python2
sudo dpkg -i libpng12.deb libssl1.0.0.deb libzip4.deb
2020-09-07 09:55:38 +02:00
fi
if [ [ $UBUNTU_CODENAME = = "focal" ] ] ; then
2020-08-16 09:09:55 +02:00
ln -sf /usr/lib/x86_64-linux-gnu/libimobiledevice.so.6 ../resources/lib/libimobiledevice-1.0.so.6
ln -sf /usr/lib/x86_64-linux-gnu/libplist.so.3 ../resources/lib/libplist-2.0.so.3
ln -sf /usr/lib/x86_64-linux-gnu/libusbmuxd.so.6 ../resources/lib/libusbmuxd-2.0.so.6
2020-08-14 10:07:14 +02:00
fi
2020-07-23 02:47:36 +02:00
2020-07-23 16:35:52 +02:00
elif [ [ $ID = = "fedora" ] ] ; then
2020-09-07 09:55:38 +02:00
# Fedora
2020-09-10 11:20:46 +02:00
sudo dnf install -y automake binutils bsdiff git libimobiledevice-utils libpng12 libtool libusb-devel libusbmuxd-utils make libzip perl-Digest-SHA python2 readline-devel
2020-08-11 02:57:18 +02:00
SavePkg
2020-09-06 09:57:01 +02:00
ar x libssl1.0.0.deb data.tar.xz
tar xf data.tar.xz
cp usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 ../resources/lib
2020-09-09 02:33:22 +02:00
if ( ( $VERSION_ID <= 32 ) ) ; then
ln -sf /usr/lib64/libimobiledevice.so.6 ../resources/lib/libimobiledevice-1.0.so.6
ln -sf /usr/lib64/libplist.so.3 ../resources/lib/libplist-2.0.so.3
ln -sf /usr/lib64/libusbmuxd.so.6 ../resources/lib/libusbmuxd-2.0.so.6
fi
2020-08-16 09:09:55 +02:00
ln -sf /usr/lib64/libzip.so.5 ../resources/lib/libzip.so.4
2020-05-08 03:46:30 +02:00
elif [ [ $OSTYPE = = "darwin" * ] ] ; then
# macOS
2020-08-16 13:25:32 +02:00
xcode-select --install
2020-09-23 06:46:35 +02:00
SaveFile https://github.com/libimobiledevice-win32/imobiledevice-net/releases/download/v1.3.6/libimobiledevice.1.2.1-r1091-osx-x64.zip libimobiledevice.zip dba9ca5399e9ff7e39f0062d63753d1a0c749224
2020-10-21 15:14:37 +02:00
Log "(Enter root password of your Mac when prompted)"
sudo codesign --sign - --force --deep ../resources/tools/idevicerestore_macos
2020-08-25 08:42:57 +02:00
2020-04-27 07:16:07 +02:00
else
2020-08-10 16:08:15 +02:00
Error "Distro not detected/supported by the install script." "See the repo README for supported OS versions/distros"
2020-04-27 07:16:07 +02:00
fi
2020-08-25 08:42:57 +02:00
2020-09-10 11:20:46 +02:00
if [ [ $platform = = linux ] ] ; then
Compile LukeZGD libirecovery
2020-09-13 16:26:49 +02:00
ln -sf ../libirecovery/lib/libirecovery.so.3 ../resources/lib/libirecovery-1.0.so.3
ln -sf ../libirecovery/lib/libirecovery.so.3 ../resources/lib/libirecovery.so.3
2020-09-10 11:20:46 +02:00
else
2020-08-25 08:42:57 +02:00
mkdir ../resources/libimobiledevice_$platform
unzip libimobiledevice.zip -d ../resources/libimobiledevice_$platform
chmod +x ../resources/libimobiledevice_$platform /*
2020-08-17 14:31:15 +02:00
fi
2020-07-23 02:47:36 +02:00
2020-05-08 03:46:30 +02:00
Log "Install script done! Please run the script again to proceed"
2020-07-23 02:47:36 +02:00
exit
2020-01-08 00:17:00 +01:00
}
2020-09-10 11:20:46 +02:00
function Compile {
git clone --depth 1 https://github.com/$1 /$2 .git
cd $2
2020-09-13 16:36:18 +02:00
./autogen.sh --prefix= " $( cd ../.. && pwd ) /resources/ $2 "
2020-09-13 16:26:49 +02:00
make install
2020-09-10 11:20:46 +02:00
cd ..
sudo rm -rf $2
}
2020-07-23 02:47:36 +02:00
function SaveExternal {
2020-07-30 13:31:55 +02:00
ExternalURL = " https://github.com/LukeZGD/ $1 .git "
External = $1
[ [ $1 = = "iOS-OTA-Downgrader-Keys" ] ] && External = "firmware"
2020-10-19 05:39:30 +02:00
cd resources
if [ [ ! -d $External ] ] || [ [ ! -d $External /.git ] ] ; then
2020-07-30 13:31:55 +02:00
Log " Downloading $External ... "
2020-08-04 17:49:55 +02:00
rm -rf $External
git clone $ExternalURL $External
2020-10-19 05:39:30 +02:00
#else
# Log "Updating $External..."
# cd $External
# git pull 2>/dev/null
# cd ..
2020-07-23 02:47:36 +02:00
fi
2020-08-04 17:49:55 +02:00
if [ [ ! -e $External /README.md ] ] || [ [ ! -d $External /.git ] ] ; then
2020-10-19 05:39:30 +02:00
rm -rf $External
2020-08-04 17:49:55 +02:00
Error " Downloading/updating $1 failed. Please run the script again "
fi
2020-07-30 13:31:55 +02:00
cd ..
2020-07-23 02:47:36 +02:00
}
2020-03-04 16:19:01 +01:00
2020-08-14 10:07:14 +02:00
function SaveFile {
curl -L $1 -o $2
if [ [ $( shasum $2 | awk '{print $1}' ) != $3 ] ] ; then
Error "Verifying failed. Please run the script again" "./restore.sh Install"
fi
}
2020-07-24 14:58:09 +02:00
function SavePkg {
2020-08-11 02:57:18 +02:00
if [ [ ! -d ../saved/pkg ] ] ; then
Log "Downloading packages..."
2020-09-06 09:57:01 +02:00
SaveFile https://github.com/LukeZGD/iOS-OTA-Downgrader-Keys/releases/download/tools/depends_linux.zip depends_linux.zip 7daf991e0e80647547f5ceb33007eae6c99707d2
2020-08-11 02:57:18 +02:00
mkdir -p ../saved/pkg
unzip depends_linux.zip -d ../saved/pkg
2020-07-24 14:58:09 +02:00
fi
2020-08-11 02:57:18 +02:00
cp ../saved/pkg/* .
2020-07-24 05:00:32 +02:00
}
2020-07-23 02:47:36 +02:00
function BasebandDetect {
Firmware = resources/firmware/$ProductType
BasebandURL = $( cat $Firmware /13G37/url 2>/dev/null) # iOS 9.3.6
2020-07-23 14:08:16 +02:00
Baseband = 0
2020-07-23 02:47:36 +02:00
if [ $ProductType = = iPad2,2 ] ; then
BasebandURL = $( cat $Firmware /13G36/url) # iOS 9.3.5
Baseband = ICE3_04.12.09_BOOT_02.13.Release.bbfw
BasebandSHA1 = e6f54acc5d5652d39a0ef9af5589681df39e0aca
elif [ $ProductType = = iPad2,3 ] ; then
Baseband = Phoenix-3.6.03.Release.bbfw
BasebandSHA1 = 8d4efb2214344ea8e7c9305392068ab0a7168ba4
elif [ $ProductType = = iPad2,6 ] || [ $ProductType = = iPad2,7 ] ; then
Baseband = Mav5-11.80.00.Release.bbfw
BasebandSHA1 = aa52cf75b82fc686f94772e216008345b6a2a750
elif [ $ProductType = = iPad3,2 ] || [ $ProductType = = iPad3,3 ] ; then
Baseband = Mav4-6.7.00.Release.bbfw
BasebandSHA1 = a5d6978ecead8d9c056250ad4622db4d6c71d15e
elif [ $ProductType = = iPhone4,1 ] ; then
Baseband = Trek-6.7.00.Release.bbfw
BasebandSHA1 = 22a35425a3cdf8fa1458b5116cfb199448eecf49
2020-10-22 07:16:51 +02:00
elif [ $ProductType = = iPad3,5 ] || [ $ProductType = = iPad3,6 ] ||
[ $ProductType = = iPhone5,1 ] || [ $ProductType = = iPhone5,2 ] ; then
2020-07-23 02:47:36 +02:00
BasebandURL = $( cat $Firmware /14G61/url) # iOS 10.3.4
Baseband = Mav5-11.80.00.Release.bbfw
BasebandSHA1 = 8951cf09f16029c5c0533e951eb4c06609d0ba7f
elif [ $ProductType = = iPad4,2 ] || [ $ProductType = = iPad4,3 ] || [ $ProductType = = iPad4,5 ] ||
[ $ProductType = = iPhone6,1 ] || [ $ProductType = = iPhone6,2 ] ; then
BasebandURL = $( cat $Firmware /14G60/url)
Baseband = Mav7Mav8-7.60.00.Release.bbfw
BasebandSHA1 = f397724367f6bed459cf8f3d523553c13e8ae12c
A7Device = 1
2020-07-23 14:08:16 +02:00
elif [ $ProductType = = iPad4,1 ] || [ $ProductType = = iPad4,4 ] ; then
A7Device = 1
2020-07-27 15:42:41 +02:00
elif [ $ProductType = = 0 ] ; then
2020-08-27 12:50:47 +02:00
Error "No device detected. Please put the device in normal mode (and jailbroken for 32-bit) before proceeding" "Recovery or DFU mode is also applicable for A7 devices"
2020-07-23 14:08:16 +02:00
elif [ $ProductType != iPad2,1 ] && [ $ProductType != iPad2,4 ] && [ $ProductType != iPad2,5 ] &&
2020-08-05 05:07:28 +02:00
[ $ProductType != iPad3,1 ] && [ $ProductType != iPad3,4 ] && [ $ProductType != iPod5,1 ] &&
[ $ProductType != iPhone5,3 ] && [ $ProductType != iPhone5,4 ] ; then
2020-07-23 14:08:16 +02:00
Error " Your device $ProductType is not supported. "
2020-07-23 02:47:36 +02:00
fi
2020-08-22 12:50:29 +02:00
2020-08-22 03:52:58 +02:00
[ $ProductType = = iPad2,1 ] && HWModel = k93
[ $ProductType = = iPad2,2 ] && HWModel = k94
[ $ProductType = = iPad2,3 ] && HWModel = k95
[ $ProductType = = iPad2,4 ] && HWModel = k93a
[ $ProductType = = iPad2,5 ] && HWModel = p105
[ $ProductType = = iPad2,6 ] && HWModel = p106
[ $ProductType = = iPad2,7 ] && HWModel = p107
[ $ProductType = = iPad3,1 ] && HWModel = j1
[ $ProductType = = iPad3,2 ] && HWModel = j2
[ $ProductType = = iPad3,3 ] && HWModel = j2a
[ $ProductType = = iPad3,4 ] && HWModel = p101
[ $ProductType = = iPad3,5 ] && HWModel = p102
[ $ProductType = = iPad3,6 ] && HWModel = p103
2020-07-23 02:47:36 +02:00
[ $ProductType = = iPad4,1 ] && HWModel = j71
[ $ProductType = = iPad4,2 ] && HWModel = j72
[ $ProductType = = iPad4,3 ] && HWModel = j73
[ $ProductType = = iPad4,4 ] && HWModel = j85
[ $ProductType = = iPad4,5 ] && HWModel = j86
2020-08-22 03:52:58 +02:00
[ $ProductType = = iPhone4,1 ] && HWModel = n94
[ $ProductType = = iPhone5,1 ] && HWModel = n41
[ $ProductType = = iPhone5,2 ] && HWModel = n42
[ $ProductType = = iPhone5,3 ] && HWModel = n48
[ $ProductType = = iPhone5,4 ] && HWModel = n49
[ $ProductType = = iPhone6,1 ] && HWModel = n51
[ $ProductType = = iPhone6,2 ] && HWModel = n53
[ $ProductType = = iPod5,1 ] && HWModel = n78
2020-08-22 12:50:29 +02:00
if [ $ProductType = = iPod5,1 ] ; then
iBSS = " ${ HWModel } ap "
iBSSBuildVer = '10B329'
elif [ $ProductType = = iPad3,1 ] ; then
iBSS = " ${ HWModel } ap "
iBSSBuildVer = '11D257'
elif [ $ProductType = = iPhone6,1 ] || [ $ProductType = = iPhone6,2 ] ; then
iBSS = "iphone6"
2020-09-08 07:50:27 +02:00
elif [ $ProductType = = iPad4,1 ] || [ $ProductType = = iPad4,2 ] || [ $ProductType = = iPad4,3 ] ||
[ $ProductType = = iPad4,4 ] || [ $ProductType = = iPad4,5 ] ; then
2020-08-22 12:50:29 +02:00
iBSS = "ipad4"
else
iBSS = " $HWModel "
iBSSBuildVer = '12H321'
fi
iBEC = " iBEC. $iBSS .RELEASE "
2020-09-08 07:50:27 +02:00
iBECb = " iBEC. ${ iBSS } b.RELEASE "
iBSSb = " iBSS. ${ iBSS } b.RELEASE "
2020-08-22 12:50:29 +02:00
iBSS = " iBSS. $iBSS .RELEASE "
2020-09-07 09:55:38 +02:00
SEP = " sep-firmware. $HWModel .RELEASE.im4p "
2020-07-23 02:47:36 +02:00
}
2020-09-15 05:46:17 +02:00
cd " $( dirname $0 ) "
2020-07-23 04:08:46 +02:00
Main $1