Introduction
On Windows NT and its successors, a .sys file is usually a kernel-mode
driver: code that the system loads into the kernel to control hardware, a file system
or a filter. In the file it is a PE image
(PE32+ on 64-bit Windows), with the headers,
sections and tables described on the .EXE page. The
extension is also used by MS-DOS for device drivers, which are a different, much
simpler format and are not described here.
A file dropped on any page opens in the explorer as a PE file, with its structure and code.
What is particular
- Subsystem. The optional header’s subsystem field says how the
image is run. A kernel-mode driver has the value 1,
IMAGE_SUBSYSTEM_NATIVE, which Microsoft describes as “device drivers and native Windows processes”. Windows programs have 2 (GUI) or 3 (console). - Entry point. For a program the entry point address is where the
process starts. For a driver the same field holds the address of the driver’s
initialisation routine,
DriverEntry, which the system calls once, when the driver is loaded, with a pointer to the driver object and the registry path of the driver’s service key. It fills in the driver object with the addresses of the routines that the system will call later (unload, and the handlers for requests). It returns a status, and a failure leaves the driver unloaded. - Not run from a command line. A driver is started as a service by the service control manager or the kernel, not launched like a program, and runs in the kernel’s address space at high privilege. On 64-bit Windows it must be signed.
- Imports. A driver imports from the kernel and its support
libraries (
ntoskrnl.exe,hal.dlland similar), not from the Win32 libraries.
The imports can be read in the explorer’s Imports view, and the subsystem in the optional header. For a driver that is also a library for other drivers, see the export table on the DLL page.
Not described
Known, not yet covered
- Reference: the driver model (WDM, KMDF), driver signing, and the driver packages that carry the file.
- Reference: MS-DOS device drivers, which also use .sys but are not PE files.
Links
Software
Reference
- PE Format – Microsoft’s specification, including the subsystem values
- DriverEntry for KMDF drivers – the entry point of a kernel-mode driver