MS-DOS EXE

From Just Solve the File Format Problem
(Difference between revisions)
Jump to: navigation, search
(Links)
m (Sample files)
 
(9 intermediate revisions by 3 users not shown)
Line 4: Line 4:
 
|extensions={{ext|exe}}
 
|extensions={{ext|exe}}
 
|pronom={{PRONOM|x-fmt/409}}
 
|pronom={{PRONOM|x-fmt/409}}
 +
|kaitai struct=dos_mz
 
}}
 
}}
'''MZ''' (also called by its extension '''EXE''' and by other names) is an executable file format used mainly by [[MS-DOS]]; the format is a successor of [[DOS executable (.com)|COM]].
+
'''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 [[DOS executable (.com)|COM]]. A number of other executable formats are extensions or hybrids of it; see [[EXE]] for those formats.
  
Many other executable formats are extensions of MZ, including [[New Executable]] (used by 16-bit Windows), [[Portable Executable]] (newer Windows versions) and [[Linear Executable]] (OS/2). Files in these formats usually begin with a short MZ program (called a DOS stub) which, when executed by DOS, prints a message like "This program cannot be run in DOS mode" or "This program requires Microsoft Windows" and immediately exits. Some programs contain a more functional DOS stub, e.g. the Windows 9x registry editor.
+
== Format details ==
 +
=== 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.
 +
 
 +
{| class="wikitable"
 +
! Offset !! Type !! Name !! Description and remarks
 +
|-
 +
|0 || byte[2] || e_magic || Signature - ASCII "<code>MZ</code>" or "<code>ZM</code>"
 +
|-
 +
|2 || uint16 || e_cblp || If nonzero, the number of bytes in the last page
 +
|-
 +
|4 || uint16 || e_cp || Number of 512-byte pages in the file, not counting the "overlay" segment
 +
|-
 +
|6 || uint16 || e_crlc || Number of relocations
 +
|-
 +
|8 || uint16 || e_cparhdr || Header size, in 16-byte paragraphs
 +
|-
 +
|10 || uint16 || e_minalloc || Minimum allocation
 +
|-
 +
|12 || uint16 || e_maxalloc || Maximum allocation
 +
|-
 +
|14 || int16  || e_ss || Initial SS register
 +
|-
 +
|16 || uint16 || e_sp || Initial SP register
 +
|-
 +
|18 || uint16 || e_csum || Checksum - Usually unused and set to 0
 +
|-
 +
|20 || uint16 || e_ip || Initial IP register
 +
|-
 +
|22 || int16  || e_cs || Initial CS register
 +
|-
 +
|24 || uint16 || e_lfarlc || Relocation table offset, in bytes from the start of the file
 +
|-
 +
|26 || uint16 || e_ovno || Overlay number (or other custom data) - Usually unused
 +
|}
 +
 
 +
=== Special file positions ===
 +
When analyzing DOS EXE files, especially [[Executable envelopes|"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'' (a.k.a. ''entry 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 ==
 
== Identification ==
An MZ file begins with an ASCII signature of {{magic|'M' 'Z'}} (or, rarely, {{magic|'Z' 'M'}}), followed by a series of 16-bit fields. The field at offset 24 (the relocation table offset) is ''usually'' (but apparently not always) less than 64, and at least 28.
+
See [[EXE#Identification]] 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 ==
 +
* {{DexvertSamples|executable/exe}}
  
 
== Links ==
 
== Links ==
Line 21: Line 75:
  
 
[[Category:Microsoft]]
 
[[Category:Microsoft]]
 +
[[Category:MS-DOS]]

Latest revision as of 19:55, 16 February 2024

File Format
Name MS-DOS EXE
Ontology
Extension(s) .exe
PRONOM x-fmt/409
Kaitai Struct Spec dos_mz.ksy

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.

Contents

[edit] Format details

[edit] 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.

Offset Type Name Description and remarks
0 byte[2] e_magic Signature - ASCII "MZ" or "ZM"
2 uint16 e_cblp If nonzero, the number of bytes in the last page
4 uint16 e_cp Number of 512-byte pages in the file, not counting the "overlay" segment
6 uint16 e_crlc Number of relocations
8 uint16 e_cparhdr Header size, in 16-byte paragraphs
10 uint16 e_minalloc Minimum allocation
12 uint16 e_maxalloc Maximum allocation
14 int16 e_ss Initial SS register
16 uint16 e_sp Initial SP register
18 uint16 e_csum Checksum - Usually unused and set to 0
20 uint16 e_ip Initial IP register
22 int16 e_cs Initial CS register
24 uint16 e_lfarlc Relocation table offset, in bytes from the start of the file
26 uint16 e_ovno Overlay number (or other custom data) - Usually unused

[edit] 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 (a.k.a. entry 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.

[edit] Identification

See EXE#Identification 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.

[edit] Sample files

[edit] Links

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox