I have seen code that adds or removes sections from PE files after they
are created, but it's non-trivial. Apparently offsets in the PE file
are all absolute (rather than relative to the section), so adding more
code at the beginning of the file mucks everything up.
Can you cheat a bit? How about leaving your proposed "stub" as a
separate exe? Then open your 32bit exe and overwrite 64 bytes of stub
the ld creates with something that launches your stub program? Some
variation of:
push cs
pop ds ; Used with DX for asciiz file name
push cs
pop es ; Used with BX for Launch
mov ax, 0x4b00 ; Function code for DOS Exec
mov dx,?? ; offset from 0x40 of asciiz file name
mov bx, 0x40 ; location to put psp
int 21 ; Launch exe
mov ah, 0x4c ; Function code for Exit to DOS
; Leave al return code from Launch unchanged
int 21 ; Exit to DOS
16.exe\0
I believe that even including the file name, that's less than 30 bytes.
Room to spare. So now when my32bitapp.exe is run, it turns around and
launches 16.exe. Tada!
dw
On 12/5/2014 2:26 PM, bulk 88 wrote:
> Date: Fri, 5 Dec 2014 09:49:55 +0100
> From: ktiet...@googlemail.com
> To: mingw-w64-public@lists.sourceforge.net
> Subject: Re: [Mingw-w64-public] adding dos stub program with ld to
PE binary
>
> 2014-12-05 6:45 GMT+01:00 bulk88 <bul...@hotmail.com>:
> > What is the GCC ld equivalent of Visual C's -stub ?
> > http://msdn.microsoft.com/en-us/library/7z0585h5.aspx I need to
add a MZ
> > header-ed dos program to my PE binary instead of the default "This
> > program cannot be run in DOS mode" program.
> >
>
> Hmm, interesting option. AFAI know does ld do not provide such
> feature. It wouldn't be too hard to implement it.
> So sorry, for now this feature isn't present.
>
> Kai
I found the default dos header lives in
_bfd_XXi_only_swap_filehdr_out() but that code is beyond what I can do.
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public