29
29
#pragma warning( disable : 4311 4312 )
30
30
#endif
31
31
32
- #ifdef _WIN64
33
- #define POINTER_TYPE ULONGLONG
34
- #else
35
- #define POINTER_TYPE DWORD
36
- #endif
37
-
38
32
#include <windows.h>
39
33
#include <winnt.h>
34
+ #include <stddef.h>
40
35
#include <tchar.h>
41
36
#ifdef DEBUG_OUTPUT
42
37
#include <stdio.h>
@@ -103,7 +98,7 @@ CopySections(const unsigned char *data, PIMAGE_NT_HEADERS old_headers, PMEMORYMO
103
98
MEM_COMMIT ,
104
99
PAGE_READWRITE );
105
100
106
- section -> Misc .PhysicalAddress = (DWORD ) (POINTER_TYPE ) dest ;
101
+ section -> Misc .PhysicalAddress = (DWORD ) (uintptr_t ) dest ;
107
102
memset (dest , 0 , size );
108
103
}
109
104
@@ -117,7 +112,7 @@ CopySections(const unsigned char *data, PIMAGE_NT_HEADERS old_headers, PMEMORYMO
117
112
MEM_COMMIT ,
118
113
PAGE_READWRITE );
119
114
memcpy (dest , data + section -> PointerToRawData , section -> SizeOfRawData );
120
- section -> Misc .PhysicalAddress = (DWORD ) (POINTER_TYPE ) dest ;
115
+ section -> Misc .PhysicalAddress = (DWORD ) (uintptr_t ) dest ;
121
116
}
122
117
}
123
118
@@ -140,7 +135,7 @@ FinalizeSections(PMEMORYMODULE module)
140
135
int i ;
141
136
PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION (module -> headers );
142
137
#ifdef _WIN64
143
- POINTER_TYPE imageOffset = (module -> headers -> OptionalHeader .ImageBase & 0xffffffff00000000 );
138
+ uintptr_t imageOffset = (module -> headers -> OptionalHeader .ImageBase & 0xffffffff00000000 );
144
139
#else
145
140
#define imageOffset 0
146
141
#endif
@@ -154,7 +149,7 @@ FinalizeSections(PMEMORYMODULE module)
154
149
155
150
if (section -> Characteristics & IMAGE_SCN_MEM_DISCARDABLE ) {
156
151
// 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 );
158
153
continue ;
159
154
}
160
155
@@ -176,7 +171,7 @@ FinalizeSections(PMEMORYMODULE module)
176
171
177
172
if (size > 0 ) {
178
173
// 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 )
180
175
#ifdef DEBUG_OUTPUT
181
176
OutputLastError ("Error protecting memory page" )
182
177
#endif
@@ -275,7 +270,7 @@ BuildImportTable(PMEMORYMODULE module)
275
270
if (directory -> Size > 0 ) {
276
271
PIMAGE_IMPORT_DESCRIPTOR importDesc = (PIMAGE_IMPORT_DESCRIPTOR ) (codeBase + directory -> VirtualAddress );
277
272
for (; !IsBadReadPtr (importDesc , sizeof (IMAGE_IMPORT_DESCRIPTOR )) && importDesc -> Name ; importDesc ++ ) {
278
- POINTER_TYPE * thunkRef ;
273
+ uintptr_t * thunkRef ;
279
274
FARPROC * funcRef ;
280
275
HCUSTOMMODULE handle = module -> loadLibrary ((LPCSTR ) (codeBase + importDesc -> Name ), module -> userdata );
281
276
if (handle == NULL ) {
@@ -295,11 +290,11 @@ BuildImportTable(PMEMORYMODULE module)
295
290
296
291
module -> modules [module -> numModules ++ ] = handle ;
297
292
if (importDesc -> OriginalFirstThunk ) {
298
- thunkRef = (POINTER_TYPE * ) (codeBase + importDesc -> OriginalFirstThunk );
293
+ thunkRef = (uintptr_t * ) (codeBase + importDesc -> OriginalFirstThunk );
299
294
funcRef = (FARPROC * ) (codeBase + importDesc -> FirstThunk );
300
295
} else {
301
296
// no hint table
302
- thunkRef = (POINTER_TYPE * ) (codeBase + importDesc -> FirstThunk );
297
+ thunkRef = (uintptr_t * ) (codeBase + importDesc -> FirstThunk );
303
298
funcRef = (FARPROC * ) (codeBase + importDesc -> FirstThunk );
304
299
}
305
300
for (; * thunkRef ; thunkRef ++ , funcRef ++ ) {
@@ -433,7 +428,7 @@ HMEMORYMODULE MemoryLoadLibraryEx(const void *data,
433
428
result -> headers = (PIMAGE_NT_HEADERS )& ((const unsigned char * )(headers ))[dos_header -> e_lfanew ];
434
429
435
430
// update position
436
- result -> headers -> OptionalHeader .ImageBase = (POINTER_TYPE )code ;
431
+ result -> headers -> OptionalHeader .ImageBase = (uintptr_t )code ;
437
432
438
433
// copy sections from DLL file block to new memory location
439
434
CopySections ((const unsigned char * ) data , old_header , result );
@@ -606,7 +601,7 @@ static PIMAGE_RESOURCE_DIRECTORY_ENTRY _MemorySearchResourceEntry(
606
601
// followed by an ordered list of id entries - we can do
607
602
// a binary search to find faster...
608
603
if (IS_INTRESOURCE (key )) {
609
- WORD check = (WORD ) (POINTER_TYPE ) key ;
604
+ WORD check = (WORD ) (uintptr_t ) key ;
610
605
start = resources -> NumberOfNamedEntries ;
611
606
end = start + resources -> NumberOfIdEntries ;
612
607
@@ -708,7 +703,7 @@ HMEMORYRSRC MemoryFindResourceEx(HMEMORYMODULE module, LPCTSTR name, LPCTSTR typ
708
703
}
709
704
710
705
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 );
712
707
if (foundLanguage == NULL ) {
713
708
// requested language not found, use first available
714
709
if (nameResources -> NumberOfIdEntries == 0 ) {
0 commit comments