diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2023-12-29 23:19:48 +0100 |
---|---|---|
committer | Silvio <silvio.traversaro@iit.it> | 2025-04-28 14:49:51 +0200 |
commit | c815879efea297cad9d9fbf76baf972d49dd97fa (patch) | |
tree | 94f3e466898353600e4b9c037cdb8b1c65fb78a0 /src | |
parent | 56ba0f7b07930ec827328a139e8cf5c25d64d428 (diff) | |
download | dlfcn-win32-c815879efea297cad9d9fbf76baf972d49dd97fa.tar.gz dlfcn-win32-c815879efea297cad9d9fbf76baf972d49dd97fa.tar.bz2 dlfcn-win32-c815879efea297cad9d9fbf76baf972d49dd97fa.zip |
Add proper guards for platform code
Do not expect that non-ARM code is automatically X86 code as it does not
have to be. Returns failure (not thunk) in other case.
Make sure that windows test code is not called on non-windows platforms.
Test code tests/test-dladdr.c is written to be validated on any platforms,
including non-windows.
Diffstat (limited to 'src')
-rw-r--r-- | src/dlfcn.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/dlfcn.c b/src/dlfcn.c index 749c35f..522eed0 100644 --- a/src/dlfcn.c +++ b/src/dlfcn.c | |||
@@ -754,8 +754,10 @@ static BOOL is_import_thunk( const void *addr ) | |||
754 | && ( opCode2 & 0xffe003ff ) == 0xf9400210 /* ldr x16, [x16, offset] */ | 754 | && ( opCode2 & 0xffe003ff ) == 0xf9400210 /* ldr x16, [x16, offset] */ |
755 | && opCode3 == 0xd61f0200 /* br x16 */ | 755 | && opCode3 == 0xd61f0200 /* br x16 */ |
756 | ? TRUE : FALSE; | 756 | ? TRUE : FALSE; |
757 | #else | 757 | #elif defined(_M_AMD64) || defined(_M_IX86) || defined(__x86_64__) || defined(__i386__) |
758 | return *(USHORT *) addr == 0x25ff ? TRUE : FALSE; | 758 | return *(USHORT *) addr == 0x25ff ? TRUE : FALSE; |
759 | #else | ||
760 | return FALSE; | ||
759 | #endif | 761 | #endif |
760 | } | 762 | } |
761 | 763 | ||
@@ -785,7 +787,7 @@ static void *get_address_from_import_address_table( void *iat, DWORD iat_size, c | |||
785 | 787 | ||
786 | /* Calculate the final address */ | 788 | /* Calculate the final address */ |
787 | BYTE *ptr = (BYTE *) ( (ULONG64) thkp & ~0xfffull ) + page + offset; | 789 | BYTE *ptr = (BYTE *) ( (ULONG64) thkp & ~0xfffull ) + page + offset; |
788 | #else | 790 | #elif defined(_M_AMD64) || defined(_M_IX86) || defined(__x86_64__) || defined(__i386__) |
789 | /* Get offset from thunk table (after instruction 0xff 0x25) | 791 | /* Get offset from thunk table (after instruction 0xff 0x25) |
790 | * 4018c8 <_VirtualQuery>: ff 25 4a 8a 00 00 | 792 | * 4018c8 <_VirtualQuery>: ff 25 4a 8a 00 00 |
791 | */ | 793 | */ |
@@ -804,6 +806,8 @@ static void *get_address_from_import_address_table( void *iat, DWORD iat_size, c | |||
804 | */ | 806 | */ |
805 | BYTE *ptr = (BYTE *) offset; | 807 | BYTE *ptr = (BYTE *) offset; |
806 | #endif | 808 | #endif |
809 | #else | ||
810 | return NULL; | ||
807 | #endif | 811 | #endif |
808 | 812 | ||
809 | if( !is_valid_address( ptr ) || ptr < (BYTE *) iat || ptr > (BYTE *) iat + iat_size ) | 813 | if( !is_valid_address( ptr ) || ptr < (BYTE *) iat || ptr > (BYTE *) iat + iat_size ) |