Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Mac resource fork

From ReverseEngineering.wiki
Format
On this wiki Facts · Code · Notes · Topics

The classic Mac OS resource format: a 16-byte header with data and map offsets, a resource map (type list, reference list, name list) and length-prefixed resource data, stored in the resource fork of a file or in a data fork (.rsrc, dfont). All integers are big-endian.

Overview

A classic Mac file has two forks. The resource fork holds typed, numbered chunks (resources) read through the Resource Manager: 'CODE' segments of 68k applications, 'cfrg' code fragment descriptors, 'DRVR' drivers, 'MDEF'/'WDEF'/'CDEF' definition procedures, 'vers' version records, 'STR ' and 'STR#' strings, 'PICT' and 'snd ' media, 'dcmp' decompressors and so on. The same layout is used for stand-alone resource files (.rsrc) and for resources stored in the data fork (for example macOS .dfont fonts). On non-Mac filesystems the fork travels inside a container: Format:MacBinary, Format:AppleSingle and AppleDouble, Format:BinHex 4.0 or Format:StuffIt. See Platform:Classic Mac OS for the overview.

Layout

All integers are big-endian. In python-rsrcfork's api.py (MIT) the structures are (lines 19-61):

  • File header (STRUCT_RESOURCE_HEADER, ">IIII112s128s", 256 bytes): u32 offset of resource data (the source comment says basically always 0x100), u32 offset of resource map, u32 length of resource data, u32 length of resource map, 112 bytes system-reserved, 128 bytes application data.
  • Each resource in the data area: u32 length, then that many bytes.
  • Resource map header: 16 bytes reserved (copy of the file header in memory, zero in the file), 4 bytes reserved (handle to next map), 2 bytes reserved (file reference number), u16 file attributes, u16 offset from map start to the type list, u16 offset from map start to the name list.
  • Type list: u16 (number of types minus 1), then per type 8 bytes: 4-byte type, u16 (count of resources minus 1), u16 offset from the type list start to this type's reference list. Both counts are stored minus one.
  • Reference list entry, 12 bytes (STRUCT_RESOURCE_REFERENCE ">hHI4x"): s16 resource ID (the only signed integer), u16 offset into the name list or 0xFFFF for no name, then one u32 whose top byte is the attributes byte and low 3 bytes are the offset of the resource's length field from the start of the data area (code: attributes = value >> 24, offset = value & 0xFFFFFF, lines 512-513), then 4 reserved bytes (the in-memory handle).
  • Name list: Pascal strings (length byte then the name), addressed by offset from the name list start.

The 24-bit data offset is why resource forks cannot be much larger than 16 MiB (the reader's docstring says this, line 411).

Attribute flags

Resource attributes byte (class ResourceAttrs, api.py lines 89-99): 0x80 resSysRef, 0x40 resSysHeap, 0x20 resPurgeable, 0x10 resLocked, 0x08 resProtected, 0x04 resPreload, 0x02 resChanged, 0x01 resCompressed. The source comment says resCompressed is documented only in the ksfl wiki, not by Apple.

Map attribute word (ResourceFileAttrs, lines 68-87): 0x8000 resources locked, 0x0100 printer driver MultiFinder compatible, 0x0080 read-only, 0x0040 compact needed, 0x0020 map changed.

Compressed resources

A resource with the 0x01 attribute starts with a header (rsrcfork compress/common.py lines 12-37): signature A8 9F 65 72 (0xA89F6572), u16 header length (always 0x0012 in practice), u16 compression type (0x0801 "type 8", used in the Finder and ResEdit; 0x0901 "type 9", used in the System file and System 7.5's Installer), u32 decompressed length, then 6 type-specific bytes. Type 8: u8 working buffer fractional size, u8 expansion buffer size, s16 'dcmp' ID (only 0 supported by that reader), u16 reserved. Type 9: s16 'dcmp' ID (only 2 supported) and 4 bytes of parameters. The decompressors are themselves 'dcmp' resources.

Identification

A resource file has no magic number. Unverified heuristic: check that the data offset is 0x100, that data offset plus data length equals the map offset, and that the map offset plus map length is the file size. The reader in rsrcfork raises an error unless the data offset equals the end of the 256-byte header (lines 464-465). Executable forks are recognised by their types: 'CODE' 0 (68k), 'cfrg' (PEF, see Format:PEF (Preferred Executable Format)).

Reversing

68k applications keep their code in 'CODE' resources, see Format:Classic Mac 68k CODE segments. PowerPC applications keep the code in the data fork as a PEF container located through 'cfrg'. Drivers ('DRVR'), and window, menu and control definition procedures ('WDEF', 'MDEF', 'CDEF', 'LDEF') are 68k code resources whose first bytes are an entry stub; Unverified: the exact header of 'DRVR' (flags, delay, event mask, menu, then offsets to open, prime, control, status and close routines) is from memory of Inside Macintosh, not read in a source.

Tools

  • python-rsrcfork (dgelessus, MIT): reader with list/read CLI and 'dcmp' decompression.
  • macresources (elliotnunn, MIT): Rez-like text conversion and Python parser.
  • ResDecompress and ResExtract (elliotnunn): decompress compressed resources.

Code & repositories

  • https://github.com/dgelessus/python-rsrcfork @ d2bbab1f5dd8670baa1ea5a31a1754b824743493 · license: MIT
    Python reader and CLI for classic Mac resource files, with 'dcmp' decompression of compressed resources.
    Tested on: source read, not run: read the source only (api.py, compress/common.py) · checked 2026-10-19; last activity 2023-02-14