MS-DOS EXE

MS-DOS EXE (or DOS EXE), also known as MZ format, is an executable file format used mainly by MS-DOS. It is the successor of COM. A number of other executable formats are extensions or hybrids of it; see EXE for those formats.

Header structure
DOS EXE files begin with a fixed 28-byte header.

The field names in this table are taken from the IMAGE_DOS_HEADER structure defined in modern Windows SDKs. Byte order is little-endian.

Special file positions
When analyzing DOS EXE files, especially "envelope" formats, it can be helpful to calculate certain special file positions. The positions given here are in bytes, from the start of the file.


 * End of relocation table: e_lfarlc + 4×e_crlc
 * Start of code image segment: 16×e_cparhdr
 * Execution starting point: 16×e_cparhdr + 16×e_cs + e_ip. Note that e_cs may be negative.
 * Start of overlay segment (or end of code image segment): If e_cblp=0, this is 512×e_cp. Otherwise, 512×(e_cp−1) + e_cblp.

Identification
See EXE for EXE format in general.

It's not clear if there is any completely reliable way to identify a file as strictly DOS EXE, except in the negative (i.e., it looks like EXE, and is not a valid NE, PE, etc., file).

If the relocation table offset is from 28 to 63, or any segment (relocation table or code image) overlaps the four bytes starting at offset 60, it is pretty certainly DOS EXE.

Most non-DOS EXE files set the relocation table offset to 64, but it's probably not safe to rely on that.

Sample files

 * https://telparia.com/fileFormatSamples/executable/exe/

Links

 * Wikipedia article
 * MZ, from the OSDev Wiki
 * http://www.delorie.com/djgpp/doc/exe/
 * DOS EXE format
 * EXE Explorer utility
 * Ralf Brown's Interrupt Reference has an extensive list of (mostly older) MZ-based executable formats