@@ -131,6 +131,9 @@ class SysHook : LibraryHook
131
131
// we start with a refcount of 1 because we initialise WSA ourselves for our own sockets.
132
132
m_WSARefCount = 1 ;
133
133
134
+ m_RecurseSlot = Threading::AllocateTLSSlot ();
135
+ Threading::SetTLSValue (m_RecurseSlot, NULL );
136
+
134
137
if (!success)
135
138
return false ;
136
139
@@ -149,7 +152,19 @@ class SysHook : LibraryHook
149
152
bool m_EnabledHooks;
150
153
151
154
int m_WSARefCount;
155
+ uint64_t m_RecurseSlot = 0 ;
156
+
157
+ bool CheckRecurse ()
158
+ {
159
+ if (Threading::GetTLSValue (m_RecurseSlot) == NULL )
160
+ {
161
+ Threading::SetTLSValue (m_RecurseSlot, (void *)1 );
162
+ return false ;
163
+ }
152
164
165
+ return true ;
166
+ }
167
+ void EndRecurse () { Threading::SetTLSValue (m_RecurseSlot, NULL ); }
153
168
Hook<PFN_CREATE_PROCESS_A> CreateProcessA;
154
169
Hook<PFN_CREATE_PROCESS_W> CreateProcessW;
155
170
@@ -203,6 +218,11 @@ class SysHook : LibraryHook
203
218
std::function<BOOL(DWORD dwCreationFlags, LPPROCESS_INFORMATION lpProcessInformation)> realFunc,
204
219
DWORD dwCreationFlags, bool inject, LPPROCESS_INFORMATION lpProcessInformation)
205
220
{
221
+ bool recursive = syshooks.CheckRecurse ();
222
+
223
+ if (recursive)
224
+ return realFunc (dwCreationFlags, lpProcessInformation);
225
+
206
226
PROCESS_INFORMATION dummy;
207
227
RDCEraseEl (dummy);
208
228
@@ -219,7 +239,9 @@ class SysHook : LibraryHook
219
239
bool resume = (dwCreationFlags & CREATE_SUSPENDED) == 0 ;
220
240
dwCreationFlags |= CREATE_SUSPENDED;
221
241
242
+ RDCDEBUG (" Calling real %s" , entryPoint);
222
243
BOOL ret = realFunc (dwCreationFlags, lpProcessInformation);
244
+ RDCDEBUG (" Called real %s" , entryPoint);
223
245
224
246
if (ret && inject)
225
247
{
@@ -247,6 +269,8 @@ class SysHook : LibraryHook
247
269
CloseHandle (dummy.hThread );
248
270
}
249
271
272
+ syshooks.EndRecurse ();
273
+
250
274
return ret;
251
275
}
252
276
0 commit comments