Adding a section to a PE executable at runtime



Hey all,

I want to add a new 'section' of code to a PE executable. I'll redirect the entry point of the .exe to the new section so that I can run code before the application starts running (No, I'm not writing a virus :)). I've written a little tool which should be able to do this: It adds an entry into the section table, writes out the new section (Padded out to and aligned on the FileAlignment size), and updates ImageSize (ie. RoundUpToSectionAlignment( Sections[lastsection].VirtualAddress+Sections[lastsection].VirtualSize) ). But Windows chokes on the .exe, giving "My program.exe is not a valid Win32 application".

The modified .exe looks kosher in PEBrowse professional. How can I figure out why Windows is rejecting my .exe?

Cheers,
Nicholas Sherlock

--
http://www.sherlocksoftware.org
.



Relevant Pages

  • Re: Invoking Console Applications Program.Main from another project
    ... Is it possible to invoke the entry point of a console application project from another project. ... do I have to invoke the associated exe as per the post below ... initialization to happen, but it might not; ...
    (microsoft.public.dotnet.languages.csharp)
  • Softice newbie, packed Win32 exe debug question.
    ... have an exe packed with UPX compression. ... Then it immediately executes the binary ... without breaking at the entry-point - how do I break it at that entry ... I have spent several hours searching on Google/SI docs for info, ...
    (comp.lang.asm.x86)
  • Softice newbie, packed win32 exe question.
    ... have an exe packed with UPX compression. ... Then it immediately executes the binary ... without breaking at the entry-point - how do I break it at that entry ... I have spent several hours searching on Google/SI docs for info, ...
    (microsoft.public.development.device.drivers)
  • Re: Adding a section to a PE executable at runtime
    ... I've written a little tool which should be able to do this: It adds an entry into the section table, writes out the new section, and updates ImageSize (ie. RoundUpToSectionAlignment( ... But Windows chokes on the .exe, giving "My program.exe is not a valid Win32 application". ... The function InsertDebugDataIntoExecutableFile creates a new section and updates the file on the disk. ...
    (borland.public.delphi.language.basm)
  • Re: using exe as dll
    ... >It is possible to export functions out of exe and then use it as ... >dll.What are the potential problems? ... the initial entry point goes instead to main or ... Thus, although you CAN load an executable as a DLL, as soon ...
    (microsoft.public.win32.programmer.kernel)