|
-
Mar 18th, 2003, 03:59 AM
#1
Thread Starter
New Member
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
-
Mar 23rd, 2003, 03:51 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|