c - Execute a mapped file on Windows -
hello fellow developers,
i'm trying map executable binary file on windows , execute mapped file.
so far, managed mapping using createfilemapping
, mapviewoffile
. these functions gave me handle mapped file , pointer mapped info have no clue how execute mapped binary. think should utilize createprocess
function should given parameters ?
char *binarypath = "c:/myexecutable.exe"; // binary size std::fstream stream(binarypath, std::ios::in | std::ios::binary); stream.seekg(0, std::ios::end); unsigned int size = stream.tellg(); // create mapped file in paging file scheme handle mappedfile = createfilemapping(invalid_handle_value, null, page_execute_read, 0, size, null); // set executable info mapped file void* mappeddata = mapviewoffile(mappedfile, file_map_read | file_map_execute, 0, 0, size); stream.read((char*)mapping, size); stream.close(); // should ?
there no native way run raw executable image resides in memory. createprocess()
official way run executable image, image must reside on file scheme instead. os loads image memory , patches needed (resolves dll references, etc) run correctly.
with said, have seen third-party code floating around duplicates os when loads executable image memory. i've ever seen used dlls (so code not have utilize loadlibrary/ex()
utilize dll in memory), not exes.
c winapi createprocess file-mapping
No comments:
Post a Comment