Removing the stub DOS kernel?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
vinicius9107
Posts: 8
Joined: Sun Sep 08, 2013 5:11 pm

Removing the stub DOS kernel?

Post 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?
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Removing the stub DOS kernel?

Post 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
Last edited by VolTeK on Mon Sep 09, 2013 10:36 am, edited 1 time in total.
vinicius9107
Posts: 8
Joined: Sun Sep 08, 2013 5:11 pm

Re: Removing the stub DOS kernel?

Post by vinicius9107 »

Will you help me or not?
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Removing the stub DOS kernel?

Post 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?
h0bby1
Member
Member
Posts: 240
Joined: Wed Aug 21, 2013 7:08 am

Re: Removing the stub DOS kernel?

Post 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
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: Removing the stub DOS kernel?

Post 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).
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Removing the stub DOS kernel?

Post 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.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Removing the stub DOS kernel?

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Removing the stub DOS kernel?

Post 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
vinicius9107
Posts: 8
Joined: Sun Sep 08, 2013 5:11 pm

Re: Removing the stub DOS kernel?

Post by vinicius9107 »

Thanks guys, now this solved.
Post Reply