Urgent.News

What's breaking now, across hundreds of outlets.

Tech

How WinHelp files work

WinHelp files are a format used by Microsoft to store help documentation. They are not officially documented by Microsoft, but the format has been reverse-engineered by developers. Libhlp is a Rust library that allows for opening and reading WinHelp .hlp files.

A .hlp file starts with a magic number, 3F 5F 03 00, followed by the position of its internal directory. The .hlp file is essentially an archive, and the directory lists the files contained within. Most file names start with a pipe character, such as |SYSTEM, |TOPIC, |FONT, and |CONTEXT. Pictures are stored in files like |bm0.

The directory itself is a B+ tree, and each index in the file is also a B+ tree. Text is stored in the |TOPIC file, which is divided into fixed-size blocks. Each block can be compressed using the LZ77 algorithm. The blocks take up the same amount of space in memory, whether they are completely filled or not. Inside the blocks, the text is a linked list of records. Some records mark the beginning of a new topic, while the rest hold paragraphs.

Each paragraph consists of a formatting part and a text part. The text part can be compressed again, adding another layer of complexity to the WinHelp format. Back-references are a unique feature of WinHelp compression. They allow the text to reference previous bytes, rather than repeating them. This can lead to some quirky behavior, such as back-references reaching before the start of the data.

Additional compression can be applied to the most common phrases in the help file. WinHelp 3.1 uses a simple table in |Phrases, while Windows 95 introduced Hall compression in |PhrIndex and |PhrImage. These compression methods allow for the storage of short codes for frequently used phrases.

WinHelp files also contain links, which are stored as hashes of the target topic name. To follow a link, you hash the target name using the same algorithm as WinHelp and look up the result in the |CONTEXT file, which maps the hash to the position of the target topic. The text itself is stored in the code page used by the author, which may vary depending on the language of the text.

WinHelp 3.0 has some differences in its format, including block sizes and compression methods. Libhlp can read these files, but it required a separate commit to handle the format correctly.

Rewritten by urgent.news; may contain errors — check the original.

Source: quin.fyi

Read the original at quin.fyi →

Report a problem with this story

More in Tech

More from Thursday 26 November →