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:
- CPU type;
- CPU subtype;
- file offset;
- slice size;
- alignment as a power of two.
The classic wrapper structures are stored big-endian.
Build the parser
Write a Python program that:
- recognizes
FAT_MAGICand swapped representations; - reads the architecture count;
- validates that the architecture table fits in the file;
- parses every architecture record;
- validates that each slice offset and size remain inside the file;
- reports architecture identity, offset, size, and alignment;
- 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:
fat_parser.py;- a JSON architecture map;
- SHA-256 of the tested file;
- one paragraph explaining the wrapper's byte order;
- one paragraph explaining why an offset table is different from “just concatenating binaries.”
Cross-check with lipo -info on macOS if available, or with an independent library such as LIEF on another platform.