Update and fix various stuff (#107)

* Add FindDevice timeout and choice to continue

* Use libimobiledevice and libirecovery from Homebrew when detected

* Update depends.sh

* Detect ASi homebrew, add attempts for entering pwnREC

* Update depends.sh

* Fix some things
This commit is contained in:
LukeeGD 2021-07-12 22:36:51 +08:00 committed by GitHub
parent d3d27a0c4f
commit 073615b140
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 24 deletions

View File

@ -90,6 +90,8 @@
- Do not use USB-C to lightning cables as this can prevent a successful restore - Do not use USB-C to lightning cables as this can prevent a successful restore
- ipwndfu is unfortunately very unreliable on Linux, you may have to try multiple times (Linux users may also try in a live USB) - ipwndfu is unfortunately very unreliable on Linux, you may have to try multiple times (Linux users may also try in a live USB)
- If the script cannot find your device in pwnREC mode or gets stuck, you may have to start over by [force restarting](https://support.apple.com/en-ph/guide/iphone/iph8903c3ee6/ios) and re-entering recovery/DFU mode - If the script cannot find your device in pwnREC mode or gets stuck, you may have to start over by [force restarting](https://support.apple.com/en-ph/guide/iphone/iph8903c3ee6/ios) and re-entering recovery/DFU mode
- macOS users may have to install libimobiledevice and libirecovery from [Homebrew](https://brew.sh/) with this command: `brew install libimobiledevice libirecovery`
- The script will detect this automatically and will use the Homebrew versions of the tools
- Use an Intel PC/Mac as entering pwnDFU (checkm8) may be a lot more unreliable on AMD devices - Use an Intel PC/Mac as entering pwnDFU (checkm8) may be a lot more unreliable on AMD devices
- Other than the above, unfortunately there is not much else I can do to help regarding entering pwnDFU mode. - Other than the above, unfortunately there is not much else I can do to help regarding entering pwnDFU mode.
- **For 32-bit devices:** - **For 32-bit devices:**

View File

@ -1,10 +1,12 @@
#!/bin/bash #!/bin/bash
SetToolPaths() { SetToolPaths() {
local MPath="./resources/libimobiledevice_"
if [[ $OSTYPE == "linux"* ]]; then if [[ $OSTYPE == "linux"* ]]; then
. /etc/os-release 2>/dev/null . /etc/os-release 2>/dev/null
platform="linux" platform="linux"
platformver="$PRETTY_NAME" platformver="$PRETTY_NAME"
MPath+="$platform"
bspatch="$(which bspatch)" bspatch="$(which bspatch)"
futurerestore1="sudo LD_PRELOAD=./resources/lib/libcurl.so.3 LD_LIBRARY_PATH=./resources/lib ./resources/tools/futurerestore1_linux" futurerestore1="sudo LD_PRELOAD=./resources/lib/libcurl.so.3 LD_LIBRARY_PATH=./resources/lib ./resources/tools/futurerestore1_linux"
@ -19,6 +21,14 @@ SetToolPaths() {
elif [[ $OSTYPE == "darwin"* ]]; then elif [[ $OSTYPE == "darwin"* ]]; then
platform="macos" platform="macos"
platformver="${1:-$(sw_vers -productVersion)}" platformver="${1:-$(sw_vers -productVersion)}"
MPath+="$platform"
if [[ -e /usr/local/bin/idevicedate && -e /usr/local/bin/irecovery ]]; then
Log "Detected libimobiledevice and libirecovery installed from Homebrew (Intel Mac)"
MPath="/usr/local/bin"
elif [[ -e /opt/homebrew/bin/idevicedate && -e /opt/homebrew/bin/irecovery ]]; then
Log "Detected libimobiledevice and libirecovery installed from Homebrew (Apple Silicon)"
MPath="/opt/homebrew/bin"
fi
bspatch="/usr/bin/bspatch" bspatch="/usr/bin/bspatch"
futurerestore1="./resources/tools/futurerestore1_macos" futurerestore1="./resources/tools/futurerestore1_macos"
@ -32,11 +42,11 @@ SetToolPaths() {
tsschecker2="./resources/tools/tsschecker2_macos" tsschecker2="./resources/tools/tsschecker2_macos"
fi fi
git="$(which git)" git="$(which git)"
ideviceenterrecovery="./resources/libimobiledevice_$platform/ideviceenterrecovery" ideviceenterrecovery="$MPath/ideviceenterrecovery"
ideviceinfo="./resources/libimobiledevice_$platform/ideviceinfo" ideviceinfo="$MPath/ideviceinfo"
iproxy="./resources/libimobiledevice_$platform/iproxy" iproxy="$MPath/iproxy"
ipsw="./tools/ipsw_$platform" ipsw="./tools/ipsw_$platform"
irecoverychk="./resources/libimobiledevice_$platform/irecovery" irecoverychk="$MPath/irecovery"
irecovery="$irecoverychk" irecovery="$irecoverychk"
[[ $platform == "linux" ]] && irecovery="sudo LD_LIBRARY_PATH=./resources/lib $irecovery" [[ $platform == "linux" ]] && irecovery="sudo LD_LIBRARY_PATH=./resources/lib $irecovery"
partialzip="./resources/tools/partialzip_$platform" partialzip="./resources/tools/partialzip_$platform"
@ -130,6 +140,10 @@ InstallDepends() {
elif [[ $platform == "macos" ]]; then elif [[ $platform == "macos" ]]; then
xcode-select --install xcode-select --install
libimobiledevice=("https://github.com/libimobiledevice-win32/imobiledevice-net/releases/download/v1.3.14/libimobiledevice.1.2.1-r1116-osx-x64.zip" "328e809dea350ae68fb644225bbf8469c0f0634b") libimobiledevice=("https://github.com/libimobiledevice-win32/imobiledevice-net/releases/download/v1.3.14/libimobiledevice.1.2.1-r1116-osx-x64.zip" "328e809dea350ae68fb644225bbf8469c0f0634b")
Echo "* iOS-OTA-Downgrader provides a copy of libimobiledevice and libirecovery by default"
Echo "* In case that problems occur, try installing them from Homebrew"
Echo "* The script will detect this automatically and will use the Homebrew versions of the tools"
Echo "* Install using this command: 'brew install libimobiledevice libirecovery'"
else else
Error "Distro not detected/supported by the install script." "See the repo README for supported OS versions/distros" Error "Distro not detected/supported by the install script." "See the repo README for supported OS versions/distros"
@ -140,9 +154,11 @@ InstallDepends() {
fi fi
if [[ ! -d ../resources/libimobiledevice_$platform ]]; then if [[ ! -d ../resources/libimobiledevice_$platform ]]; then
Log "Downloading libimobiledevice..."
SaveFile ${libimobiledevice[0]} libimobiledevice.zip ${libimobiledevice[1]} SaveFile ${libimobiledevice[0]} libimobiledevice.zip ${libimobiledevice[1]}
mkdir ../resources/libimobiledevice_$platform mkdir ../resources/libimobiledevice_$platform
unzip libimobiledevice.zip -d ../resources/libimobiledevice_$platform Log "Extracting libimobiledevice..."
unzip -q libimobiledevice.zip -d ../resources/libimobiledevice_$platform
chmod +x ../resources/libimobiledevice_$platform/* chmod +x ../resources/libimobiledevice_$platform/*
fi fi

View File

@ -1,17 +1,29 @@
#!/bin/bash #!/bin/bash
FindDevice() { FindDevice() {
local DeviceIn
local i=0
local Timeout=999
local USB local USB
[[ $1 == "DFU" ]] && USB=1227 || USB=1281 [[ $1 == "DFU" ]] && USB=1227 || USB=1281
[[ ! -z $2 ]] && Timeout=3
Log "Finding device in $1 mode..." Log "Finding device in $1 mode..."
while [[ $DeviceState != "$1" ]]; do while (( $i < $Timeout )); do
[[ $platform == "linux" ]] && DeviceState=$(lsusb | grep -c $USB) [[ $($irecovery -q 2>/dev/null | grep "MODE" | cut -c 7-) == "$1" ]] && DeviceIn=1
[[ $platform == "macos" && $($irecovery -q 2>/dev/null | grep "MODE" | cut -c 7-) == "$1" ]] && DeviceState=1 if [[ $DeviceIn == 1 ]]; then
[[ $DeviceState == 1 ]] && DeviceState="$1" Log "Found device in $1 mode."
DeviceState="$1"
break
fi
sleep 1 sleep 1
((i++))
done done
Log "Found device in $1 mode."
if [[ $DeviceIn != 1 ]]; then
[[ $2 == "error" ]] && Error "Failed to find device in $1 mode. (Timed out)"
return 1
fi
} }
GetDeviceValues() { GetDeviceValues() {
@ -171,7 +183,7 @@ CheckM8() {
if [[ $pwnDFUDevice != 0 && $($irecovery -q | grep -c "PWND") != 1 ]]; then if [[ $pwnDFUDevice != 0 && $($irecovery -q | grep -c "PWND") != 1 ]]; then
echo -e "\n${Color_R}[Error] Failed to enter pwnDFU mode. Please run the script again: ./restore.sh Downgrade ${Color_N}" echo -e "\n${Color_R}[Error] Failed to enter pwnDFU mode. Please run the script again: ./restore.sh Downgrade ${Color_N}"
echo "${Color_Y}* This step may fail a lot, especially on Linux, and unfortunately there is nothing I can do about the low success rates. ${Color_N}" echo "${Color_Y}* This step may fail a lot, especially on Linux, and unfortunately there is nothing I can do about the low success rates. ${Color_N}"
echo "${Color_Y}* The only option is to make sure you are using an Intel or M1 device, and to try multiple times ${Color_N}" echo "${Color_Y}* The only option is to make sure you are using an Intel or Apple Silicon device, and to try multiple times ${Color_N}"
Echo "* For more details, read the \"Other Notes\" section of the README" Echo "* For more details, read the \"Other Notes\" section of the README"
exit 1 exit 1
elif [[ $pwnDFUDevice == 0 ]]; then elif [[ $pwnDFUDevice == 0 ]]; then
@ -208,7 +220,7 @@ Recovery() {
done done
echo echo
FindDevice "DFU" FindDevice "DFU" error
CheckM8 CheckM8
} }
@ -282,20 +294,29 @@ kDFU() {
} }
pwnREC() { pwnREC() {
local Attempt=1
if [[ $ProductType == "iPad4,4" || $ProductType == "iPad4,5" ]]; then if [[ $ProductType == "iPad4,4" || $ProductType == "iPad4,5" ]]; then
Log "iPad mini 2 device detected. Setting iBSS and iBEC to \"ipad4b\"" Log "iPad mini 2 device detected. Setting iBSS and iBEC to \"ipad4b\""
iBEC=$iBECb iBEC=$iBECb
iBSS=$iBSSb iBSS=$iBSSb
fi fi
Log "Entering pwnREC mode..."
Log "Sending iBSS..." while (( $Attempt < 4 )); do
$irecovery -f $IPSWCustom/Firmware/dfu/$iBSS.im4p Log "Entering pwnREC mode... (Attempt $Attempt)"
$irecovery -f $IPSWCustom/Firmware/dfu/$iBSS.im4p Log "Sending iBSS..."
Log "Sending iBEC..." $irecovery -f $IPSWCustom/Firmware/dfu/$iBSS.im4p
$irecovery -f $IPSWCustom/Firmware/dfu/$iBEC.im4p $irecovery -f $IPSWCustom/Firmware/dfu/$iBSS.im4p
sleep 5 Log "Sending iBEC..."
Echo "* If your device has backlight turned on, you may try unplugging and re-plugging in your device to attempt to continue" $irecovery -f $IPSWCustom/Firmware/dfu/$iBEC.im4p
Echo "* If not, you may have to force restart your device and start over entering pwnDFU mode again" sleep 3
Echo "* You can press Ctrl+C to cancel finding device" FindDevice "Recovery" timeout
FindDevice "Recovery" [[ $? == 0 ]] && break
((Attempt++))
done
if (( $Attempt == 4 )); then
Error "Failed to enter pwnREC mode. You may have to force restart your device and start over entering pwnDFU mode again" \
"macOS users may have to install libimobiledevice and libirecovery from Homebrew. For more details, read the \"Other Notes\" section of the README"
fi
} }

View File

@ -83,7 +83,7 @@ Main() {
fi fi
if [[ $platform == "macos" && $(uname -m) != "x86_64" ]]; then if [[ $platform == "macos" && $(uname -m) != "x86_64" ]]; then
Log "M1 Mac detected. Support is limited, proceed at your own risk." Log "Apple Silicon Mac detected. Support may be limited, proceed at your own risk."
elif [[ $(uname -m) != "x86_64" ]]; then elif [[ $(uname -m) != "x86_64" ]]; then
Error "Only 64-bit (x86_64) distributions are supported." Error "Only 64-bit (x86_64) distributions are supported."
fi fi