@@ -54,11 +54,11 @@ PVOID SC_Address(PVOID NtApiAddress)
54
54
#ifdef _WIN64
55
55
// If the process is 64-bit on a 64-bit OS, we need to search for syscall
56
56
BYTE syscall_code [] = { 0x0f , 0x05 , 0xc3 };
57
- ULONG distance_to_syscall = 0x12 ;
57
+ ULONG distance_to_syscall [ 2 ] = { 0x12 , 0x8 }; //in some ntdll version it is 8 distance
58
58
#else
59
59
// If the process is 32-bit on a 32-bit OS, we need to search for sysenter
60
60
BYTE syscall_code [] = { 0x0f , 0x34 , 0xc3 };
61
- ULONG distance_to_syscall = 0x0f ;
61
+ ULONG distance_to_syscall [ 1 ] = { 0x0f } ;
62
62
#endif
63
63
64
64
#ifdef _M_IX86
@@ -74,46 +74,49 @@ PVOID SC_Address(PVOID NtApiAddress)
74
74
75
75
// we don't really care if there is a 'jmp' between
76
76
// NtApiAddress and the 'syscall; ret' instructions
77
- SyscallAddress = SW3_RVA2VA (PVOID , NtApiAddress , distance_to_syscall );
78
-
79
- if (!memcmp ((PVOID )syscall_code , SyscallAddress , sizeof (syscall_code )))
77
+ for (ULONG32 index = 0 ;index < _countof (distance_to_syscall ); index ++ )
80
78
{
81
- // we can use the original code for this system call :)
82
- #if defined(DEBUG )
83
- printf ("Found Syscall Opcodes at address 0x%p\n" , SyscallAddress );
84
- #endif
85
- return SyscallAddress ;
86
- }
87
-
88
- // the 'syscall; ret' intructions have not been found,
89
- // we will try to use one near it, similarly to HalosGate
79
+ SyscallAddress = SW3_RVA2VA (PVOID , NtApiAddress , distance_to_syscall [index ]);
90
80
91
- for (ULONG32 num_jumps = 1 ; num_jumps < searchLimit ; num_jumps ++ )
92
- {
93
- // let's try with an Nt* API below our syscall
94
- SyscallAddress = SW3_RVA2VA (
95
- PVOID ,
96
- NtApiAddress ,
97
- distance_to_syscall + num_jumps * 0x20 );
98
81
if (!memcmp ((PVOID )syscall_code , SyscallAddress , sizeof (syscall_code )))
99
82
{
100
- #if defined(DEBUG )
101
- printf ("Found Syscall Opcodes at address 0x%p\n" , SyscallAddress );
102
- #endif
83
+ // we can use the original code for this system call :)
84
+ #if defined(DEBUG )
85
+ printf ("Found Syscall Opcodes at address 0x%p\n" , SyscallAddress );
86
+ #endif
103
87
return SyscallAddress ;
104
88
}
105
89
106
- // let's try with an Nt* API above our syscall
107
- SyscallAddress = SW3_RVA2VA (
108
- PVOID ,
109
- NtApiAddress ,
110
- distance_to_syscall - num_jumps * 0x20 );
111
- if (!memcmp ((PVOID )syscall_code , SyscallAddress , sizeof (syscall_code )))
90
+ // the 'syscall; ret' intructions have not been found,
91
+ // we will try to use one near it, similarly to HalosGate
92
+
93
+ for (ULONG32 num_jumps = 1 ; num_jumps < searchLimit ; num_jumps ++ )
112
94
{
113
- #if defined(DEBUG )
114
- printf ("Found Syscall Opcodes at address 0x%p\n" , SyscallAddress );
115
- #endif
116
- return SyscallAddress ;
95
+ // let's try with an Nt* API below our syscall
96
+ SyscallAddress = SW3_RVA2VA (
97
+ PVOID ,
98
+ NtApiAddress ,
99
+ distance_to_syscall [index ] + num_jumps * 0x20 );
100
+ if (!memcmp ((PVOID )syscall_code , SyscallAddress , sizeof (syscall_code )))
101
+ {
102
+ #if defined(DEBUG )
103
+ printf ("Found Syscall Opcodes at address 0x%p\n" , SyscallAddress );
104
+ #endif
105
+ return SyscallAddress ;
106
+ }
107
+
108
+ // let's try with an Nt* API above our syscall
109
+ SyscallAddress = SW3_RVA2VA (
110
+ PVOID ,
111
+ NtApiAddress ,
112
+ distance_to_syscall [index ] - num_jumps * 0x20 );
113
+ if (!memcmp ((PVOID )syscall_code , SyscallAddress , sizeof (syscall_code )))
114
+ {
115
+ #if defined(DEBUG )
116
+ printf ("Found Syscall Opcodes at address 0x%p\n" , SyscallAddress );
117
+ #endif
118
+ return SyscallAddress ;
119
+ }
117
120
}
118
121
}
119
122
0 commit comments