From e32c546536e534ba7465929cbe03b678913b7d32 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Wed, 20 Oct 2004 20:32:18 +0000 Subject: [PATCH] - debug output disabled by default - tries to allocate memory at arbitrary address if specified ImageBase is invalid or cannot be allocated --- MemoryModule.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MemoryModule.c b/MemoryModule.c index 7426dac..6dcfc31 100644 --- a/MemoryModule.c +++ b/MemoryModule.c @@ -24,8 +24,6 @@ // disable warnings about pointer <-> DWORD conversions #pragma warning( disable : 4311 4312 ) -#define DEBUG_OUTPUT 1 - #include #include #ifdef DEBUG_OUTPUT @@ -300,6 +298,13 @@ HMEMORYMODULE MemoryLoadLibrary(const void *data, const size_t size) MEM_RESERVE, PAGE_READWRITE); + if (code == NULL) + // try to allocate memory at arbitrary position + code = (unsigned char *)VirtualAlloc(NULL, + old_header->OptionalHeader.SizeOfImage, + MEM_RESERVE, + PAGE_READWRITE); + if (code == NULL) { #if DEBUG_OUTPUT