Subject: dos stub
From: [email-masked] (root)

21 Dec 1998 02:21:05 -0800
Message-ID: <[email-masked]>
Content-Type: text
To: [email-masked]

> Is there anyway to attach a dos program to a windows program so it will
> run whtn the program is started in dos instead of windows.  I think
> Visual C++ calls it a stub program.
> 
All windows 95/NT executables have a 'dos stub' at the beginning of the file.
This program will be activated by the DOS loader, since it is actually the
data for a small program that displays:

'This program can't be run in DOS mode'

at the user screeni and quits.

The linker of lcc-win32 appends this stub at the beginning of the executable
but it is fixed, i.e. the linker considers it as a fixed data part of the
executable.
I think Gnu's linker 'ld' does the same thing. Theoretically you could change
this program by any other dos program. If you look at the structure definition
for IMAGE_DOS_HEADER, in the standard windows header files, you will see the
field e_lfanew, that points the Win32 loader to the beginning of the real
executable file. You could, theoretically I repeat, change the data following
this header to another dos program, and modify the dos header accordingly, to
point to the new location where your (presumably bigger) dos stub ends.

This would be quite a lot of work actually, since the linker has to be
recompiled and modified...
You should then, do the following:

1) Get the sources of 'ld' and rebuild it from source.
2) Compile a dos program of your choice.
3) Modify the linker to read a new command line option to give it the name
   of the stub.
4) Figure out which part of the dos program has to be copied into the
   win32 executable. I presume the header at least should be stripped.
5) Instruct 'ld' to do this automatically, and append this to the exe. Since
   the dos header now is not fixed, many things later on in the linker could
   brake since the offsets from the beginning of the file would be variable...
   This will add excitment and fun to this undertaking.
6) Testing your modifications involves testing under windows to see if the
   program still loads, rebooting and testing under DOS to see if the stub is
   displayed correctly and DOS still lives after loading it!

Have fun!

-- 
Jacob Navia	Logiciels/Informatique
41 rue Maurice Ravel			Tel 01 48.23.51.44
93430 Villetaneuse 			Fax 01 48.23.95.39
France
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".