aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2023-05-24 21:10:25 +0200
committerSilvio <silvio.traversaro@iit.it>2025-04-28 14:49:51 +0200
commit56ba0f7b07930ec827328a139e8cf5c25d64d428 (patch)
treea3d69ec5a68e2e73de912c7e4d3039c4326283ae
parent3b735be29deae48aea3b30d84fda040501600ce9 (diff)
downloaddlfcn-win32-56ba0f7b07930ec827328a139e8cf5c25d64d428.tar.gz
dlfcn-win32-56ba0f7b07930ec827328a139e8cf5c25d64d428.tar.bz2
dlfcn-win32-56ba0f7b07930ec827328a139e8cf5c25d64d428.zip
Style fixes
-rw-r--r--src/dlfcn.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/dlfcn.c b/src/dlfcn.c
index be6e01f..749c35f 100644
--- a/src/dlfcn.c
+++ b/src/dlfcn.c
@@ -710,11 +710,11 @@ static BOOL is_valid_address( const void *addr )
710} 710}
711 711
712#if defined(_M_ARM64) || defined(__aarch64__) 712#if defined(_M_ARM64) || defined(__aarch64__)
713static INT64 sign_extend(UINT64 value, UINT bits) 713static INT64 sign_extend( UINT64 value, UINT bits )
714{ 714{
715 const UINT left = 64 - bits; 715 const UINT left = 64 - bits;
716 const INT64 m1 = -1; 716 const INT64 m1 = -1;
717 const INT64 wide = (INT64) (value << left); 717 const INT64 wide = (INT64) ( value << left );
718 const INT64 sign = ( wide < 0 ) ? ( m1 << left ) : 0; 718 const INT64 sign = ( wide < 0 ) ? ( m1 << left ) : 0;
719 719
720 return value | sign; 720 return value | sign;
@@ -746,16 +746,16 @@ static INT64 sign_extend(UINT64 value, UINT bits)
746static BOOL is_import_thunk( const void *addr ) 746static BOOL is_import_thunk( const void *addr )
747{ 747{
748#if defined(_M_ARM64) || defined(__aarch64__) 748#if defined(_M_ARM64) || defined(__aarch64__)
749 ULONG opCode1 = * (ULONG *) ( (BYTE *) addr ); 749 ULONG opCode1 = *(ULONG *) ( (BYTE *) addr );
750 ULONG opCode2 = * (ULONG *) ( (BYTE *) addr + 4 ); 750 ULONG opCode2 = *(ULONG *) ( (BYTE *) addr + 4 );
751 ULONG opCode3 = * (ULONG *) ( (BYTE *) addr + 8 ); 751 ULONG opCode3 = *(ULONG *) ( (BYTE *) addr + 8 );
752 752
753 return (opCode1 & 0x9f00001f) == 0x90000010 /* adrp x16, [page_offset] */ 753 return ( opCode1 & 0x9f00001f ) == 0x90000010 /* adrp x16, [page_offset] */
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#else
758 return *(short *) addr == 0x25ff ? TRUE : FALSE; 758 return *(USHORT *) addr == 0x25ff ? TRUE : FALSE;
759#endif 759#endif
760} 760}
761 761
@@ -772,16 +772,16 @@ static void *get_address_from_import_address_table( void *iat, DWORD iat_size, c
772 * 0x7ff772ae78c4 <+25764>: ldr x16, [x16, #0xdc0] 772 * 0x7ff772ae78c4 <+25764>: ldr x16, [x16, #0xdc0]
773 * 0x7ff772ae78c8 <+25768>: br x16 773 * 0x7ff772ae78c8 <+25768>: br x16
774 */ 774 */
775 ULONG opCode1 = * (ULONG *) ( (BYTE *) addr ); 775 ULONG opCode1 = *(ULONG *) ( (BYTE *) addr );
776 ULONG opCode2 = * (ULONG *) ( (BYTE *) addr + 4 ); 776 ULONG opCode2 = *(ULONG *) ( (BYTE *) addr + 4 );
777 777
778 /* Extract the offset from adrp instruction */ 778 /* Extract the offset from adrp instruction */
779 UINT64 pageLow2 = (opCode1 >> 29) & 3; 779 UINT64 pageLow2 = ( opCode1 >> 29 ) & 3;
780 UINT64 pageHigh19 = (opCode1 >> 5) & ~(~0ull << 19); 780 UINT64 pageHigh19 = ( opCode1 >> 5 ) & ~( ~0ull << 19 );
781 INT64 page = sign_extend((pageHigh19 << 2) | pageLow2, 21) << 12; 781 INT64 page = sign_extend( ( pageHigh19 << 2 ) | pageLow2, 21 ) << 12;
782 782
783 /* Extract the offset from ldr instruction */ 783 /* Extract the offset from ldr instruction */
784 UINT64 offset = ((opCode2 >> 10) & ~(~0ull << 12)) << 3; 784 UINT64 offset = ( ( opCode2 >> 10 ) & ~( ~0ull << 12 ) ) << 3;
785 785
786 /* Calculate the final address */ 786 /* Calculate the final address */
787 BYTE *ptr = (BYTE *) ( (ULONG64) thkp & ~0xfffull ) + page + offset; 787 BYTE *ptr = (BYTE *) ( (ULONG64) thkp & ~0xfffull ) + page + offset;
@@ -789,7 +789,7 @@ static void *get_address_from_import_address_table( void *iat, DWORD iat_size, c
789 /* Get offset from thunk table (after instruction 0xff 0x25) 789 /* Get offset from thunk table (after instruction 0xff 0x25)
790 * 4018c8 <_VirtualQuery>: ff 25 4a 8a 00 00 790 * 4018c8 <_VirtualQuery>: ff 25 4a 8a 00 00
791 */ 791 */
792 ULONG offset = *(ULONG *)( thkp + 2 ); 792 ULONG offset = *(ULONG *) ( thkp + 2 );
793#if defined(_M_AMD64) || defined(__x86_64__) 793#if defined(_M_AMD64) || defined(__x86_64__)
794 /* On 64 bit the offset is relative 794 /* On 64 bit the offset is relative
795 * 4018c8: ff 25 4a 8a 00 00 jmpq *0x8a4a(%rip) # 40a318 <__imp_VirtualQuery> 795 * 4018c8: ff 25 4a 8a 00 00 jmpq *0x8a4a(%rip) # 40a318 <__imp_VirtualQuery>
@@ -797,7 +797,7 @@ static void *get_address_from_import_address_table( void *iat, DWORD iat_size, c
797 * 100002f20: ff 25 3a e1 ff ff jmpq *-0x1ec6(%rip) # 0x100001060 797 * 100002f20: ff 25 3a e1 ff ff jmpq *-0x1ec6(%rip) # 0x100001060
798 * So cast to signed LONG type 798 * So cast to signed LONG type
799 */ 799 */
800 BYTE *ptr = (BYTE *)( thkp + 6 + (LONG) offset ); 800 BYTE *ptr = (BYTE *) ( thkp + 6 + (LONG) offset );
801#else 801#else
802 /* On 32 bit the offset is absolute 802 /* On 32 bit the offset is absolute
803 * 4019b4: ff 25 90 71 40 00 jmp *0x40719 803 * 4019b4: ff 25 90 71 40 00 jmp *0x40719