Skip to content

Commit e32c546

Browse files
committed
- debug output disabled by default
- tries to allocate memory at arbitrary address if specified ImageBase is invalid or cannot be allocated
1 parent 37fc1b6 commit e32c546

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

MemoryModule.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
// disable warnings about pointer <-> DWORD conversions
2525
#pragma warning( disable : 4311 4312 )
2626

27-
#define DEBUG_OUTPUT 1
28-
2927
#include <Windows.h>
3028
#include <winnt.h>
3129
#ifdef DEBUG_OUTPUT
@@ -300,6 +298,13 @@ HMEMORYMODULE MemoryLoadLibrary(const void *data, const size_t size)
300298
MEM_RESERVE,
301299
PAGE_READWRITE);
302300

301+
if (code == NULL)
302+
// try to allocate memory at arbitrary position
303+
code = (unsigned char *)VirtualAlloc(NULL,
304+
old_header->OptionalHeader.SizeOfImage,
305+
MEM_RESERVE,
306+
PAGE_READWRITE);
307+
303308
if (code == NULL)
304309
{
305310
#if DEBUG_OUTPUT

0 commit comments

Comments
 (0)