ReactOS 0.4.15-dev-5893-g1bb4167
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;
330
331 phk = pHP->pHk;
332 lParam = pHP->lParam;
333
334 switch(HookId)
335 {
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}
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:1099
struct _HOOKPACK * PHOOKPACK
Definition: hook.c:17
PVOID pHookStructs
Definition: hook.c:20
PHOOK pHk
Definition: hook.c:18
LPARAM lParam
Definition: hook.c:19
INT_PTR ihmod
Definition: ntuser.h:244
HOOKPROC Proc
Definition: ntuser.h:249
ULONG_PTR offPfn
Definition: ntuser.h:242
BOOLEAN Ansi
Definition: ntuser.h:250
UNICODE_STRING ModuleName
Definition: ntuser.h:251
_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:426

Referenced by co_MsqDispatchOneSentMessage().

◆ co_EVENT_CallEvents()

LRESULT APIENTRY co_EVENT_CallEvents ( DWORD  event,
HWND  hwnd,
UINT_PTR  idObject,
LONG_PTR  idChild 
)

Definition at line 151 of file event.c.

155{
156 PEVENTHOOK pEH;
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}
#define EngGetTickCount32()
Definition: eng.h:43
struct _cl_event * event
Definition: glext.h:7739
#define TRACE(s)
Definition: solgame.cpp:4
LONG idObject
Definition: event.c:15
LONG idChild
Definition: event.c:16
PEVENTHOOK pEH
Definition: event.c:14
LONG idThread
Definition: event.c:17
WINEVENTPROC Proc
Definition: hook.h:23
ULONG_PTR offPfn
Definition: hook.h:25
INT_PTR ihmod
Definition: hook.h:26
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:838
struct _EVENTPACK * PEVENTPACK
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by handle_internal_events().

◆ co_HOOK_CallHooks()

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

Definition at line 1103 of file hook.c.

1107{
1108 PHOOK Hook, SaveHook;
1109 PTHREADINFO pti;
1111 PLIST_ENTRY pLastHead;
1112 PDESKTOP pdo;
1113 BOOL Local = FALSE, Global = FALSE;
1114 LRESULT Result = 0;
1116
1117 ASSERT(WH_MINHOOK <= HookId && HookId <= WH_MAXHOOK);
1118
1120 if (!pti || !pti->rpdesk || !pti->rpdesk->pDeskInfo)
1121 {
1122 pdo = IntGetActiveDesktop();
1123 /* If KeyboardThread|MouseThread|(RawInputThread or RIT) aka system threads,
1124 pti->fsHooks most likely, is zero. So process KbT & MsT to "send" the message.
1125 */
1126 if ( !pti || !pdo || (!(HookId == WH_KEYBOARD_LL) && !(HookId == WH_MOUSE_LL)) )
1127 {
1128 TRACE("No PDO %d\n", HookId);
1129 goto Exit;
1130 }
1131 }
1132 else
1133 {
1134 pdo = pti->rpdesk;
1135 }
1136
1138 {
1139 TRACE("Hook Thread dead %d\n", HookId);
1140 goto Exit;
1141 }
1142
1143 if ( ISITHOOKED(HookId) )
1144 {
1145 TRACE("Local Hooker %d\n", HookId);
1146 Local = TRUE;
1147 }
1148
1149 if ( pdo->pDeskInfo->fsHooks & HOOKID_TO_FLAG(HookId) )
1150 {
1151 TRACE("Global Hooker %d\n", HookId);
1152 Global = TRUE;
1153 }
1154
1155 if ( !Local && !Global ) goto Exit; // No work!
1156
1157 Hook = NULL;
1158
1159 /* SetWindowHookEx sorts out the Thread issue by placing the Hook to
1160 the correct Thread if not NULL.
1161 */
1162 if ( Local )
1163 {
1164 pLastHead = &pti->aphkStart[HOOKID_TO_INDEX(HookId)];
1165 if (IsListEmpty(pLastHead))
1166 {
1167 ERR("No Local Hook Found!\n");
1168 goto Exit;
1169 }
1170
1171 Hook = CONTAINING_RECORD(pLastHead->Flink, HOOK, Chain);
1172 ObReferenceObject(pti->pEThread);
1174 UserRefObjectCo(Hook, &Ref);
1175
1176 ClientInfo = pti->pClientInfo;
1177 SaveHook = pti->sphkCurrent;
1178 /* Note: Setting pti->sphkCurrent will also lock the next hook to this
1179 * hook ID. So, the CallNextHookEx will only call to that hook ID
1180 * chain anyway. For Thread Hooks....
1181 */
1182
1183 /* Load it for the next call. */
1184 pti->sphkCurrent = Hook;
1185 Hook->phkNext = IntGetNextHook(Hook);
1186 if (ClientInfo)
1187 {
1188 _SEH2_TRY
1189 {
1190 ClientInfo->phkCurrent = Hook;
1191 }
1193 {
1194 ClientInfo = NULL; // Don't bother next run.
1195 }
1196 _SEH2_END;
1197 }
1198 Result = co_IntCallHookProc( HookId,
1199 Code,
1200 wParam,
1201 lParam,
1202 Hook->Proc,
1203 Hook->ihmod,
1204 Hook->offPfn,
1205 Hook->Ansi,
1206 &Hook->ModuleName);
1207 if (ClientInfo)
1208 {
1209 _SEH2_TRY
1210 {
1211 ClientInfo->phkCurrent = SaveHook;
1212 }
1214 {
1215 /* Do nothing */
1216 (void)0;
1217 }
1218 _SEH2_END;
1219 }
1220 pti->sphkCurrent = SaveHook;
1221 Hook->phkNext = NULL;
1222 UserDerefObjectCo(Hook);
1224 ObDereferenceObject(pti->pEThread);
1225 }
1226
1227 if ( Global )
1228 {
1229 PTHREADINFO ptiHook;
1230 HHOOK *pHookHandles;
1231 unsigned i;
1232
1233 /* Keep hooks in array because hooks can be destroyed in user world */
1234 pHookHandles = IntGetGlobalHookHandles(pdo, HookId);
1235 if(!pHookHandles)
1236 goto Exit;
1237
1238 /* Performance goes down the drain. If more hooks are associated to this
1239 * hook ID, this will have to post to each of the thread message queues
1240 * or make a direct call.
1241 */
1242 for(i = 0; pHookHandles[i]; ++i)
1243 {
1244 Hook = (PHOOK)UserGetObject(gHandleTable, pHookHandles[i], TYPE_HOOK);
1245 if(!Hook)
1246 {
1247 ERR("Invalid hook!\n");
1248 continue;
1249 }
1250
1251 /* Hook->Thread is null, we hax around this with Hook->head.pti. */
1252 ptiHook = Hook->head.pti;
1253
1254 if ( (pti->TIF_flags & TIF_DISABLEHOOKS) || (ptiHook->TIF_flags & TIF_INCLEANUP))
1255 {
1256 TRACE("Next Hook %p, %p\n", ptiHook->rpdesk, pdo);
1257 continue;
1258 }
1259 UserRefObjectCo(Hook, &Ref);
1260
1261 if (ptiHook != pti )
1262 {
1263 // Block | TimeOut
1264 if ( HookId == WH_JOURNALPLAYBACK || // 1 | 0
1265 HookId == WH_JOURNALRECORD || // 1 | 0
1266 HookId == WH_KEYBOARD || // 1 | 200
1267 HookId == WH_MOUSE || // 1 | 200
1268 HookId == WH_KEYBOARD_LL || // 0 | 300
1269 HookId == WH_MOUSE_LL ) // 0 | 300
1270 {
1271 TRACE("\nGlobal Hook posting to another Thread! %d\n",HookId );
1273 }
1274 else if (ptiHook->ppi == pti->ppi)
1275 {
1276 TRACE("\nGlobal Hook calling to another Thread! %d\n",HookId );
1277 ObReferenceObject(ptiHook->pEThread);
1278 IntReferenceThreadInfo(ptiHook);
1279 Result = co_IntCallHookProc( HookId,
1280 Code,
1281 wParam,
1282 lParam,
1283 Hook->Proc,
1284 Hook->ihmod,
1285 Hook->offPfn,
1286 Hook->Ansi,
1287 &Hook->ModuleName);
1288 IntDereferenceThreadInfo(ptiHook);
1289 ObDereferenceObject(ptiHook->pEThread);
1290 }
1291 }
1292 else
1293 { /* Make the direct call. */
1294 TRACE("Global going Local Hook calling to Thread! %d\n",HookId );
1295 ObReferenceObject(pti->pEThread);
1297 Result = co_IntCallHookProc( HookId,
1298 Code,
1299 wParam,
1300 lParam,
1301 Hook->Proc,
1302 Hook->ihmod,
1303 Hook->offPfn,
1304 Hook->Ansi,
1305 &Hook->ModuleName);
1307 ObDereferenceObject(pti->pEThread);
1308 }
1309 UserDerefObjectCo(Hook);
1310 }
1311 ExFreePoolWithTag(pHookHandles, TAG_HOOK);
1312 TRACE("Ret: Global HookId %d Result 0x%x\n", HookId,Result);
1313 }
1314Exit:
1315 return Result;
1316}
#define ERR(fmt,...)
Definition: debug.h:110
#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:262
struct tagHOOK * PHOOK
@ TYPE_HOOK
Definition: ntuser.h:45
#define TIF_DISABLEHOOKS
Definition: ntuser.h:290
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:963
static LRESULT FASTCALL co_IntCallLowLevelHook(PHOOK Hook, INT Code, WPARAM wParam, LPARAM lParam)
Definition: hook.c:240
PHOOK FASTCALL IntGetNextHook(PHOOK Hook)
Definition: hook.c:996
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:34
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:240
THRDESKHEAD head
Definition: ntuser.h:239
#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().

◆ IntGetHookObject()

PHOOK FASTCALL IntGetHookObject ( HHOOK  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
956
957 return Hook;
958}
VOID FASTCALL UserReferenceObject(PVOID obj)
Definition: object.c:731
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28
#define ERROR_INVALID_HOOK_HANDLE
Definition: winerror.h:885

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}
LIST_ENTRY Chain
Definition: ntuser.h:248
int HookId
Definition: ntuser.h:241
struct _THREADINFO * ptiHooked
Definition: ntuser.h:245

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}
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
HANDLE NTAPI PsGetProcessId(PEPROCESS Process)
Definition: process.c:1063
UNICODE_STRING strUahModule
Definition: hook.c:23
UNICODE_STRING strUahInitFunc
Definition: hook.c:24
#define W32PF_APIHOOKLOADED
Definition: win32.h:35
BOOL NTAPI co_IntClientLoadLibrary(PUNICODE_STRING pstrLibName, PUNICODE_STRING pstrInitFunc, BOOL Unload, BOOL ApiHook)
Definition: callback.c:136

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);
139 return TRUE;
140 }
141 return FALSE;
142}
PSERVERINFO gpsi
Definition: imm.c:18
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
@ TYPE_WINEVENTHOOK
Definition: ntuser.h:55
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
LIST_ENTRY Chain
Definition: hook.h:18
UINT Counts
Definition: hook.h:32
DWORD dwInstalledEventHooks
Definition: ntuser.h:1066
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
static PEVENTTABLE GlobalEvents
Definition: event.c:20
BOOL FASTCALL UserDeleteObject(HANDLE h, HANDLE_TYPE type)
Definition: object.c:717

Referenced by NtUserUnhookWinEvent().

◆ IntRemoveHook()

BOOLEAN IntRemoveHook ( PVOID  Object)

Definition at line 1037 of file hook.c.

1038{
1039 INT HookId;
1040 PTHREADINFO ptiHook, pti;
1041 PDESKTOP pdo;
1042 PHOOK Hook = Object;
1043
1045
1046 HookId = Hook->HookId;
1048
1049 if (Hook->ptiHooked) // Local
1050 {
1051 ptiHook = Hook->ptiHooked;
1052
1053 IntFreeHook(Hook);
1054
1055 if (IsListEmpty(&ptiHook->aphkStart[HOOKID_TO_INDEX(HookId)]))
1056 {
1057 BOOL bOtherProcess;
1059
1060 ptiHook->fsHooks &= ~HOOKID_TO_FLAG(HookId);
1061 bOtherProcess = (ptiHook->ppi != pti->ppi);
1062
1063 if (bOtherProcess)
1064 KeStackAttachProcess(&ptiHook->ppi->peProcess->Pcb, &ApcState);
1065
1066 _SEH2_TRY
1067 {
1068 ptiHook->pClientInfo->fsHooks = ptiHook->fsHooks;
1069 }
1071 {
1072 /* Do nothing */
1073 (void)0;
1074 }
1075 _SEH2_END;
1076
1077 if (bOtherProcess)
1079 }
1080 }
1081 else // Global
1082 {
1083 IntFreeHook(Hook);
1084
1085 pdo = IntGetActiveDesktop();
1086
1087 if (pdo &&
1088 pdo->pDeskInfo &&
1090 {
1091 pdo->pDeskInfo->fsHooks &= ~HOOKID_TO_FLAG(HookId);
1092 }
1093 }
1094
1095 return TRUE;
1096}
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1727
static VOID FASTCALL IntFreeHook(PHOOK Hook)
Definition: hook.c:1023
BOOL FASTCALL UserIsEnteredExclusive(VOID)
Definition: ntuser.c:227
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
LIST_ENTRY aphkStart[NB_HOOKS]
Definition: ntuser.h:139
ULONG fsHooks
Definition: win32.h:117
int32_t INT
Definition: typedefs.h:58
KAPC_STATE
Definition: ketypes.h:1285
#define NT_ASSERT
Definition: rtlfuncs.h:3310

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

◆ IntUnhookWindowsHook()

BOOL FASTCALL IntUnhookWindowsHook ( int  HookId,
HOOKPROC  pfnFilterProc 
)

Definition at line 1320 of file hook.c.

1321{
1322 PHOOK Hook;
1323 PLIST_ENTRY pLastHead, pElement;
1325
1326 if (HookId < WH_MINHOOK || WH_MAXHOOK < HookId )
1327 {
1329 return FALSE;
1330 }
1331
1332 if (pti->fsHooks)
1333 {
1334 pLastHead = &pti->aphkStart[HOOKID_TO_INDEX(HookId)];
1335
1336 pElement = pLastHead->Flink;
1337 while (pElement != pLastHead)
1338 {
1339 Hook = CONTAINING_RECORD(pElement, HOOK, Chain);
1340
1341 /* Get the next element now, we might free the hook in what follows */
1342 pElement = Hook->Chain.Flink;
1343
1344 if (Hook->Proc == pfnFilterProc)
1345 {
1346 if (Hook->head.pti == pti)
1347 {
1348 IntRemoveHook(Hook);
1349 return TRUE;
1350 }
1351 else
1352 {
1354 return FALSE;
1355 }
1356 }
1357 }
1358 }
1359 return FALSE;
1360}
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
BOOLEAN IntRemoveHook(PVOID Object)
Definition: hook.c:1037
#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{
135}
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 */
228 gpsi->dwSRVIFlags &= ~SRVINFO_APIHOOK;
232
233 /* Notify all applications that the api hook module must be unloaded */
234 return IntHookModuleUnloaded(pti->rpdesk, WH_APIHOOK, 0);
235}
#define SRVINFO_APIHOOK
Definition: ntuser.h:945
#define UserMode
Definition: asm.h:35
BOOL IntHookModuleUnloaded(PDESKTOP pdesk, int iHookID, HHOOK hHook)
Definition: hook.c:89
PPROCESSINFO ppiUahServer
Definition: hook.c:25
static __inline VOID ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString, IN KPROCESSOR_MODE CurrentMode)
Definition: probe.h:239
DWORD dwSRVIFlags
Definition: ntuser.h:1046

Referenced by ExitThreadCallback(), and NtUserUnregisterUserApiHook().

Variable Documentation

◆ ppiUahServer

PPROCESSINFO ppiUahServer
extern

Definition at line 25 of file hook.c.

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