hn.today

How WinHelp Files Work

quin.fyi35 points24 comments
Screenshot of How WinHelp Files Work

WinHelp .hlp files are archive-like containers with an internal directory, usually a B+ tree, that points to components such as system settings, topic text, fonts, context names, and pictures. The format was undocumented by Microsoft, so building a reader required relying on an existing technical description and testing real files. Topic text is stored in fixed-size blocks, often LZ77-compressed; its addresses refer to decompressed text, and each block occupies a fixed span even when the content is shorter. Topic records link together and contain paragraphs whose formatting instructions and text are stored separately. Text may also use phrase compression: WinHelp 3.1 substitutes common phrases with codes, while the Windows 95-era Hall scheme encodes phrases and runs of literal bytes, spaces, or zeroes.

The implementation’s difficulties reveal several quirks that matter for compatibility. LZ77 references can reach before the start of a block and must yield zeroes; phrase lengths are bit-packed, with a step size of one requiring no remainder bits; and links store hashes of context names rather than topic positions. Hashing must account for case-insensitive lookup, signed table values, and the special hash for an empty name. Formatting is represented through font changes, while text encoding depends on the author’s Windows code page and may need to be inferred. WinHelp 3.0 differs substantially in block size, record structure, and link targets. The resulting Rust library reads supported WinHelp versions, including text, links, pictures, and formatting, while rejecting unrelated formats that merely share the .hlp extension.

Read on quin.fyi24 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Source Control from Hell

Source Control from Hell

An early software job relied on a shared folder, manual change descriptions, and a tech lead copying code by hand, with coworkers announcing when they needed access to avoid overwriting each other. Discovering Git showed Alex how version control could make collaboration faster and safer, but his company kept its old process for years because it worked well enough for them. (frantic.im)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.