LPMSG lpMsg,
int nCode)
{
- BOOL ret = FALSE;
-
- if (nCode != HCBT_CREATEWND) ret = NtUserCallMsgFilter((LPMSG) lpMsg, nCode);
- else
+ MSG Msg;
+ if (NtCurrentTeb()->Win32ThreadInfo && IsThreadHooked(GetWin32ClientInfo()))
+ {
+ if ( lpMsg->message & ~WM_MAXIMUM )
{
- UNICODE_STRING usBuffer;
- CBT_CREATEWNDA *cbtcwA = (CBT_CREATEWNDA *)lpMsg->lParam;
- CBT_CREATEWNDW cbtcwW;
- CREATESTRUCTW csW;
- MSG Msg;
-
- Msg.hwnd = lpMsg->hwnd;
- Msg.message = lpMsg->message;
- Msg.time = lpMsg->time;
- Msg.pt = lpMsg->pt;
- Msg.wParam = lpMsg->wParam;
-
- cbtcwW.lpcs = &csW;
- cbtcwW.hwndInsertAfter = cbtcwA->hwndInsertAfter;
- csW = *(CREATESTRUCTW *)cbtcwA->lpcs;
-
- if (HIWORD(cbtcwA->lpcs->lpszName))
- {
- RtlCreateUnicodeStringFromAsciiz(&usBuffer,cbtcwA->lpcs->lpszName);
- csW.lpszName = usBuffer.Buffer;
- }
- if (HIWORD(cbtcwA->lpcs->lpszClass))
- {
- RtlCreateUnicodeStringFromAsciiz(&usBuffer,cbtcwA->lpcs->lpszClass);
- csW.lpszClass = usBuffer.Buffer;
- }
- Msg.lParam =(LPARAM) &cbtcwW;
-
- ret = NtUserCallMsgFilter((LPMSG)&Msg, nCode);
-
- lpMsg->time = Msg.time;
- lpMsg->pt = Msg.pt;
-
- cbtcwA->hwndInsertAfter = cbtcwW.hwndInsertAfter;
- if (HIWORD(csW.lpszName)) HeapFree( GetProcessHeap(), 0, (LPWSTR)csW.lpszName );
- if (HIWORD(csW.lpszClass)) HeapFree( GetProcessHeap(), 0, (LPWSTR)csW.lpszClass );
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
}
- return ret;
+ RtlCopyMemory(&Msg, lpMsg, sizeof(MSG));
+ return NtUserCallMsgFilter( &Msg, nCode);
+ }
+ return FALSE;
}
LPMSG lpMsg,
int nCode)
{
- return NtUserCallMsgFilter((LPMSG) lpMsg, nCode);
+ MSG Msg;
+ if (NtCurrentTeb()->Win32ThreadInfo && IsThreadHooked(GetWin32ClientInfo()))
+ {
+ if ( lpMsg->message & ~WM_MAXIMUM )
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+ RtlCopyMemory(&Msg, lpMsg, sizeof(MSG));
+ return NtUserCallMsgFilter( &Msg, nCode);
+ }
+ return FALSE;
}
User32CallHookProcFromKernel(PVOID Arguments, ULONG ArgumentLength)
{
PHOOKPROC_CALLBACK_ARGUMENTS Common;
- LRESULT Result;
CREATESTRUCTW Csw;
CBT_CREATEWNDW CbtCreatewndw;
- CREATESTRUCTA Csa;
- CBT_CREATEWNDA CbtCreatewnda;
PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS CbtCreatewndExtra = NULL;
- WPARAM wParam = 0;
- LPARAM lParam = 0;
- PKBDLLHOOKSTRUCT pKeyboardLlData;
- PMSLLHOOKSTRUCT pMouseLlData;
- PMSG pMsg;
+ KBDLLHOOKSTRUCT KeyboardLlData, *pKeyboardLlData;
+ MSLLHOOKSTRUCT MouseLlData, *pMouseLlData;
+ MSG *pcMsg, *pMsg;
PMOUSEHOOKSTRUCT pMHook;
- PCWPSTRUCT pCWP;
- PCWPRETSTRUCT pCWPR;
+ CWPSTRUCT CWP, *pCWP;
+ CWPRETSTRUCT CWPR, *pCWPR;
PRECTL prl;
LPCBTACTIVATESTRUCT pcbtas;
+ WPARAM wParam = 0;
+ LPARAM lParam = 0;
+ LRESULT Result = 0;
BOOL Hit = FALSE;
Common = (PHOOKPROC_CALLBACK_ARGUMENTS) Arguments;
{
case WH_CBT:
{
+ //ERR("WH_CBT: Code %d\n", Common->Code);
switch(Common->Code)
{
case HCBT_CREATEWND:
CbtCreatewndExtra = (PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS)
((PCHAR) Common + Common->lParam);
- Csw = CbtCreatewndExtra->Cs;
- if (NULL != CbtCreatewndExtra->Cs.lpszName)
- {
- Csw.lpszName = (LPCWSTR)((PCHAR) CbtCreatewndExtra
- + (ULONG_PTR) CbtCreatewndExtra->Cs.lpszName);
- }
- if (0 != HIWORD(CbtCreatewndExtra->Cs.lpszClass))
- {
- Csw.lpszClass = (LPCWSTR)((PCHAR) CbtCreatewndExtra
- + LOWORD((ULONG_PTR) CbtCreatewndExtra->Cs.lpszClass));
- }
+ RtlCopyMemory(&Csw, &CbtCreatewndExtra->Cs, sizeof(CREATESTRUCTW));
+ CbtCreatewndw.lpcs = &Csw;
+ CbtCreatewndw.hwndInsertAfter = CbtCreatewndExtra->WndInsertAfter;
wParam = Common->wParam;
- if (Common->Ansi)
- {
- memcpy(&Csa, &Csw, sizeof(CREATESTRUCTW));
- CbtCreatewnda.lpcs = &Csa;
- CbtCreatewnda.hwndInsertAfter = CbtCreatewndExtra->WndInsertAfter;
- lParam = (LPARAM) &CbtCreatewnda;
- }
- else
- {
- CbtCreatewndw.lpcs = &Csw;
- CbtCreatewndw.hwndInsertAfter = CbtCreatewndExtra->WndInsertAfter;
- lParam = (LPARAM) &CbtCreatewndw;
- }
+ lParam = (LPARAM) &CbtCreatewndw;
+ //ERR("HCBT_CREATEWND: hWnd 0x%x Name 0x%x Class 0x%x\n", Common->wParam, Csw.lpszName, Csw.lpszClass);
break;
case HCBT_CLICKSKIPPED:
pMHook = (PMOUSEHOOKSTRUCT)((PCHAR) Common + Common->lParam);
}
else
{
- ERR("Common = 0x%x, Proc = 0x%x\n",Common,Common->Proc);
+ ERR("Null Proc! Common = 0x%x, Proc = 0x%x\n",Common,Common->Proc);
}
switch(Common->Code)
{
case HCBT_CREATEWND:
CbtCreatewndExtra->WndInsertAfter = CbtCreatewndw.hwndInsertAfter;
+ CbtCreatewndExtra->Cs.x = CbtCreatewndw.lpcs->x;
+ CbtCreatewndExtra->Cs.y = CbtCreatewndw.lpcs->y;
+ CbtCreatewndExtra->Cs.cx = CbtCreatewndw.lpcs->cx;
+ CbtCreatewndExtra->Cs.cy = CbtCreatewndw.lpcs->cy;
break;
}
break;
}
case WH_KEYBOARD_LL:
+ //ERR("WH_KEYBOARD_LL: Code %d, wParam %d\n",Common->Code,Common->wParam);
pKeyboardLlData = (PKBDLLHOOKSTRUCT)((PCHAR) Common + Common->lParam);
- Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) pKeyboardLlData);
+ RtlCopyMemory(&KeyboardLlData, pKeyboardLlData, sizeof(KBDLLHOOKSTRUCT));
+ Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) &KeyboardLlData);
break;
case WH_MOUSE_LL:
+ //ERR("WH_MOUSE_LL: Code %d, wParam %d\n",Common->Code,Common->wParam);
pMouseLlData = (PMSLLHOOKSTRUCT)((PCHAR) Common + Common->lParam);
- Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) pMouseLlData);
+ RtlCopyMemory(&MouseLlData, pMouseLlData, sizeof(MSLLHOOKSTRUCT));
+ Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) &MouseLlData);
break;
case WH_MOUSE: /* SEH support */
pMHook = (PMOUSEHOOKSTRUCT)((PCHAR) Common + Common->lParam);
_SEH2_END;
break;
case WH_CALLWNDPROC:
+// ERR("WH_CALLWNDPROC: Code %d, wParam %d\n",Common->Code,Common->wParam);
pCWP = (PCWPSTRUCT)((PCHAR) Common + Common->lParam);
- Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) pCWP);
+ RtlCopyMemory(&CWP, pCWP, sizeof(CWPSTRUCT));
+ Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) &CWP);
break;
case WH_CALLWNDPROCRET:
pCWPR = (PCWPRETSTRUCT)((PCHAR) Common + Common->lParam);
- Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) pCWPR);
+ RtlCopyMemory(&CWPR, pCWPR, sizeof(CWPRETSTRUCT));
+ Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) &CWPR);
break;
case WH_MSGFILTER: /* All SEH support */
case WH_SYSMSGFILTER:
case WH_GETMESSAGE:
pMsg = (PMSG)((PCHAR) Common + Common->lParam);
+ pcMsg = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSG));
+ RtlCopyMemory(pcMsg, pMsg, sizeof(MSG));
+// ERR("pMsg %d pcMsg %d\n",pMsg->message, pcMsg->message);
_SEH2_TRY
{
- Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) pMsg);
+ Result = Common->Proc(Common->Code, Common->wParam, (LPARAM) pcMsg);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Hit = TRUE;
}
_SEH2_END;
+ if (!Hit && Common->HookId == WH_GETMESSAGE)
+ RtlCopyMemory(pMsg, pcMsg, sizeof(MSG));
+ HeapFree( GetProcessHeap(), 0, pcMsg );
break;
- case WH_FOREGROUNDIDLE: /* <-- SEH support */
case WH_KEYBOARD:
case WH_SHELL:
+ Result = Common->Proc(Common->Code, Common->wParam, Common->lParam);
+ break;
+ case WH_FOREGROUNDIDLE: /* <-- SEH support */
_SEH2_TRY
{
Result = Common->Proc(Common->Code, Common->wParam, Common->lParam);