|
-
May 24th, 2001, 11:06 AM
#5
Re: It says in MSDN...
Other than the double-load bug in the sample code, there's a fundemental misunderstanding of what happens when a PE file is loaded and what happens when MapAndLoad is called.
The short answer to this problem as people have pointed out is that you can't. But here's why you can't:
PE executables are not designed to relocation. Most load on the 4MB boundary, but it does depend on where they've been told to locate themselves.
The purpose of calling CreateProcess is to create a new Virtual Address Space for the exe. Therefore as it has the whole of memory available (virtually speaking) it can load where the hell it wants.
DLLs on the other hand are intended to relocate, therefore the process of calling LoadLibrary and GetAddress will work fine for those types of solution.
If you wanted to load an exe into another exe's address space you have very view options. (1) You have to go through the loaded code and relocate all the addresses (not my idea of fun) or (2) Locate the load exe in a different part of memory so not to clash with the load and then use a Mapping function other than MapAndLoad so that you can force it to load into the correct place.
If you'd looked at the disassembly of your test program in the debugger you'd have got a good hint as to the problem as all the addresses would look wrong as your base would be above 4MB compared to those in the loaded exe.
In fact, one optimization that I've seen exe packing compressors do in Win32 is to strip the relocation block from an exe as its not used.
Whatever way you choose to solve this, it's a heck of a lot of work. Far better to rethink the strategy of what you're going.
MapAndLoad seems to be publically posted source, and from this code you can see it does nothing regarding address fix-up. It's also critical to call UnMapAndLoad when you're done as it maintains a set of handles.
And finally, having said all this, if you choose to fight the great fight. Publish the solution, as it'll be interesting to see how difficult/hard it was to do the relocation and fix-ups.
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
|