Page 1 of 1

Way to replace DOS part of an EXE?

Posted: Tue Mar 23, 2010 8:06 pm
by Firestryke31
I was wondering if there existed a way to replace the DOS part of a PE EXE, so I wouldn't have to write a potentially buggy utility to do that. I'm using VC++08EE to write the PE part, in case there's some hidden thing in there.

I'm working on my bootloader, which at this point will load and try to run the MZ exe. The problem is that the default stub does not do what I need it to in any way, shape or form, and depends on DOS (big surprise there), which my stage1 is not. I want to write a new stub that will set up the environment for, as well as parse and set up, the PE part of the EXE, so that hopefully the second stage can be run by both my stage1 and eventually an EFI setup (though I don't have a clue how I'm going to test that without any EFI emulator, unless someone can suggest one of those too).

Re: Way to replace DOS part of an EXE?

Posted: Wed Mar 24, 2010 3:06 am
by qw
The WDOSX DOS extender does that. It is quite old but very good. It replaces the DOS stub with its own. The stub contains the DPMI server, PE loader and a decompressor (as the original file gets compressed). You could have a look at its source code.

Re: Way to replace DOS part of an EXE?

Posted: Wed Mar 24, 2010 6:27 am
by Gigasoft
When you link, use the /STUB:filename option and specify an existing MZ exe as the filename.

Re: Way to replace DOS part of an EXE?

Posted: Wed Mar 24, 2010 7:57 am
by qw
Gigasoft, you are right of course, but the OP still needs a stub.

Re: Way to replace DOS part of an EXE?

Posted: Wed Mar 24, 2010 9:18 am
by Firestryke31
I can make the stub (I wanted to do it myself anyway), I just didn't know how to get it into the PE file without doing it manually. I'll try the /STUB:blah thing, I hope it works. Does it automatically resize the header to lop off unneeded padding (since YASM's EXE output pads the header to 512 bytes)?