Re: Adding a section to a PE executable at runtime



Nicholas Sherlock a écrit :
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?

This question is OT in this group. You should post this article in news://newsgroups.borland.com:119/borland.public.delphi.language.delphi.win32 or news://newsgroups.borland.com:119/borland.public.delphi.nativeapi.win32

However, you can find a working implementation of this functionality in the Jedi Code Library (JCL http://jcl.sf.net) in the unit JclDebug.pas. The function InsertDebugDataIntoExecutableFile creates a new section and updates the file on the disk.

Best regards,

--
Florent Ouchet
.



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: Using AttachConsole() to run GUI app in command prompt console
    ... After we discussed in your previous post, my thought truns to the entry point of an .exe. ... Microsoft Online Partner Support ...
    (microsoft.public.win32.programmer.kernel)
  • 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)