ReactOS 0.4.15-dev-8119-g4fb2fdb
hook.c File Reference
#include <win32k.h>
Include dependency graph for hook.c:

Go to the source code of this file.

Classes

struct  _HOOKPACK
 

Typedefs

typedef struct _HOOKPACK HOOKPACK
 
typedef struct _HOOKPACKPHOOKPACK
 

Functions

 DBG_DEFAULT_CHANNEL (UserHook)
 
BOOL IntLoadHookModule (int iHookID, HHOOK hHook, BOOL Unload)
 
BOOL IntHookModuleUnloaded (PDESKTOP pdesk, int iHookID, HHOOK hHook)
 
BOOL FASTCALL UserLoadApiHook (VOID)
 
BOOL FASTCALL UserRegisterUserApiHook (PUNICODE_STRING pstrDllName, PUNICODE_STRING pstrFuncName)
 
BOOL FASTCALL UserUnregisterUserApiHook (VOID)
 
static LRESULT FASTCALL co_IntCallLowLevelHook (PHOOK Hook, INT Code, WPARAM wParam, LPARAM lParam)
 
LRESULT APIENTRY co_CallHook (INT HookId, INT Code, WPARAM wParam, LPARAM lParam)
 
static LRESULT APIENTRY co_HOOK_CallHookNext (PHOOK Hook, INT Code, WPARAM wParam, LPARAM lParam)
 
static LRESULT FASTCALL co_IntCallDebugHook (PHOOK Hook, int Code, WPARAM wParam, LPARAM lParam, BOOL Ansi)
 
static LRESULT APIENTRY co_UserCallNextHookEx (PHOOK Hook, int Code, WPARAM wParam, LPARAM lParam, BOOL Ansi)
 
PHOOK FASTCALL IntGetHookObject (HHOOK hHook)
 
static HHOOK *FASTCALL IntGetGlobalHookHandles (PDESKTOP pdo, int HookId)
 
PHOOK FASTCALL IntGetNextHook (PHOOK Hook)
 
static VOID FASTCALL IntFreeHook (PHOOK Hook)
 
BOOLEAN IntRemoveHook (PVOID Object)
 
LRESULT APIENTRY co_HOOK_CallHooks (INT HookId, INT Code, WPARAM wParam, LPARAM lParam)
 
BOOL FASTCALL IntUnhookWindowsHook (int HookId, HOOKPROC pfnFilterProc)
 
LRESULT APIENTRY NtUserCallNextHookEx (int Code, WPARAM wParam, LPARAM lParam, BOOL Ansi)
 
HHOOK APIENTRY NtUserSetWindowsHookAW (int idHook, HOOKPROC lpfn, BOOL Ansi)
 
HHOOK APIENTRY NtUserSetWindowsHookEx (HINSTANCE Mod, PUNICODE_STRING UnsafeModuleName, DWORD ThreadId, int HookId, HOOKPROC HookProc, BOOL Ansi)
 
BOOL APIENTRY NtUserUnhookWindowsHookEx (HHOOK Hook)
 
BOOL APIENTRY NtUserRegisterUserApiHook (PUNICODE_STRING m_dllname1, PUNICODE_STRING m_funname1, DWORD dwUnknown3, DWORD dwUnknown4)
 
BOOL APIENTRY NtUserUnregisterUserApiHook (VOID)
 

Variables

UNICODE_STRING strUahModule
 
UNICODE_STRING strUahInitFunc
 
PPROCESSINFO ppiUahServer
 

Typedef Documentation

◆ HOOKPACK

◆ PHOOKPACK

Function Documentation

◆ co_CallHook()

LRESULT APIENTRY co_CallHook ( INT  HookId,
INT  Code,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 321 of file hook.c.

325{
326 LRESULT Result = 0;
327 PHOOK phk;
329
330 phk = pHP->pHk;
331 lParam = pHP->lParam;
332
333 switch(HookId)
334 {
336 case WH_JOURNALRECORD:
337 case WH_KEYBOARD_LL:
338 case WH_MOUSE_LL:
339 case WH_MOUSE:
340 lParam = (LPARAM)pHP->pHookStructs;
341 case WH_KEYBOARD:
342 break;
343 }
344
346 {
347 /* The odds are high for this to be a Global call. */
348 Result = co_IntCallHookProc( HookId,
349 Code,
350 wParam,
351 lParam,
352 phk->Proc,
353 phk->ihmod,
354 phk->offPfn,
355 phk->Ansi,
356 &phk->ModuleName);
357 }
358 /* The odds so high, no one is waiting for the results. */
361 return Result;
362}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
struct _HOOKPACK * PHOOKPACK
Definition: hook.c:16
PVOID pHookStructs
Definition: hook.c:19
PHOOK pHk
Definition: hook.c:17
LPARAM lParam
Definition: hook.c:18
INT_PTR ihmod
Definition: ntuser.h:245
HOOKPROC Proc
Definition: ntuser.h:250
ULONG_PTR offPfn
Definition: ntuser.h:243
BOOLEAN Ansi
Definition: ntuser.h:251
UNICODE_STRING ModuleName
Definition: ntuser.h:252
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1701
LRESULT APIENTRY co_IntCallHookProc(INT HookId, INT Code, WPARAM wParam, LPARAM lParam, HOOKPROC Proc, INT Mod, ULONG_PTR offPfn, BOOLEAN Ansi, PUNICODE_STRING ModuleName)
Definition: callback.c:508
BOOL FASTCALL UserObjectInDestroy(HANDLE h)
Definition: object.c:703
#define TAG_HOOK
Definition: tags.h:5
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
#define WH_KEYBOARD
Definition: winuser.h:32
#define WH_JOURNALPLAYBACK
Definition: winuser.h:31
#define WH_MOUSE_LL
Definition: winuser.h:44
#define WH_MOUSE
Definition: winuser.h:37
#define WH_KEYBOARD_LL
Definition: winuser.h:43
#define WH_JOURNALRECORD
Definition: winuser.h:30
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by co_MsqDispatchOneSentMessage().

◆ co_HOOK_CallHookNext()

static LRESULT APIENTRY co_HOOK_CallHookNext ( PHOOK  Hook,
INT  Code,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 367 of file hook.c.

371{
372 TRACE("Calling Next HOOK %d\n", Hook->HookId);
373
374 return co_IntCallHookProc( Hook->HookId,
375 Code,
376 wParam,
377 lParam,
378 Hook->Proc,
379 Hook->ihmod,
380 Hook->offPfn,
381 Hook->Ansi,
382 &Hook->ModuleName);
383}
#define TRACE(s)
Definition: solgame.cpp:4
int HookId
Definition: ntuser.h:242

Referenced by co_IntCallDebugHook(), and co_UserCallNextHookEx().

◆ co_HOOK_CallHooks()

LRESULT APIENTRY co_HOOK_CallHooks ( INT  HookId,
INT  Code,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 1102 of file hook.c.

1106{
1107 PHOOK Hook, SaveHook;
1108 PTHREADINFO pti;
1110 PLIST_ENTRY pLastHead;
1111 PDESKTOP pdo;
1112 BOOL Local = FALSE, Global = FALSE;
1113 LRESULT Result = 0;
1115
1116 ASSERT(WH_MINHOOK <= HookId && HookId <= WH_MAXHOOK);
1117
1119 if (!pti || !pti->rpdesk || !pti->rpdesk->pDeskInfo)
1120 {
1121 pdo = IntGetActiveDesktop();
1122 /* If KeyboardThread|MouseThread|(RawInputThread or RIT) aka system threads,
1123 pti->fsHooks most likely, is zero. So process KbT & MsT to "send" the message.
1124 */
1125 if ( !pti || !pdo || (!(HookId == WH_KEYBOARD_LL) && !(HookId == WH_MOUSE_LL)) )
1126 {
1127 TRACE("No PDO %d\n", HookId);
1128 goto Exit;
1129 }
1130 }
1131 else
1132 {
1133 pdo = pti->rpdesk;
1134 }
1135
1137 {
1138 TRACE("Hook Thread dead %d\n", HookId);
1139 goto Exit;
1140 }
1141
1142 if ( ISITHOOKED(HookId) )
1143 {
1144 TRACE("Local Hooker %d\n", HookId);
1145 Local = TRUE;
1146 }
1147
1148 if ( pdo->pDeskInfo->fsHooks & HOOKID_TO_FLAG(HookId) )
1149 {
1150 TRACE("Global Hooker %d\n", HookId);
1151 Global = TRUE;
1152 }
1153
1154 if ( !Local && !Global ) goto Exit; // No work!
1155
1156 Hook = NULL;
1157
1158 /* SetWindowHookEx sorts out the Thread issue by placing the Hook to
1159 the correct Thread if not NULL.
1160 */
1161 if ( Local )
1162 {
1163 pLastHead = &pti->aphkStart[HOOKID_TO_INDEX(HookId)];
1164 if (IsListEmpty(pLastHead))
1165 {
1166 ERR("No Local Hook Found!\n");
1167 goto Exit;
1168 }
1169
1170 Hook = CONTAINING_RECORD(pLastHead->Flink, HOOK, Chain);
1171 ObReferenceObject(pti->pEThread);
1173 UserRefObjectCo(Hook, &Ref);
1174
1175 ClientInfo = pti->pClientInfo;
1176 SaveHook = pti->sphkCurrent;
1177 /* Note: Setting pti->sphkCurrent will also lock the next hook to this
1178 * hook ID. So, the CallNextHookEx will only call to that hook ID
1179 * chain anyway. For Thread Hooks....
1180 */
1181
1182 /* Load it for the next call. */
1183 pti->sphkCurrent = Hook;
1184 Hook->phkNext = IntGetNextHook(Hook);
1185 if (ClientInfo)
1186 {
1187 _SEH2_TRY
1188 {
1189 ClientInfo->phkCurrent = Hook;
1190 }
1192 {
1193 ClientInfo = NULL; // Don't bother next run.
1194 }
1195 _SEH2_END;
1196 }
1197 Result = co_IntCallHookProc( HookId,
1198 Code,
1199 wParam,
1200 lParam,
1201 Hook->Proc,
1202 Hook->ihmod,
1203 Hook->offPfn,
1204 Hook->Ansi,
1205 &Hook->ModuleName);
1206 if (ClientInfo)
1207 {
1208 _SEH2_TRY
1209 {
1210 ClientInfo->phkCurrent = SaveHook;
1211 }
1213 {
1214 /* Do nothing */
1215 (void)0;
1216 }
1217 _SEH2_END;
1218 }
1219 pti->sphkCurrent = SaveHook;
1220 Hook->phkNext = NULL;
1221 UserDerefObjectCo(Hook);
1223 ObDereferenceObject(pti->pEThread);
1224 }
1225
1226 if ( Global )
1227 {
1228 PTHREADINFO ptiHook;
1229 HHOOK *pHookHandles;
1230 unsigned i;
1231
1232 /* Keep hooks in array because hooks can be destroyed in user world */
1233 pHookHandles = IntGetGlobalHookHandles(pdo, HookId);
1234 if(!pHookHandles)
1235 goto Exit;
1236
1237 /* Performance goes down the drain. If more hooks are associated to this
1238 * hook ID, this will have to post to each of the thread message queues
1239 * or make a direct call.
1240 */
1241 for(i = 0; pHookHandles[i]; ++i)
1242 {
1243 Hook = (PHOOK)UserGetObject(gHandleTable, pHookHandles[i], TYPE_HOOK);
1244 if(!Hook)
1245 {
1246 ERR("Invalid hook!\n");
1247 continue;
1248 }
1249
1250 /* Hook->Thread is null, we hax around this with Hook->head.pti. */
1251 ptiHook = Hook->head.pti;
1252
1253 if ( (pti->TIF_flags & TIF_DISABLEHOOKS) || (ptiHook->TIF_flags & TIF_INCLEANUP))
1254 {
1255 TRACE("Next Hook %p, %p\n", ptiHook->rpdesk, pdo);
1256 continue;
1257 }
1258 UserRefObjectCo(Hook, &Ref);
1259
1260 if (ptiHook != pti )
1261 {
1262 // Block | TimeOut
1263 if ( HookId == WH_JOURNALPLAYBACK || // 1 | 0
1264 HookId == WH_JOURNALRECORD || // 1 | 0
1265 HookId == WH_KEYBOARD || // 1 | 200
1266 HookId == WH_MOUSE || // 1 | 200
1267 HookId == WH_KEYBOARD_LL || // 0 | 300
1268 HookId == WH_MOUSE_LL ) // 0 | 300
1269 {
1270 TRACE("\nGlobal Hook posting to another Thread! %d\n",HookId );
1272 }
1273 else if (ptiHook->ppi == pti->ppi)
1274 {
1275 TRACE("\nGlobal Hook calling to another Thread! %d\n",HookId );
1276 ObReferenceObject(ptiHook->pEThread);
1277 IntReferenceThreadInfo(ptiHook);
1278 Result = co_IntCallHookProc( HookId,
1279 Code,
1280 wParam,
1281 lParam,
1282 Hook->Proc,
1283 Hook->ihmod,
1284 Hook->offPfn,
1285 Hook->Ansi,
1286 &Hook->ModuleName);
1287 IntDereferenceThreadInfo(ptiHook);
1288 ObDereferenceObject(ptiHook->pEThread);
1289 }
1290 }
1291 else
1292 { /* Make the direct call. */
1293 TRACE("Global going Local Hook calling to Thread! %d\n",HookId );
1294 ObReferenceObject(pti->pEThread);
1296 Result = co_IntCallHookProc( HookId,
1297 Code,
1298 wParam,
1299 lParam,
1300 Hook->Proc,
1301 Hook->ihmod,
1302 Hook->offPfn,
1303 Hook->Ansi,
1304 &Hook->ModuleName);
1306 ObDereferenceObject(pti->pEThread);
1307 }
1308 UserDerefObjectCo(Hook);
1309 }
1310 ExFreePoolWithTag(pHookHandles, TAG_HOOK);
1311 TRACE("Ret: Global HookId %d Result 0x%x\n", HookId,Result);
1312 }
1313Exit:
1314 return Result;
1315}
#define ERR(fmt,...)
Definition: debug.h:113
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define HOOKID_TO_INDEX(HookId)
Definition: hook.h:4
#define ISITHOOKED(HookId)
Definition: hook.h:6
#define HOOKID_TO_FLAG(HookId)
Definition: hook.h:5
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define TIF_INCLEANUP
Definition: ntuser.h:263
struct tagHOOK * PHOOK
@ TYPE_HOOK
Definition: ntuser.h:45
#define TIF_DISABLEHOOKS
Definition: ntuser.h:291
CLIENT_DATA ClientInfo
UNICODE_STRING Global
Definition: symlink.c:37
#define ASSERT(a)
Definition: mode.c:44
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
static HHOOK *FASTCALL IntGetGlobalHookHandles(PDESKTOP pdo, int HookId)
Definition: hook.c:962
static LRESULT FASTCALL co_IntCallLowLevelHook(PHOOK Hook, INT Code, WPARAM wParam, LPARAM lParam)
Definition: hook.c:239
PHOOK FASTCALL IntGetNextHook(PHOOK Hook)
Definition: hook.c:995
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:40
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
static void Exit(void)
Definition: sock.c:1330
DWORD fsHooks
Definition: ntuser.h:138
PDESKTOPINFO pDeskInfo
Definition: desktop.h:8
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PPROCESSINFO ppi
Definition: win32.h:88
struct tagHOOK * sphkCurrent
Definition: win32.h:118
struct _CLIENTINFO * pClientInfo
Definition: win32.h:94
LIST_ENTRY aphkStart[NB_HOOKS]
FIXME!
Definition: win32.h:143
FLONG TIF_flags
Definition: win32.h:95
struct _DESKTOP * rpdesk
Definition: win32.h:92
Definition: object.h:4
struct tagHOOK * phkNext
Definition: ntuser.h:241
THRDESKHEAD head
Definition: ntuser.h:240
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define IntDereferenceThreadInfo(pti)
Definition: win32.h:171
#define IntReferenceThreadInfo(pti)
Definition: win32.h:166
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1262
PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, HANDLE_TYPE type)
Definition: object.c:495
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13
#define WH_MINHOOK
Definition: winuser.h:46
#define WH_MAXHOOK
Definition: winuser.h:47
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by co_CallLowLevelKeyboardHook(), co_IntGetPeekMessage(), co_IntProcessKeyboardMessage(), co_IntProcessMouseMessage(), co_IntSetActiveWindow(), co_IntShellHookNotify(), co_MsqInsertMouseMessage(), co_UserCreateWindowEx(), co_UserDestroyWindow(), co_UserSetFocus(), co_WinPosMinMaximize(), DefWndDoSizeMove(), DefWndHandleSysCommand(), IdlePing(), IntCallMsgFilter(), IntCallWndProc(), IntCallWndProcRet(), IntDefWindowProc(), NtUserCallMsgFilter(), NtUserDragDetect(), and NtUserNotifyIMEStatus().

◆ co_IntCallDebugHook()

static LRESULT FASTCALL co_IntCallDebugHook ( PHOOK  Hook,
int  Code,
WPARAM  wParam,
LPARAM  lParam,
BOOL  Ansi 
)
static

Definition at line 388 of file hook.c.

393{
394 LRESULT lResult = 0;
395 ULONG Size;
396 DEBUGHOOKINFO Debug;
397 PVOID HooklParam = NULL;
398 BOOL BadChk = FALSE;
399
400 if (lParam)
401 {
403 {
405 sizeof(DEBUGHOOKINFO),
406 1);
407
408 RtlCopyMemory(&Debug,
409 (PVOID)lParam,
410 sizeof(DEBUGHOOKINFO));
411 }
413 {
414 BadChk = TRUE;
415 }
416 _SEH2_END;
417
418 if (BadChk)
419 {
420 ERR("HOOK WH_DEBUG read from lParam ERROR!\n");
421 return lResult;
422 }
423 }
424 else
425 return lResult; /* Need lParam! */
426
427 switch (wParam)
428 {
429 case WH_CBT:
430 {
431 switch (Debug.code)
432 {
434 Size = sizeof(MOUSEHOOKSTRUCTEX);
435 break;
436
437 case HCBT_MOVESIZE:
438 Size = sizeof(RECT);
439 break;
440
441 case HCBT_ACTIVATE:
442 Size = sizeof(CBTACTIVATESTRUCT);
443 break;
444
445 case HCBT_CREATEWND: /* Handle ANSI? */
446 Size = sizeof(CBT_CREATEWND);
447 /* What shall we do? Size += sizeof(HOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS); same as CREATESTRUCTEX */
448 break;
449
450 default:
451 Size = sizeof(LPARAM);
452 }
453 }
454 break;
455
456 case WH_MOUSE_LL:
457 Size = sizeof(MSLLHOOKSTRUCT);
458 break;
459
460 case WH_KEYBOARD_LL:
461 Size = sizeof(KBDLLHOOKSTRUCT);
462 break;
463
464 case WH_MSGFILTER:
465 case WH_SYSMSGFILTER:
466 case WH_GETMESSAGE:
467 Size = sizeof(MSG);
468 break;
469
471 case WH_JOURNALRECORD:
472 Size = sizeof(EVENTMSG);
473 break;
474
476 case WH_KEYBOARD:
477 case WH_SHELL:
478 default:
479 Size = sizeof(LPARAM);
480 }
481
482 if (Size > sizeof(LPARAM))
484
485 if (HooklParam)
486 {
488 {
490 Size,
491 1);
492
493 RtlCopyMemory(HooklParam,
494 (PVOID)Debug.lParam,
495 Size);
496 }
498 {
499 BadChk = TRUE;
500 }
501 _SEH2_END;
502
503 if (BadChk)
504 {
505 ERR("HOOK WH_DEBUG read from Debug.lParam ERROR!\n");
506 ExFreePoolWithTag(HooklParam, TAG_HOOK);
507 return lResult;
508 }
509 }
510
511 if (HooklParam) Debug.lParam = (LPARAM)HooklParam;
512 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, (LPARAM)&Debug);
513 if (HooklParam) ExFreePoolWithTag(HooklParam, TAG_HOOK);
514
515 return lResult;
516}
#define MSG
Definition: Mailslot.c:11
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
static LRESULT APIENTRY co_HOOK_CallHookNext(PHOOK Hook, INT Code, WPARAM wParam, LPARAM lParam)
Definition: hook.c:367
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define RECT
Definition: precomp.h:26
struct tagEVENTMSG EVENTMSG
#define HCBT_ACTIVATE
Definition: winuser.h:60
#define WH_MSGFILTER
Definition: winuser.h:29
struct tagCBTACTIVATESTRUCT CBTACTIVATESTRUCT
#define WH_SHELL
Definition: winuser.h:40
CBT_CREATEWNDA CBT_CREATEWND
Definition: winuser.h:5727
#define WH_CBT
Definition: winuser.h:35
#define HCBT_CREATEWND
Definition: winuser.h:58
#define HCBT_CLICKSKIPPED
Definition: winuser.h:61
#define HCBT_MOVESIZE
Definition: winuser.h:55
#define WH_GETMESSAGE
Definition: winuser.h:33
#define WH_SYSMSGFILTER
Definition: winuser.h:36
struct tagMSLLHOOKSTRUCT MSLLHOOKSTRUCT
struct tagKBDLLHOOKSTRUCT KBDLLHOOKSTRUCT
#define WH_FOREGROUNDIDLE
Definition: winuser.h:41

Referenced by co_UserCallNextHookEx().

◆ co_IntCallLowLevelHook()

static LRESULT FASTCALL co_IntCallLowLevelHook ( PHOOK  Hook,
INT  Code,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 239 of file hook.c.

243{
245 PTHREADINFO pti;
246 PHOOKPACK pHP;
247 INT Size = 0;
248 UINT uTimeout = 300;
249 BOOL Block = FALSE;
250 ULONG_PTR uResult = 0;
251
252 if (Hook->ptiHooked)
253 pti = Hook->ptiHooked;
254 else
255 pti = Hook->head.pti;
256
258 if (!pHP) return 0;
259
260 pHP->pHk = Hook;
261 pHP->lParam = lParam;
262 pHP->pHookStructs = NULL;
263
264// This prevents stack corruption from the caller.
265 switch(Hook->HookId)
266 {
268 case WH_JOURNALRECORD:
269 uTimeout = 0;
270 Size = sizeof(EVENTMSG);
271 break;
272 case WH_KEYBOARD_LL:
273 Size = sizeof(KBDLLHOOKSTRUCT);
274 break;
275 case WH_MOUSE_LL:
276 Size = sizeof(MSLLHOOKSTRUCT);
277 break;
278 case WH_MOUSE:
279 uTimeout = 200;
280 Block = TRUE;
281 Size = sizeof(MOUSEHOOKSTRUCT);
282 break;
283 case WH_KEYBOARD:
284 uTimeout = 200;
285 Block = TRUE;
286 break;
287 }
288
289 if (Size)
290 {
293 }
294
295 /* FIXME: Should get timeout from
296 * HKEY_CURRENT_USER\Control Panel\Desktop\LowLevelHooksTimeout */
298 IntToPtr(Code), // hWnd
299 Hook->HookId, // Msg
300 wParam,
301 (LPARAM)pHP,
302 uTimeout,
303 Block,
305 &uResult);
306 if (!NT_SUCCESS(Status))
307 {
308 ERR("Error Hook Call SendMsg. %d Status: 0x%x\n", Hook->HookId, Status);
311 }
312 return NT_SUCCESS(Status) ? uResult : 0;
313}
LONG NTSTATUS
Definition: precomp.h:26
#define IntToPtr(i)
Definition: basetsd.h:89
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
NTSTATUS FASTCALL co_MsqSendMessage(PTHREADINFO ptirec, HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam, UINT uTimeout, BOOL Block, INT HookMessage, ULONG_PTR *uResult)
Definition: msgqueue.c:1056
#define MSQ_ISHOOK
Definition: msgqueue.h:5
unsigned int UINT
Definition: ndis.h:50
struct _THREADINFO * ptiHooked
Definition: ntuser.h:246
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct tagMOUSEHOOKSTRUCT MOUSEHOOKSTRUCT

Referenced by co_HOOK_CallHooks().

◆ co_UserCallNextHookEx()

static LRESULT APIENTRY co_UserCallNextHookEx ( PHOOK  Hook,
int  Code,
WPARAM  wParam,
LPARAM  lParam,
BOOL  Ansi 
)
static

Definition at line 521 of file hook.c.

526{
527 LRESULT lResult = 0;
528 BOOL BadChk = FALSE;
529
530 /* Handle this one first. */
531 if ((Hook->HookId == WH_MOUSE) ||
532 (Hook->HookId == WH_CBT && Code == HCBT_CLICKSKIPPED))
533 {
534 MOUSEHOOKSTRUCTEX Mouse;
535 if (lParam)
536 {
538 {
540 sizeof(MOUSEHOOKSTRUCTEX),
541 1);
542
544 (PVOID)lParam,
545 sizeof(MOUSEHOOKSTRUCTEX));
546 }
548 {
549 BadChk = TRUE;
550 }
551 _SEH2_END;
552
553 if (BadChk)
554 {
555 ERR("HOOK WH_MOUSE read from lParam ERROR!\n");
556 }
557 }
558
559 if (!BadChk)
560 {
561 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, (LPARAM)&Mouse);
562 }
563
564 return lResult;
565 }
566
567 switch(Hook->HookId)
568 {
569 case WH_MOUSE_LL:
570 {
572
573 if (lParam)
574 {
576 {
578 sizeof(MSLLHOOKSTRUCT),
579 1);
580
582 (PVOID)lParam,
583 sizeof(MSLLHOOKSTRUCT));
584 }
586 {
587 BadChk = TRUE;
588 }
589 _SEH2_END;
590
591 if (BadChk)
592 {
593 ERR("HOOK WH_MOUSE_LL read from lParam ERROR!\n");
594 }
595 }
596
597 if (!BadChk)
598 {
599 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, (LPARAM)&Mouse);
600 }
601 break;
602 }
603
604 case WH_KEYBOARD_LL:
605 {
607
608 if (lParam)
609 {
611 {
613 sizeof(KBDLLHOOKSTRUCT),
614 1);
615
617 (PVOID)lParam,
618 sizeof(KBDLLHOOKSTRUCT));
619 }
621 {
622 BadChk = TRUE;
623 }
624 _SEH2_END;
625
626 if (BadChk)
627 {
628 ERR("HOOK WH_KEYBORD_LL read from lParam ERROR!\n");
629 }
630 }
631
632 if (!BadChk)
633 {
634 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, (LPARAM)&Keyboard);
635 }
636 break;
637 }
638
639 case WH_MSGFILTER:
640 case WH_SYSMSGFILTER:
641 case WH_GETMESSAGE:
642 {
643 MSG Msg;
644
645 if (lParam)
646 {
648 {
650 sizeof(MSG),
651 1);
652
654 (PVOID)lParam,
655 sizeof(MSG));
656 }
658 {
659 BadChk = TRUE;
660 }
661 _SEH2_END;
662
663 if (BadChk)
664 {
665 ERR("HOOK WH_XMESSAGEX read from lParam ERROR!\n");
666 }
667 }
668
669 if (!BadChk)
670 {
671 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, (LPARAM)&Msg);
672
673 if (lParam && (Hook->HookId == WH_GETMESSAGE))
674 {
676 {
678 sizeof(MSG),
679 1);
680
682 &Msg,
683 sizeof(MSG));
684 }
686 {
687 BadChk = TRUE;
688 }
689 _SEH2_END;
690
691 if (BadChk)
692 {
693 ERR("HOOK WH_GETMESSAGE write to lParam ERROR!\n");
694 }
695 }
696 }
697 break;
698 }
699
700 case WH_CBT:
701 TRACE("HOOK WH_CBT!\n");
702 switch (Code)
703 {
704 case HCBT_CREATEWND:
705 {
707
708 TRACE("HOOK HCBT_CREATEWND\n");
710 {
711 if (Ansi)
712 {
713 ProbeForRead( pcbtcww,
714 sizeof(CBT_CREATEWNDA),
715 1);
716 ProbeForWrite(pcbtcww->lpcs,
717 sizeof(CREATESTRUCTA),
718 1);
719 ProbeForRead( pcbtcww->lpcs->lpszName,
720 sizeof(CHAR),
721 1);
722
723 if (!IS_ATOM(pcbtcww->lpcs->lpszClass))
724 {
725 _Analysis_assume_(pcbtcww->lpcs->lpszClass != NULL);
726 ProbeForRead(pcbtcww->lpcs->lpszClass,
727 sizeof(CHAR),
728 1);
729 }
730 }
731 else
732 {
733 ProbeForRead( pcbtcww,
734 sizeof(CBT_CREATEWNDW),
735 1);
736 ProbeForWrite(pcbtcww->lpcs,
737 sizeof(CREATESTRUCTW),
738 1);
739 ProbeForRead( pcbtcww->lpcs->lpszName,
740 sizeof(WCHAR),
741 1);
742
743 if (!IS_ATOM(pcbtcww->lpcs->lpszClass))
744 {
745 _Analysis_assume_(pcbtcww->lpcs->lpszClass != NULL);
746 ProbeForRead(pcbtcww->lpcs->lpszClass,
747 sizeof(WCHAR),
748 1);
749 }
750 }
751 }
753 {
754 BadChk = TRUE;
755 }
756 _SEH2_END;
757
758 if (BadChk)
759 {
760 ERR("HOOK HCBT_CREATEWND write ERROR!\n");
761 }
762 /* The next call handles the structures. */
763 if (!BadChk && Hook->Proc)
764 {
765 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, lParam);
766 }
767 break;
768 }
769
770 case HCBT_MOVESIZE:
771 {
772 RECTL rt;
773
774 TRACE("HOOK HCBT_MOVESIZE\n");
775
776 if (lParam)
777 {
779 {
781 sizeof(RECT),
782 1);
783
784 RtlCopyMemory(&rt,
785 (PVOID)lParam,
786 sizeof(RECT));
787 }
789 {
790 BadChk = TRUE;
791 }
792 _SEH2_END;
793
794 if (BadChk)
795 {
796 ERR("HOOK HCBT_MOVESIZE read from lParam ERROR!\n");
797 }
798 }
799
800 if (!BadChk)
801 {
802 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, (LPARAM)&rt);
803 }
804 break;
805 }
806
807 case HCBT_ACTIVATE:
808 {
810
811 TRACE("HOOK HCBT_ACTIVATE\n");
812 if (lParam)
813 {
815 {
817 sizeof(CBTACTIVATESTRUCT),
818 1);
819
820 RtlCopyMemory(&CbAs,
821 (PVOID)lParam,
822 sizeof(CBTACTIVATESTRUCT));
823 }
825 {
826 BadChk = TRUE;
827 }
828 _SEH2_END;
829
830 if (BadChk)
831 {
832 ERR("HOOK HCBT_ACTIVATE read from lParam ERROR!\n");
833 }
834 }
835
836 if (!BadChk)
837 {
838 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, (LPARAM)&CbAs);
839 }
840 break;
841 }
842
843 /* The rest just use default. */
844 default:
845 TRACE("HOOK HCBT_ %d\n",Code);
846 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, lParam);
847 break;
848 }
849 break;
850/*
851 Note WH_JOURNALPLAYBACK,
852 "To have the system wait before processing the message, the return value
853 must be the amount of time, in clock ticks, that the system should wait."
854 */
856 case WH_JOURNALRECORD:
857 {
858 EVENTMSG EventMsg;
859
860 if (lParam)
861 {
863 {
865 sizeof(EVENTMSG),
866 1);
867
868 RtlCopyMemory(&EventMsg,
869 (PVOID)lParam,
870 sizeof(EVENTMSG));
871 }
873 {
874 BadChk = TRUE;
875 }
876 _SEH2_END;
877
878 if (BadChk)
879 {
880 ERR("HOOK WH_JOURNAL read from lParam ERROR!\n");
881 }
882 }
883
884 if (!BadChk)
885 {
886 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, (LPARAM)(lParam ? &EventMsg : NULL));
887
888 if (lParam)
889 {
891 {
893 sizeof(EVENTMSG),
894 1);
895
897 &EventMsg,
898 sizeof(EVENTMSG));
899 }
901 {
902 BadChk = TRUE;
903 }
904 _SEH2_END;
905
906 if (BadChk)
907 {
908 ERR("HOOK WH_JOURNAL write to lParam ERROR!\n");
909 }
910 }
911 }
912 break;
913 }
914
915 case WH_DEBUG:
916 lResult = co_IntCallDebugHook(Hook, Code, wParam, lParam, Ansi);
917 break;
918
919 /*
920 * Default the rest like, WH_FOREGROUNDIDLE, WH_KEYBOARD and WH_SHELL.
921 */
923 case WH_KEYBOARD:
924 case WH_SHELL:
925 lResult = co_HOOK_CallHookNext(Hook, Code, wParam, lParam);
926 break;
927
928 default:
929 ERR("Unsupported HOOK Id -> %d\n",Hook->HookId);
930 break;
931 }
932 return lResult;
933}
#define IS_ATOM(x)
Definition: class.h:3
struct @1637 Msg[]
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
@ Keyboard
Definition: i8042prt.h:115
@ Mouse
Definition: i8042prt.h:116
#define _Analysis_assume_(expr)
Definition: ms_sal.h:2901
static LRESULT FASTCALL co_IntCallDebugHook(PHOOK Hook, int Code, WPARAM wParam, LPARAM lParam, BOOL Ansi)
Definition: hook.c:388
LPCREATESTRUCTW lpcs
Definition: winuser.h:2975
LPCWSTR lpszClass
Definition: winuser.h:2965
LPCWSTR lpszName
Definition: winuser.h:2964
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define WH_DEBUG
Definition: winuser.h:39
struct tagCBT_CREATEWNDW * LPCBT_CREATEWNDW
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

Referenced by NtUserCallNextHookEx().

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserHook  )

◆ IntFreeHook()

static VOID FASTCALL IntFreeHook ( PHOOK  Hook)
static

Definition at line 1022 of file hook.c.

1023{
1024 RemoveEntryList(&Hook->Chain);
1025 if (Hook->ModuleName.Buffer)
1026 {
1028 Hook->ModuleName.Buffer = NULL;
1029 }
1030 /* Close handle */
1032}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
LIST_ENTRY Chain
Definition: ntuser.h:249
BOOL FASTCALL UserDeleteObject(HANDLE h, HANDLE_TYPE type)
Definition: object.c:717

Referenced by IntRemoveHook().

◆ IntGetGlobalHookHandles()

static HHOOK *FASTCALL IntGetGlobalHookHandles ( PDESKTOP  pdo,
int  HookId 
)
static

Definition at line 962 of file hook.c.

963{
964 PLIST_ENTRY pLastHead, pElem;
965 unsigned i = 0;
966 unsigned cHooks = 0;
967 HHOOK *pList;
968 PHOOK pHook;
969
970 pLastHead = &pdo->pDeskInfo->aphkStart[HOOKID_TO_INDEX(HookId)];
971 for (pElem = pLastHead->Flink; pElem != pLastHead; pElem = pElem->Flink)
972 ++cHooks;
973
974 pList = ExAllocatePoolWithTag(PagedPool, (cHooks + 1) * sizeof(HHOOK), TAG_HOOK);
975 if (!pList)
976 {
978 return NULL;
979 }
980
981 for (pElem = pLastHead->Flink; pElem != pLastHead; pElem = pElem->Flink)
982 {
983 pHook = CONTAINING_RECORD(pElem, HOOK, Chain);
984 NT_ASSERT(i < cHooks);
985 pList[i++] = UserHMGetHandle(pHook);
986 }
987 pList[i] = NULL;
988
989 return pList;
990}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define PagedPool
Definition: env_spec_w32.h:308
FxChildList * pList
LIST_ENTRY aphkStart[NB_HOOKS]
Definition: ntuser.h:139
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:22
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by co_HOOK_CallHooks().

◆ IntGetHookObject()

PHOOK FASTCALL IntGetHookObject ( HHOOK  hHook)

Definition at line 937 of file hook.c.

938{
939 PHOOK Hook;
940
941 if (!hHook)
942 {
944 return NULL;
945 }
946
947 Hook = (PHOOK)UserGetObject(gHandleTable, hHook, TYPE_HOOK);
948 if (!Hook)
949 {
951 return NULL;
952 }
953
955
956 return Hook;
957}
VOID FASTCALL UserReferenceObject(PVOID obj)
Definition: object.c:731
#define ERROR_INVALID_HOOK_HANDLE
Definition: winerror.h:885

Referenced by NtUserUnhookWindowsHookEx().

◆ IntGetNextHook()

PHOOK FASTCALL IntGetNextHook ( PHOOK  Hook)

Definition at line 995 of file hook.c.

996{
997 int HookId = Hook->HookId;
998 PLIST_ENTRY pLastHead, pElem;
999 PTHREADINFO pti;
1000
1001 if (Hook->ptiHooked)
1002 {
1003 pti = Hook->ptiHooked;
1004 pLastHead = &pti->aphkStart[HOOKID_TO_INDEX(HookId)];
1005 }
1006 else
1007 {
1009 pLastHead = &pti->rpdesk->pDeskInfo->aphkStart[HOOKID_TO_INDEX(HookId)];
1010 }
1011
1012 pElem = Hook->Chain.Flink;
1013 if (pElem != pLastHead)
1014 return CONTAINING_RECORD(pElem, HOOK, Chain);
1015 return NULL;
1016}

Referenced by co_HOOK_CallHooks(), NtUserCallNextHookEx(), and NtUserMessageCall().

◆ IntHookModuleUnloaded()

BOOL IntHookModuleUnloaded ( PDESKTOP  pdesk,
int  iHookID,
HHOOK  hHook 
)

Definition at line 88 of file hook.c.

89{
90 PTHREADINFO ptiCurrent;
91 PLIST_ENTRY ListEntry;
92 PPROCESSINFO ppiCsr;
93
94 TRACE("IntHookModuleUnloaded: iHookID=%d\n", iHookID);
95
97
98 ListEntry = pdesk->PtiList.Flink;
99 while(ListEntry != &pdesk->PtiList)
100 {
101 ptiCurrent = CONTAINING_RECORD(ListEntry, THREADINFO, PtiLink);
102
103 /* FIXME: Do some more security checks here */
104
105 /* FIXME: HACK: The first check is a reactos specific hack for system threads */
106 if(!PsIsSystemProcess(ptiCurrent->ppi->peProcess) &&
107 ptiCurrent->ppi != ppiCsr)
108 {
109 if(ptiCurrent->ppi->W32PF_flags & W32PF_APIHOOKLOADED)
110 {
111 TRACE("IntHookModuleUnloaded: sending message to PID %p, ppi=%p\n", PsGetProcessId(ptiCurrent->ppi->peProcess), ptiCurrent->ppi);
112 co_MsqSendMessageAsync( ptiCurrent,
113 0,
114 iHookID,
115 TRUE,
116 (LPARAM)hHook,
117 NULL,
118 0,
119 FALSE,
121 }
122 }
123 ListEntry = ListEntry->Flink;
124 }
125
126 return TRUE;
127}
PEPROCESS gpepCSRSS
Definition: csr.c:15
BOOL FASTCALL co_MsqSendMessageAsync(PTHREADINFO ptiReceiver, HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, SENDASYNCPROC CompletionCallback, ULONG_PTR CompletionCallbackContext, BOOL HasPackedLParam, INT HookMessage)
Definition: msgqueue.c:1014
#define MSQ_INJECTMODULE
Definition: msgqueue.h:6
BOOLEAN NTAPI PsIsSystemProcess(IN PEPROCESS Process)
Definition: process.c:1223
PVOID NTAPI PsGetProcessWin32Process(PEPROCESS Process)
Definition: process.c:1193
HANDLE NTAPI PsGetProcessId(PEPROCESS Process)
Definition: process.c:1063
LIST_ENTRY PtiList
Definition: desktop.h:25
#define W32PF_APIHOOKLOADED
Definition: win32.h:35

Referenced by UserUnregisterUserApiHook().

◆ IntLoadHookModule()

BOOL IntLoadHookModule ( int  iHookID,
HHOOK  hHook,
BOOL  Unload 
)

Definition at line 30 of file hook.c.

31{
32 PPROCESSINFO ppi;
33 BOOL bResult;
34
36
37 TRACE("IntLoadHookModule. Client PID: %p\n", PsGetProcessId(ppi->peProcess));
38
39 /* Check if this is the api hook */
40 if(iHookID == WH_APIHOOK)
41 {
42 if(!Unload && !(ppi->W32PF_flags & W32PF_APIHOOKLOADED))
43 {
44 /* A callback in user mode can trigger UserLoadApiHook to be called and
45 as a result IntLoadHookModule will be called recursively.
46 To solve this we set the flag that means that the application has
47 loaded the api hook before the callback and in case of error we remove it */
48 ppi->W32PF_flags |= W32PF_APIHOOKLOADED;
49
50 /* Call ClientLoadLibrary in user32 */
52 TRACE("co_IntClientLoadLibrary returned %d\n", bResult );
53 if (!bResult)
54 {
55 /* Remove the flag we set before */
56 ppi->W32PF_flags &= ~W32PF_APIHOOKLOADED;
57 }
58 return bResult;
59 }
60 else if(Unload && (ppi->W32PF_flags & W32PF_APIHOOKLOADED))
61 {
62 /* Call ClientLoadLibrary in user32 */
64 if (bResult)
65 {
66 ppi->W32PF_flags &= ~W32PF_APIHOOKLOADED;
67 }
68 return bResult;
69 }
70
71 return TRUE;
72 }
73
74 STUB;
75
76 return FALSE;
77}
static VOID NTAPI Unload(PDRIVER_OBJECT DriverObject)
Definition: floppy.c:377
#define WH_APIHOOK
Definition: hook.h:12
#define STUB
Definition: kernel32.h:27
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
UNICODE_STRING strUahModule
Definition: hook.c:22
UNICODE_STRING strUahInitFunc
Definition: hook.c:23
BOOL NTAPI co_IntClientLoadLibrary(PUNICODE_STRING pstrLibName, PUNICODE_STRING pstrInitFunc, BOOL Unload, BOOL ApiHook)
Definition: callback.c:136

Referenced by co_MsqDispatchOneSentMessage(), and UserLoadApiHook().

◆ IntRemoveHook()

BOOLEAN IntRemoveHook ( PVOID  Object)

Definition at line 1036 of file hook.c.

1037{
1038 INT HookId;
1039 PTHREADINFO ptiHook, pti;
1040 PDESKTOP pdo;
1041 PHOOK Hook = Object;
1042
1044
1045 HookId = Hook->HookId;
1047
1048 if (Hook->ptiHooked) // Local
1049 {
1050 ptiHook = Hook->ptiHooked;
1051
1052 IntFreeHook(Hook);
1053
1054 if (IsListEmpty(&ptiHook->aphkStart[HOOKID_TO_INDEX(HookId)]))
1055 {
1056 BOOL bOtherProcess;
1058
1059 ptiHook->fsHooks &= ~HOOKID_TO_FLAG(HookId);
1060 bOtherProcess = (ptiHook->ppi != pti->ppi);
1061
1062 if (bOtherProcess)
1063 KeStackAttachProcess(&ptiHook->ppi->peProcess->Pcb, &ApcState);
1064
1065 _SEH2_TRY
1066 {
1067 ptiHook->pClientInfo->fsHooks = ptiHook->fsHooks;
1068 }
1070 {
1071 /* Do nothing */
1072 (void)0;
1073 }
1074 _SEH2_END;
1075
1076 if (bOtherProcess)
1078 }
1079 }
1080 else // Global
1081 {
1082 IntFreeHook(Hook);
1083
1084 pdo = IntGetActiveDesktop();
1085
1086 if (pdo &&
1087 pdo->pDeskInfo &&
1089 {
1090 pdo->pDeskInfo->fsHooks &= ~HOOKID_TO_FLAG(HookId);
1091 }
1092 }
1093
1094 return TRUE;
1095}
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1765
static VOID FASTCALL IntFreeHook(PHOOK Hook)
Definition: hook.c:1022
BOOL FASTCALL UserIsEnteredExclusive(VOID)
Definition: ntuser.c:224
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:704
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:756
ULONG fsHooks
Definition: win32.h:117
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
KAPC_STATE
Definition: ketypes.h:1409

Referenced by IntUnhookWindowsHook(), NtUserSetWindowsHookEx(), and NtUserUnhookWindowsHookEx().

◆ IntUnhookWindowsHook()

BOOL FASTCALL IntUnhookWindowsHook ( int  HookId,
HOOKPROC  pfnFilterProc 
)

Definition at line 1319 of file hook.c.

1320{
1321 PHOOK Hook;
1322 PLIST_ENTRY pLastHead, pElement;
1324
1325 if (HookId < WH_MINHOOK || WH_MAXHOOK < HookId )
1326 {
1328 return FALSE;
1329 }
1330
1331 if (pti->fsHooks)
1332 {
1333 pLastHead = &pti->aphkStart[HOOKID_TO_INDEX(HookId)];
1334
1335 pElement = pLastHead->Flink;
1336 while (pElement != pLastHead)
1337 {
1338 Hook = CONTAINING_RECORD(pElement, HOOK, Chain);
1339
1340 /* Get the next element now, we might free the hook in what follows */
1341 pElement = Hook->Chain.Flink;
1342
1343 if (Hook->Proc == pfnFilterProc)
1344 {
1345 if (Hook->head.pti == pti)
1346 {
1347 IntRemoveHook(Hook);
1348 return TRUE;
1349 }
1350 else
1351 {
1353 return FALSE;
1354 }
1355 }
1356 }
1357 }
1358 return FALSE;
1359}
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
BOOLEAN IntRemoveHook(PVOID Object)
Definition: hook.c:1036
#define ERROR_INVALID_HOOK_FILTER
Definition: winerror.h:907

Referenced by NtUserCallTwoParam().

◆ NtUserCallNextHookEx()

LRESULT APIENTRY NtUserCallNextHookEx ( int  Code,
WPARAM  wParam,
LPARAM  lParam,
BOOL  Ansi 
)

Definition at line 1370 of file hook.c.

1374{
1375 PTHREADINFO pti;
1376 PHOOK HookObj, NextObj;
1378 LRESULT lResult = 0;
1379
1380 TRACE("Enter NtUserCallNextHookEx\n");
1382
1383 pti = GetW32ThreadInfo();
1384
1385 HookObj = pti->sphkCurrent;
1386
1387 if (!HookObj)
1388 goto Exit; // Return 0
1389
1390 NextObj = HookObj->phkNext;
1391
1392 pti->sphkCurrent = NextObj;
1393 ClientInfo = pti->pClientInfo;
1394 _SEH2_TRY
1395 {
1396 ClientInfo->phkCurrent = NextObj;
1397 }
1399 {
1400 ClientInfo = NULL;
1401 }
1402 _SEH2_END;
1403
1404 /* Now in List run down. */
1405 if (ClientInfo && NextObj)
1406 {
1407 NextObj->phkNext = IntGetNextHook(NextObj);
1408 lResult = co_UserCallNextHookEx( NextObj, Code, wParam, lParam, NextObj->Ansi);
1409 }
1410
1411Exit:
1412 TRACE("Leave NtUserCallNextHookEx, ret=%i\n", lResult);
1413 UserLeave();
1414 return lResult;
1415}
struct _THREADINFO * GetW32ThreadInfo(VOID)
Definition: misc.c:805
static LRESULT APIENTRY co_UserCallNextHookEx(PHOOK Hook, int Code, WPARAM wParam, LPARAM lParam, BOOL Ansi)
Definition: hook.c:521
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:251
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:242

Referenced by CallNextHookEx().

◆ NtUserRegisterUserApiHook()

BOOL APIENTRY NtUserRegisterUserApiHook ( PUNICODE_STRING  m_dllname1,
PUNICODE_STRING  m_funname1,
DWORD  dwUnknown3,
DWORD  dwUnknown4 
)

Definition at line 1722 of file hook.c.

1727{
1728 BOOL ret;
1729 UNICODE_STRING strDllNameSafe;
1730 UNICODE_STRING strFuncNameSafe;
1732
1733 /* Probe and capture parameters */
1734 Status = ProbeAndCaptureUnicodeString(&strDllNameSafe, UserMode, m_dllname1);
1735 if(!NT_SUCCESS(Status))
1736 {
1738 return FALSE;
1739 }
1740
1741 Status = ProbeAndCaptureUnicodeString(&strFuncNameSafe, UserMode, m_funname1);
1742 if(!NT_SUCCESS(Status))
1743 {
1744 ReleaseCapturedUnicodeString(&strDllNameSafe, UserMode);
1746 return FALSE;
1747 }
1748
1750
1751 /* Call internal function */
1752 ret = UserRegisterUserApiHook(&strDllNameSafe, &strFuncNameSafe);
1753
1754 UserLeave();
1755
1756 /* Cleanup only in case of failure */
1757 if(ret == FALSE)
1758 {
1759 ReleaseCapturedUnicodeString(&strDllNameSafe, UserMode);
1760 ReleaseCapturedUnicodeString(&strFuncNameSafe, UserMode);
1761 }
1762
1763 return ret;
1764}
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define UserMode
Definition: asm.h:35
BOOL FASTCALL UserRegisterUserApiHook(PUNICODE_STRING pstrDllName, PUNICODE_STRING pstrFuncName)
Definition: hook.c:138
static __inline NTSTATUS ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest, IN KPROCESSOR_MODE CurrentMode, IN const UNICODE_STRING *UnsafeSrc)
Definition: probe.h:142
static __inline VOID ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString, IN KPROCESSOR_MODE CurrentMode)
Definition: probe.h:239
int ret

Referenced by RegisterUserApiHook().

◆ NtUserSetWindowsHookAW()

HHOOK APIENTRY NtUserSetWindowsHookAW ( int  idHook,
HOOKPROC  lpfn,
BOOL  Ansi 
)

Definition at line 1419 of file hook.c.

1422{
1423 DWORD ThreadId;
1424 UNICODE_STRING USModuleName;
1425
1426 RtlInitUnicodeString(&USModuleName, NULL);
1428
1430 &USModuleName,
1431 ThreadId,
1432 idHook,
1433 lpfn,
1434 Ansi);
1435}
#define PtrToUint(p)
Definition: basetsd.h:85
unsigned long DWORD
Definition: ntddk_ex.h:95
#define NtCurrentTeb
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
HHOOK APIENTRY NtUserSetWindowsHookEx(HINSTANCE Mod, PUNICODE_STRING UnsafeModuleName, DWORD ThreadId, int HookId, HOOKPROC HookProc, BOOL Ansi)
Definition: hook.c:1439
HANDLE UniqueThread
Definition: compat.h:826
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151

◆ NtUserSetWindowsHookEx()

HHOOK APIENTRY NtUserSetWindowsHookEx ( HINSTANCE  Mod,
PUNICODE_STRING  UnsafeModuleName,
DWORD  ThreadId,
int  HookId,
HOOKPROC  HookProc,
BOOL  Ansi 
)

Definition at line 1439 of file hook.c.

1445{
1446 PWINSTATION_OBJECT WinStaObj;
1447 PHOOK Hook = NULL;
1450 HHOOK Handle;
1451 PTHREADINFO pti, ptiHook = NULL;
1452 HHOOK Ret = NULL;
1453
1454 TRACE("Enter NtUserSetWindowsHookEx\n");
1456
1458
1459 if (HookId < WH_MINHOOK || WH_MAXHOOK < HookId )
1460 {
1462 goto Cleanup; // Return NULL
1463 }
1464
1465 if (!HookProc)
1466 {
1468 goto Cleanup; // Return NULL
1469 }
1470
1471 if (ThreadId) /* thread-local hook */
1472 {
1473 if ( HookId == WH_JOURNALRECORD ||
1474 HookId == WH_JOURNALPLAYBACK ||
1475 HookId == WH_KEYBOARD_LL ||
1476 HookId == WH_MOUSE_LL ||
1477 HookId == WH_SYSMSGFILTER)
1478 {
1479 TRACE("Local hook installing Global HookId: %d\n",HookId);
1480 /* these can only be global */
1482 goto Cleanup; // Return NULL
1483 }
1484
1485 if ( !(ptiHook = IntTID2PTI( UlongToHandle(ThreadId) )))
1486 {
1487 ERR("Invalid thread id 0x%x\n", ThreadId);
1489 goto Cleanup; // Return NULL
1490 }
1491
1492 if ( ptiHook->rpdesk != pti->rpdesk) // gptiCurrent->rpdesk)
1493 {
1494 ERR("Local hook wrong desktop HookId: %d\n",HookId);
1496 goto Cleanup; // Return NULL
1497 }
1498
1499 if (ptiHook->ppi != pti->ppi)
1500 {
1501 if ( !Mod &&
1502 (HookId == WH_GETMESSAGE ||
1503 HookId == WH_CALLWNDPROC ||
1504 HookId == WH_CBT ||
1505 HookId == WH_HARDWARE ||
1506 HookId == WH_DEBUG ||
1507 HookId == WH_SHELL ||
1508 HookId == WH_FOREGROUNDIDLE ||
1509 HookId == WH_CALLWNDPROCRET) )
1510 {
1511 ERR("Local hook needs hMod HookId: %d\n",HookId);
1513 goto Cleanup; // Return NULL
1514 }
1515
1516 if ( (ptiHook->TIF_flags & (TIF_CSRSSTHREAD|TIF_SYSTEMTHREAD)) &&
1517 (HookId == WH_GETMESSAGE ||
1518 HookId == WH_CALLWNDPROC ||
1519 HookId == WH_CBT ||
1520 HookId == WH_HARDWARE ||
1521 HookId == WH_DEBUG ||
1522 HookId == WH_SHELL ||
1523 HookId == WH_FOREGROUNDIDLE ||
1524 HookId == WH_CALLWNDPROCRET) )
1525 {
1527 goto Cleanup; // Return NULL
1528 }
1529 }
1530 }
1531 else /* System-global hook */
1532 {
1533 ptiHook = pti; // gptiCurrent;
1534 if ( !Mod &&
1535 (HookId == WH_GETMESSAGE ||
1536 HookId == WH_CALLWNDPROC ||
1537 HookId == WH_CBT ||
1538 HookId == WH_SYSMSGFILTER ||
1539 HookId == WH_HARDWARE ||
1540 HookId == WH_DEBUG ||
1541 HookId == WH_SHELL ||
1542 HookId == WH_FOREGROUNDIDLE ||
1543 HookId == WH_CALLWNDPROCRET) )
1544 {
1545 ERR("Global hook needs hMod HookId: %d\n",HookId);
1547 goto Cleanup; // Return NULL
1548 }
1549 }
1550
1552 UserMode,
1553 0,
1554 &WinStaObj,
1555 0);
1556
1557 if (!NT_SUCCESS(Status))
1558 {
1560 goto Cleanup; // Return NULL
1561 }
1562 ObDereferenceObject(WinStaObj);
1563
1564 Hook = UserCreateObject(gHandleTable, NULL, ptiHook, (PHANDLE)&Handle, TYPE_HOOK, sizeof(HOOK));
1565
1566 if (!Hook)
1567 {
1568 goto Cleanup; // Return NULL
1569 }
1570
1571 Hook->ihmod = (INT_PTR)Mod; // Module Index from atom table, Do this for now.
1572 Hook->HookId = HookId;
1573 Hook->rpdesk = ptiHook->rpdesk;
1574 Hook->phkNext = NULL; /* Dont use as a chain! Use link lists for chaining. */
1575 Hook->Proc = HookProc;
1576 Hook->Ansi = Ansi;
1577
1578 TRACE("Set Hook Desk %p DeskInfo %p Handle Desk %p\n", pti->rpdesk, pti->pDeskInfo, Hook->head.rpdesk);
1579
1580 if (ThreadId) /* Thread-local hook */
1581 {
1582 InsertHeadList(&ptiHook->aphkStart[HOOKID_TO_INDEX(HookId)], &Hook->Chain);
1583 ptiHook->sphkCurrent = NULL;
1584 Hook->ptiHooked = ptiHook;
1585 ptiHook->fsHooks |= HOOKID_TO_FLAG(HookId);
1586
1587 if (ptiHook->pClientInfo)
1588 {
1589 if ( ptiHook->ppi == pti->ppi) /* gptiCurrent->ppi) */
1590 {
1591 _SEH2_TRY
1592 {
1593 ptiHook->pClientInfo->fsHooks = ptiHook->fsHooks;
1594 ptiHook->pClientInfo->phkCurrent = NULL;
1595 }
1597 {
1598 ERR("Problem writing to Local ClientInfo!\n");
1599 }
1600 _SEH2_END;
1601 }
1602 else
1603 {
1605
1606 KeStackAttachProcess(&ptiHook->ppi->peProcess->Pcb, &ApcState);
1607 _SEH2_TRY
1608 {
1609 ptiHook->pClientInfo->fsHooks = ptiHook->fsHooks;
1610 ptiHook->pClientInfo->phkCurrent = NULL;
1611 }
1613 {
1614 ERR("Problem writing to Remote ClientInfo!\n");
1615 }
1616 _SEH2_END;
1618 }
1619 }
1620 }
1621 else
1622 {
1623 InsertHeadList(&ptiHook->rpdesk->pDeskInfo->aphkStart[HOOKID_TO_INDEX(HookId)], &Hook->Chain);
1624 Hook->ptiHooked = NULL;
1625 //gptiCurrent->pDeskInfo->fsHooks |= HOOKID_TO_FLAG(HookId);
1626 ptiHook->rpdesk->pDeskInfo->fsHooks |= HOOKID_TO_FLAG(HookId);
1627 ptiHook->sphkCurrent = NULL;
1628 ptiHook->pClientInfo->phkCurrent = NULL;
1629 }
1630
1632
1633 if (Mod)
1634 {
1636 UnsafeModuleName,
1637 sizeof(UNICODE_STRING));
1638 if (!NT_SUCCESS(Status))
1639 {
1640 IntRemoveHook(Hook);
1642 goto Cleanup; // Return NULL
1643 }
1644
1646 ModuleName.MaximumLength,
1647 TAG_HOOK);
1648 if (NULL == Hook->ModuleName.Buffer)
1649 {
1650 IntRemoveHook(Hook);
1652 goto Cleanup; // Return NULL
1653 }
1654
1655 Hook->ModuleName.MaximumLength = ModuleName.MaximumLength;
1657 ModuleName.Buffer,
1658 ModuleName.MaximumLength);
1659 if (!NT_SUCCESS(Status))
1660 {
1662 Hook->ModuleName.Buffer = NULL;
1663 IntRemoveHook(Hook);
1665 goto Cleanup; // Return NULL
1666 }
1667
1671 FIXME("NtUserSetWindowsHookEx Setting process hMod instance addressing.\n");
1672 /* Make proc relative to the module base */
1673 Hook->offPfn = (ULONG_PTR)((char *)HookProc - (char *)Mod);
1674 }
1675 else
1676 Hook->offPfn = 0;
1677
1678 TRACE("Installing: HookId %d Global %s\n", HookId, !ThreadId ? "TRUE" : "FALSE");
1679 Ret = Handle;
1680
1681Cleanup:
1682 if (Hook)
1684 TRACE("Leave NtUserSetWindowsHookEx, ret=%p\n", Ret);
1685 UserLeave();
1686 return Ret;
1687}
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1280
#define UlongToHandle(ul)
Definition: basetsd.h:97
#define FIXME(fmt,...)
Definition: debug.h:114
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static const WCHAR Cleanup[]
Definition: register.c:80
#define ULONG_PTR
Definition: config.h:101
#define InsertHeadList(ListHead, Entry)
ULONG Handle
Definition: gdb_input.c:15
#define TIF_CSRSSTHREAD
Definition: ntuser.h:266
#define TIF_SYSTEMTHREAD
Definition: ntuser.h:265
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:232
#define MmCopyFromCaller
Definition: polytest.cpp:29
struct _DESKTOP * rpdesk
Definition: ntuser.h:194
struct _DESKTOPINFO * pDeskInfo
Definition: win32.h:93
USHORT MaximumLength
Definition: env_spec_w32.h:370
ACPI_SIZE Length
Definition: actypes.h:1053
struct _DESKTOP * rpdesk
Definition: ntuser.h:247
int32_t INT_PTR
Definition: typedefs.h:64
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:31
PTHREADINFO FASTCALL IntTID2PTI(HANDLE id)
Definition: misc.c:42
BOOL FASTCALL UserDereferenceObject(PVOID Object)
Definition: object.c:644
PVOID FASTCALL UserCreateObject(PUSER_HANDLE_TABLE ht, PDESKTOP pDesktop, PTHREADINFO pti, HANDLE *h, HANDLE_TYPE type, ULONG size)
Definition: object.c:568
#define ERROR_HOOK_TYPE_NOT_ALLOWED
Definition: winerror.h:939
#define ERROR_INVALID_FILTER_PROC
Definition: winerror.h:908
#define ERROR_HOOK_NEEDS_HMOD
Definition: winerror.h:909
#define ERROR_GLOBAL_ONLY_HOOK
Definition: winerror.h:910
#define WH_CALLWNDPROCRET
Definition: winuser.h:42
#define WH_HARDWARE
Definition: winuser.h:38
#define WH_CALLWNDPROC
Definition: winuser.h:34
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by IntSetWindowsHook(), and NtUserSetWindowsHookAW().

◆ NtUserUnhookWindowsHookEx()

BOOL APIENTRY NtUserUnhookWindowsHookEx ( HHOOK  Hook)

Definition at line 1691 of file hook.c.

1692{
1693 PHOOK HookObj;
1694 BOOL Ret = FALSE;
1695
1696 TRACE("Enter NtUserUnhookWindowsHookEx\n");
1698
1699 if (!(HookObj = IntGetHookObject(Hook)))
1700 {
1701 ERR("Invalid handle passed to NtUserUnhookWindowsHookEx\n");
1702 /* SetLastNtError(Status); */
1703 goto Exit; // Return FALSE
1704 }
1705
1706 ASSERT(Hook == UserHMGetHandle(HookObj));
1707
1708 IntRemoveHook(HookObj);
1709
1710 UserDereferenceObject(HookObj);
1711
1712 Ret = TRUE;
1713
1714Exit:
1715 TRACE("Leave NtUserUnhookWindowsHookEx, ret=%i\n", Ret);
1716 UserLeave();
1717 return Ret;
1718}
PHOOK FASTCALL IntGetHookObject(HHOOK hHook)
Definition: hook.c:937

◆ NtUserUnregisterUserApiHook()

BOOL APIENTRY NtUserUnregisterUserApiHook ( VOID  )

Definition at line 1768 of file hook.c.

1769{
1770 BOOL ret;
1771
1774 UserLeave();
1775
1776 return ret;
1777}
BOOL FASTCALL UserUnregisterUserApiHook(VOID)
Definition: hook.c:206

Referenced by UnregisterUserApiHook().

◆ UserLoadApiHook()

BOOL FASTCALL UserLoadApiHook ( VOID  )

Definition at line 131 of file hook.c.

132{
134}
BOOL IntLoadHookModule(int iHookID, HHOOK hHook, BOOL Unload)
Definition: hook.c:30

Referenced by NtUserCallNoParam().

◆ UserRegisterUserApiHook()

BOOL FASTCALL UserRegisterUserApiHook ( PUNICODE_STRING  pstrDllName,
PUNICODE_STRING  pstrFuncName 
)

Definition at line 138 of file hook.c.

141{
142 PTHREADINFO pti, ptiCurrent;
143 HWND *List;
144 PWND DesktopWindow, pwndCurrent;
145 ULONG i;
146 PPROCESSINFO ppiCsr;
147
150
151 /* Fail if the api hook is already registered */
153 {
154 return FALSE;
155 }
156
157 TRACE("UserRegisterUserApiHook. Server PID: %p\n", PsGetProcessId(pti->ppi->peProcess));
158
159 /* Register the api hook */
161
162 strUahModule = *pstrDllName;
163 strUahInitFunc = *pstrFuncName;
164 ppiUahServer = pti->ppi;
165
166 /* Broadcast an internal message to every top level window */
169
170 if (List != NULL)
171 {
172 for (i = 0; List[i]; i++)
173 {
174 pwndCurrent = UserGetWindowObject(List[i]);
175 if(pwndCurrent == NULL)
176 {
177 continue;
178 }
179 ptiCurrent = pwndCurrent->head.pti;
180
181 /* FIXME: The first check is a reactos specific hack for system threads */
182 if(PsIsSystemProcess(ptiCurrent->ppi->peProcess) ||
183 ptiCurrent->ppi == ppiCsr)
184 {
185 continue;
186 }
187
188 co_MsqSendMessageAsync( ptiCurrent,
189 0,
191 FALSE, /* Load the module */
192 0,
193 NULL,
194 0,
195 FALSE,
197 }
199 }
200
201 return TRUE;
202}
PSERVERINFO gpsi
Definition: imm.c:18
#define SRVINFO_APIHOOK
Definition: ntuser.h:950
PPROCESSINFO ppiUahServer
Definition: hook.c:24
Implementation of the Explorer desktop window.
Definition: desktop.h:52
Definition: ntuser.h:694
THRDESKHEAD head
Definition: ntuser.h:695
DWORD dwSRVIFlags
Definition: ntuser.h:1051
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:122
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
HWND FASTCALL IntGetDesktopWindow(VOID)
Definition: desktop.c:1374
#define USERTAG_WINDOWLIST
Definition: tags.h:298
HWND *FASTCALL IntWinListChildren(PWND Window)
Definition: window.c:274

Referenced by NtUserRegisterUserApiHook().

◆ UserUnregisterUserApiHook()

BOOL FASTCALL UserUnregisterUserApiHook ( VOID  )

Definition at line 206 of file hook.c.

207{
208 PTHREADINFO pti;
209
211
212 /* Fail if the api hook is not registered */
214 {
215 return FALSE;
216 }
217
218 /* Only the process that registered the api hook can uregister it */
220 {
221 return FALSE;
222 }
223
224 TRACE("UserUnregisterUserApiHook. Server PID: %p\n", PsGetProcessId(pti->ppi->peProcess));
225
226 /* Unregister the api hook */
227 gpsi->dwSRVIFlags &= ~SRVINFO_APIHOOK;
231
232 /* Notify all applications that the api hook module must be unloaded */
233 return IntHookModuleUnloaded(pti->rpdesk, WH_APIHOOK, 0);
234}
BOOL IntHookModuleUnloaded(PDESKTOP pdesk, int iHookID, HHOOK hHook)
Definition: hook.c:88

Referenced by ExitThreadCallback(), and NtUserUnregisterUserApiHook().

Variable Documentation

◆ ppiUahServer

PPROCESSINFO ppiUahServer

Definition at line 24 of file hook.c.

Referenced by ExitThreadCallback(), UserRegisterUserApiHook(), and UserUnregisterUserApiHook().

◆ strUahInitFunc

UNICODE_STRING strUahInitFunc

Definition at line 23 of file hook.c.

Referenced by IntLoadHookModule(), UserRegisterUserApiHook(), and UserUnregisterUserApiHook().

◆ strUahModule

UNICODE_STRING strUahModule

Definition at line 22 of file hook.c.

Referenced by IntLoadHookModule(), UserRegisterUserApiHook(), and UserUnregisterUserApiHook().