Skip to content

Commit

Permalink
[BUGFIX] Fixed load_payload func
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Aug 12, 2022
1 parent 9827905 commit 21cd6aa
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions project_template/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,27 @@ bool load_payload(LPCTSTR pe_path)
*/
size_t bufsize = 0;
BYTE* buf = peconv::load_file(pe_path, bufsize);
if (buf) {
// if the file is NOT dropped on the disk, you can load it directly from a memory buffer:
g_Payload = peconv::load_pe_executable(buf, bufsize, g_PayloadSize);
if (!buf) {
return false;
}
// if the file is NOT dropped on the disk, you can load it directly from a memory buffer:
g_Payload = peconv::load_pe_executable(buf, bufsize, g_PayloadSize);

// if the loaded PE needs to access resources, you may need to connect it to the PEB:
peconv::set_main_module_in_peb((HMODULE)g_Payload);
// at this point we can free the buffer with the raw payload:
peconv::free_file(buf); buf = nullptr;

#endif
if (!g_Payload) {
return false;
}

// load delayed imports (if present):
const ULONGLONG loadBase = (ULONGLONG)g_Payload;
peconv::load_delayed_imports(g_Payload, loadBase);
// if the loaded PE needs to access resources, you may need to connect it to the PEB:
peconv::set_main_module_in_peb((HMODULE)g_Payload);

// at this point we can free the buffer with the raw payload:
peconv::free_file(buf); buf = nullptr;
// load delayed imports (if present):
const ULONGLONG loadBase = (ULONGLONG)g_Payload;
peconv::load_delayed_imports(g_Payload, loadBase);

if (!g_Payload) {
return false;
}
}
#endif
return true;
}

Expand Down

0 comments on commit 21cd6aa

Please sign in to comment.