Skip to content

Commit 21cd6aa

Browse files
committed
[BUGFIX] Fixed load_payload func
1 parent 9827905 commit 21cd6aa

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

project_template/main.cpp

+17-15
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,27 @@ bool load_payload(LPCTSTR pe_path)
2727
*/
2828
size_t bufsize = 0;
2929
BYTE* buf = peconv::load_file(pe_path, bufsize);
30-
if (buf) {
31-
// if the file is NOT dropped on the disk, you can load it directly from a memory buffer:
32-
g_Payload = peconv::load_pe_executable(buf, bufsize, g_PayloadSize);
30+
if (!buf) {
31+
return false;
32+
}
33+
// if the file is NOT dropped on the disk, you can load it directly from a memory buffer:
34+
g_Payload = peconv::load_pe_executable(buf, bufsize, g_PayloadSize);
3335

34-
// if the loaded PE needs to access resources, you may need to connect it to the PEB:
35-
peconv::set_main_module_in_peb((HMODULE)g_Payload);
36+
// at this point we can free the buffer with the raw payload:
37+
peconv::free_file(buf); buf = nullptr;
38+
39+
#endif
40+
if (!g_Payload) {
41+
return false;
42+
}
3643

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

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

44-
if (!g_Payload) {
45-
return false;
46-
}
47-
}
48-
#endif
4951
return true;
5052
}
5153

0 commit comments

Comments
 (0)