Skip to content

Instantly share code, notes, and snippets.

@bruienne
Last active June 7, 2024 19:59
Show Gist options
  • Save bruienne/ec5205408b9e52bd5cfc to your computer and use it in GitHub Desktop.
Save bruienne/ec5205408b9e52bd5cfc to your computer and use it in GitHub Desktop.
Linux DMG/PKG notes

DMG/PKG Linux notes

Mounting DMGs w/ HFS partitions:

http://linuxforums.org.uk/index.php?topic=1072.0

Tools needed:

apt-get install hfsplus hfsutils hfsprogs dmg2img

Convert DMG to raw IMG (pkgdmgs don't need this)

dmg2img image.dmg image.img

An HFS+/HFSX partition starts with 1024 reserved bytes (for boot code), followed by the volume header.

The first 4 bytes of the volume header are a signature and a version number:

  • "H+" followed by version 4 = HFS

  • "HX" followed by version 5 = HFSX

Search raw img for either HFS+ or HFSX header

  • "48 2b 00 04" = HFS+

  • "48 58 00 05" = HFSX

  • hexdump -C image.img | grep "48 2b 00 04"

Subtract 1024 bytes to find the beginning of the partition

  • expr $(printf "%d" 0x<ADDRESS FROM HEXDUMP>) - 1024

Get the offset in a one-liner using first found match for HFS+ volume header in SOURCE.img:

  • expr $(printf "%d" 0x$(hexdump -C SOURCE.img | grep -m 1 "48 2b 00 04" | awk '{print $1}')) - 1024

Setup .img as a block device:

  • losetup -o <CALCULATED OFFSET IN DEC> /dev/loop0 image.img

Mount the block device:

  • mount -t hfsplus /dev/loop0 /mnt

Install XAR from source:

apt-get install -y build-essentials git autoconf libxml2-dev libcurl4-openssl-dev python2.7 libbz2-dev liblzma-dev

git clone https://github.com/mackyle/xar.git

cd xar
./autogen.sh
./configure --with-bzip2 --with-lzma=/usr
make
make install

Convert and extract

PBZX-wrapped Payload (as of OS X 10.10) needs extra processing if:

file path/to/Payload
> path/to/Payload: data

Use Michael Lynn's Python script to remove PBZX wrapper: https://gist.github.com/pudquick/ff412bcb29c9c1fa4b8d

xar -x -f /mnt/SOME.pkg path/to/Payload

file path/to/Payload
> path/to/Payload: data

parsepbzx.py path/to/Payload

file /Payload.cpio.xz
> Payload.cpio.xz: XZ compressed data

xz -d /Payload.cpio.xz

file /Payload.cpio
> Payload.cpio: ASCII cpio archive (pre-SVR4 or odc)

cpio -i --list -I /Payload.cpio

>.
>./System
>./System/Library
>./System/Library/Input Methods
>./usr
>./Library

Install bomutils from source

git clone https://github.com/hogliux/bomutils.git
make
make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment