The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Larry Hammick on November 12, 2007, 09:06:11 AM

Title: a utility about DOS stubs
Post by: Larry Hammick on November 12, 2007, 09:06:11 AM
The DOS stub used by MS Link is unnecessarily large, and it contains débris. Also, rather than say "This program cannot be run...", it's slightly better for the user to see the /name/ of the program that won't run. Attached is an applet which improves the DOS stub of any PE from Link. MASM source included.

[attachment deleted by admin]
Title: Re: a utility about DOS stubs
Post by: Vortex on November 12, 2007, 07:01:13 PM
Hi Larry,

Nice idea. Did you try it with Pelle's linker Polink creating smaller executables? This tool is supplied with the Masm32 package.
Title: Re: a utility about DOS stubs
Post by: Larry Hammick on November 12, 2007, 08:26:37 PM
I haven't seen the newer linkers. I should download one or two of them. BTW I tried GoLink on the peek.dll source, and there's a problem with the exported symbols. The COFF file made by MASM seems to store the exported symbol names with a leading underscore, e.g. _regs for the public regs. If I tell GoLink to look for those symbols, it finds them, but then the dll contains bad addresses. What's the fix? Thx.
Title: Re: a utility about DOS stubs
Post by: Vortex on November 12, 2007, 09:11:15 PM
Hi Larry,

Yes, ml.exe decorares the exported symbols. Linking Masm object files with GoLink is easy. I attached an example for you.

To see the decoration sheme :

\masm32\bin\dumpbin /symbols Iconsamp.obj

.
.
.
01A 00000000 UNDEF  notype ()    External     | _RegisterClassExA@4
01B 00000000 UNDEF  notype ()    External     | _ShowWindow@8
01C 00000000 UNDEF  notype ()    External     | _TranslateMessage@4
01D 00000000 UNDEF  notype ()    External     | _UpdateWindow@4
01E 00000004 SECT3  notype       Static       | hIcon
01F 00000000 SECT3  notype       Static       | hInstance
020 00000000 SECT1  notype       External     | _start
021 0000000C SECT2  notype       Static       | AppName
022 00000000 SECT2  notype       Static       | ClassName
023 00000034 SECT1  notype ()    External     | _WinMain@16
024 00000112 SECT1  notype ()    External     | _WndProc@16
.
.
.



[attachment deleted by admin]
Title: Re: a utility about DOS stubs
Post by: Larry Hammick on November 13, 2007, 03:52:47 AM
Somewhat smarter dosstub source attached.

[attachment deleted by admin]
Title: Re: a utility about DOS stubs
Post by: Larry Hammick on November 14, 2007, 12:51:48 AM
A fix is needed. At the end of the source, below the line
;we want to erase any debris...
replace the remainder with this:

    mov edi,PaddingNeeded
    or edi,edi
    jz short @F      ;writing zero bytes would truncate the file!
    invoke LocalAlloc,LMEM_ZEROINIT,edi
    or eax,eax
    jz short @F
    mov edx,esp
    invoke WriteFile,esi,eax,edi,edx,0
@@: invoke CloseHandle,esi
    jmp quit

end Start