2019-11-22 11:48:41 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-03-09 02:30:19 +01:00
|
|
|
function BasebandDetect {
|
2020-03-31 07:46:59 +02:00
|
|
|
BasebandURL=$(cat resources/firmware/${ProductType}/13G37/url 2>/dev/null)
|
2020-03-29 05:53:53 +02:00
|
|
|
if [ $ProductType == iPad2,2 ]; then
|
2020-03-31 07:46:59 +02:00
|
|
|
BasebandURL=$(cat resources/firmware/${ProductType}/13G36/url)
|
|
|
|
Baseband=ICE3_04.12.09_BOOT_02.13.Release.bbfw
|
2020-03-29 05:53:53 +02:00
|
|
|
elif [ $ProductType == iPad2,3 ]; then
|
2020-03-31 07:46:59 +02:00
|
|
|
Baseband=Phoenix-3.6.03.Release.bbfw
|
|
|
|
elif [ $ProductType == iPad2,6 ] || [ $ProductType == iPad2,7 ]; then
|
|
|
|
Baseband=Mav5-11.80.00.Release.bbfw
|
|
|
|
elif [ $ProductType == iPad3,2 ] || [ $ProductType == iPad3,3 ]; then
|
|
|
|
Baseband=Mav4-6.7.00.Release.bbfw
|
2020-03-29 05:53:53 +02:00
|
|
|
elif [ $ProductType == iPhone4,1 ]; then
|
2020-03-31 07:46:59 +02:00
|
|
|
Baseband=Trek-6.7.00.Release.bbfw
|
|
|
|
elif [ $ProductType == iPad3,5 ] || [ $ProductType == iPad3,6 ] ||
|
|
|
|
[ $ProductType == iPhone5,1 ] || [ $ProductType == iPhone5,2 ]; then
|
|
|
|
BasebandURL=$(cat resources/firmware/${ProductType}/14G61/url)
|
|
|
|
Baseband=Mav5-11.80.00.Release.bbfw
|
2020-03-29 05:53:53 +02:00
|
|
|
else # For Wi-Fi only devices
|
|
|
|
Baseband=0
|
2020-03-09 02:30:19 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function Clean {
|
2020-03-13 05:12:49 +01:00
|
|
|
# Clean up files (called on MainMenu and trap dependency)
|
2020-03-31 07:46:59 +02:00
|
|
|
rm -rf iP*/ tmp/ $(ls ${UniqueChipID}_${ProductType}_${DowngradeVer}-*.shsh2 2>/dev/null) $(ls *.bbfw 2>/dev/null) BuildManifest.plist
|
2020-03-09 02:30:19 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 12:48:41 +01:00
|
|
|
function MainMenu {
|
|
|
|
Clean
|
|
|
|
mkdir tmp
|
|
|
|
|
2020-03-13 05:12:49 +01:00
|
|
|
if [ $(lsusb | grep -c '1227') == 1 ]; then
|
|
|
|
read -p "[Input] Device in DFU mode detected. Is the device in kDFU mode? (y/N) " kDFUManual
|
2020-03-09 02:30:19 +01:00
|
|
|
if [[ $kDFUManual == y ]] || [[ $kDFUManual == Y ]]; then
|
2020-03-10 03:55:04 +01:00
|
|
|
read -p "[Input] Enter ProductType (eg. iPad2,1): " ProductType
|
2020-03-13 05:12:49 +01:00
|
|
|
if [ $(which irecovery) ]; then
|
|
|
|
# Get ECID with irecovery (optional)
|
2020-03-29 05:53:53 +02:00
|
|
|
echo "[Log] Getting UniqueChipID (ECID) with irecovery..."
|
2020-03-13 05:12:49 +01:00
|
|
|
UniqueChipID=$(sudo irecovery -q | grep 'ECID:' | cut -c 7-)
|
|
|
|
else
|
|
|
|
read -p "[Input] Enter UniqueChipID (ECID): " UniqueChipID
|
|
|
|
fi
|
2020-03-09 02:30:19 +01:00
|
|
|
BasebandDetect
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Downgrading device $ProductType in kDFU mode..."
|
2020-03-09 02:30:19 +01:00
|
|
|
Mode='Downgrade'
|
|
|
|
SelectVersion
|
|
|
|
else
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Error] Please put the device in normal mode and jailbroken before proceeding"
|
2020-03-09 02:30:19 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
elif [ ! $ProductType ]; then
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Error] Please plug the device in and trust this computer before proceeding"
|
2020-03-05 12:48:41 +01:00
|
|
|
exit
|
|
|
|
fi
|
2020-03-10 03:55:04 +01:00
|
|
|
BasebandDetect
|
|
|
|
|
2020-03-05 12:48:41 +01:00
|
|
|
echo "Main Menu"
|
|
|
|
echo
|
2020-03-31 07:46:59 +02:00
|
|
|
echo "HardwareModel: $HWModel"
|
2020-03-05 12:48:41 +01:00
|
|
|
echo "ProductType: $ProductType"
|
2020-03-31 07:46:59 +02:00
|
|
|
echo "ProductVersion: $ProductVer"
|
2020-03-05 12:48:41 +01:00
|
|
|
echo "UniqueChipID (ECID): $UniqueChipID"
|
|
|
|
echo
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Input] Select an option:"
|
2020-03-05 12:48:41 +01:00
|
|
|
select opt in "Downgrade device" "Save OTA blobs" "Just put device in kDFU mode" "(Re-)Install Dependencies" "Exit"; do
|
|
|
|
case $opt in
|
2020-03-31 07:46:59 +02:00
|
|
|
"Downgrade device" ) Mode='Downgrade'; break;;
|
|
|
|
"Save OTA blobs" ) Mode='SaveOTABlobs'; break;;
|
|
|
|
"Just put device in kDFU mode" ) Mode='kDFU'; break;;
|
|
|
|
"(Re-)Install Dependencies" ) InstallDependencies;;
|
2020-03-05 12:48:41 +01:00
|
|
|
"Exit" ) exit;;
|
|
|
|
*) MainMenu;;
|
|
|
|
esac
|
|
|
|
done
|
2020-03-31 07:46:59 +02:00
|
|
|
SelectVersion
|
2020-03-05 12:48:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function SelectVersion {
|
2020-03-10 03:55:04 +01:00
|
|
|
if [ $ProductType == iPad2,1 ] || [ $ProductType == iPad2,2 ] ||
|
|
|
|
[ $ProductType == iPad2,3 ] || [ $ProductType == iPhone4,1 ]; then
|
|
|
|
echo "[Input] Select iOS version:"
|
2020-03-05 12:48:41 +01:00
|
|
|
if [[ $Mode == 'Downgrade' ]]; then
|
|
|
|
select opt in "iOS 8.4.1" "iOS 6.1.3" "Other" "Back"; do
|
|
|
|
case $opt in
|
|
|
|
"iOS 8.4.1" ) Select841; break;;
|
|
|
|
"iOS 6.1.3" ) Select613; break;;
|
|
|
|
"Other" ) SelectOther; break;;
|
|
|
|
"Back" ) MainMenu; break;;
|
|
|
|
*) SelectVersion;;
|
|
|
|
esac
|
|
|
|
done
|
2020-03-31 07:46:59 +02:00
|
|
|
elif [[ $Mode != 'kDFU' ]]; then
|
2020-03-05 12:48:41 +01:00
|
|
|
select opt in "iOS 8.4.1" "iOS 6.1.3" "Back"; do
|
|
|
|
case $opt in
|
|
|
|
"iOS 8.4.1" ) Select841; break;;
|
|
|
|
"iOS 6.1.3" ) Select613; break;;
|
|
|
|
"Back" ) MainMenu; break;;
|
|
|
|
*) SelectVersion;;
|
|
|
|
esac
|
|
|
|
done
|
2020-03-31 07:46:59 +02:00
|
|
|
else
|
|
|
|
Select841
|
2020-03-05 12:48:41 +01:00
|
|
|
fi
|
|
|
|
elif [[ $Mode == 'Downgrade' ]]; then
|
2020-03-23 07:35:04 +01:00
|
|
|
echo "[Input] Select iOS version:"
|
2020-03-05 12:48:41 +01:00
|
|
|
select opt in "iOS 8.4.1" "Other" "Back"; do
|
|
|
|
case $opt in
|
|
|
|
"iOS 8.4.1" ) Select841; break;;
|
|
|
|
"Other" ) SelectOther; break;;
|
|
|
|
"Back" ) MainMenu; break;;
|
|
|
|
*) SelectVersion;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
else
|
|
|
|
Select841
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function Select841 {
|
|
|
|
echo "iOS 8.4.1 $Mode"
|
2020-03-31 07:46:59 +02:00
|
|
|
iBSS="iBSS.$HWModelLower.RELEASE"
|
|
|
|
DowngradeVer="8.4.1"
|
2019-11-22 11:48:41 +01:00
|
|
|
DowngradeBuildVer="12H321"
|
2020-03-05 12:48:41 +01:00
|
|
|
Action
|
|
|
|
}
|
|
|
|
|
|
|
|
function Select613 {
|
|
|
|
echo "iOS 6.1.3 $Mode"
|
2020-03-31 07:46:59 +02:00
|
|
|
iBSS="iBSS.${HWModelLower}ap.RELEASE"
|
|
|
|
DowngradeVer="6.1.3"
|
2020-03-05 12:48:41 +01:00
|
|
|
DowngradeBuildVer="10B329"
|
|
|
|
Action
|
|
|
|
}
|
|
|
|
|
|
|
|
function SelectOther {
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "Other $Mode"
|
2020-03-31 07:46:59 +02:00
|
|
|
iBSS="iBSS.$HWModelLower.RELEASE"
|
2020-03-05 12:48:41 +01:00
|
|
|
NotOTA=1
|
2020-03-10 03:55:04 +01:00
|
|
|
read -p "[Input] Path to IPSW (drag IPSW to terminal window): " IPSW
|
2020-03-10 14:19:08 +01:00
|
|
|
IPSW="$(basename "$IPSW" .ipsw)"
|
2020-03-10 03:55:04 +01:00
|
|
|
read -p "[Input] Path to SHSH (drag SHSH to terminal window): " SHSH
|
2020-03-31 07:46:59 +02:00
|
|
|
Action
|
2019-11-22 11:48:41 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 12:48:41 +01:00
|
|
|
function Action {
|
2020-03-31 07:46:59 +02:00
|
|
|
Firmware=resources/firmware/${ProductType}/${DowngradeBuildVer}
|
|
|
|
IV=$(cat $Firmware/iv)
|
|
|
|
Key=$(cat $Firmware/key)
|
|
|
|
|
2020-03-05 12:48:41 +01:00
|
|
|
if [[ $Mode == 'Downgrade' ]]; then
|
2020-01-08 00:17:00 +01:00
|
|
|
Downgrade
|
2020-03-05 12:48:41 +01:00
|
|
|
elif [[ $Mode == 'SaveOTABlobs' ]]; then
|
|
|
|
SaveOTABlobs
|
2020-03-10 03:55:04 +01:00
|
|
|
elif [[ $Mode == 'kDFU' ]]; then
|
|
|
|
kDFU
|
2019-11-22 11:48:41 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-11-23 05:15:35 +01:00
|
|
|
function SaveOTABlobs {
|
2020-03-31 07:46:59 +02:00
|
|
|
BuildManifest="resources/manifests/BuildManifest_${ProductType}_${DowngradeVer}.plist"
|
|
|
|
echo "[Log] Saving $DowngradeVer blobs with tsschecker..."
|
|
|
|
env "LD_PRELOAD=libcurl.so.3" resources/tools/tsschecker_$platform -d $ProductType -i $DowngradeVer -o -s -e $UniqueChipID -m $BuildManifest
|
|
|
|
SHSH=$(ls ${UniqueChipID}_${ProductType}_${DowngradeVer}-*.shsh2)
|
2020-03-10 14:19:08 +01:00
|
|
|
if [ ! -e "$SHSH" ]; then
|
2020-03-31 07:46:59 +02:00
|
|
|
echo "[Error] Saving $DowngradeVer blobs failed. Please run the script again"
|
|
|
|
echo "It is also possible that $DowngradeVer for $ProductType is no longer signed"
|
2019-11-22 11:48:41 +01:00
|
|
|
exit
|
|
|
|
fi
|
2020-03-29 05:53:53 +02:00
|
|
|
mkdir -p saved/shsh 2>/dev/null
|
|
|
|
cp "$SHSH" saved/shsh
|
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-03-13 05:12:49 +01:00
|
|
|
# Downloading 8.4.1 iBSS for "other" downgrades
|
|
|
|
# This is because this script only provides 8.4.1 iBSS IV and Keys
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Downloading iBSS..."
|
2020-03-31 07:46:59 +02:00
|
|
|
resources/tools/pzb_$platform -g Firmware/dfu/${iBSS}.dfu -o $iBSS.dfu $(cat $Firmware/url)
|
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
|
|
|
|
echo "[Log] Decrypting iBSS..."
|
2020-03-31 07:46:59 +02:00
|
|
|
echo "IV = ${!IV}"
|
|
|
|
echo "Key = ${!Key}"
|
|
|
|
resources/tools/xpwntool_$platform saved/$ProductType/$iBSS.dfu tmp/iBSS.dec -k ${!Key} -iv ${!IV} -decrypt
|
2019-11-22 11:48:41 +01:00
|
|
|
dd bs=64 skip=1 if=tmp/iBSS.dec of=tmp/iBSS.dec2
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Patching iBSS..."
|
2020-03-02 08:20:47 +01:00
|
|
|
bspatch tmp/iBSS.dec2 tmp/pwnediBSS resources/patches/$iBSS.patch
|
2020-03-13 05:12:49 +01:00
|
|
|
|
|
|
|
# Regular kloader only works on iOS 6 to 9, so other versions are provided for iOS 5 and 10
|
2019-12-15 04:52:10 +01:00
|
|
|
if [[ $VersionDetect == 1 ]]; then
|
2020-03-10 03:55:04 +01:00
|
|
|
kloader='kloader_hgsp'
|
2019-12-15 04:52:10 +01:00
|
|
|
elif [[ $VersionDetect == 5 ]]; then
|
2020-03-10 03:55:04 +01:00
|
|
|
kloader='kloader5'
|
2019-11-22 11:48:41 +01:00
|
|
|
else
|
2020-03-10 03:55:04 +01:00
|
|
|
kloader='kloader'
|
2019-11-22 11:48:41 +01:00
|
|
|
fi
|
|
|
|
|
2019-12-15 04:52:10 +01:00
|
|
|
if [[ $VersionDetect == 1 ]]; then
|
2020-03-13 05:12:49 +01:00
|
|
|
# SSH is unreliable/not working on iOS 10 devices, so ifuse+MTerminal is used instead
|
|
|
|
# It's less convenient, but it should work every time
|
2020-03-10 03:55:04 +01:00
|
|
|
if [ ! $(which ifuse) ]; then
|
|
|
|
echo "[Error] ifuse not found. Please re-install dependencies and try again"
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "For macOS systems, install osxfuse and ifuse with brew"
|
2020-03-10 03:55:04 +01:00
|
|
|
exit
|
|
|
|
fi
|
2020-03-01 20:47:48 +01:00
|
|
|
WifiAddr=$(ideviceinfo -s | grep 'WiFiAddress' | cut -c 14-)
|
2019-11-22 11:48:41 +01:00
|
|
|
WifiAddrDecr=$(echo $(printf "%x\n" $(expr $(printf "%d\n" 0x$(echo "${WifiAddr}" | tr -d ':')) - 1)) | sed 's/\(..\)/\1:/g;s/:$//')
|
2020-01-08 00:28:11 +01:00
|
|
|
echo '#!/bin/bash' > tmp/pwn.sh
|
|
|
|
echo "nvram wifiaddr=$WifiAddrDecr
|
|
|
|
chmod 755 kloader_hgsp
|
|
|
|
./kloader_hgsp pwnediBSS" >> tmp/pwn.sh
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Mounting device with ifuse..."
|
2020-03-13 05:12:49 +01:00
|
|
|
mkdir mount
|
2020-03-08 11:59:22 +01:00
|
|
|
ifuse mount
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Copying stuff to device..."
|
2020-03-08 11:59:22 +01:00
|
|
|
cp "tmp/pwn.sh" "resources/tools/$kloader" "tmp/pwnediBSS" "mount/"
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Unmounting device..."
|
2020-03-08 11:59:22 +01:00
|
|
|
sudo umount mount
|
2019-11-22 11:48:41 +01:00
|
|
|
echo
|
2020-03-10 16:07:11 +01:00
|
|
|
echo "[Log] Open MTerminal and run these commands:"
|
2019-11-22 11:48:41 +01:00
|
|
|
echo
|
2020-01-08 00:17:00 +01:00
|
|
|
echo '$ su'
|
2019-11-22 11:48:41 +01:00
|
|
|
echo "(enter root password, default is 'alpine')"
|
2020-01-08 00:17:00 +01:00
|
|
|
echo "# cd Media"
|
2020-01-08 00:28:11 +01:00
|
|
|
echo "# chmod +x pwn.sh"
|
|
|
|
echo "# ./pwn.sh"
|
2019-11-22 11:48:41 +01:00
|
|
|
else
|
2020-03-13 05:12:49 +01:00
|
|
|
# SSH: Send kloader and pwnediBSS to device root and run kloader as root
|
2019-11-22 11:48:41 +01:00
|
|
|
echo "Make sure SSH is installed and working on the device!"
|
2020-03-05 12:48:41 +01:00
|
|
|
echo "Please enter Wi-Fi IP address of device for SSH connection"
|
2020-03-10 16:07:11 +01:00
|
|
|
read -p "[Input] IP Address: " IPAddress
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Coonecting to device via SSH... Please enter root password when prompted (default is 'alpine')"
|
|
|
|
echo "[Log] Copying stuff to device..."
|
2020-03-02 08:20:47 +01:00
|
|
|
scp resources/tools/$kloader tmp/pwnediBSS root@$IPAddress:/
|
2020-03-09 07:24:45 +01:00
|
|
|
if [ $? == 1 ]; then
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Error] Cannot connect to device via SSH. Please check your ~/.ssh/known_hosts file and try again"
|
2020-03-09 07:24:45 +01:00
|
|
|
exit
|
|
|
|
fi
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Entering kDFU mode..."
|
2020-03-02 08:20:47 +01:00
|
|
|
ssh root@$IPAddress "chmod 755 /$kloader && /$kloader /pwnediBSS" &
|
2019-11-22 11:48:41 +01:00
|
|
|
fi
|
2020-01-08 00:17:00 +01:00
|
|
|
echo
|
2019-11-22 11:48:41 +01:00
|
|
|
echo "Press home/power button once when screen goes black on the device"
|
2019-12-15 04:52:10 +01:00
|
|
|
FindDFU
|
|
|
|
}
|
2019-11-22 11:48:41 +01:00
|
|
|
|
2019-12-15 04:52:10 +01:00
|
|
|
function FindDFU {
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Finding device in DFU mode..."
|
2019-12-15 04:52:10 +01:00
|
|
|
while [[ $DFUDevice != 1 ]]; do
|
|
|
|
DFUDevice=$(lsusb | grep -c "1227")
|
2019-11-22 11:48:41 +01:00
|
|
|
sleep 2
|
|
|
|
done
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Found device in DFU mode."
|
2019-11-22 11:48:41 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 12:48:41 +01:00
|
|
|
function Downgrade {
|
2020-03-29 05:53:53 +02:00
|
|
|
# Firmware keys for 8.4.1 and 6.1.3
|
2020-03-22 01:37:31 +01:00
|
|
|
rm -rf resources/firmware
|
2020-03-23 07:35:04 +01:00
|
|
|
echo "[Log] Downloading firmware keys..."
|
2020-03-22 01:37:31 +01:00
|
|
|
curl -L https://github.com/LukeZGD/32bit-OTA-Downgrader/archive/firmware.zip -o tmp/firmware.zip
|
|
|
|
unzip -q tmp/firmware.zip -d tmp
|
|
|
|
mkdir resources/firmware
|
2020-03-31 07:46:59 +02:00
|
|
|
mv tmp/32bit-OTA-Downgrader-firmware/* resources/firmware
|
2020-03-08 11:59:22 +01:00
|
|
|
|
2020-03-05 12:48:41 +01:00
|
|
|
if [ ! $NotOTA ]; then
|
|
|
|
SaveOTABlobs
|
2020-03-31 07:46:59 +02:00
|
|
|
IPSW="${ProductType}_${DowngradeVer}_${DowngradeBuildVer}_Restore"
|
2020-03-10 14:19:08 +01:00
|
|
|
if [ ! -e "$IPSW.ipsw" ]; then
|
2020-03-31 07:46:59 +02:00
|
|
|
echo "[Log] iOS $DowngradeVer IPSW is missing, downloading IPSW..."
|
|
|
|
curl -L $(cat $Firmware/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-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Verifying IPSW..."
|
2020-03-31 07:46:59 +02:00
|
|
|
SHA1IPSW=$(cat $Firmware/sha1sum)
|
2020-03-19 14:04:06 +01:00
|
|
|
SHA1IPSWL=$(sha1sum "$IPSW.ipsw" | awk '{print $1}')
|
|
|
|
if [ $SHA1IPSW != $SHA1IPSWL ]; then
|
2020-03-31 07:46:59 +02:00
|
|
|
echo "[Error] SHA1 of IPSW does not match. Please run the script again"
|
|
|
|
exit
|
2020-03-19 14:04:06 +01:00
|
|
|
fi
|
|
|
|
echo "[Log] Extracting iBSS from IPSW..."
|
2020-03-29 05:53:53 +02:00
|
|
|
mkdir -p saved/$ProductType 2>/dev/null
|
2020-03-29 07:05:45 +02:00
|
|
|
unzip -o -j "$IPSW.ipsw" Firmware/dfu/$iBSS.dfu -d saved/$ProductType
|
2019-11-22 11:48:41 +01:00
|
|
|
fi
|
2020-03-05 12:48:41 +01:00
|
|
|
|
2020-03-10 03:55:04 +01:00
|
|
|
if [ ! $kDFUManual ]; then
|
2020-03-09 07:24:45 +01:00
|
|
|
kDFU
|
|
|
|
fi
|
2020-03-05 12:48:41 +01:00
|
|
|
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Extracting IPSW..."
|
2020-03-10 16:07:11 +01:00
|
|
|
unzip -q "$IPSW.ipsw" -d "$IPSW/"
|
2020-03-10 03:55:04 +01:00
|
|
|
|
|
|
|
echo "[Log] Preparing for futurerestore (starting local server)..."
|
2020-03-05 12:48:41 +01:00
|
|
|
cd resources
|
2020-03-29 07:05:45 +02:00
|
|
|
sudo bash -c "python3 -m http.server 80 &"
|
2020-03-05 12:48:41 +01:00
|
|
|
cd ..
|
|
|
|
|
2020-03-29 05:53:53 +02:00
|
|
|
if [ $Baseband == 0 ]; then
|
|
|
|
echo "[Log] Device $ProductType has no baseband"
|
|
|
|
echo "[Log] Proceeding to futurerestore..."
|
|
|
|
sudo env "LD_PRELOAD=libcurl.so.3" resources/tools/futurerestore_$platform -t "$SHSH" --no-baseband --use-pwndfu "$IPSW.ipsw"
|
|
|
|
else
|
|
|
|
if [ ! -e saved/$ProductType/*.bbfw ]; then
|
|
|
|
echo "[Log] Downloading baseband..."
|
2020-03-31 07:46:59 +02:00
|
|
|
resources/tools/pzb_$platform -g Firmware/$Baseband -o $Baseband $BasebandURL
|
2020-03-29 05:53:53 +02:00
|
|
|
resources/tools/pzb_$platform -g BuildManifest.plist -o BuildManifest.plist $BasebandURL
|
|
|
|
mkdir -p saved/$ProductType 2>/dev/null
|
|
|
|
cp $(ls *.bbfw) 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-03-29 05:53:53 +02:00
|
|
|
if [ ! -e *.bbfw ]; then
|
|
|
|
echo "[Error] Downloading baseband failed!"
|
|
|
|
echo "Your device is still in kDFU mode, you may run the script again"
|
|
|
|
echo "If you continue, futurerestore can attempt to download the baseband again"
|
|
|
|
read -p "[Input] Continue anyway? (y/N)" Continue
|
|
|
|
if [[ $Continue == y ]] || [[ $Continue == Y ]]; then
|
|
|
|
echo "[Log] Proceeding to futurerestore..."
|
|
|
|
sudo env "LD_PRELOAD=libcurl.so.3" resources/tools/futurerestore_$platform -t "$SHSH" --latest-baseband --use-pwndfu "$IPSW.ipsw"
|
|
|
|
else
|
|
|
|
exit
|
|
|
|
fi
|
2020-03-05 12:48:41 +01:00
|
|
|
fi
|
2020-03-29 05:53:53 +02:00
|
|
|
if [[ $Continue != y ]] && [[ $Continue != Y ]]; then
|
|
|
|
echo "[Log] Proceeding to futurerestore..."
|
|
|
|
sudo env "LD_PRELOAD=libcurl.so.3" resources/tools/futurerestore_$platform -t "$SHSH" -b $(ls *.bbfw) -p BuildManifest.plist --use-pwndfu "$IPSW.ipsw"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "[Log] futurerestore done!"
|
|
|
|
echo "[Log] Stopping local server..."
|
2020-03-29 07:05:45 +02:00
|
|
|
ps aux | awk '/python3/ {print "sudo kill -9 "$2" 2>/dev/null"}' | bash
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Downgrade script done!"
|
2020-03-05 12:48:41 +01:00
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2020-01-08 00:17:00 +01:00
|
|
|
function InstallDependencies {
|
|
|
|
echo "Install Dependencies"
|
2019-12-04 08:11:24 +01:00
|
|
|
|
2020-03-09 02:30:19 +01:00
|
|
|
. /etc/os-release 2>/dev/null
|
2020-01-08 00:17:00 +01:00
|
|
|
if [[ $(which pacman) ]] || [[ $NAME == "Arch Linux" ]]; then
|
2020-02-04 16:33:45 +01:00
|
|
|
Arch
|
2020-01-08 00:17:00 +01:00
|
|
|
elif [[ $NAME == "Ubuntu" ]] && [[ $VERSION_ID == "16.04" ]]; then
|
2019-12-04 08:11:24 +01:00
|
|
|
Ubuntu
|
2020-01-08 00:17:00 +01:00
|
|
|
elif [[ $(which apt) ]] || [[ $NAME == "Ubuntu" ]] && [[ $VERSION_ID == "18.04" ]]; then
|
2019-12-04 08:11:24 +01:00
|
|
|
Ubuntu
|
|
|
|
Ubuntu1804
|
2020-01-08 00:17:00 +01:00
|
|
|
elif [[ $OSTYPE == "darwin"* ]]; then
|
2020-02-04 16:33:45 +01:00
|
|
|
macOS
|
2019-12-04 08:11:24 +01:00
|
|
|
else
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Input] Distro not detected/supported. Please select manually"
|
2020-02-04 16:33:45 +01:00
|
|
|
select opt in "Ubuntu Xenial" "Ubuntu Bionic" "Arch Linux" "macOS"; do
|
2019-12-04 08:11:24 +01:00
|
|
|
case $opt in
|
2020-02-04 16:33:45 +01:00
|
|
|
"Ubuntu Xenial" ) Ubuntu; break;;
|
|
|
|
"Ubuntu Bionic" ) Ubuntu; Ubuntu1804; break;;
|
|
|
|
"Arch Linux" ) Arch; break;;
|
|
|
|
"macOS" ) macOS; break;;
|
2019-12-04 08:11:24 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Log] Install script done! Please run the script again to proceed"
|
2020-01-08 00:17:00 +01:00
|
|
|
}
|
|
|
|
|
2020-02-04 16:33:45 +01:00
|
|
|
function Arch {
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Installing dependencies for Arch with pacman..."
|
2020-03-02 09:11:52 +01:00
|
|
|
sudo pacman -Sy --noconfirm bsdiff curl ifuse libcurl-compat libpng12 libzip openssh openssl-1.0 python unzip usbutils
|
2020-02-08 16:19:36 +01:00
|
|
|
sudo pacman -S --noconfirm libimobiledevice usbmuxd
|
2020-02-04 16:33:45 +01:00
|
|
|
sudo ln -sf /usr/lib/libzip.so.5 /usr/lib/libzip.so.4
|
|
|
|
}
|
|
|
|
|
|
|
|
function macOS {
|
2020-03-10 03:55:04 +01:00
|
|
|
read -p "[Input] Warning: macOS dependency install script is not fully tested and supported. Continue anyway? (y/N) " Continue
|
|
|
|
if [[ $Continue != y ]] && [[ $Continue != Y ]]; then
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Error] Please install these dependencies manually with brew to proceed:"
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "libimobiledevice, usbmuxd, libzip, lsusb, osxfuse, ifuse"
|
|
|
|
exit
|
|
|
|
fi
|
2020-02-04 16:33:45 +01:00
|
|
|
if [[ ! $(which brew) ]]; then
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Homebrew is not detected/installed, installing Homebrew..."
|
2020-03-05 12:48:41 +01:00
|
|
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
|
2020-02-04 16:33:45 +01:00
|
|
|
fi
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Installing dependencies for macOS with Homebrew..."
|
2020-02-04 16:33:45 +01:00
|
|
|
brew uninstall --ignore-dependencies usbmuxd
|
|
|
|
brew uninstall --ignore-dependencies libimobiledevice
|
|
|
|
brew install --HEAD usbmuxd
|
|
|
|
brew install --HEAD libimobiledevice
|
2020-03-06 00:46:08 +01:00
|
|
|
brew install libzip lsusb
|
|
|
|
brew cask install osxfuse
|
|
|
|
brew install ifuse
|
2020-02-04 16:33:45 +01:00
|
|
|
}
|
|
|
|
|
2020-01-08 00:17:00 +01:00
|
|
|
function Ubuntu {
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Running APT update..."
|
2020-01-08 00:17:00 +01:00
|
|
|
sudo apt update
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Installing dependencies for Ubuntu with APT..."
|
2020-03-02 09:11:52 +01:00
|
|
|
sudo apt -y install bsdiff curl ifuse libimobiledevice-utils libzip4 python3 usbmuxd
|
2020-01-08 00:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function Ubuntu1804 {
|
2020-03-19 14:04:06 +01:00
|
|
|
echo "[Log] Installing dependencies for Ubuntu 18.04 with APT..."
|
2020-01-08 00:17:00 +01:00
|
|
|
sudo apt -y install binutils
|
|
|
|
mkdir tmp
|
|
|
|
cd tmp
|
|
|
|
apt download -o=dir::cache=. libcurl3
|
|
|
|
ar x libcurl3* data.tar.xz
|
|
|
|
tar xf data.tar.xz
|
2020-03-15 03:43:07 +01:00
|
|
|
sudo cp usr/lib/x86_64-linux-gnu/libcurl.so.4.* /usr/lib/libcurl.so.3
|
|
|
|
curl -L http://mirrors.edge.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb -o libpng12.deb
|
2020-01-08 00:17:00 +01:00
|
|
|
sudo dpkg -i libpng12.deb
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
2020-03-13 05:12:49 +01:00
|
|
|
# --- MAIN SCRIPT STARTS HERE ---
|
2020-02-04 16:33:45 +01:00
|
|
|
|
2020-03-10 03:55:04 +01:00
|
|
|
trap Clean INT TERM EXIT
|
2020-02-24 15:52:46 +01:00
|
|
|
clear
|
|
|
|
echo "******* 32bit-OTA-Downgrader *******"
|
2020-03-05 12:48:41 +01:00
|
|
|
echo " Downgrade script by LukeZGD "
|
2020-02-24 15:52:46 +01:00
|
|
|
echo
|
|
|
|
|
|
|
|
if [[ $OSTYPE == "linux-gnu" ]]; then
|
2020-03-10 03:55:04 +01:00
|
|
|
platform='linux'
|
2020-02-24 15:52:46 +01:00
|
|
|
elif [[ $OSTYPE == "darwin"* ]]; then
|
2020-03-10 03:55:04 +01:00
|
|
|
platform='macos'
|
2020-02-24 15:52:46 +01:00
|
|
|
else
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Error] OSTYPE unknown/not supported"
|
|
|
|
echo "Supports Linux and macOS only"
|
2020-02-24 15:52:46 +01:00
|
|
|
exit
|
|
|
|
fi
|
2020-03-04 16:19:01 +01:00
|
|
|
if [[ ! $(ping -c1 google.com 2>/dev/null) ]]; then
|
2020-03-10 03:55:04 +01:00
|
|
|
echo "[Error] Please check your Internet connection before proceeding"
|
2020-03-04 16:19:01 +01:00
|
|
|
exit
|
|
|
|
fi
|
2020-03-15 03:43:07 +01:00
|
|
|
if [[ $(uname -m) != 'x86_64' ]]; then
|
|
|
|
echo "[Error] Only x86_64 distributions are supported. Use a 64-bit distro and try again"
|
|
|
|
exit
|
|
|
|
fi
|
2020-03-04 16:19:01 +01:00
|
|
|
|
2020-03-31 07:46:59 +02:00
|
|
|
HWModel=$(ideviceinfo -s | grep 'HWModel' | cut -c 16-)
|
|
|
|
HWModelLower=$(echo $HWModel | tr '[:upper:]' '[:lower:]' | sed 's/.\{2\}$//')
|
2020-03-01 20:47:48 +01:00
|
|
|
ProductType=$(ideviceinfo -s | grep 'ProductType' | cut -c 14-)
|
2020-03-02 11:08:15 +01:00
|
|
|
[ ! $ProductType ] && ProductType=$(ideviceinfo | grep 'ProductType' | cut -c 14-)
|
2020-03-31 07:46:59 +02:00
|
|
|
ProductVer=$(ideviceinfo -s | grep 'ProductVer' | cut -c 17-)
|
|
|
|
VersionDetect=$(echo $ProductVer | cut -c 1)
|
2020-03-01 20:47:48 +01:00
|
|
|
UniqueChipID=$(ideviceinfo -s | grep 'UniqueChipID' | cut -c 15-)
|
2020-02-24 15:52:46 +01:00
|
|
|
|
2020-03-10 03:55:04 +01:00
|
|
|
if [ ! $(which bspatch) ] || [ ! $(which ideviceinfo) ] || [ ! $(which lsusb) ] || [ ! $(which ssh) ] || [ ! $(which python3) ]; then
|
2020-01-08 00:17:00 +01:00
|
|
|
InstallDependencies
|
2019-12-04 08:11:24 +01:00
|
|
|
else
|
2020-03-02 08:20:47 +01:00
|
|
|
chmod +x resources/tools/*
|
2019-12-04 08:11:24 +01:00
|
|
|
MainMenu
|
2019-12-08 10:53:44 +01:00
|
|
|
fi
|