Skip to content

Instantly share code, notes, and snippets.

@superr4y
Created September 6, 2017 19:44
Show Gist options
  • Select an option

  • Save superr4y/781f6cda8e266f3a5d3ae15150955066 to your computer and use it in GitHub Desktop.

Select an option

Save superr4y/781f6cda8e266f3a5d3ae15150955066 to your computer and use it in GitHub Desktop.
Extract apple updates (dmg files)
#!/bin/bash
if [ $# -eq 1 ]; then
dmg2img $1 "$1.img"
USER=user
# get start and size of the last section
echo "Hit I"
sudo parted "$1.img" unit b p > tmp
out=$(sudo cat tmp | tail -2 | awk '{printf $2 $4}' | sed 's/B/ /g')
IFS=' ' read -ra array <<< "$out"
pstart=${array[0]}
psize=${array[1]}
# mount img file
sudo mkdir /media/tmp
sudo mount -v -t hfsplus -o "ro,loop,offset=${pstart},sizelimit=${psize}" "$1.img" /media/tmp
OUT_DIR="out_$1"
mkdir ${OUT_DIR}
sudo cp -rf /media/tmp/* ${OUT_DIR}/
sync
sudo umount /media/tmp
sudo rm -rf /media/tmp
sudo chown -R $USER:$USER ${OUT_DIR}
# iter over pkg files and extract Payload
cd ${OUT_DIR}
for pkg in $(find . -type f | grep -E "*.pkg"); do
echo "Found $pkg"
mv ${pkg} ../
xar -x -f "../$pkg"
for target in $(find -name Payload -o -name Scripts); do
echo "Found $target"
if file $target | grep -q "bzip2"; then
bzip2 -dc $target | cpio -i
elif file $target | grep -q "gzip"; then
gunzip -c $target | cpio -i
else
echo "Unknown file format in $target"
file $target
fi
rm $target
done
done
cd ..
sudo chown -R $USER:$USER ${OUT_DIR}
else
echo "Usage $1 <dmg file>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment