Last active
February 26, 2024 06:05
-
-
Save miticollo/80891d22615052150fc6f53390082e64 to your computer and use it in GitHub Desktop.
In a new macOS terminal run `bash ./futurerestore.sh <path/to/SHSH> <path/to/ipsw> -c` and follow instructions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Perform iOS and iPadOS downgrade using gaster and futurerestore. | |
set -e | |
BOLD=$(tput bold) | |
readonly BOLD | |
NC=$(tput sgr0) | |
readonly NC | |
# register the cleanup function to be called on the EXIT signal | |
trap cleanup EXIT | |
function err() { | |
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2 | |
} | |
function is_command_installed() { | |
if ! command -v "${1}" &> /dev/null | |
then | |
err "${1} could not be found" | |
exit 1 | |
fi | |
} | |
####################################### | |
# Deletes the temp directory. | |
# Globals: | |
# WORK_DIR | |
# Arguments: | |
# None | |
# Outputs: | |
# Writes location to stdout | |
####################################### | |
function cleanup { | |
# shellcheck disable=SC2317 | |
rm -rf "$WORK_DIR" | |
# shellcheck disable=SC2317 | |
echo "Deleted temp working directory $WORK_DIR" | |
} | |
function create_tmp_dir() { | |
WORK_DIR=$(mktemp -d) | |
readonly WORK_DIR | |
# check if tmp dir was created | |
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then | |
err "Could not create temp dir" | |
exit 1 | |
fi | |
} | |
function show_manual_action() { | |
echo | |
echo "${BOLD}${1}${NC}" | |
# shellcheck disable=SC2162 | |
read -p "Press enter to continue" | |
} | |
####################################### | |
# Detect the architecture of current | |
# macOS. | |
# Arguments: | |
# None | |
# Outputs: | |
# Writes an error msg if the current | |
# arch is not supported | |
# Credit: | |
# palera1n team | |
####################################### | |
function detect_arch() { | |
local arch_check | |
arch_check=$(uname -m) | |
case "${arch_check}" in | |
x86_64*) | |
arch=x86_64 | |
;; | |
arm64*) | |
arch=arm64 | |
;; | |
*) | |
error "Unknown or unsupported architecture ($arch_check)." | |
exit 1 | |
;; | |
esac | |
} | |
function main() { | |
is_command_installed 'git' | |
is_command_installed 'cmake' | |
is_command_installed 'gmake' | |
is_command_installed 'xcrun' | |
create_tmp_dir | |
pushd "${WORK_DIR}" || exit 2 | |
local download_version | |
download_version=$(curl -s "https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/main/" | awk -F'href="' '!/\.+\// && $2{print $2}' | awk -F'/' 'NF>1{print $1}' | tail -1) | |
detect_arch | |
curl -o 'palera1n' -L "https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/main/${download_version}/binaries/palera1n-macos-${arch}" | |
chmod +x ./palera1n | |
set +e | |
xattr -d com.apple.quarantine ./palera1n | |
set -e | |
git clone --recursive --depth=1 -j8 https://github.com/0x7ff/gaster.git gaster | |
pushd ./gaster || exit 3 | |
gmake | |
popd || exit 4 | |
if [ "${3}" = "-c" ]; then | |
git clone --recursive -j8 -b 'cryptex' 'https://github.com/futurerestore/futurerestore.git' 'futurerestore-src' | |
curl -o 'deps.tar.zst' -LO "https://cdn.cryptiiiic.com/deps/static/macOS/${arch}/macOS_${arch}_Debug_Latest.tar.zst" | |
tar xvvf ./'deps.tar.zst' -C ./futurerestore-src/dep_root | |
pushd ./futurerestore-src || exit 5 | |
git cherry-pick 9554c0068dc50e141872ced5da2bd95baa595805^..36879969be71d56af062aa99be5f28ee482a12bc | |
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM="$(which gmake)" -DCMAKE_C_COMPILER="$(which clang)" -DCMAKE_CXX_COMPILER="$(which clang++)" -DCMAKE_MESSAGE_LOG_LEVEL="WARNING" -G "CodeBlocks - Unix Makefiles" -S ./ -B cmake-build-debug -DARCH=${arch} -DNO_PKGCFG=1 | |
gmake -j$(($(/usr/sbin/sysctl -n hw.logicalcpu) + 1)) -l4 -C cmake-build-debug | |
popd || exit 6 | |
cp -v ./futurerestore-src/cmake-build-debug/src/futurerestore ./ | |
else | |
curl -LO https://nightly.link/futurerestore/futurerestore/workflows/ci/main/futurerestore-macOS-DEBUG.zip | |
unzip -p futurerestore-macOS-DEBUG.zip | tar -xv | |
rm -v futurerestore*.zip | |
set +e | |
xattr -d com.apple.quarantine ./futurerestore | |
set -e | |
fi | |
# RELEVANT PART | |
./palera1n -l -D | |
sleep 2 | |
./gaster/gaster pwn | |
./gaster/gaster reset | |
sleep 2 | |
# --skip-blob is useful if you restore using an OTA update SHSH blob | |
if [ "${3}" = "-c" ]; then | |
# WORKAROUND from https://gist.github.com/mineek/bd8d0e002ce67e82831a23a8d7eceb3c by Mineek | |
./futurerestore -t "${1}" -d --no-cache --use-pwndfu --latest-sep --latest-baseband --skip-blob --set-nonce "${2}" | |
show_manual_action "Force reboot your iDevice using the button combination." | |
./palera1n -l -D >>/dev/null 2>&1 & | |
if command -v "irecovery" &> /dev/null; then | |
echo | |
echo "${BOLD}Waiting Recovery Mode...${NC}" | |
set +e | |
while :; do | |
if [[ "$(irecovery -m 2>/dev/null)" =~ "Recovery" ]]; then | |
break | |
else | |
sleep 1 | |
fi | |
done | |
set -e | |
else | |
# irecovery not found! Switch to manual mode (legacy). | |
show_manual_action "Wait Recovery Mode logo." | |
fi | |
kill %1 | |
./futurerestore -d -t "${1}" --latest-sep --latest-baseband "${2}" | |
else | |
./futurerestore -t "${1}" -d --no-cache --use-pwndfu --latest-sep --latest-baseband --skip-blob "${2}" | |
fi | |
popd | |
} | |
main "$@" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment