Introduction
.exe is the extension of programs on MS-DOS, on
Microsoft Windows and on OS/2. Six
formats have used it, each building on the ones before: the MS-DOS MZ format from
1983; the 16-bit NE format of Windows 1.0 to 3.11 and of the first OS/2; the 32-bit
LE format of Windows device drivers and DOS extenders; the LX format of 32-bit OS/2;
and the PE format of 32-bit and 64-bit Windows since 1993, in its two forms, PE32 and
PE32+. The newer formats are also used for libraries and drivers, under extensions
such as .dll, .drv, .sys and
.vxd.
All six start with the bytes MZ. Each newer format keeps a complete
MS-DOS program at the front of the file, the stub, so that running it under DOS prints
a message such as “This program cannot be run in DOS mode” instead of crashing. The
real header comes after the stub, and its position is stored at offset
0x3C.
Here, versions that only add to a format share it; a version that changes structures already there is a separate format. NE, LE, LX and PE each replace the header and the tables after it. LX changes fields that LE already had, and PE32+ changes the layout of PE32’s optional header, so those are separate formats too. Everything else that changed over forty years, such as new data directories, flags and machines in PE, only added.
A program dropped on any page opens in the explorer. It shows the program’s structure, every header and table in the order of its bytes; its resources; and its code, with an instruction decoded at every byte and the instructions laid out in columns, so that a jump into the middle of another instruction can be followed. The explorer disassembles 16-bit, 32-bit x86 and x64 code; the instructions are described in the x86 instruction reference.
Variations
| Format | Variation | About | Open |
|---|---|---|---|
.EXE | MS-DOS executable (MZ) | 16-bit DOS programs: an MZ header, relocations and the code. | Open |
.EXE | 16-bit Windows executable (NE) | Windows 3.x and early OS/2 programs and DLLs, in movable segments. | Open |
.EXE | Linear Executable (LE) | 32-bit Windows VxD drivers and DOS extender programs, in paged objects. | Open |
.EXE | OS/2 executable (LX) | 32-bit OS/2 programs and DLLs, in paged objects. | Open |
.EXE | Windows executable (PE32) | 32-bit Windows programs and DLLs, with a 32-bit optional header (magic 0x10B). | Open |
.EXE | Windows 64-bit executable (PE32+) | 64-bit Windows programs and DLLs (x64, ARM64), with a 64-bit optional header (magic 0x20B). | Open |
MS-DOS executable (MZ)
The executable format of MS-DOS, from DOS 2.0 in 1983, named after the initials of Mark Zbikowski, one of its designers. An MZ program is 16-bit x86 code with a short header and a table of relocations, which DOS uses to adjust the program’s segment addresses to wherever it was loaded. DOS loads one image; anything after it, an overlay, is left for the program to read, which is how self-extracting archives and DOS extenders carry their payload.
The file starts with MZ (a few very early ones with ZM)
and has no valid second header: the value at 0x3C does not lead to a PE,
NE, LE or LX header that passes the checks below. A Windows program whose new header
is missing or damaged is therefore shown as an MS-DOS program.
16-bit Windows executable (NE)
The New Executable format of 16-bit Windows, from Windows 1.0 to 3.11, and of OS/2 1.x. It splits code and data into segments that can be loaded and moved on demand, imports functions from other modules by name or number, and stores resources such as icons, menus and dialogs inside the file. OS/2 1.x files keep their resources as segments instead.
The file starts with MZ, and the 32-bit offset at 0x3C
points to the bytes NE, the start of a 64-byte header whose table
offsets all lie inside the file.
Linear Executable (LE)
A 32-bit format for code that runs in the flat memory of the 386, in objects cut
into pages of a fixed size. Windows 3.x and Windows 95, 98 and Me use it for virtual
device drivers (.386 and .vxd files), and DOS extenders
such as DOS/4GW run 32-bit DOS programs in it, most of them linked with Watcom’s
tools.
The offset at 0x3C points to the bytes LE. The header
then says little-endian byte and word order and format level 0, names a known
processor, and has a sensible page size. Each entry of its object page table is 4
bytes.
OS/2 executable (LX)
The Linear eXecutable format of 32-bit OS/2, from OS/2 2.0 in 1992, for programs
and libraries, still used by ArcaOS. It is LE with changes to fields LE already
had: each page has an 8-byte entry with its own offset, size and flags, so pages can
be of any size and anywhere in the file, and stored iterated, and the header word at
0x2C is a page offset shift rather than the size of the last page.
The offset at 0x3C points to the bytes LX, with the same
header checks as LE and a page offset shift of 24 or less.
Windows executable (PE32)
The Portable Executable format of 32-bit Windows, from Windows NT 3.1 in 1993 and Windows 95, still run by every 64-bit Windows. Built on the COFF object format, it holds code and data in sections, with tables of imports, exports, resources and relocations located by the data directories of its optional header. .NET assemblies built for any processor and some UEFI images are PE32 files too.
The offset at 0x3C points to PE\0\0, and the optional
header 24 bytes later starts with the magic number 0x10B. Its
optional header has a BaseOfData field and a 32-bit image base, and is 224 bytes
with 16 data directories.
Windows 64-bit executable (PE32+)
The 64-bit form of PE, from the Itanium edition of Windows XP in 2001, and the format of every program on x64 Windows from 2005 and on ARM64 Windows from 2017, and of 64-bit UEFI images. Its sections and tables are those of PE32, but its image base, stack and heap sizes, import entries, TLS directory and most of its load configuration are 64 bits, and its functions are described in an exception table for unwinding.
The offset at 0x3C points to PE\0\0, and the optional
header starts with the magic number 0x20B. It has no BaseOfData, and is
240 bytes with 16 data directories.
Telling them apart
The explorer reads the two bytes at the start, then the 32-bit value at
0x3C, e_lfanew, and tries the formats in this order,
taking the first whose checks pass:
PE\0\0ate_lfanewand an optional header magic of0x10B: PE32.PE\0\0and a magic of0x20B: PE32+.NE: NE.LE: LE.LX: LX.- Anything else, an offset past the end of the file, or a newer header that fails its checks: MZ, if the MS-DOS header itself is sound.
An MS-DOS program’s header is only 28 bytes, so the value at 0x3C may
be part of its relocations or code. That is why each newer format checks more than
its signature before it takes a file.
Versions
The systems that brought each format, and the releases that changed what Windows programs contain, up to the present day.
| When | Release | What it writes or runs | Format |
|---|---|---|---|
| 1983 | MS-DOS 2.0 | The first .exe programs | MZ |
| 1985 | Windows 1.0 | Windows programs and libraries | NE |
| 1987 | OS/2 1.0 | OS/2 programs, with resources as segments | NE |
| 1990 | Windows 3.0 | Windows programs; virtual device drivers for 386 enhanced mode (.386) | NE, LE |
| 1992 | OS/2 2.0 | 32-bit OS/2 programs and libraries | LX |
| July 1993 | Windows NT 3.1 | 32-bit Windows programs | PE32 |
| 1990s | DOS extenders (DOS/4GW and others) | 32-bit DOS programs, most linked with Watcom’s tools | LE |
| August 1995 | Windows 95 | 32-bit programs; VxD drivers (.vxd) with a version resource | PE32, LE |
| 2001 | Windows XP 64-bit Edition | 64-bit programs for Itanium | PE32+ |
| February 2002 | .NET Framework 1.0 | .NET assemblies, with a CLR header | PE32, later PE32+ |
| 2005 | Windows XP Professional x64 Edition | 64-bit programs for x64 | PE32+ |
| 2017 | Windows 10 on ARM | 64-bit programs for ARM64 | PE32+ |
| 2021 | Windows 11 | 64-bit only; ARM64EC and ARM64X images; still runs 32-bit programs | PE32+, PE32 |
| Today | Windows and its tools | Current Windows tools write PE32 and PE32+ only; NE, LE and LX are no longer written by them, and ArcaOS still runs LX | PE32, PE32+ |
That Windows 3.0 was the first to put its .386 drivers in LE is taken
from earlier pages of this site and has not been checked further.
Linker versions
A PE file’s optional header records the version of the linker that made it, which often tells the tools apart. The values seen most in the files examined for this site:
| Linker version | Written by |
|---|---|
| 2.x, such as 2.41 | GNU ld, from MinGW, Cygwin and Wine: 2.41 is the GNU ld that built Wine’s own DLLs |
| 5.10, 5.12 | Microsoft’s linker in Visual C++ 5, the oldest seen to write a Rich header |
| 6.00 | Visual C++ 6.0 |
| 7.00, 7.10 | Visual Studio .NET 2002 and 2003 |
| 8.00 | Visual Studio 2005; also seen in .NET assemblies |
| 9.00, 10.00, 11.00, 12.00 | Visual Studio 2008, 2010, 2012 and 2013 |
| 14.00 and later | Visual Studio 2015 and every release since |
| 48.00 | .NET compilers (an inference from the files) |
The Rich header of a file from Microsoft’s linker names each tool and its build, which tells Visual Studio releases apart more exactly.
Not described
Known, not yet covered
- Reference: the Rich header that Microsoft’s linker writes, and its checksum key. Microsoft has not documented it, but it has been worked out and published by others.
- Reference and viewer: installer overlays (NSIS, Inno Setup and others), whose layouts are in their open source code. Named only; not unpacked.
- Viewer: CodeView debug information kept in the file itself (the NBxx forms), and CodeView forms other than PDB references. Shown as labelled bytes.
- Viewer: exception tables for machines other than x64, IA-64, ARM, MIPS, Alpha and Windows CE, which the PE specification defines. Shown as labelled bytes.
- Viewer: the DOS stub’s code, shown as bytes rather than disassembled.
Unknown
- Reference: the bytes Borland TLINK writes in the MZ header, some NE header values and the NE checksum, the LE resource table (read from real files, with no specification), one bit of the LE entry table, and some LX header fields that no source confirms.
Also used for
- .NET assembly – .NET assemblies and modules: a PE file with ECMA-335 metadata tables, heaps and signatures.
Links
Software
- IDA Pro – commercial disassembler and decompiler that loads all six formats (Windows, macOS, Linux)
- Ghidra – the NSA’s free reverse engineering suite (Windows, macOS, Linux)
- Wine – runs Windows programs, PE and NE, on other systems (Linux, macOS)
- winevdm – runs 16-bit Windows programs on 64-bit Windows (Windows)
- DOSBox – emulator that runs MS-DOS programs and DOS extenders (Windows, macOS, Linux)
- ArcaOS – the current OS/2 distribution, which runs LX programs
Developers
- pefile – reads and edits PE files (Python)
- LIEF – reads and modifies PE, ELF and Mach-O (C++, with Python and Rust bindings)
- Open Watcom – compilers and a linker that writes LE and LX among other formats, with the wdump tool that prints them (C, C++)
Reference
- PE Format – Microsoft’s specification of PE32, PE32+ and COFF, which also describes the MS-DOS stub
- LX – Linear eXecutable Module Format Description – IBM’s description of LX, on EDM2
- EXE Format – DJ Delorie’s notes on the MS-DOS header
- The NE EXE File Format – a description of the NE header and its tables, on fileformat.info