v1ral_ITS

Legacy IOS Part3

Jun 10th, 2026
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 125.05 KB | None | 0 0
  1.         if (( target_vers_maj >= 16 )) || [[ $restore_usedev == 1 || $device_type == "iPhone10,"* ]]; then
  2.             fr_latest="c473a1748559b4673e0c43fa73cfa4421857be12"
  3.             fr_branch="dev"
  4.         fi
  5.         local fr_current="$(cat ${futurerestore2}-${fr_branch}_version 2>/dev/null)"
  6.         log "futurerestore $fr_branch branch will be used for this restore"
  7.         if [[ $fr_latest != "$fr_current" ]]; then
  8.             log "futurerestore nightly update detected, downloading."
  9.             rm -f ${futurerestore2}-${fr_branch}*
  10.         fi
  11.         if [[ ! -e ${futurerestore2}-${fr_branch} ]]; then
  12.             local url="https://github.com/LukeeGD/futurerestore/releases/download/latest/"
  13.             local file="futurerestore-"
  14.             case $platform in
  15.                 "macos" ) file+="macOS-RELEASE-${fr_branch}.zip";;
  16.                 "linux" ) file+="Linux-x86_64-RELEASE-${fr_branch}.zip";;
  17.             esac
  18.             url+="$file"
  19.             file_download $url $file
  20.             file_extract "$file"
  21.             tar -xJvf futurerestore*.xz
  22.             mv futurerestore ${futurerestore2}-${fr_branch}
  23.             chmod +x ${futurerestore2}-${fr_branch}
  24.             [[ $platform == "macos" ]] && /usr/bin/xattr -cr ${futurerestore2}-${fr_branch}
  25.             echo "$fr_latest" > ${futurerestore2}-${fr_branch}_version
  26.         fi
  27.         futurerestore2+="-${fr_branch}"
  28.     fi
  29.     # custom arg(s), either --use-pwndfu or --skip-blob, or both
  30.     for arg in "$@"; do
  31.         if [[ $device_proc == 7 && $device_target_other != 1 && $device_target_vers == "10.3.3" &&
  32.               $restore_usepwndfu64 != 1 && $arg == "--skip-blob" &&
  33.               $FUTURERESTORE_I_SOLEMNLY_SWEAR_THAT_I_AM_UP_TO_NO_GOOD == 1 ]]; then
  34.             arg+="2" # --skip-blob2
  35.         fi
  36.         [[ -n "$arg" ]] && ExtraArr+=("$arg")
  37.     done
  38.     if [[ $debug_mode == 1 ]]; then
  39.         ExtraArr+=("-d")
  40.     fi
  41.     ExtraArr+=("-t" "$shsh_path" "$ipsw_path.ipsw")
  42.     ipsw_extract
  43.  
  44.     log "Running futurerestore with command: $futurerestore2 ${ExtraArr[*]}"
  45.     $futurerestore2 "${ExtraArr[@]}"
  46.     opt=$?
  47.     log "Restoring done! Read the message below if any error has occurred:"
  48.     print "* For device activation, go to: Main Menu -> Attempt Activation"
  49.     if [[ $platform == "macos" && $platform_arch == "arm64" ]]; then
  50.         print "* Make sure that you are using a USB dock or hub to connect your device. Do not use USB dongles."
  51.         echo
  52.     fi
  53.     if [[ $opt != 0 ]] && (( device_proc < 7 )); then
  54.         print "* If you are getting the error: \"could not retrieve device serial number\","
  55.         print " -> Try restoring with the jailbreak option enabled"
  56.     fi
  57.     print "* Please read the \"Troubleshooting\" wiki page in GitHub before opening any issue!"
  58.     print "* Your problem may have already been addressed within the wiki page."
  59.     print "* If opening an issue in GitHub, please provide a FULL log/output. Otherwise, your issue may be dismissed."
  60.     kill $httpserver_pid 2>/dev/null
  61. }
  62.  
  63. restore_latest() {
  64.     local idevicerestore2="$idevicerestore"
  65.     local ExtraArgs="-e"
  66.     local noextract
  67.     local newidr
  68.  
  69.     # remove erase arg if update
  70.     [[ $1 == "update" ]] && ExtraArgs=
  71.  
  72.     # use newer idr for newer ios
  73.     local major=$(echo "$device_latest_vers" | cut -d. -f1)
  74.     if (( major >= 12 )); then
  75.         newidr=1
  76.     fi
  77.     if [[ $newidr == 1 ]]; then
  78.         idevicerestore2+="2"
  79.         ExtraArgs+=" -y"
  80.         noextract=1
  81.     fi
  82.  
  83.     if [[ $1 == "custom" ]]; then
  84.         ExtraArgs+=" -c"
  85.         ipsw_path="$ipsw_custom"
  86.         ipsw_extract custom
  87.     else
  88.         device_enter_mode Recovery
  89.         [[ $noextract != 1 ]] && ipsw_extract
  90.     fi
  91.     if [[ $device_type == "iPhone1,2" && $device_target_vers == "4"* ]]; then
  92.         if [[ $1 == "custom" ]]; then
  93.             log "Sending s5l8900xall..."
  94.             $irecovery -f "$ipsw_custom/Firmware/dfu/WTF.s5l8900xall.RELEASE.dfu"
  95.             device_find_mode DFUreal
  96.             log "Sending iBSS..."
  97.             $irecovery -f "$ipsw_custom/Firmware/dfu/iBSS.${device_model}ap.RELEASE.dfu"
  98.             device_find_mode Recovery
  99.         fi
  100.     elif [[ $device_proc == 1 && $device_target_vers == "3.1.3" && $mode == "customipsw" ]]; then
  101.         log "Sending iBSS..."
  102.         $irecovery -f "$ipsw_custom/Firmware/dfu/iBSS.${device_model}ap.RELEASE.dfu"
  103.         device_find_mode Recovery
  104.     fi
  105.     if [[ $debug_mode == 1 ]]; then
  106.         ExtraArgs+=" -d"
  107.     fi
  108.     log "Running idevicerestore with command: $idevicerestore2 $ExtraArgs \"$ipsw_path.ipsw\""
  109.     $idevicerestore2 $ExtraArgs "$ipsw_path.ipsw"
  110.     local opt=$?
  111.     if [[ $platform == "macos" && $platform_arch == "arm64" ]]; then
  112.         print "* Make sure that you are using a USB dock or hub to connect your device. Do not use USB dongles."
  113.         echo
  114.     fi
  115.     if [[ $2 == "first" ]]; then
  116.         return $opt
  117.     fi
  118.     if [[ $1 == "custom" ]]; then
  119.         log "Restoring done! Read the message below if any error has occurred:"
  120.         print "* Please read the \"Troubleshooting\" wiki page in GitHub before opening any issue!"
  121.         print "* Your problem may have already been addressed within the wiki page."
  122.         print "* If opening an issue in GitHub, please provide a FULL log/output. Otherwise, your issue may be dismissed."
  123.     fi
  124.     print "* For device activation, go to: Main Menu -> Attempt Activation"
  125. }
  126.  
  127. restore_prepare_pwnrec64() {
  128.     local attempt=1
  129.     if [[ $device_pwnrec == 1 ]]; then
  130.         warn "Pwned recovery flag detected, skipping pwned recovery mode procedure. Proceed with caution"
  131.         return
  132.     fi
  133.  
  134.     device_enter_mode pwnDFU
  135.     sleep 1
  136.     while (( attempt <= 5 )); do
  137.         log "Entering pwned recovery mode... (Attempt $attempt of 5)"
  138.         log "Sending iBSS..."
  139.         $irecovery -f $iBSS.im4p
  140.         sleep 1
  141.         log "Sending iBEC..."
  142.         $irecovery -f $iBEC.im4p
  143.         sleep 3
  144.         device_find_mode Recovery 1
  145.         if [[ $? == 0 ]]; then
  146.             break
  147.         fi
  148.         print "* You may also try to unplug and replug your device"
  149.         ((attempt++))
  150.     done
  151.     if [[ $device_proc == 10 ]]; then
  152.         log "irecovery -c go"
  153.         $irecovery -c "go"
  154.         sleep 3
  155.     fi
  156.  
  157.     if (( attempt > 5 )); then
  158.         error "Failed to enter pwned recovery mode. You might have to force restart your device and start over entering pwnDFU mode again"
  159.     fi
  160. }
  161.  
  162. device_buttons() {
  163.     local selection=("kDFU" "pwnDFU")
  164.     if [[ $device_jailbrokenselected == 1 ]]; then
  165.         device_enter_mode kDFU
  166.         return
  167.     elif [[ $device_mode != "Normal" ]]; then
  168.         device_enter_mode pwnDFU
  169.         return
  170.     fi
  171.     input "pwnDFU/kDFU Mode Option"
  172.     print "* This device needs to be in pwnDFU/kDFU mode before proceeding."
  173.     if [[ $device_proc == 5 ]]; then
  174.         print "* Selecting kDFU is recommended. Your device must be jailbroken and have OpenSSH installed for this option."
  175.         print "* Selecting pwnDFU is only for those that have the option to use checkm8-a5 (needs Arduino+USB Host Shield or Pi Pico)."
  176.         warn "Selecting pwnDFU will require usage of checkm8-a5. For more info, go here: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/checkm8-a5"
  177.     elif [[ $device_proc == 6 && $platform != "macos" ]] || [[ $platform_cpu == "AMD"* ]]; then
  178.         print "* Selecting kDFU is recommended. Your device must be jailbroken and have OpenSSH installed for this option."
  179.         print "* Selecting pwnDFU is only for those that do not want to/cannot jailbreak their device."
  180.         [[ $device_proc == 6 ]] && warn "Selecting pwnDFU will use checkm8 which has lower success rates on Linux for A6 devices."
  181.         if [[ $platform_cpu == "AMD"* ]]; then
  182.             case $device_type in
  183.                 iPhone3,* | iPad1,1 | iPod4,1 ) :;;
  184.                 * ) warn "Selecting pwnDFU will use checkm8 which has low success rates on AMD desktop CPUs if you have one.";;
  185.             esac
  186.         fi
  187.     else
  188.         selection=("pwnDFU" "kDFU")
  189.         print "* Selecting pwnDFU is recommended. Both your home and power buttons must be working properly for entering DFU mode."
  190.         print "* Selecting kDFU is for those that prefer the jailbroken method instead (have OpenSSH installed)."
  191.     fi
  192.     input "Select your option:"
  193.     local opt2
  194.     select_option "${selection[@]}"
  195.     opt2="${selection[$?]}"
  196.     if [[ $opt2 == *"DFU" ]]; then
  197.         device_enter_mode $opt2
  198.     fi
  199. }
  200.  
  201. device_buttons2() {
  202.     local selection=("Jailbroken" "pwnDFU")
  203.     if [[ $device_mode != "Normal" ]]; then
  204.         device_enter_mode pwnDFU
  205.         return
  206.     elif [[ $device_jailbrokenselected == 1 ]]; then
  207.         return
  208.     fi
  209.     input "Jailbroken/pwnDFU Mode Option"
  210.     print "* This device needs to be jailbroken/in pwnDFU mode before proceeding."
  211.     print "* Selecting Jailbroken is recommended. Your device must be jailbroken and have OpenSSH installed for this option."
  212.     print "* Selecting pwnDFU is for those that prefer the ramdisk method instead."
  213.     if [[ $device_proc == 5 ]]; then
  214.         warn "Selecting pwnDFU will require usage of checkm8-a5."
  215.         print "* For more info about checkm8-a5, go here: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/checkm8-a5"
  216.     fi
  217.     input "Select your option:"
  218.     local opt2
  219.     select_option "${selection[@]}"
  220.     opt2="${selection[$?]}"
  221.     case $opt2 in
  222.         "Jailbroken" ) device_jailbrokenselected=1;;
  223.         "pwnDFU"     ) device_enter_mode pwnDFU;;
  224.     esac
  225. }
  226.  
  227. restore_deviceprepare() {
  228.     if [[ $device_type == "$device_disable_bbupdate" && $device_deadbb != 1 ]]; then
  229.         device_dump baseband
  230.     fi
  231.     if [[ $device_actrec == 1 ]]; then
  232.         device_dump activation
  233.     fi
  234.     if [[ $mode == "custom-ipsw" ]]; then
  235.         return
  236.     fi
  237.     case $device_proc in
  238.         1 )
  239.             if [[ $device_target_vers == "4"* && $ipsw_jailbreak == 1 ]]; then
  240.                 device_enter_mode WTFreal
  241.             elif [[ $ipsw_jailbreak == 1 ]]; then
  242.                 device_enter_mode DFU
  243.             fi
  244.         ;;
  245.  
  246.         4 )
  247.             if [[ -n $device_type_special ]]; then
  248.                 shsh_save version $device_latest_vers
  249.                 device_buttons
  250.             elif [[ $device_target_tethered == 1 ]]; then
  251.                 shsh_save version $device_latest_vers
  252.                 device_enter_mode pwnDFU
  253.             elif [[ $device_target_vers == "$device_latest_vers" ]]; then
  254.                 if [[ $ipsw_jailbreak == 1 || $ipsw_gasgauge_patch == 1 ]]; then
  255.                     shsh_save version $device_latest_vers
  256.                     device_buttons
  257.                 fi
  258.             elif [[ $device_target_vers == "4.1" ]]; then
  259.                 case $device_type in
  260.                     iPhone2,1 | iPod[23],1 )
  261.                         shsh_save version 4.1
  262.                         if [[ $ipsw_jailbreak == 1 ]]; then
  263.                             device_enter_mode pwnDFU
  264.                         else
  265.                             device_enter_mode DFU
  266.                         fi
  267.                     ;;
  268.                     * ) device_enter_mode pwnDFU;;
  269.                 esac
  270.             else
  271.                 if [[ $device_target_powder == 1 ]]; then
  272.                     shsh_save version $device_latest_vers
  273.                 fi
  274.                 case $device_target_vers in
  275.                     [34]* ) device_enter_mode pwnDFU;;
  276.                     * ) device_buttons;;
  277.                 esac
  278.             fi
  279.         ;;
  280.  
  281.         [56] )
  282.             # 32-bit devices A5/A6
  283.             if [[ $target_vers_maj == 10 && $device_target_tethered == 1 ]]; then
  284.                 return # do nothing, use kuroutadori
  285.             elif [[ $device_target_tethered == 1 ]]; then
  286.                 shsh_save version $device_latest_vers
  287.                 device_enter_mode pwnDFU
  288.                 return
  289.             elif [[ $device_target_other != 1 && $device_target_powder != 1 ]]; then
  290.                 shsh_save
  291.             fi
  292.             if [[ $device_target_vers == "$device_latest_vers" && $ipsw_gasgauge_patch != 1 ]]; then
  293.                 device_enter_mode Recovery
  294.             else
  295.                 device_buttons
  296.             fi
  297.         ;;
  298.     esac
  299. }
  300.  
  301. restore_prepare() {
  302.     case $device_proc in
  303.         1 )
  304.             if [[ $ipsw_jailbreak != 1 ]]; then
  305.                 if [[ $target_vers_maj == 4 ]]; then
  306.                     restore_latest
  307.                     return
  308.                 fi
  309.                 device_enter_mode Recovery
  310.                 ipsw_custom="$ipsw_path"
  311.             fi
  312.             restore_latest custom
  313.         ;;
  314.  
  315.         4 )
  316.             if [[ -n $device_type_special ]]; then
  317.                 restore_idevicerestore special
  318.             elif [[ $device_target_tethered == 1 || $device_target_other == 1 ]] ||
  319.                  [[ $device_target_vers == "4.1" && $ipsw_jailbreak == 1 && $device_target_powder != 1 ]]; then
  320.                 restore_idevicerestore
  321.             elif [[ $device_target_powder == 1 ]]; then
  322.                 case $device_target_vers in
  323.                     3* | 4.[012]* )
  324.                         local ipsw_custom_part2="$ipsw_custom"
  325.                         ipsw_custom="$ipsw_custom_part1"
  326.                         if [[ $ipsw_skip_first != 1 ]]; then
  327.                             restore_idevicerestore first
  328.                             log "Do not disconnect your device, not done yet"
  329.                             print "* Please put the device in DFU mode after it reboots!"
  330.                             sleep 5
  331.                             device_mode=
  332.                             log "Press Enter/Return when the device reboots and is on black screen, Apple logo, or iTunes logo."
  333.                             device_enter_mode DFU
  334.                         fi
  335.                         log "Finding device in Recovery/DFU mode..."
  336.                         until [[ -n $device_mode ]]; do
  337.                             device_mode="$($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-)"
  338.                         done
  339.                         ipsw_custom="$ipsw_custom_part2"
  340.                         print "* If pwning fails here, re-enter DFU and run the script again with --skip-first flag enabled to continue the process."
  341.                         device_enter_mode pwnDFU
  342.                         restore_idevicerestore
  343.                     ;;
  344.                     * ) restore_idevicerestore;;
  345.                 esac
  346.                 if [[ $device_target_vers == "3"* || $device_target_vers == "4"* ]]; then
  347.                     echo
  348.                     log "The device may enter recovery mode after the restore"
  349.                     print "* To fix this, go to: Useful Utilities -> Disable/Enable Exploit -> Enable Exploit"
  350.                 fi
  351.             elif [[ $device_target_vers == "4.1" ]]; then
  352.                 restore_latest
  353.                 if [[ $device_type == "iPhone2,1" ]]; then
  354.                     log "Ignore the baseband error and do not disconnect your device yet"
  355.                     device_find_mode Recovery 50
  356.                     log "Attempting to exit recovery mode"
  357.                     $irecovery -n
  358.                     log "Done. Your device should reboot now"
  359.                 fi
  360.             elif [[ $device_target_vers == "$device_latest_vers" ]]; then
  361.                 if [[ $ipsw_jailbreak == 1 || $ipsw_gasgauge_patch == 1 ]]; then
  362.                     restore_idevicerestore
  363.                 else
  364.                     restore_latest
  365.                 fi
  366.             else
  367.                 if [[ $device_type == "iPhone2,1" && $device_newbr != 0 ]]; then
  368.                     restore_latest custom first
  369.                     local opt=$?
  370.                     print "* Proceed to install the alloc8 exploit for the device to boot:"
  371.                     print " -> Go to: Useful Utilities -> Install alloc8 Exploit"
  372.                     if [[ $opt != 0 ]]; then
  373.                         warn "The restore seems to have failed. Will not continue with alloc8 install."
  374.                         print "* Do not attempt alloc8 install manually either. It will not work without a successful restore."
  375.                         return
  376.                     fi
  377.                     log "Do not disconnect your device, not done yet"
  378.                     device_find_mode DFU 50
  379.                     device_alloc8
  380.                 else
  381.                     restore_latest custom
  382.                 fi
  383.             fi
  384.         ;;
  385.  
  386.         [56] )
  387.             # 32-bit devices A5/A6
  388.             if [[ $device_target_vers == "$device_latest_vers" && $ipsw_gasgauge_patch != 1 ]]; then
  389.                 restore_latest
  390.             elif [[ $ipsw_jailbreak == 1 || -e "$ipsw_custom.ipsw" ]]; then
  391.                 restore_idevicerestore
  392.             elif [[ $target_vers_maj == 10 ]]; then
  393.                 restore_kuroutadori
  394.             else
  395.                 restore_futurerestore --use-pwndfu
  396.             fi
  397.         ;;
  398.  
  399.         7 )
  400.             if [[ $device_target_other != 1 && $device_target_vers == "10.3.3" ]]; then
  401.                 shsh_save
  402.             fi
  403.             if [[ $restore_usepwndfu64 == 1 ]]; then
  404.                 restore_pwned64
  405.             elif [[ $device_target_other != 1 && $device_target_vers == "10.3.3" ]]; then
  406.                 if [[ $device_type == "iPad4,4" || $device_type == "iPad4,5" ]]; then
  407.                     iBSS=$iBSSb
  408.                     iBEC=$iBECb
  409.                 fi
  410.                 restore_prepare_pwnrec64
  411.                 shsh_save apnonce $($irecovery -q | grep "NONC" | cut -c 7-)
  412.                 restore_futurerestore --skip-blob
  413.             elif [[ $device_target_vers == "$device_latest_vers" ]]; then
  414.                 restore_latest
  415.             else
  416.                 restore_notpwned64
  417.             fi
  418.         ;;
  419.  
  420.         [89] | 10 )
  421.             if [[ $restore_usepwndfu64 == 1 ]]; then
  422.                 restore_pwned64
  423.             elif [[ $device_target_vers == "$device_latest_vers" ]]; then
  424.                 restore_latest
  425.             else
  426.                 restore_notpwned64
  427.             fi
  428.         ;;
  429.  
  430.         11 ) restore_latest;;
  431.     esac
  432. }
  433.  
  434. restore_kuroutadori() {
  435.     local args=("-w" "--load-shsh" "$shsh_path")
  436.     if [[ $device_target_tethered == 1 ]]; then
  437.         args=("-o")
  438.     fi
  439.     args+=("-y" "$ipsw_path.ipsw")
  440.     device_enter_mode DFU
  441.     kuroutadori_init
  442.     kuroutadori_litera1n -D
  443.     device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
  444.     if [[ $device_pwnd != "yolo" ]]; then
  445.         device_pwnerror
  446.     fi
  447.     log "Running turdus_merula: $kuroutadori/turdus_merula ${args[*]}"
  448.     $kuroutadori/turdus_merula "${args[@]}"
  449. }
  450.  
  451. # Function to get iOS version from build number using firmwares.json
  452. get_ios_version_from_build() {
  453.     local build="$1"
  454.  
  455.     # Ensure firmwares.json exists
  456.     if [[ ! -s ../saved/firmwares.json ]]; then
  457.         log "Downloading firmwares.json for build lookup..."
  458.         file_download https://api.ipsw.me/v2.1/firmwares.json/condensed firmwares.json
  459.         mv firmwares.json ../saved
  460.     fi
  461.  
  462.     # Use firmwares.json to find version
  463.     local version=$(cat ../saved/firmwares.json | $jq -r --arg build "$build" '
  464.        [.. | objects | select(.buildid == $build) | .version] |
  465.        if length > 0 then .[0] else empty end' 2>/dev/null)
  466.  
  467.     if [[ -n "$version" && "$version" != "null" ]]; then
  468.         echo "$version"
  469.     else
  470.         echo ""
  471.     fi
  472. }
  473.  
  474. restore_pwned64() {
  475.     device_enter_mode pwnDFU
  476.     if [[ ! -s ../saved/firmwares.json ]]; then
  477.         file_download https://api.ipsw.me/v2.1/firmwares.json/condensed firmwares.json
  478.         mv firmwares.json ../saved
  479.     fi
  480.     rm -f /tmp/firmwares.json
  481.     cp ../saved/firmwares.json /tmp
  482.     local opt
  483.     if [[ $device_proc == 7 && $device_target_other != 1 &&
  484.           $device_target_vers == "10.3.3" ]] || [[ $restore_useskipblob == 1 ]]; then
  485.         opt="--skip-blob"
  486.     fi
  487.     restore_futurerestore --use-pwndfu $opt
  488. }
  489.  
  490. restore_notpwned64() {
  491.     log "The generator for your SHSH blob is: $shsh_generator"
  492.     print "* Before continuing, make sure to set the nonce generator of your device!"
  493.     print "* For more details, go to: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/futurerestore"
  494.     print "* Using \"Set Nonce Only\" in the Restore/Downgrade menu is also an option"
  495.     pause
  496.     if [[ $device_mode == "Normal" ]]; then
  497.         device_enter_mode Recovery
  498.     fi
  499.     restore_futurerestore
  500. }
  501.  
  502. ipsw_prepare() {
  503.     case $device_proc in
  504.         1 )
  505.             if [[ $ipsw_jailbreak == 1 ]]; then
  506.                 ipsw_prepare_s5l8900
  507.             elif [[ $device_target_vers == "$device_latest_vers" && ! -s "../$ipsw_latest_path.ipsw" ]]; then
  508.                 ipsw_path="../$ipsw_latest_path"
  509.                 ipsw_download "$ipsw_path"
  510.             fi
  511.         ;;
  512.  
  513.         4 )
  514.             if [[ $device_type == "iPod4,1" || $device_type == "iPad1,1" ]] && [[ $device_target_vers == "7."* ]]; then
  515.                 ipsw_prepare_specialios7
  516.             elif [[ -n $device_type_special ]]; then
  517.                 ipsw_prepare_sundanceinh2a
  518.             elif [[ $device_target_tethered == 1 ]]; then
  519.                 ipsw_prepare_tethered
  520.             elif [[ $device_target_other == 1 || $ipsw_gasgauge_patch == 1 ]] ||
  521.                  [[ $device_target_vers == "$device_latest_vers" && $ipsw_jailbreak == 1 ]]; then
  522.                 case $device_type in
  523.                     iPhone2,1 ) ipsw_prepare_jailbreak;;
  524.                     iPod2,1 ) ipsw_prepare_custom;;
  525.                     * ) ipsw_prepare_32bit;;
  526.                 esac
  527.             elif [[ $device_target_powder == 1 ]] && [[ $device_target_vers == "3"* || $device_target_vers == "4"* ]]; then
  528.                 shsh_save version $device_latest_vers
  529.                 case $device_target_vers in
  530.                     4.3* ) ipsw_prepare_ios4powder;;
  531.                     * ) ipsw_prepare_ios4multipart;;
  532.                 esac
  533.             elif [[ $device_target_powder == 1 ]]; then
  534.                 ipsw_prepare_powder
  535.             elif [[ $device_target_vers != "$device_latest_vers" ]]; then
  536.                 ipsw_prepare_custom
  537.             fi
  538.             if [[ $ipsw_isbeta == 1 && $ipsw_prepare_ios4multipart_patch != 1 ]] ||
  539.                [[ $device_target_vers == "3.2"* && $ipsw_prepare_ios4multipart_patch != 1 ]] ||
  540.                [[ $ipsw_gasgauge_patch == 1 ]]; then
  541.                 ipsw_prepare_multipatch
  542.             fi
  543.         ;;
  544.  
  545.         [56] )
  546.             # 32-bit devices A5/A6
  547.             if [[ $target_vers_maj == 10 && $device_target_tethered == 1 ]]; then
  548.                 return # do nothing, use kuroutadori
  549.             elif [[ $device_target_tethered == 1 ]]; then
  550.                 ipsw_prepare_tethered
  551.             elif [[ $device_target_powder == 1 ]]; then
  552.                 ipsw_prepare_powder
  553.             elif [[ $device_target_vers != "$device_latest_vers" || $ipsw_gasgauge_patch == 1 ]]; then
  554.                 ipsw_prepare_32bit
  555.             fi
  556.             if [[ $ipsw_fourthree == 1 ]]; then
  557.                 ipsw_prepare_fourthree_part2
  558.             elif [[ $ipsw_isbeta == 1 || $ipsw_gasgauge_patch == 1 ]]; then
  559.                 ipsw_prepare_multipatch
  560.             fi
  561.         ;;
  562.  
  563.         [789] | 10 )
  564.             if [[ $device_type == "iPhone10,3" || $device_type == "iPhone10,6" ]] && (( target_vers_maj <= 15 )); then
  565.                 # patch restored_external for iPhone X downgrades to 14.3-15.x
  566.                 ipsw_ipx=1
  567.                 ipsw_prepare_ipx
  568.             else
  569.                 ipsw_ipx=
  570.             fi
  571.             restore_usepwndfu64_option
  572.             if [[ $device_target_other != 1 && $device_target_vers == "10.3.3" && $restore_usepwndfu64 != 1 ]]; then
  573.                 ipsw_prepare_1033
  574.             fi
  575.         ;;
  576.     esac
  577. }
  578.  
  579. restore_usepwndfu64_option() {
  580.     if [[ $device_target_vers == "$device_latest_vers" ]]; then
  581.         return
  582.     elif [[ $restore_usepwndfu64 == 1 ]]; then
  583.         log "use-pwndfu flag detected, Pwned Restore Option enabled."
  584.         restore_usepwndfu64=1
  585.         return
  586.     elif [[ $restore_useskipblob == 1 ]]; then
  587.         log "skip-blob flag detected, Pwned Restore Option enabled."
  588.         restore_usepwndfu64=1
  589.         return
  590.     elif [[ $device_mode == "DFU" && $device_target_other == 1 ]]; then
  591.         log "Device is in DFU mode, Pwned Restore Option enabled."
  592.         print "* If you want to disable Pwned Restore Option, place the device in Normal/Recovery mode"
  593.         restore_usepwndfu64=1
  594.         return
  595.     elif [[ $device_target_setnonce == 1 ]]; then
  596.         log "Set Nonce Only mode detected, Pwned Restore Option enabled."
  597.         restore_usepwndfu64=1
  598.         return
  599.     fi
  600.     local opt
  601.     input "Pwned Restore Option"
  602.     print "* When this option is enabled, use-pwndfu will be enabled for restoring."
  603.     if [[ $device_target_other == 1 ]]; then
  604.         print "* When disabled, user must set the device generator manually before the restore."
  605.     fi
  606.     if [[ $device_proc == 7 && $device_target_vers == "10.3.3" && $device_target_other != 1 ]] ||
  607.        [[ $device_proc == 7 && $platform == "linux" ]]; then
  608.         if [[ $device_target_vers == "10.3.3" && $device_target_other != 1 ]]; then
  609.             print "* It is recommended to disable this option for A7 10.3.3 restores."
  610.         fi
  611.         print "* This option is disabled by default (N). Select this option if unsure."
  612.         select_yesno "Enable this option?" 0
  613.         if [[ $? != 0 ]]; then
  614.             log "Pwned restore option enabled by user."
  615.             restore_usepwndfu64=1
  616.         else
  617.             log "Pwned restore option disabled."
  618.         fi
  619.     else
  620.         print "* This option is enabled by default (Y). Select this option if unsure."
  621.         select_yesno "Enable this option?" 1
  622.         if [[ $? != 1 ]]; then
  623.             log "Pwned restore option disabled by user."
  624.         else
  625.             log "Pwned restore option enabled."
  626.             restore_usepwndfu64=1
  627.         fi
  628.     fi
  629. }
  630.  
  631. ipsw_prepare_ipx() {
  632.     restore_usepwndfu64=1
  633.     log "Extracting BuildManifest.plist from IPSW"
  634.     file_extract_from_archive "$ipsw_path.ipsw" BuildManifest.plist
  635.     log "Get paths"
  636.     local kernelcache=$($PlistBuddy2 -c "Print BuildIdentities:0:Manifest:KernelCache:Info:Path" BuildManifest.plist | tr -d '"')
  637.     local restoreramdisk=$($PlistBuddy2 -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" BuildManifest.plist | tr -d '"')
  638.     log "KernelCache: $kernelcache"
  639.     log "RestoreRamDisk: $restoreramdisk"
  640.  
  641.     # patch kernelcache amfi (required when using custom ramdisk)
  642.     log "Extracting KernelCache from IPSW"
  643.     file_extract_from_archive "$ipsw_path.ipsw" $kernelcache
  644.     log "Processing KernelCache"
  645.     "$dir/img4" -i $kernelcache -o kcache.raw
  646.     log "Patching KernelCache"
  647.     "$dir/KPlooshFinder" kcache.raw kcache.patched
  648.     "$dir/kerneldiff" kcache.raw kcache.patched kcache.bpatch
  649.     log "Repacking KernelCache"
  650.     "$dir/img4" -i $kernelcache -o kcache.im4p -T rkrn -P kcache.bpatch -J
  651.  
  652.     log "Extracting RestoreRamDisk from IPSW"
  653.     file_extract_from_archive "$ipsw_path.ipsw" $restoreramdisk
  654.  
  655.     local platform2="$platform"
  656.     [[ $platform2 == "macos" ]] && platform2+="x"
  657.     ldid="../saved/ldid_${platform2}_$(uname -m)"
  658.     if [[ ! -s $ldid ]]; then
  659.         file_download https://github.com/ProcursusTeam/ldid/releases/download/v2.1.5-procursus7/$(basename $ldid) ldid
  660.         mv ldid $ldid
  661.     fi
  662.     if [[ ! -s $ldid ]]; then
  663.         error "Failed to download ldid. Please run the script again"
  664.     fi
  665.     chmod +x $ldid
  666.  
  667.     # patch restored_external for iPhone X downgrades to 14.3-15.x
  668.     log "Processing RestoreRamDisk"
  669.     "$dir/img4" -i $restoreramdisk -o ramdisk.raw
  670.     log "Extracting restored_external"
  671.     "$dir/hfsplus" ramdisk.raw extract usr/local/bin/restored_external
  672.     log "Patching restored_external"
  673.     mv restored_external restored_external.orig
  674.     "$dir/ipx_restored_patcher" restored_external.orig restored_external
  675.     $ldid -e restored_external.orig > ent.xml
  676.     $ldid -Sent.xml restored_external
  677.     if [[ ! -s restored_external ]]; then
  678.         error "Failed to patch restored_external (???) Please run the script again."
  679.     fi
  680.     log "Replacing restored_external"
  681.     "$dir/hfsplus" ramdisk.raw rm usr/local/bin/restored_external
  682.     "$dir/hfsplus" ramdisk.raw add restored_external usr/local/bin/restored_external
  683.     "$dir/hfsplus" ramdisk.raw chmod 755 usr/local/bin/restored_external
  684.     log "Repacking RestoreRamDisk"
  685.     "$dir/img4" -i ramdisk.raw -o rdsk.im4p -T rdsk -A
  686. }
  687.  
  688. menu_remove4() {
  689.     local menu_items
  690.     local selected
  691.     local back
  692.  
  693.     while [[ -z "$mode" && -z "$back" ]]; do
  694.         menu_items=("Disable Exploit" "Enable Exploit" "Go Back")
  695.         menu_print_info
  696.         print " > Main Menu > Useful Utilities > Disable/Enable Exploit"
  697.         input "Select an option:"
  698.         select_option "${menu_items[@]}"
  699.         selected="${menu_items[$?]}"
  700.         case $selected in
  701.             "Disable Exploit" ) rec=0;;
  702.             "Enable Exploit" ) rec=2;;
  703.         esac
  704.         case $selected in
  705.             "Go Back" ) back=1;;
  706.             * ) mode="remove4";;
  707.         esac
  708.     done
  709. }
  710.  
  711. device_send_rdtar() {
  712.     log "Sending and extracting $1"
  713.     if [[ $2 == "gz" ]]; then
  714.         cp $jelbrek/$1.gz .
  715.         gzip -d $1.gz
  716.         cat $1 | $ssh -p $ssh_port root@127.0.0.1 "tar -xvf - -C /mnt1"
  717.         return
  718.     fi
  719.     cat $jelbrek/$1 | $ssh -p $ssh_port root@127.0.0.1 "tar -xvf - -C /mnt1"
  720. }
  721.  
  722. device_ramdisk64() {
  723.     local sshtar="../saved/ssh64.tar"
  724.     local comps=("iBSS" "iBEC" "DeviceTree" "Kernelcache" "RestoreRamdisk")
  725.     local name
  726.     local iv
  727.     local key
  728.     local path
  729.     local url
  730.     local decrypt
  731.     local opt
  732.     local build_id="16A366"
  733.     if (( device_proc >= 9 )) || [[ $device_type == "iPad5"* ]]; then
  734.         build_id="18C66"
  735.     fi
  736.  
  737.     if [[ $device_ramdisk_ios8 == 1 ]]; then
  738.         build_id="12B410"
  739.         if [[ $device_type == "iPhone"* ]]; then
  740.             build_id="12B411"
  741.         elif [[ $device_type == "iPod7,1" ]]; then
  742.             build_id="12H321"
  743.         fi
  744.         sshtar="../saved/iram.tar"
  745.         if [[ ! -e $sshtar ]]; then
  746.             log "Downloading iram.tar from iarchive.app..."
  747.             file_download https://github.com/LukeZGD/Legacy-iOS-Kit/files/14952123/iram.zip iram.zip
  748.             file_extract iram.zip
  749.             mv iram.tar $sshtar
  750.         fi
  751.         cp $sshtar ssh.tar
  752.     else
  753.         comps+=("Trustcache")
  754.         if [[ $($sha1sum $sshtar.gz 2>/dev/null | awk '{print $1}') != "61975423c096d5f21fd9f8a48042fffd3828708b" ]]; then
  755.             rm -f $sshtar $sshtar.gz
  756.         fi
  757.         if [[ ! -e $sshtar.gz ]]; then
  758.             log "Downloading ssh.tar from SSHRD_Script..."
  759.             file_download https://raw.githubusercontent.com/LukeZGD/sshtars/eed9dcb6aa7562c185eb8b3b66c6035c0b026d47/ssh.tar.gz ssh.tar.gz
  760.             mv ssh.tar.gz $sshtar.gz
  761.         fi
  762.         cp $sshtar.gz ssh.tar.gz
  763.         gzip -d ssh.tar.gz
  764.     fi
  765.  
  766.     local ramdisk_path="../saved/$device_type/ramdisk_$build_id"
  767.     device_target_build="$build_id"
  768.     device_fw_key_check
  769.     ipsw_get_url $build_id
  770.     mkdir -p $ramdisk_path
  771.     rm -f $ramdisk_path/*.img4 $ramdisk_path/iBEC.im4p $ramdisk_path/iBSS.im4p
  772.  
  773.     for getcomp in "${comps[@]}"; do
  774.         name=$(echo $device_fw_key | $jq -j '.keys[] | select(.image == "'$getcomp'") | .filename')
  775.         iv=$(echo $device_fw_key | $jq -j '.keys[] | select(.image == "'$getcomp'") | .iv')
  776.         key=$(echo $device_fw_key | $jq -j '.keys[] | select(.image == "'$getcomp'") | .key')
  777.         if [[ $device_type == "iPhone8,"* && $getcomp == "iB"* ]]; then
  778.             name=$(echo $device_fw_key | $jq -j '.keys[] | select(.image | startswith("'$getcomp'")) | select(.filename | startswith("'$getcomp'.'$device_model'.")) | .filename')
  779.             iv=$(echo $device_fw_key | $jq -j '.keys[] | select(.image | startswith("'$getcomp'")) | select(.filename | startswith("'$getcomp'.'$device_model'.")) | .iv')
  780.             key=$(echo $device_fw_key | $jq -j '.keys[] | select(.image | startswith ("'$getcomp'")) | select(.filename | startswith("'$getcomp'.'$device_model'.")) | .key')
  781.         fi
  782.         case $getcomp in
  783.             "iBSS" | "iBEC" ) path="Firmware/dfu/";;
  784.             "DeviceTree" ) path="Firmware/all_flash/";;
  785.             "Trustcache" ) path="Firmware/";;
  786.             * ) path="";;
  787.         esac
  788.         if [[ $device_ramdisk_ios8 == 1 && $getcomp == "DeviceTree" ]]; then
  789.             path="$all_flash/"
  790.         fi
  791.         if [[ -z $name ]]; then
  792.             local hwmodel
  793.             ipsw_hwmodel_set
  794.             hwmodel="$ipsw_hwmodel"
  795.             case $getcomp in
  796.                 "iBSS" | "iBEC"  ) name="$getcomp.$hwmodel.RELEASE.im4p";;
  797.                 "DeviceTree"     ) name="$getcomp.${device_model}ap.im4p";;
  798.                 "Kernelcache"    ) name="kernelcache.release.$hwmodel";;
  799.                 "Trustcache"     ) name="048-08497-242.dmg.trustcache";;
  800.                 "RestoreRamdisk" ) name="048-08497-242.dmg";;
  801.             esac
  802.             if [[ $device_type == "iPhone8,1" || $device_type == "iPhone8,2" ]] && [[ $getcomp == "Kernelcache" ]]; then
  803.                 name="kernelcache.release.${device_model:0:3}"
  804.             fi
  805.             if [[ $build_id == "18C66" ]]; then
  806.                 case $getcomp in
  807.                     "Trustcache"     ) name="038-83284-083.dmg.trustcache";;
  808.                     "RestoreRamdisk" ) name="038-83284-083.dmg";;
  809.                 esac
  810.             fi
  811.         fi
  812.  
  813.         log "$getcomp"
  814.         if [[ -e $ramdisk_path/$name ]]; then
  815.             cp $ramdisk_path/$name .
  816.         else
  817.             "$dir/pzb" -g "${path}$name" -o "$name" "$ipsw_url"
  818.             cp $name $ramdisk_path/
  819.         fi
  820.         mv $name $getcomp.orig
  821.         local reco="-i $getcomp.orig -o $getcomp.img4 -M ../resources/sshrd/IM4M$device_proc -T "
  822.         case $getcomp in
  823.             "iBSS" | "iBEC" )
  824.                 reco+="$(echo $getcomp | tr '[:upper:]' '[:lower:]') -A"
  825.                 "$dir/img4" -i $getcomp.orig -o $getcomp.dec -k ${iv}${key}
  826.                 mv $getcomp.orig $getcomp.orig0
  827.                 if [[ $device_ramdisk_ios8 == 1 ]]; then
  828.                     $bspatch $getcomp.dec $getcomp.orig ../resources/sshrd/ios8/$name.patch
  829.                 else
  830.                     $bspatch $getcomp.dec $getcomp.orig ../resources/sshrd/$name.patch
  831.                 fi
  832.             ;;
  833.             "Kernelcache" )
  834.                 reco+="rkrn"
  835.                 if [[ $device_ramdisk_ios8 == 1 ]]; then
  836.                     mv $getcomp.orig $getcomp.orig0
  837.                     "$dir/img4" -i $getcomp.orig0 -o $getcomp.orig -k ${iv}${key} -D
  838.                 else
  839.                     reco+=" -P ../resources/sshrd/$name.bpatch"
  840.                     if [[ $platform == "linux" && $build_id == "18"* ]] || [[ $device_proc == 10 ]]; then
  841.                         reco+=" -J"
  842.                     fi
  843.                 fi
  844.             ;;
  845.             "DeviceTree" )
  846.                 reco+="rdtr"
  847.                 if [[ $device_ramdisk_ios8 == 1 ]]; then
  848.                     reco+=" -A"
  849.                     mv $getcomp.orig $getcomp.orig0
  850.                     "$dir/img4" -i $getcomp.orig0 -o $getcomp.orig -k ${iv}${key}
  851.                 fi
  852.             ;;
  853.             "Trustcache" ) reco+="rtsc";;
  854.             "RestoreRamdisk" )
  855.                 reco+="rdsk -A"
  856.                 mv $getcomp.orig $getcomp.orig0
  857.                 if [[ $device_ramdisk_ios8 == 1 ]]; then
  858.                     "$dir/img4" -i $getcomp.orig0 -o $getcomp.orig -k ${iv}${key}
  859.                     "$dir/hfsplus" $getcomp.orig grow 50000000
  860.                 else
  861.                     "$dir/img4" -i $getcomp.orig0 -o $getcomp.orig
  862.                     "$dir/hfsplus" $getcomp.orig grow 130000000
  863.                 fi
  864.                 "$dir/hfsplus" $getcomp.orig untar ssh.tar
  865.                 "$dir/hfsplus" $getcomp.orig untar ../resources/sshrd/sbplist.tar
  866.             ;;
  867.         esac
  868.         "$dir/img4" $reco
  869.     done
  870.  
  871.     mv iBSS.img4 iBSS.im4p
  872.     mv iBEC.img4 iBEC.im4p
  873.     iBSS="iBSS"
  874.     iBEC="iBEC"
  875.  
  876.     if [[ $device_argmode == "none" ]]; then
  877.         mkdir -p $ramdisk_path/saved
  878.         cp *.img4 iBEC.im4p iBSS.im4p $ramdisk_path/saved/
  879.         log "Done creating SSH ramdisk files: saved/$device_type/ramdisk_$build_id/saved"
  880.         return
  881.     fi
  882.     restore_prepare_pwnrec64
  883.  
  884.     log "Booting, please wait..."
  885.     $irecovery -f RestoreRamdisk.img4
  886.     $irecovery -c ramdisk
  887.     $irecovery -f DeviceTree.img4
  888.     $irecovery -c devicetree
  889.     if [[ $device_ramdisk_ios8 != 1 ]]; then
  890.         $irecovery -f Trustcache.img4
  891.         $irecovery -c firmware
  892.     fi
  893.     $irecovery -f Kernelcache.img4
  894.     $irecovery -c bootx
  895.     sleep 6
  896.  
  897.     if [[ $device_ramdisk_ios8 == 1 ]]; then
  898.         device_iproxy no-logging 44
  899.         print "* Booted SSH ramdisk is based on: https://ios7.iarchive.app/downgrade/making-ramdisk.html"
  900.     else
  901.         device_iproxy no-logging
  902.         print "* Booted SSH ramdisk is based on: https://github.com/verygenericname/SSHRD_Script"
  903.     fi
  904.     device_sshpass alpine
  905.  
  906.     local found
  907.     log "Waiting for device..."
  908.     print "* You may need to unplug and replug your device."
  909.     while [[ $found != 1 ]]; do
  910.         found=$($ssh -p $ssh_port root@127.0.0.1 "echo 1")
  911.         sleep 2
  912.     done
  913.  
  914.     case $1 in
  915.         "getversion" ) device_datetime_cmd;;
  916.     esac
  917.  
  918.     echo
  919.     print "* Mount filesystems with this command (for iOS 11.3 and newer):"
  920.     print "    mount_filesystems"
  921.     print "* Mount root filesystem with this command (for iOS 10.3.x/11.x):"
  922.     print "    mount_apfs /dev/disk0s1s1 /mnt1"
  923.     print "* Mount root filesystem with this command (for iOS 10.2.1 and older):"
  924.     print "    mount_hfs /dev/disk0s1s1 /mnt1"
  925.     warn "Mounting and/or modifying data partition (/mnt2) might not work for 64-bit iOS"
  926.     warn "Mount filesystems at your own risk: there is a chance of bootlooping! Especially on versions older than iOS 11.3."
  927.     print "* For more details, go to: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/SSH-Ramdisk"
  928.  
  929.     menu_ramdisk $build_id
  930. }
  931.  
  932. device_ramdisk() {
  933.     local comps=("iBSS" "iBEC" "DeviceTree" "Kernelcache")
  934.     local name
  935.     local iv
  936.     local key
  937.     local path
  938.     local url
  939.     local decrypt
  940.     local ramdisk_path
  941.     local version
  942.     local build_id
  943.     local mode="$1"
  944.     local rec=2
  945.     local bundle="../resources/firmware/FirmwareBundles/Down_"
  946.  
  947.     if [[ $1 == "setnvram" ]]; then
  948.         rec=$2
  949.     fi
  950.     if [[ $1 != "justboot" ]]; then
  951.         comps+=("RestoreRamdisk")
  952.     fi
  953.     case $device_type in
  954.         iPhone1,[12] | iPod1,1 ) device_target_build="7E18"; device_target_vers="3.1.3";;
  955.         iPod2,1 ) device_target_build="8C148"; device_target_vers="4.2.1";;
  956.         iPod3,1 | iPad1,1 ) device_target_build="9B206";;
  957.         iPhone2,1 | iPod4,1 ) device_target_build="10B500";;
  958.         iPhone5,[34] ) device_target_build="11D257";;
  959.         * ) device_target_build="10B329";;
  960.     esac
  961.     if [[ -n $device_rd_build ]]; then
  962.         device_target_build=$device_rd_build
  963.         device_rd_build=
  964.     fi
  965.     version=$device_target_vers
  966.     build_id=$device_target_build
  967.     bundle+="${device_type}_${version}_${build_id}.bundle"
  968.     if [[ -z $ipsw_justboot_path ]]; then
  969.         local ipsw_path=$(ls ../${device_type}*${build_id}_Restore.ipsw 2>/dev/null)
  970.         if [[ -s "$ipsw_path" ]]; then
  971.             ipsw_justboot_path="${ipsw_path%%.ipsw*}"
  972.         else
  973.             local build_id2="$(echo "$build_id" | tr '[:upper:]' '[:lower:]')"
  974.             ipsw_path=$(ls ../${device_type_lower}*${build_id2}_restore.ipsw 2>/dev/null)
  975.             [[ -s "$ipsw_path" ]] && ipsw_justboot_path="${ipsw_path%%.ipsw*}"
  976.         fi
  977.         [[ -n $ipsw_justboot_path ]] && log "Found IPSW to use: $ipsw_justboot_path.ipsw"
  978.     fi
  979.  
  980.     device_fw_key_check
  981.     ipsw_get_url $build_id $device_type $version
  982.     ramdisk_path="../saved/$device_type/ramdisk_$build_id"
  983.     mkdir -p $ramdisk_path
  984.     rm -f $ramdisk_path/*.dec $ramdisk_path/iBEC $ramdisk_path/iBSS $ramdisk_path/Ramdisk.dmg
  985.  
  986.     for getcomp in "${comps[@]}"; do
  987.         name=$(echo $device_fw_key | $jq -j '.keys[] | select(.image == "'$getcomp'") | .filename')
  988.         iv=$(echo $device_fw_key | $jq -j '.keys[] | select(.image == "'$getcomp'") | .iv')
  989.         key=$(echo $device_fw_key | $jq -j '.keys[] | select(.image == "'$getcomp'") | .key')
  990.         case $getcomp in
  991.             "iBSS" | "iBEC" ) path="Firmware/dfu/";;
  992.             "DeviceTree" )
  993.                 path="Firmware/all_flash/"
  994.                 case $build_id in
  995.                     14[EFG]* ) :;;
  996.                     * ) path="$all_flash/";;
  997.                 esac
  998.             ;;
  999.             * ) path="";;
  1000.         esac
  1001.         if [[ -z $name ]]; then
  1002.             local hwmodel="$device_model"
  1003.             case $build_id in
  1004.                 14[EFG]* )
  1005.                     case $device_type in
  1006.                         iPhone5,[12] ) hwmodel="iphone5";;
  1007.                         iPhone5,[34] ) hwmodel="iphone5b";;
  1008.                         iPad3,[456] )  hwmodel="ipad3b";;
  1009.                     esac
  1010.                 ;;
  1011.                 [789]* | 10* | 11* ) hwmodel+="ap";;
  1012.             esac
  1013.             case $getcomp in
  1014.                 "iBSS" | "iBEC" ) name="$getcomp.$hwmodel.RELEASE.dfu";;
  1015.                 "DeviceTree" )    name="$getcomp.${device_model}ap.img3";;
  1016.                 "Kernelcache" )   name="kernelcache.release.$hwmodel";;
  1017.             esac
  1018.         fi
  1019.         [[ $name == *".dmg" ]] && name="${name%%.dmg*}.dmg"
  1020.  
  1021.         log "$getcomp"
  1022.         if [[ -n $ipsw_justboot_path ]]; then
  1023.             file_extract_from_archive "$ipsw_justboot_path.ipsw" "${path}$name"
  1024.         elif [[ -s $ramdisk_path/$name ]]; then
  1025.             cp $ramdisk_path/$name .
  1026.         else
  1027.             "$dir/pzb" -g "${path}$name" -o "$name" "$ipsw_url"
  1028.         fi
  1029.         if [[ ! -s $name ]]; then
  1030.             error "Failed to get $name. Please run the script again."
  1031.         fi
  1032.         if [[ ! -s $ramdisk_path/$name ]]; then
  1033.             cp $name $ramdisk_path/
  1034.         fi
  1035.         mv $name $getcomp.orig
  1036.         if [[ $getcomp == "Kernelcache" || $getcomp == "iBSS" ]] && [[ $device_proc == 1 || $device_type == "iPod2,1" ]]; then
  1037.             decrypt="-iv $iv -k $key"
  1038.             "$dir/xpwntool" $getcomp.orig $getcomp.dec $decrypt
  1039.         elif [[ $build_id == "14"* ]]; then
  1040.             cp $getcomp.orig $getcomp.dec
  1041.         else
  1042.             "$dir/xpwntool" $getcomp.orig $getcomp.dec -iv $iv -k $key -decrypt
  1043.         fi
  1044.     done
  1045.  
  1046.     if [[ $1 != "justboot" ]]; then
  1047.         log "Patch RestoreRamdisk"
  1048.         "$dir/xpwntool" RestoreRamdisk.dec Ramdisk.raw
  1049.         "$dir/hfsplus" Ramdisk.raw grow 32000000
  1050.         "$dir/hfsplus" Ramdisk.raw untar ../resources/sshrd/sbplist.tar
  1051.     fi
  1052.  
  1053.     if [[ $device_proc == 1 || $device_type == "iPod2,1" ]]; then
  1054.         cp ../resources/sshrd/ssh_old.tar.gz .
  1055.         gzip -d ssh_old.tar.gz
  1056.         "$dir/hfsplus" Ramdisk.raw untar ssh_old.tar
  1057.         "$dir/xpwntool" Ramdisk.raw Ramdisk.dmg -t RestoreRamdisk.dec
  1058.         log "Patch iBSS"
  1059.         $bspatch iBSS.dec iBSS.patched $bundle/iBSS.${device_model}ap.RELEASE.patch
  1060.         "$dir/xpwntool" iBSS.patched iBSS -t iBSS.orig
  1061.         log "Patch Kernelcache"
  1062.         mv Kernelcache.dec Kernelcache0.dec
  1063.         $bspatch Kernelcache0.dec Kernelcache.patched $bundle/kernelcache.release.patch
  1064.         "$dir/xpwntool" Kernelcache.patched Kernelcache.dec -t Kernelcache.orig $decrypt
  1065.         rm DeviceTree.dec
  1066.         mv DeviceTree.orig DeviceTree.dec
  1067.     else
  1068.         if [[ $1 != "justboot" ]]; then
  1069.             cp ../resources/sshrd/ssh.tar.gz .
  1070.             gzip -d ssh.tar.gz
  1071.             "$dir/hfsplus" Ramdisk.raw untar ssh.tar
  1072.             if [[ $1 == "jailbreak" && $device_vers == "8"* ]]; then
  1073.                 "$dir/hfsplus" Ramdisk.raw untar ../resources/jailbreak/daibutsu/bin.tar
  1074.             fi
  1075.             "$dir/hfsplus" Ramdisk.raw mv sbin/reboot sbin/reboot_bak
  1076.             "$dir/hfsplus" Ramdisk.raw mv sbin/halt sbin/halt_bak
  1077.             case $build_id in
  1078.                  "12"* | "13"* | "14"* )
  1079.                     echo '#!/bin/bash' > restored_external
  1080.                     echo "/sbin/sshd; exec /usr/local/bin/restored_external_o" >> restored_external
  1081.                     "$dir/hfsplus" Ramdisk.raw mv usr/local/bin/restored_external usr/local/bin/restored_external_o
  1082.                     "$dir/hfsplus" Ramdisk.raw add restored_external usr/local/bin/restored_external
  1083.                     "$dir/hfsplus" Ramdisk.raw chmod 755 usr/local/bin/restored_external
  1084.                     "$dir/hfsplus" Ramdisk.raw chown 0:0 usr/local/bin/restored_external
  1085.                 ;;
  1086.             esac
  1087.             "$dir/xpwntool" Ramdisk.raw Ramdisk.dmg -t RestoreRamdisk.dec
  1088.         fi
  1089.         log "Patch iBSS"
  1090.         "$dir/xpwntool" iBSS.dec iBSS.raw
  1091.         if [[ $device_type == "iPad2,"* || $device_type == "iPhone3,3" ]]; then
  1092.             case $build_id in
  1093.                 8[FGHJKL]* | 8E600 | 8E501 ) device_boot4=1;;
  1094.             esac
  1095.         fi
  1096.         if [[ $device_boot4 == 1 && $build_id == "8E"* ]]; then
  1097.             "$dir/iBoot32Patcher" iBSS.raw iBSS.patched --rsa --debug -b "-v amfi=0xff cs_enforcement_disable=1"
  1098.         else
  1099.             "$dir/iBoot32Patcher" iBSS.raw iBSS.patched --rsa --debug -b "$device_bootargs"
  1100.         fi
  1101.         "$dir/xpwntool" iBSS.patched iBSS -t iBSS.dec
  1102.         if [[ $build_id == "7"* || $build_id == "8"* ]] && [[ $device_type != "iPad"* ]]; then
  1103.             :
  1104.         else
  1105.             log "Patch iBEC"
  1106.             "$dir/xpwntool" iBEC.dec iBEC.raw
  1107.             if [[ $1 == "justboot" ]]; then
  1108.                 "$dir/iBoot32Patcher" iBEC.raw iBEC.patched --rsa -b "$device_bootargs"
  1109.             else
  1110.                 "$dir/iBoot32Patcher" iBEC.raw iBEC.patched --rsa --debug -b "rd=md0 -v amfi=0xff amfi_get_out_of_my_way=1 cs_enforcement_disable=1 pio-error=0"
  1111.             fi
  1112.             "$dir/xpwntool" iBEC.patched iBEC -t iBEC.dec
  1113.         fi
  1114.     fi
  1115.  
  1116.     if [[ $device_boot4 == 1 && $build_id == "8E"* ]]; then
  1117.         log "Patch Kernelcache"
  1118.         mv Kernelcache.dec Kernelcache0.dec
  1119.         "$dir/xpwntool" Kernelcache0.dec Kernelcache.raw
  1120.         $bspatch Kernelcache.raw Kernelcache.patched ../resources/patch/kernelcache.release.${device_model}.${build_id}.patch
  1121.         "$dir/xpwntool" Kernelcache.patched Kernelcache.dec -t Kernelcache0.dec
  1122.     fi
  1123.  
  1124.     if [[ $device_argmode == "none" ]]; then
  1125.         mkdir -p $ramdisk_path/saved
  1126.         cp *.dec iBEC iBSS Ramdisk.dmg $ramdisk_path/saved/
  1127.         log "Done creating SSH ramdisk files: saved/$device_type/ramdisk_$build_id/saved"
  1128.         return
  1129.     fi
  1130.  
  1131.     if [[ $1 == "jailbreak" || $1 == "justboot" || $device_type == "iPod2,1" ]]; then
  1132.         device_enter_mode pwnDFU
  1133.     elif [[ $device_proc == 1 ]]; then
  1134.         device_enter_mode DFU
  1135.     else
  1136.         device_buttons
  1137.     fi
  1138.  
  1139.     if [[ $device_type == "iPad1,1" && $build_id != "9"* ]]; then
  1140.         patch_ibss
  1141.         log "Sending iBSS..."
  1142.         $irecovery -f pwnediBSS.dfu
  1143.         sleep 1
  1144.         log "Sending iBEC..."
  1145.         $irecovery -f iBEC
  1146.     elif (( device_proc < 5 )) && [[ $device_pwnrec != 1 ]]; then
  1147.         log "Sending iBSS..."
  1148.         $irecovery -f iBSS
  1149.     fi
  1150.     sleep 1
  1151.     if [[ $build_id != "7"* && $build_id != "8"* ]]; then
  1152.         log "Sending iBEC..."
  1153.         $irecovery -f iBEC
  1154.         if [[ $device_pwnrec == 1 ]]; then
  1155.             $irecovery -c "go"
  1156.         fi
  1157.     fi
  1158.     device_find_mode Recovery
  1159.     if [[ $1 != "justboot" ]]; then
  1160.         log "Sending ramdisk..."
  1161.         $irecovery -f Ramdisk.dmg
  1162.         log "Running ramdisk"
  1163.         $irecovery -c "getenv ramdisk-delay" # required for s5l8900
  1164.         $irecovery -c ramdisk
  1165.     fi
  1166.     log "Sending DeviceTree..."
  1167.     $irecovery -f DeviceTree.dec
  1168.     log "Running devicetree"
  1169.     $irecovery -c devicetree
  1170.     log "Sending KernelCache..."
  1171.     $irecovery -f Kernelcache.dec
  1172.     $irecovery -c bootx
  1173.  
  1174.     if [[ $1 == "justboot" ]]; then
  1175.         log "Device should now boot."
  1176.         return
  1177.     fi
  1178.     log "Booting, please wait..."
  1179.     sleep 6
  1180.  
  1181.     if [[ -n $1 ]]; then
  1182.         device_iproxy
  1183.     else
  1184.         device_iproxy no-logging
  1185.     fi
  1186.     device_sshpass alpine
  1187.  
  1188.     local found
  1189.     log "Waiting for device..."
  1190.     print "* You may need to unplug and replug your device."
  1191.     while [[ $found != 1 ]]; do
  1192.         found=$($ssh -p $ssh_port root@127.0.0.1 "echo 1")
  1193.         sleep 2
  1194.     done
  1195.  
  1196.     case $mode in
  1197.         "activation" | "baseband" )
  1198.             return
  1199.         ;;
  1200.  
  1201.         "TwistedMind2" )
  1202.             log "Sending TwistedMind2"
  1203.             $scp -P $ssh_port TwistedMind2 root@127.0.0.1:/
  1204.             log "Waiting for disks..."
  1205.             $ssh -p $ssh_port root@127.0.0.1 'while [[ ! $(ls /dev/rdisk* 2>/dev/null) ]]; do :; done'
  1206.             log "Sending dd command for TwistedMind2"
  1207.             $ssh -p $ssh_port root@127.0.0.1 "dd if=/TwistedMind2 of=/dev/rdisk0 bs=8192; reboot_bak"
  1208.             return
  1209.         ;;
  1210.  
  1211.         "getversion" )
  1212.             device_ramdisk_iosvers
  1213.             log "Done. Proceeding to SSH Ramdisk Menu. You may reboot from there or do other stuff if needed."
  1214.             pause
  1215.         ;;
  1216.  
  1217.         "jailbreak" )
  1218.             local vers
  1219.             local build
  1220.             local untether
  1221.             device_ramdisk_iosvers
  1222.             vers=$device_vers
  1223.             build=$device_build
  1224.             log "$device_type is on iOS $vers-$build"
  1225.  
  1226.             if [[ -n $($ssh -p $ssh_port root@127.0.0.1 "ls /mnt1/bin/bash 2>/dev/null") ]]; then
  1227.                 case $vers in
  1228.                     4.[10]* | 3.[21]* ) $ssh -p $ssh_port root@127.0.0.1 "mkdir -p /mnt1/private/var/db; echo '' > /mnt1/private/var/db/.launchd_use_gmalloc";;
  1229.                 esac
  1230.                 log "Mounting data partition"
  1231.                 $ssh -p $ssh_port root@127.0.0.1 "mount.sh pv"
  1232.                 warn "Your device seems to be already jailbroken. Cannot continue jailbreaking."
  1233.                 if [[ $ipsw_openssh == 1 ]]; then
  1234.                     log "Will try installing OpenSSH anyway..."
  1235.                     device_send_rdtar sshdeb.tar
  1236.                     device_send_rdtar openssh.tar gz
  1237.                     device_send_rdtar openssl.tar gz
  1238.                 fi
  1239.                 log "Rebooting"
  1240.                 $ssh -p "$ssh_port" root@127.0.0.1 "reboot_bak"
  1241.                 return
  1242.             fi
  1243.  
  1244.             case $vers in
  1245.                 9.3.[56] ) :;;
  1246.                 9.*  ) untether="everuntether.tar";;
  1247.                 8.*  ) untether="daibutsu/untether.tar";;
  1248.                 7.*  ) untether="aquila_7.tar";;
  1249.                 6.*  ) untether="aquila_6.tar";;
  1250.                 5.*  ) untether="aquila_5.tar";;
  1251.                 4.3* ) untether="aquila_4.tar";;
  1252.                 4.2.[8761] | 4.[10]* | 3.2* | 3.1.3 )
  1253.                     untether="greenpois0n/${device_type}_${build}.tar"
  1254.                 ;;
  1255.                 4.2* )
  1256.                     case $device_type in
  1257.                         # untether=1 means no untether package, but the var still needs to be set
  1258.                         iPhone3,3 ) untether=1;;
  1259.                     esac
  1260.                 ;;
  1261.                 3.* ) [[ $device_type == "iPhone2,1" ]] && untether=1;;
  1262.                 '' )
  1263.                     warn "Something wrong happened. Failed to get iOS version."
  1264.                     print "* Please reboot the device into normal operating mode, then perform a clean \"slide to power off\", then try again."
  1265.                     $ssh -p $ssh_port root@127.0.0.1 "reboot_bak"
  1266.                     return
  1267.                 ;;
  1268.             esac
  1269.  
  1270.             # temporary measure for a6 ios 6
  1271.             if [[ $device_proc == 6 ]]; then
  1272.                 case $vers in
  1273.                     6.1.[34] ) untether="p0sixspwn.tar";;
  1274.                     6.*      ) untether="evasi0n6-untether.tar";;
  1275.                 esac
  1276.             fi
  1277.             # temporary measure for a5 ios 5
  1278.             if [[ $device_proc == 5 && $vers == "5."* ]]; then
  1279.                 untether="g1lbertJB/${device_type}_${build}.tar"
  1280.             fi
  1281.  
  1282.             # use everuntether+jsc_untether instead of everuntether+dsc haxx for a5(x) 8.0-8.2
  1283.             if [[ $device_proc == 5 ]]; then
  1284.                 case $vers in
  1285.                     8.[012]* )
  1286.                         ipsw_everuntether=1
  1287.                         untether="everuntether.tar"
  1288.                     ;;
  1289.                 esac
  1290.             fi
  1291.  
  1292.             # untether var must be set by now
  1293.             if [[ -z $untether ]]; then
  1294.                 warn "iOS $vers is not supported for jailbreaking with SSHRD."
  1295.                 $ssh -p $ssh_port root@127.0.0.1 "reboot_bak"
  1296.                 return
  1297.             fi
  1298.             log "Nice, iOS $vers is compatible."
  1299.  
  1300.             local otherfreeze
  1301.             if [[ $device_type == "iPhone2,1" && $vers == "4.3"* ]]; then
  1302.                 otherfreeze=1
  1303.             fi
  1304.  
  1305.             if [[ $otherfreeze == 1 && ! -s ../saved/freeze5.tar.gz ]]; then
  1306.                 file_download https://github.com/LukeZGD/Legacy-iOS-Kit-Keys/releases/download/a/freeze5.tar.gz freeze5.tar.gz 15c92613d4f7e6bbabd9bd3521db8e4baf032265
  1307.                 mv freeze5.tar.gz ../saved/
  1308.             fi
  1309.  
  1310.             # skip untether stuff for 3gs 3.x, kernel is patched for those
  1311.             if [[ $device_type == "iPhone2,1" && $vers == "3."* ]]; then
  1312.                 :
  1313.             elif [[ $untether != 1 ]]; then
  1314.                 log "Sending $untether"
  1315.                 $scp -P $ssh_port $jelbrek/$untether root@127.0.0.1:/mnt1
  1316.                 case $vers in
  1317.                     4.2.[8761] | 4.[10]* | 3.* ) untether="${device_type}_${build}.tar";; # remove folder name after sending tar
  1318.                 esac
  1319.  
  1320.                 # temporary measure for a5 ios 5
  1321.                 if [[ $device_proc == 5 && $vers == "5."* ]]; then
  1322.                     untether="${device_type}_${build}.tar"
  1323.                 fi
  1324.  
  1325.                 # 3.1.3–4.1 untether must be extracted before data partition mount
  1326.                 case $vers in
  1327.                     4.[10]* | 3.2* | 3.1.3 )
  1328.                         log "Extracting $untether"
  1329.                         $ssh -p $ssh_port root@127.0.0.1 "tar -xvf /mnt1/$untether -C /mnt1; rm /mnt1/$untether"
  1330.                     ;;
  1331.                 esac
  1332.             fi
  1333.  
  1334.             log "Mounting data partition"
  1335.             $ssh -p $ssh_port root@127.0.0.1 "mount.sh pv"
  1336.  
  1337.             # do stuff
  1338.             case $vers in
  1339.                 [98].* ) device_send_rdtar fstab8.tar;;
  1340.                 7.*    ) device_send_rdtar fstab7.tar;;
  1341.                 6.*    ) device_send_rdtar fstab_rw.tar;;
  1342.                 4.2.[8761] )
  1343.                     log "launchd to punchd"
  1344.                     $ssh -p $ssh_port root@127.0.0.1 "[[ ! -e /mnt1/sbin/punchd ]] && mv /mnt1/sbin/launchd /mnt1/sbin/punchd"
  1345.                 ;;
  1346.             esac
  1347.             case $vers in
  1348.                 [43].* )
  1349.                     log "fstab"
  1350.                     local fstab="fstab_new" # disk0s2s1 data
  1351.                     if [[ $device_proc == 1 || $device_type == "iPod2,1" ]]; then
  1352.                         fstab="fstab_old" # disk0s2 data
  1353.                     fi
  1354.                     $scp -P $ssh_port $jelbrek/$fstab root@127.0.0.1:/mnt1/private/etc/fstab
  1355.                 ;;
  1356.             esac
  1357.  
  1358.             # untether extraction
  1359.             case $vers in
  1360.                 8.* ) # extract now if everuntether, later if daibutsu+dsc haxx
  1361.                     if [[ $ipsw_everuntether == 1 ]]; then
  1362.                         log "Extracting $untether"
  1363.                         $ssh -p $ssh_port root@127.0.0.1 "tar -xvf /mnt1/$untether -C /mnt1; rm /mnt1/$untether"
  1364.                     fi
  1365.                 ;;
  1366.                 4.[10]* | 3.* ) :;; # already extracted
  1367.                 * )
  1368.                     if [[ $untether != 1 ]]; then
  1369.                         log "Extracting $untether"
  1370.                         $ssh -p $ssh_port root@127.0.0.1 "tar -xvf /mnt1/$untether -C /mnt1; rm /mnt1/$untether"
  1371.                     fi
  1372.                 ;;
  1373.             esac
  1374.  
  1375.             # bootstrap extraction
  1376.             if [[ $otherfreeze == 1 ]]; then
  1377.                 # 4.3.x 3gs'es have little free space in rootfs. workaround: extract an older strap that takes less space
  1378.                 cp ../saved/freeze5.tar.gz $jelbrek/
  1379.                 device_send_rdtar freeze5.tar gz
  1380.                 rm $jelbrek/freeze5.tar.gz
  1381.             else
  1382.                 device_send_rdtar freeze.tar gz
  1383.             fi
  1384.  
  1385.             # extras extraction
  1386.             if [[ $ipsw_openssh == 1 ]]; then
  1387.                 device_send_rdtar sshdeb.tar
  1388.                 device_send_rdtar openssh.tar gz
  1389.                 device_send_rdtar openssl.tar gz
  1390.             fi
  1391.             case $vers in
  1392.                 [543]* ) device_send_rdtar cydiasubstrate.tar;;
  1393.             esac
  1394.             case $vers in
  1395.                 9.* ) device_send_rdtar launchctl.tar; device_send_rdtar zebra.tar;;
  1396.                 3.* ) device_send_rdtar cydiahttpatch.tar;;
  1397.             esac
  1398.             case $vers in
  1399.                 [43].* ) :;;
  1400.                 * ) device_send_rdtar LukeZGD.tar;;
  1401.             esac
  1402.  
  1403.             # remove patcyh except for ios 8.3+ where it's required
  1404.             case $vers in
  1405.                 9.* | 8.[43]* ) :;;
  1406.                 * )
  1407.                     $ssh -p $ssh_port root@127.0.0.1 "cd /mnt1; rm Library/MobileSubstrate/DynamicLibraries/patcyh* private/lib/dpkg/info/com.saurik.patcyh* usr/lib/libpatcyh.dylib"
  1408.                     device_send_rdtar nopatcyh.tar
  1409.                 ;;
  1410.             esac
  1411.  
  1412.             # final setup for ios 8.x daibutsu, and/or reboot
  1413.             if [[ $vers == "8."* && $ipsw_everuntether != 1 ]] || [[ $vers == "7."* ]]; then
  1414.                 log "Sending daibutsu/move.sh"
  1415.                 $scp -P $ssh_port $jelbrek/daibutsu/move.sh root@127.0.0.1:/mnt1
  1416.                 log "Moving files"
  1417.                 $ssh -p $ssh_port root@127.0.0.1 "bash /mnt1/move.sh $vers; rm /mnt1/move.sh"
  1418.  
  1419.                 if [[ $vers == "7."* ]]; then
  1420.                     log "Rebooting"
  1421.                     $ssh -p $ssh_port root@127.0.0.1 "reboot_bak"
  1422.                 else
  1423.                     untether="untether.tar"
  1424.                     log "Extracting $untether"
  1425.                     $ssh -p $ssh_port root@127.0.0.1 "tar -xvf /mnt1/$untether -C /mnt1; rm /mnt1/$untether"
  1426.                     log "Running haxx_overwrite --${device_type}_${build}"
  1427.                     $ssh -p $ssh_port root@127.0.0.1 "/usr/bin/haxx_overwrite --${device_type}_${build}"
  1428.                 fi
  1429.  
  1430.             else
  1431.                 log "Rebooting"
  1432.                 $ssh -p $ssh_port root@127.0.0.1 "reboot_bak"
  1433.             fi
  1434.  
  1435.             log "Cool, done and jailbroken (hopefully)"
  1436.             return
  1437.         ;;
  1438.  
  1439.         "clearnvram" )
  1440.             log "Sending commands for clearing NVRAM..."
  1441.             $ssh -p $ssh_port root@127.0.0.1 "nvram -c; reboot_bak"
  1442.             log "Done. Your device should reboot now"
  1443.             return
  1444.         ;;
  1445.  
  1446.         "setnvram" )
  1447.             device_ramdisk_setnvram
  1448.             $ssh -p $ssh_port root@127.0.0.1 "reboot_bak"
  1449.             log "Done. Your device should reboot now"
  1450.             return
  1451.         ;;
  1452.  
  1453.         * ) log "Device should now boot to SSH ramdisk mode.";;
  1454.     esac
  1455.  
  1456.     echo
  1457.     print "* Mount filesystems with this command:"
  1458.     print "    mount.sh"
  1459.     print "* For more details, go to: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/SSH-Ramdisk"
  1460.  
  1461.     menu_ramdisk
  1462. }
  1463.  
  1464. device_ramdisk_setnvram() {
  1465.     log "Sending commands for setting NVRAM variables..."
  1466.     $ssh -p $ssh_port root@127.0.0.1 "nvram -c; nvram boot-partition=$rec"
  1467.     if [[ $rec == 2 ]]; then
  1468.         case $device_type in
  1469.             iPad1,1 | iPhone3,1 | iPod3,1 )
  1470.                 if [[ $device_type != "iPhone3,1" ]]; then
  1471.                     device_ramdisk_iosvers
  1472.                     if [[ $device_vers == "3"* ]]; then
  1473.                         device_ramdisk_ios3exploit
  1474.                     fi
  1475.                 fi
  1476.             ;;
  1477.             * ) $ssh -p $ssh_port root@127.0.0.1 "nvram boot-ramdisk=/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/0/1/2/3/4/5/6/7/8/9/A/B/C/disk.dmg";;
  1478.         esac
  1479.     elif [[ $device_type == "iPad1,1" ]]; then
  1480.         device_ramdisk_iosvers
  1481.         if [[ $device_vers == "3"* && -n $($ssh -p $ssh_port root@127.0.0.1 "ls /mnt1/bin/bash 2>/dev/null") ]]; then
  1482.             untether="${device_type}_${device_build}.tar"
  1483.             log "Sending $untether"
  1484.             $scp -P $ssh_port $jelbrek/greenpois0n/$untether root@127.0.0.1:/mnt1
  1485.             log "Extracting $untether"
  1486.             $ssh -p $ssh_port root@127.0.0.1 "tar -xvf /mnt1/$untether -C /mnt1; rm /mnt1/$untether"
  1487.         fi
  1488.     fi
  1489.     log "Done"
  1490. }
  1491.  
  1492. device_ramdisk_ios3exploit() {
  1493.     log "iOS 3.x detected, running exploit commands"
  1494.     local fdisk_out="$($ssh -p $ssh_port [email protected] "fdisk /dev/rdisk0")"
  1495.     echo "$fdisk_out"
  1496.     local offset="$(echo "$fdisk_out" | grep AF | head -1)"
  1497.     offset="${offset##*-}"
  1498.     offset="$(echo ${offset%]*} | tr -d ' ')"
  1499.     offset=$((offset+63))
  1500.     local sector_size="$(echo "$fdisk_out" | grep "Sector size" | awk '{print $3}')"
  1501.     local partition_size=$((65536/sector_size))
  1502.     log "Got offset $offset"
  1503.     log "Got sector size $sector_size. Partition size will be $partition_size"
  1504.     $ssh -p $ssh_port root@127.0.0.1 "echo -e 'e 3\nAF\n\n${offset}\n${partition_size}\nw\ny\nq\n' | fdisk -e /dev/rdisk0"
  1505.     echo
  1506.     log "Writing exploit ramdisk"
  1507.     $scp -P $ssh_port ../resources/firmware/src/target/$device_model/9B206/exploit root@127.0.0.1:/
  1508.     $ssh -p $ssh_port root@127.0.0.1 "dd of=/dev/rdisk0s3 if=/exploit bs=64k count=1"
  1509.     if [[ $device_type == "iPad1,1" ]]; then
  1510.         $scp -P $ssh_port ../saved/iPad1,1/iBoot3_$device_ecid root@127.0.0.1:/mnt1/iBEC
  1511.     fi
  1512.     if [[ -n $($ssh -p $ssh_port root@127.0.0.1 "ls /mnt1/bin/bash 2>/dev/null") ]]; then
  1513.         log "fstab"
  1514.         $scp -P $ssh_port $jelbrek/fstab_new root@127.0.0.1:/mnt1/private/etc/fstab
  1515.         untether="${device_type}_${device_build}.tar"
  1516.         log "Sending $untether"
  1517.         $scp -P $ssh_port $jelbrek/greenpois0n/$untether root@127.0.0.1:/mnt1
  1518.         log "Extracting $untether"
  1519.         $ssh -p $ssh_port root@127.0.0.1 "tar -xvf /mnt1/$untether -C /mnt1; rm /mnt1/$untether"
  1520.     fi
  1521.     log "Fixing autoboot"
  1522.     $ssh -p $ssh_port root@127.0.0.1 "nvram auto-boot=1"
  1523. }
  1524.  
  1525. device_datetime_cmd() {
  1526.     log "Running command to Update DateTime"
  1527.     $ssh -p $ssh_port root@127.0.0.1 "date -s @$(date +%s)"
  1528.     if [[ $1 != "nopause" ]]; then
  1529.         log "Done"
  1530.         pause
  1531.     fi
  1532. }
  1533.  
  1534. device_ramdisk_iosvers() {
  1535.     device_vers=
  1536.     device_build=
  1537.     device_datetime_cmd nopause
  1538.     if (( device_proc < 7 )); then
  1539.         log "Mounting root filesystem"
  1540.         $ssh -p $ssh_port root@127.0.0.1 "mount.sh root"
  1541.         sleep 1
  1542.     fi
  1543.     log "Getting iOS version"
  1544.     $scp -P $ssh_port root@127.0.0.1:/mnt1/System/Library/CoreServices/SystemVersion.plist .
  1545.     if [[ $platform == "macos" ]]; then
  1546.         rm -f BuildVer Version
  1547.         plutil -extract 'ProductVersion' xml1 SystemVersion.plist -o Version
  1548.         device_vers=$(cat Version | sed -ne '/<string>/,/<\/string>/p' | sed -e "s/<string>//" | sed "s/<\/string>//" | sed '2d')
  1549.         plutil -extract 'ProductBuildVersion' xml1 SystemVersion.plist -o BuildVer
  1550.         device_build=$(cat BuildVer | sed -ne '/<string>/,/<\/string>/p' | sed -e "s/<string>//" | sed "s/<\/string>//" | sed '2d')
  1551.     else
  1552.         device_vers=$(cat SystemVersion.plist | grep -i ProductVersion -A 1 | grep -oPm1 "(?<=<string>)[^<]+")
  1553.         device_build=$(cat SystemVersion.plist | grep -i ProductBuildVersion -A 1 | grep -oPm1 "(?<=<string>)[^<]+")
  1554.     fi
  1555.     if [[ -n $device_vers ]]; then
  1556.         log "Retrieved the current iOS version"
  1557.         print "* iOS Version: $device_vers ($device_build)"
  1558.     else
  1559.         warn "Something wrong happened. Failed to get iOS version."
  1560.     fi
  1561. }
  1562.  
  1563. menu_ramdisk() {
  1564.     local loop
  1565.     local menu_items=("Connect to SSH")
  1566.     local reboot="reboot_bak"
  1567.     if (( device_proc >= 7 )); then
  1568.         reboot="/sbin/reboot"
  1569.     else
  1570.         menu_items+=("Dump Baseband/Activation")
  1571.     fi
  1572.     if [[ $1 == "18C66" ]]; then
  1573.         menu_items+=("Install TrollStore")
  1574.     elif [[ $device_proc == 7 && $device_ramdisk_ios8 == 1 ]]; then
  1575.         log "Ramdisk should now boot and fix iOS 7 not booting."
  1576.     fi
  1577.     if [[ $device_ramdisk_ios8 != 1 ]]; then
  1578.         menu_items+=("Dump Blobs")
  1579.         if (( device_proc <= 8 )); then
  1580.             menu_items+=("Erase All (iOS 7 and 8)")
  1581.         fi
  1582.         if (( device_proc >= 5 )); then
  1583.             menu_items+=("Erase All (iOS 9+)")
  1584.         fi
  1585.         if [[ $device_canpowder == 1 ]]; then
  1586.             menu_items+=("Disable/Enable Exploit")
  1587.         fi
  1588.         if (( device_proc >= 7 )) && [[ $device_proc != 10 ]]; then
  1589.             menu_items+=("Install Bootstrap (iOS 7/8/9)")
  1590.         fi
  1591.         if [[ $device_proc == 7 ]]; then
  1592.             menu_items+=("Install Untether (iOS 7)")
  1593.         fi
  1594.         menu_items+=("Install OpenSSH (iOS 10 and lower)" "Clear NVRAM" "Get iOS Version" "Update DateTime")
  1595.     fi
  1596.     menu_items+=("Reboot Device" "Exit")
  1597.  
  1598.     print "* For accessing data, note the following:"
  1599.     print "* Host: sftp://127.0.0.1 | User: root | Password: alpine | Port: $ssh_port"
  1600.     echo
  1601.     print "* Other Useful SSH Ramdisk commands:"
  1602.     print "* Clear NVRAM with this command:"
  1603.     print "    nvram -c"
  1604.     print "* Erase All Content and Settings with this command (iOS 9+ only):"
  1605.     print "    nvram oblit-inprogress=5"
  1606.     print "* To reboot, use this command:"
  1607.     print "    $reboot"
  1608.     echo
  1609.  
  1610.     while [[ $loop != 1 ]]; do
  1611.         mode=
  1612.         print "* SSH Ramdisk Menu"
  1613.         while [[ -z $mode ]]; do
  1614.             input "Select an option:"
  1615.             select_option "${menu_items[@]}"
  1616.             selected="${menu_items[$?]}"
  1617.             case $selected in
  1618.                 "Connect to SSH" ) mode="ssh";;
  1619.                 "Reboot Device" ) mode="reboot";;
  1620.                 "Dump Blobs" ) mode="dump-blobs";;
  1621.                 "Get iOS Version" ) mode="iosvers";;
  1622.                 "Dump Baseband/Activation" ) mode="dump-bbactrec";;
  1623.                 "Install TrollStore" ) mode="trollstore";;
  1624.                 "Erase All (iOS 7 and 8)" ) mode="erase78";;
  1625.                 "Erase All (iOS 9+)" ) mode="erase9";;
  1626.                 "Clear NVRAM" ) mode="clearnvram";;
  1627.                 "Disable/Enable Exploit" ) menu_remove4;;
  1628.                 "Update DateTime" ) mode="datetime";;
  1629.                 "Install Bootstrap (iOS 7/8/9)" ) mode="bootstrap";;
  1630.                 "Install Untether (iOS 7)" ) mode="untether7";;
  1631.                 "Install OpenSSH (iOS 10 and lower)" ) mode="openssh";;
  1632.                 "Exit" ) mode="exit";;
  1633.             esac
  1634.         done
  1635.  
  1636.         case $mode in
  1637.             "ssh" )
  1638.                 log "Use the \"exit\" command to go back to SSH Ramdisk Menu"
  1639.                 if [[ $device_ramdisk_ios8 == 1 ]]; then
  1640.                     $ssh -p $ssh_port root@127.0.0.1 &
  1641.                     ssh_pid=$!
  1642.                     sleep 1
  1643.                     kill $ssh_pid
  1644.                 fi
  1645.                 $ssh -p $ssh_port root@127.0.0.1
  1646.             ;;
  1647.             "reboot" ) $ssh -p $ssh_port root@127.0.0.1 "$reboot"; loop=1;;
  1648.             "exit" ) loop=1;;
  1649.             "dump-blobs" )
  1650.                 local shsh="../saved/shsh/$device_ecid-$device_type-$(date +%Y-%m-%d-%H%M).shsh2"
  1651.                 if (( device_proc < 7 )); then
  1652.                     warn "This is the wrong place to dump onboard blobs for 32-bit devices."
  1653.                     print "* Reboot your device, run the script again and go to Save SHSH Blobs -> Onboard Blobs"
  1654.                     print "* For more details, go to: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Saving-onboard-SHSH-blobs-of-current-iOS-version"
  1655.                     pause
  1656.                     continue
  1657.                 fi
  1658.                 log "Attempting to dump blobs"
  1659.                 $ssh -p $ssh_port root@127.0.0.1 "cat /dev/rdisk1" | dd of=dump.raw bs=256 count=$((0x4000))
  1660.                 if [[ ! -s dump.raw ]]; then
  1661.                     warn "Dumping rdisk1 failed, cannot continue."
  1662.                     continue
  1663.                 fi
  1664.                 "$dir/img4tool" --convert -s $shsh dump.raw
  1665.                 if [[ -s $shsh ]]; then
  1666.                     log "Onboard blobs should be dumped to $shsh"
  1667.                     continue
  1668.                 fi
  1669.                 warn "Failed to convert raw dump to SHSH."
  1670.                 local raw="../saved/shsh/rawdump_${device_ecid}-${device_type}_$(date +%Y-%m-%d-%H%M).raw"
  1671.                 mv dump.raw $raw
  1672.                 log "Raw dump saved at: $raw"
  1673.                 warn "This raw dump is not usable for restoring, you need to convert it first."
  1674.                 print "* If unable to be converted, this dump is likely not usable for restoring."
  1675.             ;;
  1676.             "iosvers" )
  1677.                 if (( device_proc >= 7 )); then
  1678.                     print "* Unfortunately the mount command needs to be done manually for 64-bit devices."
  1679.                     print "* The mount command also changes depending on the iOS version (which is what we're trying to get here in the first place)"
  1680.                     print "* You need to mount filesystems using the appropriate command before continuing (scroll up to see the commands)"
  1681.                     warn "Make sure that you know what you are doing when using this option on 64-bit devices."
  1682.                     select_yesno
  1683.                     if [[ $? != 1 ]]; then
  1684.                         continue
  1685.                     fi
  1686.                 fi
  1687.                 device_ramdisk_iosvers
  1688.             ;;
  1689.             "dump-bbactrec" ) device_dumprd;;
  1690.             "trollstore" )
  1691.                 print "* Make sure that your device is on iOS 14 or 15 before continuing, and have the Tips app installed."
  1692.                 print "* If your device is on iOS 13 or below, TrollStore will NOT work."
  1693.                 select_yesno
  1694.                 if [[ $? != 1 ]]; then
  1695.                     continue
  1696.                 fi
  1697.                 log "Checking for latest TrollStore"
  1698.                 download_from_url "https://api.github.com/repos/opa334/TrollStore/releases/latest" latest
  1699.                 local latest="$(cat latest | $jq -r ".tag_name")"
  1700.                 local current="$(cat ../saved/TrollStore_version 2>/dev/null || echo "none")"
  1701.                 log "Latest version: $latest, current version: $current"
  1702.                 if [[ $current != "$latest" ]]; then
  1703.                     rm -f ../saved/TrollStore.tar ../saved/PersistenceHelper_Embedded
  1704.                 fi
  1705.                 if [[ -s ../saved/TrollStore.tar && -s ../saved/PersistenceHelper_Embedded ]]; then
  1706.                     cp ../saved/TrollStore.tar ../saved/PersistenceHelper_Embedded .
  1707.                 else
  1708.                     rm -f ../saved/TrollStore.tar ../saved/PersistenceHelper_Embedded
  1709.                     log "Downloading files for latest TrollStore"
  1710.                     file_download https://github.com/opa334/TrollStore/releases/download/$latest/PersistenceHelper_Embedded PersistenceHelper_Embedded
  1711.                     file_download https://github.com/opa334/TrollStore/releases/download/$latest/TrollStore.tar TrollStore.tar
  1712.                     mv TrollStore.tar PersistenceHelper_Embedded ../saved
  1713.                     echo "$latest" > ../saved/TrollStore_version
  1714.                 fi
  1715.                 tar -xf TrollStore.tar
  1716.                 log "Installing TrollStore to Tips"
  1717.                 $ssh -p $ssh_port root@127.0.0.1 "mount_filesystems"
  1718.                 local tips="$($ssh -p $ssh_port [email protected] "find /mnt2/containers/Bundle/Application/ -name \"Tips.app\"")"
  1719.                 $scp -P $ssh_port PersistenceHelper_Embedded TrollStore.app/trollstorehelper ../resources/sshrd/trollstore.sh root@127.0.0.1:$tips
  1720.                 rm -r PersistenceHelper_Embedded TrollStore*
  1721.                 $ssh -p $ssh_port root@127.0.0.1 "bash $tips/trollstore.sh; rm $tips/trollstore.sh"
  1722.                 log "Done!"
  1723.             ;;
  1724.             "erase78" )
  1725.                 log "Please read the message below:"
  1726.                 warn "This will do a \"Erase All Content and Settings\" procedure for iOS 7 and 8 devices."
  1727.                 warn "Do NOT do this if your device is jailbroken untethered!!!"
  1728.                 print "* This procedure will do step 6 of this tutorial: https://reddit.com/r/LegacyJailbreak/comments/13of20g/tutorial_new_restoringerasingwipingrescuing_a/"
  1729.                 print "* Note that it may also be better to do this process manually instead by following the commands in the tutorial."
  1730.                 print "* For iOS 8 devices, also remove this file if you will be doing it manually: /mnt2/mobile/Library/SpringBoard/LockoutStateJournal.plist"
  1731.                 if (( device_proc >= 7 )); then
  1732.                     print "* If your device is on iOS 7, make sure to boot an iOS 8 ramdisk afterwards to fix booting."
  1733.                 fi
  1734.                 print "* When the device boots back up, trigger a restore by entering wrong passwords 10 times."
  1735.                 select_yesno
  1736.                 if [[ $? != 1 ]]; then
  1737.                     continue
  1738.                 fi
  1739.                 $ssh -p $ssh_port root@127.0.0.1 "/sbin/mount_hfs /dev/disk0s1s1 /mnt1; /sbin/mount_hfs /dev/disk0s1s2 /mnt2; cp /com.apple.springboard.plist /mnt1/"
  1740.                 $ssh -p $ssh_port root@127.0.0.1 "cd /mnt2/mobile/Library/Preferences; mv com.apple.springboard.plist com.apple.springboard.plist.bak; ln -s /com.apple.springboard.plist ./com.apple.springboard.plist"
  1741.                 $ssh -p $ssh_port root@127.0.0.1 "rm /mnt2/mobile/Library/SpringBoard/LockoutStateJournal.plist"
  1742.                 $ssh -p $ssh_port root@127.0.0.1 "sync; cd /; /sbin/umount /mnt2; /sbin/umount /mnt1; sync; /sbin/reboot"
  1743.                 log "Done. Your device should reboot now"
  1744.                 print "* Proceed to trigger a restore by entering wrong passwords 10 times."
  1745.                 loop=1
  1746.             ;;
  1747.             "clearnvram" )
  1748.                 log "Sending command for clearing NVRAM..."
  1749.                 $ssh -p $ssh_port root@127.0.0.1 "/usr/sbin/nvram -c"
  1750.                 log "Done"
  1751.             ;;
  1752.             "erase9" )
  1753.                 warn "This will do a \"Erase All Content and Settings\" procedure for iOS 9+ devices."
  1754.                 warn "Do NOT do this if your device is jailbroken untethered!!! (mostly iOS 9.3.4/9.1 and lower)"
  1755.                 select_yesno
  1756.                 if [[ $? != 1 ]]; then
  1757.                     continue
  1758.                 fi
  1759.                 log "Sending command for erasing all content and settings..."
  1760.                 $ssh -p $ssh_port root@127.0.0.1 "/usr/sbin/nvram oblit-inprogress=5"
  1761.                 log "Done. Reboot to apply changes, or clear NVRAM now to cancel erase"
  1762.             ;;
  1763.             "remove4" ) device_ramdisk_setnvram;;
  1764.             "datetime" ) device_datetime_cmd;;
  1765.             "bootstrap" )
  1766.                 log "Please read the message below:"
  1767.                 warn "This will install the jailbreak bootstrap with Cydia installed to your device."
  1768.                 warn "Do NOT continue if your device is not a 64-bit device on iOS 7/8/9! Also do this at your own risk."
  1769.                 warn "You might also need your device to be freshly restored/erased and never booted for this to work."
  1770.                 print "* This procedure will do the commands in this post: https://www.reddit.com/r/LegacyJailbreak/comments/1jwo0gr/tutorial_manually_install_bootstrap_to_64bit/"
  1771.                 select_yesno
  1772.                 if [[ $? != 1 ]]; then
  1773.                     continue
  1774.                 fi
  1775.                 $ssh -p $ssh_port root@127.0.0.1 "/sbin/mount_hfs /dev/disk0s1s1 /mnt1; /sbin/mount_hfs /dev/disk0s1s2 /mnt2"
  1776.                 device_ramdisk_iosvers
  1777.                 case $device_vers in
  1778.                     [789].* ) :;;
  1779.                     * )
  1780.                         log "iOS version does not seem to be in the supported range. Cannot continue."
  1781.                         continue
  1782.                     ;;
  1783.                 esac
  1784.                 cp $jelbrek/freeze.tar.gz .
  1785.                 gzip -d freeze.tar.gz
  1786.                 cat freeze.tar | $ssh -p $ssh_port root@127.0.0.1 "cd /mnt1; tar -xvf - -C .; mv private/var/lib private"
  1787.                 if [[ $device_vers == "9"* ]]; then
  1788.                     cat $jelbrek/launchctl.tar | $ssh -p $ssh_port root@127.0.0.1 "tar -xvf - -C /mnt1"
  1789.                 fi
  1790.                 cp $jelbrek/openssh.tar.gz $jelbrek/openssl.tar.gz .
  1791.                 gzip -d openssh.tar.gz
  1792.                 gzip -d openssl.tar.gz
  1793.                 cat openssh.tar | $ssh -p $ssh_port root@127.0.0.1 "tar -xf - -C /mnt1"
  1794.                 cat openssl.tar | $ssh -p $ssh_port root@127.0.0.1 "tar -xf - -C /mnt1"
  1795.                 case $device_vers in
  1796.                     9.3.[45] ) :;;
  1797.                     9.[23]*  ) $scp -P $ssh_port $jelbrek/io.pangu93.loader.plist root@127.0.0.1:/mnt1/Library/LaunchDaemons;;
  1798.                     7.* | 8.[012]* ) # remove patcyh
  1799.                         $ssh -p $ssh_port root@127.0.0.1 "cd /mnt1; rm Library/MobileSubstrate/DynamicLibraries/patcyh* private/lib/dpkg/info/com.saurik.patcyh* usr/lib/libpatcyh.dylib"
  1800.                         cat $jelbrek/nopatcyh.tar | $ssh -p $ssh_port root@127.0.0.1 "cd /mnt1; tar -xvf - -C .; mv private/var/lib/dpkg/* private/lib/dpkg"
  1801.                     ;;
  1802.                 esac
  1803.                 $ssh -p $ssh_port root@127.0.0.1 "cd /mnt1; mv private/var/mobile/Library/Preferences/com.apple.springboard.plist private; rm -r private/var/*; touch .cydia_no_stash"
  1804.                 $ssh -p $ssh_port root@127.0.0.1 "cd /mnt2; ln -s /private/lib; cd mobile/Library/Preferences; rm -f com.apple.springboard.plist; ln -s /private/com.apple.springboard.plist; /usr/sbin/chown 501:501 com.apple.springboard.plist"
  1805.                 log "Installing bootstrap done."
  1806.                 if [[ $device_proc == 7 ]]; then
  1807.                     print "* If your device is on iOS 7, proceed to Install Untether next."
  1808.                 fi
  1809.             ;;
  1810.             "untether7" )
  1811.                 log "Please read the message below:"
  1812.                 warn "This will install the iOS 7 untether for your device and iOS version. Make sure that bootstrap is already installed."
  1813.                 warn "Do NOT continue if your device is not on iOS 7! Also do this at your own risk."
  1814.                 select_yesno
  1815.                 if [[ $? != 1 ]]; then
  1816.                     continue
  1817.                 fi
  1818.                 $ssh -p $ssh_port root@127.0.0.1 "/sbin/mount_hfs /dev/disk0s1s1 /mnt1"
  1819.                 device_ramdisk_iosvers
  1820.                 if [[ $device_vers != "7."* ]]; then
  1821.                     log "iOS version does not seem to be in the supported range. Cannot continue."
  1822.                     continue
  1823.                 fi
  1824.                 local untether
  1825.                 case $device_vers in
  1826.                     "7.1"* ) untether="panguaxe.tar";;
  1827.                     "7.0"  ) untether="evasi0n7-untether-70.tar";;
  1828.                     "7.0"* ) untether="evasi0n7-untether.tar";;
  1829.                 esac
  1830.                 cat $jelbrek/$untether | $ssh -p $ssh_port root@127.0.0.1 "tar -xf - -C /mnt1"
  1831.                 input "Stashing to free up space on system partition"
  1832.                 print "* When enabled, Cydia will move some components to the data partition on its first run."
  1833.                 print "* This frees up more space for installing tweaks."
  1834.                 print "* However, this option can be unstable and lead to bootloop issues."
  1835.                 print "* This option is disabled by default (N). Disable this option if unsure."
  1836.                 select_yesno "Enable this option?" 0
  1837.                 if [[ $? != 0 ]]; then
  1838.                     log "Stashing option enabled by user."
  1839.                     $ssh -p $ssh_port root@127.0.0.1 "cd /mnt1; rm .cydia_no_stash"
  1840.                 else
  1841.                     log "Stashing disabled."
  1842.                 fi
  1843.             ;;
  1844.             "openssh" )
  1845.                 log "Please read the message below:"
  1846.                 warn "This will install files for OpenSSH to your device. Make sure that your device is jailbroken, and filesystems are already mounted."
  1847.                 warn "Do NOT continue if your device is not jailbroken. Also do this at your own risk."
  1848.                 select_yesno
  1849.                 if [[ $? != 1 ]]; then
  1850.                     continue
  1851.                 fi
  1852.                 if (( device_proc < 7 )); then
  1853.                     device_ramdisk_iosvers
  1854.                     $ssh -p $ssh_port root@127.0.0.1 "mount.sh pv"
  1855.                 fi
  1856.                 cp $jelbrek/openssh.tar.gz $jelbrek/openssl.tar.gz .
  1857.                 gzip -d openssh.tar.gz
  1858.                 gzip -d openssl.tar.gz
  1859.                 cat openssh.tar | $ssh -p $ssh_port root@127.0.0.1 "tar -xf - -C /mnt1"
  1860.                 cat openssl.tar | $ssh -p $ssh_port root@127.0.0.1 "tar -xf - -C /mnt1"
  1861.                 if (( device_proc < 7 )); then
  1862.                     cat $jelbrek/sshdeb.tar | $ssh -p $ssh_port root@127.0.0.1 "tar -xf - -C /mnt1"
  1863.                 fi
  1864.                 log "Done."
  1865.             ;;
  1866.         esac
  1867.     done
  1868. }
  1869.  
  1870. shsh_save_onboard64() {
  1871.     if [[ $device_latest_vers != "16"* && $device_checkm8ipad != 1 ]]; then
  1872.         print "* There are other ways for dumping onboard blobs for 64-bit devices as listed below:"
  1873.         print "* It is recommended to use SSH Ramdisk option to dump onboard blobs instead: Useful Utilities -> SSH Ramdisk"
  1874.         print "* For A8 and newer, you can also use SSHRD_Script: https://github.com/verygenericname/SSHRD_Script"
  1875.         select_yesno
  1876.         if [[ $? != 1 ]]; then
  1877.             return 1
  1878.         fi
  1879.     elif (( device_vers_maj >= 16 )); then
  1880.         print "* Make sure to have the following installed for Cryptex:"
  1881.         print "    libkrw0 1.1.2, libkrw0-tfp0 1.1.2, libx8a4-1, x8A4"
  1882.         print "* You may install these from this repo: https://lukezgd.github.io/x8a4"
  1883.         print "* You may also install debs from here: https://github.com/Cryptiiiic/x8A4/releases"
  1884.     fi
  1885.     echo
  1886.     if [[ $device_mode != "Normal" ]]; then
  1887.         warn "Device must be in normal mode and jailbroken, cannot continue."
  1888.         print "* Use the SSH Ramdisk option instead: Useful Utilities -> SSH Ramdisk"
  1889.         print "* For A8 and newer, you can also use SSHRD_Script: https://github.com/verygenericname/SSHRD_Script"
  1890.         return
  1891.     fi
  1892.     log "Proceeding to dump onboard blobs on normal mode"
  1893.     device_iproxy
  1894.     device_ssh_message
  1895.     device_sshpass
  1896.     local shsh="../saved/shsh/$device_ecid-$device_type-$device_vers-$device_build.shsh2"
  1897.     local shsh2
  1898.     local disk
  1899.     if [[ $ssh_user == "mobile" ]]; then
  1900.         disk="echo '$SSHPASS' | sudo -S "
  1901.     fi
  1902.     if (( device_vers_maj >= 16 )); then
  1903.         shsh2="$shsh"
  1904.         shsh="temp.shsh2"
  1905.         disk+="cat /dev/disk2"
  1906.     else
  1907.         disk+="cat /dev/disk1"
  1908.     fi
  1909.     $ssh -p $ssh_port ${ssh_user}@127.0.0.1 "$disk" | dd of=dump.raw bs=256 count=$((0x4000))
  1910.     "$dir/img4tool" --convert -s $shsh dump.raw
  1911.     if [[ -s $shsh && -n $shsh2 ]]; then
  1912.         log "Grabbing Cryptex APTicket"
  1913.         $ssh -p $ssh_port ${ssh_user}@127.0.0.1 "cat /private/preboot/cryptex1/current/apticket*" > apticket.im4m
  1914.         log "Getting Cryptex seed using x8A4"
  1915.         local seed="$($ssh -p $ssh_port ${ssh_user}@127.0.0.1 "echo '$SSHPASS' | sudo -S x8A4 -x | grep 0x | cut -c 19- | cut -c -34")"
  1916.         echo
  1917.         if [[ -z $seed ]]; then
  1918.             error "Failed to get Cryptex seed. Make sure x8A4 and dependencies are installed."
  1919.         fi
  1920.         cat $shsh | sed '$d' | sed '$d' > temp2.shsh2
  1921.         echo -e "<key>cryptexTicket</key><dict>\n<key>Cryptex1,Ticket</key><data>" >> temp2.shsh2
  1922.         cat apticket.im4m | base64 >> temp2.shsh2
  1923.         echo -e "</data></dict>\n<key>cryptexSeed</key>\n<string>$seed</string>\n</dict></plist>" >> temp2.shsh2
  1924.         shsh="$shsh2"
  1925.         mv temp2.shsh2 $shsh
  1926.     elif [[ ! -s $shsh ]]; then
  1927.         warn "Failed to convert raw dump to SHSH."
  1928.         if [[ -s dump.raw ]]; then
  1929.             local raw="../saved/shsh/rawdump_${device_ecid}-${device_type}-${device_vers}-${device_build}_$(date +%Y-%m-%d-%H%M).raw"
  1930.             mv dump.raw $raw
  1931.             log "Raw dump saved at: $raw"
  1932.             warn "This raw dump is not usable for restoring, you need to convert it first."
  1933.             print "* If unable to be converted, this dump is likely not usable for restoring."
  1934.         fi
  1935.         if [[ $device_latest_vers == "16"* || $device_checkm8ipad == 1 ]]; then
  1936.             error "Saving onboard SHSH blobs failed. Make sure to have OpenSSH installed."
  1937.         else
  1938.             error "Saving onboard SHSH blobs failed. Make sure to have OpenSSH installed." \
  1939.                   "* It is recommended to dump onboard SHSH blobs on SSH Ramdisk instead."
  1940.         fi
  1941.     fi
  1942.     log "Successfully saved $device_vers blobs: $shsh"
  1943.     kill $iproxy_pid
  1944. }
  1945.  
  1946. shsh_save_onboard() {
  1947.     if (( device_proc >= 7 )); then
  1948.         shsh_save_onboard64
  1949.         [[ $? == 0 ]] && pause
  1950.         return
  1951.     else
  1952.         device_buttons
  1953.     fi
  1954.     if [[ $device_proc == 4 && $device_pwnrec != 1 ]]; then
  1955.         patch_ibss
  1956.         log "Sending iBSS..."
  1957.         $irecovery -f pwnediBSS.dfu
  1958.     fi
  1959.     sleep 1
  1960.     patch_ibec
  1961.     log "Sending iBEC..."
  1962.     $irecovery -f pwnediBEC.dfu
  1963.     if [[ $device_pwnrec == 1 ]]; then
  1964.         $irecovery -c "go"
  1965.     fi
  1966.     device_find_mode Recovery
  1967.     log "Dumping raw dump now"
  1968.     (echo -e "/send ../resources/payload\ngo blobs\n/exit") | $irecovery2 -s
  1969.     $irecovery2 -g dump.raw
  1970.     log "Rebooting device"
  1971.     $irecovery -n
  1972.     local raw
  1973.     local err
  1974.     shsh_convert_onboard $1
  1975.     err=$?
  1976.     if [[ $1 == "dump" ]]; then
  1977.         raw="../saved/shsh/rawdump_${device_ecid}-${device_type}_$(date +%Y-%m-%d-%H%M)_${shsh_onboard_iboot}.raw"
  1978.     else
  1979.         raw="../saved/shsh/rawdump_${device_ecid}-${device_type}-${device_target_vers}-${device_target_build}_$(date +%Y-%m-%d-%H%M)_${shsh_onboard_iboot}.raw"
  1980.     fi
  1981.     if [[ $1 == "dump" ]] || [[ $err != 0 && -s dump.raw ]]; then
  1982.         mv dump.raw $raw
  1983.         log "Raw dump saved at: $raw"
  1984.         warn "This raw dump is not usable for restoring, you need to convert it first."
  1985.         print "* If unable to be converted, this dump is likely not usable for restoring."
  1986.         print "* For the IPSW to download and use, see the raw dump iBoot version above"
  1987.         print "* Then go here to find the matching iOS version: https://theapplewiki.com/wiki/IBoot_(Bootloader)"
  1988.     fi
  1989. }
  1990.  
  1991. shsh_convert_onboard() {
  1992.     local shsh="../saved/shsh/${device_ecid}-${device_type}_$(date +%Y-%m-%d-%H%M).shsh"
  1993.     if (( device_proc < 7 )); then
  1994.         shsh="../saved/shsh/${device_ecid}-${device_type}-${device_target_vers}-${device_target_build}.shsh"
  1995.         # remove ibob for powdersn0w/dra downgraded devices. fixes unknown magic 69626f62
  1996.         local blob=$(xxd -p dump.raw | tr -d '\n')
  1997.         local bobi="626f6269"
  1998.         local blli="626c6c69"
  1999.         if [[ $blob == *"$bobi"* ]]; then
  2000.             log "Detected \"ibob\". Fixing... (This happens on DRA/powdersn0w downgraded devices)"
  2001.             rm -f dump.raw
  2002.             printf "%s" "${blob%"$bobi"*}${blli}${blob##*"$blli"}" | xxd -r -p > dump.raw
  2003.         fi
  2004.         shsh_onboard_iboot="$(cat dump.raw | strings | grep iBoot | head -1)"
  2005.         log "Raw dump iBoot version: $shsh_onboard_iboot"
  2006.         if [[ $1 == "dump" ]]; then
  2007.             return
  2008.         fi
  2009.         log "Converting raw dump to SHSH blob"
  2010.         "$dir/ticket" dump.raw dump.shsh "$ipsw_path.ipsw" -z
  2011.         log "Attempting to validate SHSH blob"
  2012.         "$dir/validate" dump.shsh "$ipsw_path.ipsw" -z
  2013.         if [[ $? != 0 ]]; then
  2014.             warn "Saved SHSH blobs might be invalid. Did you select the correct IPSW?"
  2015.             print "* If you selected the correct IPSW and the error is not APTicket and/or LLB, the blob is most likely usable."
  2016.         fi
  2017.     else
  2018.         "$dir/img4tool" --convert -s dump.shsh dump.raw
  2019.     fi
  2020.     if [[ ! -s dump.shsh ]]; then
  2021.         warn "Converting onboard SHSH blobs failed."
  2022.         return 1
  2023.     fi
  2024.     mv dump.shsh $shsh
  2025.     log "Successfully saved $device_target_vers blobs: $shsh"
  2026. }
  2027.  
  2028. shsh_save_cydia() {
  2029.     download_from_url "https://api.ipsw.me/v4/device/${device_type}?type=ipsw" tmp.json
  2030.     local json=$(cat tmp.json)
  2031.     local len=$(echo "$json" | $jq -r ".firmwares | length")
  2032.     local builds=()
  2033.     local i=0
  2034.     while (( i < len )); do
  2035.         builds+=($(echo "$json" | $jq -r ".firmwares[$i].buildid"))
  2036.         ((i++))
  2037.     done
  2038.     for build in ${builds[@]}; do
  2039.         if [[ $build == "10"* && $build != "10B329" && $build != "10B350" ]]; then
  2040.             continue
  2041.         fi
  2042.         printf "\n%s " "$build"
  2043.         $tsschecker -d $device_type -e $device_ecid --server-url "http://cydia.saurik.com/TSS/controller?action=2/" -s -g 0x1111111111111111 --buildid $build >/dev/null
  2044.         if [[ $(ls *$build* 2>/dev/null) ]]; then
  2045.             printf "saved"
  2046.             mv $(ls *$build*) ../saved/shsh/$device_ecid-$device_type-$build.shsh
  2047.         else
  2048.             printf "failed"
  2049.         fi
  2050.     done
  2051.     echo
  2052. }
  2053.  
  2054. menu_print_info() {
  2055.     if [[ $debug_mode != 1 ]]; then
  2056.         clear
  2057.     fi
  2058.     print " *** Legacy iOS Kit ***"
  2059.     print " - Script by LukeZGD -"
  2060.     echo
  2061.     if [[ -n $version_current ]]; then
  2062.         print "* Version: $version_current ($git_hash)"
  2063.     fi
  2064.     if [[ $no_internet_check == 1 ]]; then
  2065.         warn "No internet check flag detected, check is disabled and no support will be provided."
  2066.     fi
  2067.     if [[ $no_version_check == 1 ]]; then
  2068.         warn "No version check flag detected, check is disabled and no support will be provided."
  2069.     fi
  2070.     if [[ $EUID == 0 && $run_as_root == 1 ]]; then
  2071.         warn "Script is running as root. This is not supported, proceed with caution."
  2072.     fi
  2073.     if [[ $git_hash_latest != "$git_hash" ]]; then
  2074.         warn "Current version is newer/different than remote: $version_latest ($git_hash_latest)"
  2075.     fi
  2076.     print "* Platform: $platform ($platform_ver - $platform_arch) $live_session_str"
  2077.     if [[ $platform == "macos" && $platform_arch == "arm64" ]]; then
  2078.         if (( mac_majver == 12 && mac_minver < 6 )) || (( mac_majver < 12 )); then
  2079.             warn "Updating to macOS 12.6 or newer is recommended for Apple Silicon Macs."
  2080.         fi
  2081.     fi
  2082.     echo
  2083.     if [[ $device_argmode == "entry" ]]; then
  2084.         warn "Device type and/or ECID manually specified"
  2085.     fi
  2086.     print "* Device: $device_name (${device_type} - ${device_model}ap) in $device_mode mode"
  2087.     device_manufacturing
  2088.     if [[ $device_unactivated == 1 ]]; then
  2089.         print "* Device is not activated, select Attempt Activation to activate."
  2090.     fi
  2091.     if [[ $device_disable_actrec == 1 ]]; then
  2092.         warn "disable-actrec flag detected, activation dumping/stitching disabled. Proceed with caution"
  2093.     fi
  2094.     if [[ $device_type == "$device_disable_bbupdate" && $device_use_bb != 0 ]] && (( device_proc < 7 )); then
  2095.         if [[ $device_deadbb == 1 ]]; then
  2096.             warn "dead-bb flag detected, baseband flashing disabled. Your device will not activate after restore"
  2097.         else
  2098.             warn "disable-bbupdate flag detected, baseband stitching enabled. Proceed with caution"
  2099.             print "* Current device baseband will be dumped and stitched to custom IPSW"
  2100.             warn "Note that stitching baseband does not always work! There is a chance of non-working baseband after the restore"
  2101.         fi
  2102.     elif [[ -n $device_disable_bbupdate ]]; then
  2103.         warn "disable-bbupdate flag detected, but this flag is not supported for this device"
  2104.     fi
  2105.     if [[ -n $device_disable_bbupdate ]]; then
  2106.         print "* For more details, go to: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Baseband-Update"
  2107.     fi
  2108.     if [[ $ipsw_jailbreak == 1 ]] && (( device_proc < 7 )); then
  2109.         warn "Jailbreak flag detected. Jailbreak option enabled."
  2110.     fi
  2111.     if [[ $device_proc != 1 ]] && (( device_proc < 7 )); then
  2112.         case $device_proc in
  2113.             [56] )
  2114.                 if [[ $device_imei == "9900"* ]]; then
  2115.                     warn "Your device's IMEI starts with 9900. These devices are affected by an activation issue."
  2116.                 elif [[ $device_9900candidate == 1 && $device_mode == "Normal" && -n $device_imei ]]; then
  2117.                     print "* Your device's IMEI does not start with 9900. Your device should be safe from the activation issue."
  2118.                 elif [[ $device_9900candidate == 1 && $device_mode != "Normal" ]]; then
  2119.                     warn "Your device is possibly affected by an activation issue. Please check your device's IMEI."
  2120.                     print "* If it starts with 9900, enable Activation Records stitching in Misc Utilities"
  2121.                 elif [[ $device_type == "iPad3,3" ]]; then
  2122.                     warn "Your device is an iPad3,3. These devices are affected by an activation issue."
  2123.                     [[ $device_unactivated != 2 ]] && print "* If you haven't already, dump activation by selecting Activation Records in Misc Utilities"
  2124.                 fi
  2125.             ;;
  2126.         esac
  2127.         if [[ $device_auto_actrec == 1 ]]; then
  2128.             print "* Activated A${device_proc}(X) device with 9900 IMEI detected. Activation Records stitching enabled."
  2129.         elif [[ $device_auto_actrec == 2 ]]; then
  2130.             print "* Existing activation records detected. Activation Records stitching enabled."
  2131.         elif [[ $device_auto_actrec == 3 ]]; then
  2132.             print "* Activated iPad3,3 detected. Activation Records stitching enabled."
  2133.         elif [[ $device_actrec == 1 ]]; then
  2134.             warn "activation-records flag detected. Activation Records stitching enabled."
  2135.         fi
  2136.         if [[ $device_pwnrec == 1 ]]; then
  2137.             warn "Pwned recovery flag detected. Assuming device is in pwned recovery mode."
  2138.         elif [[ $device_skip_ibss == 1 ]]; then
  2139.             warn "Skip iBSS flag detected. Assuming device is in pwned iBSS mode."
  2140.         fi
  2141.         if [[ $ipsw_gasgauge_patch == 1 ]]; then
  2142.             warn "gasgauge-patch/multipatch flag detected. multipatch enabled."
  2143.         fi
  2144.         if [[ $ipsw_skip_first == 1 ]]; then
  2145.             warn "skip-first flag detected. Skipping first restore and flashing part 2 IPSW only for powdersn0w 4.2.x and lower"
  2146.         fi
  2147.     elif (( device_proc >= 7 )) && (( device_proc <= 10 )); then
  2148.         if [[ $restore_useskipblob == 1 ]]; then
  2149.             warn "skip-blob flag detected. futurerestore will have --skip-blob enabled."
  2150.         fi
  2151.         if [[ $restore_usedev == 1 ]]; then
  2152.             warn "use-dev flag detected. futurerestore dev branch will be used."
  2153.         fi
  2154.         if [[ $restore_usepwndfu64 == 1 ]]; then
  2155.             warn "use-pwndfu flag detected. futurerestore will have --use-pwndfu enabled."
  2156.         fi
  2157.     fi
  2158.     if [[ -n $device_build ]]; then
  2159.         print "* iOS Version: $device_vers ($device_build)"
  2160.     else
  2161.         print "* iOS Version: $device_vers"
  2162.     fi
  2163.     if [[ $device_proc != 1 && $device_mode == "DFU" ]] && (( device_proc < 7 )); then
  2164.         print "* To get iOS version, go to: Misc Utilities -> Get iOS Version"
  2165.     fi
  2166.     if [[ $device_proc != 1 || $device_type == "iPhone1,2" ]]; then
  2167.         print "* ECID: $device_ecid"
  2168.     fi
  2169.     if [[ -n $device_pwnd ]]; then
  2170.         print "* Pwned: $device_pwnd"
  2171.     fi
  2172.     echo
  2173. }
  2174.  
  2175. menu_main() {
  2176.     local menu_items
  2177.     local selected
  2178.     local back
  2179.     while [[ -z "$mode" ]]; do
  2180.         menu_items=()
  2181.         menu_print_info
  2182.         print " > Main Menu"
  2183.         input "Select an option:"
  2184.         if [[ $device_mode != "none" ]]; then
  2185.             menu_items+=("Restore/Downgrade")
  2186.             if (( device_proc < 7 )); then
  2187.                 menu_items+=("Jailbreak Device")
  2188.                 if [[ $device_proc != 1 && $device_type != "iPod2,1" ]]; then
  2189.                     case $device_mode in
  2190.                         "Recovery" | "DFU" ) menu_items+=("Just Boot");;
  2191.                     esac
  2192.                 fi
  2193.             fi
  2194.             if [[ $device_unactivated == 1 ]]; then
  2195.                 menu_items+=("Attempt Activation")
  2196.             elif [[ $device_mode == "Recovery" ]]; then
  2197.                 menu_items+=("Exit Recovery Mode")
  2198.             elif [[ $device_mode == "WTF" && $debug_mode == 1 ]]; then
  2199.                 menu_items+=("Enter pwnDFU Mode")
  2200.             elif [[ $device_mode == "Normal" ]] && (( device_proc >= 8 )); then
  2201.                 if (( device_vers_maj == 15 && device_vers_min >= 2 )) || # ios 15.2+
  2202.                    (( device_vers_maj == 16 && device_vers_min <= 6 )) || # ios 16.0-16.6.1
  2203.                    [[ $device_vers == "17.0" || $device_build == "20H18" ]]; then # ios 17.0 and 16.7 20h18
  2204.                     menu_items+=("Install TrollStore")
  2205.                 fi
  2206.             fi
  2207.         fi
  2208.         if [[ $device_proc != 1 && $device_type != "iPod2,1" ]] && (( device_proc < 11 )); then
  2209.             menu_items+=("Save SHSH Blobs")
  2210.         fi
  2211.         if [[ $device_mode == "Normal" ]]; then
  2212.             case $device_vers in
  2213.                 [12].*  ) :;;
  2214.                 [126789]* ) menu_items+=("Sideload IPA");;
  2215.             esac
  2216.             menu_items+=("App Management" "Data Management")
  2217.         fi
  2218.         if [[ $device_mode != "none" ]]; then
  2219.             menu_items+=("Useful Utilities")
  2220.         fi
  2221.         menu_items+=("Misc Utilities")
  2222.         if [[ $device_mode == "Normal" ]] && (( device_vers_maj >= 7 )); then
  2223.             menu_items+=("Pair Device")
  2224.         fi
  2225.         menu_items+=("Exit")
  2226.         select_option "${menu_items[@]}"
  2227.         selected="${menu_items[$?]}"
  2228.         case $selected in
  2229.             "Restore/Downgrade" ) menu_restore;;
  2230.             "Jailbreak Device" ) device_jailbreak_confirm;;
  2231.             "Save SHSH Blobs" ) menu_shsh;;
  2232.             "Sideload IPA" ) menu_ipa "$selected";;
  2233.             "App Management" ) menu_appmanage;;
  2234.             "Data Management" ) menu_datamanage;;
  2235.             "Misc Utilities" ) menu_miscutilities;;
  2236.             "Useful Utilities" ) menu_usefulutilities;;
  2237.             "Attempt Activation" ) device_activate;;
  2238.             "Exit Recovery Mode" ) mode="exitrecovery";;
  2239.             "Just Boot" ) menu_justboot;;
  2240.             "Pair Device" ) device_pair;;
  2241.             "Install TrollStore" )
  2242.                 print "* This option will install TrollStore to your device using TrollRestore."
  2243.                 print "* This method of installing TrollStore is compatible with iOS 15.2-15.8.x, 16.0-16.6.1, 16.7 RC, and 17.0."
  2244.                 select_yesno
  2245.                 if [[ $? != 1 ]]; then
  2246.                     continue
  2247.                 fi
  2248.                 mode="device_trollrestore"
  2249.             ;;
  2250.             "Exit" ) mode="exit";;
  2251.         esac
  2252.     done
  2253. }
  2254.  
  2255. menu_appmanage() {
  2256.     local menu_items
  2257.     local selected
  2258.     local back
  2259.  
  2260.     menu_print_info
  2261.     print "* For more info about App Management options, go here: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/App-Management"
  2262.     while [[ -z "$mode" && -z "$back" ]]; do
  2263.         menu_items=()
  2264.         if [[ $device_unactivated == 1 ]]; then
  2265.             warn "Device is not activated. Most App Management options are not available."
  2266.         fi
  2267.         if (( device_vers_maj >= 5 )); then
  2268.             if [[ $device_vers_maj == 10 ]]; then
  2269.                 [[ $device_unactivated != 1 ]] && menu_items+=("Install IPA (ideviceinstaller)")
  2270.                 menu_items+=("Install IPA (appinst)")
  2271.             else
  2272.                 menu_items+=("Install IPA (appinst)")
  2273.                 [[ $device_unactivated != 1 ]] && menu_items+=("Install IPA (ideviceinstaller)")
  2274.             fi
  2275.         else
  2276.             [[ $device_unactivated != 1 ]] && menu_items+=("Install IPA (ideviceinstaller)")
  2277.         fi
  2278.         if (( device_vers_maj >= 4 )); then
  2279.             menu_items+=("Dump App as IPA" "Dump All Apps as IPA")
  2280.         fi
  2281.         [[ $device_unactivated != 1 ]] && menu_items+=("List User Apps" "List System Apps" "List All Apps")
  2282.         menu_items+=("Go Back")
  2283.         print " > Main Menu > App Management"
  2284.         input "Select an option:"
  2285.         select_option "${menu_items[@]}"
  2286.         selected="${menu_items[$?]}"
  2287.         case $selected in
  2288.             "Install IPA"*          ) menu_ipa "$selected";;
  2289.             "Dump App as IPA"       ) device_dumpapp;;
  2290.             "Dump All Apps as IPA"  ) device_dumpapp all;;
  2291.             "List User Apps"        ) device_pair; $ideviceinstaller list --user;;
  2292.             "List System Apps"      ) device_pair; $ideviceinstaller list --system;;
  2293.             "List All Apps"         ) device_pair; $ideviceinstaller list --all;;
  2294.             "Go Back" ) back=1;;
  2295.         esac
  2296.     done
  2297. }
  2298.  
  2299. menu_datamanage() {
  2300.     local menu_items=("Connect to SSH")
  2301.     local selected
  2302.     local back
  2303.  
  2304.     menu_print_info
  2305.     print "* For more info about Data Management options, go here: https://github.com/LukeZGD/Legacy-iOS-Kit/wiki/Data-Management"
  2306.     if [[ -z $sshfs ]]; then
  2307.         warn "sshfs not installed. Mount Device options are not available. Install sshfs from your package manager to fix this"
  2308.         [[ $platform == "macos" ]] && print "* On macOS, install fuse-t-sshfs"
  2309.     else
  2310.         menu_items+=("Mount Device" "Mount Device (Raw File System)" "Cydia App Install")
  2311.     fi
  2312.     if (( device_vers_maj < 4 )); then
  2313.         warn "Device is on lower than iOS 4. Backup and Restore options are not available."
  2314.     else
  2315.         menu_items+=("Backup" "Restore" "Encryption")
  2316.     fi
  2317.     if (( device_vers_maj >= 9 )); then
  2318.         menu_items+=("Erase All Content and Settings")
  2319.     fi
  2320.     menu_items+=("Go Back")
  2321.     while [[ -z "$mode" && -z "$back" ]]; do
  2322.         echo
  2323.         print " > Main Menu > Data Management"
  2324.         input "Select an option:"
  2325.         select_option "${menu_items[@]}"
  2326.         selected="${menu_items[$?]}"
  2327.         case $selected in
  2328.             "Go Back" ) back=1;;
  2329.             "Backup"  )
  2330.                 print "* A backup of your device will be created. Please see the notes above."
  2331.                 select_yesno
  2332.                 if [[ $? != 1 ]]; then
  2333.                     continue
  2334.                 fi
  2335.                 mode="device_backup_create"
  2336.             ;;
  2337.             "Restore" ) menu_backup_restore;;
  2338.             "Erase All Content and Settings" ) mode="device_erase";;
  2339.             "Mount Device"* | "Cydia App Install" )
  2340.                 local path="/var/mobile/Media"
  2341.                 case $selected in
  2342.                     *"Raw"*   ) path="/";;
  2343.                     *"Cydia"* ) path="/var/root/Media/Cydia/AutoInstall";;
  2344.                 esac
  2345.                 device_iproxy no-logging
  2346.                 device_ssh_message
  2347.                 device_sshpass
  2348.                 if [[ $selected == *"Cydia"* ]]; then
  2349.                     $ssh -p $ssh_port ${ssh_user}@127.0.0.1 "mkdir -p $path"
  2350.                     print "* Place the .deb files you want to install to the mount folder, then reboot the device afterwards."
  2351.                 fi
  2352.                 mkdir -p ../mount
  2353.                 if [[ $platform == "linux" ]]; then
  2354.                     $sshfs -o ssh_command="$(cd .. && pwd)/bin/linux/$platform_arch/sshpass -p$SSHPASS $(pwd)/ssh -F $(pwd)/ssh_config -p $ssh_port" -d ${ssh_user}@127.0.0.1:$path ../mount &>../saved/sshfs.log &
  2355.                     sshfs_pid=$!
  2356.                 else
  2357.                     $dir/sshpass -p$SSHPASS $sshfs -d -F $(pwd)/ssh_config -p $ssh_port ${ssh_user}@127.0.0.1:$path ../mount &>../saved/sshfs.log &
  2358.                     sshfs_pid=$!
  2359.                 fi
  2360.                 log "Device's \"$path\" should now be mounted on mount folder."
  2361.                 print "* If the mount folder is empty, make sure to have run \"Connect to SSH\" at least once."
  2362.                 print "* Press Enter/Return to unmount the device."
  2363.                 pause
  2364.                 umount ../mount 2>/dev/null
  2365.                 kill $iproxy_pid $sshfs_pid
  2366.             ;;
  2367.             "Connect to SSH" ) device_ssh;;
  2368.             "Encryption" ) menu_backup_encryption;;
  2369.         esac
  2370.     done
  2371. }
  2372.  
  2373. menu_backup_restore() {
  2374.     local menu_items
  2375.     local selected
  2376.     local back
  2377.  
  2378.     while [[ -z "$mode" && -z "$back" ]]; do
  2379.         menu_print_info
  2380.         local backupdir="../saved/backups/${device_ecid}_${device_type}"
  2381.         if [[ ! -d $backupdir ]]; then
  2382.             mkdir -p $backupdir
  2383.         fi
  2384.         local backups=($(ls $backupdir 2>/dev/null))
  2385.         if [[ -z "${backups[*]}" ]]; then
  2386.             print "* No backups (saved/backups)"
  2387.         else
  2388.             print "* Backups list (saved/backups):"
  2389.             for b in "${backups[@]}"; do
  2390.                 menu_items+=("$(basename $b)")
  2391.             done
  2392.         fi
  2393.         menu_items+=("Go Back")
  2394.         echo
  2395.         print " > Main Menu > Data Management > Restore"
  2396.         input "Select option to restore:"
  2397.         select_option "${menu_items[@]}"
  2398.         selected="${menu_items[$?]}"
  2399.         case $selected in
  2400.             "Go Back" ) back=1;;
  2401.             * )
  2402.                 device_backup="$selected"
  2403.                 print "* The selected backup $device_backup will be restored to the device."
  2404.                 select_yesno
  2405.                 if [[ $? != 1 ]]; then
  2406.                     device_backup=
  2407.                     continue
  2408.                 fi
  2409.                 mode="device_backup_restore"
  2410.             ;;
  2411.         esac
  2412.     done
  2413. }
  2414.  
  2415. menu_backup_encryption() {
  2416.     local menu_items
  2417.     local selected
  2418.     local back
  2419.  
  2420.     while [[ -z "$mode" && -z "$back" ]]; do
  2421.         menu_print_info
  2422.         menu_items=("Encryption On" "Encryption Off" "Change Password" "Go Back")
  2423.         echo
  2424.         print " > Main Menu > Data Management > Encryption"
  2425.         input "Select an option:"
  2426.         select_option "${menu_items[@]}"
  2427.         selected="${menu_items[$?]}"
  2428.         case $selected in
  2429.             "Encryption On"   ) "$dir/idevicebackup2" -i encryption on; pause;;
  2430.             "Encryption Off"  ) "$dir/idevicebackup2" -i encryption off; pause;;
  2431.             "Change Password" ) "$dir/idevicebackup2" -i changepw; pause;;
  2432.             "Go Back" ) back=1;;
  2433.         esac
  2434.     done
  2435. }
  2436.  
  2437. menu_fourthree() {
  2438.     local menu_items
  2439.     local selected
  2440.     local back
  2441.  
  2442.     ipa_path=
  2443.     ipsw_fourthree=
  2444.     while [[ -z "$mode" && -z "$back" ]]; do
  2445.         menu_items=("Step 1: Restore" "Step 2: Partition" "Step 3: OS Install")
  2446.         if [[ $device_mode == "Normal" ]]; then
  2447.             menu_items+=("Reinstall App" "Boot iOS 4.3.x")
  2448.         fi
  2449.         menu_items+=("Go Back")
  2450.         menu_print_info
  2451.         print "* FourThree Utility: Dualboot iPad 2 to iOS 4.3.x"
  2452.         print "* This is a 3 step process for the device. Follow through the steps to successfully set up a dualboot."
  2453.         print "* Please read the README here: https://github.com/LukeZGD/FourThree-iPad2"
  2454.         warn "Support for FourThree Utility is no longer provided. Any issues will not be entertained nor fixed."
  2455.         echo
  2456.         print " > Main Menu > FourThree Utility"
  2457.         input "Select an option:"
  2458.         select_option "${menu_items[@]}"
  2459.         selected="${menu_items[$?]}"
  2460.         case $selected in
  2461.             "Step 1: Restore" ) ipsw_fourthree=1; menu_ipsw "iOS 6.1.3" "fourthree";;
  2462.             "Step 2: Partition" ) mode="device_fourthree_step2";;
  2463.             "Step 3: OS Install" ) mode="device_fourthree_step3";;
  2464.             "Reinstall App" ) mode="device_fourthree_app";;
  2465.             "Boot iOS 4.3.x" ) mode="device_fourthree_boot";;
  2466.             "Go Back" ) back=1;;
  2467.         esac
  2468.     done
  2469. }
  2470.  
  2471. menu_ipa() {
  2472.     local menu_items
  2473.     local selected
  2474.     local back
  2475.  
  2476.     ipa_path=
  2477.     while [[ -z "$mode" && -z "$back" ]]; do
  2478.         menu_items=("Select IPA")
  2479.         menu_print_info
  2480.         if [[ $1 == "Install IPA (appinst)" ]]; then
  2481.             print "* Make sure that appinst and OpenSSH are installed on your device."
  2482.         elif [[ $1 == "Install IPA (ideviceinstaller)" ]]; then
  2483.             print "* Make sure that AppSync is installed on your device, if the IPA you are installing is cracked."
  2484.         else
  2485.             print "* Sideload IPA is for iOS 6 and newer. Sideloading will require an Apple ID."
  2486.             print "* Your Apple ID and password will only be sent to Apple servers."
  2487.             print "* Make sure that your iOS device is connected to the Internet."
  2488.             if [[ $platform == "linux" ]] && (( device_vers_maj >= 9 )); then
  2489.                 print "* There are 2 options for sideloading, \"using Sideloader\" is recommended."
  2490.             fi
  2491.             print "* If you have AppSync installed, or are installing an app with a valid"
  2492.             print "  signature, go to App Management -> Install IPA (ideviceinstaller) or (appinst) instead."
  2493.             if [[ $device_unactivated == 1 ]]; then
  2494.                 echo
  2495.                 warn "Device is not activated. Sideload IPA option is not available."
  2496.                 pause
  2497.                 break
  2498.             fi
  2499.         fi
  2500.         echo
  2501.         if [[ -n $ipa_path ]]; then
  2502.             print "* Selected IPA: $ipa_path"
  2503.             if [[ $1 == "Sideload"* ]]; then
  2504.                 if [[ $platform == "linux" ]]; then
  2505.                     menu_items+=("Install IPA using Sideloader")
  2506.                     if (( device_vers_maj >= 9 )); then
  2507.                         menu_items+=("Install IPA using AltServer")
  2508.                     fi
  2509.                 fi
  2510.             else
  2511.                 menu_items+=("Install IPA")
  2512.             fi
  2513.         elif [[ $1 == "Install"* ]]; then
  2514.             print "* Select IPA file(s) to install (multiple selection)"
  2515.         else
  2516.             print "* Select IPA file to install"
  2517.         fi
  2518.         if [[ $1 == "Sideload"* ]]; then
  2519.             menu_items+=("List and Revoke Certificate")
  2520.         fi
  2521.         menu_items+=("Go Back")
  2522.         echo
  2523.         print " > Main Menu > $1"
  2524.         input "Select an option:"
  2525.         select_option "${menu_items[@]}"
  2526.         selected="${menu_items[$?]}"
  2527.         case $selected in
  2528.             "Select IPA" ) menu_ipa_browse;;
  2529.             "Install IPA" )
  2530.                 if [[ $1 == "Install IPA (ideviceinstaller)" ]]; then
  2531.                     device_ideviceinstaller
  2532.                 else
  2533.                     device_appinst
  2534.                 fi
  2535.                 pause
  2536.             ;;
  2537.             "Install IPA using AltServer" )
  2538.                 device_altserver
  2539.                 pause
  2540.             ;;
  2541.             "Install IPA using Sideloader" )
  2542.                 device_sideloader
  2543.                 log "Checking for any existing certificates..."
  2544.                 local temp=$(mktemp)
  2545.                 $sideloader cert list | tee /dev/tty > "$temp"
  2546.                 local check=${PIPESTATUS[0]}
  2547.                 local revoke=$(grep -m1 "serial number" "$temp" | sed -E 's/.*number `//' | cut -c -32 | tr -dc '[:alnum:]')
  2548.                 if [[ $check != 0 ]]; then
  2549.                     warn "Sideloader returned an error. Incorrect Apple ID credentials?"
  2550.                     pause
  2551.                     continue
  2552.                 fi
  2553.                 if [[ -n $revoke ]]; then
  2554.                     log "Revoking existing certificate: $revoke"
  2555.                     $sideloader cert revoke $revoke
  2556.                 fi
  2557.                 log "Installing IPA using Sideloader..."
  2558.                 $sideloader install "$ipa_path"
  2559.                 local ret=$?
  2560.                 local ipa_base="$(basename "$ipa_path")"
  2561.                 local ipa_check="$(ls "/tmp/$ipa_base/Payload/"*".app/embedded.mobileprovision" 2>/dev/null)"
  2562.                 if [[ -s "$ipa_check" && $platform == "linux" && $ret != 0 ]]; then
  2563.                     log "Attempting Linux workaround..."
  2564.                     pushd "/tmp/$ipa_base"
  2565.                     zip -r0 Payload.ipa Payload
  2566.                     popd
  2567.                     device_pair
  2568.                     $ideviceinstaller install "/tmp/$ipa_base/Payload.ipa"
  2569.                 fi
  2570.                 print "* If you see an error but the app is in the home screen, the installation is most likely successful and the error can be safely ignored."
  2571.                 print "* If you see an error regarding certificate, you may need to revoke an existing certificate in your account."
  2572.                 print "* If you see an error regarding verification, make sure that your iOS device is connected to the Internet."
  2573.                 pause
  2574.             ;;
  2575.             "List and Revoke Certificate" )
  2576.                 device_sideloader
  2577.                 log "Checking for any existing certificates..."
  2578.                 $sideloader cert list
  2579.                 if [[ $? != 0 ]]; then
  2580.                     warn "Sideloader returned an error. Incorrect Apple ID credentials?"
  2581.                     pause
  2582.                     continue
  2583.                 fi
  2584.                 print "* Take note of the certificate serial number that you want to revoke."
  2585.                 local revoke
  2586.                 revoke=
  2587.                 while [[ -z $revoke ]]; do
  2588.                     read -p "$(input 'Certificate Serial Number: ')" revoke
  2589.                 done
  2590.                 $sideloader cert revoke $revoke
  2591.                 print "* If you see no error, the certificate should be revoked successfully."
  2592.                 pause
  2593.             ;;
  2594.             "Go Back" ) back=1;;
  2595.         esac
  2596.     done
  2597. }
  2598.  
  2599. device_sideloader() {
  2600.     local arch="$platform_arch"
  2601.     sideloader="sideloader-cli-"
  2602.     if [[ $platform == "macos" && $arch == "arm64" ]]; then
  2603.         arch="arm64-apple-macos"
  2604.     elif [[ $platform == "macos" ]]; then
  2605.         arch="x86_64-apple-darwin"
  2606.     elif [[ $arch == "arm64" ]]; then
  2607.         arch="aarch64-linux-gnu"
  2608.     else
  2609.         arch="x86_64-linux-gnu"
  2610.     fi
  2611.     sideloader+="$arch"
  2612.     log "Checking for latest Sideloader"
  2613.     download_from_url "https://api.github.com/repos/LukeZGD/Sideloader/releases/latest" latest
  2614.     local latest="$(cat latest | $jq -r ".tag_name")"
  2615.     local current="$(cat ../saved/Sideloader_version 2>/dev/null || echo "none")"
  2616.     log "Latest version: $latest, current version: $current"
  2617.     if [[ $current != "$latest" ]]; then
  2618.         rm -f ../saved/$sideloader
  2619.     fi
  2620.     if [[ ! -e ../saved/$sideloader ]]; then
  2621.         file_download https://github.com/LukeZGD/Sideloader/releases/download/$latest/$sideloader.zip $sideloader.zip
  2622.         file_extract_from_archive $sideloader.zip $sideloader
  2623.         mv $sideloader ../saved
  2624.     fi
  2625.     echo "$latest" > ../saved/Sideloader_version
  2626.     device_pair
  2627.     log "Launching Dadoum Sideloader"
  2628.     local apple_id="$APPLE_ID_USER"
  2629.     local apple_pass="$APPLE_ID_PWD"
  2630.     if [[ -z $apple_id || -z $apple_pass ]]; then
  2631.         log "Enter Apple ID details to continue."
  2632.         print "* Your Apple ID and password will only be sent to Apple servers."
  2633.     fi
  2634.     while [[ -z $apple_id ]]; do
  2635.         read -p "$(input 'Apple ID: ')" apple_id
  2636.     done
  2637.     export APPLE_ID_USER="$apple_id"
  2638.     print "* Your password input may not be visible, but it is still being entered."
  2639.     while [[ -z $apple_pass ]]; do
  2640.         read -s -p "$(input 'Password: ')" apple_pass
  2641.     done
  2642.     echo
  2643.     export APPLE_ID_PWD="$apple_pass"
  2644.     chmod +x ../saved/$sideloader
  2645.     sideloader="../saved/$sideloader"
  2646. }
  2647.  
  2648. menu_zenity_check() {
  2649.     if [[ $platform == "linux" && ! $(command -v zenity) ]]; then
  2650.         warn "zenity not found in PATH. Install zenity to have a working file picker."
  2651.     fi
  2652. }
  2653.  
  2654. menu_ipa_browse() {
  2655.     local newpath
  2656.     input "Select your IPA file(s) in the file selection window."
  2657.     menu_zenity_check
  2658.     newpath="$($zenity --file-selection --multiple --file-filter='IPA | *.ipa' --title="Select IPA file(s)")"
  2659.    [[ -z "$newpath" ]] && read -p "$(input "Enter path to IPA file (or press Enter/Return or Ctrl+C to cancel): ")" newpath
  2660.    ipa_path="$newpath"
  2661. }
  2662.  
  2663. menu_shsh() {
  2664.    local menu_items
  2665.    local selected
  2666.    local back
  2667.  
  2668.    device_target_vers=
  2669.    device_target_build=
  2670.    while [[ -z "$mode" && -z "$back" ]]; do
  2671.        menu_items=("Latest iOS ($device_latest_vers)")
  2672.        case $device_type in
  2673.            iPad4,[12345] | iPhone6,[12] )
  2674.                menu_items+=("iOS 10.3.3");;
  2675.            iPad[23]* | iPhone4,1 | iPhone5,[12] | iPod5,1 )
  2676.                menu_items+=("iOS 8.4.1");;
  2677.        esac
  2678.        case $device_type in
  2679.            iPad2,[123] | iPhone4,1 )
  2680.                menu_items+=("iOS 6.1.3");;
  2681.            iPhone1,2 | iPhone2,1 | iPod[23],1 )
  2682.                menu_items+=("iOS 4.1");;
  2683.        esac
  2684.        if (( device_proc < 7 )); then
  2685.            menu_items+=("Cydia Blobs")
  2686.        fi
  2687.        if [[ $device_type != "iPhone2,1" && $device_type != "iPod3,1" && $device_type != "iPad1,1" ]]; then
  2688.            if [[ $device_mode != "none" ]]; then
  2689.                menu_items+=("Onboard Blobs")
  2690.                if (( device_proc < 7 )); then
  2691.                    menu_items+=("Onboard Blobs (Raw Dump)")
  2692.                fi
  2693.            fi
  2694.            menu_items+=("Convert Raw Dump")
  2695.        fi
  2696.        menu_items+=("Go Back")
  2697.        menu_print_info
  2698.        print " > Main Menu > Save SHSH Blobs"
  2699.        input "Select an option:"
  2700.        select_option "${menu_items[@]}"
  2701.        selected="${menu_items[$?]}"
  2702.        case $selected in
  2703.            "Latest iOS"* )
  2704.                device_target_vers="$device_latest_vers"
  2705.                device_target_build="$device_latset_build"
  2706.            ;;
  2707.            "iOS 10.3.3" )
  2708.                device_target_vers="10.3.3"
  2709.                device_target_build="14G60"
  2710.            ;;
  2711.            "iOS 8.4.1" )
  2712.                device_target_vers="8.4.1"
  2713.                device_target_build="12H321"
  2714.            ;;
  2715.            "iOS 6.1.3" )
  2716.                device_target_vers="6.1.3"
  2717.                device_target_build="10B329"
  2718.            ;;
  2719.            "iOS 4.1" )
  2720.                device_target_vers="4.1"
  2721.                device_target_build="8B117"
  2722.            ;;
  2723.        esac
  2724.        target_vers_maj=$(echo "$device_target_vers" | cut -d. -f1)
  2725.        target_vers_min=$(echo "$device_target_vers" | cut -d. -f2)
  2726.        case $selected in
  2727.            *"iOS"* ) shsh_save; pause;;
  2728.            "Onboard Blobs" ) menu_shsh_onboard;;
  2729.            "Onboard Blobs (Raw Dump)" )
  2730.                print "* This option will save onboard blobs of your device, but only as a raw dump. You will need to convert them to be usable."
  2731.                print "* This option is useful for determining the iBoot version of your device first, to get the correct IPSW for conversion."
  2732.                print "* Use the Convert Raw Dump option for converting raw dumps to usable SHSH blobs."
  2733.                select_yesno
  2734.                if [[ $? != 1 ]]; then
  2735.                    continue
  2736.                fi
  2737.                shsh_save_onboard dump
  2738.                pause
  2739.            ;;
  2740.  
  2741.            "Cydia Blobs" )
  2742.                print "* This option will check if this device has saved blobs in Cydia servers, and proceed to save them if there are any."
  2743.                select_yesno
  2744.                if [[ $? != 1 ]]; then
  2745.                    continue
  2746.                fi
  2747.                shsh_save_cydia
  2748.                pause
  2749.            ;;
  2750.            "Convert Raw Dump" ) menu_shsh_convert;;
  2751.            "Go Back" ) back=1;;
  2752.        esac
  2753.    done
  2754. }
  2755.  
  2756. menu_shsh_onboard() {
  2757.    local menu_items
  2758.    local selected
  2759.    local back
  2760.  
  2761.    ipsw_path=
  2762.    if (( device_proc >= 7 )); then
  2763.        shsh_save_onboard
  2764.        return
  2765.    fi
  2766.    while [[ -z "$mode" && -z "$back" ]]; do
  2767.        menu_items=("Select IPSW")
  2768.        menu_print_info
  2769.        if [[ -n $ipsw_path ]]; then
  2770.            print "* Selected IPSW: $ipsw_path.ipsw"
  2771.            print "* IPSW Version: $device_target_vers-$device_target_build"
  2772.            if [[ $device_mode == "Normal" && $device_target_vers != "$device_vers" ]]; then
  2773.                warn "Selected IPSW does not seem to match the current version."
  2774.                print "* Ignore this warning if this is a DRA/powdersn0w downgraded device."
  2775.            fi
  2776.            menu_items+=("(*) Save Onboard Blobs")
  2777.        else
  2778.            print "* Select IPSW of your current iOS version to continue"
  2779.        fi
  2780.        menu_items+=("Go Back")
  2781.        echo
  2782.        print " > Main Menu > Save SHSH Blobs > Onboard Blobs"
  2783.        input "Select an option:"
  2784.        select_option "${menu_items[@]}"
  2785.        selected="${menu_items[$?]}"
  2786.        case $selected in
  2787.            "Select IPSW" ) menu_ipsw_browse onboard;;
  2788.            "(*) Save Onboard Blobs" ) mode="shsh_save_onboard";;
  2789.            "Go Back" ) back=1;;
  2790.        esac
  2791.    done
  2792. }
  2793.  
  2794. menu_shsh_convert() {
  2795.    local menu_items
  2796.    local selected
  2797.    local back
  2798.  
  2799.    ipsw_path=
  2800.    shsh_path=
  2801.    while [[ -z "$mode" && -z "$back" ]]; do
  2802.        menu_items=("Select Raw Dump")
  2803.        menu_print_info
  2804.        if [[ -n $shsh_path ]]; then
  2805.            print "* Selected dump: $shsh_path"
  2806.            if (( device_proc < 7 )); then
  2807.                shsh_onboard_iboot="$(cat "$shsh_path" | strings | grep iBoot | head -1)"
  2808.                print "* Raw dump iBoot version: $shsh_onboard_iboot"
  2809.                print "* Go here to find the matching iOS version: https://theapplewiki.com/wiki/IBoot_(Bootloader)"
  2810.                menu_items+=("Select IPSW")
  2811.            else
  2812.                menu_items+=("(*) Convert Raw Dump")
  2813.            fi
  2814.        else
  2815.            print "* Select raw dump file to continue"
  2816.        fi
  2817.        if [[ -n $ipsw_path ]]; then
  2818.            echo
  2819.            print "* Selected IPSW: $ipsw_path.ipsw"
  2820.            print "* IPSW Version: $device_target_vers-$device_target_build"
  2821.            if [[ $device_target_vers == "10"* ]]; then
  2822.                warn "Saving iOS 10 blobs is not supported, converting raw dump to SHSH blob will fail."
  2823.            fi
  2824.            menu_items+=("(*) Convert Raw Dump")
  2825.        elif (( device_proc < 7 )); then
  2826.            echo
  2827.            print "* Select IPSW of the raw dump's iOS version to continue"
  2828.        fi
  2829.        menu_items+=("Go Back")
  2830.        echo
  2831.        print " > Main Menu > Save SHSH Blobs > Convert Raw Dump"
  2832.        input "Select an option:"
  2833.        select_option "${menu_items[@]}"
  2834.        selected="${menu_items[$?]}"
  2835.        case $selected in
  2836.            "Select IPSW" ) menu_ipsw_browse;;
  2837.            "Select Raw Dump" ) menu_shshdump_browse;;
  2838.            "(*) Convert Raw Dump" )
  2839.                rm -f dump.raw
  2840.                cp "$shsh_path" dump.raw
  2841.                shsh_convert_onboard
  2842.                pause
  2843.            ;;
  2844.            "Go Back" ) back=1;;
  2845.        esac
  2846.    done
  2847. }
  2848.  
  2849. menu_restore() {
  2850.    local menu_items
  2851.    local selected
  2852.    local back
  2853.  
  2854.    while [[ -z "$mode" && -z "$back" ]]; do
  2855.        menu_items=()
  2856.        case $device_type in
  2857.            iPad4,[12345] | iPhone6,[12] )
  2858.                menu_items+=("iOS 10.3.3");;
  2859.            iPad2,[1234567] | iPad3,[123456] | iPhone4,1 | iPhone5,[12] | iPod5,1 )
  2860.                menu_items+=("iOS 8.4.1");;
  2861.        esac
  2862.        case $device_type in
  2863.            iPad2,[123] | iPhone4,1 )
  2864.                menu_items+=("iOS 6.1.3");;
  2865.            iPhone2,1 )
  2866.                menu_items+=("5.1.1" "4.3.5" "4.1" "3.1.3" "More versions");;
  2867.            iPod3,1 )
  2868.                menu_items+=("4.1");;
  2869.            iPhone1,2 | iPod2,1 )
  2870.                menu_items+=("4.1" "3.1.3")
  2871.                if [[ $device_type == "iPod2,1" ]] && [[ $device_newbr == 0 || $device_mode == "none" ]]; then
  2872.                    menu_items+=("More versions")
  2873.                fi
  2874.            ;;
  2875.        esac
  2876.        case $device_type in
  2877.            iPhone3,* | iPad1,1 | iPod3,1 )
  2878.                menu_items+=("powdersn0w (any iOS)");;
  2879.        esac
  2880.        if (( device_proc < 7 )) || [[ $platform == "linux" ]]; then
  2881.            menu_items+=("Latest iOS ($device_latest_vers)")
  2882.        fi
  2883.        case $device_type in
  2884.            iPod4,1 ) menu_items+=("7.1.2");;
  2885.            iPod3,1 ) menu_items+=("6.0" "6.1.3" "6.1.6");;
  2886.            iPad1,1 ) menu_items+=("6.1.3" "7.1.2");;
  2887.        esac
  2888.        if [[ $device_canpowder == 1 && $device_proc != 4 ]]; then
  2889.            menu_items+=("Other (powdersn0w $base_vers blobs)")
  2890.        fi
  2891.        if [[ $device_proc != 1 && $device_type != "iPod2,1" ]] && (( device_proc <= 10 )); then
  2892.            menu_items+=("Other (Use SHSH Blobs)")
  2893.            if (( device_proc < 7 )); then
  2894.                menu_items+=("Other (Tethered)")
  2895.            fi
  2896.        fi
  2897.        if [[ $1 != "ipsw" ]] && (( device_proc < 5 )); then
  2898.            menu_items+=("Other (Custom IPSW)")
  2899.        fi
  2900.        if (( device_proc < 7 )); then
  2901.            menu_items+=("DFU IPSW")
  2902.        elif (( device_proc >= 7 )) && (( device_proc <= 10 )); then
  2903.            menu_items+=("Set Nonce Only")
  2904.        fi
  2905.        menu_items+=("IPSW Downloader" "Go Back")
  2906.        menu_print_info
  2907.        if [[ $1 == "ipsw" ]]; then
  2908.            print " > Main Menu > Misc Utilities > Create Custom IPSW"
  2909.        else
  2910.            print " > Main Menu > Restore/Downgrade"
  2911.            if [[ $device_proc == 1 ]]; then
  2912.                print "* Select \"Other (Custom IPSW)\" to restore to other iOS versions (2.0 to 3.1.2) (1.x will not work)"
  2913.                echo
  2914.            elif [[ $device_type == "iPod2,1" && $device_newbr == 0 ]]; then
  2915.                print "* Select \"Other (Custom IPSW)\" to restore to other iOS versions (2.1.1 to 3.0)"
  2916.                echo
  2917.            elif [[ $device_type == "iPhone2,1" && $device_newbr != 0 ]]; then
  2918.                print "* Some new bootrom devices might be incompatible with older iOS versions"
  2919.                echo
  2920.            fi
  2921.        fi
  2922.        case $device_type in
  2923.            iPad2,4      ) print "* iPad2,4 does not support 6.1.3 downgrades, you need blobs for 6.1.3 or 7.1.x"; echo;;
  2924.            iPhone5,[34] ) print "* iPhone 5C does not support 8.4.1 downgrades, you need blobs for 8.4.1 or 7.x"; echo;;
  2925.            iPod4,1      ) print "* iPod touch 4 does not support any untethered downgrades without blobs"; echo;;
  2926.        esac
  2927.        if [[ $platform == "macos" ]] && (( device_proc >= 7 )); then
  2928.            print "* Note: Restoring to latest iOS for 64-bit devices is not supported on macOS, use iTunes/Finder instead for that"
  2929.            echo
  2930.        fi
  2931.        input "Select an option:"
  2932.        select_option "${menu_items[@]}"
  2933.        selected="${menu_items[$?]}"
  2934.        case $selected in
  2935.            "" ) :;;
  2936.            "Go Back" ) back=1;;
  2937.            "Other (Custom IPSW)" ) restore_customipsw_confirm;;
  2938.            "DFU IPSW" ) device_dfuipsw_confirm $1;;
  2939.            "More versions" ) menu_restore_more "$1";;
  2940.            "IPSW Downloader" ) menu_ipsw_downloader "$1";;
  2941.            7.* )
  2942.                case $device_type in
  2943.                    iPod4,1 | iPad1,1 ) menu_ipsw_special "$selected" "$1";;
  2944.                    * ) menu_ipsw "$selected" "$1";;
  2945.                esac
  2946.            ;;
  2947.            6.* )
  2948.                case $device_type in
  2949.                    iPod3,1 | iPad1,1 ) menu_ipsw_special "$selected" "$1";;
  2950.                    * ) menu_ipsw "$selected" "$1";;
  2951.                esac
  2952.            ;;
  2953.            * ) menu_ipsw "$selected" "$1";;
  2954.        esac
  2955.    done
  2956. }
  2957.  
  2958. menu_ipsw_downloader() {
  2959.    local menu_items
  2960.    local selected
  2961.    local back
  2962.    local build
  2963.  
  2964.    while [[ -z "$back" ]]; do
  2965.        menu_items=("Enter Build Version")
  2966.        if [[ -n $build ]]; then
  2967.            menu_items+=("(*) Start Download")
  2968.        fi
  2969.        menu_items+=("Go Back")
  2970.        menu_print_info
  2971.        if [[ $1 == "ipsw" ]]; then
  2972.            print " > Main Menu > Misc Utilities > Create Custom IPSW > IPSW Downloader"
  2973.        else
  2974.            print " > Main Menu > Restore/Downgrade > IPSW Downloader"
  2975.        fi
  2976.        print "* To know more about build version, go here: https://theapplewiki.com/wiki/Firmware"
  2977.        if [[ -n $build ]]; then
  2978.            print "* Build Version entered: $build"
  2979.        else
  2980.            print "* Enter build version to continue"
  2981.        fi
  2982.        echo
  2983.        input "Select an option:"
  2984.        select_option "${menu_items[@]}"
  2985.        selected="${menu_items[$?]}"
  2986.        case $selected in
  2987.            "Enter Build Version" )
  2988.                print "* Enter the build version of the IPSW you want to download."
  2989.                device_enter_build
  2990.                build="$device_rd_build"
  2991.            ;;
  2992.            "(*) Start Download" )
  2993.                device_target_build="$build"
  2994.                ipsw_download
  2995.                log "IPSW downloading is done"
  2996.                pause
  2997.            ;;
  2998.            "Go Back" ) device_rd_build=; back=1;;
  2999.        esac
  3000.    done
Add Comment
Please, Sign In to add comment