Win32 .res (compiled resource script) file parser.
Backs the VB6 LoadResData, LoadResPicture, and LoadResString functions,
which read from the single .res file a VB6 project links at compile time.
File format
A .res file is a flat, ordered sequence of resource records with no
global file header and no directory. Each record is self-describing and
carries its own header, so the file is parsed by walking record to record
until the buffer is exhausted. Every record has this layout:
offset size field
------ ---- ---------------------------------------------------------
0 4 DataSize byte length of the resource data
4 4 HeaderSize byte length of this header, data starts here
8 * Type ordinal-or-name (see below)
* * Name ordinal-or-name (see below)
* 0-2 padding to align the following DWORD to 4 bytes
* 4 DataVersion
* 2 MemoryFlags
* 2 LanguageId Win32 LANGID, e.g. 0x0409 = en-US
* 4 Version
* 4 Characteristics
* * data DataSize bytes, then padded to a 4-byte bound
Type and Name are each an ordinal-or-name: if the first u16 is
[ORDINAL_MARKER] (0xFFFF) the field is a 4-byte ordinal whose value is
the second u16; otherwise it is a NUL-terminated UTF-16LE string. This is
why the header is variable-length and why HeaderSize — not a fixed
constant — must be used to find the data.
Note that HeaderSize is authoritative: it is used to locate the data, and
the fixed trailer is read at the position derived from the type/name fields.
Both are cross-checked, and a record whose HeaderSize disagrees with its
parsed contents is rejected as a malformed file.
Every well-formed .res file begins with a null record: Type ordinal 0,
Name ordinal 0, and DataSize 0. It carries no resource and is skipped.