Is there any way to edit the DOS stub of the output file in masm? Any linker swithches, something?
Posted on 2003-09-23 02:52:37 by Ghirai
You can use your own stub, and use the /stub:mystub.exe option when linking your program.
Posted on 2003-09-23 03:30:24 by f0dder
Cool, and in what can i write that stub? Say TASM or what?
All i want to do is call int 21h to exit...

Ok, here's the code:

.286
DOSSEG
.MODEL SMALL
.STACK 200h
.DATA
.CODE

START:
INT 20
END START

The problem is that link.exe returns: stub.exe : fatal error LNK1132: invalid format for MS-DOS stub file "stub.exe"
What's wrong? The exe works(exits) fine... :confused:
Posted on 2003-09-23 04:13:41 by Ghirai
You can use whatever produces an EXE output - and yes, it must be an EXE file. Plus there is a minimum size, but the linker will take care of that.
Posted on 2003-09-23 04:58:20 by f0dder
Well, my stub is an 4 bytes exe, conatining "?L?!" :)
Do you think it's too small or something?
Posted on 2003-09-23 05:01:38 by Ghirai
you have produced a COM file output - the file extension itself isn't enough.
Posted on 2003-09-23 05:03:32 by f0dder
Ok, i got a exefile, but why is is 517 bytes??? It's a little huge for :

mov ax, 4C00h
int 21h

It's bigger than the original stub that link.exe produces.
Posted on 2003-09-23 05:41:51 by Ghirai
Hi, f0dder.

I don't think above example is .COM file. Com file need "org 100h" and COM format doesn't allow setting stack size. In addition dos linkers creates only EXE files, you must convert it to COM (if such is possible).

regards.
Posted on 2003-09-23 05:43:23 by JohnFound
Hi, Ghirai
May be I'm wrong, but I belive that the bast way to write stub is to use a HEX editor.
Also you should search for some about PE format

Here's my stub for example (I'm near MZ :) )
Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

00000000 4D 5A 00 00 01 00 00 00 02 00 00 00 FF FF 00 00 MZ..........??..
00000010 40 00 00 00 00 00 00 00 40 00 00 00 53 54 41 53 @.......@...STAS
00000020 0E 1F B4 09 BA 0E 00 CD 21 B8 00 4C CD 21 50 45 ..?.?..?!?.L?!PE
00000030 20 66 6F 72 20 57 69 6E 33 32 07 24 00 00 00 00 for Win32.$....


Also link.exe adds some "signature" to yor file.
Here's some info
Posted on 2003-09-23 05:48:21 by S.T.A.S.
JohnFound, according to

Well, my stub is an 4 bytes exe, conatining "?L?!"
Do you think it's too small or something?

the output was a com file - binary, headerless output, anyway.

As for small stub construction... tjah.
Posted on 2003-09-23 08:47:29 by f0dder
Thanks for the stub S.T.A.S., i've already read your post.
I suppose files genrated by the patched link.exe will have no problems running on non NT boxes, right?
Posted on 2003-09-23 09:01:05 by Ghirai
Ghirai,

You can check my dialog box example,it's linked with a stub of 64 bytes.
Posted on 2003-09-23 12:38:10 by Vortex

I suppose files genrated by the patched link.exe will have no problems running on non NT boxes, right?
I'm using link.exe v5 pathed. No problems with my stub uneder Win98SE/2K SP3&4/XP/XP SP1.
Don't know about Win95&NT. Some time is passed after I've last seen these versions :tongue:

IIRC, when we're using original stub, no signature is added.
I think these bytes are "special signs" showing that the prog is linked by ms linker.
Not sure is it legal or not to remove them, but there are other linkers available in inet.
Posted on 2003-09-23 18:23:29 by S.T.A.S.