News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Micro-flaw in the DOS stub generated by MASM

Started by Larry Hammick, September 30, 2005, 07:59:07 AM

Previous topic - Next topic

Larry Hammick

The DOS stub writes this message:
db "This program cannot be run in DOS mode.",0Dh,0Dh,0Ah
Two consecutive carriage returns! An entire byte wasted! But it's easy to fix by poking in the file ml.exe (whose own DOS stub, by the way, has the same flaw).

hutch--

Larry,

There are two solutions, sit up at night wringing your hands in despair or write your own DOS stub. Here is the stub I used to use for a very old version of TheGun.exe.


; H:\masm32\thegun\\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
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Larry Hammick

What I do is paste in a DOS stub at location 40h, because the offset at 3Ch (a pointer to "PE") may change from one build to the next. The pasting is done by a dos utility called snip.exe
www3.telus.net/ldh/asm/SNIP.EXE
At the C prompt, type SNIP|MORE for usage. SNIP can copy any _part_ of any file and, optionally, paste it into any other file at any location. More uses than a Swiss Army knife.
IMO the stub should name the program, and not just say "This program cannot be run...".
BTW there are a couple of ways to write a stub without the instructions push cs / pop ds.