- How long you been coding/hacking?
- 5y+
I'm trying to start an exe by "calling" its entry point, aka run PE in memory; so far I've managed to map the whole PE stuff (with this guide!) into memory and the PE runs successfully without errors, but the caller (main process) also terminated along with the callee (the mapped exe's entry point)...... that's not how a function call should be right!?
Full source: ken1882/Mem-PE-Exec
(Compile and enter path to exe desire to make it run in memory)
And the exe I mapped:
what am I missing here?
EDIT: Solved myself, see post below
main code snippet:
parseHeader32();
if(_reloced){ applyRelocation32(); }
parseImport32();
parseTLS32();
uintptr_t entry_addr = INH32.OptionalHeader.ImageBase + INH32.OptionalHeader.AddressOfEntryPoint;
std::cout << "Entry addr: " << (void*)entry_addr << '\n';
((void(*)()) entry_addr)(); // PE starts up nicely
// (int(*)()) entry_addr)(); // will not "return to parent" too
// never reaches here :(
std::cout << "This line will not execute\n";
(Compile and enter path to exe desire to make it run in memory)
And the exe I mapped:
C++:
#include <windows.h>
int main(void){
MessageBoxA(NULL, "Test Message", "TEST", 0x0);
return 0;
}
EDIT: Solved myself, see post below
Last edited: