News:

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

a utility about DOS stubs

Started by Larry Hammick, November 12, 2007, 09:06:11 AM

Previous topic - Next topic

Larry Hammick

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]

Vortex

Hi Larry,

Nice idea. Did you try it with Pelle's linker Polink creating smaller executables? This tool is supplied with the Masm32 package.

Larry Hammick

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.

Vortex

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]

Larry Hammick

Somewhat smarter dosstub source attached.

[attachment deleted by admin]

Larry Hammick

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