Page 1 of 1
Removing the stub DOS kernel?
Posted: Sun Sep 08, 2013 5:24 pm
by vinicius9107
Hello guys, I'm new here on the forum and I am using Google Translate.
I wanted to know how to remove the DOS stub, for example when I create a binary file in Visual C++ even in native mode subsystem is he still with the sentence "This program can not be run in DOS mode".
As I take that sentence?
Re: Removing the stub DOS kernel?
Posted: Sun Sep 08, 2013 6:12 pm
by VolTeK
Can already imagine how many people are going to wet their panties talking about how the newbie used colors in his/her post.
Other then that, look up PE EXE
Re: Removing the stub DOS kernel?
Posted: Sun Sep 08, 2013 6:25 pm
by vinicius9107
Will you help me or not?
Re: Removing the stub DOS kernel?
Posted: Mon Sep 09, 2013 12:26 am
by sortie
The DOS stub is part of the PE executable format. It's a couple bytes and Windows ignores the DOS header if it detects a magic combination that means it's really a PE file. Don't worry about it, it's not a problem. Is this because you wish to flatten a PE file?
Re: Removing the stub DOS kernel?
Posted: Mon Sep 09, 2013 1:27 am
by h0bby1
you can't remove it if you compile 32 bit pe executable, it used to be usefull as PE format could be used also under DOS, and as dos is in real mode, the linker needed to detect it and prevent a 32 bit protected mode PE to be run under real mode 16 bit environment, so each time you want to compile a 32 bit PE file, it need to add the check, the only way you can get rid of it is by linking the PE as a 16 bit PE exe, most modern C compiler are very awkward at managing real mode assembler code, but as they didn't make a totally different exe format for 32 bit exe, and at that time there was still lot of dos around, and running a PE compiled as 32 bit protected mode under real mode would lead to many problems, so they added this stub, you can't remove it, it's all part of 32 bit pe executable, either you do your own exe format to get rid of it, or compile it as 16 bit code, you can't have 32 pe without this
some size optimized PE loader create the exe as 16 bit, and then decompress the actual exe data into a 32 bit code sections to save the bytes, but it need a special handling of the PE code, and to put all the 32 bit code sections as data and load them as 32 bit when the 16 bit exe is run, but there are many issue with this as windows will automatically load 16 bits PE in special mode, i think windows automatically launch 16 bit PE files in v86 mode, but if (what i assume), you don't want the exe to be loaded by windows, it can be managed, but it need very special handling , you can look at exe size optimizer/compressers like crinkler if you want to know how to optimize PE file for size, it does lot of work on PE headers and sections in order to shrink exe data, it can fit lot more data in very little exe
they explain this here
http://www.phreedom.org/research/tinype/
'Switching to assembly and removing the DOS stub'
but if you want to have really minimalistic exe format for your os, you'd rather make your own, because both PE and elf have many thing for compatibilities, and many things that you don't necessarily need but that need lot of work to get rid of
Re: Removing the stub DOS kernel?
Posted: Tue Sep 10, 2013 11:03 am
by rdos
Real compilers (not M$) allows to place a customer DOS EXE-file as a stub. For instance, my OpenWatcom stub for RDOS executables is only 0x80 bytes large (total of 512 bytes), and contains a custom stub which should have wriitten "This is a RDOS executable" under real DOS, but doesn't do so in Win XP or higher (meaning latter Windows versions doesn't support running the stub when it doesn't understand the PE format).
Re: Removing the stub DOS kernel?
Posted: Tue Sep 10, 2013 11:25 am
by bluemoon
rdos wrote:Real compilers (not M$) allows to place a customer DOS EXE-file as a stub. For instance, my OpenWatcom stub for RDOS executables is only 0x80 bytes large (total of 512 bytes), and contains a custom stub which should have wriitten "This is a RDOS executable" under real DOS, but doesn't do so in Win XP or higher (meaning latter Windows versions doesn't support running the stub when it doesn't understand the PE format).
IIRC the old ML linker also allow customized stub with a linker flag.
Re: Removing the stub DOS kernel?
Posted: Wed Sep 11, 2013 4:08 am
by qw
bluemoon wrote:IIRC the old ML linker also allow customized stub with a linker flag.
The new do too:
http://msdn.microsoft.com/en-us/library ... 20%29.aspx
Re: Removing the stub DOS kernel?
Posted: Wed Sep 11, 2013 4:15 am
by AJ
rdos wrote:...contains a custom stub which should have wriitten "This is a RDOS executable" under real DOS, but doesn't do so in Win XP or higher (meaning latter Windows versions doesn't support running the stub when it doesn't understand the PE format).
This is probably to do with the fact that XP was NT-based whereas 9x ran on top of MS-DOS.
Cheers,
Adam
Re: Removing the stub DOS kernel?
Posted: Thu Sep 19, 2013 4:25 pm
by vinicius9107
Thanks guys, now this solved.