c++ how to run an .exe file whose contents are sto

2020-06-23 02:11发布

问题:

I'm making a specific program and i just wondered if I could do this: run a file whose contents are stored in a char array ON WINDOWS.

this is the code that reads the executable and stores it in a char array:

filetoopen.open (C:\blahlbah.exe, ios::binary);
filetoopen.seekg (0, ios::end);
length = filetoopen.tellg();
filetoopen.seekg (0, ios::beg);
buffer = new char [length];
filetoopen.read (buffer, length);
filetoopen.close();

I heard something about RunPE and I did some searching, I haven't succeeded in finding any piece of C++ code to use.

回答1:

This shows how to Load an EXE File and Run It from Memory : http://www.codeproject.com/KB/cs/LoadExeIntoAssembly.aspx

Additional readings here : CreateProcess from memory buffer and here : How to run unmanaged executable from memory rather than disc