ZDX ACADEMY

Understanding Apple Mach-O Binary Internals · Universal binaries and architecture slices

Language:English

Lab: Parse a universal Mach-O wrapper

Use course fixtures, software you own, or binaries you are authorized to inspect.

Apple's fat.h defines a wrapper with a fat_header followed by architecture records.

For the classic 32-bit fat_arch form, each architecture record includes:

The classic wrapper structures are stored big-endian.

Build the parser

Write a Python program that:

  1. recognizes FAT_MAGIC and swapped representations;
  2. reads the architecture count;
  3. validates that the architecture table fits in the file;
  4. parses every architecture record;
  5. validates that each slice offset and size remain inside the file;
  6. reports architecture identity, offset, size, and alignment;
  7. reads the first four bytes of each slice and reports whether it appears to contain a Mach-O image.

Do not assume slices are adjacent. Use their explicit offsets.

Deliverable

Produce:

Cross-check with lipo -info on macOS if available, or with an independent library such as LIEF on another platform.

Course outline