v1ral_ITS

Legacy IOS Part1

Jun 10th, 2026
47
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 119.74 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. ipsw_openssh=1 # OpenSSH will be added to jailbreak/custom IPSW if set to 1.
  4. device_rd_build="" # You can change the version of SSH Ramdisk and Pwned iBSS/iBEC here. (default is 10B329 for most devices)
  5. device_bootargs_default="pio-error=0 debug=0x2014e serial=3"
  6. device_disable_sudoloop=1
  7. jelbrek="../resources/jailbreak"
  8. sundance="../saved/SundanceInH2A"
  9. ssh_port=6414
  10.  
  11. bash_test=$(echo -n 0)
  12. (( bash_test += 1 ))
  13. if [ "$bash_test" != "1" ] || [ -z $BASH_VERSION ]; then
  14.     echo "[Error] Detected that script is not running with bash on runtime. Please run the script properly using bash."
  15.     exit 1
  16. fi
  17. bash_ver=$(/usr/bin/env bash -c 'echo ${BASH_VERSINFO[0]}')
  18.  
  19. print() {
  20.     echo "${color_B}${1}${color_N}"
  21. }
  22.  
  23. input() {
  24.     echo "${color_Y}[Input] ${1}${color_N}"
  25. }
  26.  
  27. log() {
  28.     echo "${color_G}[Log] ${1}${color_N}"
  29. }
  30.  
  31. warn() {
  32.     echo "${color_Y}[WARNING] ${1}${color_N}"
  33. }
  34.  
  35. error() {
  36.     echo -e "${color_R}[Error] ${1}\n${color_Y}${*:2}${color_N}"
  37.     exit 1
  38. }
  39.  
  40. pause() {
  41.     input "Press Enter/Return to continue (or press Ctrl+C to cancel)"
  42.     read -s
  43. }
  44.  
  45. exit_message() {
  46.     echo
  47.     print "* Save the terminal output now if needed. (macOS: Cmd+S, Linux: Ctrl+Shift+S)"
  48.     if [[ -n $version_current && -n $git_hash ]]; then
  49.         print "* Legacy iOS Kit $version_current ($git_hash)"
  50.     else
  51.         print "* Legacy iOS Kit"
  52.     fi
  53.     if [[ -n $platform ]]; then
  54.         print "* Platform: $platform ($platform_ver - $platform_arch) $live_session_str"
  55.     fi
  56. }
  57.  
  58. clean() {
  59.     exit_message
  60.     kill $httpserver_pid $iproxy_pid $anisette_pid $sshfs_pid 2>/dev/null
  61.     popd &>/dev/null
  62.     [[ -d "$(dirname "$0")/tmp$$/" ]] && rm -rf "$(dirname "$0")/tmp$$/"* "$(dirname "$0")/tmp$$/"
  63.     [[ $noclean == 1 ]] && return
  64.     rm -rf "$(dirname "$0")/iP"*/
  65.     if [[ $platform == "macos" && $(ls "$(dirname "$0")" | grep -v tmp$$ | grep -c tmp) == 0 &&
  66.           $no_finder != 1 ]]; then
  67.         killall -CONT AMPDevicesAgent AMPDeviceDiscoveryAgent MobileDeviceUpdater 2>/dev/null
  68.     fi
  69. }
  70.  
  71. clean_sudo() {
  72.     clean
  73.     [[ -d "$(dirname "$0")/tmp$$/" ]] && $sudo rm -rf "$(dirname "$0")/tmp$$/"* "$(dirname "$0")/tmp$$/"
  74.     [[ $noclean == 1 ]] && return
  75.     $sudo rm -rf "$(dirname "$0")/iP"*/ /tmp/futurerestore /tmp/*.json
  76.     $sudo kill $sudoloop_pid 2>/dev/null
  77. }
  78.  
  79. clean_usbmuxd() {
  80.     [[ $platform != "linux" ]] && return
  81.     if [[ $noclean != 1 ]]; then
  82.         if [[ -z $device_disable_usbmuxd ]]; then
  83.             echo
  84.             log "Terminating own usbmuxd instance(s)"
  85.             if [[ $live_session != 1 ]]; then
  86.                 print "* Enter your user password when prompted"
  87.                 print "* Your password input may not be visible, but it is still being entered."
  88.             fi
  89.             $sudo -v
  90.         fi
  91.     fi
  92.     if [[ -z $device_disable_sudoloop ]]; then
  93.         clean_sudo
  94.     else
  95.         clean
  96.     fi
  97.     [[ $noclean == 1 ]] && return
  98.     $sudo killall -9 usbmuxd usbmuxd2 2>/dev/null
  99.     sleep 1
  100.     if [[ $(command -v restorecon) ]]; then
  101.         $sudo restorecon /var/run/usbmuxd
  102.         $sudo systemctl restart usbmuxd
  103.     fi
  104.     if [[ $(command -v systemctl) ]]; then
  105.         $sudo systemctl restart usbmuxd 2>/dev/null
  106.     elif [[ $(command -v rc-service) ]]; then
  107.         $sudo rc-service usbmuxd start 2>/dev/null
  108.     fi
  109. }
  110.  
  111. display_help() {
  112.     echo ' *** Legacy iOS Kit ***
  113.  - Script by LukeZGD -
  114.  
  115. Usage: ./restore.sh [Options]
  116.  
  117. List of options:
  118.    --debug                   Enable script debugging (set -x and debug mode)
  119.    --device=<type>           Specify device type
  120.    --dfuhelper               Launch to DFU Mode Helper only
  121.    --disable-usbmuxd         Disable use of own usbmuxd instance on Linux
  122.    --enable-sudoloop         Enable running some tools as root on Linux
  123.    --ecid=<ecid>             Specify device ECID
  124.    --entry-device            Enable manual device type and ECID entry
  125.    --exit-recovery           Attempt to exit recovery mode
  126.    --kdfu                    Enter kDFU mode with the connected device
  127.    --help                    Display this help message
  128.    --no-color                Disable colors for script output
  129.    --no-finder               Disable Finder device detection and keep it disabled after script exit
  130.                              To re-enable it, run the script without this flag and exit
  131.    --no-device               Enable no device mode
  132.    --old-menu                Use the old menus with number select and y/n
  133.    --pwn                     Pwn the connected device
  134.    --sshrd                   Enter SSH ramdisk mode
  135.    --sshrd-menu              Re-enter SSH ramdisk menu (device must be in SSH ramdisk mode)
  136.    --use-usbmuxd2            Use usbmuxd2 instead of usbmuxd on Linux
  137.  
  138. For 32-bit devices compatible with restores/downgrades (see README):
  139.    --activation-records      Enable dumping/stitching activation records
  140.    --build-id=<build>        Specify iOS build ID for SSH ramdisk/tether boot
  141.    --bootargs=<bootargs>     Specify custom bootargs for SSH ramdisk/tether boot
  142.    --dead-bb                 Disable bbupdate completely without dumping/stitching baseband
  143.    --disable-actrec          Disable dumping/stitching activation records
  144.    --disable-bbupdate        Disable bbupdate and enable dumping/stitching baseband
  145.    --ipsw-hacktivate         Enable hacktivation for creating IPSW (iPhone 2G/3G/3GS only)
  146.    --ipsw-verbose            Enable verbose boot option (3GS and powdersn0w only)
  147.    --jailbreak               Enable jailbreak option
  148.    --just-boot               Tether boot the device (requires --build-id)
  149.    --multipatch              Enable multipatch to get past "gas gauge" error (aka error 29 in iTunes)
  150.                              This patch also attempts to get past "invalid ticket" error
  151.    --memory                  Enable memory option for creating IPSW
  152.    --pwned-recovery          Assume that device is in pwned recovery mode (experimental)
  153.    --ra1n-timeout=<value>    Set RA1N_ABORT_TIMEOUT for litera1n A6(X) (recommended: 1000000)
  154.    --skip-first              Skip first restore and flash part 2 IPSW only for powdersn0w 4.2.x and lower
  155.    --skip-ibss               Assume that pwned iBSS has already been sent to the device
  156.  
  157. For 64-bit checkm8 devices compatible with pwned restores:
  158.    --skip-blob               Enable futurerestore skip blob option for OTA/onboard/factory blobs
  159.    --use-dev                 Use dev branch of futurerestore nightly
  160.    --use-pwndfu              Enable futurerestore pwned restore option
  161.  
  162.    * Default IPSW path: <script location>/<name of IPSW file>.ipsw
  163.    * Default SHSH path: <script location>/saved/shsh/<name of SHSH file>.shsh(2)
  164.    '
  165. }
  166.  
  167. tar2="$(command -v tar)"
  168. [[ $OSTYPE == "darwin"* ]] && tar2="/usr/bin/tar"
  169. unzip2="$(command -v unzip)"
  170. zip2="$(command -v zip)"
  171.  
  172. tar() {
  173.     $tar2 "$@" || error "An error occurred with the tar operation: $*"
  174. }
  175.  
  176. unzip() {
  177.     $unzip2 "$@" || error "An error occurred with the unzip operation: $*"
  178. }
  179.  
  180. zip() {
  181.     $zip2 "$@" || error "An error occurred with the zip operation: $*"
  182. }
  183.  
  184. file_extract() {
  185.     local archive="$1"
  186.     local dest="$2"
  187.     local arr=()
  188.     if [[ $platform == "macos" ]]; then
  189.         arr+=("-xzvf" "$archive")
  190.         [[ -n $dest ]] && arr+=("-C" "$dest")
  191.         tar "${arr[@]}"
  192.         return
  193.     fi
  194.     arr+=("-o" "$archive")
  195.     [[ -n $dest ]] && arr+=("-d" "$dest")
  196.     unzip "${arr[@]}"
  197. }
  198.  
  199. file_extract_from_archive() {
  200.     local archive="$1"
  201.     local file="$2"
  202.     local dest="$3"
  203.     [[ -z $dest ]] && dest=.
  204.     local arr=()
  205.     if [[ $platform == "macos" && $file != *"/"* ]]; then
  206.         arr+=("-xzvOf" "$archive")
  207.         arr+=("$file")
  208.         tar "${arr[@]}" > "$dest/$file"
  209.         return
  210.     fi
  211.     arr+=("-o" "-j" "$archive" "$file")
  212.     [[ -n $dest ]] && arr+=("-d" "$dest")
  213.     unzip "${arr[@]}"
  214. }
  215.  
  216. # from https://unix.stackexchange.com/questions/146570/arrow-key-enter-menu#415155
  217. select_option() {
  218.     if [[ $menu_old == 1 ]]; then
  219.         select opt in "$@"; do
  220.             selected=$((REPLY-1))
  221.             break
  222.         done
  223.         return $selected
  224.     fi
  225.  
  226.     # clear input buffer to prevent error
  227.     if (( bash_ver > 3 )); then
  228.         while read -s -t 0.01 -n 1; do :; done
  229.     else
  230.         local old=$(stty -g)
  231.         stty -icanon -echo min 0 time 1
  232.         dd bs=1 count=1000 if=/dev/tty of=/dev/null 2>/dev/null
  233.         stty "$old"
  234.     fi
  235.  
  236.     # little helpers for terminal print control and key input
  237.     ESC=$( printf "\033")
  238.     cursor_blink_on()  { printf "$ESC[?25h"; }
  239.     cursor_blink_off() { printf "$ESC[?25l"; }
  240.     cursor_to()        { printf "$ESC[$1;${2:-1}H"; }
  241.     print_option()     { printf "   $1  "; }
  242.     print_selected()   { printf " ->$ESC[7m $1 $ESC[27m"; }
  243.     get_cursor_row()   { IFS=';' read -sdR -p $'\E[6n' ROW COL; echo ${ROW#*[}; }
  244.     key_input()        { read -s -n3 key 2>/dev/null >&2
  245.                          if [[ $key = $ESC[A ]]; then echo up;    fi
  246.                          if [[ $key = $ESC[B ]]; then echo down;  fi
  247.                          if [[ $key = ""     ]]; then echo enter; fi; }
  248.  
  249.     # initially print empty new lines (scroll down if at bottom of screen)
  250.     for opt; do printf "\n"; done
  251.  
  252.     # determine current screen position for overwriting the options
  253.     local lastrow=`get_cursor_row`
  254.     local startrow=$(($lastrow - $#))
  255.  
  256.     # ensure cursor and input echoing back on upon a ctrl+c during read -s
  257.     trap "cursor_blink_on; stty echo; printf '\n'; exit" 2
  258.     cursor_blink_off
  259.  
  260.     local selected=0
  261.     while true; do
  262.         # print options by overwriting the last lines
  263.         local idx=0
  264.         for opt; do
  265.             cursor_to $(($startrow + $idx))
  266.             if [ $idx -eq $selected ]; then
  267.                 print_selected "$opt"
  268.             else
  269.                 print_option "$opt"
  270.             fi
  271.             ((idx++))
  272.         done
  273.  
  274.         # user key control
  275.         case `key_input` in
  276.             enter) break;;
  277.             up)    ((selected--));
  278.                    if [ $selected -lt 0 ]; then selected=$(($# - 1)); fi;;
  279.             down)  ((selected++));
  280.                    if [ $selected -ge $# ]; then selected=0; fi;;
  281.         esac
  282.     done
  283.  
  284.     # cursor position back to normal
  285.     cursor_to $lastrow
  286.     printf "\n"
  287.     cursor_blink_on
  288.  
  289.     return $selected
  290. }
  291.  
  292. select_yesno() {
  293.     local msg="Do you want to continue?"
  294.     if [[ -n $1 ]]; then
  295.         msg="$1"
  296.     fi
  297.     [[ $2 == 1 ]] && msg+=" (Y/n): " || msg+=" (y/N): "
  298.  
  299.     if [[ $menu_old == 1 ]]; then
  300.         local opt
  301.         while true; do
  302.             read -p "$(input "$msg")" opt
  303.             case $opt in
  304.                 [NnYy] ) break;;
  305.                 "" ) # select default if no y/n given
  306.                     [[ $2 == 1 ]] && opt='y' || opt='n'
  307.                     break
  308.                 ;;
  309.             esac
  310.         done
  311.         if [[ $2 == 1 ]]; then # default is "yes" if $2 is set to 1
  312.             [[ $opt == [Nn] ]] && return 0 || return 1
  313.         fi
  314.         # default is "no" otherwise
  315.         [[ $opt == [Yy] ]] && return 1 || return 0
  316.     fi
  317.  
  318.     local yesno=("No" "Yes") # default is "no" by default
  319.     if [[ $2 == 1 ]]; then # default is "yes" if $2 is set to 1
  320.         yesno=("Yes" "No")
  321.     fi
  322.     input "$msg"
  323.     select_option "${yesno[@]}"
  324.     local res=$?
  325.     if [[ $2 == 1 ]]; then
  326.         [[ $res == 0 ]] && return 1 || return 0
  327.     fi
  328.     return $res
  329. }
  330.  
  331. set_tool_paths() {
  332.     : '
  333.    sets variables: platform, platform_ver, dir
  334.    also checks architecture (linux) and macos version
  335.    also set distro, debian_ver, ubuntu_ver, fedora_ver variables for linux
  336.  
  337.    list of tools set here:
  338.    bspatch, jq, scp, ssh, sha1sum (for macos: shasum -a 1), zenity
  339.  
  340.    these ones "need" sudo for linux arm, not for others:
  341.    futurerestore, gaster, idevicerestore, ipwnder, irecovery
  342.  
  343.    tools set here will be executed using:
  344.    $name_of_tool
  345.  
  346.    the rest of the tools not listed here will be executed using:
  347.    "$dir/$name_of_tool"
  348.    '
  349.  
  350.     if [[ $OSTYPE == "linux"* ]]; then
  351.         source /etc/os-release
  352.         platform="linux"
  353.         platform_ver="$PRETTY_NAME"
  354.         dir="../bin/linux/"
  355.  
  356.         # architecture check
  357.         platform_arch="$(uname -m)"
  358.         if [[ $platform_arch == "aarch64" ]]; then
  359.             platform_arch="arm64"
  360.         elif [[ $platform_arch != "x86_64" ]]; then
  361.             error "Your architecture ($platform_arch) is not supported."
  362.         fi
  363.         dir+="$platform_arch"
  364.  
  365.         platform_cpu="$(awk -F': ' '/model name/{print $2; exit}' /proc/cpuinfo)"
  366.  
  367.         # version check
  368.         if [[ -n $UBUNTU_CODENAME ]]; then
  369.             case $UBUNTU_CODENAME in
  370.                 "jammy" | "kinetic"   ) ubuntu_ver=22;;
  371.                 "lunar" | "mantic"    ) ubuntu_ver=23;;
  372.                 "noble" | "oracular"  ) ubuntu_ver=24;;
  373.                 "plucky" | "questing" ) ubuntu_ver=25;;
  374.                 "resolute" ) ubuntu_ver=26;;
  375.             esac
  376.             if [[ -z $ubuntu_ver ]]; then
  377.                 source /etc/upstream-release/lsb-release 2>/dev/null
  378.                 ubuntu_ver="$(echo "$DISTRIB_RELEASE" | cut -c -2)"
  379.             fi
  380.             if [[ -z $ubuntu_ver ]]; then
  381.                 ubuntu_ver="$(echo "$VERSION_ID" | cut -c -2)"
  382.             fi
  383.         elif [[ -e /etc/debian_version ]]; then
  384.             debian_ver=$(cat /etc/debian_version)
  385.             case $debian_ver in
  386.                 *"sid" | "kali"* ) debian_ver="sid";;
  387.                 * ) debian_ver="$(echo "$debian_ver" | cut -c -2)";;
  388.             esac
  389.         elif [[ $ID == "fedora" || $ID_LIKE == "fedora" || $ID == "nobara" ]]; then
  390.             fedora_ver=$VERSION_ID
  391.         fi
  392.  
  393.         # distro check
  394.         if [[ $ID == "steamos" ]]; then
  395.             distro="steamos"
  396.         elif [[ $ID == "arch" || $ID_LIKE == "arch" || $ID == "artix" || $ID == "cachyos" ]]; then
  397.             distro="arch"
  398.         elif (( ubuntu_ver >= 22 )) || (( debian_ver >= 12 )) || [[ $debian_ver == "sid" ]]; then
  399.             distro="debian"
  400.         elif (( fedora_ver >= 40 )); then
  401.             distro="fedora"
  402.             if [[ $(command -v rpm-ostree) ]]; then
  403.                 distro="fedora-atomic"
  404.             fi
  405.         elif [[ $ID == "opensuse-tumbleweed" ]]; then
  406.             distro="opensuse"
  407.         elif [[ $ID == "gentoo" || $ID_LIKE == "gentoo" || $ID == "pentoo" ]]; then
  408.             distro="gentoo"
  409.         elif [[ $ID == "void" ]]; then
  410.             distro="void"
  411.         elif [[ -n $ubuntu_ver || -n $debian_ver || -n $fedora_ver ]]; then
  412.             error "Your distro version ($platform_ver - $platform_arch) is not supported. See the repo README for supported OS versions/distros"
  413.         else
  414.             warn "Your distro ($platform_ver - $platform_arch) is not detected/supported. See the repo README for supported OS versions/distros"
  415.             print "* You may still continue, but you will need to install required packages and libraries manually as needed."
  416.             sleep 5
  417.             pause
  418.         fi
  419.         bspatch="$dir/bspatch"
  420.         PlistBuddy="$dir/PlistBuddy"
  421.         PlistBuddy2="${PlistBuddy}2"
  422.         sha1sum="$(command -v sha1sum)"
  423.         tsschecker="$dir/tsschecker"
  424.         zenity="$(command -v zenity)"
  425.         scp2="$dir/scp"
  426.         ssh2="$dir/ssh"
  427.         cp $ssh2 . 2>/dev/null
  428.         chmod +x ssh 2>/dev/null
  429.         export LD_LIBRARY_PATH="$dir/lib"
  430.  
  431.         # live cd/usb check
  432.         if [[ $(id -u $USER) == 999 || $USER == "liveuser" || $(df | grep -c "/cow") != 0 ]] ||
  433.            [[ $(hostname 2>/dev/null) == *"ubuntu" && $USER == *"ubuntu" ]] ||
  434.            [[ $(hostname 2>/dev/null) == "mint" && $USER == "mint" ]]; then
  435.             live_session=1
  436.             live_session_str="Live session"
  437.             log "Linux Live session detected."
  438.             if [[ $(pwd) == "/home/"* ]]; then
  439.                 df . -h # just display items
  440.                 if [[ $(lsblk -o label | grep -c "casper-rw") == 1 || $(lsblk -o label | grep -c "persistence") == 1 ]]; then
  441.                     log "Detected Legacy iOS Kit running on persistent storage."
  442.                     live_session_str+=" - Persistent storage"
  443.                 else
  444.                     warn "Detected Legacy iOS Kit running on temporary storage."
  445.                     print "* You may run out of space and get errors during the restore process."
  446.                     print "* Please move Legacy iOS Kit to a drive that is NOT used for the live USB."
  447.                     print "* This may mean using another external HDD/flash drive to store Legacy iOS Kit on."
  448.                     print "* To use one USB drive only, create the live USB using Rufus with Persistent Storage enabled."
  449.                     sleep 5
  450.                     pause
  451.                     live_session_str+=" - Temporary storage"
  452.                 fi
  453.             fi
  454.         fi
  455.  
  456.         # if "/media/" is detected in pwd, warn user of possible permission issues
  457.         if [[ $(pwd) == *"/media/"* ]]; then
  458.             warn "You might get permission errors like \"Permission denied\" on getting device info."
  459.             print "* If this is the case, try moving Legacy iOS Kit to the Desktop or Documents folder."
  460.             live_session_str+=" - External storage"
  461.         fi
  462.  
  463.         if [[ $device_argmode == "none" ]]; then
  464.             device_disable_sudoloop=1
  465.             device_disable_usbmuxd=1
  466.         fi
  467.         if [[ -z $device_disable_sudoloop ]]; then
  468.             device_sudoloop=1 # Run some tools as root for device detection if set to 1. (for Linux)
  469.             trap "clean_sudo" EXIT
  470.         fi
  471.         sudo="/usr/bin/sudo"
  472.         if [[ $($sudo -V 2>&1) == "sudo-rs"* ]]; then
  473.             if [[ -z $device_disable_sudoloop && -z $device_disable_usbmuxd ]]; then
  474.                 log "sudo-rs detected. Switching to sudo.ws"
  475.             fi
  476.             sudo+=".ws"
  477.         fi
  478.         if [[ $device_sudoloop == 1 || $live_session == 1 ]]; then
  479.             if [[ $live_session != 1 ]]; then
  480.                 print "* Enter your user password when prompted"
  481.                 print "* Your password input may not be visible, but it is still being entered."
  482.             fi
  483.             $sudo -v
  484.             #(while true; do $sudo -v; sleep 60; done) &
  485.             sudoloop_pid=$!
  486.             a6meowing="$sudo "
  487.             futurerestore="$sudo "
  488.             gaster="$sudo "
  489.             idevicerestore="$sudo LD_LIBRARY_PATH=$dir/lib "
  490.             irecovery="$sudo "
  491.             irecovery2="$sudo "
  492.             irecovery3="$sudo "
  493.             primepwn="$sudo "
  494.         fi
  495.         if [[ $(command -v gio) && ! -e ../resources/new && $device_argmode != "none" ]]; then
  496.             log "gio detected. Unmounting all iOS devices with it"
  497.             gio mount -l | awk '/gphoto2:\/\/Apple_Inc|afc:\/\// {print $NF}' | while read -r m; do gio mount -u "$m"; done
  498.         fi
  499.         if [[ $device_argmode != "none" && $device_disable_usbmuxd != 1 && ! -e ../resources/new ]]; then
  500.             trap "clean_usbmuxd" EXIT
  501.             if [[ $othertmp == 0 ]]; then
  502.                 if [[ $live_session != 1 && $device_disable_sudoloop == 1 ]]; then
  503.                     print "* Enter your user password when prompted"
  504.                     print "* Your password input may not be visible, but it is still being entered."
  505.                 fi
  506.                 if [[ $(command -v systemctl) ]]; then
  507.                     $sudo systemctl stop usbmuxd 2>/dev/null
  508.                 elif [[ $(command -v rc-service) ]]; then
  509.                     $sudo rc-service usbmuxd zap 2>/dev/null
  510.                 else
  511.                     $sudo killall -9 usbmuxd usbmuxd2 2>/dev/null
  512.                 fi
  513.                 #$sudo killall usbmuxd 2>/dev/null
  514.                 #sleep 1
  515.                 if [[ $use_usbmuxd2 == 1 ]]; then
  516.                     log "Running usbmuxd2"
  517.                     $sudo -b $dir/usbmuxd2 &>../saved/usbmuxd2.log
  518.                 else
  519.                     log "Running usbmuxd"
  520.                     $sudo -b $dir/usbmuxd -pf &>../saved/usbmuxd.log
  521.                 fi
  522.             else
  523.                 warn "Detected existing tmp folder(s), there might be other Legacy iOS Kit instance(s) running"
  524.                 warn "Not running usbmuxd"
  525.             fi
  526.         fi
  527.         if [[ ! -e ../resources/new ]]; then
  528.             install_udev_rules
  529.         fi
  530.         gaster+="$dir/gaster"
  531.  
  532.     elif [[ $(uname -m) == "iP"* ]]; then
  533.         error "Running Legacy iOS Kit on iOS is not supported (yet)" \
  534.               "* Supported platforms: Linux, macOS"
  535.  
  536.     elif [[ $OSTYPE == "darwin"* ]]; then
  537.         platform="macos"
  538.         platform_ver="${1:-$(sw_vers -productVersion)}"
  539.         IFS='.' read -r mac_majver mac_minver mac_patch <<< "$platform_ver"
  540.         dir="../bin/macos"
  541.  
  542.         platform_arch="$(uname -m)"
  543.         [[ $(sysctl -in hw.optional.arm64) == 1 ]] && platform_arch="arm64"
  544.         [[ $platform_arch == "arm64" ]] && dir+="/arm64"
  545.  
  546.         # macos checks
  547.         if [[ $mac_majver == 10 ]]; then
  548.             if (( mac_minver < 11 )); then
  549.                 error "Your macOS version ($platform_ver - $platform_arch) is not supported." \
  550.                       "* Supported macOS versions are 10.11 and newer."
  551.             elif [[ $mac_minver == 11 ]]; then
  552.                 mac_cocoa=1
  553.             fi
  554.             case $mac_minver in
  555.                 11 ) mac_name="El Capitan";;
  556.                 12 ) mac_name="Sierra";;
  557.                 13 ) mac_name="High Sierra";;
  558.                 14 ) mac_name="Mojave";;
  559.                 15 ) mac_name="Catalina";;
  560.             esac
  561.         fi
  562.         case $mac_majver in
  563.             11 ) mac_name="Big Sur";;
  564.             12 ) mac_name="Monterey";;
  565.             13 ) mac_name="Ventura";;
  566.             14 ) mac_name="Sonoma";;
  567.             15 ) mac_name="Sequoia";;
  568.             26 ) mac_name="Tahoe";;
  569.         esac
  570.         if [[ -n $mac_name ]]; then
  571.             platform_ver="$(sysctl -n hw.model) - $mac_name $platform_ver"
  572.         fi
  573.         if [[ $(xcode-select -p 1>/dev/null; echo $?) != 0 ]]; then
  574.             local error_msg="* You need to install Xcode Command Line Tools with this command: xcode-select --install"
  575.             error_msg+=$'\n* If the above command does not work, try this: sudo xcode-select --reset'
  576.             error_msg+=$'\n* Please read the wiki and install the requirements needed: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/How-to-Use'
  577.             xcode-select --install
  578.             error "Xcode Command Line Tools not installed, cannot continue." "$error_msg"
  579.         fi
  580.         /usr/bin/xattr -cr ../bin/macos
  581.  
  582.         bspatch="$(command -v bspatch)"
  583.         cocoadialog="$(command -v cocoadialog)"
  584.         gaster+="../bin/macos/gaster"
  585.         PlistBuddy="/usr/libexec/PlistBuddy"
  586.         PlistBuddy2="$PlistBuddy"
  587.         sha1sum="$(command -v shasum) -a 1"
  588.         tsschecker="../bin/macos/tsschecker"
  589.         zenity="$dir/zenity"
  590.         scp2="/usr/bin/scp"
  591.         ssh2="/usr/bin/ssh"
  592.  
  593.         # kill macos daemons
  594.         killall -STOP AMPDevicesAgent AMPDeviceDiscoveryAgent MobileDeviceUpdater 2>/dev/null
  595.  
  596.     else
  597.         error "Your platform ($OSTYPE) is not supported." \
  598.               "* Supported platforms: Linux, macOS"
  599.     fi
  600.     log "Running on platform: $platform ($platform_ver - $platform_arch)"
  601.     if [[ $platform == "macos" && $platform_arch == "arm64" ]]; then
  602.         if (( mac_majver == 12 && mac_minver < 6 )) || (( mac_majver < 12 )); then
  603.             warn "Updating to macOS 12.6 or newer is recommended for Apple Silicon Macs."
  604.         fi
  605.     fi
  606.     if [[ ! -d $dir ]]; then
  607.         error "Failed to find bin directory ($dir), cannot continue." \
  608.               "* Re-download Legacy iOS Kit from releases (or do a git clone/reset)"
  609.     fi
  610.     if [[ $device_sudoloop == 1 ]]; then
  611.         $sudo chmod +x $dir/*
  612.         if [[ $? != 0 ]]; then
  613.             error "Failed to set up execute permissions of binaries, cannot continue. Try to move Legacy iOS Kit somewhere else."
  614.         fi
  615.     else
  616.         chmod +x $dir/*
  617.     fi
  618.  
  619.     a6meowing+="$dir/a6meowing"
  620.     aria2c="$(command -v aria2c)"
  621.     [[ -z $aria2c ]] && aria2c="$dir/aria2c"
  622.     aria2c+=" --no-conf --download-result=hide"
  623.     curl="$(command -v curl)"
  624.     futurerestore+="$dir/futurerestore"
  625.     ideviceactivation+="$dir/ideviceactivation"
  626.     idevicediagnostics+="$dir/idevicediagnostics"
  627.     ideviceinfo="$dir/ideviceinfo"
  628.     ideviceinstaller+="$dir/ideviceinstaller"
  629.     idevicerestore+="$dir/idevicerestore"
  630.     irecovery+="$dir/irecovery"
  631.     irecovery2+="$dir/irecovery2"
  632.     irecovery3+="../$dir/irecovery"
  633.     jq="$dir/jq"
  634.     primepwn+="$dir/primepwn"
  635.     sshfs="$(command -v sshfs)"
  636.  
  637.     cp ../resources/ssh_config . 2>/dev/null
  638.     if [[ $(ssh -V 2>&1 | grep -c SSH_8.8) == 1 || $(ssh -V 2>&1 | grep -c SSH_8.9) == 1 ||
  639.           $(ssh -V 2>&1 | grep -c SSH_9.) == 1 || $(ssh -V 2>&1 | grep -c SSH_1) == 1 ]]; then
  640.         echo "    PubkeyAcceptedAlgorithms +ssh-rsa" >> ssh_config
  641.     elif [[ $(ssh -V 2>&1 | grep -c SSH_6) == 1 ]]; then
  642.         cat ../resources/ssh_config | sed "s,Add,#Add,g" | sed "s,HostKeyA,#HostKeyA,g" > ssh_config
  643.     fi
  644.     scp2+=" -F ./ssh_config"
  645.     ssh2+=" -F ./ssh_config"
  646. }
  647.  
  648. install_udev_rules() {
  649.     local rule="/etc/udev/rules.d/99-libirecovery.rules"
  650.     [[ -s $rule ]] && return
  651.     log "Setting up udev rules..."
  652.     if [[ $live_session != 1 && $device_disable_usbmuxd == 1 ]]; then
  653.         print "* Enter your user password when prompted"
  654.         print "* Your password input may not be visible, but it is still being entered."
  655.     fi
  656.     $sudo mkdir -p $(dirname $rule)
  657.     echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="05ac", MODE:="0666", TAG+="uaccess"' | $sudo tee $rule
  658.     $sudo udevadm control --reload-rules
  659.     $sudo udevadm trigger -s usb
  660. }
  661.  
  662. install_depends() {
  663.     rm -f "../saved/firstrun"
  664.  
  665.     if [[ $platform == "linux" ]]; then
  666.         print "* Legacy iOS Kit will be installing dependencies from your distribution's package manager"
  667.         print "* Enter your user password when prompted"
  668.         print "* Your password input may not be visible, but it is still being entered."
  669.  
  670.         if [[ $distro != "debian" && $distro != "fedora-atomic" ]]; then
  671.             echo
  672.             warn "Before continuing, make sure that your system is fully updated first!"
  673.             echo "${color_Y}* This operation can result in a partial upgrade and may cause breakage if your system is not updated${color_N}"
  674.             echo
  675.         fi
  676.         pause
  677.     fi
  678.  
  679.     log "Installing dependencies..."
  680.     if [[ $distro == "arch" ]]; then
  681.         $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
  682.  
  683.     elif [[ $distro == "debian" ]]; then
  684.         if [[ -n $ubuntu_ver ]]; then
  685.             $sudo add-apt-repository -y universe
  686.         fi
  687.         $sudo apt update
  688.         $sudo apt install -m -y aria2 ca-certificates curl git libssl3 libzstd1 openssh-client patch python3 sshfs unzip usbmuxd usbutils xxd zenity zip zlib1g
  689.         if [[ $(command -v systemctl 2>/dev/null) ]]; then
  690.             $sudo systemctl enable --now udev systemd-udevd usbmuxd 2>/dev/null
  691.         fi
  692.  
  693.     elif [[ $distro == "fedora" ]]; then
  694.         $sudo dnf install -y aria2 ca-certificates git libimobiledevice libzstd openssl patch python3 sshfs systemd udev usbmuxd vim-common zenity zip
  695.         $sudo ln -sf /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-certificates.crt
  696.  
  697.     elif [[ $distro == "fedora-atomic" ]]; then
  698.         local packages=(patch sshfs vim-common zenity)
  699.         for package in "${packages[@]}"; do
  700.             rpm-ostree install $package
  701.         done
  702.         print "* You may need to reboot to apply changes with rpm-ostree. Perform a reboot after this before running the script again."
  703.  
  704.     elif [[ $distro == "opensuse" ]]; then
  705.         $sudo zypper -n install aria2 ca-certificates curl git libimobiledevice-1_0-6 libzstd1 openssl-3 patch python3 sshfs usbmuxd unzip vim zenity zip
  706.  
  707.     elif [[ $distro == "gentoo" ]]; then
  708.         $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
  709.  
  710.     elif [[ $distro == "void" ]]; then
  711.         $sudo xbps-install aria2 curl git patch openssh python3 unzip xxd zenity zip
  712.     fi
  713.  
  714.     if [[ $platform == "linux" ]]; then
  715.         install_udev_rules
  716.     fi
  717.     echo "$platform_ver" > "../saved/firstrun"
  718.  
  719.     log "Install script done! Please run the script again to proceed"
  720.     log "If your iOS device is plugged in, you may need to unplug and replug your device"
  721.     exit
  722. }
  723.  
  724. download_from_url() {
  725.     local url="$1"
  726.     local file="$2"
  727.     local extra
  728.     if [[ $file == *".ipsw" ]]; then
  729.         extra="-c -s 16 -x 16 -k 1M -j 1"
  730.     fi
  731.     if [[ -n "$file" ]]; then
  732.         rm -f "$file"
  733.         $aria2c "$url" $extra -o "$file" || \
  734.         $curl -L "$url" -o "$file" || \
  735.         wget -O "$file" "$url"
  736.         return
  737.     fi
  738.     $aria2c "$url" || \
  739.     $curl -LO "$url" || \
  740.     wget "$url"
  741. }
  742.  
  743. version_update_check() {
  744.     pushd "tmp$$" >/dev/null
  745.     if [[ $platform == "macos" && ! -s ../saved/firstrun ]]; then
  746.         /usr/bin/xattr -cr ../bin/macos
  747.     fi
  748.     log "Checking for updates..."
  749.     download_from_url "https://api.github.com/repos/LukeZGD/Legacy-iOS-Kit/releases/latest" latest
  750.     github_api=$(cat latest 2>/dev/null)
  751.     version_latest=$(echo "$github_api" | $jq -r '.name')
  752.     version_latest=${version_latest#Latest-}
  753.     git_hash_latest=$(echo "$github_api" | $jq -r '.target_commitish')
  754.     git_hash_latest=${git_hash_latest:0:7}
  755.     popd >/dev/null
  756. }
  757.  
  758. version_update() {
  759.     select_yesno "Do you want to update now?" 1
  760.     if [[ $? != 1 ]]; then
  761.         log "User selected N, cannot continue. Exiting."
  762.         exit
  763.     fi
  764.     if [[ -d .git ]]; then
  765.         log "Running git reset..."
  766.         git reset --hard
  767.         log "Running git pull..."
  768.         git pull origin $(git rev-parse --abbrev-ref HEAD)
  769.         pushd "tmp$$" >/dev/null
  770.         log "Done! Please run the script again"
  771.         exit
  772.     fi
  773.     pushd "tmp$$" >/dev/null
  774.     log "Downloading..."
  775.     git clone --filter=blob:none "https://github.com/LukeZGD/Legacy-iOS-Kit"
  776.     if [[ $? != 0 ]]; then
  777.         git clone "https://github.com/LukeZGD/Legacy-iOS-Kit"
  778.         if [[ $? != 0 ]]; then
  779.             local error_msg=$'\n* If you have not installed/updated git, please install git from your package manager.'
  780.             if [[ $platform == "macos" ]]; then
  781.                 error_msg+=$'\n* On macOS, you may just need to install Xcode Command Line Tools with this command: xcode-select --install'
  782.                 error_msg+=$'\n* If the above command does not work, try this: sudo xcode-select --reset'
  783.                 xcode-select --install
  784.             fi
  785.             error "git clone failed. Please run the script again" "$error_msg"
  786.         fi
  787.     fi
  788.     popd >/dev/null
  789.     log "Updating..."
  790.     rm -rf bin/ LICENSE README.md restore.sh
  791.     if [[ $device_sudoloop == 1 ]]; then
  792.         $sudo rm -rf resources/
  793.     fi
  794.     rm -rf resources/
  795.     mv tmp$$/Legacy-iOS-Kit/* tmp$$/Legacy-iOS-Kit/.git* .
  796.     pushd "tmp$$" >/dev/null
  797.     log "Done! Please run the script again"
  798.     exit
  799. }
  800.  
  801. version_get() {
  802.     pushd .. >/dev/null
  803.     if [[ -d .git ]]; then
  804.         if [[ -e .git/shallow ]]; then
  805.             log "Shallow git repository detected. Unshallowing..."
  806.             git fetch --unshallow --filter=blob:none
  807.             if [[ $? != 0 ]]; then
  808.                 git fetch --unshallow
  809.                 if [[ $? != 0 ]]; then
  810.                     error "git fetch failed. Please run the script again" \
  811.                           "* If you have not installed/updated git, please install git from your package manager."
  812.                 fi
  813.             fi
  814.         fi
  815.         git_hash=$(git rev-parse HEAD | cut -c -7)
  816.         [[ -n $(git status --porcelain --untracked-files=no) ]] && git_hash+="-dirty"
  817.  
  818.         export TZ=UTC
  819.         local ts=$(git log -1 --format=%ct)
  820.         local yy
  821.         local mm
  822.         local month_start
  823.         if [[ $(uname) == Darwin ]]; then
  824.             yy=$(date -r "$ts" +%y)
  825.             mm=$(date -r "$ts" +%m)
  826.             month_start=$(date -j -f "%Y-%m-%d %H:%M:%S" "20$yy-$mm-01 00:00:00" +%s)
  827.         else
  828.             yy=$(date -d "@$ts" +%y)
  829.             mm=$(date -d "@$ts" +%m)
  830.             month_start=$(date -d "20$yy-$mm-01 00:00:00" +%s)
  831.         fi
  832.         local count=$(git rev-list --count HEAD --since="$month_start")
  833.         version_current="v$yy.$mm.$(printf "%02d" "$count")"
  834.         unset TZ
  835.  
  836.     elif [[ -e ./resources/git_hash ]]; then
  837.         version_current="$(cat ./resources/version)"
  838.         git_hash="$(cat ./resources/git_hash)"
  839.     elif [[ -e ./resources/new ]]; then
  840.         :
  841.     else
  842.         log ".git directory and git_hash file not found, cannot determine version."
  843.         if [[ $no_version_check != 1 ]]; then
  844.             warn "Your copy of Legacy iOS Kit is downloaded incorrectly. Do not use the \"Code\" button in GitHub."
  845.             print "* Please download Legacy iOS Kit using git clone or from GitHub releases: https://github.com/LukeZGD/Legacy-iOS-Kit/releases"
  846.         fi
  847.     fi
  848.     if [[ -n $version_current ]]; then
  849.         print "* Version: $version_current ($git_hash)"
  850.     fi
  851.     popd >/dev/null
  852. }
  853.  
  854. version_check() {
  855.     if [[ $no_version_check == 1 && ! -e ../resources/new ]]; then
  856.         warn "No version check flag detected, update check is disabled and no support will be provided."
  857.         return
  858.     fi
  859.     pushd .. >/dev/null
  860.     version_update_check
  861.     if [[ -z $version_latest ]]; then
  862.         warn "Failed to check for updates. GitHub may be down or blocked by your network."
  863.     elif [[ $git_hash_latest != "$git_hash" ]]; then
  864.         if [[ -z $version_current ]]; then
  865.             print "* Latest version:  $version_latest ($git_hash_latest)"
  866.             print "* Please download/pull the latest version before proceeding."
  867.             version_update
  868.         elif (( $(echo $version_current | cut -c 2- | sed -e 's/\.//g') >= $(echo $version_latest | cut -c 2- | sed -e 's/\.//g') )); then
  869.             warn "Current version is newer/different than remote: $version_latest ($git_hash_latest)"
  870.         else
  871.             print "* A newer version of Legacy iOS Kit is available."
  872.             print "* Current version: $version_current ($git_hash)"
  873.             print "* Latest version:  $version_latest ($git_hash_latest)"
  874.             print "* Please download/pull the latest version before proceeding."
  875.             version_update
  876.         fi
  877.     fi
  878.     popd >/dev/null
  879. }
  880.  
  881. device_entry() {
  882.     # enable manual entry
  883.     log "Manual device/ECID entry is enabled."
  884.     until [[ -n $device_type && $device_type == "iP"* ]]; do
  885.         read -p "$(input 'Enter device type (eg. iPad2,1): ')" device_type_entry
  886.         device_type="$device_type_entry"
  887.     done
  888.     case $device_type in
  889.     iPad6,1[12] | iPhone8,* )
  890.         local valid
  891.         local allowed
  892.         case $device_type in
  893.             iPhone8,1 ) allowed="n71 n71m";;
  894.             iPhone8,2 ) allowed="n66 n66m";;
  895.             iPhone8,4 ) allowed="n69 n69u";;
  896.             iPad6,11  ) allowed="j71s j71t";;
  897.             iPad6,12  ) allowed="j72s j72t";;
  898.         esac
  899.         until [[ $valid == 1 ]]; do
  900.             read -p "$(input 'Enter device model (without ap, eg. n71): ')" device_model
  901.             for m in $allowed; do
  902.                 [[ $device_model == "$m" ]] && valid=1 && break
  903.             done
  904.         done
  905.     ;;
  906.     esac
  907.  
  908.     if [[ $main_argmode == "device_justboot"* || $main_argmode == "device_enter_ramdisk"* ]]; then
  909.         :
  910.     elif [[ $device_type != "iPhone1,"* && $device_type != "iPod1,1" && $device_mode != "Normal" ]]; then
  911.         until [[ -n $device_ecid_entry ]] && [ "$device_ecid_entry" -eq "$device_ecid_entry" ]; do
  912.             read -p "$(input 'Enter device ECID (must be decimal): ')" device_ecid_entry
  913.         done
  914.     fi
  915.     if [[ $device_argmode == "none" ]]; then
  916.         device_ecid="$device_ecid_entry"
  917.     fi
  918.     if [[ -n $device_ecid_entry && $main_argmode == "device_justboot"* ]]; then
  919.         cat "$device_rd_build" > "../saved/$device_type/justboot_${device_ecid_entry}"
  920.     fi
  921. }
  922.  
  923. device_entry_s5l8900() {
  924.     device_argmode="entry"
  925.     log "Found an S5L8900 device in $device_mode mode."
  926.     print "* Device Type Option"
  927.     print "* Select your device in the options below. Make sure to select correctly."
  928.     local selection=("iPhone 2G" "iPod touch 1")
  929.     [[ $device_protocol != 1 ]] && selection+=("iPhone 3G")
  930.     input "Select your option:"
  931.     select_option "${selection[@]}"
  932.     local opt2="${selection[$?]}"
  933.     case $opt2 in
  934.         "iPhone 2G"    ) device_type="iPhone1,1";;
  935.         "iPhone 3G"    ) device_type="iPhone1,2";;
  936.         "iPod touch 1" ) device_type="iPod1,1";;
  937.     esac
  938.     device_model=
  939. }
  940.  
  941. device_get_name() {
  942.     # all devices that run iOS/iPhoneOS/iPadOS
  943.     # adding more entries here is no longer necessary since AppleDB is now used as fallback
  944.     case $device_type in
  945.         "iPhone1,1") device_name="iPhone 2G";;
  946.         "iPhone1,2") device_name="iPhone 3G";;
  947.         "iPhone2,1") device_name="iPhone 3GS";;
  948.         "iPhone3,1") device_name="iPhone 4 (GSM)";;
  949.         "iPhone3,2") device_name="iPhone 4 (GSM, Rev A)";;
  950.         "iPhone3,3") device_name="iPhone 4 (CDMA)";;
  951.         "iPhone4,1") device_name="iPhone 4S";;
  952.         "iPhone5,1") device_name="iPhone 5 (GSM)";;
  953.         "iPhone5,2") device_name="iPhone 5 (Global)";;
  954.         "iPhone5,3") device_name="iPhone 5C (GSM)";;
  955.         "iPhone5,4") device_name="iPhone 5C (Global)";;
  956.         "iPhone6,1") device_name="iPhone 5S (GSM)";;
  957.         "iPhone6,2") device_name="iPhone 5S (Global)";;
  958.         "iPhone7,1") device_name="iPhone 6 Plus";;
  959.         "iPhone7,2") device_name="iPhone 6";;
  960.         "iPhone8,1") device_name="iPhone 6S";;
  961.         "iPhone8,2") device_name="iPhone 6S Plus";;
  962.         "iPhone8,4") device_name="iPhone SE 2016";;
  963.         "iPhone9,1") device_name="iPhone 7 (Global)";;
  964.         "iPhone9,2") device_name="iPhone 7 Plus (Global)";;
  965.         "iPhone9,3") device_name="iPhone 7 (GSM)";;
  966.         "iPhone9,4") device_name="iPhone 7 Plus (GSM)";;
  967.         "iPhone10,1") device_name="iPhone 8 (Global)";;
  968.         "iPhone10,2") device_name="iPhone 8 Plus (Global)";;
  969.         "iPhone10,3") device_name="iPhone X (Global)";;
  970.         "iPhone10,4") device_name="iPhone 8 (GSM)";;
  971.         "iPhone10,5") device_name="iPhone 8 Plus (GSM)";;
  972.         "iPhone10,6") device_name="iPhone X (GSM)";;
  973.         "iPhone11,2") device_name="iPhone XS";;
  974.         "iPhone11,4") device_name="iPhone XS Max (China)";;
  975.         "iPhone11,6") device_name="iPhone XS Max";;
  976.         "iPhone11,8") device_name="iPhone XR";;
  977.         "iPhone12,1") device_name="iPhone 11";;
  978.         "iPhone12,3") device_name="iPhone 11 Pro";;
  979.         "iPhone12,5") device_name="iPhone 11 Pro Max";;
  980.         "iPhone12,8") device_name="iPhone SE 2020";;
  981.         "iPhone13,1") device_name="iPhone 12 mini";;
  982.         "iPhone13,2") device_name="iPhone 12";;
  983.         "iPhone13,3") device_name="iPhone 12 Pro";;
  984.         "iPhone13,4") device_name="iPhone 12 Pro Max";;
  985.         "iPhone14,2") device_name="iPhone 13 Pro";;
  986.         "iPhone14,3") device_name="iPhone 13 Pro Max";;
  987.         "iPhone14,4") device_name="iPhone 13 mini";;
  988.         "iPhone14,5") device_name="iPhone 13";;
  989.         "iPhone14,6") device_name="iPhone SE 2022";;
  990.         "iPhone14,7") device_name="iPhone 14";;
  991.         "iPhone14,8") device_name="iPhone 14 Plus";;
  992.         "iPhone15,2") device_name="iPhone 14 Pro";;
  993.         "iPhone15,3") device_name="iPhone 14 Pro Max";;
  994.         "iPhone15,4") device_name="iPhone 15";;
  995.         "iPhone15,5") device_name="iPhone 15 Plus";;
  996.         "iPhone16,1") device_name="iPhone 15 Pro";;
  997.         "iPhone16,2") device_name="iPhone 15 Pro Max";;
  998.         "iPhone17,1") device_name="iPhone 16 Pro";;
  999.         "iPhone17,2") device_name="iPhone 16 Pro Max";;
  1000.         "iPhone17,3") device_name="iPhone 16";;
  1001.         "iPhone17,4") device_name="iPhone 16 Plus";;
  1002.         "iPhone17,5") device_name="iPhone 16e";;
  1003.         "iPad1,1") device_name="iPad 1";;
  1004.         "iPad2,1") device_name="iPad 2 (Wi-Fi)";;
  1005.         "iPad2,2") device_name="iPad 2 (GSM)";;
  1006.         "iPad2,3") device_name="iPad 2 (CDMA)";;
  1007.         "iPad2,4") device_name="iPad 2 (Wi-Fi, Rev A)";;
  1008.         "iPad2,5") device_name="iPad mini 1 (Wi-Fi)";;
  1009.         "iPad2,6") device_name="iPad mini 1 (GSM)";;
  1010.         "iPad2,7") device_name="iPad mini 1 (Global)";;
  1011.         "iPad3,1") device_name="iPad 3 (Wi-Fi)";;
  1012.         "iPad3,2") device_name="iPad 3 (CDMA)";;
  1013.         "iPad3,3") device_name="iPad 3 (GSM)";;
  1014.         "iPad3,4") device_name="iPad 4 (Wi-Fi)";;
  1015.         "iPad3,5") device_name="iPad 4 (GSM)";;
  1016.         "iPad3,6") device_name="iPad 4 (Global)";;
  1017.         "iPad4,1") device_name="iPad Air 1 (Wi-Fi)";;
  1018.         "iPad4,2") device_name="iPad Air 1 (Cellular)";;
  1019.         "iPad4,3") device_name="iPad Air 1 (China)";;
  1020.         "iPad4,4") device_name="iPad mini 2 (Wi-Fi)";;
  1021.         "iPad4,5") device_name="iPad mini 2 (Cellular)";;
  1022.         "iPad4,6") device_name="iPad mini 2 (China)";;
  1023.         "iPad4,7") device_name="iPad mini 3 (Wi-Fi)";;
  1024.         "iPad4,8") device_name="iPad mini 3 (Cellular)";;
  1025.         "iPad4,9") device_name="iPad mini 3 (China)";;
  1026.         "iPad5,1") device_name="iPad mini 4 (Wi-Fi)";;
  1027.         "iPad5,2") device_name="iPad mini 4 (Cellular)";;
  1028.         "iPad5,3") device_name="iPad Air 2 (Wi-Fi)";;
  1029.         "iPad5,4") device_name="iPad Air 2 (Cellular)";;
  1030.         "iPad6,3") device_name="iPad Pro 9.7\" (Wi-Fi)";;
  1031.         "iPad6,4") device_name="iPad Pro 9.7\" (Cellular)";;
  1032.         "iPad6,7") device_name="iPad Pro 12.9\" (Wi-Fi)";;
  1033.         "iPad6,8") device_name="iPad Pro 12.9\" (Cellular)";;
  1034.         "iPad6,11") device_name="iPad 5 (Wi-Fi)";;
  1035.         "iPad6,12") device_name="iPad 5 (Cellular)";;
  1036.         "iPad7,1") device_name="iPad Pro 12.9\" (2nd gen, Wi-Fi)";;
  1037.         "iPad7,2") device_name="iPad Pro 12.9\" (2nd gen, Cellular)";;
  1038.         "iPad7,3") device_name="iPad Pro 10.5\" (Wi-Fi)";;
  1039.         "iPad7,4") device_name="iPad Pro 10.5\" (Cellular)";;
  1040.         "iPad7,5") device_name="iPad 6 (Wi-Fi)";;
  1041.         "iPad7,6") device_name="iPad 6 (Cellular)";;
  1042.         "iPad7,11") device_name="iPad 7 (Wi-Fi)";;
  1043.         "iPad7,12") device_name="iPad 7 (Cellular)";;
  1044.         "iPad8,1") device_name="iPad Pro 11\" (Wi-Fi)";;
  1045.         "iPad8,2") device_name="iPad Pro 11\" (Wi-Fi, 6GB RAM)";;
  1046.         "iPad8,3") device_name="iPad Pro 11\" (Cellular)";;
  1047.         "iPad8,4") device_name="iPad Pro 11\" (Cellular, 6GB RAM)";;
  1048.         "iPad8,5") device_name="iPad Pro 12.9\" (3rd gen, Wi-Fi)";;
  1049.         "iPad8,6") device_name="iPad Pro 12.9\" (3rd gen, Wi-Fi, 6GB RAM)";;
  1050.         "iPad8,7") device_name="iPad Pro 12.9\" (3rd gen, Cellular)";;
  1051.         "iPad8,8") device_name="iPad Pro 12.9\" (3rd gen, Cellular, 6GB RAM)";;
  1052.         "iPad8,9") device_name="iPad Pro 11\" (2nd gen, Wi-Fi)";;
  1053.         "iPad8,10") device_name="iPad Pro 11\" (2nd gen, Cellular)";;
  1054.         "iPad8,11") device_name="iPad Pro 12.9\" (4th gen, Wi-Fi)";;
  1055.         "iPad8,12") device_name="iPad Pro 12.9\" (4th gen, Cellular)";;
  1056.         "iPad11,1") device_name="iPad mini 5 (Wi-Fi)";;
  1057.         "iPad11,2") device_name="iPad mini 5 (Cellular)";;
  1058.         "iPad11,3") device_name="iPad Air 3 (Wi-Fi)";;
  1059.         "iPad11,4") device_name="iPad Air 3 (Cellular)";;
  1060.         "iPad11,6") device_name="iPad 8 (Wi-Fi)";;
  1061.         "iPad11,7") device_name="iPad 8 (Cellular)";;
  1062.         "iPad12,1") device_name="iPad 9 (Wi-Fi)";;
  1063.         "iPad12,2") device_name="iPad 9 (Cellular)";;
  1064.         "iPad13,1") device_name="iPad Air 4 (Wi-Fi)";;
  1065.         "iPad13,2") device_name="iPad Air 4 (Cellular)";;
  1066.         "iPad13,4") device_name="iPad Pro 11\" (3rd gen, Wi-Fi)";;
  1067.         "iPad13,5") device_name="iPad Pro 11\" (3rd gen, Wi-Fi, 16GB RAM)";;
  1068.         "iPad13,6") device_name="iPad Pro 11\" (3rd gen, Cellular)";;
  1069.         "iPad13,7") device_name="iPad Pro 11\" (3rd gen, Cellular, 16GB RAM)";;
  1070.         "iPad13,8") device_name="iPad Pro 12.9\" (5th gen, Wi-Fi)";;
  1071.         "iPad13,9") device_name="iPad Pro 12.9\" (5th gen, Wi-Fi, 16GB RAM)";;
  1072.         "iPad13,10") device_name="iPad Pro 12.9\" (5th gen, Cellular)";;
  1073.         "iPad13,11") device_name="iPad Pro 12.9\" (5th gen, Cellular, 16GB RAM)";;
  1074.         "iPad13,16") device_name="iPad Air 5 (Wi-Fi)";;
  1075.         "iPad13,17") device_name="iPad Air 5 (Cellular)";;
  1076.         "iPad13,18") device_name="iPad 10 (Wi-Fi)";;
  1077.         "iPad13,19") device_name="iPad 10 (Cellular)";;
  1078.         "iPad14,1") device_name="iPad mini 6 (Wi-Fi)";;
  1079.         "iPad14,2") device_name="iPad mini 6 (Cellular)";;
  1080.         "iPad14,3") device_name="iPad Pro 11\" (4th gen, Wi-Fi)";;
  1081.         "iPad14,4") device_name="iPad Pro 11\" (4th gen, Cellular)";;
  1082.         "iPad14,5") device_name="iPad Pro 12.9\" (6th gen, Wi-Fi)";;
  1083.         "iPad14,6") device_name="iPad Pro 12.9\" (6th gen, Cellular)";;
  1084.         "iPad14,8") device_name="iPad Air 11\" (M2, Wi-Fi)";;
  1085.         "iPad14,9") device_name="iPad Air 11\" (M2, Cellular)";;
  1086.         "iPad14,10") device_name="iPad Air 13\" (M2, Wi-Fi)";;
  1087.         "iPad14,11") device_name="iPad Air 13\" (M2, Cellular)";;
  1088.         "iPad16,1") device_name="iPad mini (A17 Pro, Wi-Fi)";;
  1089.         "iPad16,2") device_name="iPad mini (A17 Pro, Cellular)";;
  1090.         "iPad16,3") device_name="iPad Pro 11\" (M4, Wi-Fi)";;
  1091.         "iPad16,4") device_name="iPad Pro 11\" (M4, Cellular)";;
  1092.         "iPad16,5") device_name="iPad Pro 12.9\" (M4, Wi-Fi)";;
  1093.         "iPad16,6") device_name="iPad Pro 12.9\" (M4, Cellular)";;
  1094.         "iPod1,1") device_name="iPod touch 1";;
  1095.         "iPod2,1") device_name="iPod touch 2";;
  1096.         "iPod3,1") device_name="iPod touch 3";;
  1097.         "iPod4,1") device_name="iPod touch 4";;
  1098.         "iPod5,1") device_name="iPod touch 5";;
  1099.         "iPod7,1") device_name="iPod touch 6";;
  1100.         "iPod9,1") device_name="iPod touch 7";;
  1101.     esac
  1102.     if [[ -z $device_name && -n $device_type ]]; then
  1103.         log "Getting device name"
  1104.         download_appledb "device/$device_type"
  1105.         device_name="$(cat tmp.json | $jq -r ".name")"
  1106.     fi
  1107. }
  1108.  
  1109. device_get_paired_info() {
  1110.     device_serial="$($ideviceinfo -k SerialNumber | cut -c 3- | cut -c -3)"
  1111.     device_unactivated=$($ideviceactivation state | grep -c "Unactivated")
  1112.     device_imei=$($ideviceinfo -k InternationalMobileEquipmentIdentity)
  1113. }
  1114.  
  1115. device_manufacturing() {
  1116.     if (( device_proc > 10 )) || [[ $device_proc != 1 && $device_argmode == "none" ]]; then
  1117.         return
  1118.     fi
  1119.     if [[ $device_type == "iPhone2,1" && $device_mode != "DFU" ]]; then
  1120.         local week=$(echo "$device_serial" | cut -c 2-)
  1121.         local year=$(echo "$device_serial" | cut -c 1)
  1122.         year=$((year+2010))
  1123.         [[ $year == 2019 ]] && year=2009
  1124.         if [[ $year != 2009 ]] || (( week >= 46 )); then
  1125.             device_newbr=1
  1126.         elif [[ $year == 2009 ]] && (( week >= 40 )); then
  1127.             device_newbr=2 # gray area
  1128.         else
  1129.             device_newbr=0
  1130.         fi
  1131.     elif [[ $device_type == "iPod2,1" && $device_mode == "Recovery" ]]; then
  1132.         device_newbr=2
  1133.         print "* Cannot check $device_name bootrom model in Recovery mode. Enter DFU mode to get bootrom model"
  1134.         return
  1135.     elif [[ $device_type != "iPhone2,1" && $device_type != "iPod2,1" ]]; then
  1136.         case $device_type in
  1137.             iPhone4,1 | iPhone5,2 | iPad2,7 | iPad3,[26] ) device_9900candidate=1;;
  1138.         esac
  1139.         if [[ $device_type == "DFU" ]]; then
  1140.             print "* Cannot check for manufacturing date in DFU mode"
  1141.             return
  1142.         fi
  1143.         local fourth="${device_serial:1:1}"
  1144.         local year_half
  1145.         case $fourth in
  1146.             C ) year_half="1st half 2010";;
  1147.             D ) year_half="2nd half 2010";;
  1148.             F ) year_half="1st half 2011";;
  1149.             G ) year_half="2nd half 2011";;
  1150.             H ) year_half="1st half 2012";;
  1151.             J ) year_half="2nd half 2012";;
  1152.             K ) year_half="1st half 2013";;
  1153.             L ) year_half="2nd half 2013";;
  1154.             M ) year_half="1st half 2014";;
  1155.             N ) year_half="2nd half 2014";;
  1156.             P ) year_half="1st half 2015";;
  1157.             Q ) year_half="2nd half 2015";;
  1158.             R ) year_half="1st half 2016";;
  1159.             S ) year_half="2nd half 2016";;
  1160.             T ) year_half="1st half 2017";;
  1161.             V ) year_half="2nd half 2017";;
  1162.             W ) year_half="1st half 2018";;
  1163.             X ) year_half="2nd half 2018";;
  1164.             Y ) year_half="1st half 2019";;
  1165.             Z ) year_half="2nd half 2019";;
  1166.         esac
  1167.         if [[ -n $year_half ]]; then
  1168.             print "* Manufactured in $year_half"
  1169.         elif [[ $device_mode == "Normal" ]] && (( device_proc >= 5 )); then
  1170.             print "* Select Pair Device to get more device information"
  1171.             if [[ -n $device_use_bb && $device_9900candidate == 1 ]]; then
  1172.                 print "* This will also check if your device is affected by the 9900 IMEI activation issue"
  1173.             fi
  1174.         fi
  1175.     fi
  1176.     case $device_newbr in
  1177.         0 ) print "* This $device_name is an old bootrom model";;
  1178.         1 ) print "* This $device_name is a new bootrom model";;
  1179.         2 ) print "* This $device_name bootrom model cannot be determined. Enter DFU mode to get bootrom model";;
  1180.     esac
  1181.     if [[ $device_type == "iPhone2,1" && $device_mode == "DFU" ]]; then
  1182.         print "* Cannot check for manufacturing date in DFU mode"
  1183.     elif [[ $device_type == "iPhone2,1" ]]; then
  1184.         print "* Manufactured in Week $week - $year"
  1185.     fi
  1186. }
  1187.  
  1188. device_s5l8900xall() {
  1189.     local wtf_sha="cb96954185a91712c47f20adb519db45a318c30f"
  1190.     local wtf_saved="../saved/WTF.s5l8900xall.RELEASE.dfu"
  1191.     local wtf_patched="$wtf_saved.patched"
  1192.     local wtf_patch="../resources/patch/WTF.s5l8900xall.RELEASE.patch"
  1193.     local wtf_sha_local="$($sha1sum "$wtf_saved" 2>/dev/null | awk '{print $1}')"
  1194.     mkdir -p ../saved
  1195.     if [[ $wtf_sha_local != "$wtf_sha" ]]; then
  1196.         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
  1197.         rm -f "$wtf_saved"
  1198.         mv WTF.s5l8900xall.RELEASE.dfu $wtf_saved
  1199.     fi
  1200.     rm -f "$wtf_patched"
  1201.     log "Patching WTF.s5l8900xall"
  1202.     $bspatch $wtf_saved $wtf_patched $wtf_patch
  1203.     log "Sending patched WTF.s5l8900xall (Pwnage 2.0)"
  1204.     $irecovery -f "$wtf_patched"
  1205.     if [[ $platform == "macos" ]]; then
  1206.         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."
  1207.     fi
  1208.     device_find_mode DFUreal
  1209.     device_srtg="$($irecovery -q | grep "SRTG" | cut -c 7-)"
  1210.     log "SRTG: $device_srtg"
  1211.     if [[ $device_srtg == "iBoot-636.66.3x" ]]; then
  1212.         device_argmode=
  1213.         device_type=$($irecovery -q | grep "PRODUCT" | cut -c 10-)
  1214.         device_model=$($irecovery -q | grep "MODEL" | cut -c 8-)
  1215.         device_model="${device_model%??}"
  1216.         device_get_name
  1217.         device_pwnd="Pwnage 2.0"
  1218.     fi
  1219. }
  1220.  
  1221. device_get_info() {
  1222.     : '
  1223.    usage: device_get_info (no arguments)
  1224.    sets the variables: device_mode, device_type, device_ecid, device_vers, device_udid, device_model, device_fw_dir,
  1225.    device_use_vers, device_use_build, device_use_bb, device_use_bb_sha1, device_latest_vers, device_latest_build,
  1226.    device_latest_bb, device_latest_bb_sha1, device_proc
  1227.    '
  1228.  
  1229.     if [[ ! -s $ideviceinfo ]]; then
  1230.         error "ideviceinfo not found. Make sure to update the script and/or check your Internet connection."
  1231.     fi
  1232.     if [[ $device_argmode == "none" ]]; then
  1233.         log "No device mode is enabled."
  1234.         device_mode="none"
  1235.         device_vers="Unknown"
  1236.     elif [[ $main_argmode == "device_enter_ramdisk_menu" ]]; then
  1237.         log "sshrd-menu flag detected, assuming device is in SSH ramdisk mode"
  1238.         device_mode="Normal"
  1239.     else
  1240.         log "Finding device in Normal mode..."
  1241.         if [[ $platform == "linux" ]]; then
  1242.             print "* If it gets stuck here, try to restart your PC"
  1243.             if [[ $othertmp != 0 ]]; then
  1244.                 print "* If it fails to detect devices, try to delete all \"tmp\" folders in your Legacy iOS Kit folder"
  1245.             fi
  1246.         fi
  1247.         $ideviceinfo -s >/dev/null
  1248.         if [[ $? == 0 ]]; then
  1249.             device_mode="Normal"
  1250.         else
  1251.             $ideviceinfo >/dev/null
  1252.             if [[ $? == 0 ]]; then
  1253.                 device_mode="Normal"
  1254.             fi
  1255.         fi
  1256.     fi
  1257.  
  1258.     if [[ -z $device_mode ]]; then
  1259.         log "Finding device in Recovery/DFU mode..."
  1260.         device_mode="$($irecovery -q | grep -w "MODE" | cut -c 7-)"
  1261.     fi
  1262.  
  1263.     if [[ $device_mode == "Recovery" && $device_pwnrec == 1 ]]; then
  1264.         device_mode="DFU"
  1265.     fi
  1266.  
  1267.     if [[ -z $device_mode ]]; then
  1268.         local error_msg=$'* Make sure to trust this computer by selecting "Trust" at the pop-up.'
  1269.         if [[ $platform == "macos" ]]; then
  1270.             error_msg+=$'\n* Make sure to have the initial setup dependencies installed before retrying.'
  1271.             error_msg+=$'\n* Double-check if the device is being detected by iTunes/Finder.'
  1272.         else
  1273.             error_msg+=$'\n* If your device in normal mode is not being detected, this is likely a usbmuxd issue.'
  1274.             error_msg+=$'\n* You may also try again in a live USB.'
  1275.         fi
  1276.         error_msg+=$'\n* Try restarting your PC/Mac as well as using different USB ports/cables.'
  1277.         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'
  1278.         error "No device found! Please connect the iOS device to proceed." "$error_msg"
  1279.     fi
  1280.  
  1281.     log "Getting device info..."
  1282.     case $device_mode in
  1283.         "WTF" | "DFU" | "Recovery" )
  1284.             if [[ -n $device_argmode ]]; then
  1285.                 device_entry
  1286.             else
  1287.                 device_type=$($irecovery -q | grep "PRODUCT" | cut -c 10-)
  1288.                 device_ecid=$(printf "%d" $($irecovery -q | grep "ECID" | cut -c 7-)) # converts hex ecid to dec
  1289.             fi
  1290.             device_model=$($irecovery -q | grep "MODEL" | cut -c 8-)
  1291.             if [[ $device_mode != "DFU" && -z $device_argmode && $device_model == "m68ap" ]]; then
  1292.                 device_entry_s5l8900
  1293.             fi
  1294.             if [[ $device_mode == "Recovery" ]]; then
  1295.                 device_vers=$(echo "/exit" | $irecovery -s | grep -a "iBoot-")
  1296.             fi
  1297.             if [[ -z $device_vers ]]; then
  1298.                 device_vers="Unknown"
  1299.                 if [[ $device_mode == "Recovery" ]]; then
  1300.                     device_vers+=". Re-enter recovery mode to get iBoot version"
  1301.                 fi
  1302.             fi
  1303.             device_serial="$($irecovery -q | grep "SRNM" | cut -c 7- | cut -c 3- | cut -c -3)"
  1304.             device_get_name
  1305.             print "* Device: $device_name (${device_type} - ${device_model}) in $device_mode mode"
  1306.             print "* iOS Version: $device_vers"
  1307.             print "* ECID: $device_ecid"
  1308.             device_manufacturing
  1309.             if [[ $device_type == "iPod2,1" && $device_newbr != 2 ]]; then
  1310.                 device_newbr="$($irecovery -q | grep -c '240.5.1')"
  1311.             elif [[ $device_type == "iPhone2,1" ]]; then
  1312.                 device_newbr="$($irecovery -q | grep -c '359.3.2')"
  1313.             fi
  1314.             device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
  1315.             device_srtg="$($irecovery -q | grep "SRTG" | cut -c 7-)"
  1316.         ;;
  1317.  
  1318.         "Normal" )
  1319.             if [[ -n $device_argmode ]]; then
  1320.                 device_entry
  1321.             else
  1322.                 device_type=$($ideviceinfo -s -k ProductType)
  1323.                 [[ -z $device_type ]] && device_type=$($ideviceinfo -k ProductType)
  1324.             fi
  1325.             if [[ $main_argmode != "device_enter_ramdisk"* ]]; then
  1326.                 device_ecid=$($ideviceinfo -s -k UniqueChipID)
  1327.                 device_model=$($ideviceinfo -s -k HardwareModel)
  1328.                 if [[ $device_model == "N81AP" ]]; then
  1329.                     device_type="iPod4,1" # this is needed since touch 4 devices on ios 7 show as iphone3,1/3,3
  1330.                 fi
  1331.                 device_vers=$($ideviceinfo -s -k ProductVersion)
  1332.                 [[ -z $device_vers ]] && device_vers=$($ideviceinfo -k ProductVersion)
  1333.                 device_vers_maj=$(echo "$device_vers" | cut -d. -f1)
  1334.                 device_vers_min=$(echo "$device_vers" | cut -d. -f2)
  1335.                 device_build=$($ideviceinfo -s -k BuildVersion)
  1336.                 [[ -z $device_build ]] && device_build=$($ideviceinfo -k BuildVersion)
  1337.                 device_udid=$($ideviceinfo -s -k UniqueDeviceID)
  1338.                 [[ -z $device_udid ]] && device_udid=$($ideviceinfo -k UniqueDeviceID)
  1339.                 if [[ $device_type == "iPod2,1" ]]; then
  1340.                     device_newbr="$($ideviceinfo -k ModelNumber | grep -c 'C')"
  1341.                 fi
  1342.                 # i'd like to force pair for all it but would prob get annoying quick especially on linux
  1343.                 device_get_paired_info
  1344.                 device_protocol=$($ideviceinfo -s -k ProtocolVersion)
  1345.                 if [[ $device_protocol == 1 ]]; then
  1346.                     device_entry_s5l8900
  1347.                 fi
  1348.             fi
  1349.         ;;
  1350.     esac
  1351.  
  1352.     if [[ $device_argmode == "none" ]]; then
  1353.         device_entry
  1354.     fi
  1355.  
  1356.     device_model="$(echo $device_model | tr '[:upper:]' '[:lower:]')"
  1357.     device_model="${device_model%ap}" # remove "ap" from the end
  1358.     # workaround for https://github.com/LukeZGD/Legacy-iOS-Kit/issues/932, hopefully this is the only case where this is needed
  1359.     if [[ $device_type == "iPad2,1" ]]; then
  1360.         device_model="k93"
  1361.     fi
  1362.     # device_model fallback/failsafe (this will be up to checkm8 devices only)
  1363.     case $device_model in
  1364.         k48  ) device_type="iPad1,1";;
  1365.         k93  ) device_type="iPad2,1";;
  1366.         k94  ) device_type="iPad2,2";;
  1367.         k95  ) device_type="iPad2,3";;
  1368.         k93a ) device_type="iPad2,4";;
  1369.         p105 ) device_type="iPad2,5";;
  1370.         p106 ) device_type="iPad2,6";;
  1371.         p107 ) device_type="iPad2,7";;
  1372.         j1   ) device_type="iPad3,1";;
  1373.         j2   ) device_type="iPad3,2";;
  1374.         j2a  ) device_type="iPad3,3";;
  1375.         p101 ) device_type="iPad3,4";;
  1376.         p102 ) device_type="iPad3,5";;
  1377.         p103 ) device_type="iPad3,6";;
  1378.         j71  ) device_type="iPad4,1";;
  1379.         j72  ) device_type="iPad4,2";;
  1380.         j73  ) device_type="iPad4,3";;
  1381.         j85  ) device_type="iPad4,4";;
  1382.         j86  ) device_type="iPad4,5";;
  1383.         j87  ) device_type="iPad4,6";;
  1384.         j85m ) device_type="iPad4,7";;
  1385.         j86m ) device_type="iPad4,8";;
  1386.         j87m ) device_type="iPad4,9";;
  1387.         j96  ) device_type="iPad5,1";;
  1388.         j97  ) device_type="iPad5,2";;
  1389.         j81  ) device_type="iPad5,3";;
  1390.         j82  ) device_type="iPad5,4";;
  1391.         j127 ) device_type="iPad6,3";;
  1392.         j128 ) device_type="iPad6,4";;
  1393.         j98a ) device_type="iPad6,7";;
  1394.         j99a ) device_type="iPad6,8";;
  1395.         j71s ) device_type="iPad6,11";;
  1396.         j71t ) device_type="iPad6,11";;
  1397.         j72s ) device_type="iPad6,12";;
  1398.         j72t ) device_type="iPad6,12";;
  1399.         j120 ) device_type="iPad7,1";;
  1400.         j121 ) device_type="iPad7,2";;
  1401.         j207 ) device_type="iPad7,3";;
  1402.         j208 ) device_type="iPad7,4";;
  1403.         j71b ) device_type="iPad7,5";;
  1404.         j72b ) device_type="iPad7,6";;
  1405.         j171 ) device_type="iPad7,11";;
  1406.         j172 ) device_type="iPad7,12";;
  1407.         m68  ) device_type="iPhone1,1";;
  1408.         n82  ) device_type="iPhone1,2";;
  1409.         n88  ) device_type="iPhone2,1";;
  1410.         n90  ) device_type="iPhone3,1";;
  1411.         n90b ) device_type="iPhone3,2";;
  1412.         n92  ) device_type="iPhone3,3";;
  1413.         n94  ) device_type="iPhone4,1";;
  1414.         n41  ) device_type="iPhone5,1";;
  1415.         n42  ) device_type="iPhone5,2";;
  1416.         n48  ) device_type="iPhone5,3";;
  1417.         n49  ) device_type="iPhone5,4";;
  1418.         n51  ) device_type="iPhone6,1";;
  1419.         n53  ) device_type="iPhone6,2";;
  1420.         n56  ) device_type="iPhone7,1";;
  1421.         n61  ) device_type="iPhone7,2";;
  1422.         n71  ) device_type="iPhone8,1";;
  1423.         n71m ) device_type="iPhone8,1";;
  1424.         n66  ) device_type="iPhone8,2";;
  1425.         n66m ) device_type="iPhone8,2";;
  1426.         n69  ) device_type="iPhone8,4";;
  1427.         n69u ) device_type="iPhone8,4";;
  1428.         d10  ) device_type="iPhone9,1";;
  1429.         d11  ) device_type="iPhone9,2";;
  1430.         d101 ) device_type="iPhone9,3";;
  1431.         d111 ) device_type="iPhone9,4";;
  1432.         d20  ) device_type="iPhone10,1";;
  1433.         d21  ) device_type="iPhone10,2";;
  1434.         d22  ) device_type="iPhone10,3";;
  1435.         d201 ) device_type="iPhone10,4";;
  1436.         d211 ) device_type="iPhone10,5";;
  1437.         d221 ) device_type="iPhone10,6";;
  1438.         n45  ) device_type="iPod1,1";;
  1439.         n72  ) device_type="iPod2,1";;
  1440.         n18  ) device_type="iPod3,1";;
  1441.         n81  ) device_type="iPod4,1";;
  1442.         n78  ) device_type="iPod5,1";;
  1443.         n102 ) device_type="iPod7,1";;
  1444.         n112 ) device_type="iPod9,1";;
  1445.     esac
  1446.     device_type_lower="$(echo "$device_type" | tr '[:upper:]' '[:lower:]')"
  1447.     # device_model fallback/failsafe
  1448.     case $device_type in
  1449.         iPad1,1  ) device_model="k48";;
  1450.         iPad2,1  ) device_model="k93";;
  1451.         iPad2,2  ) device_model="k94";;
  1452.         iPad2,3  ) device_model="k95";;
  1453.         iPad2,4  ) device_model="k93a";;
  1454.         iPad2,5  ) device_model="p105";;
  1455.         iPad2,6  ) device_model="p106";;
  1456.         iPad2,7  ) device_model="p107";;
  1457.         iPad3,1  ) device_model="j1";;
  1458.         iPad3,2  ) device_model="j2";;
  1459.         iPad3,3  ) device_model="j2a";;
  1460.         iPad3,4  ) device_model="p101";;
  1461.         iPad3,5  ) device_model="p102";;
  1462.         iPad3,6  ) device_model="p103";;
  1463.         iPad4,1  ) device_model="j71";;
  1464.         iPad4,2  ) device_model="j72";;
  1465.         iPad4,3  ) device_model="j73";;
  1466.         iPad4,4  ) device_model="j85";;
  1467.         iPad4,5  ) device_model="j86";;
  1468.         iPad4,6  ) device_model="j87";;
  1469.         iPad4,7  ) device_model="j85m";;
  1470.         iPad4,8  ) device_model="j86m";;
  1471.         iPad4,9  ) device_model="j87m";;
  1472.         iPad5,1  ) device_model="j96";;
  1473.         iPad5,2  ) device_model="j97";;
  1474.         iPad5,3  ) device_model="j81";;
  1475.         iPad5,4  ) device_model="j82";;
  1476.         iPad6,3  ) device_model="j127";;
  1477.         iPad6,4  ) device_model="j128";;
  1478.         iPad6,7  ) device_model="j98a";;
  1479.         iPad6,8  ) device_model="j99a";;
  1480.         #iPad6,11 ) device_model="j71s";;
  1481.         #iPad6,12 ) device_model="j72s";;
  1482.         iPad7,1  ) device_model="j120";;
  1483.         iPad7,2  ) device_model="j121";;
  1484.         iPad7,3  ) device_model="j207";;
  1485.         iPad7,4  ) device_model="j208";;
  1486.         iPad7,5  ) device_model="j71b";;
  1487.         iPad7,6  ) device_model="j72b";;
  1488.         iPad7,11 ) device_model="j171";;
  1489.         iPad7,12 ) device_model="j172";;
  1490.         iPhone1,1) device_model="m68";;
  1491.         iPhone1,2) device_model="n82";;
  1492.         iPhone2,1) device_model="n88";;
  1493.         iPhone3,1) device_model="n90";;
  1494.         iPhone3,2) device_model="n90b";;
  1495.         iPhone3,3) device_model="n92";;
  1496.         iPhone4,1) device_model="n94";;
  1497.         iPhone5,1) device_model="n41";;
  1498.         iPhone5,2) device_model="n42";;
  1499.         iPhone5,3) device_model="n48";;
  1500.         iPhone5,4) device_model="n49";;
  1501.         iPhone6,1) device_model="n51";;
  1502.         iPhone6,2) device_model="n53";;
  1503.         iPhone7,1) device_model="n56";;
  1504.         iPhone7,2) device_model="n61";;
  1505.         #iPhone8,1) device_model="n71";;
  1506.         #iPhone8,2) device_model="n66";;
  1507.         #iPhone8,4) device_model="n69";;
  1508.         iPhone9,1) device_model="d10";;
  1509.         iPhone9,2) device_model="d11";;
  1510.         iPhone9,3) device_model="d101";;
  1511.         iPhone9,4) device_model="d111";;
  1512.         iPhone10,1) device_model="d20";;
  1513.         iPhone10,2) device_model="d21";;
  1514.         iPhone10,3) device_model="d22";;
  1515.         iPhone10,4) device_model="d201";;
  1516.         iPhone10,5) device_model="d211";;
  1517.         iPhone10,6) device_model="d221";;
  1518.         iPod1,1 ) device_model="n45";;
  1519.         iPod2,1 ) device_model="n72";;
  1520.         iPod3,1 ) device_model="n18";;
  1521.         iPod4,1 ) device_model="n81";;
  1522.         iPod5,1 ) device_model="n78";;
  1523.         iPod7,1 ) device_model="n102";;
  1524.         iPod9,1 ) device_model="n112";;
  1525.     esac
  1526.  
  1527.     device_fw_dir="../saved/firmware/$device_type"
  1528.     mkdir -p $device_fw_dir 2>/dev/null
  1529.     all_flash="Firmware/all_flash/all_flash.${device_model}ap.production"
  1530.     device_use_bb=0
  1531.     device_latest_bb=0
  1532.     # set device_proc (what processor the device has)
  1533.     case $device_type in
  1534.         iPhone1,* | iPod1,1 )
  1535.             device_proc=1;; # S5L8900
  1536.         iPad1,1 | iPhone[23],* | iPod[234],1 )
  1537.             device_proc=4;; # A4/S5L8720/8920/8922
  1538.         iPad2,* | iPad3,[123] | iPhone4,1 | iPod5,1 )
  1539.             device_proc=5;; # A5
  1540.         iPad3,* | iPhone5,* )
  1541.             device_proc=6;; # A6
  1542.         iPad4,* | iPhone6,* )
  1543.             device_proc=7;; # A7
  1544.         iPad5,* | iPhone7,* | iPod7,1 )
  1545.             device_proc=8;; # A8
  1546.         iPad6,* | iPhone8,* )
  1547.             device_proc=9;; # A9
  1548.         iPad7,* | iPhone9,* | iPhone10,* | iPod9,1 )
  1549.             device_proc=10;; # A10 or A11
  1550.         iPad* | iPhone* )
  1551.             device_proc=11;; # Newer devices
  1552.     esac
  1553.     case $device_type in
  1554.         iPad[67],* ) device_checkm8ipad=1;;
  1555.     esac
  1556.     device_get_name
  1557.     if [[ $device_mode == "Normal" && -z $device_ecid && $main_argmode != "device_enter_ramdisk"* ]]; then
  1558.         warn "Unable to detect device type/ECID. Is your device on 2.x or lower?"
  1559.         warn "Limited support for iOS versions lower than 3.x. Expect features to not work properly."
  1560.         print "* For better support, enter Recovery/DFU mode and/or update your device to iOS 3.x or newer."
  1561.         pause
  1562.         [[ -z $device_vers_maj ]] && device_vers_maj=1
  1563.     fi
  1564.     if [[ $device_type == "AppleTV"* || $device_type == "Watch"* ]]; then
  1565.         device_proc=11
  1566.     elif [[ -z $device_name || -z $device_proc ]]; then
  1567.         error "Unrecognized device $device_type. Enter the device type properly."
  1568.     fi
  1569.     if (( device_proc > 10 )); then
  1570.         print "* Device: $device_name (${device_type} - ${device_model}ap) in $device_mode mode"
  1571.         print "* iOS Version: $device_vers"
  1572.         print "* ECID: $device_ecid"
  1573.         echo
  1574.         warn "This device is mostly not supported by Legacy iOS Kit."
  1575.         print "* You may still continue but options will be limited to sideloading and other basic features."
  1576.         pause
  1577.     fi
  1578.  
  1579.     if [[ $device_proc == 1 && $device_mode == "DFU" ]]; then
  1580.         log "SRTG: $device_srtg"
  1581.         if [[ $device_srtg == "iBoot-636.66.3x" ]]; then
  1582.             device_pwnd="Pwnage 2.0"
  1583.         else
  1584.             log "Found an S5L8900 device in $device_mode mode. Your device needs to be in WTF mode to continue."
  1585.             print "* Force restart your device and place it in normal or recovery mode, then re-enter WTF mode."
  1586.             print "* You can enter WTF mode by doing the DFU mode procedure."
  1587.             echo
  1588.             device_dfuhelper norec WTFreal
  1589.             device_find_mode WTFreal 100
  1590.         fi
  1591.     fi
  1592.  
  1593.     # set device_use_vers, device_use_build (where to get the baseband and manifest from for ota/other)
  1594.     # for a7/a8 other restores 11.3+, device_latest_vers and device_latest_build are used
  1595.     # these latest versions are not expected to change anymore (maybe except for 18.x)
  1596.     case $device_type in
  1597.         iPhone1,1 | iPod1,1 )
  1598.             device_use_vers="3.1.3"
  1599.             device_use_build="7E18"
  1600.         ;;
  1601.         iPhone1,2 | iPod2,1 )
  1602.             device_use_vers="4.2.1"
  1603.             device_use_build="8C148"
  1604.         ;;
  1605.         iPad1,1 | iPod3,1 )
  1606.             device_use_vers="5.1.1"
  1607.             device_use_build="9B206"
  1608.         ;;
  1609.         iPhone2,1 | iPod4,1 )
  1610.             device_use_vers="6.1.6"
  1611.             device_use_build="10B500"
  1612.         ;;
  1613.         iPhone3,[123] )
  1614.             device_use_vers="7.1.2"
  1615.             device_use_build="11D257"
  1616.         ;;
  1617.         iPad2,[1245] | iPad3,1 | iPod5,1 )
  1618.             device_use_vers="9.3.5"
  1619.             device_use_build="13G36"
  1620.         ;;
  1621.         iPad2,[367] | iPad3,[23] | iPhone4,1 )
  1622.             device_use_vers="9.3.6"
  1623.             device_use_build="13G37"
  1624.         ;;
  1625.         iPad3,[456] | iPhone5,[1234] ) # 10.3.4 works for ALL A6(X) devices
  1626.             device_use_vers="10.3.4"
  1627.             device_use_build="14G61"
  1628.         ;;
  1629.         iPad4,[12345] | iPhone6,[12] )
  1630.             device_use_vers="10.3.3"
  1631.             device_use_build="14G60"
  1632.         ;;
  1633.     esac
  1634.     case $device_type in
  1635.         iPad4,* | iPhone[67],* | iPod7,1 )
  1636.             device_latest_vers="12.5.8"
  1637.             device_latest_build="16H88"
  1638.         ;;
  1639.         iPad5,* | iPhone[89],* | iPod9,1 )
  1640.             device_latest_vers="15.8.8"
  1641.             device_latest_build="19H422"
  1642.         ;;
  1643.         iPad6,* | iPhone10,* )
  1644.             device_latest_vers="16.7.16"
  1645.             device_latest_build="20H392"
  1646.         ;;
  1647.         iPad7,[123456] )
  1648.             device_latest_vers="17.7.11"
  1649.             device_latest_build="21H461"
  1650.         ;;
  1651.         iPad7,1[12] | iPhone11,* )
  1652.             device_latest_vers="18.7.9"
  1653.             device_latest_build="22H355"
  1654.         ;;
  1655.     esac
  1656.     # if latest vers is not set, copy use vers to latest
  1657.     if [[ -z $device_latest_vers ]]; then
  1658.         device_latest_vers="$device_use_vers"
  1659.         device_latest_build="$device_use_build"
  1660.     fi
  1661.     # if still not set and on linux, get from ipsw.me
  1662.     if [[ -z $device_latest_vers && $platform == "linux" ]]; then
  1663.         log "Getting latest iOS version for $device_type"
  1664.         download_from_url "https://api.ipsw.me/v4/device/$device_type?type=ipsw" tmp.json
  1665.         local latestver="$(cat tmp.json | $jq -j ".firmwares[0]")"
  1666.         device_latest_vers="$(echo "$latestver" | $jq -j ".version")"
  1667.         device_latest_build="$(echo "$latestver" | $jq -j ".buildid")"
  1668.     fi
  1669.     # set device_use_bb, device_use_bb_sha1 (what baseband to use for ota/other)
  1670.     # for a7/a8 other restores 11.3+, device_latest_bb and device_latest_bb_sha1 are used instead
  1671.     case $device_type in
  1672.         iPhone4,1 ) # MDM6610
  1673.             device_use_bb="Trek-6.7.00.Release.bbfw"
  1674.             device_use_bb_sha1="22a35425a3cdf8fa1458b5116cfb199448eecf49"
  1675.         ;;
  1676.         iPad2,[67] ) # MDM9615 9.3.6 (32bit)
  1677.             device_use_bb="Mav5-11.80.00.Release.bbfw"
  1678.             device_use_bb_sha1="aa52cf75b82fc686f94772e216008345b6a2a750"
  1679.         ;;
  1680.         iPhone5,[12] | iPad3,[56] ) # MDM9615 10.3.4 (32bit)
  1681.             device_use_bb="Mav5-11.80.00.Release.bbfw"
  1682.             device_use_bb_sha1="8951cf09f16029c5c0533e951eb4c06609d0ba7f"
  1683.         ;;
  1684.         iPad4,[235] | iPhone5,[34] | iPhone6,[12] ) # MDM9615 10.3.3 (5C, 5S, air, mini2)
  1685.             device_use_bb="Mav7Mav8-7.60.00.Release.bbfw"
  1686.             device_use_bb_sha1="f397724367f6bed459cf8f3d523553c13e8ae12c"
  1687.         ;;
  1688.         iPad1,1 | iPhone[123],* ) device_use_bb2=1;;
  1689.         iPad[23],[23] ) device_use_bb2=2;;
  1690.     esac
  1691.     case $device_type in
  1692.         iPad4,[235689] | iPhone6,[12] ) # MDM9615 12.4-latest
  1693.             device_latest_bb="Mav7Mav8-10.80.02.Release.bbfw"
  1694.             device_latest_bb_sha1="f5db17f72a78d807a791138cd5ca87d2f5e859f0"
  1695.         ;;
  1696.     esac
  1697.     # if use bb is not set but latest bb is set, copy latest bb to use
  1698.     if [[ -z $device_use_bb && -n $device_latest_bb ]]; then
  1699.         device_use_bb="$device_latest_bb"
  1700.         device_use_bb_sha1="$device_latest_bb_sha1"
  1701.     fi
  1702.     # disable baseband update if var is set to 1 (manually disabled w/ --disable-bbupdate arg)
  1703.     if [[ $device_disable_bbupdate == 1 && $device_use_bb != 0 ]] && (( device_proc < 7 )); then
  1704.         device_disable_bbupdate="$device_type"
  1705.     fi
  1706.     # enable activation records flag if device is a5(x)/a6(x), normal mode, and activated
  1707.     if [[ $device_proc == 5 || $device_proc == 6 ]] && [[ -z $device_disable_actrec ]]; then
  1708.         if [[ $device_mode == "Normal" && $device_unactivated != 1 && $device_imei == "9900"* ]]; then
  1709.             device_actrec=1
  1710.             device_auto_actrec=1
  1711.         elif [[ -s ../saved/$device_type/activation-$device_ecid.tar ]]; then
  1712.             device_actrec=1
  1713.             device_auto_actrec=2
  1714.         elif [[ $device_type == "iPad3,3" && $device_mode == "Normal" && $device_unactivated != 1 ]]; then
  1715.             device_actrec=1
  1716.             device_auto_actrec=3
  1717.         fi
  1718.     fi
  1719.     if [[ $device_argmode == "none" ]]; then
  1720.         device_mode="none"
  1721.         device_vers="Unknown"
  1722.     fi
  1723.  
  1724.     # powdersn0w device and base version support
  1725.     case $device_type in
  1726.         iPhone[345],* | iPad1,1 | iPad2,[4567] | iPad3,* | iPod[35],1 ) device_canpowder=1;;
  1727.     esac
  1728.     check_vers="7.1"
  1729.     case $device_type in
  1730.         iPad3,[456] | iPhone5,* | iPod5,1 ) check_vers="7";;
  1731.         iPad2,[567] ) check_vers="7.0";;
  1732.     esac
  1733.     base_vers="$check_vers.x"
  1734.     if [[ $device_proc == 4 ]]; then
  1735.         check_vers="$device_latest_vers"
  1736.         base_vers="$device_latest_vers"
  1737.     fi
  1738. }
  1739.  
  1740. device_find_mode() {
  1741.     # usage: device_find_mode {DFU,Recovery,Restore} {Timeout (default: 24 for linux, 4 for other)}
  1742.     # finds device in given mode, and sets the device_mode variable
  1743.     local usb
  1744.     local timeout=4
  1745.     local i=0
  1746.     local device_in
  1747.     local mode="$1"
  1748.     local mode2
  1749.     local wtfreal
  1750.  
  1751.     if [[ $mode == "Recovery" ]]; then
  1752.         usb=1281
  1753.     elif [[ $device_proc == 1 ]]; then
  1754.         usb=1222
  1755.         if [[ $mode == "DFUreal" ]]; then
  1756.             mode="DFU"
  1757.             usb=1227
  1758.         elif [[ $mode == "WTFreal" ]]; then
  1759.             mode="WTF"
  1760.             wtfreal=1
  1761.         elif [[ $mode == "DFU" ]]; then
  1762.             mode="WTF"
  1763.         fi
  1764.     else
  1765.         usb=1227
  1766.     fi
  1767.  
  1768.     if [[ -n $2 ]]; then
  1769.         timeout=$2
  1770.     elif [[ $platform == "linux" ]]; then
  1771.         timeout=24
  1772.     fi
  1773.  
  1774.     log "Finding device in $mode mode..."
  1775.     while (( i < timeout )); do
  1776.         if [[ $platform == "linux" ]]; then
  1777.             device_in=$(lsusb | grep -c "05ac:$usb")
  1778.         fi
  1779.         if [[ $mode == "Recovery" && $timeout == 50 ]]; then # find recovery/dfu instead of just recovery, only if timeout is 50
  1780.             mode2="$($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-)"
  1781.             if [[ -n $mode2 ]]; then
  1782.                 device_in=1
  1783.                 mode="$mode2"
  1784.             fi
  1785.         elif [[ $platform != "linux" ]]; then
  1786.             mode2="$($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-)"
  1787.             if [[ $mode2 == "$mode" ]]; then
  1788.                 device_in=1
  1789.             fi
  1790.         fi
  1791.  
  1792.         if [[ $device_in == 1 ]]; then
  1793.             log "Found device in $mode mode."
  1794.             device_mode="$mode"
  1795.             break
  1796.         fi
  1797.         sleep 1
  1798.         ((i++))
  1799.     done
  1800.  
  1801.     if [[ $device_in != 1 ]]; then
  1802.         if [[ $timeout != 1 && $timeout != 20 ]]; then
  1803.             error "Failed to find device in $mode mode (Timed out). Please run the script again."
  1804.         fi
  1805.         return 1
  1806.     elif [[ $mode == "WTF" && $wtfreal != 1 ]]; then
  1807.         device_s5l8900xall
  1808.     fi
  1809. }
  1810.  
  1811. device_sshpass() {
  1812.     # ask for device password and use sshpass for scp and ssh
  1813.     ssh_user="root"
  1814.     if (( device_vers_maj >= 15 )); then
  1815.         log "iOS 15+ device detected. Connecting to device SSH as mobile..."
  1816.         ssh_user="mobile"
  1817.     fi
  1818.     local pass="$1"
  1819.     if [[ -z $pass ]]; then
  1820.         read -s -p "$(input "Enter the SSH $ssh_user password of your iOS device: ")" pass
  1821.         echo
  1822.     fi
  1823.     if [[ -z $pass ]]; then
  1824.         pass="alpine"
  1825.     fi
  1826.     export SSHPASS="$pass"
  1827.     if [[ "$SSHPASS" == *" "* ]]; then
  1828.         warn "Your SSH password contains spaces. sshpass will not be used for this session"
  1829.         print "* It is recommended to change your password to remove spaces"
  1830.     else
  1831.         scp="$dir/sshpass -p$SSHPASS "
  1832.         ssh="$scp"
  1833.     fi
  1834.     scp+="$scp2"
  1835.     ssh+="$ssh2"
  1836. }
  1837.  
  1838. device_iproxy() {
  1839.     local port=22
  1840.     log "Running iproxy for SSH..."
  1841.     if [[ -n $2 ]]; then
  1842.         port=$2
  1843.     fi
  1844.     if [[ $1 == "no-logging" && $debug_mode != 1 ]]; then
  1845.         "$dir/iproxy" $ssh_port $port -s 127.0.0.1 >/dev/null &
  1846.         iproxy_pid=$!
  1847.     else
  1848.         "$dir/iproxy" $ssh_port $port -s 127.0.0.1 &
  1849.         iproxy_pid=$!
  1850.     fi
  1851.     log "iproxy PID: $iproxy_pid"
  1852.     sleep 1
  1853. }
  1854.  
  1855. device_find_all() {
  1856.     # find device stuff from palera1n legacy
  1857.     local opt
  1858.     if [[ $1 == "norec" || $mode == "device_dfuhelper" ]]; then
  1859.         return
  1860.     fi
  1861.     if [[ $platform == "macos" ]]; then
  1862.         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')"
  1863.     elif [[ $platform == "linux" ]]; then
  1864.         opt="$(lsusb | cut -d' ' -f6 | grep '05ac:' | cut -d: -f2)"
  1865.     fi
  1866.     case $opt in
  1867.         1227 ) return 1;; # dfu
  1868.         1281 ) return 2;; # recovery
  1869.         1222 ) return 3;; # wtf
  1870.         12[9a][0123456789abcdef] ) return 4;; # normal
  1871.     esac
  1872. }
  1873.  
  1874. device_dfuhelper2() {
  1875.     local top="SIDE"
  1876.     if [[ $device_type == "iPad"* ]]; then
  1877.         top="TOP"
  1878.     fi
  1879.     echo
  1880.     print "* Press the VOL UP button now."
  1881.     sleep 1
  1882.     print "* Press the VOL DOWN button now."
  1883.     sleep 1
  1884.     print "* Press and hold the $top button."
  1885.     for i in {10..1}; do
  1886.         echo -n "$i "
  1887.         sleep 1
  1888.     done
  1889.     echo -e "\n$(print "* Press and hold VOL DOWN and $top buttons.")"
  1890.     for i in {5..1}; do
  1891.         echo -n "$i "
  1892.         sleep 1
  1893.     done
  1894.     echo -e "\n$(print "* Release $top button and keep holding VOL DOWN button.")"
  1895.     for i in {8..1}; do
  1896.         echo -n "$i "
  1897.         device_find_all $1
  1898.         opt=$?
  1899.         if [[ $opt == 1 ]]; then
  1900.             echo -e "\n$(log 'Found device in DFU mode.')"
  1901.             device_mode="DFU"
  1902.             return
  1903.         fi
  1904.         sleep 1
  1905.     done
  1906.     echo
  1907.     device_find_mode DFU
  1908. }
  1909.  
  1910. device_dfuhelper3() {
  1911.     local sec=10
  1912.     if [[ $device_mode == "Recovery" ]]; then
  1913.         sec=8
  1914.     fi
  1915.     echo -e "\n$(print "* Hold TOP and HOME buttons.")"
  1916.     while (( sec > 0 )); do
  1917.         echo -n "$sec "
  1918.         sleep 1
  1919.         sec=$((sec-1))
  1920.     done
  1921.     echo -e "\n$(print "* Release TOP button and keep holding HOME button.")"
  1922.     for i in {13..1}; do
  1923.         echo -n "$i "
  1924.         sleep 1
  1925.     done
  1926.     echo
  1927.     if [[ $1 == "WTFreal" ]]; then
  1928.         device_find_mode WTFreal
  1929.     else
  1930.         device_find_mode DFU
  1931.     fi
  1932. }
  1933.  
  1934. device_dfuhelper() {
  1935.     local opt
  1936.     local rec=" recovery mode"
  1937.     if [[ $1 == "norec" || $mode == "device_dfuhelper" ]]; then
  1938.         rec=
  1939.     fi
  1940.     if [[ $device_mode == "DFU" && $1 == "DFUreal" ]]; then
  1941.         log "Device is already in DFU mode"
  1942.         return
  1943.     fi
  1944.     if [[ $device_mode == "DFU" && $mode != "device_dfuhelper" && $device_proc != 1 ]]; then
  1945.         log "Device is already in DFU mode"
  1946.         return
  1947.     fi
  1948.     print "* DFU Mode Helper - Get ready to enter DFU mode."
  1949.     print "* If you already know how to enter DFU mode, you may do so right now before continuing."
  1950.     select_yesno "Select Y to continue, N to exit$rec" 1
  1951.     if [[ $? != 1 ]]; then
  1952.         if [[ -z $1 && $device_mode == "Recovery" ]]; then
  1953.             log "Attempting to exit Recovery mode."
  1954.             $irecovery -n
  1955.         fi
  1956.         exit
  1957.     fi
  1958.     print "* Get ready..."
  1959.     device_mode="$($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-)"
  1960.     if [[ $device_mode == "DFU" && $mode != "device_dfuhelper" ]]; then
  1961.         log "Found device in DFU mode."
  1962.         return
  1963.     elif [[ -n $device_mode ]]; then
  1964.         for i in {3..1}; do
  1965.             echo -n "$i "
  1966.             sleep 1
  1967.         done
  1968.     fi
  1969.     case $device_type in
  1970.         iPhone1,* | iPod1,1  ) device_dfuhelper3 $2; return;;
  1971.         iPad1,1 | iPad1[12]* ) :;;
  1972.         iPhone1* | iPad[81]* ) device_dfuhelper2; return;;
  1973.     esac
  1974.     local top="TOP"
  1975.     local home="HOME"
  1976.     case $device_type in
  1977.         iPhone[79],* | iPhone8,[12] ) top="SIDE";;
  1978.     esac
  1979.     if [[ $device_type == "iPhone9,"* || $device_type == "iPod9,1" ]]; then
  1980.         home="VOL DOWN"
  1981.     fi
  1982.     local sec=10
  1983.     if [[ $device_mode == "Recovery" ]]; then
  1984.         sec=8
  1985.     fi
  1986.     echo -e "\n$(print "* Hold $top and $home buttons.")"
  1987.     while (( sec > 0 )); do
  1988.         echo -n "$sec "
  1989.         device_find_all $1
  1990.         opt=$?
  1991.         if [[ $opt == 1 ]]; then
  1992.             echo -e "\n$(log 'Found device in DFU mode.')"
  1993.             device_mode="DFU"
  1994.             return
  1995.         fi
  1996.         sleep 1
  1997.         sec=$((sec-1))
  1998.     done
  1999.     echo -e "\n$(print "* Release $top button and keep holding $home button.")"
  2000.     for i in {8..1}; do
  2001.         echo -n "$i "
  2002.         device_find_all $1
  2003.         opt=$?
  2004.         if [[ $opt == 1 ]]; then
  2005.             echo -e "\n$(log 'Found device in DFU mode.')"
  2006.             device_mode="DFU"
  2007.             return
  2008.         fi
  2009.         sleep 1
  2010.     done
  2011.     echo
  2012.     device_find_mode DFU
  2013. }
  2014.  
  2015. device_enter_mode() {
  2016.     # usage: device_enter_mode {Recovery, DFU, kDFU, pwnDFU}
  2017.     # attempt to enter given mode, and device_find_mode function will then set device_mode variable
  2018.     local opt
  2019.     case $1 in
  2020.         "WTFreal" )
  2021.             if [[ $device_mode == "WTF" ]]; then
  2022.                 return
  2023.             elif [[ $device_mode == "Normal" ]]; then
  2024.                 device_enter_mode Recovery
  2025.             fi
  2026.             if [[ $device_mode == "Recovery" ]]; then
  2027.                 device_dfuhelper norec WTFreal
  2028.                 return
  2029.             fi
  2030.             log "Found an S5L8900 device in $device_mode mode. Your device needs to be in WTF mode to continue."
  2031.             print "* Force restart your device and place it in normal or recovery mode, then re-enter WTF mode."
  2032.             print "* You can enter WTF mode by doing the DFU mode procedure."
  2033.             echo
  2034.             device_dfuhelper norec WTFreal
  2035.             device_find_mode WTFreal 100
  2036.         ;;
  2037.  
  2038.         "Recovery" )
  2039.             if [[ $device_mode == "Normal" ]]; then
  2040.                 device_pair
  2041.                 if [[ $mode != "enterrecovery" ]]; then
  2042.                     print "* The device needs to be in Recovery/DFU mode before proceeding."
  2043.                     select_yesno "Send device to recovery mode?" 1
  2044.                     if [[ $? != 1 ]]; then
  2045.                         log "User selected N, cannot continue. Exiting."
  2046.                         exit
  2047.                     fi
  2048.                 fi
  2049.                 log "Entering recovery mode..."
  2050.                 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"
  2051.                 "$dir/ideviceenterrecovery" "$device_udid" >/dev/null
  2052.                 device_find_mode Recovery 50
  2053.             fi
  2054.         ;;
  2055.  
  2056.         "DFU" )
  2057.             if [[ $device_mode == "Normal" ]]; then
  2058.                 device_enter_mode Recovery
  2059.             elif [[ $device_mode == "WTF" ]]; then
  2060.                 device_s5l8900xall
  2061.                 return
  2062.             elif [[ $device_mode == "DFU" ]]; then
  2063.                 return
  2064.             fi
  2065.             device_dfuhelper DFUreal
  2066.         ;;
  2067.  
  2068.         "kDFU" )
  2069.             local sendfiles=()
  2070.             local ip="127.0.0.1"
  2071.  
  2072.             if [[ $device_mode != "Normal" ]]; then
  2073.                 device_enter_mode pwnDFU
  2074.                 return
  2075.             fi
  2076.  
  2077.             echo "chmod +x /tmp/kloader*" > kloaders
  2078.             opt="kloader"
  2079.             if (( device_vers_maj <= 5 )); then
  2080.                 opt="kloader_axi0mX"
  2081.                 case $device_type in
  2082.                     iPad2,4 | iPad3,* ) opt="kloader5";; # needed for ipad 3 ios 5, unsure for ipad2,4
  2083.                 esac
  2084.                 log "Using $opt for $device_type iOS $device_vers_maj"
  2085.             fi
  2086.             echo "/tmp/$opt /tmp/pwnediBSS" >> kloaders
  2087.             sendfiles+=("../resources/kloader/$opt" "kloaders" "pwnediBSS")
  2088.             patch_ibss
  2089.  
  2090.             device_iproxy
  2091.             if [[ $device_jailbrokenselected != 1 ]]; then
  2092.                 device_ssh_message
  2093.                 print "3. On entering kDFU mode, the device will disconnect."
  2094.                 print "  - Proceed to unplug and replug the device when prompted."
  2095.                 print "  - Alternatively, press the TOP or HOME button."
  2096.                 device_sshpass
  2097.             fi
  2098.  
  2099.             log "Entering kDFU mode..."
  2100.             print "* This may take a while, but should not take longer than a minute."
  2101.             log "Sending files to device: ${sendfiles[*]}"
  2102.             if [[ $device_vers_maj == 10 ]]; then
  2103.                 for file in "${sendfiles[@]}"; do
  2104.                     cat $file | $ssh -p $ssh_port root@127.0.0.1 "cat > /tmp/$(basename $file)" &>scp.log &
  2105.                 done
  2106.                 sleep 3
  2107.                 cat scp.log
  2108.                 check="$(cat scp.log | grep -c "Connection reset")"
  2109.             else
  2110.                 $scp -P $ssh_port ${sendfiles[@]} root@127.0.0.1:/tmp
  2111.                 check=$?
  2112.             fi
  2113.             if [[ $check == 0 ]]; then
  2114.                 log "Running kloader"
  2115.                 $ssh -p $ssh_port root@127.0.0.1 "bash /tmp/kloaders" &
  2116.             else
  2117.                 warn "Failed to connect to device via USB SSH."
  2118.                 if [[ $device_vers_maj == 10 ]]; then
  2119.                     print "* Try to re-install both OpenSSH and Dropbear, reboot, re-jailbreak, and try again."
  2120.                     error "Failed to connect to device via SSH, cannot continue."
  2121.                 else
  2122.                     print "* Try to re-install OpenSSH, reboot, re-jailbreak if needed, and try again."
  2123.                 fi
  2124.                 input "Press Enter/Return to try again with Wi-Fi SSH (or press Ctrl+C to cancel and try again)"
  2125.                 read -s
  2126.                 log "Trying again with Wi-Fi SSH..."
  2127.                 print "* Make sure that your iOS device and PC/Mac are on the same network."
  2128.                 print "* To get your iOS device's IP Address, go to: Settings -> Wi-Fi/WLAN -> tap the 'i' or '>' next to your network name"
  2129.                 ip=
  2130.                 until [[ -n $ip ]]; do
  2131.                     read -p "$(input 'Enter the IP Address of your device: ')" ip
  2132.                 done
  2133.                 log "Sending files to device: ${sendfiles[*]}"
  2134.                 $scp ${sendfiles[@]} root@$ip:/tmp
  2135.                 if [[ $? != 0 ]]; then
  2136.                     error "Failed to connect to device via SSH, cannot continue."
  2137.                 fi
  2138.                 log "Running kloader"
  2139.                 $ssh root@$ip "bash /tmp/kloaders" &
  2140.             fi
  2141.  
  2142.             local attempt=1
  2143.             local device_in
  2144.             local port
  2145.             if [[ $ip == "127.0.0.1" ]]; then
  2146.                 port="-p $ssh_port"
  2147.             fi
  2148.             while (( attempt <= 5 )); do
  2149.                 log "Finding device in kDFU mode... (Attempt $attempt of 5)"
  2150.                 if [[ $($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-) == "DFU" ]]; then
  2151.                     device_in=1
  2152.                 fi
  2153.                 if [[ $device_in == 1 ]]; then
  2154.                     log "Found device in kDFU mode."
  2155.                     device_mode="DFU"
  2156.                     break
  2157.                 fi
  2158.                 if [[ $opt == "kloader_axi0mX" ]]; then
  2159.                     print "* Keep the device plugged in"
  2160.                     $ssh $port root@$ip "bash /tmp/kloaders" &
  2161.                 else
  2162.                     print "* Unplug and replug your device now"
  2163.                 fi
  2164.                 ((attempt++))
  2165.             done
  2166.             if (( attempt > 5 )); then
  2167.                 error "Failed to find device in kDFU mode. Please run the script again"
  2168.             fi
  2169.             kill $iproxy_pid
  2170.         ;;
  2171.  
  2172.         "pwnDFU" )
  2173.             local irec_pwned
  2174.             local tool_pwned
  2175.             local tool
  2176.  
  2177.             if [[ $device_skip_ibss == 1 ]]; then
  2178.                 warn "Skip iBSS flag detected, skipping pwned DFU check. Proceed with caution"
  2179.                 return
  2180.             elif [[ $device_pwnrec == 1 ]]; then
  2181.                 warn "Pwned recovery flag detected, skipping pwned DFU check. Proceed with caution"
  2182.                 return
  2183.             elif [[ $device_proc == 1 ]]; then
  2184.                 device_enter_mode DFU
  2185.                 return
  2186.             fi
  2187.  
  2188.             if [[ $device_mode == "DFU" ]]; then
  2189.                 device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
  2190.                 device_srtg="$($irecovery -q | grep "SRTG" | cut -c 7-)"
  2191.             fi
  2192.             if [[ -n $device_pwnd ]]; then
  2193.                 log "Device seems to be already in pwned DFU mode"
  2194.                 print "* Pwned: $device_pwnd"
  2195.                 case $device_proc in
  2196.                     [56] ) device_send_unpacked_ibss;;
  2197.                     [789] | 10 )
  2198.                         if [[ $device_proc == 7 && $device_pwnd == "checkm8" ]]; then
  2199.                             warn "Device is not pwned with ipwnder or updated gaster. Restoring/ramdisk booting will fail."
  2200.                         fi
  2201.                         log "gaster reset"
  2202.                         $gaster reset
  2203.                     ;;
  2204.                 esac
  2205.                 return
  2206.             elif [[ $device_mode == "DFU" && $device_boot4 != 1 && $device_srtg != "iBoot"* ]] &&
  2207.                  [[ $device_proc == 4 || $device_proc == 5 || $device_proc == 6 ]]; then
  2208.                 log "No SRTG for device in DFU mode! Already pwned iBSS mode?"
  2209.                 print "* If your device is not in pwnDFU/kDFU mode, sending iBEC will fail."
  2210.                 return
  2211.             fi
  2212.  
  2213.             if [[ $device_proc == 5 ]]; then
  2214.                 if [[ $device_mode != "DFU" ]]; then
  2215.                     device_enter_mode DFU
  2216.                     log "Device is now in DFU mode. Now put your device in PWNED DFU mode using checkm8-a5."
  2217.                 fi
  2218.                 echo
  2219.                 print "* DFU mode for A5(X) device - Make sure that your device is in PWNED DFU mode."
  2220.                 print "* You need to have an Raspberry Pi Pico or Arduino+USB Host Shield for checkm8-a5."
  2221.                 print "* For more details, go to: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/checkm8-a5"
  2222.                 echo
  2223.                 print "* As much as possible, RESTART YOUR DEVICE IN NORMAL MODE AND USE THE JAILBREAK/KDFU METHOD INSTEAD."
  2224.                 echo
  2225.                 log "After putting your device in PWNED DFU, plug it back in your PC/Mac before pressing Enter/Return."
  2226.                 pause
  2227.                 echo
  2228.                 log "Checking for device"
  2229.                 device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
  2230.                 if [[ -n $device_pwnd ]]; then
  2231.                     log "Found device in pwned DFU mode."
  2232.                     print "* Pwned: $device_pwnd"
  2233.                 else
  2234.                     local error_msg=$'\n* If you have just used checkm8-a5, it may have just failed. Just re-enter DFU and retry.'
  2235.                     if [[ $mode != "device_justboot" && $device_target_tethered != 1 ]]; then
  2236.                         error_msg+=$'\n\n* As much as possible, RESTART YOUR DEVICE IN NORMAL MODE AND USE THE JAILBREAK/KDFU METHOD INSTEAD.'
  2237.                         error_msg+=$'\n* You just need to have OpenSSH installed from Cydia.'
  2238.                         error_msg+=$'\n    - https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Restore-32-bit-Device'
  2239.                     fi
  2240.                     error_msg+=$'\n* Exit DFU mode first by holding the TOP and HOME buttons for about 10 seconds.'
  2241.                     error_msg+=$'\n* For more info about kDFU/pwnDFU, read the "Troubleshooting" wiki page in GitHub'
  2242.                     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'
  2243.                     error "32-bit A5 device is NOT in PWNED DFU mode. Already pwned iBSS mode?" "$error_msg"
  2244.                 fi
  2245.                 device_send_unpacked_ibss
  2246.                 return
  2247.             fi
  2248.  
  2249.             device_enter_mode DFU
  2250.  
  2251.             tool="gaster"
  2252.             if [[ $device_proc == 4 ]]; then
  2253.                 tool="primepwn"
  2254.                 if [[ $platform == "macos" && $device_type != "iPod2,1" ]]; then
  2255.                     tool="ipwnder_lite"
  2256.                 fi
  2257.             elif [[ $device_proc == 6 ]]; then
  2258.                 tool="litera1n"
  2259.                 if [[ $platform == "macos" ]]; then
  2260.                     tool="ipwnder32"
  2261.                     if [[ $platform_arch == "arm64" ]]; then
  2262.                         tool="ipwnder_lite"
  2263.                     fi
  2264.                 elif [[ $device_type == "iPhone5,"* ]]; then
  2265.                     tool="a6meowing"
  2266.                 fi
  2267.             elif [[ $device_proc == 7 && $platform == "macos" && $platform_arch == "arm64" ]]; then
  2268.                 tool="ipwnder_lite"
  2269.             fi
  2270.  
  2271.             if [[ $platform == "linux" ]]; then
  2272.                 log "CPU: $platform_cpu"
  2273.                 print "* Include this in your log/screenshot for pwning assistance if needed."
  2274.             fi
  2275.  
  2276.             log "Placing device to pwnDFU mode using $tool"
  2277.             print "* If pwning fails and gets stuck, you can press Ctrl+C to cancel, then re-enter DFU and retry."
  2278.             if [[ $tool == "gaster" ]]; then
  2279.                 $gaster pwn
  2280.                 tool_pwned=$?
  2281.                 log "gaster reset"
  2282.                 $gaster reset
  2283.             elif [[ $tool == "a6meowing" ]]; then
  2284.                 $a6meowing
  2285.                 tool_pwned=$?
  2286.             elif [[ $tool == "litera1n" ]]; then
  2287.                 kuroutadori_init
  2288.                 kuroutadori_litera1n -p
  2289.                 tool_pwned=$?
  2290.             elif [[ $tool == "ipwnder32" ]]; then
  2291.                 "$dir/ipwnder32" -p --noibss
  2292.                 tool_pwned=$?
  2293.             elif [[ $tool == "ipwnder_lite" ]]; then
  2294.                 mkdir -p image3 ../saved/image3
  2295.                 cp ../saved/image3/* image3/ 2>/dev/null
  2296.                 "$dir/ipwnder" -pv
  2297.                 tool_pwned=$?
  2298.                 cp image3/* ../saved/image3/ 2>/dev/null
  2299.                 log "gaster reset"
  2300.                 $gaster reset
  2301.             elif [[ $tool == "primepwn" ]]; then
  2302.                 $primepwn
  2303.                 tool_pwned=$?
  2304.             fi
  2305.             sleep 1
  2306.  
  2307.             log "Checking for device"
  2308.             irec_pwned=$($irecovery -q | grep -c "PWND")
  2309.             device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
  2310.             # irec_pwned is instances of "PWND" in serial, must be 1
  2311.             # tool_pwned is error code of pwning tool, must be 0
  2312.             if [[ $irec_pwned != 1 && $tool_pwned != 0 ]]; then
  2313.                 device_pwnerror
  2314.             fi
  2315.             if [[ -n $device_pwnd ]]; then
  2316.                 log "Found device in pwned DFU mode."
  2317.                 print "* Pwned: $device_pwnd"
  2318.                 if [[ $device_proc == 6 ]]; then
  2319.                     device_send_unpacked_ibss
  2320.                 fi
  2321.             elif [[ $device_proc == 6 ]]; then
  2322.                 device_srtg="$($irecovery -q | grep "SRTG" | cut -c 7-)"
  2323.                 if [[ $device_srtg != "iBoot"* ]]; then
  2324.                     log "Found device in pwned iBSS mode."
  2325.                 else
  2326.                     device_pwnerror
  2327.                 fi
  2328.             else
  2329.                 device_pwnerror
  2330.             fi
  2331.         ;;
  2332.     esac
  2333. }
  2334.  
  2335. device_pwnerror() {
  2336.     local error_msg=$'\n* Exit DFU mode first by holding the TOP and HOME buttons for about 10 seconds.'
  2337.     if [[ $platform == "linux" ]]; then
  2338.         [[ $platform_cpu == "AMD"* ]] && error_msg+=$'\n\n* Unfortunately, pwning may have low success rates on AMD desktop CPUs if you have one.'
  2339.         [[ $device_proc == 6 || $device_proc == 7 ]] && error_msg+=$'\n* Also, success rates for A6 and A7 checkm8 are lower on Linux.'
  2340.         error_msg+=$'\n* Pwning using an Intel PC or another Mac or iOS device may be better options if needed.'
  2341.         if [[ $device_proc == 6 && $mode != "device_justboot" && $device_target_tethered != 1 ]]; then
  2342.             error_msg+=$'\n\n* As much as possible, RESTART YOUR DEVICE IN NORMAL MODE AND USE THE JAILBREAK/KDFU METHOD INSTEAD.'
  2343.             error_msg+=$'\n* You just need to have OpenSSH (and Dropbear if on iOS 10) installed from Cydia/Zebra.'
  2344.             error_msg+=$'\n    - https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Restore-32-bit-Device'
  2345.         fi
  2346.     fi
  2347.     error_msg+=$'\n\n* For more details, read the "Troubleshooting" wiki page in GitHub'
  2348.     error_msg+=$'\n* Troubleshooting links:
  2349.    - https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Troubleshooting
  2350.    - https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Pwning-Using-Another-iOS-Device'
  2351.     [[ $platform == "linux" ]] && log "CPU: $platform_cpu"
  2352.     error "Failed to enter pwnDFU mode. Please run the script again." "$error_msg"
  2353. }
  2354.  
  2355. device_send_unpacked_ibss() {
  2356.     local pwnrec="pwned iBSS"
  2357.     local tool_pwned
  2358.     if [[ $device_boot4 == 1 ]]; then
  2359.         pwnrec="pwned recovery"
  2360.         cp iBSS.patched pwnediBSS
  2361.     else
  2362.         device_rd_build=
  2363.         patch_ibss
  2364.     fi
  2365.     if [[ $device_pwnd == *"wnder" ]]; then
  2366.         log "Sending packed iBSS..."
  2367.         $primepwn pwnediBSS.dfu
  2368.         tool_pwned=$?
  2369.     elif [[ $device_proc == 6 ]]; then
  2370.         log "gaster reset"
  2371.         $gaster reset
  2372.         sleep 1
  2373.         log "Sending iBSS..."
  2374.         $irecovery -f pwnediBSS.dfu
  2375.         tool_pwned=$?
  2376.     else
  2377.         log "Sending unpacked iBSS..."
  2378.         $primepwn pwnediBSS
  2379.         tool_pwned=$?
  2380.     fi
  2381.     rm -f pwnediBSS
  2382.     if [[ $tool_pwned != 0 ]]; then
  2383.         error "Failed to send iBSS. Your device has likely failed to enter PWNED DFU mode." \
  2384.               "* You might need to exit DFU and (re-)enter PWNED DFU mode before retrying."
  2385.     fi
  2386.     sleep 1
  2387.     log "Checking for device"
  2388.     local irec="$($irecovery -q 2>&1)"
  2389.     device_pwnd="$(echo "$irec" | grep "PWND" | cut -c 7-)"
  2390.     if [[ -z $device_pwnd && $irec != "ERROR"* ]]; then
  2391.         log "Device should now be in $pwnrec mode."
  2392.     elif [[ $device_proc == 5 ]]; then
  2393.         error "Device failed to enter $pwnrec mode." \
  2394.               "* 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."
  2395.     else
  2396.         error "Device failed to enter $pwnrec mode."
  2397.     fi
  2398. }
  2399.  
  2400. ipwndfu_init() {
  2401.     local ipwndfu_comm="6f5df8d84eaca33c2373118c68a25c72a797454f"
  2402.     local ipwndfu_sha1="04cc31dd1ed79705a51e8aba7e1e805fbf6fe1f4"
  2403.     ipwndfu="ipwndfu_python3"
  2404.     if [[ $device_sudoloop == 1 ]]; then
  2405.         psudo="$sudo"
  2406.     fi
  2407.     if [[ $platform == "macos" ]] && (( mac_majver <= 11 )); then
  2408.         ipwndfu="ipwndfu"
  2409.         ipwndfu_comm="1536e97dfbe22115693c3609d62014be62f974b6"
  2410.         ipwndfu_sha1="8202c12ad4e302ef1eda305d6479cfb541c8179c"
  2411.     fi
  2412.     if [[ ! -s ../saved/$ipwndfu/ipwndfu || $(cat ../saved/$ipwndfu/sha1check) != "$ipwndfu_sha1" ]]; then
  2413.         rm -rf ../saved/$ipwndfu
  2414.         file_download https://github.com/LukeZGD/ipwndfu/archive/$ipwndfu_comm.zip ipwndfu.zip $ipwndfu_sha1
  2415.         file_extract ipwndfu.zip
  2416.         mv ipwndfu-* ../saved/$ipwndfu
  2417.         echo "$ipwndfu_sha1" > ../saved/$ipwndfu/sha1check
  2418.     fi
  2419. }
  2420.  
  2421. kuroutadori_init() {
  2422.     local comm="https://sep.lol/files/legacypreviews/v1.0.2/a3ad4e6e525393239b3ac4ad58499f25a336b03b97cba6fba4f3a273c8505653548f2c7ad37fc18b1e69e0fddb5b73a3/kurouta_dori_v1.0.2_75aab959_legacymacosx.tar.gz"
  2423.     local sha1="61d3d964d194fd9a2084045c3cd95dc3e7920015"
  2424.     kuroutadori="kuroutadori_${platform}"
  2425.     if [[ $device_sudoloop == 1 ]]; then
  2426.         psudo="$sudo"
  2427.         [[ -n $device_ra1n_timeout ]] && psudo+=" RA1N_ABORT_TIMEOUT=$device_ra1n_timeout"
  2428.     elif [[ -n $device_ra1n_timeout ]]; then
  2429.         psudo="env RA1N_ABORT_TIMEOUT=$device_ra1n_timeout"
  2430.     fi
  2431.     if [[ $platform == "linux" ]]; then
  2432.         kuroutadori+="-${platform_arch}"
  2433.         comm="https://sep.lol/files/legacypreviews/v1.0.2/37daa814d98a38640813527be6c82ec1ee0561923b543c2290a0d519e9b2e7f7b73147a26e38d7f8a849fd70e0713125/kurouta_dori_v1.0.2_75aab959_linux-amd64.tar.gz"
  2434.         sha1="6d801a59979c64ff73015a8bfc950518dc043525"
  2435.         if [[ $platform_arch == "arm64" ]]; then
  2436.             comm="https://sep.lol/files/legacypreviews/v1.0.2/e04e9d27bcb8339e2e876ad92cc751b1e679b1ce91d2807b13ff1bc820d97349ee5ce5d1c58e61ec062e1a6b7bc2b726/kurouta_dori_v1.0.2_75aab959_linux-arm64.tar.gz"
  2437.             sha1="1dea1e3e5c7ca921ea6f6380ed0261d9c36a0165"
  2438.         fi
  2439.     fi
  2440.     if [[ ! -s ../saved/$kuroutadori/bin/litera1n || $(cat ../saved/$kuroutadori/sha1check) != "$sha1" ]]; then
  2441.         rm -rf ../saved/$kuroutadori
  2442.         file_download "$comm" kuroutadori.tar.gz $sha1
  2443.         mkdir -p ../saved/$kuroutadori
  2444.         tar -xvf kuroutadori.tar.gz -C ../saved/$kuroutadori
  2445.         echo "$sha1" > ../saved/$kuroutadori/sha1check
  2446.     fi
  2447.     kuroutadori="$psudo ../saved/$kuroutadori/bin"
  2448. }
  2449.  
  2450. kuroutadori_litera1n() {
  2451.     local tool_pwned
  2452.     print "* If pwning fails, try to rerun the script with --ra1n-timeout=1000000 (or adjust the value as needed)"
  2453.     print "* If it gets stuck at \"checkm8 setup stage\", unplug and replug the device."
  2454.     print "* If it gets stuck at \"Checkmate?\", press Ctrl+C to cancel, then re-enter DFU and retry."
  2455.     for i in {1..3}; do
  2456.         log "Running litera1n (attempt $i): $kuroutadori/litera1n $1"
  2457.         $kuroutadori/litera1n $1
  2458.         tool_pwned=$?
  2459.         [[ $tool_pwned == 0 || $tool_pwned == 30 ]] && break
  2460.     done
  2461.     return $tool_pwned
  2462. }
  2463.  
  2464. device_alloc8() {
  2465.     local tool_pwned=0
  2466.     device_enter_mode pwnDFU
  2467.     ipwndfu_init
  2468.  
  2469.     if [[ ! -s ../saved/n88ap-iBSS-4.3.5.img3 ]]; then
  2470.         local ibss_sha="eb90af5310a958e6186f32c1440002962d1f975d"
  2471.         log "Downloading iOS 4.3.5 iBSS"
  2472.         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
  2473.         mv n88ap-iBSS-4.3.5.img3 ../saved/
  2474.     fi
  2475.     cp ../saved/n88ap-iBSS-4.3.5.img3 ../saved/$ipwndfu/
  2476.  
  2477.     pushd ../saved/$ipwndfu/ >/dev/null
  2478.     log "Installing alloc8 to device"
  2479.     $psudo ./ipwndfu -x
  2480.     tool_pwned=$?
  2481.     if [[ $device_sudoloop == 1 ]]; then
  2482.         $sudo rm -rf __pycache__/ *.pyc libusbfinder/*.pyc usb/*.pyc usb/backend/*.pyc
  2483.     fi
  2484.     popd >/dev/null
  2485.  
  2486.     if [[ $tool_pwned == 0 ]]; then
  2487.         log "Done!"
  2488.     else
  2489.         warn "ipwndfu alloc8 seems to have failed. Just force restart the device, enter DFU, and try again."
  2490.         print "* You may also need to force restart the device and re-enter DFU mode before retrying."
  2491.         print "* To retry, just go back to: Useful Utilities -> Install alloc8 Exploit"
  2492.     fi
  2493. }
  2494.  
  2495. file_download() {
  2496.     # usage: file_download {link} {target location} {sha1}
  2497.     local filename="$(basename $2)"
  2498.     log "Downloading $filename..."
  2499.     download_from_url "$1" "$2"
  2500.     if [[ ! -s $2 ]]; then
  2501.         error "Downloading $2 failed. Please run the script again"
  2502.     fi
  2503.     if [[ -z $3 ]]; then
  2504.         return
  2505.     fi
  2506.     local sha1=$($sha1sum $2 | awk '{print $1}')
  2507.     if [[ $sha1 != "$3" ]]; then
  2508.         error "Verifying $filename failed. The downloaded file may be corrupted or incomplete. Please run the script again" \
  2509.               "* SHA1sum mismatch. Expected $3, got $sha1"
  2510.     fi
  2511. }
  2512.  
  2513. device_fw_key_check() {
  2514.     # check and download keys for device_target_build, then set the variable device_fw_key (or device_fw_key_base)
  2515.     local key
  2516.     local build="$device_target_build"
  2517.     case $1 in
  2518.         base ) build="$device_base_build";;
  2519.         temp ) build="$2";;
  2520.     esac
  2521.     local keys_path="$device_fw_dir/$build"
  2522.  
  2523.     # do not continue if ipados/ios 18
  2524.     if [[ $build == "22"* ]]; then
  2525.         log "iOS 18 detected, skipping firmware key check"
  2526.         return
  2527.     fi
  2528.  
  2529.     log "Checking firmware keys in $keys_path"
  2530.     if [[ $(cat "$keys_path/index.html" 2>/dev/null | grep -c "$build") != 1 ]]; then
  2531.         rm -f "$keys_path/index.html"
  2532.     fi
  2533.  
  2534.     if [[ ! -e "$keys_path/index.html" ]]; then
  2535.         mkdir -p "$keys_path"
  2536.         local try=("https://raw.githubusercontent.com/LukeZGD/Legacy-iOS-Kit-Keys/master/$device_type/$build/index.html"
  2537.                    "http://127.0.0.1:8888/firmware/$device_type/$build"
  2538.                    "https://api.m1sta.xyz/wikiproxy/$device_type/$build")
  2539.         for i in "${try[@]}"; do
  2540.             log "Getting firmware keys for $device_type-$build: $i"
  2541.             download_from_url "$i" index.html
  2542.             if [[ $(cat index.html | grep -c "$build") == 1 ]]; then
  2543.                 break
  2544.             fi
  2545.             rm -f index.html
  2546.         done
  2547.         if [[ $(cat index.html | grep -c "$build") != 1 ]]; then
  2548.             local error_msg="* You may need to run wikiproxy to get firmware keys."
  2549.             error_msg+=$'\n* For more details, go to the "Troubleshooting" wiki page in GitHub.'
  2550.             error_msg+=$'\n* Troubleshooting link: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Troubleshooting#running-wikiproxy'
  2551.             error "Failed to download firmware keys." "$error_msg"
  2552.         fi
  2553.         mv index.html "$keys_path/"
  2554.     fi
  2555.  
  2556.     if [[ $1 == "base" ]]; then
  2557.         device_fw_key_base="$(cat $keys_path/index.html)"
  2558.     elif [[ $1 == "temp" ]]; then
  2559.         device_fw_key_temp="$(cat $keys_path/index.html)"
  2560.     else
  2561.         device_fw_key="$(cat $keys_path/index.html)"
  2562.     fi
  2563. }
  2564.  
  2565. ipsw_get_url() {
  2566.     local build_id="$1"
  2567.     local device_type="$device_type"
  2568.     local device_fw_dir="$device_fw_dir"
  2569.     if [[ -n $2 ]]; then
  2570.         device_type="$2"
  2571.         device_fw_dir="../saved/firmware/$device_type"
  2572.     fi
  2573.     local version="$3"
  2574.     local url="$(cat "$device_fw_dir/$build_id/url" 2>/dev/null)"
  2575.     local url_local="$url"
  2576.     local ipg_url
  2577.     ipsw_url=
  2578.     log "Checking URL in $device_fw_dir/$build_id/url"
  2579.     if [[ $(echo "$url" | grep -c '<') != 0 || $url != *"$build_id"* ]]; then
  2580.         rm -f "$device_fw_dir/$build_id/url"
  2581.         url=
  2582.     fi
  2583.     case $device_type in
  2584.         iPod1,1 ) [[ $build_id == "5"* || $build_id == "7"* ]] && ipg_url=1;;
  2585.         iPod2,1 ) [[ $build_id == "7"* ]] && ipg_url=1;;
  2586.     esac
  2587.     if [[ $ipg_url == 1 ]]; then
  2588.         if [[ -z $version ]]; then
  2589.             download_appledb ios $build_id
  2590.             version="$(cat tmp.json | $jq -r ".version")"
  2591.         fi
  2592.         url="https://invoxiplaygames.uk/ipsw/${device_type}_${version}_${build_id}_Restore.ipsw"
  2593.     fi
  2594.     if [[ -z $url ]]; then
  2595.         log "Getting URL for $device_type-$build_id"
  2596.         download_appledb ios $build_id
  2597.         url="$(cat tmp.json | $jq -r ".sources[] | select(.type == \"ipsw\" and any(.deviceMap[]; . == \"$device_type\")) | .links[0].url")"
  2598.        local url2="$(echo "$url" | tr '[:upper:]' '[:lower:]')"
  2599.        local build_id2="$(echo "$build_id" | tr '[:upper:]' '[:lower:]')"
  2600.        if [[ $(echo "$url" | grep -c '<') != 0 || $url2 != *"$build_id2"* ]]; then
  2601.            if [[ -n $url_local ]]; then
  2602.                url="$url_local"
  2603.                log "Using saved URL for this IPSW: $url"
  2604.                echo "$url" > $device_fw_dir/$build_id/url
  2605.                ipsw_url="$url"
  2606.                return
  2607.            fi
  2608.            if [[ $ipsw_isbeta != 1 ]]; then
  2609.                error "Unable to get URL for $device_type-$build_id"
  2610.            fi
  2611.        fi
  2612.        mkdir -p $device_fw_dir/$build_id
  2613.        echo "$url" > $device_fw_dir/$build_id/url
  2614.    fi
  2615.    ipsw_url="$url"
  2616. }
  2617.  
  2618. download_appledb() {
  2619.    local query="$1"
  2620.    if [[ $query == "ios" ]]; then
  2621.        local phone="iOS" # iOS
  2622.        local build_id="$2"
  2623.        case $build_id in
  2624.            [23][0123456789]* | 7B405 | 7B500 ) :;;
  2625.            1[AC]* | [2345]* ) phone="iPhone%20Software";; # iPhone Software
  2626.            7* ) phone="iPhone%20OS";; # iPhone OS
  2627.        esac
  2628.        if [[ $device_type == "iPad"* ]]; then
  2629.            case $build_id in
  2630.                1[789]* | [23]* ) phone="iPadOS";; # iPadOS
  2631.            esac
  2632.        fi
  2633.        query="ios/${phone};${build_id}"
  2634.    fi
  2635.  
  2636.    local try=("https://api.appledb.dev/${query}.json"
  2637.               "https://raw.githubusercontent.com/littlebyteorg/appledb/gh-pages/${query}.json")
  2638.    for request in "${try[@]}"; do
  2639.        log "AppleDB request: $request"
  2640.        download_from_url "$request" tmp.json
  2641.        [[ -s tmp.json ]] && break
  2642.    done
  2643.    if [[ ! -s tmp.json ]]; then
  2644.        error "Failed to get AppleDB request. Please run the script again"
  2645.    fi
  2646. }
  2647.  
  2648. download_comp() {
  2649.    # usage: download_comp [build_id] [comp]
  2650.    local build_id="$1"
  2651.    local comp="$2"
  2652.    ipsw_get_url $build_id
  2653.    download_targetfile="$comp.$device_model"
  2654.    if [[ $build_id != "12"* ]]; then
  2655.        download_targetfile+="ap"
  2656.    fi
  2657.    download_targetfile+=".RELEASE"
  2658.  
  2659.    if [[ -e "../saved/$device_type/${comp}_$build_id.dfu" ]]; then
  2660.        cp "../saved/$device_type/${comp}_$build_id.dfu" ${comp}
  2661.    else
  2662.        log "Downloading ${comp}..."
  2663.        "$dir/pzb" -g "Firmware/dfu/$download_targetfile.dfu" -o ${comp} "$ipsw_url"
  2664.        cp ${comp} "../saved/$device_type/${comp}_$build_id.dfu"
  2665.    fi
  2666. }
  2667.  
  2668. patch_ibss() {
  2669.    # creates file pwnediBSS to be sent to device
  2670.    local build_id
  2671.    case $device_type in
  2672.        iPad1,1 | iPod3,1 ) build_id="9B206";;
  2673.        iPhone2,1 | iPod4,1 ) build_id="10B500";;
  2674.        iPhone3,[123] ) build_id="11D257";;
  2675.        * ) build_id="12H321";;
  2676.    esac
  2677.    if [[ -n $device_rd_build ]]; then
  2678.        build_id="$device_rd_build"
  2679.    fi
  2680.    download_comp $build_id iBSS
  2681.    device_fw_key_check temp $build_id
  2682.    local iv=$(echo $device_fw_key_temp | $jq -j '.keys[] | select(.image == "iBSS") | .iv')
  2683.    local key=$(echo $device_fw_key_temp | $jq -j '.keys[] | select(.image == "iBSS") | .key')
  2684.    log "Decrypting iBSS..."
  2685.    "$dir/xpwntool" iBSS iBSS.dec -iv $iv -k $key
  2686.    log "Patching iBSS..."
  2687.    "$dir/iBoot32Patcher" iBSS.dec pwnediBSS --rsa
  2688.    "$dir/xpwntool" pwnediBSS pwnediBSS.dfu -t iBSS
  2689.    cp pwnediBSS pwnediBSS.dfu ../saved/$device_type/
  2690.    log "Pwned iBSS saved at: saved/$device_type/pwnediBSS"
  2691.    log "Pwned iBSS img3 saved at: saved/$device_type/pwnediBSS.dfu"
  2692. }
  2693.  
  2694. patch_ibec() {
  2695.    # creates file pwnediBEC to be sent to device for blob dumping
  2696.    local build_id
  2697.    case $device_type in
  2698.        iPad1,1 | iPod3,1 )
  2699.            build_id="9B206";;
  2700.        iPhone2,1 | iPhone3,[123] | iPod4,1 | iPad3,1 )
  2701.            build_id="10A403";;
  2702.        iPad2,[367] | iPad3,[25] )
  2703.            build_id="12H321";;
  2704.        iPhone5,3 )
  2705.            build_id="11B511";;
  2706.        iPhone5,4 )
  2707.            build_id="11B651";;
  2708.        * )
  2709.            build_id="10B329";;
  2710.    esac
  2711.    if [[ -n $device_rd_build ]]; then
  2712.        build_id="$device_rd_build"
  2713.    fi
  2714.    download_comp $build_id iBEC
  2715.    device_fw_key_check temp $build_id
  2716.    local name="iBEC"
  2717.    local iv=$(echo $device_fw_key_temp | $jq -j '.keys[] | select(.image == "iBEC") | .iv')
  2718.    local key=$(echo $device_fw_key_temp | $jq -j '.keys[] | select(.image == "iBEC") | .key')
  2719.    local address="0x80000000"
  2720.    if [[ $device_proc == 4 ]]; then
  2721.        address="0x40000000"
  2722.    fi
  2723.    mv iBEC $name.orig
  2724.    log "Decrypting iBEC..."
  2725.    "$dir/xpwntool" $name.orig $name.dec -iv $iv -k $key
  2726.    log "Patching iBEC..."
  2727.    if [[ $device_proc == 4 || -n $device_rd_build || $device_type == "iPad3,1" ]]; then
  2728.        "$dir/iBoot32Patcher" $name.dec $name.patched --rsa --ticket -b "rd=md0 -v amfi=0xff cs_enforcement_disable=1" -c "go" $address
  2729.    else
  2730.        $bspatch $name.dec $name.patched "../resources/patch/odysseus/$download_targetfile.patch"
  2731.    fi
  2732.    "$dir/xpwntool" $name.patched pwnediBEC.dfu -t $name.orig
  2733.    rm $name.dec $name.orig $name.patched
  2734.    cp pwnediBEC.dfu ../saved/$device_type/
  2735.    log "Pwned iBEC img3 saved at: saved/$device_type/pwnediBEC.dfu"
  2736. }
  2737.  
  2738. ipsw_nojailbreak_message() {
  2739.    local hac
  2740.    local tohac
  2741.    case $device_type in
  2742.        iPhone[23],1 ) hac=" (and hacktivate)"; tohac=1;;
  2743.    esac
  2744.    log "Jailbreak option is not available for this version. You may jailbreak$hac later after the restore"
  2745.    print "* To jailbreak after the restore, select \"Jailbreak Device\" in the main menu"
  2746.    if [[ $tohac == 1 ]]; then
  2747.        print "* To hacktivate, go to \"Useful Utilities -> Hacktivate Device\" after jailbreaking"
  2748.    fi
  2749.    echo
  2750. }
  2751.  
  2752. ipsw_preference_set() {
  2753.    # sets ipsw variables: ipsw_jailbreak, ipsw_memory, ipsw_verbose
  2754.    case $device_latest_vers in
  2755.        [76543]* ) ipsw_canjailbreak=1;;
  2756.    esac
  2757.    if [[ $device_target_vers == "$device_latest_vers" && $device_deadbb == 1 ]]; then
  2758.        ipsw_gasgauge_patch=1
  2759.    fi
  2760.    if [[ $device_target_tethered == 1 && $ipsw_gasgauge_patch == 1 &&
  2761.          $device_proc == 6 && $target_vers_maj == 10 ]]; then
  2762.        warn "multipatch is not supported on A6(X) tethered iOS 10, so it will be disabled."
  2763.        ipsw_gasgauge_patch=
  2764.    fi
  2765.    if (( device_proc >= 7 )) || [[ $device_target_vers == "$device_latest_vers" && $ipsw_canjailbreak != 1 && $ipsw_gasgauge_patch != 1 ]]; then
  2766.        return
  2767.    fi
  2768.  
  2769.    # jailbreak option: available for versions 3.1.3 to 9.3.4, with some exceptions:
  2770.    # 3.1-4.1: option is disabled due to an issue with putting .launchd_use_gmalloc in the correct partition.
  2771.    # it should be in system, but restore puts it in data instead due to it being in var.
  2772.    # for some reason though, it does it correctly on 4.x for 3gs and touch 2, so its enabled for those.
  2773.    # it also does it correctly on 3.1.3-4.x for s5l8900 devices, so its also enabled there.
  2774.    # for 3.x 3gs, and old br 3.1.3 touch 2, kernel is patched so its also supposed to be enabled for those
  2775.    # but since there is an issue with ios 3 asr when fs is modified, they are disabled for now
  2776.    # update: should be fixed after updating xpwn ipsw, will revert if reports say otherwise or if other issues pop up
  2777.    ipsw_canjailbreak=
  2778.    case $device_target_vers in
  2779.        9.3.[4321] | 9.3 | 9.[210]* | [876543].* ) ipsw_canjailbreak=1;;
  2780.    esac
  2781.    if [[ $device_target_powder == 1 ]]; then
  2782.        case $device_target_vers in
  2783.        4.[10]* )
  2784.            ipsw_canjailbreak=
  2785.            ipsw_nojailbreak_message
  2786.        ;;
  2787.        esac
  2788.    elif [[ $device_type == "iPod2,1" && $ipsw_24o != 1 ]]; then
  2789.        case $device_target_vers in
  2790.        3.1* )
  2791.            ipsw_canjailbreak=
  2792.            ipsw_nojailbreak_message
  2793.        ;;
  2794.        esac
  2795.    fi
  2796.  
  2797.    # ipsw_nskip being 1 means that it will always create/use a custom ipsw.
  2798.    # useful for disabling baseband update, or in the case of macos arm64, not having to use futurerestore for 32-bit.
  2799.    case $device_type in
  2800.        iPad[23],[23] | "$device_disable_bbupdate" ) ipsw_nskip=1;;
  2801.    esac
  2802.    if [[ $ipsw_gasgauge_patch != 1 && $ipsw_jailbreak != 1 && $device_target_vers == "$device_latest_vers" ]]; then
  2803.        ipsw_nskip=
  2804.    elif [[ $ipsw_gasgauge_patch == 1 ]] || [[ $platform == "macos" && $platform_arch == "arm64" ]] ||
  2805.         [[ $device_proc == 5 && $target_vers_maj == 4 ]]; then
  2806.        ipsw_nskip=1
  2807.    fi
  2808.  
  2809.    # make jailbreak option enabled for all of 8.x-9.x if the restore is a powdersn0w one.
  2810.    # also, exit this function if ipsw_canjailbreak is not set to 1 and/or other options will not be used.
  2811.    local jbpowder
  2812.    if [[ $device_target_powder == 1 ]]; then
  2813.        case $device_target_vers in
  2814.            [98]* )
  2815.                ipsw_canjailbreak=1
  2816.                ipsw_jailbreak=1
  2817.                jbpowder=1
  2818.                log "iOS 8.x-9.x powdersn0w detected. Enabling jailbreak option"
  2819.            ;;
  2820.        esac
  2821.    elif [[ $device_target_other == 1 && $ipsw_canjailbreak != 1 && $ipsw_nskip != 1 ]]; then
  2822.        return
  2823.    fi
  2824.  
  2825.    # detect certain ios betas now. for ios 8, disable betas 1 and 2 since powdersn0w cant patch the kernels for those.
  2826.    # for betas below ios 6, disable the jailbreak option, its not supported since (currently) no patchfinders used there and stuff.
  2827.    if [[ $ipsw_isbeta == 1 ]]; then
  2828.        case $device_target_vers in
  2829.            8* )
  2830.                if [[ $device_target_build == "12A4265u" || $device_target_build == "12A4297e" ]]; then
  2831.                    warn "iOS 8 beta 1-2 detected. Disabling jailbreak option"
  2832.                    ipsw_canjailbreak=
  2833.                    ipsw_jailbreak=
  2834.                fi
  2835.            ;;
  2836.            9.[123]* | [76]* ) :;;
  2837.            * )
  2838.                warn "iOS beta detected. Disabling jailbreak option"
  2839.                ipsw_canjailbreak=
  2840.                ipsw_jailbreak=
  2841.            ;;
  2842.        esac
  2843.        if [[ $ipsw_canjailbreak == 1 ]]; then
  2844.            warn "iOS beta detected. Jailbreak option might not work properly"
  2845.        fi
  2846.    fi
  2847.  
  2848.    if [[ $ipsw_fourthree == 1 ]]; then
  2849.        ipsw_jailbreak=1
  2850.    elif [[ $ipsw_jailbreak == 1 && $jbpowder != 1 ]]; then
  2851.        warn "Jailbreak flag detected, jailbreak option enabled by user."
  2852.    elif [[ $ipsw_canjailbreak == 1 && -z $ipsw_jailbreak ]]; then
  2853.        input "Jailbreak Option"
  2854.        print "* When this option is enabled, your device will be jailbroken on restore."
  2855.        print "* I recommend to enable this option to have the jailbreak and Cydia pre-installed."
  2856.        print "* This option is enabled by default (Y). Select this option if unsure."
  2857.        if [[ $device_type == "iPad2"* && $device_target_vers == "4.3"* && $device_target_tethered != 1 ]]; then
  2858.            warn "This will be a semi-tethered jailbreak. checkm8-a5 is required to boot to a jailbroken state."
  2859.            print "* To boot jailbroken later, go to: Main Menu -> Just Boot"
  2860.        elif [[ $device_type == "iPhone3,3" ]]; then
  2861.            case $device_target_vers in
  2862.                4.2.9 | 4.2.10 )
  2863.                    warn "This will be a semi-tethered jailbreak."
  2864.                    print "* To boot jailbroken later, go to: Main Menu -> Just Boot"
  2865.                ;;
  2866.            esac
  2867.        fi
  2868.        select_yesno "Enable this option?" 1
  2869.        if [[ $? != 1 ]]; then
  2870.            ipsw_jailbreak=
  2871.            log "Jailbreak option disabled by user."
  2872.        else
  2873.            ipsw_jailbreak=1
  2874.            log "Jailbreak option enabled."
  2875.        fi
  2876.        echo
  2877.    fi
  2878.  
  2879.    if [[ $ipsw_jailbreak == 1 && -z $ipsw_hacktivate && $ipsw_canhacktivate == 1 ]]; then
  2880.        input "Hacktivate Option"
  2881.        print "* When this option is enabled, your device will be activated on restore."
  2882.        print "* Enable this option if you have no valid SIM card to activate the phone."
  2883.        print "* Disable this option if you have a working SIM card and want cellular data."
  2884.        print "* This option is disabled by default (N). Select this option if unsure."
  2885.        select_yesno "Enable this option?" 0
  2886.        if [[ $? != 0 ]]; then
  2887.            log "Hacktivate option enabled by user."
  2888.            ipsw_hacktivate=1
  2889.        else
  2890.            log "Hacktivate option disabled."
  2891.            ipsw_hacktivate=
  2892.        fi
  2893.        echo
  2894.    fi
  2895.  
  2896.    case $device_type in
  2897.        iPhone2,1 | iPod2,1 ) ipsw_canmemory=1;;
  2898.        iPad[23],[23] ) ipsw_canmemory=1;;
  2899.        iPhone3,1 | iPad1,1 | iPad2* | iPod[34],1 )
  2900.            case $device_target_vers in
  2901.                [34]* ) ipsw_canmemory=1;;
  2902.            esac
  2903.        ;;
  2904.    esac
  2905.  
  2906.    if [[ $device_proc == 1 && $device_type != "iPhone1,2" ]]; then
  2907.        ipsw_canmemory=
  2908.    elif [[ -n $device_type_special ]]; then
  2909.        ipsw_canmemory=
  2910.    elif [[ $device_proc == 6 && $target_vers_maj == 10 ]]; then
  2911.        ipsw_canmemory=
  2912.    elif [[ $device_target_powder == 1 || $device_target_tethered == 1 ||
  2913.          $ipsw_jailbreak == 1 || $ipsw_gasgauge_patch == 1 || $ipsw_nskip == 1 ||
  2914.          $device_type == "$device_disable_bbupdate" || $device_actrec == 1 ]]; then
  2915.        ipsw_canmemory=1
  2916.    fi
  2917.  
  2918.    if [[ $ipsw_canmemory == 1 && -z $ipsw_memory ]]; then
  2919.        input "Memory Option for creating custom IPSW"
  2920.        print "* When this option is enabled, system RAM will be used for the IPSW creation process."
  2921.        print "* I recommend to enable this option to speed up creating the custom IPSW."
  2922.        print "* However, if your PC/Mac has less than 8 GB of RAM, disable this option."
  2923.        print "* This option is enabled by default (Y). Select this option if unsure."
  2924.        select_yesno "Enable this option?" 1
  2925.        if [[ $? != 1 ]]; then
  2926.            log "Memory option disabled by user."
  2927.            ipsw_memory=
  2928.        else
  2929.            log "Memory option enabled."
  2930.            ipsw_memory=1
  2931.        fi
  2932.        echo
  2933.    fi
  2934.  
  2935.    if [[ $device_target_powder == 1 ]]; then
  2936.        ipsw_canverbose=1
  2937.    elif [[ $device_type == "iPhone2,1" && $device_target_other != 1 ]]; then
  2938.        case $device_target_vers in
  2939.            6.1.6 | 4.1 ) log "3GS verbose boot is not supported on 6.1.6 and 4.1";;
  2940.            3.0*        ) log "3GS verbose boot is always enabled on 3.0.x";;
  2941.            * ) ipsw_canverbose=1;;
  2942.        esac
  2943.    fi
  2944.  
  2945.    if [[ $ipsw_canverbose == 1 && -z $ipsw_verbose ]]; then
  2946.        input "Verbose Boot Option"
  2947.        print "* When this option is enabled, the device will have verbose boot on restore."
  2948.        print "* This option is enabled by default (Y). Select this option if unsure."
  2949.        select_yesno "Enable this option?" 1
  2950.        if [[ $? != 1 ]]; then
  2951.            ipsw_verbose=
  2952.            log "Verbose boot option disabled by user."
  2953.        else
  2954.            ipsw_verbose=1
  2955.            log "Verbose boot option enabled."
  2956.        fi
  2957.        echo
  2958.    fi
  2959.  
  2960.    ipsw_custom_set
  2961. }
  2962.  
  2963. shsh_save() {
  2964.    # usage: shsh_save {apnonce (optional)}
  2965.    # sets variable shsh_path
  2966.    local version=$device_target_vers
  2967.    local build_id=$device_target_build
  2968.    local apnonce
  2969.    local shsh_check
  2970.    local buildmanifest="../resources/manifest/BuildManifest_${device_type}_${version}.plist"
  2971.    local ExtraArgs=
  2972.  
  2973.    if [[ $1 == "apnonce" ]]; then
  2974.        apnonce=$2
  2975.    elif [[ $1 == "version" ]]; then
  2976.        version=$2
  2977.    fi
  2978.  
  2979.    if [[ $version == "$device_latest_vers" || $version == "4.1" ]]; then
  2980.        if [[ $version != "4.1" ]]; then
  2981.            build_id="$device_latest_build"
  2982.        fi
  2983.        buildmanifest="../saved/$device_type/$build_id.plist"
  2984.        if [[ ! -e $buildmanifest ]]; then
  2985.            if [[ -e "$ipsw_base_path.ipsw" ]]; then
  2986.                log "Extracting BuildManifest from $version IPSW..."
  2987.                file_extract_from_archive "$ipsw_base_path.ipsw" BuildManifest.plist
  2988.            else
  2989.                ipsw_get_url $build_id
  2990.                log "Downloading BuildManifest for $version..."
  2991.                "$dir/pzb" -g BuildManifest.plist -o BuildManifest.plist "$ipsw_url"
  2992.            fi
  2993.            mv BuildManifest.plist $buildmanifest
  2994.        fi
  2995.    fi
  2996.    shsh_check=${device_ecid}_${device_type}_${device_model}ap_${version}-${build_id}_${apnonce}*.shsh*
  2997.  
  2998.    if [[ $(ls ../saved/shsh/$shsh_check 2>/dev/null) && -z $apnonce ]]; then
  2999.        shsh_path="$(ls ../saved/shsh/$shsh_check)"
  3000.        log "Found existing saved $version blobs: $shsh_path"
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • Adzakga
    20 days
    # CSS 0.44 KB | 0 0
    1. Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment