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:BinHex 4.0

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

Text encoding (.hqx) of a Mac file's name, type, creator, flags and both forks: the line '(This file must be converted with BinHex 4.0)', then a ':'-delimited stream in a 64-character alphabet with run-length 0x90 compression and CRC-16 checks.

Overview

BinHex 4.0 makes a Mac file safe for 7-bit text channels (email, Usenet). See Platform:Classic Mac OS, Format:MacBinary, Format:StuffIt (a .sit.hqx is a common combination).

Recognition

From XADMaster XADBinHexParser.m (LGPL-2.1, lines 30-68): the text '(This file must be converted with BinHex' (40 characters, the rest of the line is normally ' 4.0).') can appear anywhere in the first 8192 bytes; after the end of that line and any line breaks, spaces or tabs the next character must be ':'. The recognizer then decodes the start of the stream and requires: a name length 1-63, a CRC-16 (polynomial 0x1021, init 0) over the length byte and the 19 + length bytes after it equal to the following big-endian u16.

Decoded layout

Parser lines 93-119: u8 name length, the name, 1 byte version (skipped), u32 file type, u32 creator, u16 Finder flags, u32 data fork length, u32 resource fork length, u16 header CRC. The data fork follows at decoded offset 22 + name length (line 'BinHexDataOffset'), then a CRC, the resource fork and a CRC. Unverified: the exact byte offset of the resource fork part and the trailing CRC values were not read.

Encoding

The 64-character alphabet in the parser (line 191) is "!"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr"; six bits per character, characters outside it are line breaks, and the stream ends at the closing ':'. Before the base-64-like stage the data is run-length coded: the byte 0x90 starts a run, 0x90 0x00 stands for a literal 0x90, and 0x90 n repeats the previous byte n-1 more times (lines 239-243; a count of 1 is an error).

Code & repositories

  • https://github.com/MacPaw/XADMaster @ 7cb9ee0abbb163f261e4cb74501e15067032319c · license: LGPL-2.1
    The Unarchiver's engine (Objective-C, LGPL-2.1): recognisers and parsers for MacBinary, AppleSingle/Double, BinHex and StuffIt 1-5.
    Tested on: source read, not run: read the source only · checked 2026-10-19; last activity 2026-09-21