DR5 .RES Format

Windows 1.0 DR5 uses an early NE format, possibly closer to the older Module (.MOD) format than the final NE format. A major difference between the ancient NE format and the modern NE format is where resources are stored. DR5 stores the resources in a .RES file with the same name as the executable instead of being integrated into the executable itself like the final NE format. This document will describe DR5's resource format.

Basic Information
The resource file can be split into 2 sections - the header and the body. The header can be further broken into 2 sections - the file header and the resource header. The file header contains information such as the number of resources and length of the header. The resource header contains the name, type and address of each resource in the .RES file. The body simply contains all the resources, no padding.

Limitations
It appears that a resource file cannot safely contain more than 50 resources. While the resource script will compile with 51 or more resources defined, the compiled .RES will look slightly different and there is no guarantee that it will function as expected. When there are more than 50 resources, the last 2 bytes of the first field of the file header (numRes) will be overwritten by the first 2 bytes of the name of the 51st resource. The resource header of all resources after the 50th one will look different. Instead of being padded with zeros if the name or type is less than 16 bytes, all resource headers after the 50th one will be padded with seemingly random bytes from memory, most likely from the resource compiler itself. Even worse, the 51st resource header will have its first 14 bytes overwritten by the file header. The strings despite not being padded, will still be null-terminated, so they will not cause troubles. The last 2 bytes of numRes being overwritten does not seem to have any impacts but the 51st resource header will be invalid as the resource name will be messed up (although the first 2 characters will be the same). This is most likely due to a bug in the resource compiler code but the chance of it being done on purpose should not be neglected.

Documentation
DR5 Resource Format │ ├───Header │  ├───File header │  │       dword       numRes                  Number of resources │  │       dword       headLength              Length of .RES header (file header + resource header) │  │       bytes       6 DUP(0)                6 bytes of empty space │  │ │   └───Resource header │          word        0                       Maybe reserved │          bytes       resName (16 bytes)      Resource name (pad with zeros if less than 16 bytes) │          bytes       resType (16 bytes)      Resource type (pad with zeros if less than 16 bytes) │          dword       resSize                 Resource size │          dword       resAddr                 Location of the resource (relative to .RES body) │                              --> Next resource │ └───Body └───Resources bytes      resource                Compiled resource --> Next resource