aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2023-05-21 12:11:20 +0200
committerPali Rohár <pali.rohar@gmail.com>2023-05-21 12:11:20 +0200
commit1beb65cdfc4ba10f8d57091fd1a4acd95d39784c (patch)
tree68de1adad0301961cec3317c33345c956be8e1a6
parent6444294ee354796536c34b54e154c0538a4d1eaf (diff)
downloaddlfcn-win32-1beb65cdfc4ba10f8d57091fd1a4acd95d39784c.tar.gz
dlfcn-win32-1beb65cdfc4ba10f8d57091fd1a4acd95d39784c.tar.bz2
dlfcn-win32-1beb65cdfc4ba10f8d57091fd1a4acd95d39784c.zip
Fix compilation with older SDK
Do not use SIZE_T which is not defined in older SDK. There is only size_t type, so use it instead. Do not use IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR which is not defined in older SDK. Use IMAGE_NUMBEROF_DIRECTORY_ENTRIES macro for checking if directory index is valid. In all SDKs is DataDirectory[] array size defined from IMAGE_NUMBEROF_DIRECTORY_ENTRIES macro. Cast members in IMAGE_EXPORT_DIRECTORY and IMAGE_DIRECTORY_ENTRY_IMPORT to DWORD as in older SDK they are defined as PDWORD and compiler throws error 'cannot add two pointers'.
-rw-r--r--src/dlfcn.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/dlfcn.c b/src/dlfcn.c
index 1402df2..da9a37a 100644
--- a/src/dlfcn.c
+++ b/src/dlfcn.c
@@ -252,7 +252,7 @@ static HMODULE MyGetModuleHandleFromAddress( const void *addr )
252 HMODULE kernel32; 252 HMODULE kernel32;
253 HMODULE hModule; 253 HMODULE hModule;
254 MEMORY_BASIC_INFORMATION info; 254 MEMORY_BASIC_INFORMATION info;
255 SIZE_T sLen; 255 size_t sLen;
256 256
257 if( !failed && GetModuleHandleExAPtr == NULL ) 257 if( !failed && GetModuleHandleExAPtr == NULL )
258 { 258 {
@@ -615,7 +615,7 @@ static BOOL get_image_section( HMODULE module, int index, void **ptr, DWORD *siz
615 if( optionalHeader->Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC ) 615 if( optionalHeader->Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC )
616 return FALSE; 616 return FALSE;
617 617
618 if( index < 0 || index > IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR ) 618 if( index < 0 || index >= IMAGE_NUMBEROF_DIRECTORY_ENTRIES )
619 return FALSE; 619 return FALSE;
620 620
621 if( optionalHeader->DataDirectory[index].Size == 0 || optionalHeader->DataDirectory[index].VirtualAddress == 0 ) 621 if( optionalHeader->DataDirectory[index].Size == 0 || optionalHeader->DataDirectory[index].VirtualAddress == 0 )
@@ -636,9 +636,9 @@ static const char *get_export_symbol_name( HMODULE module, IMAGE_EXPORT_DIRECTOR
636 void *candidateAddr = NULL; 636 void *candidateAddr = NULL;
637 int candidateIndex = -1; 637 int candidateIndex = -1;
638 BYTE *base = (BYTE *) module; 638 BYTE *base = (BYTE *) module;
639 DWORD *functionAddressesOffsets = (DWORD *) (base + ied->AddressOfFunctions); 639 DWORD *functionAddressesOffsets = (DWORD *) (base + (DWORD) ied->AddressOfFunctions);
640 DWORD *functionNamesOffsets = (DWORD *) (base + ied->AddressOfNames); 640 DWORD *functionNamesOffsets = (DWORD *) (base + (DWORD) ied->AddressOfNames);
641 USHORT *functionNameOrdinalsIndexes = (USHORT *) (base + ied->AddressOfNameOrdinals); 641 USHORT *functionNameOrdinalsIndexes = (USHORT *) (base + (DWORD) ied->AddressOfNameOrdinals);
642 642
643 for( i = 0; i < ied->NumberOfFunctions; i++ ) 643 for( i = 0; i < ied->NumberOfFunctions; i++ )
644 { 644 {
@@ -666,7 +666,7 @@ static const char *get_export_symbol_name( HMODULE module, IMAGE_EXPORT_DIRECTOR
666static BOOL is_valid_address( const void *addr ) 666static BOOL is_valid_address( const void *addr )
667{ 667{
668 MEMORY_BASIC_INFORMATION info; 668 MEMORY_BASIC_INFORMATION info;
669 SIZE_T result; 669 size_t result;
670 670
671 if( addr == NULL ) 671 if( addr == NULL )
672 return FALSE; 672 return FALSE;
@@ -852,7 +852,7 @@ int dladdr( const void *addr, Dl_info *info )
852 if( iid == NULL || iid->Characteristics == 0 || iid->FirstThunk == 0 ) 852 if( iid == NULL || iid->Characteristics == 0 || iid->FirstThunk == 0 )
853 return 0; 853 return 0;
854 854
855 iat = (void *)( (BYTE *) hModule + iid->FirstThunk ); 855 iat = (void *)( (BYTE *) hModule + (DWORD) iid->FirstThunk );
856 /* We assume that in this case iid and iat's are in linear order */ 856 /* We assume that in this case iid and iat's are in linear order */
857 iatSize = iidSize - (DWORD) ( (BYTE *) iat - (BYTE *) iid ); 857 iatSize = iidSize - (DWORD) ( (BYTE *) iat - (BYTE *) iid );
858 } 858 }