Hacker News new | ask | show | jobs
by netsharc 897 days ago
Trivia: all Windows EXEs run on DOS, but most of them just print something like "this program doesn't run on DOS" and terminate.

There are exceptions, like REGEDIT.EXE of Windows 95.

2 comments

And you can replace the default DOS stub file with `/STUB` in the MSVC linker. Different linkers can and do use different stub files, though MSVC and GCC happen to use the same stub file because the original author of the BFD code---that was eventually used by GNU ld to generate a PE file---had apparently no idea what it was...

    /* this next collection of data are mostly just characters.  It appears
       to be constant within the headers put on NT exes */
    filehdr_in->pe.dos_message[0]  = 0x0eba1f0e;
    filehdr_in->pe.dos_message[1]  = 0xcd09b400;
    filehdr_in->pe.dos_message[2]  = 0x4c01b821;
    /* ... snip ... */
    filehdr_in->pe.dos_message[13] = 0x0a0d0d2e;
    filehdr_in->pe.dos_message[14] = 0x24;
    filehdr_in->pe.dos_message[15] = 0x0;
    filehdr_in->pe.nt_signature = NT_SIGNATURE;
(Of course, this code dates back to 1996 or earlier so the existence of DOS stubs might not have been a common knowledge if you didn't do any Windows programming.)

On the other hand, lld uses a functionally same but slightly different stub file [1] because it prints no newlines.

[1] https://github.com/llvm/llvm-project/blob/d7642b2/lld/COFF/W...

Even the DLL's are executables. It is about 100 bytes in where it says the real executable type. Some are OS1.x, win3x, win32... and so on. Think there is also a platform byte (x86, arm, mips, etc). My google fu is failing on the list of different types at the moment.