Files
palera1n/palera1n.sh
T

319 lines
13 KiB
Bash
Raw Normal View History

2022-09-17 08:34:50 -04:00
#!/usr/bin/env bash
set -e
# Variables
version="1.0.0"
os=$(uname)
dir="$(pwd)/binaries/$os"
# Functions
step() {
for i in $(seq "$1" -1 1); do
printf '\r\e[1;36m%s (%d) ' "$2" "$i"
sleep 1
done
printf '\r\e[0m%s (0)\n' "$2"
}
# Error handler
ERR_HANDLER () {
[ $? -eq 0 ] && exit
echo "[-] An error occurred"
2022-09-17 12:26:09 -04:00
if [ "$os" = 'Darwin' ]; then
2022-09-18 10:44:05 -04:00
if [ ! "$2" = '--dfu' ] || [ ! "$2" = '--recovery' ]; then
2022-09-17 12:26:09 -04:00
defaults write -g ignore-devices -bool false
defaults write com.apple.AMPDevicesAgent dontAutomaticallySyncIPods -bool false
killall Finder
fi
fi
2022-09-17 08:34:50 -04:00
}
trap ERR_HANDLER EXIT
if [ "$1" = 'clean' ]; then
rm -rf boot work
echo "[*] Removed the created boot files"
exit
fi
# Download gaster
if [ ! -e $dir/gaster ]; then
curl -sLO https://nightly.link/verygenericname/gaster/workflows/makefile/main/gaster-$os.zip
unzip gaster-$os.zip >> /dev/null
mv gaster $dir/
rm -rf gaster gaster-$os.zip
fi
2022-09-18 10:30:43 -04:00
# Check for pyimg4
if ! python3 -c 'import pkgutil; exit(not pkgutil.find_loader("pyimg4"))'; then
echo '[-] pyimg4 not installed. Press any key to install it, or press ctrl + c to cancel'
read -n 1 -s
python3 -m pip install pyimg4 > /dev/null
fi
2022-09-17 08:34:50 -04:00
# Re-create work dir if it exists, else, make it
if [ -e work ]; then
rm -rf work
mkdir work
else
mkdir work
fi
chmod +x $dir/*
echo "palera1n | Version $version"
2022-09-17 11:04:13 -04:00
echo "Written by Nebula | Some code by Nathan | Patching commands and ramdisk by Mineek | Loader app by Amy"
2022-09-17 08:34:50 -04:00
echo ""
2022-09-17 10:22:48 -04:00
# Get device's iOS version from ideviceinfo if in normal mode
2022-09-18 10:47:46 -04:00
if [ "$2" = '--dfu' ] || [ "$2" = '--recovery' ]; then
2022-09-17 10:22:48 -04:00
if [ -z "$3" ]; then
2022-09-18 10:44:05 -04:00
echo "[-] When using --dfu or --recovery, please pass the version you're device is on"
2022-09-17 10:22:48 -04:00
exit
else
version=$3
fi
else
if [ "$os" = 'Darwin' ]; then
2022-09-17 18:58:16 -04:00
if ! (system_profiler SPUSBDataType 2> /dev/null | grep 'Manufacturer: Apple Inc.' >> /dev/null); then
2022-09-17 10:22:48 -04:00
echo "[*] Waiting for device in normal mode"
fi
2022-09-17 16:09:06 +02:00
2022-09-17 18:58:16 -04:00
while ! (system_profiler SPUSBDataType 2> /dev/null | grep 'Manufacturer: Apple Inc.' >> /dev/null); do
2022-09-17 10:22:48 -04:00
sleep 1
done
defaults write -g ignore-devices -bool true
defaults write com.apple.AMPDevicesAgent dontAutomaticallySyncIPods -bool true
killall Finder
else
2022-09-17 18:58:16 -04:00
if ! (lsusb 2> /dev/null | grep ' Apple, Inc.' >> /dev/null); then
2022-09-17 10:22:48 -04:00
echo "[*] Waiting for device in normal mode"
fi
2022-09-17 18:58:16 -04:00
while ! (lsusb 2> /dev/null | grep ' Apple, Inc.' >> /dev/null); do
2022-09-17 10:22:48 -04:00
sleep 1
done
fi
2022-09-17 11:04:13 -04:00
version=$(ideviceinfo | grep "ProductVersion: " | sed 's/ProductVersion: //')
2022-09-18 10:30:43 -04:00
arch=$(ideviceinfo | grep "CPUArchitecture: " | sed 's/CPUArchitecture: //')
if [ ! "$arch" = "arm64" ]; then
echo "[-] palera1n doesn't, and never will, work on non-checkm8 devices"
exit
fi
echo "Hello, $(ideviceinfo | grep "ProductType: " | sed 's/ProductType: //') on $version!"
2022-09-17 16:09:06 +02:00
fi
2022-09-17 08:34:50 -04:00
# Put device into recovery mode, and set auto-boot to true
if [ "$2" = '--dfu' ] || [ "$2" = '--recovery' ]; then
:
else
2022-09-17 10:22:48 -04:00
echo "[*] Switching device into recovery mode..."
ideviceenterrecovery $(ideviceinfo | grep "UniqueDeviceID: " | sed 's/UniqueDeviceID: //') > /dev/null
if [ "$os" = 'Darwin' ]; then
if ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (Recovery Mode):' >> /dev/null); then
echo "[*] Waiting for device to reconnect in recovery mode"
fi
2022-09-17 08:34:50 -04:00
2022-09-17 10:22:48 -04:00
while ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (Recovery Mode):' >> /dev/null); do
sleep 1
done
else
2022-09-17 18:58:16 -04:00
if ! (lsusb 2> /dev/null | grep ' Apple, Inc.' >> /dev/null); then
2022-09-17 10:22:48 -04:00
echo "[*] Waiting for device to reconnect in recovery mode"
fi
2022-09-17 08:34:50 -04:00
2022-09-17 18:58:16 -04:00
while ! (lsusb 2> /dev/null | grep ' Apple, Inc.' >> /dev/null); do
2022-09-17 10:22:48 -04:00
sleep 1
done
fi
$dir/irecovery -c "setenv auto-boot true"
$dir/irecovery -c "saveenv"
2022-09-17 08:34:50 -04:00
fi
2022-09-17 10:22:48 -04:00
# Grab more info
2022-09-17 08:34:50 -04:00
echo "[*] Getting device info..."
cpid=$($dir/irecovery -q | grep CPID | sed 's/CPID: //')
model=$($dir/irecovery -q | grep MODEL | sed 's/MODEL: //')
deviceid=$($dir/irecovery -q | grep PRODUCT | sed 's/PRODUCT: //')
ipswurl=$(curl -sL "https://api.ipsw.me/v4/device/$deviceid?type=ipsw" | $dir/jq '.firmwares | .[] | select(.version=="'$version'") | .url' --raw-output)
# Have the user put the device into DFU
2022-09-17 10:22:48 -04:00
if [ ! "$2" = '--dfu' ]; then
echo "[*] Press any key when ready for DFU mode"
read -n 1 -s
step 3 "Get ready"
step 4 "Hold volume down + side button" &
sleep 3
irecovery -c reset
step 1 "Keep holding"
step 10 'Release side button, but keep holding volume down'
sleep 1
fi
2022-09-17 08:34:50 -04:00
# Check if device entered dfu
2022-09-17 10:22:48 -04:00
if [ ! "$2" = '--dfu' ]; then
if [ "$os" = 'Darwin' ]; then
if ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (DFU Mode):' >> /dev/null); then
echo "[-] Device didn't go in DFU mode, please rerun the script and try again"
exit
fi
else
if ! (lsusb 2> /dev/null | grep ' Apple Mobile Device (DFU Mode):' >> /dev/null); then
echo "[-] Device didn't go in DFU mode, please rerun the script and try again"
exit
fi
2022-09-17 08:34:50 -04:00
fi
2022-09-17 10:22:48 -04:00
echo "[*] Device entered DFU!"
2022-09-17 08:34:50 -04:00
fi
sleep 2
2022-09-18 10:30:43 -04:00
echo "[*] Pwning device"
2022-09-17 08:34:50 -04:00
$dir/gaster pwn > /dev/null
2022-09-17 15:24:35 -04:00
sleep 1
2022-09-17 08:34:50 -04:00
if [ ! -e boot ]; then
# Downloading files, and decrypting iBSS/iBEC
mkdir boot
cd work
echo "[*] Downloading BuildManifest"
$dir/pzb -g BuildManifest.plist $ipswurl > /dev/null
$dir/img4tool -e -s $1 -m IM4M > /dev/null
echo "[*] Downloading and decrypting iBSS"
$dir/pzb -g "$(awk "/""$cpid""/{x=1}x&&/iBSS[.]/{print;exit}" BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1)" $ipswurl > /dev/null
$dir/gaster decrypt "$(awk "/""$cpid""/{x=1}x&&/iBSS[.]/{print;exit}" BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" iBSS.dec > /dev/null
echo "[*] Downloading and decrypting iBEC"
$dir/pzb -g "$(awk "/""$cpid""/{x=1}x&&/iBEC[.]/{print;exit}" BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1)" $ipswurl > /dev/null
$dir/gaster decrypt "$(awk "/""$cpid""/{x=1}x&&/iBEC[.]/{print;exit}" BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" iBEC.dec > /dev/null
echo "[*] Downloading DeviceTree"
2022-09-18 10:30:43 -04:00
#$dir/pzb -g "$(awk "/""$cpid""/{x=1}x&&/DeviceTree[.]/{print;exit}" BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1)" $ipswurl > /dev/null
$dir/pzb -g Firmware/all_flash/DeviceTree.$model.im4p $ipswurl > /dev/null
2022-09-17 08:34:50 -04:00
echo "[*] Downloading trustcache"
if [ "$os" = 'Darwin' ]; then
2022-09-18 10:30:43 -04:00
$dir/pzb -g "$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."StaticTrustCache"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1 | head -1)" $ipswurl > /dev/null
2022-09-17 08:34:50 -04:00
else
2022-09-18 10:30:43 -04:00
$dir/pzb -g "$($dir/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:StaticTrustCache:Info:Path" | sed 's/"//g')" $ipswurl > /dev/null
2022-09-17 08:34:50 -04:00
fi
2022-09-17 19:26:53 -04:00
#if [[ "$@" == *"install"* ]]; then
# echo "[*] Downloading ramdisk"
# if [ "$os" = 'Darwin' ]; then
# $dir/pzb -g "$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1 | head -1)" $ipswurl > /dev/null
# else
# $dir/pzb -g "$($dir/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" $ipswurl > /dev/null
# fi
#fi
2022-09-17 16:09:06 +02:00
2022-09-17 08:34:50 -04:00
echo "[*] Downloading kernelcache"
$dir/pzb -g "$(awk "/""$cpid""/{x=1}x&&/kernelcache.release/{print;exit}" BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1)" $ipswurl > /dev/null
echo "[*] Patching and repacking iBSS/iBEC"
$dir/iBoot64Patcher iBSS.dec iBSS.patched > /dev/null
2022-09-17 14:44:31 -04:00
$dir/iBoot64Patcher iBEC.dec iBEC.patched -b '-v keepsyms=1 debug=0xfffffffe panic-wait-forever=1 wdt=-1' > /dev/null
2022-09-17 19:26:53 -04:00
#if [[ "$@" == *"install"* ]]; then
# $dir/iBoot64Patcher iBEC.patched restore_ibec.patched -b '-v rd=md0 debug=0x2014e wdt=-1' > /dev/null
#fi
2022-09-17 08:34:50 -04:00
cd ..
$dir/img4 -i work/iBSS.patched -o boot/iBSS.img4 -M work/IM4M -A -T ibss > /dev/null
$dir/img4 -i work/iBEC.patched -o boot/iBEC.img4 -M work/IM4M -A -T ibec > /dev/null
2022-09-17 19:26:53 -04:00
#if [[ "$@" == *"install"* ]]; then
# $dir/img4 -i work/restore_ibec.patched -o boot/restore_ibec.img4 -M work/IM4M -A -T ibec > /dev/null
#fi
2022-09-17 08:34:50 -04:00
echo "[*] Patching and converting kernelcache"
2022-09-18 10:30:43 -04:00
#$dir/img4 -i work/"$(awk "/""$model""/{x=1}x&&/kernelcache.release/{print;exit}" work/BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1)" -o work/kcache.raw > /dev/null
#$dir/Kernel64Patcher work/kcache.raw work/kcache.patched -a -o > /dev/null
#python3 kerneldiff.py work/kcache.raw work/kcache.patched work/kc.bpatch > /dev/null
#$dir/img4 -i work/"$(awk "/""$model""/{x=1}x&&/kernelcache.release/{print;exit}" work/BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1)" -o boot/kernelcache.img4 -M work/IM4M -T rkrn -P work/kc.bpatch `if [ "$os" = 'Linux' ]; then echo "-J"; fi` > /dev/null
python3 -m pyimg4 im4p extract -i work/"$(awk "/""$model""/{x=1}x&&/kernelcache.release/{print;exit}" work/BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1)" -o work/kcache.raw `if [ "$deviceid" == *'iPhone8'* ]; then echo "--extra kpp.bin"; fi` > /dev/null
2022-09-18 11:13:38 -04:00
$dir/Kernel64Patcher work/kcache.raw work/kcache.patched -a -o > /dev/null
2022-09-18 10:30:43 -04:00
python3 -m pyimg4 im4p create -i work/kcache.patched -o work/krnlboot.im4p `if [ "$deviceid" == *'iPhone8'* ]; then echo "--extra kpp.bin"; fi` -f rkrn --lzss > /dev/null
python3 -m pyimg4 img4 create -p work/krnlboot.im4p -o boot/kernelcache.img4 -m work/IM4M > /dev/null
2022-09-17 08:34:50 -04:00
echo "[*] Converting DeviceTree"
$dir/img4 -i work/"$(awk "/""$model""/{x=1}x&&/DeviceTree[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1 | sed 's/Firmware[/]all_flash[/]//')" -o boot/devicetree.img4 -M work/IM4M -T rdtr > /dev/null
echo "[*] Patching and converting trustcache"
if [ "$os" = 'Darwin' ]; then
$dir/img4 -i work/"$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."StaticTrustCache"."Info"."Path" xml1 -o - work/BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1 | head -1 | sed 's/Firmware\///')" -o boot/trustcache.img4 -M work/IM4M -T rtsc > /dev/null
2022-09-17 08:34:50 -04:00
else
$dir/img4 -i work/"$($dir/PlistBuddy work/BuildManifest.plist -c "Print BuildIdentities:0:Manifest:StaticTrustCache:Info:Path" | sed 's/"//g'| sed 's/Firmware\///')" -o boot/trustcache.img4 -M work/IM4M -T rtsc > /dev/null
2022-09-17 08:34:50 -04:00
fi
2022-09-17 11:04:13 -04:00
2022-09-17 19:26:53 -04:00
#if [[ "$@" == *"install"* ]]; then
# echo "[*] Making ramdisk... this may take awhile"
# if [ "$os" = 'Darwin' ]; then
# $dir/img4 -i work/"$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - work/BuildManifest.plist | grep '<string>' | cut -d\> -f2 | cut -d\< -f1 | head -1)" -o work/ramdisk.dmg > /dev/null
# else
# $dir/img4 -i work/"$(Linux/PlistBuddy work/BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" -o work/ramdisk.dmg > /dev/null
# fi
# $dir/hfsplus work/ramdisk.dmg grow 300000000 > /dev/null
# $dir/hfsplus work/ramdisk.dmg untar other/ramdisk.tar.gz > /dev/null
# $dir/img4 -i work/ramdisk.dmg -o boot/ramdisk.img4 -M work/IM4M -A -T rdsk > /dev/null
#fi
2022-09-17 08:34:50 -04:00
fi
echo "[*] Booting device"
2022-09-17 15:24:35 -04:00
$dir/gaster reset > /dev/null
sleep 1
2022-09-17 08:34:50 -04:00
$dir/irecovery -f boot/iBSS.img4
sleep 3
2022-09-17 19:26:53 -04:00
#if [[ "$@" == *"install"* ]]; then
# $dir/irecovery -f boot/restore_ibec.img4
# sleep 2
#else
$dir/irecovery -f boot/iBEC.img4
sleep 2
#fi
2022-09-17 16:09:06 +02:00
if [[ "$cpid" == *"0x80"* ]]; then
2022-09-17 19:26:53 -04:00
#if [[ "$@" == *"install"* ]]; then
# $dir/irecovery -f boot/restore_ibec.img4
#else
# $dir/irecovery -f boot/iBEC.img4
#fi
2022-09-17 16:09:06 +02:00
sleep 2
2022-09-17 08:34:50 -04:00
$dir/irecovery -c "go"
sleep 5
fi
2022-09-17 19:26:53 -04:00
#if [[ "$@" == *"install"* ]]; then
# $dir/irecovery -f boot/ramdisk.img4
# sleep 2
# $dir/irecovery -c "ramdisk"
# sleep 2
#fi
2022-09-17 08:34:50 -04:00
$dir/irecovery -f boot/devicetree.img4
sleep 1
$dir/irecovery -c "devicetree"
sleep 1
$dir/irecovery -f boot/trustcache.img4
sleep 1
$dir/irecovery -c "firmware"
sleep 1
$dir/irecovery -f boot/kernelcache.img4
sleep 1
$dir/irecovery -c "bootx"
2022-09-17 08:48:02 -04:00
if [ "$os" = 'Darwin' ]; then
2022-09-18 10:44:05 -04:00
if [ ! "$2" = '--dfu' ] || [ ! "$2" = '--recovery' ]; then
2022-09-17 11:04:13 -04:00
defaults write -g ignore-devices -bool false
defaults write com.apple.AMPDevicesAgent dontAutomaticallySyncIPods -bool false
killall Finder
fi
2022-09-17 08:48:02 -04:00
fi
2022-09-17 08:34:50 -04:00
rm -rf work
echo ""
echo "Done!"
2022-09-17 19:26:53 -04:00
#if [[ "$@" == *"install"* ]]; then
# echo "The device should now reboot after about 30 seconds, then you can rerun the script without the install arg"
#else
echo "The device should now boot to iOS"
echo "If you already have installed Pogo, click uicache and remount preboot in the tools section"
echo "If not, get an IPA from the latest action build of Pogo and install with TrollStore"
echo "Add the repo mineek.github.io/repo for Procursus"
#fi