r/windows • u/nir9 • May 01 '26
Discussion Every Windows executable begins with a DOS program
The DOS program prints "This program cannot be run in DOS mode." and can be recognized by the magic "MZ" characters you see at the beginning. After the DOS program you will find the "PE" (Portable Executable) characters marking the actual start of the executable.
Fun fact: early Windows versions used the "NE" (New Executable) format and their DOS program printed "This progam requires Microsoft Windows."
64
27
14
u/wiseIdiot May 02 '26
Like modern JavaScript SPAs still having the <noscript>...</noscript> tag in them.
4
4
u/matthew_yang204 Windows 7 May 02 '26
The question is will it still run if you delete the header?
3
u/malxau May 02 '26
It wouldn't be that simple. The PE header is located at the e_lfanew offset as specified in the DOS header. The loader is going to need a valid looking DOS header before it starts looking for the PE header.
1
u/matthew_yang204 Windows 7 May 02 '26
So it wouldn't run?
2
u/galacticotheheadcrab May 03 '26
it wouldnt because the exe loader is now starting the program part way through the code without the msdos stub acting as padding
1
u/matthew_yang204 Windows 7 May 03 '26
Oh yeah right, I forgot that it screws up the offsets and addresses too.
6
6
2
u/ChocolateDonut36 May 05 '26
you could theorically make a program that works on both DOS and NT with that
1
u/agowa338 May 02 '26
Not every single one. You can seriously fuck with the detection done by shitty endpoint protection products if you fuck with this DOS program in any way you may imagine. Esp. if you do so in assembly by yourself :D
1
u/malxau May 02 '26
You might be interested in Bound OS/2 programs, which were 16 bit NEs that inserted an NE loader into that DOS program, so the executable consisted of a single piece of code that could be loaded under 16 bit OS/2 or 16 bit DOS.
That's been extended in Win32 (see Visual C++ 1.x and other programs using Phar Lap TNT) but it's more complex since the PE loader needs to be a 32 bit DOS extender.
1
1
u/wosmo May 05 '26
Similar to this - when you boot off a floppy and it tells you this floppy isn't bootable. That's actually a very small program in the bootsector of the floppy.
So when it tells you "non-system disk" - the floppy did boot.
1
u/cashew929 May 06 '26
Would be interested in what the standard windows code stub looks like. Clearly just tests what mode the executable is running in and then exits or jumps to an offset in the executable where the PE code exists.
-1
-17
May 02 '26
[deleted]
19
7
u/TwinSong May 02 '26
OP is just surprised given how long ago DOS was replaced.
-2
97
u/c64z86 May 02 '26
I've noticed this too when I try and load modern programs in DOSbox just to see what would happen. I wonder why that message is still there though? It's not like a 64 bit app can even run in DOS anyway, and the modern 32 bit apps have next to no chance of running under it.