----- Original Message -----
From: "Paul Moore" <pf_moore@...>
Sent: Friday, September 10, 2004 4:07 AM
Subject: [Mingw-users] Re: How do I change the subsystem of an executable?
> Christof Petig <christof@...> writes:
> > Earnie Boyd schrieb:
> >> I don't remember which byte in the executable header; but it is
> >> possible to do the binary edit. It has been discussed on this list
> >> many many months and into years ago.
> > this is the program we (MAGuS project) use to switch it.
> Thanks - that helps a lot. With this, I can write something to do
> what I want, and it's simple enough that it isn't an issue to do so.
> Earnie - I did try searching the archives, but I didn't manage to
> find the right combination of search terms to locate anything...
> [Later] Actually, a bit more experimenting leaves me somewhat
> puzzled. It doesn't seem that simple. For example, I have a program
> (gnudoit.exe) which displays as a console app using MS's DUMPBIN or
> Mingw's objdump, but which has a zero at offset 0xdc. MSDN documents
> a PE format which looks a bit more complex than just a fixed-offset
> format. This is starting to look harder, which is why I was hoping
> that it already existed - but if it doesn't, I'll either do without
> or write something for myself.
> Thanks for the information, anyway.
If you look at the PE format you will see that there is really only one
extra step required to get the proper offset: read a 32-bit value from
offset 0x3c to get the offset of the PE signature, then access the subsystem
type at offset 0x5c from the signature. I suppose the 0xdc value works for
MinGW-generated executables because the MS-DOS stub is a known size.