This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

dos stub



> 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
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]