Skip to content

Instantly share code, notes, and snippets.

@korniltsev
Forked from PsychoTea/PanicParser.py
Created November 23, 2019 21:23
Show Gist options
  • Save korniltsev/404540b2373af46aa2b978bbbb967487 to your computer and use it in GitHub Desktop.
Save korniltsev/404540b2373af46aa2b978bbbb967487 to your computer and use it in GitHub Desktop.
A collection of useful iOS-related scripts
#!/bin/bash
for id in $(idevice_id -l); do
ideviceinfo_data=$(ideviceinfo -u $id)
product_type=$(echo "$ideviceinfo_data" | grep ProductType | sed 's/ProductType: //g')
# strip 'iPhone' or 'iPad' and the comma from the product type
short_product_type=$(echo "$product_type" | sed 's/iPhone//g; s/iPad//g; s/,//g' )
short_product_version=$(echo "$ideviceinfo_data" | grep ProductVersion | sed 's/ProductVersion: //g; s/\.//g')
kernel_string="$short_product_type"-"$short_product_version"
if [[ "$product_type" == iPad* ]]; then
kernel_string=ipad"$kernel_string"
fi
kernel_path="/Users/ben/Desktop/kernels/$kernel_string"
printf "$id"
printf ' | '
printf "$(echo "$ideviceinfo_data" | grep DeviceName | sed 's/DeviceName: //g')"
printf ' | '
printf "$(echo "$ideviceinfo_data" | grep ProductType | sed 's/ProductType: //g')"
printf ' | '
printf "$(echo "$ideviceinfo_data" | grep ProductVersion | sed 's/ProductVersion: //g')"
printf ' | '
printf "$(echo "$ideviceinfo_data" | grep BuildVersion | sed 's/BuildVersion: //g')"
printf ' | '
if [[ -e "$kernel_path" ]]; then
quick_path=$(echo $kernel_path | sed 's/\/Users\/ben/~/')
printf "$quick_path"
else
printf '-'
fi
printf '\n'
done
#!/bin/bash
# Requires ideviceinfo (libimobiledevice), pzb, curl, jq
if [[ "$#" -lt "2" ]]; then
echo "Usage: pullipsw [uuid] [version]"
exit 0
fi
target_uuid="$1"
target_version="$2"
echo "Finding IPSW for $target_uuid, version $target_version..."
device_info=$(ideviceinfo -u $target_uuid)
if [[ "$device_info" == ERROR* ]]; then
echo "Failed to find device with UUID $target_uuid!"
exit 0
fi
device_name=$(echo "$device_info" | grep DeviceName | sed 's/DeviceName: //g')
product_type=$(echo "$device_info" | grep ProductType | sed 's/ProductType: //g')
product_version=$(echo "$device_info" | grep ProductVersion | sed 's/ProductVersion: //g')
build_version=$(echo "$device_info" | grep BuildVersion | sed 's/BuildVersion: //g')
echo "Device name: $device_name"
echo "Product type: $product_type"
echo "Product version: $product_version"
echo "Build version: $build_version"
# Find the buildid from the version number
ipsw_url=$(curl https://api.ipsw.me/v4/device/$product_type?type=ipsw 2>/dev/null | jq -r '.firmwares[] | select(.version == "'$target_version'") | .url')
echo
echo IPSW URL: $ipsw_url
echo
cd /tmp
wget $ipsw_url
file_name=$(echo $ipsw_curl | rev | cut -d'/' -f1 | rev)
echo "Saved to $file_name."
#!/bin/bash
# Requires ideviceinfo (libimobiledevice), pzb, jtool2
build_kernel_string () {
# $1 = product type ie. iPhone12,1
# $2 = product version ie. 13.2.2
short_product_type=$(echo "$1" | sed 's/iPhone//g; s/iPad//g; s/,//g')
short_product_version=$(echo "$2" | sed 's/\.//g')
echo "$short_product_type-$short_product_version"
}
if [[ "$#" == "0" ]]; then
echo "Usage: pullkernel [uuid]"
exit 0
fi
target_uuid=$1
echo "Finding kernel for $target_uuid..."
device_info=$(ideviceinfo -u $target_uuid)
if [[ "$device_info" == ERROR* ]]; then
echo "Failed to find device with UUID $target_uuid!"
exit 0
fi
device_name=$(echo "$device_info" | grep DeviceName | sed 's/DeviceName: //g')
product_type=$(echo "$device_info" | grep ProductType | sed 's/ProductType: //g')
product_version=$(echo "$device_info" | grep ProductVersion | sed 's/ProductVersion: //g')
build_version=$(echo "$device_info" | grep BuildVersion | sed 's/BuildVersion: //g')
kernel_string=$(build_kernel_string $product_type $product_version)
echo "Device name: $device_name"
echo "Product type: $product_type"
echo "Product version: $product_version"
echo "Build version: $build_version"
echo "Kernel string: $kernel_string"
final_kernel_path="/Users/ben/Desktop/kernels/$kernel_string"
if [[ -e $final_kernel_path ]]; then
echo "Kernel already found, exiting..."
exit 0
fi
# Download the kernel
cd /tmp
url_string="https://api.ipsw.me/v4/ipsw/download/$product_type/$build_version"
echo "URL: $url_string"
echo "Fetching files..."
pzb_kernel_string=$(pzb -l "$url_string" | grep kernelcache | cut -d' ' -f5)
echo "Pulling kernel file $pzb_kernel_string..."
pzb -g $pzb_kernel_string $url_string | grep '\['
echo "Decompressing with jtool2..."
jtool2 -dec $pzb_kernel_string
mv kernel $final_kernel_path
echo
listdevices
echo
echo "Complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment