ReactOS  0.4.13-dev-52-g0efcfec
hook.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tagEVENTHOOK
 
struct  tagEVENTTABLE
 
struct  _NOTIFYEVENT
 

Macros

#define HOOK_THREAD_REFERENCED   (0x1)
 
#define HOOKID_TO_INDEX(HookId)   (HookId - WH_MINHOOK)
 
#define HOOKID_TO_FLAG(HookId)   (1 << ((HookId) + 1))
 
#define ISITHOOKED(HookId)   (((PTHREADINFO)PsGetCurrentThreadWin32Thread())->fsHooks & HOOKID_TO_FLAG(HookId))
 
#define WH_APIHOOK   WH_MAX + 1
 

Typedefs

typedef struct tagEVENTHOOK EVENTHOOK
 
typedef struct tagEVENTHOOKPEVENTHOOK
 
typedef struct tagEVENTTABLE EVENTTABLE
 
typedef struct tagEVENTTABLEPEVENTTABLE
 
typedef struct _NOTIFYEVENT NOTIFYEVENT
 
typedef struct _NOTIFYEVENTPNOTIFYEVENT
 

Functions

LRESULT APIENTRY co_CallHook (INT HookId, INT Code, WPARAM wParam, LPARAM lParam)
 
LRESULT APIENTRY co_HOOK_CallHooks (INT HookId, INT Code, WPARAM wParam, LPARAM lParam)
 
LRESULT APIENTRY co_EVENT_CallEvents (DWORD, HWND, UINT_PTR, LONG_PTR)
 
PHOOK FASTCALL IntGetHookObject (HHOOK)
 
PHOOK FASTCALL IntGetNextHook (PHOOK Hook)
 
LRESULT APIENTRY UserCallNextHookEx (PHOOK pHook, int Code, WPARAM wParam, LPARAM lParam, BOOL Ansi)
 
BOOL FASTCALL IntUnhookWindowsHook (int, HOOKPROC)
 
BOOLEAN IntRemoveHook (PVOID Object)
 
BOOLEAN IntRemoveEvent (PVOID Object)
 
BOOL FASTCALL UserLoadApiHook (VOID)
 
BOOL IntLoadHookModule (int iHookID, HHOOK hHook, BOOL Unload)
 
BOOL FASTCALL UserUnregisterUserApiHook (VOID)
 

Variables

PPROCESSINFO ppiUahServer
 

Macro Definition Documentation

◆ HOOK_THREAD_REFERENCED

#define HOOK_THREAD_REFERENCED   (0x1)

Definition at line 3 of file hook.h.

◆ HOOKID_TO_FLAG

#define HOOKID_TO_FLAG (   HookId)    (1 << ((HookId) + 1))

Definition at line 5 of file hook.h.

◆ HOOKID_TO_INDEX

#define HOOKID_TO_INDEX (   HookId)    (HookId - WH_MINHOOK)

Definition at line 4 of file hook.h.

◆ ISITHOOKED

#define ISITHOOKED (   HookId)    (((PTHREADINFO)PsGetCurrentThreadWin32Thread())->fsHooks & HOOKID_TO_FLAG(HookId))

Definition at line 6 of file hook.h.

◆ WH_APIHOOK

#define WH_APIHOOK   WH_MAX + 1

Definition at line 12 of file hook.h.

Typedef Documentation

◆ EVENTHOOK

◆ EVENTTABLE

◆ NOTIFYEVENT

◆ PEVENTHOOK

◆ PEVENTTABLE

◆ PNOTIFYEVENT

Function Documentation

◆ co_CallHook()

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

Definition at line 322 of file hook.c.

326 {
327  LRESULT Result = 0;
328  PHOOK phk;
329  PHOOKPACK pHP = (PHOOKPACK)lParam;
330 
331  phk = pHP->pHk;
332  lParam = pHP->lParam;
333 
334  switch(HookId)
335  {
336  case WH_JOURNALPLAYBACK:
337  case WH_JOURNALRECORD:
338  case WH_KEYBOARD_LL:
339  case WH_MOUSE_LL:
340  case WH_MOUSE:
341  lParam = (LPARAM)pHP->pHookStructs;
342  case WH_KEYBOARD:
343  break;
344  }
345 
347  {
348  /* The odds are high for this to be a Global call. */
349  Result = co_IntCallHookProc( HookId,
350  Code,
351  wParam,
352  lParam,
353  phk->Proc,
354  phk->ihmod,
355  phk->offPfn,
356  phk->Ansi,
357  &phk->ModuleName);
358  }
359  /* The odds so high, no one is waiting for the results. */
362  return Result;
363 }
#define WH_MOUSE
Definition: winuser.h:37
#define TAG_HOOK
Definition: tags.h:5
LPARAM lParam
Definition: hook.c:19
struct _HOOKPACK * PHOOKPACK
Definition: hook.c:16
WPARAM wParam
Definition: combotst.c:138
#define WH_MOUSE_LL
Definition: winuser.h:44
_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:426
LONG_PTR LPARAM
Definition: windef.h:208
BOOL FASTCALL UserObjectInDestroy(HANDLE h)
Definition: object.c:669
#define WH_JOURNALRECORD
Definition: winuser.h:30
#define Code
Definition: deflate.h:80
#define UserHMGetHandle(obj)
Definition: ntuser.h:208
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:513
BOOLEAN Ansi
Definition: ntuser.h:228
INT_PTR ihmod
Definition: ntuser.h:222
UNICODE_STRING ModuleName
Definition: ntuser.h:229
#define WH_KEYBOARD_LL
Definition: winuser.h:43
#define WH_JOURNALPLAYBACK
Definition: winuser.h:31
HOOKPROC Proc
Definition: ntuser.h:227
PHOOK pHk
Definition: hook.c:18
PVOID pHookStructs
Definition: hook.c:20
#define WH_KEYBOARD
Definition: winuser.h:32
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
ULONG_PTR offPfn
Definition: ntuser.h:220

Referenced by co_MsqDispatchOneSentMessage().

◆ co_EVENT_CallEvents()

LRESULT APIENTRY co_EVENT_CallEvents ( DWORD  ,
HWND  ,
UINT_PTR  ,
LONG_PTR   
)

Definition at line 151 of file event.c.

155 {
156  PEVENTHOOK pEH;
157  LRESULT Result;
158  PEVENTPACK pEP = (PEVENTPACK)idChild;
159 
160  pEH = pEP->pEH;
161  TRACE("Dispatch Event 0x%lx, idObject %uI hwnd %p\n", event, idObject, hwnd);
163  event,
164  hwnd,
165  pEP->idObject,
166  pEP->idChild,
167  pEP->idThread,
169  pEH->Proc,
170  pEH->ihmod,
171  pEH->offPfn);
172 
174  return Result;
175 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
INT_PTR ihmod
Definition: hook.h:26
#define TAG_HOOK
Definition: tags.h:5
#define EngGetTickCount32()
Definition: eng.h:43
LONG idObject
Definition: event.c:15
LRESULT APIENTRY co_IntCallEventProc(HWINEVENTHOOK hook, DWORD event, HWND hWnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime, WINEVENTPROC Proc, INT Mod, ULONG_PTR offPfn)
Definition: callback.c:824
_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:426
WINEVENTPROC Proc
Definition: hook.h:23
PEVENTHOOK pEH
Definition: event.c:14
#define UserHMGetHandle(obj)
Definition: ntuser.h:208
LONG idThread
Definition: event.c:17
#define TRACE(s)
Definition: solgame.cpp:4
struct _cl_event * event
Definition: glext.h:7739
LONG idChild
Definition: event.c:16
struct _EVENTPACK * PEVENTPACK
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
ULONG_PTR offPfn
Definition: hook.h:25
LONG_PTR LRESULT
Definition: windef.h:209

Referenced by handle_internal_events().

◆ co_HOOK_CallHooks()

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

Definition at line 1089 of file hook.c.

1093 {
1094  PHOOK Hook, SaveHook;
1095  PTHREADINFO pti;
1097  PLIST_ENTRY pLastHead;
1098  PDESKTOP pdo;
1099  BOOL Local = FALSE, Global = FALSE;
1100  LRESULT Result = 0;
1102 
1103  ASSERT(WH_MINHOOK <= HookId && HookId <= WH_MAXHOOK);
1104 
1106  if (!pti || !pti->rpdesk || !pti->rpdesk->pDeskInfo)
1107  {
1108  pdo = IntGetActiveDesktop();
1109  /* If KeyboardThread|MouseThread|(RawInputThread or RIT) aka system threads,
1110  pti->fsHooks most likely, is zero. So process KbT & MsT to "send" the message.
1111  */
1112  if ( !pti || !pdo || (!(HookId == WH_KEYBOARD_LL) && !(HookId == WH_MOUSE_LL)) )
1113  {
1114  TRACE("No PDO %d\n", HookId);
1115  goto Exit;
1116  }
1117  }
1118  else
1119  {
1120  pdo = pti->rpdesk;
1121  }
1122 
1124  {
1125  TRACE("Hook Thread dead %d\n", HookId);
1126  goto Exit;
1127  }
1128 
1129  if ( ISITHOOKED(HookId) )
1130  {
1131  TRACE("Local Hooker %d\n", HookId);
1132  Local = TRUE;
1133  }
1134 
1135  if ( pdo->pDeskInfo->fsHooks & HOOKID_TO_FLAG(HookId) )
1136  {
1137  TRACE("Global Hooker %d\n", HookId);
1138  Global = TRUE;
1139  }
1140 
1141  if ( !Local && !Global ) goto Exit; // No work!
1142 
1143  Hook = NULL;
1144 
1145  /* SetWindowHookEx sorts out the Thread issue by placing the Hook to
1146  the correct Thread if not NULL.
1147  */
1148  if ( Local )
1149  {
1150  pLastHead = &pti->aphkStart[HOOKID_TO_INDEX(HookId)];
1151  if (IsListEmpty(pLastHead))
1152  {
1153  ERR("No Local Hook Found!\n");
1154  goto Exit;
1155  }
1156 
1157  Hook = CONTAINING_RECORD(pLastHead->Flink, HOOK, Chain);
1158  ObReferenceObject(pti->pEThread);
1160  UserRefObjectCo(Hook, &Ref);
1161 
1162  ClientInfo = pti->pClientInfo;
1163  SaveHook = pti->sphkCurrent;
1164  /* Note: Setting pti->sphkCurrent will also lock the next hook to this
1165  * hook ID. So, the CallNextHookEx will only call to that hook ID
1166  * chain anyway. For Thread Hooks....
1167  */
1168 
1169  /* Load it for the next call. */
1170  pti->sphkCurrent = Hook;
1171  Hook->phkNext = IntGetNextHook(Hook);
1172  if (ClientInfo)
1173  {
1174  _SEH2_TRY
1175  {
1176  ClientInfo->phkCurrent = Hook;
1177  }
1179  {
1180  ClientInfo = NULL; // Don't bother next run.
1181  }
1182  _SEH2_END;
1183  }
1184  Result = co_IntCallHookProc( HookId,
1185  Code,
1186  wParam,
1187  lParam,
1188  Hook->Proc,
1189  Hook->ihmod,
1190  Hook->offPfn,
1191  Hook->Ansi,
1192  &Hook->ModuleName);
1193  if (ClientInfo)
1194  {
1195  _SEH2_TRY
1196  {
1197  ClientInfo->phkCurrent = SaveHook;
1198  }
1200  {
1201  /* Do nothing */
1202  (void)0;
1203  }
1204  _SEH2_END;
1205  }
1206  pti->sphkCurrent = SaveHook;
1207  Hook->phkNext = NULL;
1208  UserDerefObjectCo(Hook);
1210  ObDereferenceObject(pti->pEThread);
1211  }
1212 
1213  if ( Global )
1214  {
1215  PTHREADINFO ptiHook;
1216  HHOOK *pHookHandles;
1217  unsigned i;
1218 
1219  /* Keep hooks in array because hooks can be destroyed in user world */
1220  pHookHandles = IntGetGlobalHookHandles(pdo, HookId);
1221  if(!pHookHandles)
1222  goto Exit;
1223 
1224  /* Performance goes down the drain. If more hooks are associated to this
1225  * hook ID, this will have to post to each of the thread message queues
1226  * or make a direct call.
1227  */
1228  for(i = 0; pHookHandles[i]; ++i)
1229  {
1230  Hook = (PHOOK)UserGetObject(gHandleTable, pHookHandles[i], TYPE_HOOK);
1231  if(!Hook)
1232  {
1233  ERR("Invalid hook!\n");
1234  continue;
1235  }
1236 
1237  /* Hook->Thread is null, we hax around this with Hook->head.pti. */
1238  ptiHook = Hook->head.pti;
1239 
1240  if ( (pti->TIF_flags & TIF_DISABLEHOOKS) || (ptiHook->TIF_flags & TIF_INCLEANUP))
1241  {
1242  TRACE("Next Hook %p, %p\n", ptiHook->rpdesk, pdo);
1243  continue;
1244  }
1245  UserRefObjectCo(Hook, &Ref);
1246 
1247  if (ptiHook != pti )
1248  {
1249  // Block | TimeOut
1250  if ( HookId == WH_JOURNALPLAYBACK || // 1 | 0
1251  HookId == WH_JOURNALRECORD || // 1 | 0
1252  HookId == WH_KEYBOARD || // 1 | 200
1253  HookId == WH_MOUSE || // 1 | 200
1254  HookId == WH_KEYBOARD_LL || // 0 | 300
1255  HookId == WH_MOUSE_LL ) // 0 | 300
1256  {
1257  TRACE("\nGlobal Hook posting to another Thread! %d\n",HookId );
1259  }
1260  else if (ptiHook->ppi == pti->ppi)
1261  {
1262  TRACE("\nGlobal Hook calling to another Thread! %d\n",HookId );
1263  ObReferenceObject(ptiHook->pEThread);
1264  IntReferenceThreadInfo(ptiHook);
1265  Result = co_IntCallHookProc( HookId,
1266  Code,
1267  wParam,
1268  lParam,
1269  Hook->Proc,
1270  Hook->ihmod,
1271  Hook->offPfn,
1272  Hook->Ansi,
1273  &Hook->ModuleName);
1274  IntDereferenceThreadInfo(ptiHook);
1275  ObDereferenceObject(ptiHook->pEThread);
1276  }
1277  }
1278  else
1279  { /* Make the direct call. */
1280  TRACE("Global going Local Hook calling to Thread! %d\n",HookId );
1281  ObReferenceObject(pti->pEThread);
1283  Result = co_IntCallHookProc( HookId,
1284  Code,
1285  wParam,
1286  lParam,
1287  Hook->Proc,
1288  Hook->ihmod,
1289  Hook->offPfn,
1290  Hook->Ansi,
1291  &Hook->ModuleName);
1293  ObDereferenceObject(pti->pEThread);
1294  }
1295  UserDerefObjectCo(Hook);
1296  }
1297  ExFreePoolWithTag(pHookHandles, TAG_HOOK);
1298  TRACE("Ret: Global HookId %d Result 0x%x\n", HookId,Result);
1299  }
1300 Exit:
1301  return Result;
1302 }
#define WH_MOUSE
Definition: winuser.h:37
#define HOOKID_TO_FLAG(HookId)
Definition: hook.h:5
#define TRUE
Definition: types.h:120
PDESKTOPINFO pDeskInfo
Definition: desktop.h:8
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
DWORD fsHooks
Definition: ntuser.h:137
#define TAG_HOOK
Definition: tags.h:5
PHOOK FASTCALL IntGetNextHook(PHOOK Hook)
Definition: hook.c:996
FLONG TIF_flags
Definition: win32.h:94
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
struct tagHOOK * phkNext
Definition: ntuser.h:218
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:25
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
struct _DESKTOP * rpdesk
Definition: win32.h:91
UNICODE_STRING Global
Definition: symlink.c:37
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
WPARAM wParam
Definition: combotst.c:138
_SEH2_TRY
Definition: create.c:4250
PPROCESSINFO ppi
Definition: win32.h:87
CLIENT_DATA ClientInfo
#define WH_MOUSE_LL
Definition: winuser.h:44
struct tagHOOK * PHOOK
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
unsigned int BOOL
Definition: ntddk_ex.h:94
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:38
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
Definition: object.h:3
smooth NULL
Definition: ftsmooth.c:416
_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:426
#define WH_MAXHOOK
Definition: winuser.h:47
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define WH_JOURNALRECORD
Definition: winuser.h:30
#define HOOKID_TO_INDEX(HookId)
Definition: hook.h:4
#define IntReferenceThreadInfo(pti)
Definition: win32.h:162
#define Code
Definition: deflate.h:80
#define WH_MINHOOK
Definition: winuser.h:46
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:513
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
BOOLEAN Ansi
Definition: ntuser.h:228
INT_PTR ihmod
Definition: ntuser.h:222
UNICODE_STRING ModuleName
Definition: ntuser.h:229
#define WH_KEYBOARD_LL
Definition: winuser.h:43
static void Exit(void)
Definition: sock.c:1331
static HHOOK *FASTCALL IntGetGlobalHookHandles(PDESKTOP pdo, int HookId)
Definition: hook.c:963
#define ISITHOOKED(HookId)
Definition: hook.h:6
THRDESKHEAD head
Definition: ntuser.h:217
#define WH_JOURNALPLAYBACK
Definition: winuser.h:31
HOOKPROC Proc
Definition: ntuser.h:227
struct _CLIENTINFO * pClientInfo
Definition: win32.h:93
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LIST_ENTRY aphkStart[NB_HOOKS]
FIXME!
Definition: win32.h:137
Definition: typedefs.h:117
struct tagHOOK * sphkCurrent
Definition: win32.h:117
static LRESULT FASTCALL co_IntCallLowLevelHook(PHOOK Hook, INT Code, WPARAM wParam, LPARAM lParam)
Definition: hook.c:240
#define ERR(fmt,...)
Definition: debug.h:109
_SEH2_END
Definition: create.c:4424
PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, HANDLE_TYPE type)
Definition: object.c:462
#define WH_KEYBOARD
Definition: winuser.h:32
#define ObReferenceObject
Definition: obfuncs.h:204
#define TIF_DISABLEHOOKS
Definition: ntuser.h:268
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1226
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
LONG_PTR LRESULT
Definition: windef.h:209
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13
#define IntDereferenceThreadInfo(pti)
Definition: win32.h:167
LPARAM lParam
Definition: combotst.c:139
#define TIF_INCLEANUP
Definition: ntuser.h:240
ULONG_PTR offPfn
Definition: ntuser.h:220

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(), and NtUserDragDetect().

◆ IntGetHookObject()

PHOOK FASTCALL IntGetHookObject ( HHOOK  )

Definition at line 938 of file hook.c.

939 {
940  PHOOK Hook;
941 
942  if (!hHook)
943  {
945  return NULL;
946  }
947 
948  Hook = (PHOOK)UserGetObject(gHandleTable, hHook, TYPE_HOOK);
949  if (!Hook)
950  {
952  return NULL;
953  }
954 
955  UserReferenceObject(Hook);
956 
957  return Hook;
958 }
#define ERROR_INVALID_HOOK_HANDLE
Definition: winerror.h:885
struct tagHOOK * PHOOK
smooth NULL
Definition: ftsmooth.c:416
PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, HANDLE_TYPE type)
Definition: object.c:462
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
VOID FASTCALL UserReferenceObject(PVOID obj)
Definition: object.c:697

Referenced by NtUserUnhookWindowsHookEx().

◆ IntGetNextHook()

PHOOK FASTCALL IntGetNextHook ( PHOOK  Hook)

Definition at line 996 of file hook.c.

997 {
998  int HookId = Hook->HookId;
999  PLIST_ENTRY pLastHead, pElem;
1000  PTHREADINFO pti;
1001 
1002  if (Hook->ptiHooked)
1003  {
1004  pti = Hook->ptiHooked;
1005  pLastHead = &pti->aphkStart[HOOKID_TO_INDEX(HookId)];
1006  }
1007  else
1008  {
1010  pLastHead = &pti->rpdesk->pDeskInfo->aphkStart[HOOKID_TO_INDEX(HookId)];
1011  }
1012 
1013  pElem = Hook->Chain.Flink;
1014  if (pElem != pLastHead)
1015  return CONTAINING_RECORD(pElem, HOOK, Chain);
1016  return NULL;
1017 }
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
struct _DESKTOP * rpdesk
Definition: win32.h:91
struct _THREADINFO * ptiHooked
Definition: ntuser.h:223
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define HOOKID_TO_INDEX(HookId)
Definition: hook.h:4
int HookId
Definition: ntuser.h:219
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY aphkStart[NB_HOOKS]
FIXME!
Definition: win32.h:137
Definition: typedefs.h:117
LIST_ENTRY Chain
Definition: ntuser.h:226

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

◆ IntLoadHookModule()

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

Definition at line 31 of file hook.c.

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

Referenced by co_MsqDispatchOneSentMessage(), and UserLoadApiHook().

◆ IntRemoveEvent()

BOOLEAN IntRemoveEvent ( PVOID  Object)

Definition at line 127 of file event.c.

128 {
129  PEVENTHOOK pEH = Object;
130  if (pEH)
131  {
132  TRACE("IntRemoveEvent pEH %p\n", pEH);
134  RemoveEntryList(&pEH->Chain);
135  GlobalEvents->Counts--;
139  return TRUE;
140  }
141  return FALSE;
142 }
UINT Counts
Definition: hook.h:32
BOOL FASTCALL UserDeleteObject(HANDLE h, HANDLE_TYPE type)
Definition: object.c:683
#define TRUE
Definition: types.h:120
PSERVERINFO gpsi
Definition: main.c:27
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define UserHMGetHandle(obj)
Definition: ntuser.h:208
#define TRACE(s)
Definition: solgame.cpp:4
static IUnknown Object
Definition: main.c:512
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
static PEVENTTABLE GlobalEvents
Definition: event.c:20
DWORD dwInstalledEventHooks
Definition: ntuser.h:1024
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
LIST_ENTRY Chain
Definition: hook.h:18

Referenced by NtUserUnhookWinEvent().

◆ IntRemoveHook()

BOOLEAN IntRemoveHook ( PVOID  Object)

Definition at line 1037 of file hook.c.

1038 {
1039  INT HookId;
1040  PTHREADINFO pti;
1041  PDESKTOP pdo;
1042  PHOOK Hook = Object;
1043 
1044  HookId = Hook->HookId;
1045 
1046  if (Hook->ptiHooked) // Local
1047  {
1048  pti = Hook->ptiHooked;
1049 
1050  IntFreeHook( Hook);
1051 
1052  if ( IsListEmpty(&pti->aphkStart[HOOKID_TO_INDEX(HookId)]) )
1053  {
1054  pti->fsHooks &= ~HOOKID_TO_FLAG(HookId);
1055  _SEH2_TRY
1056  {
1057  pti->pClientInfo->fsHooks = pti->fsHooks;
1058  }
1060  {
1061  /* Do nothing */
1062  (void)0;
1063  }
1064  _SEH2_END;
1065  }
1066  }
1067  else // Global
1068  {
1069  IntFreeHook( Hook);
1070 
1071  pdo = IntGetActiveDesktop();
1072 
1073  if ( pdo &&
1074  pdo->pDeskInfo &&
1075  IsListEmpty(&pdo->pDeskInfo->aphkStart[HOOKID_TO_INDEX(HookId)]) )
1076  {
1077  pdo->pDeskInfo->fsHooks &= ~HOOKID_TO_FLAG(HookId);
1078  }
1079  }
1080 
1081  return TRUE;
1082 }
#define HOOKID_TO_FLAG(HookId)
Definition: hook.h:5
#define TRUE
Definition: types.h:120
PDESKTOPINFO pDeskInfo
Definition: desktop.h:8
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
DWORD fsHooks
Definition: ntuser.h:137
int32_t INT
Definition: typedefs.h:56
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
struct _THREADINFO * ptiHooked
Definition: ntuser.h:223
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static VOID FASTCALL IntFreeHook(PHOOK Hook)
Definition: hook.c:1023
#define HOOKID_TO_INDEX(HookId)
Definition: hook.h:4
int HookId
Definition: ntuser.h:219
ULONG fsHooks
Definition: win32.h:116
static IUnknown Object
Definition: main.c:512
struct _CLIENTINFO * pClientInfo
Definition: win32.h:93
LIST_ENTRY aphkStart[NB_HOOKS]
FIXME!
Definition: win32.h:137
_SEH2_END
Definition: create.c:4424
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1226
LIST_ENTRY aphkStart[NB_HOOKS]
Definition: ntuser.h:138

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

◆ IntUnhookWindowsHook()

BOOL FASTCALL IntUnhookWindowsHook ( int  ,
HOOKPROC   
)

Definition at line 1306 of file hook.c.

1307 {
1308  PHOOK Hook;
1309  PLIST_ENTRY pLastHead, pElement;
1311 
1312  if (HookId < WH_MINHOOK || WH_MAXHOOK < HookId )
1313  {
1315  return FALSE;
1316  }
1317 
1318  if (pti->fsHooks)
1319  {
1320  pLastHead = &pti->aphkStart[HOOKID_TO_INDEX(HookId)];
1321 
1322  pElement = pLastHead->Flink;
1323  while (pElement != pLastHead)
1324  {
1325  Hook = CONTAINING_RECORD(pElement, HOOK, Chain);
1326 
1327  /* Get the next element now, we might free the hook in what follows */
1328  pElement = Hook->Chain.Flink;
1329 
1330  if (Hook->Proc == pfnFilterProc)
1331  {
1332  if (Hook->head.pti == pti)
1333  {
1334  IntRemoveHook(Hook);
1335  return TRUE;
1336  }
1337  else
1338  {
1340  return FALSE;
1341  }
1342  }
1343  }
1344  }
1345  return FALSE;
1346 }
BOOLEAN IntRemoveHook(PVOID Object)
Definition: hook.c:1037
#define TRUE
Definition: types.h:120
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
#define WH_MAXHOOK
Definition: winuser.h:47
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define HOOKID_TO_INDEX(HookId)
Definition: hook.h:4
#define WH_MINHOOK
Definition: winuser.h:46
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ULONG fsHooks
Definition: win32.h:116
THRDESKHEAD head
Definition: ntuser.h:217
HOOKPROC Proc
Definition: ntuser.h:227
LIST_ENTRY aphkStart[NB_HOOKS]
FIXME!
Definition: win32.h:137
Definition: typedefs.h:117
LIST_ENTRY Chain
Definition: ntuser.h:226
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
#define ERROR_INVALID_HOOK_FILTER
Definition: winerror.h:907

Referenced by NtUserCallTwoParam().

◆ UserCallNextHookEx()

LRESULT APIENTRY UserCallNextHookEx ( PHOOK  pHook,
int  Code,
WPARAM  wParam,
LPARAM  lParam,
BOOL  Ansi 
)

◆ UserLoadApiHook()

BOOL FASTCALL UserLoadApiHook ( VOID  )

Definition at line 132 of file hook.c.

133 {
134  return IntLoadHookModule(WH_APIHOOK, 0, FALSE);
135 }
#define WH_APIHOOK
Definition: hook.h:12
BOOL IntLoadHookModule(int iHookID, HHOOK hHook, BOOL Unload)
Definition: hook.c:31

Referenced by NtUserCallNoParam().

◆ UserUnregisterUserApiHook()

BOOL FASTCALL UserUnregisterUserApiHook ( VOID  )

Definition at line 207 of file hook.c.

208 {
209  PTHREADINFO pti;
210 
212 
213  /* Fail if the api hook is not registered */
215  {
216  return FALSE;
217  }
218 
219  /* Only the process that registered the api hook can uregister it */
221  {
222  return FALSE;
223  }
224 
225  TRACE("UserUnregisterUserApiHook. Server PID: %p\n", PsGetProcessId(pti->ppi->peProcess));
226 
227  /* Unregister the api hook */
229  ppiUahServer = NULL;
232 
233  /* Notify all applications that the api hook module must be unloaded */
234  return IntHookModuleUnloaded(pti->rpdesk, WH_APIHOOK, 0);
235 }
UNICODE_STRING strUahInitFunc
Definition: hook.c:24
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
BOOL IntHookModuleUnloaded(PDESKTOP pdesk, int iHookID, HHOOK hHook)
Definition: hook.c:89
UNICODE_STRING strUahModule
Definition: hook.c:23
struct _DESKTOP * rpdesk
Definition: win32.h:91
PSERVERINFO gpsi
Definition: main.c:27
PPROCESSINFO ppi
Definition: win32.h:87
DWORD dwSRVIFlags
Definition: ntuser.h:1004
#define WH_APIHOOK
Definition: hook.h:12
smooth NULL
Definition: ftsmooth.c:416
static __inline VOID ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString, IN KPROCESSOR_MODE CurrentMode)
Definition: probe.h:228
#define TRACE(s)
Definition: solgame.cpp:4
PPROCESSINFO ppiUahServer
Definition: hook.c:25
#define SRVINFO_APIHOOK
Definition: ntuser.h:911
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
HANDLE NTAPI PsGetProcessId(PEPROCESS Process)
Definition: process.c:1063

Referenced by ExitThreadCallback(), and NtUserUnregisterUserApiHook().

Variable Documentation

◆ ppiUahServer

PPROCESSINFO ppiUahServer

Definition at line 25 of file hook.c.

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