I know almost nothing about the PE file format, but I'm looking for the smallest possible MS-DOS program to use as a /stub for the linker. (or is the stub padded?)

The linker will not take a .com and it needs to validate the stub .exe before it will do any linking. I have tried compiling my own, but no matter what I try and no matter what switches I use, the linker just generates a Windows app. I even tried passing it a 2 byte file with Zabrowski's initials, but no deal.

Any help here will be very much appreciated.


-ib
Posted on 2002-03-13 17:12:33 by iblis
my masm32\bin has a "smstub.exe" that is only 80 bytes long.
Posted on 2002-03-13 17:26:23 by f0dder
your masm32\bin must be special f0dder, i don't seem to have that file..
Posted on 2002-03-13 17:47:53 by mc`
Is 80 bytes the bare minimum? Any chance you could upload that?

Thanks
-ib
Posted on 2002-03-13 19:14:03 by iblis
Apart from the DOS header member that passes control to the PE header, not much else of a DOS header is necessary, the first 2 bytes MZ and the PE header offset.

MASM and I think VC as well have the option to use your own MZ header and in the linking stage, it will set the PE header offset in the DOS header BUT it will still build the EXE file to PE specifications so there is no real size advantage.

Here is the dos stub for my tiny editor TheGun.exe, written as REAL men do in HEX. :)



; D:\MASM32\THEGUN\SETTINGS\Gunstub.exe 96 bytes

00000000: 4D 5A 90 00 03 00 00 00 - 04 00 00 00 FF FF 00 00
00000010: B8 00 00 00 00 00 00 00 - 40 00 00 00 00 00 00 00
00000020: 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00
00000030: 01 00 00 00 00 00 00 00 - 00 00 00 00 B8 00 00 00
00000040: 0E 1F BA 0E 00 B4 09 CD - 21 B8 01 4C CD 21 54 68
00000050: 65 47 75 6E 20 69 73 20 - 77 69 6E 33 32 0D 0A 24

Here is the result.


; D:\MASM32\THEGUN\SETTINGS\thegun.exe 6144 bytes

00000000: 4D 5A 90 00 03 00 00 00 - 04 00 00 00 FF FF 00 00
00000010: B8 00 00 00 00 00 00 00 - 40 00 00 00 00 00 00 00
00000020: 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00
00000030: 01 00 00 00 00 00 00 00 - 00 00 00 00 98 00 00 00
00000040: 0E 1F BA 0E 00 B4 09 CD - 21 B8 01 4C CD 21 54 68
00000050: 65 47 75 6E 20 69 73 20 - 77 69 6E 33 32 0D 0A 24
00000060: 6C 3C E2 8E 28 5D 8C DD - 28 5D 8C DD 28 5D 8C DD
00000070: 28 5D 8C DD 79 5D 8C DD - D4 7D 9E DD 2C 5D 8C DD
00000080: EF 5B 8A DD 29 5D 8C DD - 52 69 63 68 28 5D 8C DD
00000090: 00 00 00 00 00 00 00 00 - 50 45 00 00 4C 01 03 00

It just fills the extra space up with junk so you do not gain any size advantage. You can manually code it smaller but you risk the file not running on all versions of Windows.

Regards,

hutch@movsd.com
Posted on 2002-03-13 19:31:40 by hutch--
It's 64 bytes long.

DOS EXE can be smaller than this.
( You can make 32bytes long DOS EXE. :) )

But, Win32 PE executable uses 3CFH offset to indicate their 'PE' signature. You should reserve 3CFH.

Therefore, I think that 64 bytes DOS stub is smallest. :)

Any other answer is welcome!
Posted on 2002-03-14 05:13:40 by nyam
Thank you Nyam!
Posted on 2002-03-14 06:27:23 by iblis
The only real test for a DOS EXE is to run it on plain DOS.

For example on Win2K you can make a .COM with just a ret (1 byte) and then renamed to .EXE and it will function.

But I am pretty sure it will crash on plain DOS.
Posted on 2002-03-14 08:28:49 by dxantos
No dxantos, dos checks the file for MZ/ZM and executes a .exe as
.com if the signature doesn't match.
Posted on 2002-03-14 08:38:04 by f0dder

No dxantos, dos checks the file for MZ/ZM and executes a .exe as .com if the signature doesn't match.



But I am pretty sure it will crash on plain DOS.


Correct me if Im wrong but its seems like the same dog with different name :)
Posted on 2002-03-14 09:15:02 by dxantos
not at all. It sees that the file is indeed a .com (it doesn't have MZ
or ZM signature), and thus dos loads the file as .com even though
it has .exe extension - and thus the RET works.
Posted on 2002-03-14 09:17:27 by f0dder

Is 80 bytes the bare minimum? Any chance you could upload that?

Thanks
-ib
No, you can cut it down to 64 bytes, i.e. the lone MZ header (just stuff your MSDOS print "Requires Win32" code into the unused part of the MZ header).

Greets,
Maverick
Posted on 2002-03-14 12:06:32 by Maverick