The DOS header and DOS stub

The DOS header is only used for backward compatibility, and precedes the DOS stub that displays an error message stating that the program might not run in DOS mode.

As per the official PE documentation (available at https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format#ms-dos-stub-image-only), the MS-DOS stub enables Windows to properly execute the image file, even though it has an MS-DOS stub.

It is placed at the front of the EXE image and prints out the message, This program cannot be run in DOS mode, when the image is run in MS-DOS.

The DOS header includes some fields for backward compatibility, and is defined as follows:

typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header    WORD   e_magic;                     // Magic ...

Get Hands-On Artificial Intelligence for Cybersecurity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.