2929#pragma warning( disable : 4311 4312 )
3030#endif
3131
32- #ifdef _WIN64
33- #define POINTER_TYPE ULONGLONG
34- #else
35- #define POINTER_TYPE DWORD
36- #endif
37-
3832#include <windows.h>
3933#include <winnt.h>
34+ #include <stddef.h>
4035#include <tchar.h>
4136#ifdef DEBUG_OUTPUT
4237#include <stdio.h>
@@ -103,7 +98,7 @@ CopySections(const unsigned char *data, PIMAGE_NT_HEADERS old_headers, PMEMORYMO
10398 MEM_COMMIT ,
10499 PAGE_READWRITE );
105100
106- section -> Misc .PhysicalAddress = (DWORD ) (POINTER_TYPE ) dest ;
101+ section -> Misc .PhysicalAddress = (DWORD ) (uintptr_t ) dest ;
107102 memset (dest , 0 , size );
108103 }
109104
@@ -117,7 +112,7 @@ CopySections(const unsigned char *data, PIMAGE_NT_HEADERS old_headers, PMEMORYMO
117112 MEM_COMMIT ,
118113 PAGE_READWRITE );
119114 memcpy (dest , data + section -> PointerToRawData , section -> SizeOfRawData );
120- section -> Misc .PhysicalAddress = (DWORD ) (POINTER_TYPE ) dest ;
115+ section -> Misc .PhysicalAddress = (DWORD ) (uintptr_t ) dest ;
121116 }
122117}
123118
@@ -140,7 +135,7 @@ FinalizeSections(PMEMORYMODULE module)
140135 int i ;
141136 PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION (module -> headers );
142137#ifdef _WIN64
143- POINTER_TYPE imageOffset = (module -> headers -> OptionalHeader .ImageBase & 0xffffffff00000000 );
138+ uintptr_t imageOffset = (module -> headers -> OptionalHeader .ImageBase & 0xffffffff00000000 );
144139#else
145140 #define imageOffset 0
146141#endif
@@ -154,7 +149,7 @@ FinalizeSections(PMEMORYMODULE module)
154149
155150 if (section -> Characteristics & IMAGE_SCN_MEM_DISCARDABLE ) {
156151 // section is not needed any more and can safely be freed
157- VirtualFree ((LPVOID )((POINTER_TYPE )section -> Misc .PhysicalAddress | imageOffset ), section -> SizeOfRawData , MEM_DECOMMIT );
152+ VirtualFree ((LPVOID )((uintptr_t )section -> Misc .PhysicalAddress | imageOffset ), section -> SizeOfRawData , MEM_DECOMMIT );
158153 continue ;
159154 }
160155
@@ -176,7 +171,7 @@ FinalizeSections(PMEMORYMODULE module)
176171
177172 if (size > 0 ) {
178173 // change memory access flags
179- if (VirtualProtect ((LPVOID )((POINTER_TYPE )section -> Misc .PhysicalAddress | imageOffset ), size , protect , & oldProtect ) == 0 )
174+ if (VirtualProtect ((LPVOID )((uintptr_t )section -> Misc .PhysicalAddress | imageOffset ), size , protect , & oldProtect ) == 0 )
180175#ifdef DEBUG_OUTPUT
181176 OutputLastError ("Error protecting memory page" )
182177#endif
@@ -275,7 +270,7 @@ BuildImportTable(PMEMORYMODULE module)
275270 if (directory -> Size > 0 ) {
276271 PIMAGE_IMPORT_DESCRIPTOR importDesc = (PIMAGE_IMPORT_DESCRIPTOR ) (codeBase + directory -> VirtualAddress );
277272 for (; !IsBadReadPtr (importDesc , sizeof (IMAGE_IMPORT_DESCRIPTOR )) && importDesc -> Name ; importDesc ++ ) {
278- POINTER_TYPE * thunkRef ;
273+ uintptr_t * thunkRef ;
279274 FARPROC * funcRef ;
280275 HCUSTOMMODULE handle = module -> loadLibrary ((LPCSTR ) (codeBase + importDesc -> Name ), module -> userdata );
281276 if (handle == NULL ) {
@@ -295,11 +290,11 @@ BuildImportTable(PMEMORYMODULE module)
295290
296291 module -> modules [module -> numModules ++ ] = handle ;
297292 if (importDesc -> OriginalFirstThunk ) {
298- thunkRef = (POINTER_TYPE * ) (codeBase + importDesc -> OriginalFirstThunk );
293+ thunkRef = (uintptr_t * ) (codeBase + importDesc -> OriginalFirstThunk );
299294 funcRef = (FARPROC * ) (codeBase + importDesc -> FirstThunk );
300295 } else {
301296 // no hint table
302- thunkRef = (POINTER_TYPE * ) (codeBase + importDesc -> FirstThunk );
297+ thunkRef = (uintptr_t * ) (codeBase + importDesc -> FirstThunk );
303298 funcRef = (FARPROC * ) (codeBase + importDesc -> FirstThunk );
304299 }
305300 for (; * thunkRef ; thunkRef ++ , funcRef ++ ) {
@@ -433,7 +428,7 @@ HMEMORYMODULE MemoryLoadLibraryEx(const void *data,
433428 result -> headers = (PIMAGE_NT_HEADERS )& ((const unsigned char * )(headers ))[dos_header -> e_lfanew ];
434429
435430 // update position
436- result -> headers -> OptionalHeader .ImageBase = (POINTER_TYPE )code ;
431+ result -> headers -> OptionalHeader .ImageBase = (uintptr_t )code ;
437432
438433 // copy sections from DLL file block to new memory location
439434 CopySections ((const unsigned char * ) data , old_header , result );
@@ -606,7 +601,7 @@ static PIMAGE_RESOURCE_DIRECTORY_ENTRY _MemorySearchResourceEntry(
606601 // followed by an ordered list of id entries - we can do
607602 // a binary search to find faster...
608603 if (IS_INTRESOURCE (key )) {
609- WORD check = (WORD ) (POINTER_TYPE ) key ;
604+ WORD check = (WORD ) (uintptr_t ) key ;
610605 start = resources -> NumberOfNamedEntries ;
611606 end = start + resources -> NumberOfIdEntries ;
612607
@@ -708,7 +703,7 @@ HMEMORYRSRC MemoryFindResourceEx(HMEMORYMODULE module, LPCTSTR name, LPCTSTR typ
708703 }
709704
710705 nameResources = (PIMAGE_RESOURCE_DIRECTORY ) (codeBase + directory -> VirtualAddress + (foundName -> OffsetToData & 0x7fffffff ));
711- foundLanguage = _MemorySearchResourceEntry (rootResources , nameResources , (LPCTSTR ) (POINTER_TYPE ) language );
706+ foundLanguage = _MemorySearchResourceEntry (rootResources , nameResources , (LPCTSTR ) (uintptr_t ) language );
712707 if (foundLanguage == NULL ) {
713708 // requested language not found, use first available
714709 if (nameResources -> NumberOfIdEntries == 0 ) {
0 commit comments