Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- ipsw_openssh=1 # OpenSSH will be added to jailbreak/custom IPSW if set to 1.
- device_rd_build="" # You can change the version of SSH Ramdisk and Pwned iBSS/iBEC here. (default is 10B329 for most devices)
- device_bootargs_default="pio-error=0 debug=0x2014e serial=3"
- device_disable_sudoloop=1
- jelbrek="../resources/jailbreak"
- sundance="../saved/SundanceInH2A"
- ssh_port=6414
- bash_test=$(echo -n 0)
- (( bash_test += 1 ))
- if [ "$bash_test" != "1" ] || [ -z $BASH_VERSION ]; then
- echo "[Error] Detected that script is not running with bash on runtime. Please run the script properly using bash."
- exit 1
- fi
- bash_ver=$(/usr/bin/env bash -c 'echo ${BASH_VERSINFO[0]}')
- print() {
- echo "${color_B}${1}${color_N}"
- }
- input() {
- echo "${color_Y}[Input] ${1}${color_N}"
- }
- log() {
- echo "${color_G}[Log] ${1}${color_N}"
- }
- warn() {
- echo "${color_Y}[WARNING] ${1}${color_N}"
- }
- error() {
- echo -e "${color_R}[Error] ${1}\n${color_Y}${*:2}${color_N}"
- exit 1
- }
- pause() {
- input "Press Enter/Return to continue (or press Ctrl+C to cancel)"
- read -s
- }
- exit_message() {
- echo
- print "* Save the terminal output now if needed. (macOS: Cmd+S, Linux: Ctrl+Shift+S)"
- if [[ -n $version_current && -n $git_hash ]]; then
- print "* Legacy iOS Kit $version_current ($git_hash)"
- else
- print "* Legacy iOS Kit"
- fi
- if [[ -n $platform ]]; then
- print "* Platform: $platform ($platform_ver - $platform_arch) $live_session_str"
- fi
- }
- clean() {
- exit_message
- kill $httpserver_pid $iproxy_pid $anisette_pid $sshfs_pid 2>/dev/null
- popd &>/dev/null
- [[ -d "$(dirname "$0")/tmp$$/" ]] && rm -rf "$(dirname "$0")/tmp$$/"* "$(dirname "$0")/tmp$$/"
- [[ $noclean == 1 ]] && return
- rm -rf "$(dirname "$0")/iP"*/
- if [[ $platform == "macos" && $(ls "$(dirname "$0")" | grep -v tmp$$ | grep -c tmp) == 0 &&
- $no_finder != 1 ]]; then
- killall -CONT AMPDevicesAgent AMPDeviceDiscoveryAgent MobileDeviceUpdater 2>/dev/null
- fi
- }
- clean_sudo() {
- clean
- [[ -d "$(dirname "$0")/tmp$$/" ]] && $sudo rm -rf "$(dirname "$0")/tmp$$/"* "$(dirname "$0")/tmp$$/"
- [[ $noclean == 1 ]] && return
- $sudo rm -rf "$(dirname "$0")/iP"*/ /tmp/futurerestore /tmp/*.json
- $sudo kill $sudoloop_pid 2>/dev/null
- }
- clean_usbmuxd() {
- [[ $platform != "linux" ]] && return
- if [[ $noclean != 1 ]]; then
- if [[ -z $device_disable_usbmuxd ]]; then
- echo
- log "Terminating own usbmuxd instance(s)"
- if [[ $live_session != 1 ]]; then
- print "* Enter your user password when prompted"
- print "* Your password input may not be visible, but it is still being entered."
- fi
- $sudo -v
- fi
- fi
- if [[ -z $device_disable_sudoloop ]]; then
- clean_sudo
- else
- clean
- fi
- [[ $noclean == 1 ]] && return
- $sudo killall -9 usbmuxd usbmuxd2 2>/dev/null
- sleep 1
- if [[ $(command -v restorecon) ]]; then
- $sudo restorecon /var/run/usbmuxd
- $sudo systemctl restart usbmuxd
- fi
- if [[ $(command -v systemctl) ]]; then
- $sudo systemctl restart usbmuxd 2>/dev/null
- elif [[ $(command -v rc-service) ]]; then
- $sudo rc-service usbmuxd start 2>/dev/null
- fi
- }
- display_help() {
- echo ' *** Legacy iOS Kit ***
- - Script by LukeZGD -
- Usage: ./restore.sh [Options]
- List of options:
- --debug Enable script debugging (set -x and debug mode)
- --device=<type> Specify device type
- --dfuhelper Launch to DFU Mode Helper only
- --disable-usbmuxd Disable use of own usbmuxd instance on Linux
- --enable-sudoloop Enable running some tools as root on Linux
- --ecid=<ecid> Specify device ECID
- --entry-device Enable manual device type and ECID entry
- --exit-recovery Attempt to exit recovery mode
- --kdfu Enter kDFU mode with the connected device
- --help Display this help message
- --no-color Disable colors for script output
- --no-finder Disable Finder device detection and keep it disabled after script exit
- To re-enable it, run the script without this flag and exit
- --no-device Enable no device mode
- --old-menu Use the old menus with number select and y/n
- --pwn Pwn the connected device
- --sshrd Enter SSH ramdisk mode
- --sshrd-menu Re-enter SSH ramdisk menu (device must be in SSH ramdisk mode)
- --use-usbmuxd2 Use usbmuxd2 instead of usbmuxd on Linux
- For 32-bit devices compatible with restores/downgrades (see README):
- --activation-records Enable dumping/stitching activation records
- --build-id=<build> Specify iOS build ID for SSH ramdisk/tether boot
- --bootargs=<bootargs> Specify custom bootargs for SSH ramdisk/tether boot
- --dead-bb Disable bbupdate completely without dumping/stitching baseband
- --disable-actrec Disable dumping/stitching activation records
- --disable-bbupdate Disable bbupdate and enable dumping/stitching baseband
- --ipsw-hacktivate Enable hacktivation for creating IPSW (iPhone 2G/3G/3GS only)
- --ipsw-verbose Enable verbose boot option (3GS and powdersn0w only)
- --jailbreak Enable jailbreak option
- --just-boot Tether boot the device (requires --build-id)
- --multipatch Enable multipatch to get past "gas gauge" error (aka error 29 in iTunes)
- This patch also attempts to get past "invalid ticket" error
- --memory Enable memory option for creating IPSW
- --pwned-recovery Assume that device is in pwned recovery mode (experimental)
- --ra1n-timeout=<value> Set RA1N_ABORT_TIMEOUT for litera1n A6(X) (recommended: 1000000)
- --skip-first Skip first restore and flash part 2 IPSW only for powdersn0w 4.2.x and lower
- --skip-ibss Assume that pwned iBSS has already been sent to the device
- For 64-bit checkm8 devices compatible with pwned restores:
- --skip-blob Enable futurerestore skip blob option for OTA/onboard/factory blobs
- --use-dev Use dev branch of futurerestore nightly
- --use-pwndfu Enable futurerestore pwned restore option
- * Default IPSW path: <script location>/<name of IPSW file>.ipsw
- * Default SHSH path: <script location>/saved/shsh/<name of SHSH file>.shsh(2)
- '
- }
- tar2="$(command -v tar)"
- [[ $OSTYPE == "darwin"* ]] && tar2="/usr/bin/tar"
- unzip2="$(command -v unzip)"
- zip2="$(command -v zip)"
- tar() {
- $tar2 "$@" || error "An error occurred with the tar operation: $*"
- }
- unzip() {
- $unzip2 "$@" || error "An error occurred with the unzip operation: $*"
- }
- zip() {
- $zip2 "$@" || error "An error occurred with the zip operation: $*"
- }
- file_extract() {
- local archive="$1"
- local dest="$2"
- local arr=()
- if [[ $platform == "macos" ]]; then
- arr+=("-xzvf" "$archive")
- [[ -n $dest ]] && arr+=("-C" "$dest")
- tar "${arr[@]}"
- return
- fi
- arr+=("-o" "$archive")
- [[ -n $dest ]] && arr+=("-d" "$dest")
- unzip "${arr[@]}"
- }
- file_extract_from_archive() {
- local archive="$1"
- local file="$2"
- local dest="$3"
- [[ -z $dest ]] && dest=.
- local arr=()
- if [[ $platform == "macos" && $file != *"/"* ]]; then
- arr+=("-xzvOf" "$archive")
- arr+=("$file")
- tar "${arr[@]}" > "$dest/$file"
- return
- fi
- arr+=("-o" "-j" "$archive" "$file")
- [[ -n $dest ]] && arr+=("-d" "$dest")
- unzip "${arr[@]}"
- }
- # from https://unix.stackexchange.com/questions/146570/arrow-key-enter-menu#415155
- select_option() {
- if [[ $menu_old == 1 ]]; then
- select opt in "$@"; do
- selected=$((REPLY-1))
- break
- done
- return $selected
- fi
- # clear input buffer to prevent error
- if (( bash_ver > 3 )); then
- while read -s -t 0.01 -n 1; do :; done
- else
- local old=$(stty -g)
- stty -icanon -echo min 0 time 1
- dd bs=1 count=1000 if=/dev/tty of=/dev/null 2>/dev/null
- stty "$old"
- fi
- # little helpers for terminal print control and key input
- ESC=$( printf "\033")
- cursor_blink_on() { printf "$ESC[?25h"; }
- cursor_blink_off() { printf "$ESC[?25l"; }
- cursor_to() { printf "$ESC[$1;${2:-1}H"; }
- print_option() { printf " $1 "; }
- print_selected() { printf " ->$ESC[7m $1 $ESC[27m"; }
- get_cursor_row() { IFS=';' read -sdR -p $'\E[6n' ROW COL; echo ${ROW#*[}; }
- key_input() { read -s -n3 key 2>/dev/null >&2
- if [[ $key = $ESC[A ]]; then echo up; fi
- if [[ $key = $ESC[B ]]; then echo down; fi
- if [[ $key = "" ]]; then echo enter; fi; }
- # initially print empty new lines (scroll down if at bottom of screen)
- for opt; do printf "\n"; done
- # determine current screen position for overwriting the options
- local lastrow=`get_cursor_row`
- local startrow=$(($lastrow - $#))
- # ensure cursor and input echoing back on upon a ctrl+c during read -s
- trap "cursor_blink_on; stty echo; printf '\n'; exit" 2
- cursor_blink_off
- local selected=0
- while true; do
- # print options by overwriting the last lines
- local idx=0
- for opt; do
- cursor_to $(($startrow + $idx))
- if [ $idx -eq $selected ]; then
- print_selected "$opt"
- else
- print_option "$opt"
- fi
- ((idx++))
- done
- # user key control
- case `key_input` in
- enter) break;;
- up) ((selected--));
- if [ $selected -lt 0 ]; then selected=$(($# - 1)); fi;;
- down) ((selected++));
- if [ $selected -ge $# ]; then selected=0; fi;;
- esac
- done
- # cursor position back to normal
- cursor_to $lastrow
- printf "\n"
- cursor_blink_on
- return $selected
- }
- select_yesno() {
- local msg="Do you want to continue?"
- if [[ -n $1 ]]; then
- msg="$1"
- fi
- [[ $2 == 1 ]] && msg+=" (Y/n): " || msg+=" (y/N): "
- if [[ $menu_old == 1 ]]; then
- local opt
- while true; do
- read -p "$(input "$msg")" opt
- case $opt in
- [NnYy] ) break;;
- "" ) # select default if no y/n given
- [[ $2 == 1 ]] && opt='y' || opt='n'
- break
- ;;
- esac
- done
- if [[ $2 == 1 ]]; then # default is "yes" if $2 is set to 1
- [[ $opt == [Nn] ]] && return 0 || return 1
- fi
- # default is "no" otherwise
- [[ $opt == [Yy] ]] && return 1 || return 0
- fi
- local yesno=("No" "Yes") # default is "no" by default
- if [[ $2 == 1 ]]; then # default is "yes" if $2 is set to 1
- yesno=("Yes" "No")
- fi
- input "$msg"
- select_option "${yesno[@]}"
- local res=$?
- if [[ $2 == 1 ]]; then
- [[ $res == 0 ]] && return 1 || return 0
- fi
- return $res
- }
- set_tool_paths() {
- : '
- sets variables: platform, platform_ver, dir
- also checks architecture (linux) and macos version
- also set distro, debian_ver, ubuntu_ver, fedora_ver variables for linux
- list of tools set here:
- bspatch, jq, scp, ssh, sha1sum (for macos: shasum -a 1), zenity
- these ones "need" sudo for linux arm, not for others:
- futurerestore, gaster, idevicerestore, ipwnder, irecovery
- tools set here will be executed using:
- $name_of_tool
- the rest of the tools not listed here will be executed using:
- "$dir/$name_of_tool"
- '
- if [[ $OSTYPE == "linux"* ]]; then
- source /etc/os-release
- platform="linux"
- platform_ver="$PRETTY_NAME"
- dir="../bin/linux/"
- # architecture check
- platform_arch="$(uname -m)"
- if [[ $platform_arch == "aarch64" ]]; then
- platform_arch="arm64"
- elif [[ $platform_arch != "x86_64" ]]; then
- error "Your architecture ($platform_arch) is not supported."
- fi
- dir+="$platform_arch"
- platform_cpu="$(awk -F': ' '/model name/{print $2; exit}' /proc/cpuinfo)"
- # version check
- if [[ -n $UBUNTU_CODENAME ]]; then
- case $UBUNTU_CODENAME in
- "jammy" | "kinetic" ) ubuntu_ver=22;;
- "lunar" | "mantic" ) ubuntu_ver=23;;
- "noble" | "oracular" ) ubuntu_ver=24;;
- "plucky" | "questing" ) ubuntu_ver=25;;
- "resolute" ) ubuntu_ver=26;;
- esac
- if [[ -z $ubuntu_ver ]]; then
- source /etc/upstream-release/lsb-release 2>/dev/null
- ubuntu_ver="$(echo "$DISTRIB_RELEASE" | cut -c -2)"
- fi
- if [[ -z $ubuntu_ver ]]; then
- ubuntu_ver="$(echo "$VERSION_ID" | cut -c -2)"
- fi
- elif [[ -e /etc/debian_version ]]; then
- debian_ver=$(cat /etc/debian_version)
- case $debian_ver in
- *"sid" | "kali"* ) debian_ver="sid";;
- * ) debian_ver="$(echo "$debian_ver" | cut -c -2)";;
- esac
- elif [[ $ID == "fedora" || $ID_LIKE == "fedora" || $ID == "nobara" ]]; then
- fedora_ver=$VERSION_ID
- fi
- # distro check
- if [[ $ID == "steamos" ]]; then
- distro="steamos"
- elif [[ $ID == "arch" || $ID_LIKE == "arch" || $ID == "artix" || $ID == "cachyos" ]]; then
- distro="arch"
- elif (( ubuntu_ver >= 22 )) || (( debian_ver >= 12 )) || [[ $debian_ver == "sid" ]]; then
- distro="debian"
- elif (( fedora_ver >= 40 )); then
- distro="fedora"
- if [[ $(command -v rpm-ostree) ]]; then
- distro="fedora-atomic"
- fi
- elif [[ $ID == "opensuse-tumbleweed" ]]; then
- distro="opensuse"
- elif [[ $ID == "gentoo" || $ID_LIKE == "gentoo" || $ID == "pentoo" ]]; then
- distro="gentoo"
- elif [[ $ID == "void" ]]; then
- distro="void"
- elif [[ -n $ubuntu_ver || -n $debian_ver || -n $fedora_ver ]]; then
- error "Your distro version ($platform_ver - $platform_arch) is not supported. See the repo README for supported OS versions/distros"
- else
- warn "Your distro ($platform_ver - $platform_arch) is not detected/supported. See the repo README for supported OS versions/distros"
- print "* You may still continue, but you will need to install required packages and libraries manually as needed."
- sleep 5
- pause
- fi
- bspatch="$dir/bspatch"
- PlistBuddy="$dir/PlistBuddy"
- PlistBuddy2="${PlistBuddy}2"
- sha1sum="$(command -v sha1sum)"
- tsschecker="$dir/tsschecker"
- zenity="$(command -v zenity)"
- scp2="$dir/scp"
- ssh2="$dir/ssh"
- cp $ssh2 . 2>/dev/null
- chmod +x ssh 2>/dev/null
- export LD_LIBRARY_PATH="$dir/lib"
- # live cd/usb check
- if [[ $(id -u $USER) == 999 || $USER == "liveuser" || $(df | grep -c "/cow") != 0 ]] ||
- [[ $(hostname 2>/dev/null) == *"ubuntu" && $USER == *"ubuntu" ]] ||
- [[ $(hostname 2>/dev/null) == "mint" && $USER == "mint" ]]; then
- live_session=1
- live_session_str="Live session"
- log "Linux Live session detected."
- if [[ $(pwd) == "/home/"* ]]; then
- df . -h # just display items
- if [[ $(lsblk -o label | grep -c "casper-rw") == 1 || $(lsblk -o label | grep -c "persistence") == 1 ]]; then
- log "Detected Legacy iOS Kit running on persistent storage."
- live_session_str+=" - Persistent storage"
- else
- warn "Detected Legacy iOS Kit running on temporary storage."
- print "* You may run out of space and get errors during the restore process."
- print "* Please move Legacy iOS Kit to a drive that is NOT used for the live USB."
- print "* This may mean using another external HDD/flash drive to store Legacy iOS Kit on."
- print "* To use one USB drive only, create the live USB using Rufus with Persistent Storage enabled."
- sleep 5
- pause
- live_session_str+=" - Temporary storage"
- fi
- fi
- fi
- # if "/media/" is detected in pwd, warn user of possible permission issues
- if [[ $(pwd) == *"/media/"* ]]; then
- warn "You might get permission errors like \"Permission denied\" on getting device info."
- print "* If this is the case, try moving Legacy iOS Kit to the Desktop or Documents folder."
- live_session_str+=" - External storage"
- fi
- if [[ $device_argmode == "none" ]]; then
- device_disable_sudoloop=1
- device_disable_usbmuxd=1
- fi
- if [[ -z $device_disable_sudoloop ]]; then
- device_sudoloop=1 # Run some tools as root for device detection if set to 1. (for Linux)
- trap "clean_sudo" EXIT
- fi
- sudo="/usr/bin/sudo"
- if [[ $($sudo -V 2>&1) == "sudo-rs"* ]]; then
- if [[ -z $device_disable_sudoloop && -z $device_disable_usbmuxd ]]; then
- log "sudo-rs detected. Switching to sudo.ws"
- fi
- sudo+=".ws"
- fi
- if [[ $device_sudoloop == 1 || $live_session == 1 ]]; then
- if [[ $live_session != 1 ]]; then
- print "* Enter your user password when prompted"
- print "* Your password input may not be visible, but it is still being entered."
- fi
- $sudo -v
- #(while true; do $sudo -v; sleep 60; done) &
- sudoloop_pid=$!
- a6meowing="$sudo "
- futurerestore="$sudo "
- gaster="$sudo "
- idevicerestore="$sudo LD_LIBRARY_PATH=$dir/lib "
- irecovery="$sudo "
- irecovery2="$sudo "
- irecovery3="$sudo "
- primepwn="$sudo "
- fi
- if [[ $(command -v gio) && ! -e ../resources/new && $device_argmode != "none" ]]; then
- log "gio detected. Unmounting all iOS devices with it"
- gio mount -l | awk '/gphoto2:\/\/Apple_Inc|afc:\/\// {print $NF}' | while read -r m; do gio mount -u "$m"; done
- fi
- if [[ $device_argmode != "none" && $device_disable_usbmuxd != 1 && ! -e ../resources/new ]]; then
- trap "clean_usbmuxd" EXIT
- if [[ $othertmp == 0 ]]; then
- if [[ $live_session != 1 && $device_disable_sudoloop == 1 ]]; then
- print "* Enter your user password when prompted"
- print "* Your password input may not be visible, but it is still being entered."
- fi
- if [[ $(command -v systemctl) ]]; then
- $sudo systemctl stop usbmuxd 2>/dev/null
- elif [[ $(command -v rc-service) ]]; then
- $sudo rc-service usbmuxd zap 2>/dev/null
- else
- $sudo killall -9 usbmuxd usbmuxd2 2>/dev/null
- fi
- #$sudo killall usbmuxd 2>/dev/null
- #sleep 1
- if [[ $use_usbmuxd2 == 1 ]]; then
- log "Running usbmuxd2"
- $sudo -b $dir/usbmuxd2 &>../saved/usbmuxd2.log
- else
- log "Running usbmuxd"
- $sudo -b $dir/usbmuxd -pf &>../saved/usbmuxd.log
- fi
- else
- warn "Detected existing tmp folder(s), there might be other Legacy iOS Kit instance(s) running"
- warn "Not running usbmuxd"
- fi
- fi
- if [[ ! -e ../resources/new ]]; then
- install_udev_rules
- fi
- gaster+="$dir/gaster"
- elif [[ $(uname -m) == "iP"* ]]; then
- error "Running Legacy iOS Kit on iOS is not supported (yet)" \
- "* Supported platforms: Linux, macOS"
- elif [[ $OSTYPE == "darwin"* ]]; then
- platform="macos"
- platform_ver="${1:-$(sw_vers -productVersion)}"
- IFS='.' read -r mac_majver mac_minver mac_patch <<< "$platform_ver"
- dir="../bin/macos"
- platform_arch="$(uname -m)"
- [[ $(sysctl -in hw.optional.arm64) == 1 ]] && platform_arch="arm64"
- [[ $platform_arch == "arm64" ]] && dir+="/arm64"
- # macos checks
- if [[ $mac_majver == 10 ]]; then
- if (( mac_minver < 11 )); then
- error "Your macOS version ($platform_ver - $platform_arch) is not supported." \
- "* Supported macOS versions are 10.11 and newer."
- elif [[ $mac_minver == 11 ]]; then
- mac_cocoa=1
- fi
- case $mac_minver in
- 11 ) mac_name="El Capitan";;
- 12 ) mac_name="Sierra";;
- 13 ) mac_name="High Sierra";;
- 14 ) mac_name="Mojave";;
- 15 ) mac_name="Catalina";;
- esac
- fi
- case $mac_majver in
- 11 ) mac_name="Big Sur";;
- 12 ) mac_name="Monterey";;
- 13 ) mac_name="Ventura";;
- 14 ) mac_name="Sonoma";;
- 15 ) mac_name="Sequoia";;
- 26 ) mac_name="Tahoe";;
- esac
- if [[ -n $mac_name ]]; then
- platform_ver="$(sysctl -n hw.model) - $mac_name $platform_ver"
- fi
- if [[ $(xcode-select -p 1>/dev/null; echo $?) != 0 ]]; then
- local error_msg="* You need to install Xcode Command Line Tools with this command: xcode-select --install"
- error_msg+=$'\n* If the above command does not work, try this: sudo xcode-select --reset'
- error_msg+=$'\n* Please read the wiki and install the requirements needed: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/How-to-Use'
- xcode-select --install
- error "Xcode Command Line Tools not installed, cannot continue." "$error_msg"
- fi
- /usr/bin/xattr -cr ../bin/macos
- bspatch="$(command -v bspatch)"
- cocoadialog="$(command -v cocoadialog)"
- gaster+="../bin/macos/gaster"
- PlistBuddy="/usr/libexec/PlistBuddy"
- PlistBuddy2="$PlistBuddy"
- sha1sum="$(command -v shasum) -a 1"
- tsschecker="../bin/macos/tsschecker"
- zenity="$dir/zenity"
- scp2="/usr/bin/scp"
- ssh2="/usr/bin/ssh"
- # kill macos daemons
- killall -STOP AMPDevicesAgent AMPDeviceDiscoveryAgent MobileDeviceUpdater 2>/dev/null
- else
- error "Your platform ($OSTYPE) is not supported." \
- "* Supported platforms: Linux, macOS"
- fi
- log "Running on platform: $platform ($platform_ver - $platform_arch)"
- if [[ $platform == "macos" && $platform_arch == "arm64" ]]; then
- if (( mac_majver == 12 && mac_minver < 6 )) || (( mac_majver < 12 )); then
- warn "Updating to macOS 12.6 or newer is recommended for Apple Silicon Macs."
- fi
- fi
- if [[ ! -d $dir ]]; then
- error "Failed to find bin directory ($dir), cannot continue." \
- "* Re-download Legacy iOS Kit from releases (or do a git clone/reset)"
- fi
- if [[ $device_sudoloop == 1 ]]; then
- $sudo chmod +x $dir/*
- if [[ $? != 0 ]]; then
- error "Failed to set up execute permissions of binaries, cannot continue. Try to move Legacy iOS Kit somewhere else."
- fi
- else
- chmod +x $dir/*
- fi
- a6meowing+="$dir/a6meowing"
- aria2c="$(command -v aria2c)"
- [[ -z $aria2c ]] && aria2c="$dir/aria2c"
- aria2c+=" --no-conf --download-result=hide"
- curl="$(command -v curl)"
- futurerestore+="$dir/futurerestore"
- ideviceactivation+="$dir/ideviceactivation"
- idevicediagnostics+="$dir/idevicediagnostics"
- ideviceinfo="$dir/ideviceinfo"
- ideviceinstaller+="$dir/ideviceinstaller"
- idevicerestore+="$dir/idevicerestore"
- irecovery+="$dir/irecovery"
- irecovery2+="$dir/irecovery2"
- irecovery3+="../$dir/irecovery"
- jq="$dir/jq"
- primepwn+="$dir/primepwn"
- sshfs="$(command -v sshfs)"
- cp ../resources/ssh_config . 2>/dev/null
- if [[ $(ssh -V 2>&1 | grep -c SSH_8.8) == 1 || $(ssh -V 2>&1 | grep -c SSH_8.9) == 1 ||
- $(ssh -V 2>&1 | grep -c SSH_9.) == 1 || $(ssh -V 2>&1 | grep -c SSH_1) == 1 ]]; then
- echo " PubkeyAcceptedAlgorithms +ssh-rsa" >> ssh_config
- elif [[ $(ssh -V 2>&1 | grep -c SSH_6) == 1 ]]; then
- cat ../resources/ssh_config | sed "s,Add,#Add,g" | sed "s,HostKeyA,#HostKeyA,g" > ssh_config
- fi
- scp2+=" -F ./ssh_config"
- ssh2+=" -F ./ssh_config"
- }
- install_udev_rules() {
- local rule="/etc/udev/rules.d/99-libirecovery.rules"
- [[ -s $rule ]] && return
- log "Setting up udev rules..."
- if [[ $live_session != 1 && $device_disable_usbmuxd == 1 ]]; then
- print "* Enter your user password when prompted"
- print "* Your password input may not be visible, but it is still being entered."
- fi
- $sudo mkdir -p $(dirname $rule)
- echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="05ac", MODE:="0666", TAG+="uaccess"' | $sudo tee $rule
- $sudo udevadm control --reload-rules
- $sudo udevadm trigger -s usb
- }
- install_depends() {
- rm -f "../saved/firstrun"
- if [[ $platform == "linux" ]]; then
- print "* Legacy iOS Kit will be installing dependencies from your distribution's package manager"
- print "* Enter your user password when prompted"
- print "* Your password input may not be visible, but it is still being entered."
- if [[ $distro != "debian" && $distro != "fedora-atomic" ]]; then
- echo
- warn "Before continuing, make sure that your system is fully updated first!"
- echo "${color_Y}* This operation can result in a partial upgrade and may cause breakage if your system is not updated${color_N}"
- echo
- fi
- pause
- fi
- log "Installing dependencies..."
- if [[ $distro == "arch" ]]; then
- $sudo pacman -Sy --noconfirm --needed aria2 base-devel ca-certificates ca-certificates-mozilla curl git libimobiledevice openssh python sshfs udev unzip usbmuxd usbutils vim zenity zip zstd
- elif [[ $distro == "debian" ]]; then
- if [[ -n $ubuntu_ver ]]; then
- $sudo add-apt-repository -y universe
- fi
- $sudo apt update
- $sudo apt install -m -y aria2 ca-certificates curl git libssl3 libzstd1 openssh-client patch python3 sshfs unzip usbmuxd usbutils xxd zenity zip zlib1g
- if [[ $(command -v systemctl 2>/dev/null) ]]; then
- $sudo systemctl enable --now udev systemd-udevd usbmuxd 2>/dev/null
- fi
- elif [[ $distro == "fedora" ]]; then
- $sudo dnf install -y aria2 ca-certificates git libimobiledevice libzstd openssl patch python3 sshfs systemd udev usbmuxd vim-common zenity zip
- $sudo ln -sf /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-certificates.crt
- elif [[ $distro == "fedora-atomic" ]]; then
- local packages=(patch sshfs vim-common zenity)
- for package in "${packages[@]}"; do
- rpm-ostree install $package
- done
- print "* You may need to reboot to apply changes with rpm-ostree. Perform a reboot after this before running the script again."
- elif [[ $distro == "opensuse" ]]; then
- $sudo zypper -n install aria2 ca-certificates curl git libimobiledevice-1_0-6 libzstd1 openssl-3 patch python3 sshfs usbmuxd unzip vim zenity zip
- elif [[ $distro == "gentoo" ]]; then
- $sudo emerge -av --noreplace app-arch/zstd app-misc/ca-certificates libimobiledevice net-fs/sshfs net-misc/aria2 net-misc/curl openssh python udev app-arch/unzip usbmuxd usbutils vim zenity app-arch/zip
- elif [[ $distro == "void" ]]; then
- $sudo xbps-install aria2 curl git patch openssh python3 unzip xxd zenity zip
- fi
- if [[ $platform == "linux" ]]; then
- install_udev_rules
- fi
- echo "$platform_ver" > "../saved/firstrun"
- log "Install script done! Please run the script again to proceed"
- log "If your iOS device is plugged in, you may need to unplug and replug your device"
- exit
- }
- download_from_url() {
- local url="$1"
- local file="$2"
- local extra
- if [[ $file == *".ipsw" ]]; then
- extra="-c -s 16 -x 16 -k 1M -j 1"
- fi
- if [[ -n "$file" ]]; then
- rm -f "$file"
- $aria2c "$url" $extra -o "$file" || \
- $curl -L "$url" -o "$file" || \
- wget -O "$file" "$url"
- return
- fi
- $aria2c "$url" || \
- $curl -LO "$url" || \
- wget "$url"
- }
- version_update_check() {
- pushd "tmp$$" >/dev/null
- if [[ $platform == "macos" && ! -s ../saved/firstrun ]]; then
- /usr/bin/xattr -cr ../bin/macos
- fi
- log "Checking for updates..."
- download_from_url "https://api.github.com/repos/LukeZGD/Legacy-iOS-Kit/releases/latest" latest
- github_api=$(cat latest 2>/dev/null)
- version_latest=$(echo "$github_api" | $jq -r '.name')
- version_latest=${version_latest#Latest-}
- git_hash_latest=$(echo "$github_api" | $jq -r '.target_commitish')
- git_hash_latest=${git_hash_latest:0:7}
- popd >/dev/null
- }
- version_update() {
- select_yesno "Do you want to update now?" 1
- if [[ $? != 1 ]]; then
- log "User selected N, cannot continue. Exiting."
- exit
- fi
- if [[ -d .git ]]; then
- log "Running git reset..."
- git reset --hard
- log "Running git pull..."
- git pull origin $(git rev-parse --abbrev-ref HEAD)
- pushd "tmp$$" >/dev/null
- log "Done! Please run the script again"
- exit
- fi
- pushd "tmp$$" >/dev/null
- log "Downloading..."
- git clone --filter=blob:none "https://github.com/LukeZGD/Legacy-iOS-Kit"
- if [[ $? != 0 ]]; then
- git clone "https://github.com/LukeZGD/Legacy-iOS-Kit"
- if [[ $? != 0 ]]; then
- local error_msg=$'\n* If you have not installed/updated git, please install git from your package manager.'
- if [[ $platform == "macos" ]]; then
- error_msg+=$'\n* On macOS, you may just need to install Xcode Command Line Tools with this command: xcode-select --install'
- error_msg+=$'\n* If the above command does not work, try this: sudo xcode-select --reset'
- xcode-select --install
- fi
- error "git clone failed. Please run the script again" "$error_msg"
- fi
- fi
- popd >/dev/null
- log "Updating..."
- rm -rf bin/ LICENSE README.md restore.sh
- if [[ $device_sudoloop == 1 ]]; then
- $sudo rm -rf resources/
- fi
- rm -rf resources/
- mv tmp$$/Legacy-iOS-Kit/* tmp$$/Legacy-iOS-Kit/.git* .
- pushd "tmp$$" >/dev/null
- log "Done! Please run the script again"
- exit
- }
- version_get() {
- pushd .. >/dev/null
- if [[ -d .git ]]; then
- if [[ -e .git/shallow ]]; then
- log "Shallow git repository detected. Unshallowing..."
- git fetch --unshallow --filter=blob:none
- if [[ $? != 0 ]]; then
- git fetch --unshallow
- if [[ $? != 0 ]]; then
- error "git fetch failed. Please run the script again" \
- "* If you have not installed/updated git, please install git from your package manager."
- fi
- fi
- fi
- git_hash=$(git rev-parse HEAD | cut -c -7)
- [[ -n $(git status --porcelain --untracked-files=no) ]] && git_hash+="-dirty"
- export TZ=UTC
- local ts=$(git log -1 --format=%ct)
- local yy
- local mm
- local month_start
- if [[ $(uname) == Darwin ]]; then
- yy=$(date -r "$ts" +%y)
- mm=$(date -r "$ts" +%m)
- month_start=$(date -j -f "%Y-%m-%d %H:%M:%S" "20$yy-$mm-01 00:00:00" +%s)
- else
- yy=$(date -d "@$ts" +%y)
- mm=$(date -d "@$ts" +%m)
- month_start=$(date -d "20$yy-$mm-01 00:00:00" +%s)
- fi
- local count=$(git rev-list --count HEAD --since="$month_start")
- version_current="v$yy.$mm.$(printf "%02d" "$count")"
- unset TZ
- elif [[ -e ./resources/git_hash ]]; then
- version_current="$(cat ./resources/version)"
- git_hash="$(cat ./resources/git_hash)"
- elif [[ -e ./resources/new ]]; then
- :
- else
- log ".git directory and git_hash file not found, cannot determine version."
- if [[ $no_version_check != 1 ]]; then
- warn "Your copy of Legacy iOS Kit is downloaded incorrectly. Do not use the \"Code\" button in GitHub."
- print "* Please download Legacy iOS Kit using git clone or from GitHub releases: https://github.com/LukeZGD/Legacy-iOS-Kit/releases"
- fi
- fi
- if [[ -n $version_current ]]; then
- print "* Version: $version_current ($git_hash)"
- fi
- popd >/dev/null
- }
- version_check() {
- if [[ $no_version_check == 1 && ! -e ../resources/new ]]; then
- warn "No version check flag detected, update check is disabled and no support will be provided."
- return
- fi
- pushd .. >/dev/null
- version_update_check
- if [[ -z $version_latest ]]; then
- warn "Failed to check for updates. GitHub may be down or blocked by your network."
- elif [[ $git_hash_latest != "$git_hash" ]]; then
- if [[ -z $version_current ]]; then
- print "* Latest version: $version_latest ($git_hash_latest)"
- print "* Please download/pull the latest version before proceeding."
- version_update
- elif (( $(echo $version_current | cut -c 2- | sed -e 's/\.//g') >= $(echo $version_latest | cut -c 2- | sed -e 's/\.//g') )); then
- warn "Current version is newer/different than remote: $version_latest ($git_hash_latest)"
- else
- print "* A newer version of Legacy iOS Kit is available."
- print "* Current version: $version_current ($git_hash)"
- print "* Latest version: $version_latest ($git_hash_latest)"
- print "* Please download/pull the latest version before proceeding."
- version_update
- fi
- fi
- popd >/dev/null
- }
- device_entry() {
- # enable manual entry
- log "Manual device/ECID entry is enabled."
- until [[ -n $device_type && $device_type == "iP"* ]]; do
- read -p "$(input 'Enter device type (eg. iPad2,1): ')" device_type_entry
- device_type="$device_type_entry"
- done
- case $device_type in
- iPad6,1[12] | iPhone8,* )
- local valid
- local allowed
- case $device_type in
- iPhone8,1 ) allowed="n71 n71m";;
- iPhone8,2 ) allowed="n66 n66m";;
- iPhone8,4 ) allowed="n69 n69u";;
- iPad6,11 ) allowed="j71s j71t";;
- iPad6,12 ) allowed="j72s j72t";;
- esac
- until [[ $valid == 1 ]]; do
- read -p "$(input 'Enter device model (without ap, eg. n71): ')" device_model
- for m in $allowed; do
- [[ $device_model == "$m" ]] && valid=1 && break
- done
- done
- ;;
- esac
- if [[ $main_argmode == "device_justboot"* || $main_argmode == "device_enter_ramdisk"* ]]; then
- :
- elif [[ $device_type != "iPhone1,"* && $device_type != "iPod1,1" && $device_mode != "Normal" ]]; then
- until [[ -n $device_ecid_entry ]] && [ "$device_ecid_entry" -eq "$device_ecid_entry" ]; do
- read -p "$(input 'Enter device ECID (must be decimal): ')" device_ecid_entry
- done
- fi
- if [[ $device_argmode == "none" ]]; then
- device_ecid="$device_ecid_entry"
- fi
- if [[ -n $device_ecid_entry && $main_argmode == "device_justboot"* ]]; then
- cat "$device_rd_build" > "../saved/$device_type/justboot_${device_ecid_entry}"
- fi
- }
- device_entry_s5l8900() {
- device_argmode="entry"
- log "Found an S5L8900 device in $device_mode mode."
- print "* Device Type Option"
- print "* Select your device in the options below. Make sure to select correctly."
- local selection=("iPhone 2G" "iPod touch 1")
- [[ $device_protocol != 1 ]] && selection+=("iPhone 3G")
- input "Select your option:"
- select_option "${selection[@]}"
- local opt2="${selection[$?]}"
- case $opt2 in
- "iPhone 2G" ) device_type="iPhone1,1";;
- "iPhone 3G" ) device_type="iPhone1,2";;
- "iPod touch 1" ) device_type="iPod1,1";;
- esac
- device_model=
- }
- device_get_name() {
- # all devices that run iOS/iPhoneOS/iPadOS
- # adding more entries here is no longer necessary since AppleDB is now used as fallback
- case $device_type in
- "iPhone1,1") device_name="iPhone 2G";;
- "iPhone1,2") device_name="iPhone 3G";;
- "iPhone2,1") device_name="iPhone 3GS";;
- "iPhone3,1") device_name="iPhone 4 (GSM)";;
- "iPhone3,2") device_name="iPhone 4 (GSM, Rev A)";;
- "iPhone3,3") device_name="iPhone 4 (CDMA)";;
- "iPhone4,1") device_name="iPhone 4S";;
- "iPhone5,1") device_name="iPhone 5 (GSM)";;
- "iPhone5,2") device_name="iPhone 5 (Global)";;
- "iPhone5,3") device_name="iPhone 5C (GSM)";;
- "iPhone5,4") device_name="iPhone 5C (Global)";;
- "iPhone6,1") device_name="iPhone 5S (GSM)";;
- "iPhone6,2") device_name="iPhone 5S (Global)";;
- "iPhone7,1") device_name="iPhone 6 Plus";;
- "iPhone7,2") device_name="iPhone 6";;
- "iPhone8,1") device_name="iPhone 6S";;
- "iPhone8,2") device_name="iPhone 6S Plus";;
- "iPhone8,4") device_name="iPhone SE 2016";;
- "iPhone9,1") device_name="iPhone 7 (Global)";;
- "iPhone9,2") device_name="iPhone 7 Plus (Global)";;
- "iPhone9,3") device_name="iPhone 7 (GSM)";;
- "iPhone9,4") device_name="iPhone 7 Plus (GSM)";;
- "iPhone10,1") device_name="iPhone 8 (Global)";;
- "iPhone10,2") device_name="iPhone 8 Plus (Global)";;
- "iPhone10,3") device_name="iPhone X (Global)";;
- "iPhone10,4") device_name="iPhone 8 (GSM)";;
- "iPhone10,5") device_name="iPhone 8 Plus (GSM)";;
- "iPhone10,6") device_name="iPhone X (GSM)";;
- "iPhone11,2") device_name="iPhone XS";;
- "iPhone11,4") device_name="iPhone XS Max (China)";;
- "iPhone11,6") device_name="iPhone XS Max";;
- "iPhone11,8") device_name="iPhone XR";;
- "iPhone12,1") device_name="iPhone 11";;
- "iPhone12,3") device_name="iPhone 11 Pro";;
- "iPhone12,5") device_name="iPhone 11 Pro Max";;
- "iPhone12,8") device_name="iPhone SE 2020";;
- "iPhone13,1") device_name="iPhone 12 mini";;
- "iPhone13,2") device_name="iPhone 12";;
- "iPhone13,3") device_name="iPhone 12 Pro";;
- "iPhone13,4") device_name="iPhone 12 Pro Max";;
- "iPhone14,2") device_name="iPhone 13 Pro";;
- "iPhone14,3") device_name="iPhone 13 Pro Max";;
- "iPhone14,4") device_name="iPhone 13 mini";;
- "iPhone14,5") device_name="iPhone 13";;
- "iPhone14,6") device_name="iPhone SE 2022";;
- "iPhone14,7") device_name="iPhone 14";;
- "iPhone14,8") device_name="iPhone 14 Plus";;
- "iPhone15,2") device_name="iPhone 14 Pro";;
- "iPhone15,3") device_name="iPhone 14 Pro Max";;
- "iPhone15,4") device_name="iPhone 15";;
- "iPhone15,5") device_name="iPhone 15 Plus";;
- "iPhone16,1") device_name="iPhone 15 Pro";;
- "iPhone16,2") device_name="iPhone 15 Pro Max";;
- "iPhone17,1") device_name="iPhone 16 Pro";;
- "iPhone17,2") device_name="iPhone 16 Pro Max";;
- "iPhone17,3") device_name="iPhone 16";;
- "iPhone17,4") device_name="iPhone 16 Plus";;
- "iPhone17,5") device_name="iPhone 16e";;
- "iPad1,1") device_name="iPad 1";;
- "iPad2,1") device_name="iPad 2 (Wi-Fi)";;
- "iPad2,2") device_name="iPad 2 (GSM)";;
- "iPad2,3") device_name="iPad 2 (CDMA)";;
- "iPad2,4") device_name="iPad 2 (Wi-Fi, Rev A)";;
- "iPad2,5") device_name="iPad mini 1 (Wi-Fi)";;
- "iPad2,6") device_name="iPad mini 1 (GSM)";;
- "iPad2,7") device_name="iPad mini 1 (Global)";;
- "iPad3,1") device_name="iPad 3 (Wi-Fi)";;
- "iPad3,2") device_name="iPad 3 (CDMA)";;
- "iPad3,3") device_name="iPad 3 (GSM)";;
- "iPad3,4") device_name="iPad 4 (Wi-Fi)";;
- "iPad3,5") device_name="iPad 4 (GSM)";;
- "iPad3,6") device_name="iPad 4 (Global)";;
- "iPad4,1") device_name="iPad Air 1 (Wi-Fi)";;
- "iPad4,2") device_name="iPad Air 1 (Cellular)";;
- "iPad4,3") device_name="iPad Air 1 (China)";;
- "iPad4,4") device_name="iPad mini 2 (Wi-Fi)";;
- "iPad4,5") device_name="iPad mini 2 (Cellular)";;
- "iPad4,6") device_name="iPad mini 2 (China)";;
- "iPad4,7") device_name="iPad mini 3 (Wi-Fi)";;
- "iPad4,8") device_name="iPad mini 3 (Cellular)";;
- "iPad4,9") device_name="iPad mini 3 (China)";;
- "iPad5,1") device_name="iPad mini 4 (Wi-Fi)";;
- "iPad5,2") device_name="iPad mini 4 (Cellular)";;
- "iPad5,3") device_name="iPad Air 2 (Wi-Fi)";;
- "iPad5,4") device_name="iPad Air 2 (Cellular)";;
- "iPad6,3") device_name="iPad Pro 9.7\" (Wi-Fi)";;
- "iPad6,4") device_name="iPad Pro 9.7\" (Cellular)";;
- "iPad6,7") device_name="iPad Pro 12.9\" (Wi-Fi)";;
- "iPad6,8") device_name="iPad Pro 12.9\" (Cellular)";;
- "iPad6,11") device_name="iPad 5 (Wi-Fi)";;
- "iPad6,12") device_name="iPad 5 (Cellular)";;
- "iPad7,1") device_name="iPad Pro 12.9\" (2nd gen, Wi-Fi)";;
- "iPad7,2") device_name="iPad Pro 12.9\" (2nd gen, Cellular)";;
- "iPad7,3") device_name="iPad Pro 10.5\" (Wi-Fi)";;
- "iPad7,4") device_name="iPad Pro 10.5\" (Cellular)";;
- "iPad7,5") device_name="iPad 6 (Wi-Fi)";;
- "iPad7,6") device_name="iPad 6 (Cellular)";;
- "iPad7,11") device_name="iPad 7 (Wi-Fi)";;
- "iPad7,12") device_name="iPad 7 (Cellular)";;
- "iPad8,1") device_name="iPad Pro 11\" (Wi-Fi)";;
- "iPad8,2") device_name="iPad Pro 11\" (Wi-Fi, 6GB RAM)";;
- "iPad8,3") device_name="iPad Pro 11\" (Cellular)";;
- "iPad8,4") device_name="iPad Pro 11\" (Cellular, 6GB RAM)";;
- "iPad8,5") device_name="iPad Pro 12.9\" (3rd gen, Wi-Fi)";;
- "iPad8,6") device_name="iPad Pro 12.9\" (3rd gen, Wi-Fi, 6GB RAM)";;
- "iPad8,7") device_name="iPad Pro 12.9\" (3rd gen, Cellular)";;
- "iPad8,8") device_name="iPad Pro 12.9\" (3rd gen, Cellular, 6GB RAM)";;
- "iPad8,9") device_name="iPad Pro 11\" (2nd gen, Wi-Fi)";;
- "iPad8,10") device_name="iPad Pro 11\" (2nd gen, Cellular)";;
- "iPad8,11") device_name="iPad Pro 12.9\" (4th gen, Wi-Fi)";;
- "iPad8,12") device_name="iPad Pro 12.9\" (4th gen, Cellular)";;
- "iPad11,1") device_name="iPad mini 5 (Wi-Fi)";;
- "iPad11,2") device_name="iPad mini 5 (Cellular)";;
- "iPad11,3") device_name="iPad Air 3 (Wi-Fi)";;
- "iPad11,4") device_name="iPad Air 3 (Cellular)";;
- "iPad11,6") device_name="iPad 8 (Wi-Fi)";;
- "iPad11,7") device_name="iPad 8 (Cellular)";;
- "iPad12,1") device_name="iPad 9 (Wi-Fi)";;
- "iPad12,2") device_name="iPad 9 (Cellular)";;
- "iPad13,1") device_name="iPad Air 4 (Wi-Fi)";;
- "iPad13,2") device_name="iPad Air 4 (Cellular)";;
- "iPad13,4") device_name="iPad Pro 11\" (3rd gen, Wi-Fi)";;
- "iPad13,5") device_name="iPad Pro 11\" (3rd gen, Wi-Fi, 16GB RAM)";;
- "iPad13,6") device_name="iPad Pro 11\" (3rd gen, Cellular)";;
- "iPad13,7") device_name="iPad Pro 11\" (3rd gen, Cellular, 16GB RAM)";;
- "iPad13,8") device_name="iPad Pro 12.9\" (5th gen, Wi-Fi)";;
- "iPad13,9") device_name="iPad Pro 12.9\" (5th gen, Wi-Fi, 16GB RAM)";;
- "iPad13,10") device_name="iPad Pro 12.9\" (5th gen, Cellular)";;
- "iPad13,11") device_name="iPad Pro 12.9\" (5th gen, Cellular, 16GB RAM)";;
- "iPad13,16") device_name="iPad Air 5 (Wi-Fi)";;
- "iPad13,17") device_name="iPad Air 5 (Cellular)";;
- "iPad13,18") device_name="iPad 10 (Wi-Fi)";;
- "iPad13,19") device_name="iPad 10 (Cellular)";;
- "iPad14,1") device_name="iPad mini 6 (Wi-Fi)";;
- "iPad14,2") device_name="iPad mini 6 (Cellular)";;
- "iPad14,3") device_name="iPad Pro 11\" (4th gen, Wi-Fi)";;
- "iPad14,4") device_name="iPad Pro 11\" (4th gen, Cellular)";;
- "iPad14,5") device_name="iPad Pro 12.9\" (6th gen, Wi-Fi)";;
- "iPad14,6") device_name="iPad Pro 12.9\" (6th gen, Cellular)";;
- "iPad14,8") device_name="iPad Air 11\" (M2, Wi-Fi)";;
- "iPad14,9") device_name="iPad Air 11\" (M2, Cellular)";;
- "iPad14,10") device_name="iPad Air 13\" (M2, Wi-Fi)";;
- "iPad14,11") device_name="iPad Air 13\" (M2, Cellular)";;
- "iPad16,1") device_name="iPad mini (A17 Pro, Wi-Fi)";;
- "iPad16,2") device_name="iPad mini (A17 Pro, Cellular)";;
- "iPad16,3") device_name="iPad Pro 11\" (M4, Wi-Fi)";;
- "iPad16,4") device_name="iPad Pro 11\" (M4, Cellular)";;
- "iPad16,5") device_name="iPad Pro 12.9\" (M4, Wi-Fi)";;
- "iPad16,6") device_name="iPad Pro 12.9\" (M4, Cellular)";;
- "iPod1,1") device_name="iPod touch 1";;
- "iPod2,1") device_name="iPod touch 2";;
- "iPod3,1") device_name="iPod touch 3";;
- "iPod4,1") device_name="iPod touch 4";;
- "iPod5,1") device_name="iPod touch 5";;
- "iPod7,1") device_name="iPod touch 6";;
- "iPod9,1") device_name="iPod touch 7";;
- esac
- if [[ -z $device_name && -n $device_type ]]; then
- log "Getting device name"
- download_appledb "device/$device_type"
- device_name="$(cat tmp.json | $jq -r ".name")"
- fi
- }
- device_get_paired_info() {
- device_serial="$($ideviceinfo -k SerialNumber | cut -c 3- | cut -c -3)"
- device_unactivated=$($ideviceactivation state | grep -c "Unactivated")
- device_imei=$($ideviceinfo -k InternationalMobileEquipmentIdentity)
- }
- device_manufacturing() {
- if (( device_proc > 10 )) || [[ $device_proc != 1 && $device_argmode == "none" ]]; then
- return
- fi
- if [[ $device_type == "iPhone2,1" && $device_mode != "DFU" ]]; then
- local week=$(echo "$device_serial" | cut -c 2-)
- local year=$(echo "$device_serial" | cut -c 1)
- year=$((year+2010))
- [[ $year == 2019 ]] && year=2009
- if [[ $year != 2009 ]] || (( week >= 46 )); then
- device_newbr=1
- elif [[ $year == 2009 ]] && (( week >= 40 )); then
- device_newbr=2 # gray area
- else
- device_newbr=0
- fi
- elif [[ $device_type == "iPod2,1" && $device_mode == "Recovery" ]]; then
- device_newbr=2
- print "* Cannot check $device_name bootrom model in Recovery mode. Enter DFU mode to get bootrom model"
- return
- elif [[ $device_type != "iPhone2,1" && $device_type != "iPod2,1" ]]; then
- case $device_type in
- iPhone4,1 | iPhone5,2 | iPad2,7 | iPad3,[26] ) device_9900candidate=1;;
- esac
- if [[ $device_type == "DFU" ]]; then
- print "* Cannot check for manufacturing date in DFU mode"
- return
- fi
- local fourth="${device_serial:1:1}"
- local year_half
- case $fourth in
- C ) year_half="1st half 2010";;
- D ) year_half="2nd half 2010";;
- F ) year_half="1st half 2011";;
- G ) year_half="2nd half 2011";;
- H ) year_half="1st half 2012";;
- J ) year_half="2nd half 2012";;
- K ) year_half="1st half 2013";;
- L ) year_half="2nd half 2013";;
- M ) year_half="1st half 2014";;
- N ) year_half="2nd half 2014";;
- P ) year_half="1st half 2015";;
- Q ) year_half="2nd half 2015";;
- R ) year_half="1st half 2016";;
- S ) year_half="2nd half 2016";;
- T ) year_half="1st half 2017";;
- V ) year_half="2nd half 2017";;
- W ) year_half="1st half 2018";;
- X ) year_half="2nd half 2018";;
- Y ) year_half="1st half 2019";;
- Z ) year_half="2nd half 2019";;
- esac
- if [[ -n $year_half ]]; then
- print "* Manufactured in $year_half"
- elif [[ $device_mode == "Normal" ]] && (( device_proc >= 5 )); then
- print "* Select Pair Device to get more device information"
- if [[ -n $device_use_bb && $device_9900candidate == 1 ]]; then
- print "* This will also check if your device is affected by the 9900 IMEI activation issue"
- fi
- fi
- fi
- case $device_newbr in
- 0 ) print "* This $device_name is an old bootrom model";;
- 1 ) print "* This $device_name is a new bootrom model";;
- 2 ) print "* This $device_name bootrom model cannot be determined. Enter DFU mode to get bootrom model";;
- esac
- if [[ $device_type == "iPhone2,1" && $device_mode == "DFU" ]]; then
- print "* Cannot check for manufacturing date in DFU mode"
- elif [[ $device_type == "iPhone2,1" ]]; then
- print "* Manufactured in Week $week - $year"
- fi
- }
- device_s5l8900xall() {
- local wtf_sha="cb96954185a91712c47f20adb519db45a318c30f"
- local wtf_saved="../saved/WTF.s5l8900xall.RELEASE.dfu"
- local wtf_patched="$wtf_saved.patched"
- local wtf_patch="../resources/patch/WTF.s5l8900xall.RELEASE.patch"
- local wtf_sha_local="$($sha1sum "$wtf_saved" 2>/dev/null | awk '{print $1}')"
- mkdir -p ../saved
- if [[ $wtf_sha_local != "$wtf_sha" ]]; then
- download_with_pzb "http://appldnld.apple.com/iPhone/061-7481.20100202.4orot/iPhone1,1_3.1.3_7E18_Restore.ipsw" "Firmware/dfu/WTF.s5l8900xall.RELEASE.dfu" WTF.s5l8900xall.RELEASE.dfu $wtf_sha
- rm -f "$wtf_saved"
- mv WTF.s5l8900xall.RELEASE.dfu $wtf_saved
- fi
- rm -f "$wtf_patched"
- log "Patching WTF.s5l8900xall"
- $bspatch $wtf_saved $wtf_patched $wtf_patch
- log "Sending patched WTF.s5l8900xall (Pwnage 2.0)"
- $irecovery -f "$wtf_patched"
- if [[ $platform == "macos" ]]; then
- print "* If your device is unable to be detected in DFU mode, try switching to a USB-C to USB-A dongle instead of USB-C dock/hub."
- fi
- device_find_mode DFUreal
- device_srtg="$($irecovery -q | grep "SRTG" | cut -c 7-)"
- log "SRTG: $device_srtg"
- if [[ $device_srtg == "iBoot-636.66.3x" ]]; then
- device_argmode=
- device_type=$($irecovery -q | grep "PRODUCT" | cut -c 10-)
- device_model=$($irecovery -q | grep "MODEL" | cut -c 8-)
- device_model="${device_model%??}"
- device_get_name
- device_pwnd="Pwnage 2.0"
- fi
- }
- device_get_info() {
- : '
- usage: device_get_info (no arguments)
- sets the variables: device_mode, device_type, device_ecid, device_vers, device_udid, device_model, device_fw_dir,
- device_use_vers, device_use_build, device_use_bb, device_use_bb_sha1, device_latest_vers, device_latest_build,
- device_latest_bb, device_latest_bb_sha1, device_proc
- '
- if [[ ! -s $ideviceinfo ]]; then
- error "ideviceinfo not found. Make sure to update the script and/or check your Internet connection."
- fi
- if [[ $device_argmode == "none" ]]; then
- log "No device mode is enabled."
- device_mode="none"
- device_vers="Unknown"
- elif [[ $main_argmode == "device_enter_ramdisk_menu" ]]; then
- log "sshrd-menu flag detected, assuming device is in SSH ramdisk mode"
- device_mode="Normal"
- else
- log "Finding device in Normal mode..."
- if [[ $platform == "linux" ]]; then
- print "* If it gets stuck here, try to restart your PC"
- if [[ $othertmp != 0 ]]; then
- print "* If it fails to detect devices, try to delete all \"tmp\" folders in your Legacy iOS Kit folder"
- fi
- fi
- $ideviceinfo -s >/dev/null
- if [[ $? == 0 ]]; then
- device_mode="Normal"
- else
- $ideviceinfo >/dev/null
- if [[ $? == 0 ]]; then
- device_mode="Normal"
- fi
- fi
- fi
- if [[ -z $device_mode ]]; then
- log "Finding device in Recovery/DFU mode..."
- device_mode="$($irecovery -q | grep -w "MODE" | cut -c 7-)"
- fi
- if [[ $device_mode == "Recovery" && $device_pwnrec == 1 ]]; then
- device_mode="DFU"
- fi
- if [[ -z $device_mode ]]; then
- local error_msg=$'* Make sure to trust this computer by selecting "Trust" at the pop-up.'
- if [[ $platform == "macos" ]]; then
- error_msg+=$'\n* Make sure to have the initial setup dependencies installed before retrying.'
- error_msg+=$'\n* Double-check if the device is being detected by iTunes/Finder.'
- else
- error_msg+=$'\n* If your device in normal mode is not being detected, this is likely a usbmuxd issue.'
- error_msg+=$'\n* You may also try again in a live USB.'
- fi
- error_msg+=$'\n* Try restarting your PC/Mac as well as using different USB ports/cables.'
- error_msg+=$'\n* For more details, read the "Troubleshooting" wiki page in GitHub.\n* Troubleshooting link: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Troubleshooting'
- error "No device found! Please connect the iOS device to proceed." "$error_msg"
- fi
- log "Getting device info..."
- case $device_mode in
- "WTF" | "DFU" | "Recovery" )
- if [[ -n $device_argmode ]]; then
- device_entry
- else
- device_type=$($irecovery -q | grep "PRODUCT" | cut -c 10-)
- device_ecid=$(printf "%d" $($irecovery -q | grep "ECID" | cut -c 7-)) # converts hex ecid to dec
- fi
- device_model=$($irecovery -q | grep "MODEL" | cut -c 8-)
- if [[ $device_mode != "DFU" && -z $device_argmode && $device_model == "m68ap" ]]; then
- device_entry_s5l8900
- fi
- if [[ $device_mode == "Recovery" ]]; then
- device_vers=$(echo "/exit" | $irecovery -s | grep -a "iBoot-")
- fi
- if [[ -z $device_vers ]]; then
- device_vers="Unknown"
- if [[ $device_mode == "Recovery" ]]; then
- device_vers+=". Re-enter recovery mode to get iBoot version"
- fi
- fi
- device_serial="$($irecovery -q | grep "SRNM" | cut -c 7- | cut -c 3- | cut -c -3)"
- device_get_name
- print "* Device: $device_name (${device_type} - ${device_model}) in $device_mode mode"
- print "* iOS Version: $device_vers"
- print "* ECID: $device_ecid"
- device_manufacturing
- if [[ $device_type == "iPod2,1" && $device_newbr != 2 ]]; then
- device_newbr="$($irecovery -q | grep -c '240.5.1')"
- elif [[ $device_type == "iPhone2,1" ]]; then
- device_newbr="$($irecovery -q | grep -c '359.3.2')"
- fi
- device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
- device_srtg="$($irecovery -q | grep "SRTG" | cut -c 7-)"
- ;;
- "Normal" )
- if [[ -n $device_argmode ]]; then
- device_entry
- else
- device_type=$($ideviceinfo -s -k ProductType)
- [[ -z $device_type ]] && device_type=$($ideviceinfo -k ProductType)
- fi
- if [[ $main_argmode != "device_enter_ramdisk"* ]]; then
- device_ecid=$($ideviceinfo -s -k UniqueChipID)
- device_model=$($ideviceinfo -s -k HardwareModel)
- if [[ $device_model == "N81AP" ]]; then
- device_type="iPod4,1" # this is needed since touch 4 devices on ios 7 show as iphone3,1/3,3
- fi
- device_vers=$($ideviceinfo -s -k ProductVersion)
- [[ -z $device_vers ]] && device_vers=$($ideviceinfo -k ProductVersion)
- device_vers_maj=$(echo "$device_vers" | cut -d. -f1)
- device_vers_min=$(echo "$device_vers" | cut -d. -f2)
- device_build=$($ideviceinfo -s -k BuildVersion)
- [[ -z $device_build ]] && device_build=$($ideviceinfo -k BuildVersion)
- device_udid=$($ideviceinfo -s -k UniqueDeviceID)
- [[ -z $device_udid ]] && device_udid=$($ideviceinfo -k UniqueDeviceID)
- if [[ $device_type == "iPod2,1" ]]; then
- device_newbr="$($ideviceinfo -k ModelNumber | grep -c 'C')"
- fi
- # i'd like to force pair for all it but would prob get annoying quick especially on linux
- device_get_paired_info
- device_protocol=$($ideviceinfo -s -k ProtocolVersion)
- if [[ $device_protocol == 1 ]]; then
- device_entry_s5l8900
- fi
- fi
- ;;
- esac
- if [[ $device_argmode == "none" ]]; then
- device_entry
- fi
- device_model="$(echo $device_model | tr '[:upper:]' '[:lower:]')"
- device_model="${device_model%ap}" # remove "ap" from the end
- # workaround for https://github.com/LukeZGD/Legacy-iOS-Kit/issues/932, hopefully this is the only case where this is needed
- if [[ $device_type == "iPad2,1" ]]; then
- device_model="k93"
- fi
- # device_model fallback/failsafe (this will be up to checkm8 devices only)
- case $device_model in
- k48 ) device_type="iPad1,1";;
- k93 ) device_type="iPad2,1";;
- k94 ) device_type="iPad2,2";;
- k95 ) device_type="iPad2,3";;
- k93a ) device_type="iPad2,4";;
- p105 ) device_type="iPad2,5";;
- p106 ) device_type="iPad2,6";;
- p107 ) device_type="iPad2,7";;
- j1 ) device_type="iPad3,1";;
- j2 ) device_type="iPad3,2";;
- j2a ) device_type="iPad3,3";;
- p101 ) device_type="iPad3,4";;
- p102 ) device_type="iPad3,5";;
- p103 ) device_type="iPad3,6";;
- j71 ) device_type="iPad4,1";;
- j72 ) device_type="iPad4,2";;
- j73 ) device_type="iPad4,3";;
- j85 ) device_type="iPad4,4";;
- j86 ) device_type="iPad4,5";;
- j87 ) device_type="iPad4,6";;
- j85m ) device_type="iPad4,7";;
- j86m ) device_type="iPad4,8";;
- j87m ) device_type="iPad4,9";;
- j96 ) device_type="iPad5,1";;
- j97 ) device_type="iPad5,2";;
- j81 ) device_type="iPad5,3";;
- j82 ) device_type="iPad5,4";;
- j127 ) device_type="iPad6,3";;
- j128 ) device_type="iPad6,4";;
- j98a ) device_type="iPad6,7";;
- j99a ) device_type="iPad6,8";;
- j71s ) device_type="iPad6,11";;
- j71t ) device_type="iPad6,11";;
- j72s ) device_type="iPad6,12";;
- j72t ) device_type="iPad6,12";;
- j120 ) device_type="iPad7,1";;
- j121 ) device_type="iPad7,2";;
- j207 ) device_type="iPad7,3";;
- j208 ) device_type="iPad7,4";;
- j71b ) device_type="iPad7,5";;
- j72b ) device_type="iPad7,6";;
- j171 ) device_type="iPad7,11";;
- j172 ) device_type="iPad7,12";;
- m68 ) device_type="iPhone1,1";;
- n82 ) device_type="iPhone1,2";;
- n88 ) device_type="iPhone2,1";;
- n90 ) device_type="iPhone3,1";;
- n90b ) device_type="iPhone3,2";;
- n92 ) device_type="iPhone3,3";;
- n94 ) device_type="iPhone4,1";;
- n41 ) device_type="iPhone5,1";;
- n42 ) device_type="iPhone5,2";;
- n48 ) device_type="iPhone5,3";;
- n49 ) device_type="iPhone5,4";;
- n51 ) device_type="iPhone6,1";;
- n53 ) device_type="iPhone6,2";;
- n56 ) device_type="iPhone7,1";;
- n61 ) device_type="iPhone7,2";;
- n71 ) device_type="iPhone8,1";;
- n71m ) device_type="iPhone8,1";;
- n66 ) device_type="iPhone8,2";;
- n66m ) device_type="iPhone8,2";;
- n69 ) device_type="iPhone8,4";;
- n69u ) device_type="iPhone8,4";;
- d10 ) device_type="iPhone9,1";;
- d11 ) device_type="iPhone9,2";;
- d101 ) device_type="iPhone9,3";;
- d111 ) device_type="iPhone9,4";;
- d20 ) device_type="iPhone10,1";;
- d21 ) device_type="iPhone10,2";;
- d22 ) device_type="iPhone10,3";;
- d201 ) device_type="iPhone10,4";;
- d211 ) device_type="iPhone10,5";;
- d221 ) device_type="iPhone10,6";;
- n45 ) device_type="iPod1,1";;
- n72 ) device_type="iPod2,1";;
- n18 ) device_type="iPod3,1";;
- n81 ) device_type="iPod4,1";;
- n78 ) device_type="iPod5,1";;
- n102 ) device_type="iPod7,1";;
- n112 ) device_type="iPod9,1";;
- esac
- device_type_lower="$(echo "$device_type" | tr '[:upper:]' '[:lower:]')"
- # device_model fallback/failsafe
- case $device_type in
- iPad1,1 ) device_model="k48";;
- iPad2,1 ) device_model="k93";;
- iPad2,2 ) device_model="k94";;
- iPad2,3 ) device_model="k95";;
- iPad2,4 ) device_model="k93a";;
- iPad2,5 ) device_model="p105";;
- iPad2,6 ) device_model="p106";;
- iPad2,7 ) device_model="p107";;
- iPad3,1 ) device_model="j1";;
- iPad3,2 ) device_model="j2";;
- iPad3,3 ) device_model="j2a";;
- iPad3,4 ) device_model="p101";;
- iPad3,5 ) device_model="p102";;
- iPad3,6 ) device_model="p103";;
- iPad4,1 ) device_model="j71";;
- iPad4,2 ) device_model="j72";;
- iPad4,3 ) device_model="j73";;
- iPad4,4 ) device_model="j85";;
- iPad4,5 ) device_model="j86";;
- iPad4,6 ) device_model="j87";;
- iPad4,7 ) device_model="j85m";;
- iPad4,8 ) device_model="j86m";;
- iPad4,9 ) device_model="j87m";;
- iPad5,1 ) device_model="j96";;
- iPad5,2 ) device_model="j97";;
- iPad5,3 ) device_model="j81";;
- iPad5,4 ) device_model="j82";;
- iPad6,3 ) device_model="j127";;
- iPad6,4 ) device_model="j128";;
- iPad6,7 ) device_model="j98a";;
- iPad6,8 ) device_model="j99a";;
- #iPad6,11 ) device_model="j71s";;
- #iPad6,12 ) device_model="j72s";;
- iPad7,1 ) device_model="j120";;
- iPad7,2 ) device_model="j121";;
- iPad7,3 ) device_model="j207";;
- iPad7,4 ) device_model="j208";;
- iPad7,5 ) device_model="j71b";;
- iPad7,6 ) device_model="j72b";;
- iPad7,11 ) device_model="j171";;
- iPad7,12 ) device_model="j172";;
- iPhone1,1) device_model="m68";;
- iPhone1,2) device_model="n82";;
- iPhone2,1) device_model="n88";;
- iPhone3,1) device_model="n90";;
- iPhone3,2) device_model="n90b";;
- iPhone3,3) device_model="n92";;
- iPhone4,1) device_model="n94";;
- iPhone5,1) device_model="n41";;
- iPhone5,2) device_model="n42";;
- iPhone5,3) device_model="n48";;
- iPhone5,4) device_model="n49";;
- iPhone6,1) device_model="n51";;
- iPhone6,2) device_model="n53";;
- iPhone7,1) device_model="n56";;
- iPhone7,2) device_model="n61";;
- #iPhone8,1) device_model="n71";;
- #iPhone8,2) device_model="n66";;
- #iPhone8,4) device_model="n69";;
- iPhone9,1) device_model="d10";;
- iPhone9,2) device_model="d11";;
- iPhone9,3) device_model="d101";;
- iPhone9,4) device_model="d111";;
- iPhone10,1) device_model="d20";;
- iPhone10,2) device_model="d21";;
- iPhone10,3) device_model="d22";;
- iPhone10,4) device_model="d201";;
- iPhone10,5) device_model="d211";;
- iPhone10,6) device_model="d221";;
- iPod1,1 ) device_model="n45";;
- iPod2,1 ) device_model="n72";;
- iPod3,1 ) device_model="n18";;
- iPod4,1 ) device_model="n81";;
- iPod5,1 ) device_model="n78";;
- iPod7,1 ) device_model="n102";;
- iPod9,1 ) device_model="n112";;
- esac
- device_fw_dir="../saved/firmware/$device_type"
- mkdir -p $device_fw_dir 2>/dev/null
- all_flash="Firmware/all_flash/all_flash.${device_model}ap.production"
- device_use_bb=0
- device_latest_bb=0
- # set device_proc (what processor the device has)
- case $device_type in
- iPhone1,* | iPod1,1 )
- device_proc=1;; # S5L8900
- iPad1,1 | iPhone[23],* | iPod[234],1 )
- device_proc=4;; # A4/S5L8720/8920/8922
- iPad2,* | iPad3,[123] | iPhone4,1 | iPod5,1 )
- device_proc=5;; # A5
- iPad3,* | iPhone5,* )
- device_proc=6;; # A6
- iPad4,* | iPhone6,* )
- device_proc=7;; # A7
- iPad5,* | iPhone7,* | iPod7,1 )
- device_proc=8;; # A8
- iPad6,* | iPhone8,* )
- device_proc=9;; # A9
- iPad7,* | iPhone9,* | iPhone10,* | iPod9,1 )
- device_proc=10;; # A10 or A11
- iPad* | iPhone* )
- device_proc=11;; # Newer devices
- esac
- case $device_type in
- iPad[67],* ) device_checkm8ipad=1;;
- esac
- device_get_name
- if [[ $device_mode == "Normal" && -z $device_ecid && $main_argmode != "device_enter_ramdisk"* ]]; then
- warn "Unable to detect device type/ECID. Is your device on 2.x or lower?"
- warn "Limited support for iOS versions lower than 3.x. Expect features to not work properly."
- print "* For better support, enter Recovery/DFU mode and/or update your device to iOS 3.x or newer."
- pause
- [[ -z $device_vers_maj ]] && device_vers_maj=1
- fi
- if [[ $device_type == "AppleTV"* || $device_type == "Watch"* ]]; then
- device_proc=11
- elif [[ -z $device_name || -z $device_proc ]]; then
- error "Unrecognized device $device_type. Enter the device type properly."
- fi
- if (( device_proc > 10 )); then
- print "* Device: $device_name (${device_type} - ${device_model}ap) in $device_mode mode"
- print "* iOS Version: $device_vers"
- print "* ECID: $device_ecid"
- echo
- warn "This device is mostly not supported by Legacy iOS Kit."
- print "* You may still continue but options will be limited to sideloading and other basic features."
- pause
- fi
- if [[ $device_proc == 1 && $device_mode == "DFU" ]]; then
- log "SRTG: $device_srtg"
- if [[ $device_srtg == "iBoot-636.66.3x" ]]; then
- device_pwnd="Pwnage 2.0"
- else
- log "Found an S5L8900 device in $device_mode mode. Your device needs to be in WTF mode to continue."
- print "* Force restart your device and place it in normal or recovery mode, then re-enter WTF mode."
- print "* You can enter WTF mode by doing the DFU mode procedure."
- echo
- device_dfuhelper norec WTFreal
- device_find_mode WTFreal 100
- fi
- fi
- # set device_use_vers, device_use_build (where to get the baseband and manifest from for ota/other)
- # for a7/a8 other restores 11.3+, device_latest_vers and device_latest_build are used
- # these latest versions are not expected to change anymore (maybe except for 18.x)
- case $device_type in
- iPhone1,1 | iPod1,1 )
- device_use_vers="3.1.3"
- device_use_build="7E18"
- ;;
- iPhone1,2 | iPod2,1 )
- device_use_vers="4.2.1"
- device_use_build="8C148"
- ;;
- iPad1,1 | iPod3,1 )
- device_use_vers="5.1.1"
- device_use_build="9B206"
- ;;
- iPhone2,1 | iPod4,1 )
- device_use_vers="6.1.6"
- device_use_build="10B500"
- ;;
- iPhone3,[123] )
- device_use_vers="7.1.2"
- device_use_build="11D257"
- ;;
- iPad2,[1245] | iPad3,1 | iPod5,1 )
- device_use_vers="9.3.5"
- device_use_build="13G36"
- ;;
- iPad2,[367] | iPad3,[23] | iPhone4,1 )
- device_use_vers="9.3.6"
- device_use_build="13G37"
- ;;
- iPad3,[456] | iPhone5,[1234] ) # 10.3.4 works for ALL A6(X) devices
- device_use_vers="10.3.4"
- device_use_build="14G61"
- ;;
- iPad4,[12345] | iPhone6,[12] )
- device_use_vers="10.3.3"
- device_use_build="14G60"
- ;;
- esac
- case $device_type in
- iPad4,* | iPhone[67],* | iPod7,1 )
- device_latest_vers="12.5.8"
- device_latest_build="16H88"
- ;;
- iPad5,* | iPhone[89],* | iPod9,1 )
- device_latest_vers="15.8.8"
- device_latest_build="19H422"
- ;;
- iPad6,* | iPhone10,* )
- device_latest_vers="16.7.16"
- device_latest_build="20H392"
- ;;
- iPad7,[123456] )
- device_latest_vers="17.7.11"
- device_latest_build="21H461"
- ;;
- iPad7,1[12] | iPhone11,* )
- device_latest_vers="18.7.9"
- device_latest_build="22H355"
- ;;
- esac
- # if latest vers is not set, copy use vers to latest
- if [[ -z $device_latest_vers ]]; then
- device_latest_vers="$device_use_vers"
- device_latest_build="$device_use_build"
- fi
- # if still not set and on linux, get from ipsw.me
- if [[ -z $device_latest_vers && $platform == "linux" ]]; then
- log "Getting latest iOS version for $device_type"
- download_from_url "https://api.ipsw.me/v4/device/$device_type?type=ipsw" tmp.json
- local latestver="$(cat tmp.json | $jq -j ".firmwares[0]")"
- device_latest_vers="$(echo "$latestver" | $jq -j ".version")"
- device_latest_build="$(echo "$latestver" | $jq -j ".buildid")"
- fi
- # set device_use_bb, device_use_bb_sha1 (what baseband to use for ota/other)
- # for a7/a8 other restores 11.3+, device_latest_bb and device_latest_bb_sha1 are used instead
- case $device_type in
- iPhone4,1 ) # MDM6610
- device_use_bb="Trek-6.7.00.Release.bbfw"
- device_use_bb_sha1="22a35425a3cdf8fa1458b5116cfb199448eecf49"
- ;;
- iPad2,[67] ) # MDM9615 9.3.6 (32bit)
- device_use_bb="Mav5-11.80.00.Release.bbfw"
- device_use_bb_sha1="aa52cf75b82fc686f94772e216008345b6a2a750"
- ;;
- iPhone5,[12] | iPad3,[56] ) # MDM9615 10.3.4 (32bit)
- device_use_bb="Mav5-11.80.00.Release.bbfw"
- device_use_bb_sha1="8951cf09f16029c5c0533e951eb4c06609d0ba7f"
- ;;
- iPad4,[235] | iPhone5,[34] | iPhone6,[12] ) # MDM9615 10.3.3 (5C, 5S, air, mini2)
- device_use_bb="Mav7Mav8-7.60.00.Release.bbfw"
- device_use_bb_sha1="f397724367f6bed459cf8f3d523553c13e8ae12c"
- ;;
- iPad1,1 | iPhone[123],* ) device_use_bb2=1;;
- iPad[23],[23] ) device_use_bb2=2;;
- esac
- case $device_type in
- iPad4,[235689] | iPhone6,[12] ) # MDM9615 12.4-latest
- device_latest_bb="Mav7Mav8-10.80.02.Release.bbfw"
- device_latest_bb_sha1="f5db17f72a78d807a791138cd5ca87d2f5e859f0"
- ;;
- esac
- # if use bb is not set but latest bb is set, copy latest bb to use
- if [[ -z $device_use_bb && -n $device_latest_bb ]]; then
- device_use_bb="$device_latest_bb"
- device_use_bb_sha1="$device_latest_bb_sha1"
- fi
- # disable baseband update if var is set to 1 (manually disabled w/ --disable-bbupdate arg)
- if [[ $device_disable_bbupdate == 1 && $device_use_bb != 0 ]] && (( device_proc < 7 )); then
- device_disable_bbupdate="$device_type"
- fi
- # enable activation records flag if device is a5(x)/a6(x), normal mode, and activated
- if [[ $device_proc == 5 || $device_proc == 6 ]] && [[ -z $device_disable_actrec ]]; then
- if [[ $device_mode == "Normal" && $device_unactivated != 1 && $device_imei == "9900"* ]]; then
- device_actrec=1
- device_auto_actrec=1
- elif [[ -s ../saved/$device_type/activation-$device_ecid.tar ]]; then
- device_actrec=1
- device_auto_actrec=2
- elif [[ $device_type == "iPad3,3" && $device_mode == "Normal" && $device_unactivated != 1 ]]; then
- device_actrec=1
- device_auto_actrec=3
- fi
- fi
- if [[ $device_argmode == "none" ]]; then
- device_mode="none"
- device_vers="Unknown"
- fi
- # powdersn0w device and base version support
- case $device_type in
- iPhone[345],* | iPad1,1 | iPad2,[4567] | iPad3,* | iPod[35],1 ) device_canpowder=1;;
- esac
- check_vers="7.1"
- case $device_type in
- iPad3,[456] | iPhone5,* | iPod5,1 ) check_vers="7";;
- iPad2,[567] ) check_vers="7.0";;
- esac
- base_vers="$check_vers.x"
- if [[ $device_proc == 4 ]]; then
- check_vers="$device_latest_vers"
- base_vers="$device_latest_vers"
- fi
- }
- device_find_mode() {
- # usage: device_find_mode {DFU,Recovery,Restore} {Timeout (default: 24 for linux, 4 for other)}
- # finds device in given mode, and sets the device_mode variable
- local usb
- local timeout=4
- local i=0
- local device_in
- local mode="$1"
- local mode2
- local wtfreal
- if [[ $mode == "Recovery" ]]; then
- usb=1281
- elif [[ $device_proc == 1 ]]; then
- usb=1222
- if [[ $mode == "DFUreal" ]]; then
- mode="DFU"
- usb=1227
- elif [[ $mode == "WTFreal" ]]; then
- mode="WTF"
- wtfreal=1
- elif [[ $mode == "DFU" ]]; then
- mode="WTF"
- fi
- else
- usb=1227
- fi
- if [[ -n $2 ]]; then
- timeout=$2
- elif [[ $platform == "linux" ]]; then
- timeout=24
- fi
- log "Finding device in $mode mode..."
- while (( i < timeout )); do
- if [[ $platform == "linux" ]]; then
- device_in=$(lsusb | grep -c "05ac:$usb")
- fi
- if [[ $mode == "Recovery" && $timeout == 50 ]]; then # find recovery/dfu instead of just recovery, only if timeout is 50
- mode2="$($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-)"
- if [[ -n $mode2 ]]; then
- device_in=1
- mode="$mode2"
- fi
- elif [[ $platform != "linux" ]]; then
- mode2="$($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-)"
- if [[ $mode2 == "$mode" ]]; then
- device_in=1
- fi
- fi
- if [[ $device_in == 1 ]]; then
- log "Found device in $mode mode."
- device_mode="$mode"
- break
- fi
- sleep 1
- ((i++))
- done
- if [[ $device_in != 1 ]]; then
- if [[ $timeout != 1 && $timeout != 20 ]]; then
- error "Failed to find device in $mode mode (Timed out). Please run the script again."
- fi
- return 1
- elif [[ $mode == "WTF" && $wtfreal != 1 ]]; then
- device_s5l8900xall
- fi
- }
- device_sshpass() {
- # ask for device password and use sshpass for scp and ssh
- ssh_user="root"
- if (( device_vers_maj >= 15 )); then
- log "iOS 15+ device detected. Connecting to device SSH as mobile..."
- ssh_user="mobile"
- fi
- local pass="$1"
- if [[ -z $pass ]]; then
- read -s -p "$(input "Enter the SSH $ssh_user password of your iOS device: ")" pass
- echo
- fi
- if [[ -z $pass ]]; then
- pass="alpine"
- fi
- export SSHPASS="$pass"
- if [[ "$SSHPASS" == *" "* ]]; then
- warn "Your SSH password contains spaces. sshpass will not be used for this session"
- print "* It is recommended to change your password to remove spaces"
- else
- scp="$dir/sshpass -p$SSHPASS "
- ssh="$scp"
- fi
- scp+="$scp2"
- ssh+="$ssh2"
- }
- device_iproxy() {
- local port=22
- log "Running iproxy for SSH..."
- if [[ -n $2 ]]; then
- port=$2
- fi
- if [[ $1 == "no-logging" && $debug_mode != 1 ]]; then
- "$dir/iproxy" $ssh_port $port -s 127.0.0.1 >/dev/null &
- iproxy_pid=$!
- else
- "$dir/iproxy" $ssh_port $port -s 127.0.0.1 &
- iproxy_pid=$!
- fi
- log "iproxy PID: $iproxy_pid"
- sleep 1
- }
- device_find_all() {
- # find device stuff from palera1n legacy
- local opt
- if [[ $1 == "norec" || $mode == "device_dfuhelper" ]]; then
- return
- fi
- if [[ $platform == "macos" ]]; then
- opt="$(ioreg -p IOUSB -l 2>/dev/null | awk -F'= ' '/idVendor/ {v=$2} /idProduct/ {p=$2; if (v == 1452) printf "%04x\n", p}' | grep '^12')"
- elif [[ $platform == "linux" ]]; then
- opt="$(lsusb | cut -d' ' -f6 | grep '05ac:' | cut -d: -f2)"
- fi
- case $opt in
- 1227 ) return 1;; # dfu
- 1281 ) return 2;; # recovery
- 1222 ) return 3;; # wtf
- 12[9a][0123456789abcdef] ) return 4;; # normal
- esac
- }
- device_dfuhelper2() {
- local top="SIDE"
- if [[ $device_type == "iPad"* ]]; then
- top="TOP"
- fi
- echo
- print "* Press the VOL UP button now."
- sleep 1
- print "* Press the VOL DOWN button now."
- sleep 1
- print "* Press and hold the $top button."
- for i in {10..1}; do
- echo -n "$i "
- sleep 1
- done
- echo -e "\n$(print "* Press and hold VOL DOWN and $top buttons.")"
- for i in {5..1}; do
- echo -n "$i "
- sleep 1
- done
- echo -e "\n$(print "* Release $top button and keep holding VOL DOWN button.")"
- for i in {8..1}; do
- echo -n "$i "
- device_find_all $1
- opt=$?
- if [[ $opt == 1 ]]; then
- echo -e "\n$(log 'Found device in DFU mode.')"
- device_mode="DFU"
- return
- fi
- sleep 1
- done
- echo
- device_find_mode DFU
- }
- device_dfuhelper3() {
- local sec=10
- if [[ $device_mode == "Recovery" ]]; then
- sec=8
- fi
- echo -e "\n$(print "* Hold TOP and HOME buttons.")"
- while (( sec > 0 )); do
- echo -n "$sec "
- sleep 1
- sec=$((sec-1))
- done
- echo -e "\n$(print "* Release TOP button and keep holding HOME button.")"
- for i in {13..1}; do
- echo -n "$i "
- sleep 1
- done
- echo
- if [[ $1 == "WTFreal" ]]; then
- device_find_mode WTFreal
- else
- device_find_mode DFU
- fi
- }
- device_dfuhelper() {
- local opt
- local rec=" recovery mode"
- if [[ $1 == "norec" || $mode == "device_dfuhelper" ]]; then
- rec=
- fi
- if [[ $device_mode == "DFU" && $1 == "DFUreal" ]]; then
- log "Device is already in DFU mode"
- return
- fi
- if [[ $device_mode == "DFU" && $mode != "device_dfuhelper" && $device_proc != 1 ]]; then
- log "Device is already in DFU mode"
- return
- fi
- print "* DFU Mode Helper - Get ready to enter DFU mode."
- print "* If you already know how to enter DFU mode, you may do so right now before continuing."
- select_yesno "Select Y to continue, N to exit$rec" 1
- if [[ $? != 1 ]]; then
- if [[ -z $1 && $device_mode == "Recovery" ]]; then
- log "Attempting to exit Recovery mode."
- $irecovery -n
- fi
- exit
- fi
- print "* Get ready..."
- device_mode="$($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-)"
- if [[ $device_mode == "DFU" && $mode != "device_dfuhelper" ]]; then
- log "Found device in DFU mode."
- return
- elif [[ -n $device_mode ]]; then
- for i in {3..1}; do
- echo -n "$i "
- sleep 1
- done
- fi
- case $device_type in
- iPhone1,* | iPod1,1 ) device_dfuhelper3 $2; return;;
- iPad1,1 | iPad1[12]* ) :;;
- iPhone1* | iPad[81]* ) device_dfuhelper2; return;;
- esac
- local top="TOP"
- local home="HOME"
- case $device_type in
- iPhone[79],* | iPhone8,[12] ) top="SIDE";;
- esac
- if [[ $device_type == "iPhone9,"* || $device_type == "iPod9,1" ]]; then
- home="VOL DOWN"
- fi
- local sec=10
- if [[ $device_mode == "Recovery" ]]; then
- sec=8
- fi
- echo -e "\n$(print "* Hold $top and $home buttons.")"
- while (( sec > 0 )); do
- echo -n "$sec "
- device_find_all $1
- opt=$?
- if [[ $opt == 1 ]]; then
- echo -e "\n$(log 'Found device in DFU mode.')"
- device_mode="DFU"
- return
- fi
- sleep 1
- sec=$((sec-1))
- done
- echo -e "\n$(print "* Release $top button and keep holding $home button.")"
- for i in {8..1}; do
- echo -n "$i "
- device_find_all $1
- opt=$?
- if [[ $opt == 1 ]]; then
- echo -e "\n$(log 'Found device in DFU mode.')"
- device_mode="DFU"
- return
- fi
- sleep 1
- done
- echo
- device_find_mode DFU
- }
- device_enter_mode() {
- # usage: device_enter_mode {Recovery, DFU, kDFU, pwnDFU}
- # attempt to enter given mode, and device_find_mode function will then set device_mode variable
- local opt
- case $1 in
- "WTFreal" )
- if [[ $device_mode == "WTF" ]]; then
- return
- elif [[ $device_mode == "Normal" ]]; then
- device_enter_mode Recovery
- fi
- if [[ $device_mode == "Recovery" ]]; then
- device_dfuhelper norec WTFreal
- return
- fi
- log "Found an S5L8900 device in $device_mode mode. Your device needs to be in WTF mode to continue."
- print "* Force restart your device and place it in normal or recovery mode, then re-enter WTF mode."
- print "* You can enter WTF mode by doing the DFU mode procedure."
- echo
- device_dfuhelper norec WTFreal
- device_find_mode WTFreal 100
- ;;
- "Recovery" )
- if [[ $device_mode == "Normal" ]]; then
- device_pair
- if [[ $mode != "enterrecovery" ]]; then
- print "* The device needs to be in Recovery/DFU mode before proceeding."
- select_yesno "Send device to recovery mode?" 1
- if [[ $? != 1 ]]; then
- log "User selected N, cannot continue. Exiting."
- exit
- fi
- fi
- log "Entering recovery mode..."
- print "* If the device does not enter recovery mode automatically, try putting the device in Recovery/DFU mode manually. You may also press Ctrl+C to cancel"
- "$dir/ideviceenterrecovery" "$device_udid" >/dev/null
- device_find_mode Recovery 50
- fi
- ;;
- "DFU" )
- if [[ $device_mode == "Normal" ]]; then
- device_enter_mode Recovery
- elif [[ $device_mode == "WTF" ]]; then
- device_s5l8900xall
- return
- elif [[ $device_mode == "DFU" ]]; then
- return
- fi
- device_dfuhelper DFUreal
- ;;
- "kDFU" )
- local sendfiles=()
- local ip="127.0.0.1"
- if [[ $device_mode != "Normal" ]]; then
- device_enter_mode pwnDFU
- return
- fi
- echo "chmod +x /tmp/kloader*" > kloaders
- opt="kloader"
- if (( device_vers_maj <= 5 )); then
- opt="kloader_axi0mX"
- case $device_type in
- iPad2,4 | iPad3,* ) opt="kloader5";; # needed for ipad 3 ios 5, unsure for ipad2,4
- esac
- log "Using $opt for $device_type iOS $device_vers_maj"
- fi
- echo "/tmp/$opt /tmp/pwnediBSS" >> kloaders
- sendfiles+=("../resources/kloader/$opt" "kloaders" "pwnediBSS")
- patch_ibss
- device_iproxy
- if [[ $device_jailbrokenselected != 1 ]]; then
- device_ssh_message
- print "3. On entering kDFU mode, the device will disconnect."
- print " - Proceed to unplug and replug the device when prompted."
- print " - Alternatively, press the TOP or HOME button."
- device_sshpass
- fi
- log "Entering kDFU mode..."
- print "* This may take a while, but should not take longer than a minute."
- log "Sending files to device: ${sendfiles[*]}"
- if [[ $device_vers_maj == 10 ]]; then
- for file in "${sendfiles[@]}"; do
- cat $file | $ssh -p $ssh_port root@127.0.0.1 "cat > /tmp/$(basename $file)" &>scp.log &
- done
- sleep 3
- cat scp.log
- check="$(cat scp.log | grep -c "Connection reset")"
- else
- $scp -P $ssh_port ${sendfiles[@]} root@127.0.0.1:/tmp
- check=$?
- fi
- if [[ $check == 0 ]]; then
- log "Running kloader"
- $ssh -p $ssh_port root@127.0.0.1 "bash /tmp/kloaders" &
- else
- warn "Failed to connect to device via USB SSH."
- if [[ $device_vers_maj == 10 ]]; then
- print "* Try to re-install both OpenSSH and Dropbear, reboot, re-jailbreak, and try again."
- error "Failed to connect to device via SSH, cannot continue."
- else
- print "* Try to re-install OpenSSH, reboot, re-jailbreak if needed, and try again."
- fi
- input "Press Enter/Return to try again with Wi-Fi SSH (or press Ctrl+C to cancel and try again)"
- read -s
- log "Trying again with Wi-Fi SSH..."
- print "* Make sure that your iOS device and PC/Mac are on the same network."
- print "* To get your iOS device's IP Address, go to: Settings -> Wi-Fi/WLAN -> tap the 'i' or '>' next to your network name"
- ip=
- until [[ -n $ip ]]; do
- read -p "$(input 'Enter the IP Address of your device: ')" ip
- done
- log "Sending files to device: ${sendfiles[*]}"
- $scp ${sendfiles[@]} root@$ip:/tmp
- if [[ $? != 0 ]]; then
- error "Failed to connect to device via SSH, cannot continue."
- fi
- log "Running kloader"
- $ssh root@$ip "bash /tmp/kloaders" &
- fi
- local attempt=1
- local device_in
- local port
- if [[ $ip == "127.0.0.1" ]]; then
- port="-p $ssh_port"
- fi
- while (( attempt <= 5 )); do
- log "Finding device in kDFU mode... (Attempt $attempt of 5)"
- if [[ $($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-) == "DFU" ]]; then
- device_in=1
- fi
- if [[ $device_in == 1 ]]; then
- log "Found device in kDFU mode."
- device_mode="DFU"
- break
- fi
- if [[ $opt == "kloader_axi0mX" ]]; then
- print "* Keep the device plugged in"
- $ssh $port root@$ip "bash /tmp/kloaders" &
- else
- print "* Unplug and replug your device now"
- fi
- ((attempt++))
- done
- if (( attempt > 5 )); then
- error "Failed to find device in kDFU mode. Please run the script again"
- fi
- kill $iproxy_pid
- ;;
- "pwnDFU" )
- local irec_pwned
- local tool_pwned
- local tool
- if [[ $device_skip_ibss == 1 ]]; then
- warn "Skip iBSS flag detected, skipping pwned DFU check. Proceed with caution"
- return
- elif [[ $device_pwnrec == 1 ]]; then
- warn "Pwned recovery flag detected, skipping pwned DFU check. Proceed with caution"
- return
- elif [[ $device_proc == 1 ]]; then
- device_enter_mode DFU
- return
- fi
- if [[ $device_mode == "DFU" ]]; then
- device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
- device_srtg="$($irecovery -q | grep "SRTG" | cut -c 7-)"
- fi
- if [[ -n $device_pwnd ]]; then
- log "Device seems to be already in pwned DFU mode"
- print "* Pwned: $device_pwnd"
- case $device_proc in
- [56] ) device_send_unpacked_ibss;;
- [789] | 10 )
- if [[ $device_proc == 7 && $device_pwnd == "checkm8" ]]; then
- warn "Device is not pwned with ipwnder or updated gaster. Restoring/ramdisk booting will fail."
- fi
- log "gaster reset"
- $gaster reset
- ;;
- esac
- return
- elif [[ $device_mode == "DFU" && $device_boot4 != 1 && $device_srtg != "iBoot"* ]] &&
- [[ $device_proc == 4 || $device_proc == 5 || $device_proc == 6 ]]; then
- log "No SRTG for device in DFU mode! Already pwned iBSS mode?"
- print "* If your device is not in pwnDFU/kDFU mode, sending iBEC will fail."
- return
- fi
- if [[ $device_proc == 5 ]]; then
- if [[ $device_mode != "DFU" ]]; then
- device_enter_mode DFU
- log "Device is now in DFU mode. Now put your device in PWNED DFU mode using checkm8-a5."
- fi
- echo
- print "* DFU mode for A5(X) device - Make sure that your device is in PWNED DFU mode."
- print "* You need to have an Raspberry Pi Pico or Arduino+USB Host Shield for checkm8-a5."
- print "* For more details, go to: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/checkm8-a5"
- echo
- print "* As much as possible, RESTART YOUR DEVICE IN NORMAL MODE AND USE THE JAILBREAK/KDFU METHOD INSTEAD."
- echo
- log "After putting your device in PWNED DFU, plug it back in your PC/Mac before pressing Enter/Return."
- pause
- echo
- log "Checking for device"
- device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
- if [[ -n $device_pwnd ]]; then
- log "Found device in pwned DFU mode."
- print "* Pwned: $device_pwnd"
- else
- local error_msg=$'\n* If you have just used checkm8-a5, it may have just failed. Just re-enter DFU and retry.'
- if [[ $mode != "device_justboot" && $device_target_tethered != 1 ]]; then
- error_msg+=$'\n\n* As much as possible, RESTART YOUR DEVICE IN NORMAL MODE AND USE THE JAILBREAK/KDFU METHOD INSTEAD.'
- error_msg+=$'\n* You just need to have OpenSSH installed from Cydia.'
- error_msg+=$'\n - https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Restore-32-bit-Device'
- fi
- error_msg+=$'\n* Exit DFU mode first by holding the TOP and HOME buttons for about 10 seconds.'
- error_msg+=$'\n* For more info about kDFU/pwnDFU, read the "Troubleshooting" wiki page in GitHub'
- error_msg+=$'\n* Troubleshooting link: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Troubleshooting#dfu-advanced-menu-a5x-pwndfu-mode-with-arduino-and-usb-host-shield'
- error "32-bit A5 device is NOT in PWNED DFU mode. Already pwned iBSS mode?" "$error_msg"
- fi
- device_send_unpacked_ibss
- return
- fi
- device_enter_mode DFU
- tool="gaster"
- if [[ $device_proc == 4 ]]; then
- tool="primepwn"
- if [[ $platform == "macos" && $device_type != "iPod2,1" ]]; then
- tool="ipwnder_lite"
- fi
- elif [[ $device_proc == 6 ]]; then
- tool="litera1n"
- if [[ $platform == "macos" ]]; then
- tool="ipwnder32"
- if [[ $platform_arch == "arm64" ]]; then
- tool="ipwnder_lite"
- fi
- elif [[ $device_type == "iPhone5,"* ]]; then
- tool="a6meowing"
- fi
- elif [[ $device_proc == 7 && $platform == "macos" && $platform_arch == "arm64" ]]; then
- tool="ipwnder_lite"
- fi
- if [[ $platform == "linux" ]]; then
- log "CPU: $platform_cpu"
- print "* Include this in your log/screenshot for pwning assistance if needed."
- fi
- log "Placing device to pwnDFU mode using $tool"
- print "* If pwning fails and gets stuck, you can press Ctrl+C to cancel, then re-enter DFU and retry."
- if [[ $tool == "gaster" ]]; then
- $gaster pwn
- tool_pwned=$?
- log "gaster reset"
- $gaster reset
- elif [[ $tool == "a6meowing" ]]; then
- $a6meowing
- tool_pwned=$?
- elif [[ $tool == "litera1n" ]]; then
- kuroutadori_init
- kuroutadori_litera1n -p
- tool_pwned=$?
- elif [[ $tool == "ipwnder32" ]]; then
- "$dir/ipwnder32" -p --noibss
- tool_pwned=$?
- elif [[ $tool == "ipwnder_lite" ]]; then
- mkdir -p image3 ../saved/image3
- cp ../saved/image3/* image3/ 2>/dev/null
- "$dir/ipwnder" -pv
- tool_pwned=$?
- cp image3/* ../saved/image3/ 2>/dev/null
- log "gaster reset"
- $gaster reset
- elif [[ $tool == "primepwn" ]]; then
- $primepwn
- tool_pwned=$?
- fi
- sleep 1
- log "Checking for device"
- irec_pwned=$($irecovery -q | grep -c "PWND")
- device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
- # irec_pwned is instances of "PWND" in serial, must be 1
- # tool_pwned is error code of pwning tool, must be 0
- if [[ $irec_pwned != 1 && $tool_pwned != 0 ]]; then
- device_pwnerror
- fi
- if [[ -n $device_pwnd ]]; then
- log "Found device in pwned DFU mode."
- print "* Pwned: $device_pwnd"
- if [[ $device_proc == 6 ]]; then
- device_send_unpacked_ibss
- fi
- elif [[ $device_proc == 6 ]]; then
- device_srtg="$($irecovery -q | grep "SRTG" | cut -c 7-)"
- if [[ $device_srtg != "iBoot"* ]]; then
- log "Found device in pwned iBSS mode."
- else
- device_pwnerror
- fi
- else
- device_pwnerror
- fi
- ;;
- esac
- }
- device_pwnerror() {
- local error_msg=$'\n* Exit DFU mode first by holding the TOP and HOME buttons for about 10 seconds.'
- if [[ $platform == "linux" ]]; then
- [[ $platform_cpu == "AMD"* ]] && error_msg+=$'\n\n* Unfortunately, pwning may have low success rates on AMD desktop CPUs if you have one.'
- [[ $device_proc == 6 || $device_proc == 7 ]] && error_msg+=$'\n* Also, success rates for A6 and A7 checkm8 are lower on Linux.'
- error_msg+=$'\n* Pwning using an Intel PC or another Mac or iOS device may be better options if needed.'
- if [[ $device_proc == 6 && $mode != "device_justboot" && $device_target_tethered != 1 ]]; then
- error_msg+=$'\n\n* As much as possible, RESTART YOUR DEVICE IN NORMAL MODE AND USE THE JAILBREAK/KDFU METHOD INSTEAD.'
- error_msg+=$'\n* You just need to have OpenSSH (and Dropbear if on iOS 10) installed from Cydia/Zebra.'
- error_msg+=$'\n - https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Restore-32-bit-Device'
- fi
- fi
- error_msg+=$'\n\n* For more details, read the "Troubleshooting" wiki page in GitHub'
- error_msg+=$'\n* Troubleshooting links:
- - https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Troubleshooting
- - https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Pwning-Using-Another-iOS-Device'
- [[ $platform == "linux" ]] && log "CPU: $platform_cpu"
- error "Failed to enter pwnDFU mode. Please run the script again." "$error_msg"
- }
- device_send_unpacked_ibss() {
- local pwnrec="pwned iBSS"
- local tool_pwned
- if [[ $device_boot4 == 1 ]]; then
- pwnrec="pwned recovery"
- cp iBSS.patched pwnediBSS
- else
- device_rd_build=
- patch_ibss
- fi
- if [[ $device_pwnd == *"wnder" ]]; then
- log "Sending packed iBSS..."
- $primepwn pwnediBSS.dfu
- tool_pwned=$?
- elif [[ $device_proc == 6 ]]; then
- log "gaster reset"
- $gaster reset
- sleep 1
- log "Sending iBSS..."
- $irecovery -f pwnediBSS.dfu
- tool_pwned=$?
- else
- log "Sending unpacked iBSS..."
- $primepwn pwnediBSS
- tool_pwned=$?
- fi
- rm -f pwnediBSS
- if [[ $tool_pwned != 0 ]]; then
- error "Failed to send iBSS. Your device has likely failed to enter PWNED DFU mode." \
- "* You might need to exit DFU and (re-)enter PWNED DFU mode before retrying."
- fi
- sleep 1
- log "Checking for device"
- local irec="$($irecovery -q 2>&1)"
- device_pwnd="$(echo "$irec" | grep "PWND" | cut -c 7-)"
- if [[ -z $device_pwnd && $irec != "ERROR"* ]]; then
- log "Device should now be in $pwnrec mode."
- elif [[ $device_proc == 5 ]]; then
- error "Device failed to enter $pwnrec mode." \
- "* If you are using Arduino for checkm8-a5, make sure you are using my (LukeZGD) or synackuk fork of checkm8-a5. Do not use a1exdandy checkm8-a5."
- else
- error "Device failed to enter $pwnrec mode."
- fi
- }
- ipwndfu_init() {
- local ipwndfu_comm="6f5df8d84eaca33c2373118c68a25c72a797454f"
- local ipwndfu_sha1="04cc31dd1ed79705a51e8aba7e1e805fbf6fe1f4"
- ipwndfu="ipwndfu_python3"
- if [[ $device_sudoloop == 1 ]]; then
- psudo="$sudo"
- fi
- if [[ $platform == "macos" ]] && (( mac_majver <= 11 )); then
- ipwndfu="ipwndfu"
- ipwndfu_comm="1536e97dfbe22115693c3609d62014be62f974b6"
- ipwndfu_sha1="8202c12ad4e302ef1eda305d6479cfb541c8179c"
- fi
- if [[ ! -s ../saved/$ipwndfu/ipwndfu || $(cat ../saved/$ipwndfu/sha1check) != "$ipwndfu_sha1" ]]; then
- rm -rf ../saved/$ipwndfu
- file_download https://github.com/LukeZGD/ipwndfu/archive/$ipwndfu_comm.zip ipwndfu.zip $ipwndfu_sha1
- file_extract ipwndfu.zip
- mv ipwndfu-* ../saved/$ipwndfu
- echo "$ipwndfu_sha1" > ../saved/$ipwndfu/sha1check
- fi
- }
- kuroutadori_init() {
- local comm="https://sep.lol/files/legacypreviews/v1.0.2/a3ad4e6e525393239b3ac4ad58499f25a336b03b97cba6fba4f3a273c8505653548f2c7ad37fc18b1e69e0fddb5b73a3/kurouta_dori_v1.0.2_75aab959_legacymacosx.tar.gz"
- local sha1="61d3d964d194fd9a2084045c3cd95dc3e7920015"
- kuroutadori="kuroutadori_${platform}"
- if [[ $device_sudoloop == 1 ]]; then
- psudo="$sudo"
- [[ -n $device_ra1n_timeout ]] && psudo+=" RA1N_ABORT_TIMEOUT=$device_ra1n_timeout"
- elif [[ -n $device_ra1n_timeout ]]; then
- psudo="env RA1N_ABORT_TIMEOUT=$device_ra1n_timeout"
- fi
- if [[ $platform == "linux" ]]; then
- kuroutadori+="-${platform_arch}"
- comm="https://sep.lol/files/legacypreviews/v1.0.2/37daa814d98a38640813527be6c82ec1ee0561923b543c2290a0d519e9b2e7f7b73147a26e38d7f8a849fd70e0713125/kurouta_dori_v1.0.2_75aab959_linux-amd64.tar.gz"
- sha1="6d801a59979c64ff73015a8bfc950518dc043525"
- if [[ $platform_arch == "arm64" ]]; then
- comm="https://sep.lol/files/legacypreviews/v1.0.2/e04e9d27bcb8339e2e876ad92cc751b1e679b1ce91d2807b13ff1bc820d97349ee5ce5d1c58e61ec062e1a6b7bc2b726/kurouta_dori_v1.0.2_75aab959_linux-arm64.tar.gz"
- sha1="1dea1e3e5c7ca921ea6f6380ed0261d9c36a0165"
- fi
- fi
- if [[ ! -s ../saved/$kuroutadori/bin/litera1n || $(cat ../saved/$kuroutadori/sha1check) != "$sha1" ]]; then
- rm -rf ../saved/$kuroutadori
- file_download "$comm" kuroutadori.tar.gz $sha1
- mkdir -p ../saved/$kuroutadori
- tar -xvf kuroutadori.tar.gz -C ../saved/$kuroutadori
- echo "$sha1" > ../saved/$kuroutadori/sha1check
- fi
- kuroutadori="$psudo ../saved/$kuroutadori/bin"
- }
- kuroutadori_litera1n() {
- local tool_pwned
- print "* If pwning fails, try to rerun the script with --ra1n-timeout=1000000 (or adjust the value as needed)"
- print "* If it gets stuck at \"checkm8 setup stage\", unplug and replug the device."
- print "* If it gets stuck at \"Checkmate?\", press Ctrl+C to cancel, then re-enter DFU and retry."
- for i in {1..3}; do
- log "Running litera1n (attempt $i): $kuroutadori/litera1n $1"
- $kuroutadori/litera1n $1
- tool_pwned=$?
- [[ $tool_pwned == 0 || $tool_pwned == 30 ]] && break
- done
- return $tool_pwned
- }
- device_alloc8() {
- local tool_pwned=0
- device_enter_mode pwnDFU
- ipwndfu_init
- if [[ ! -s ../saved/n88ap-iBSS-4.3.5.img3 ]]; then
- local ibss_sha="eb90af5310a958e6186f32c1440002962d1f975d"
- log "Downloading iOS 4.3.5 iBSS"
- download_with_pzb "http://appldnld.apple.com/iPhone4/041-1965.20110721.gxUB5/iPhone2,1_4.3.5_8L1_Restore.ipsw" "Firmware/dfu/iBSS.n88ap.RELEASE.dfu" n88ap-iBSS-4.3.5.img3 $ibss_sha
- mv n88ap-iBSS-4.3.5.img3 ../saved/
- fi
- cp ../saved/n88ap-iBSS-4.3.5.img3 ../saved/$ipwndfu/
- pushd ../saved/$ipwndfu/ >/dev/null
- log "Installing alloc8 to device"
- $psudo ./ipwndfu -x
- tool_pwned=$?
- if [[ $device_sudoloop == 1 ]]; then
- $sudo rm -rf __pycache__/ *.pyc libusbfinder/*.pyc usb/*.pyc usb/backend/*.pyc
- fi
- popd >/dev/null
- if [[ $tool_pwned == 0 ]]; then
- log "Done!"
- else
- warn "ipwndfu alloc8 seems to have failed. Just force restart the device, enter DFU, and try again."
- print "* You may also need to force restart the device and re-enter DFU mode before retrying."
- print "* To retry, just go back to: Useful Utilities -> Install alloc8 Exploit"
- fi
- }
- file_download() {
- # usage: file_download {link} {target location} {sha1}
- local filename="$(basename $2)"
- log "Downloading $filename..."
- download_from_url "$1" "$2"
- if [[ ! -s $2 ]]; then
- error "Downloading $2 failed. Please run the script again"
- fi
- if [[ -z $3 ]]; then
- return
- fi
- local sha1=$($sha1sum $2 | awk '{print $1}')
- if [[ $sha1 != "$3" ]]; then
- error "Verifying $filename failed. The downloaded file may be corrupted or incomplete. Please run the script again" \
- "* SHA1sum mismatch. Expected $3, got $sha1"
- fi
- }
- device_fw_key_check() {
- # check and download keys for device_target_build, then set the variable device_fw_key (or device_fw_key_base)
- local key
- local build="$device_target_build"
- case $1 in
- base ) build="$device_base_build";;
- temp ) build="$2";;
- esac
- local keys_path="$device_fw_dir/$build"
- # do not continue if ipados/ios 18
- if [[ $build == "22"* ]]; then
- log "iOS 18 detected, skipping firmware key check"
- return
- fi
- log "Checking firmware keys in $keys_path"
- if [[ $(cat "$keys_path/index.html" 2>/dev/null | grep -c "$build") != 1 ]]; then
- rm -f "$keys_path/index.html"
- fi
- if [[ ! -e "$keys_path/index.html" ]]; then
- mkdir -p "$keys_path"
- local try=("https://raw.githubusercontent.com/LukeZGD/Legacy-iOS-Kit-Keys/master/$device_type/$build/index.html"
- "http://127.0.0.1:8888/firmware/$device_type/$build"
- "https://api.m1sta.xyz/wikiproxy/$device_type/$build")
- for i in "${try[@]}"; do
- log "Getting firmware keys for $device_type-$build: $i"
- download_from_url "$i" index.html
- if [[ $(cat index.html | grep -c "$build") == 1 ]]; then
- break
- fi
- rm -f index.html
- done
- if [[ $(cat index.html | grep -c "$build") != 1 ]]; then
- local error_msg="* You may need to run wikiproxy to get firmware keys."
- error_msg+=$'\n* For more details, go to the "Troubleshooting" wiki page in GitHub.'
- error_msg+=$'\n* Troubleshooting link: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Troubleshooting#running-wikiproxy'
- error "Failed to download firmware keys." "$error_msg"
- fi
- mv index.html "$keys_path/"
- fi
- if [[ $1 == "base" ]]; then
- device_fw_key_base="$(cat $keys_path/index.html)"
- elif [[ $1 == "temp" ]]; then
- device_fw_key_temp="$(cat $keys_path/index.html)"
- else
- device_fw_key="$(cat $keys_path/index.html)"
- fi
- }
- ipsw_get_url() {
- local build_id="$1"
- local device_type="$device_type"
- local device_fw_dir="$device_fw_dir"
- if [[ -n $2 ]]; then
- device_type="$2"
- device_fw_dir="../saved/firmware/$device_type"
- fi
- local version="$3"
- local url="$(cat "$device_fw_dir/$build_id/url" 2>/dev/null)"
- local url_local="$url"
- local ipg_url
- ipsw_url=
- log "Checking URL in $device_fw_dir/$build_id/url"
- if [[ $(echo "$url" | grep -c '<') != 0 || $url != *"$build_id"* ]]; then
- rm -f "$device_fw_dir/$build_id/url"
- url=
- fi
- case $device_type in
- iPod1,1 ) [[ $build_id == "5"* || $build_id == "7"* ]] && ipg_url=1;;
- iPod2,1 ) [[ $build_id == "7"* ]] && ipg_url=1;;
- esac
- if [[ $ipg_url == 1 ]]; then
- if [[ -z $version ]]; then
- download_appledb ios $build_id
- version="$(cat tmp.json | $jq -r ".version")"
- fi
- url="https://invoxiplaygames.uk/ipsw/${device_type}_${version}_${build_id}_Restore.ipsw"
- fi
- if [[ -z $url ]]; then
- log "Getting URL for $device_type-$build_id"
- download_appledb ios $build_id
- url="$(cat tmp.json | $jq -r ".sources[] | select(.type == \"ipsw\" and any(.deviceMap[]; . == \"$device_type\")) | .links[0].url")"
- local url2="$(echo "$url" | tr '[:upper:]' '[:lower:]')"
- local build_id2="$(echo "$build_id" | tr '[:upper:]' '[:lower:]')"
- if [[ $(echo "$url" | grep -c '<') != 0 || $url2 != *"$build_id2"* ]]; then
- if [[ -n $url_local ]]; then
- url="$url_local"
- log "Using saved URL for this IPSW: $url"
- echo "$url" > $device_fw_dir/$build_id/url
- ipsw_url="$url"
- return
- fi
- if [[ $ipsw_isbeta != 1 ]]; then
- error "Unable to get URL for $device_type-$build_id"
- fi
- fi
- mkdir -p $device_fw_dir/$build_id
- echo "$url" > $device_fw_dir/$build_id/url
- fi
- ipsw_url="$url"
- }
- download_appledb() {
- local query="$1"
- if [[ $query == "ios" ]]; then
- local phone="iOS" # iOS
- local build_id="$2"
- case $build_id in
- [23][0123456789]* | 7B405 | 7B500 ) :;;
- 1[AC]* | [2345]* ) phone="iPhone%20Software";; # iPhone Software
- 7* ) phone="iPhone%20OS";; # iPhone OS
- esac
- if [[ $device_type == "iPad"* ]]; then
- case $build_id in
- 1[789]* | [23]* ) phone="iPadOS";; # iPadOS
- esac
- fi
- query="ios/${phone};${build_id}"
- fi
- local try=("https://api.appledb.dev/${query}.json"
- "https://raw.githubusercontent.com/littlebyteorg/appledb/gh-pages/${query}.json")
- for request in "${try[@]}"; do
- log "AppleDB request: $request"
- download_from_url "$request" tmp.json
- [[ -s tmp.json ]] && break
- done
- if [[ ! -s tmp.json ]]; then
- error "Failed to get AppleDB request. Please run the script again"
- fi
- }
- download_comp() {
- # usage: download_comp [build_id] [comp]
- local build_id="$1"
- local comp="$2"
- ipsw_get_url $build_id
- download_targetfile="$comp.$device_model"
- if [[ $build_id != "12"* ]]; then
- download_targetfile+="ap"
- fi
- download_targetfile+=".RELEASE"
- if [[ -e "../saved/$device_type/${comp}_$build_id.dfu" ]]; then
- cp "../saved/$device_type/${comp}_$build_id.dfu" ${comp}
- else
- log "Downloading ${comp}..."
- "$dir/pzb" -g "Firmware/dfu/$download_targetfile.dfu" -o ${comp} "$ipsw_url"
- cp ${comp} "../saved/$device_type/${comp}_$build_id.dfu"
- fi
- }
- patch_ibss() {
- # creates file pwnediBSS to be sent to device
- local build_id
- case $device_type in
- iPad1,1 | iPod3,1 ) build_id="9B206";;
- iPhone2,1 | iPod4,1 ) build_id="10B500";;
- iPhone3,[123] ) build_id="11D257";;
- * ) build_id="12H321";;
- esac
- if [[ -n $device_rd_build ]]; then
- build_id="$device_rd_build"
- fi
- download_comp $build_id iBSS
- device_fw_key_check temp $build_id
- local iv=$(echo $device_fw_key_temp | $jq -j '.keys[] | select(.image == "iBSS") | .iv')
- local key=$(echo $device_fw_key_temp | $jq -j '.keys[] | select(.image == "iBSS") | .key')
- log "Decrypting iBSS..."
- "$dir/xpwntool" iBSS iBSS.dec -iv $iv -k $key
- log "Patching iBSS..."
- "$dir/iBoot32Patcher" iBSS.dec pwnediBSS --rsa
- "$dir/xpwntool" pwnediBSS pwnediBSS.dfu -t iBSS
- cp pwnediBSS pwnediBSS.dfu ../saved/$device_type/
- log "Pwned iBSS saved at: saved/$device_type/pwnediBSS"
- log "Pwned iBSS img3 saved at: saved/$device_type/pwnediBSS.dfu"
- }
- patch_ibec() {
- # creates file pwnediBEC to be sent to device for blob dumping
- local build_id
- case $device_type in
- iPad1,1 | iPod3,1 )
- build_id="9B206";;
- iPhone2,1 | iPhone3,[123] | iPod4,1 | iPad3,1 )
- build_id="10A403";;
- iPad2,[367] | iPad3,[25] )
- build_id="12H321";;
- iPhone5,3 )
- build_id="11B511";;
- iPhone5,4 )
- build_id="11B651";;
- * )
- build_id="10B329";;
- esac
- if [[ -n $device_rd_build ]]; then
- build_id="$device_rd_build"
- fi
- download_comp $build_id iBEC
- device_fw_key_check temp $build_id
- local name="iBEC"
- local iv=$(echo $device_fw_key_temp | $jq -j '.keys[] | select(.image == "iBEC") | .iv')
- local key=$(echo $device_fw_key_temp | $jq -j '.keys[] | select(.image == "iBEC") | .key')
- local address="0x80000000"
- if [[ $device_proc == 4 ]]; then
- address="0x40000000"
- fi
- mv iBEC $name.orig
- log "Decrypting iBEC..."
- "$dir/xpwntool" $name.orig $name.dec -iv $iv -k $key
- log "Patching iBEC..."
- if [[ $device_proc == 4 || -n $device_rd_build || $device_type == "iPad3,1" ]]; then
- "$dir/iBoot32Patcher" $name.dec $name.patched --rsa --ticket -b "rd=md0 -v amfi=0xff cs_enforcement_disable=1" -c "go" $address
- else
- $bspatch $name.dec $name.patched "../resources/patch/odysseus/$download_targetfile.patch"
- fi
- "$dir/xpwntool" $name.patched pwnediBEC.dfu -t $name.orig
- rm $name.dec $name.orig $name.patched
- cp pwnediBEC.dfu ../saved/$device_type/
- log "Pwned iBEC img3 saved at: saved/$device_type/pwnediBEC.dfu"
- }
- ipsw_nojailbreak_message() {
- local hac
- local tohac
- case $device_type in
- iPhone[23],1 ) hac=" (and hacktivate)"; tohac=1;;
- esac
- log "Jailbreak option is not available for this version. You may jailbreak$hac later after the restore"
- print "* To jailbreak after the restore, select \"Jailbreak Device\" in the main menu"
- if [[ $tohac == 1 ]]; then
- print "* To hacktivate, go to \"Useful Utilities -> Hacktivate Device\" after jailbreaking"
- fi
- echo
- }
- ipsw_preference_set() {
- # sets ipsw variables: ipsw_jailbreak, ipsw_memory, ipsw_verbose
- case $device_latest_vers in
- [76543]* ) ipsw_canjailbreak=1;;
- esac
- if [[ $device_target_vers == "$device_latest_vers" && $device_deadbb == 1 ]]; then
- ipsw_gasgauge_patch=1
- fi
- if [[ $device_target_tethered == 1 && $ipsw_gasgauge_patch == 1 &&
- $device_proc == 6 && $target_vers_maj == 10 ]]; then
- warn "multipatch is not supported on A6(X) tethered iOS 10, so it will be disabled."
- ipsw_gasgauge_patch=
- fi
- if (( device_proc >= 7 )) || [[ $device_target_vers == "$device_latest_vers" && $ipsw_canjailbreak != 1 && $ipsw_gasgauge_patch != 1 ]]; then
- return
- fi
- # jailbreak option: available for versions 3.1.3 to 9.3.4, with some exceptions:
- # 3.1-4.1: option is disabled due to an issue with putting .launchd_use_gmalloc in the correct partition.
- # it should be in system, but restore puts it in data instead due to it being in var.
- # for some reason though, it does it correctly on 4.x for 3gs and touch 2, so its enabled for those.
- # it also does it correctly on 3.1.3-4.x for s5l8900 devices, so its also enabled there.
- # for 3.x 3gs, and old br 3.1.3 touch 2, kernel is patched so its also supposed to be enabled for those
- # but since there is an issue with ios 3 asr when fs is modified, they are disabled for now
- # update: should be fixed after updating xpwn ipsw, will revert if reports say otherwise or if other issues pop up
- ipsw_canjailbreak=
- case $device_target_vers in
- 9.3.[4321] | 9.3 | 9.[210]* | [876543].* ) ipsw_canjailbreak=1;;
- esac
- if [[ $device_target_powder == 1 ]]; then
- case $device_target_vers in
- 4.[10]* )
- ipsw_canjailbreak=
- ipsw_nojailbreak_message
- ;;
- esac
- elif [[ $device_type == "iPod2,1" && $ipsw_24o != 1 ]]; then
- case $device_target_vers in
- 3.1* )
- ipsw_canjailbreak=
- ipsw_nojailbreak_message
- ;;
- esac
- fi
- # ipsw_nskip being 1 means that it will always create/use a custom ipsw.
- # useful for disabling baseband update, or in the case of macos arm64, not having to use futurerestore for 32-bit.
- case $device_type in
- iPad[23],[23] | "$device_disable_bbupdate" ) ipsw_nskip=1;;
- esac
- if [[ $ipsw_gasgauge_patch != 1 && $ipsw_jailbreak != 1 && $device_target_vers == "$device_latest_vers" ]]; then
- ipsw_nskip=
- elif [[ $ipsw_gasgauge_patch == 1 ]] || [[ $platform == "macos" && $platform_arch == "arm64" ]] ||
- [[ $device_proc == 5 && $target_vers_maj == 4 ]]; then
- ipsw_nskip=1
- fi
- # make jailbreak option enabled for all of 8.x-9.x if the restore is a powdersn0w one.
- # also, exit this function if ipsw_canjailbreak is not set to 1 and/or other options will not be used.
- local jbpowder
- if [[ $device_target_powder == 1 ]]; then
- case $device_target_vers in
- [98]* )
- ipsw_canjailbreak=1
- ipsw_jailbreak=1
- jbpowder=1
- log "iOS 8.x-9.x powdersn0w detected. Enabling jailbreak option"
- ;;
- esac
- elif [[ $device_target_other == 1 && $ipsw_canjailbreak != 1 && $ipsw_nskip != 1 ]]; then
- return
- fi
- # detect certain ios betas now. for ios 8, disable betas 1 and 2 since powdersn0w cant patch the kernels for those.
- # for betas below ios 6, disable the jailbreak option, its not supported since (currently) no patchfinders used there and stuff.
- if [[ $ipsw_isbeta == 1 ]]; then
- case $device_target_vers in
- 8* )
- if [[ $device_target_build == "12A4265u" || $device_target_build == "12A4297e" ]]; then
- warn "iOS 8 beta 1-2 detected. Disabling jailbreak option"
- ipsw_canjailbreak=
- ipsw_jailbreak=
- fi
- ;;
- 9.[123]* | [76]* ) :;;
- * )
- warn "iOS beta detected. Disabling jailbreak option"
- ipsw_canjailbreak=
- ipsw_jailbreak=
- ;;
- esac
- if [[ $ipsw_canjailbreak == 1 ]]; then
- warn "iOS beta detected. Jailbreak option might not work properly"
- fi
- fi
- if [[ $ipsw_fourthree == 1 ]]; then
- ipsw_jailbreak=1
- elif [[ $ipsw_jailbreak == 1 && $jbpowder != 1 ]]; then
- warn "Jailbreak flag detected, jailbreak option enabled by user."
- elif [[ $ipsw_canjailbreak == 1 && -z $ipsw_jailbreak ]]; then
- input "Jailbreak Option"
- print "* When this option is enabled, your device will be jailbroken on restore."
- print "* I recommend to enable this option to have the jailbreak and Cydia pre-installed."
- print "* This option is enabled by default (Y). Select this option if unsure."
- if [[ $device_type == "iPad2"* && $device_target_vers == "4.3"* && $device_target_tethered != 1 ]]; then
- warn "This will be a semi-tethered jailbreak. checkm8-a5 is required to boot to a jailbroken state."
- print "* To boot jailbroken later, go to: Main Menu -> Just Boot"
- elif [[ $device_type == "iPhone3,3" ]]; then
- case $device_target_vers in
- 4.2.9 | 4.2.10 )
- warn "This will be a semi-tethered jailbreak."
- print "* To boot jailbroken later, go to: Main Menu -> Just Boot"
- ;;
- esac
- fi
- select_yesno "Enable this option?" 1
- if [[ $? != 1 ]]; then
- ipsw_jailbreak=
- log "Jailbreak option disabled by user."
- else
- ipsw_jailbreak=1
- log "Jailbreak option enabled."
- fi
- echo
- fi
- if [[ $ipsw_jailbreak == 1 && -z $ipsw_hacktivate && $ipsw_canhacktivate == 1 ]]; then
- input "Hacktivate Option"
- print "* When this option is enabled, your device will be activated on restore."
- print "* Enable this option if you have no valid SIM card to activate the phone."
- print "* Disable this option if you have a working SIM card and want cellular data."
- print "* This option is disabled by default (N). Select this option if unsure."
- select_yesno "Enable this option?" 0
- if [[ $? != 0 ]]; then
- log "Hacktivate option enabled by user."
- ipsw_hacktivate=1
- else
- log "Hacktivate option disabled."
- ipsw_hacktivate=
- fi
- echo
- fi
- case $device_type in
- iPhone2,1 | iPod2,1 ) ipsw_canmemory=1;;
- iPad[23],[23] ) ipsw_canmemory=1;;
- iPhone3,1 | iPad1,1 | iPad2* | iPod[34],1 )
- case $device_target_vers in
- [34]* ) ipsw_canmemory=1;;
- esac
- ;;
- esac
- if [[ $device_proc == 1 && $device_type != "iPhone1,2" ]]; then
- ipsw_canmemory=
- elif [[ -n $device_type_special ]]; then
- ipsw_canmemory=
- elif [[ $device_proc == 6 && $target_vers_maj == 10 ]]; then
- ipsw_canmemory=
- elif [[ $device_target_powder == 1 || $device_target_tethered == 1 ||
- $ipsw_jailbreak == 1 || $ipsw_gasgauge_patch == 1 || $ipsw_nskip == 1 ||
- $device_type == "$device_disable_bbupdate" || $device_actrec == 1 ]]; then
- ipsw_canmemory=1
- fi
- if [[ $ipsw_canmemory == 1 && -z $ipsw_memory ]]; then
- input "Memory Option for creating custom IPSW"
- print "* When this option is enabled, system RAM will be used for the IPSW creation process."
- print "* I recommend to enable this option to speed up creating the custom IPSW."
- print "* However, if your PC/Mac has less than 8 GB of RAM, disable this option."
- print "* This option is enabled by default (Y). Select this option if unsure."
- select_yesno "Enable this option?" 1
- if [[ $? != 1 ]]; then
- log "Memory option disabled by user."
- ipsw_memory=
- else
- log "Memory option enabled."
- ipsw_memory=1
- fi
- echo
- fi
- if [[ $device_target_powder == 1 ]]; then
- ipsw_canverbose=1
- elif [[ $device_type == "iPhone2,1" && $device_target_other != 1 ]]; then
- case $device_target_vers in
- 6.1.6 | 4.1 ) log "3GS verbose boot is not supported on 6.1.6 and 4.1";;
- 3.0* ) log "3GS verbose boot is always enabled on 3.0.x";;
- * ) ipsw_canverbose=1;;
- esac
- fi
- if [[ $ipsw_canverbose == 1 && -z $ipsw_verbose ]]; then
- input "Verbose Boot Option"
- print "* When this option is enabled, the device will have verbose boot on restore."
- print "* This option is enabled by default (Y). Select this option if unsure."
- select_yesno "Enable this option?" 1
- if [[ $? != 1 ]]; then
- ipsw_verbose=
- log "Verbose boot option disabled by user."
- else
- ipsw_verbose=1
- log "Verbose boot option enabled."
- fi
- echo
- fi
- ipsw_custom_set
- }
- shsh_save() {
- # usage: shsh_save {apnonce (optional)}
- # sets variable shsh_path
- local version=$device_target_vers
- local build_id=$device_target_build
- local apnonce
- local shsh_check
- local buildmanifest="../resources/manifest/BuildManifest_${device_type}_${version}.plist"
- local ExtraArgs=
- if [[ $1 == "apnonce" ]]; then
- apnonce=$2
- elif [[ $1 == "version" ]]; then
- version=$2
- fi
- if [[ $version == "$device_latest_vers" || $version == "4.1" ]]; then
- if [[ $version != "4.1" ]]; then
- build_id="$device_latest_build"
- fi
- buildmanifest="../saved/$device_type/$build_id.plist"
- if [[ ! -e $buildmanifest ]]; then
- if [[ -e "$ipsw_base_path.ipsw" ]]; then
- log "Extracting BuildManifest from $version IPSW..."
- file_extract_from_archive "$ipsw_base_path.ipsw" BuildManifest.plist
- else
- ipsw_get_url $build_id
- log "Downloading BuildManifest for $version..."
- "$dir/pzb" -g BuildManifest.plist -o BuildManifest.plist "$ipsw_url"
- fi
- mv BuildManifest.plist $buildmanifest
- fi
- fi
- shsh_check=${device_ecid}_${device_type}_${device_model}ap_${version}-${build_id}_${apnonce}*.shsh*
- if [[ $(ls ../saved/shsh/$shsh_check 2>/dev/null) && -z $apnonce ]]; then
- shsh_path="$(ls ../saved/shsh/$shsh_check)"
- log "Found existing saved $version blobs: $shsh_path"
Advertisement