Introduction
NE, short for New Executable, is the format of programs and libraries for 16-bit Windows, from Windows 1.0 in 1985 to Windows 3.11, and for OS/2 1.x from 1987. It added what DOS programs lacked: code and data split into segments that can be loaded, moved and discarded on demand, imports from other modules by name or number, exports that other modules can call, and resources such as icons, menus and dialogs stored inside the file.
The same format is used for programs (.exe), libraries
(.dll) and drivers (.drv). Windows 3.x font files
(.fon) are NE files that hold only resources. 64-bit Windows no longer
runs NE programs. OS/2 1.x NE files keep their resources as segments rather than in a
Windows resource table; see The resource
table. The other .exe formats are on the
.EXE page.
The code is 16-bit x86, for the processor’s real mode or 16-bit protected mode; the instructions are described in the x86 instruction reference.
A program dropped on any page opens in the explorer, which shows its structure, table by table, 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 NE file begins with an MS-DOS header and a small DOS program, the stub. The 32-bit
offset at 0x3C of the DOS header points to the 64-byte NE header, which
starts with NE. The header holds the entry point, the stack, the flags and
the target system, and the offsets of a run of tables that usually follow it straight
away. Most of those offsets count from the start of the NE header; the non-resident name
table’s counts from the start of the file. The segments and resources follow, at
positions given in units of a power of two set in the header. All numbers are
little-endian.
0x00DOS header withe_lfanewat0x3C, then the DOS stubvariese_lfanewNE headerNE, the linker version, flags, entry point and stack, counts and table offsets64 bytes+ne_segtabSegment table where each segment is, its size and flags8 bytes each+ne_rsrctabResource table resource types, then where each resource isvaries+ne_restabResident name table the module name and names of exportsvaries+ne_modtabModule reference table the modules it imports from2 bytes each+ne_imptabImported names table module and function namesvaries+ne_enttabEntry table the exported entry points, by ordinalvariesne_nrestabNon-resident name table the description and more export namesvaries…Segment data, each followed by its relocation records, and resource datavaries
Segments, imports and exports
The program’s code and data are segments of up to 64 KB, each numbered from 1 in the segment table. Windows loads a segment when it is first needed, unless it is marked preload, and can move or discard it later. Places in a segment that hold an address of another segment, or of a function in another module, are listed in relocation records stored after the segment’s data, and Windows patches them when it loads the segment.
A module refers to another module by its index in the module reference table, and to a function in it by number (its ordinal) or by name. Its own exports are listed in the entry table by ordinal, and the name tables give the names of some of them.
The code
The explorer disassembles every code segment as 16-bit code, or 32-bit when the
segment’s 32-bit flag is set, with addresses counted from 0 in the segment, and the
DOS stub as well. It marks the entry point and the exported functions, and names each
place that calls an imported function, such as → KERNEL.91 or
→ USER!MessageBox, by following the relocation records and their
chains; for a far pointer it names the far CALL (9A) just
before it. See Relocation records and
the x86 instruction reference.
Reference pages
- The DOS and NE headers – the DOS header, e_lfanew, the stub, and every field of the NE header
- The segment table – segment entries, their flags, and where the data is
- The resource table – TYPEINFO and NAMEINFO records, names, the data, and OS/2’s form
- Resident and non-resident names – the module name, its description and the names of exports
- Module references and imported names – the modules and functions a module imports
- The entry table – bundles of fixed, movable and constant entry points
- Relocation records – address types, targets, additive records and chains
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. The explorer
takes a file as NE when:
- the file is at least 64 bytes long, and the two bytes at
e_lfanewareNE; - the 64-byte NE header is inside the file;
- the segment table offset is at least
0x40, past the header; - the offsets of the entry table, segment table, resource table, resident name table, module reference table and imported names table are all inside the file;
- the whole segment table and module reference table are inside the file;
- the alignment shift is 24 or less.
A file with LE, LX or PE\0\0 there is one of
the LE, LX,
PE32 or
PE32+ formats; one that fails these checks is
shown as a plain MS-DOS program. To tell a program
from a library, check bit 15 of the flags
word at 0x0C of the NE header, which is set for a library.
Not described
The gaps are those on the EXE overview. For the NE format, some header values and the NE checksum are not confirmed by any source.
Also used for
- .NET assembly – .NET assemblies and modules: a PE file with ECMA-335 metadata tables, heaps and signatures.
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
- DOSBox-X – DOS emulator that can run Windows 3.x and its programs (Windows, macOS, Linux)
- Wine – runs Windows programs, including 16-bit ones, on other systems; its
winedumptool lists NE files (Linux, macOS) - winevdm (otvdm) – runs 16-bit Windows programs on 64-bit Windows (Windows)
- Open Watcom – compiler suite whose linker writes 16-bit Windows programs and whose
wdumptool lists them (Windows, Linux, DOS, OS/2) - Ghidra – the NSA’s free reverse engineering suite (Windows, macOS, Linux)
- IDA Pro – commercial disassembler and decompiler (Windows, macOS, Linux)
Reference
- The NE EXE File Format – fileformat.info’s copy of a description from Corion.net, with the header flags and target systems
- NE – the OSDev wiki’s page on the format
- winedump – Wine’s dumper, whose
ne.creads the segment, resource, entry and relocation tables (C)