From c815879efea297cad9d9fbf76baf972d49dd97fa Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 29 Dec 2023 23:19:48 +0100 Subject: 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. --- src/dlfcn.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') 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 ) && ( opCode2 & 0xffe003ff ) == 0xf9400210 /* ldr x16, [x16, offset] */ && opCode3 == 0xd61f0200 /* br x16 */ ? TRUE : FALSE; -#else +#elif defined(_M_AMD64) || defined(_M_IX86) || defined(__x86_64__) || defined(__i386__) return *(USHORT *) addr == 0x25ff ? TRUE : FALSE; +#else + return FALSE; #endif } @@ -785,7 +787,7 @@ static void *get_address_from_import_address_table( void *iat, DWORD iat_size, c /* Calculate the final address */ BYTE *ptr = (BYTE *) ( (ULONG64) thkp & ~0xfffull ) + page + offset; -#else +#elif defined(_M_AMD64) || defined(_M_IX86) || defined(__x86_64__) || defined(__i386__) /* Get offset from thunk table (after instruction 0xff 0x25) * 4018c8 <_VirtualQuery>: ff 25 4a 8a 00 00 */ @@ -804,6 +806,8 @@ static void *get_address_from_import_address_table( void *iat, DWORD iat_size, c */ BYTE *ptr = (BYTE *) offset; #endif +#else + return NULL; #endif if( !is_valid_address( ptr ) || ptr < (BYTE *) iat || ptr > (BYTE *) iat + iat_size ) -- cgit v1.2.3-55-g6feb