Way to replace DOS part of an EXE?

Programming, for all ages and all languages.
Post Reply
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Way to replace DOS part of an EXE?

Post 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).
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Way to replace DOS part of an EXE?

Post 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.
Gigasoft
Member
Member
Posts: 855
Joined: Sat Nov 21, 2009 5:11 pm

Re: Way to replace DOS part of an EXE?

Post by Gigasoft »

When you link, use the /STUB:filename option and specify an existing MZ exe as the filename.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Way to replace DOS part of an EXE?

Post by qw »

Gigasoft, you are right of course, but the OP still needs a stub.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Way to replace DOS part of an EXE?

Post 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)?
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Post Reply