Results 1 to 2 of 2

Thread: Running files from memory

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Location
    Netherlands
    Posts
    1

    Running files from memory

    Hello,

    I'm new to ASM and mostly use it inline. What I'm trying to do is run a PE32 executable file from memory using inline ASM in Delphi.

    I have the following code;

    var
    FS: TFileStream;
    Mem: TMemoryStream;
    Addr: Pointer;
    begin
    FS := TFileStream.Create('e:\TestApp.exe', fmOpenReadWrite or fmShareDenyWrite);
    Mem := TMemoryStream.Create();

    Mem.CopyFrom(FS, FS.Size);

    Mem.Position := 0;
    Addr := Mem.Memory;

    asm
    JMP Addr
    end;
    end;
    One would expect it to work. At the given address the exe really starts. It's just the raw mem address of the executable. Still, I keep getting Access Violations.

    Anyone know what I'm doing wrong ?

    Thanks,
    - Fahr

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You can't simply load an exe into memory and jump there. The PE loader does more than that. First, it looks in the exe header for the entry point, which is the address where the exe is supposed to start. Second, it looks for a relocation table and uses it to adjust all pointers in the exe in case the exe could not be loaded to the default address 0x00040000.
    Only then does it jump to the address.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width