Introduction
LE, the Linear Executable format, holds 32-bit code for the flat memory model of the
Intel 386. Its best-known use is for Windows virtual device drivers (VxDs): the
.386 drivers of Windows 3.x in 386 enhanced mode, and the
.vxd drivers of Windows 95, 98 and Me. Some VxDs also carry a 16-bit
object, for their real-mode initialisation code.
DOS extenders use it too. Many 32-bit DOS games and programs built with the Watcom
C compiler are LE files run by the DOS/4GW extender, which is bound into the front of
the .exe as its stub. These files say “OS/2” as their system, although
they run under DOS. OS/2 2.0 uses a close relative,
LX, which changes some of the same fields, so the
two are separate formats. All the variations are on the
.EXE page.
No full specification of LE was found for this site. What is known comes from IBM’s
description of LX, which shares most of the layout, from tools that read and write LE
files, chiefly Open Watcom’s linker and Wine’s winedump, and from the files
themselves. The code is
x86, described in the x86 instruction reference.
A program or driver dropped on any page opens in the explorer, which shows its structure, field by field, its resources, and its code: an instruction decoded at every byte, laid out in columns, so that a jump into the middle of another instruction can be followed.
Structure
An LE file begins with an MS-DOS MZ header and a DOS program, the stub; for a DOS
extender program the stub is the extender itself. The 32-bit word at 0x3C
points to the LE header, which starts with LE. The header says which
processor and system the module is for, what kind of module it is, where it starts,
and where each of its tables is. Most table offsets are from the start of the LE
header; the data pages, the non-resident names and the debug information are found by
file offsets.
Code and data are held in objects, the 32-bit successors of segments. Each object is cut into pages of a fixed size, usually 4,096 bytes, and the pages are stored one after another in the file. Fixups say which places in each page to adjust when the page is loaded.
0x00DOS header and stub, withe_lfanewat0x3Cvariese_lfanewLE headerLE, the processor and system, module flags, entry point, page size and the table offsets196 bytes…Loader section: the object table, the object page table, the resource table, the resident names and the entry tablevaries…Fixup section: the fixup page table, the fixup records, and the imported module and procedure namesvariesdata pagesPages the code and data of each object, page after pagea page each…Non-resident names, debug information and, in Windows VxDs, a version resourceoptional
The code
Executable objects hold the code. The explorer disassembles each one as 32-bit code
when the object’s big/default flag (0x2000) is set, and as 16-bit code
otherwise. A 32-bit object’s addresses count from its relocation base, the address it
was linked for; a 16-bit object’s count from 0. Exported entry points and the entry
point are named, and places that fixups patch with an imported procedure are labelled
with its module and name or ordinal. See the
x86 instruction reference.
Reference pages
- The DOS and LE headers – the DOS header and stub, every field of the LE header, the VxD fields, module directives and debug information
- The object table – each object’s size, address, flags and pages
- Object pages – the 4-byte page entries, page types and where each page is
- The resource table – resource entries and the version resource of Windows VxDs
- Resident and non-resident names – the module name, its description and exported names
- The entry table – exported entry points in bundles
- Fixups – the fixup page table and fixup records, field by field
- Imports – imported module and procedure names
Telling it apart
MS-DOS, Windows and OS/2 programs all start with MZ. The newer formats put
the file offset of a second header in the 32-bit word at 0x3C,
e_lfanew. The explorer takes a file as LE when, at that offset:
- the signature is
LE, and the 196-byte header is inside the file; - the byte order and the word order are both 0 (little-endian), and the format level is 0;
- the CPU type is a known one, such as 2 for the 80386;
- the page size is a power of two, not 0 and at most 1 MB;
- there are fewer than 65,536 objects, and the object table is inside the file.
An LX header passes the same checks but has the
signature LX. Its header’s word at 0x2C is a page offset shift,
where LE has the number of bytes in the last page, and its page entries are 8 bytes,
not 4. A file with LE at e_lfanew that fails the checks is
shown as a plain MS-DOS program, with a note.
Not described
The gaps are those on the EXE overview. For the LE format, the resource table was read from real files with no specification behind it, and one bit of the entry table is unconfirmed.
Variants
- MS-DOS executable (MZ) – 16-bit DOS programs: an MZ header, relocations and the code
- 16-bit Windows executable (NE) – Windows 3.x and early OS/2 programs and DLLs, in movable segments
- Linear Executable (LE) – 32-bit Windows VxD drivers and DOS extender programs, in paged objects
- OS/2 executable (LX) – 32-bit OS/2 programs and DLLs, in paged objects
- Windows executable (PE32) – 32-bit Windows programs and DLLs: an MZ stub, a PE header with a 32-bit optional header, and sections
- Windows 64-bit executable (PE32+) – 64-bit Windows programs and DLLs (x64, ARM64, Itanium): the PE format with a 64-bit optional header
Links
Software
- Windows 3.x, 95, 98 and Me – these systems load LE drivers
- DOSBox – DOS emulator that runs DOS/4GW programs (Windows, macOS, Linux)
- Open Watcom – compiler suite whose linker writes LE files and whose
wdumptool lists them (Windows, Linux, DOS, OS/2) - IDA Pro – commercial disassembler and decompiler (Windows, macOS, Linux)
Reference
- LX – Linear eXecutable Module Format Description – IBM’s description of LX, on EDM2, which covers most of LE’s layout too
- Open Watcom source – its
exeflat.hgives the whole 196-byte header, with the VxD fields - winedump – Wine’s file dumper, whose
le.creads LE files and the VxD header