2002-10-29 01:41:42 +01:00
|
|
|
/*
|
|
|
|
* Windows hook functions
|
|
|
|
*
|
|
|
|
* Copyright 2002 Alexandre Julliard
|
2005-02-03 17:40:20 +01:00
|
|
|
* Copyright 2005 Dmitry Timoshkov
|
2002-10-29 01:41:42 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-10-29 01:41:42 +01:00
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
* Status of the various hooks:
|
|
|
|
* WH_MSGFILTER OK
|
|
|
|
* WH_JOURNALRECORD Partially implemented
|
|
|
|
* WH_JOURNALPLAYBACK Partially implemented
|
|
|
|
* WH_KEYBOARD OK
|
|
|
|
* WH_GETMESSAGE OK (FIXME: A/W mapping?)
|
|
|
|
* WH_CALLWNDPROC OK (FIXME: A/W mapping?)
|
|
|
|
* WH_CBT
|
|
|
|
* HCBT_MOVESIZE OK
|
|
|
|
* HCBT_MINMAX OK
|
|
|
|
* HCBT_QS OK
|
|
|
|
* HCBT_CREATEWND OK
|
|
|
|
* HCBT_DESTROYWND OK
|
|
|
|
* HCBT_ACTIVATE OK
|
|
|
|
* HCBT_CLICKSKIPPED OK
|
|
|
|
* HCBT_KEYSKIPPED OK
|
2004-12-08 14:38:25 +01:00
|
|
|
* HCBT_SYSCOMMAND OK
|
2002-10-29 01:41:42 +01:00
|
|
|
* HCBT_SETFOCUS OK
|
|
|
|
* WH_SYSMSGFILTER OK
|
|
|
|
* WH_MOUSE OK
|
|
|
|
* WH_HARDWARE Not supported in Win32
|
|
|
|
* WH_DEBUG Not implemented
|
|
|
|
* WH_SHELL
|
|
|
|
* HSHELL_WINDOWCREATED OK
|
|
|
|
* HSHELL_WINDOWDESTROYED OK
|
|
|
|
* HSHELL_ACTIVATESHELLWINDOW Not implemented
|
|
|
|
* HSHELL_WINDOWACTIVATED Not implemented
|
|
|
|
* HSHELL_GETMINRECT Not implemented
|
|
|
|
* HSHELL_REDRAW Not implemented
|
|
|
|
* HSHELL_TASKMAN Not implemented
|
|
|
|
* HSHELL_LANGUAGE Not implemented
|
|
|
|
* HSHELL_SYSMENU Not implemented
|
|
|
|
* HSHELL_ENDTASK Not implemented
|
|
|
|
* HSHELL_ACCESSIBILITYSTATE Not implemented
|
|
|
|
* HSHELL_APPCOMMAND Not implemented
|
|
|
|
* HSHELL_WINDOWREPLACED Not implemented
|
|
|
|
* HSHELL_WINDOWREPLACING Not implemented
|
|
|
|
* WH_FOREGROUNDIDLE Not implemented
|
|
|
|
* WH_CALLWNDPROCRET OK (FIXME: A/W mapping?)
|
|
|
|
* WH_KEYBOARD_LL Implemented but should use SendMessage instead
|
|
|
|
* WH_MOUSE_LL Implemented but should use SendMessage instead
|
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2005-02-03 17:40:20 +01:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2020-09-21 13:53:21 +02:00
|
|
|
#include "winnls.h"
|
2012-09-27 18:13:01 +02:00
|
|
|
#include "wingdi.h"
|
2002-10-29 01:41:42 +01:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "win.h"
|
2004-12-08 19:06:14 +01:00
|
|
|
#include "user_private.h"
|
2002-10-29 01:41:42 +01:00
|
|
|
#include "wine/server.h"
|
2019-05-14 12:30:46 +02:00
|
|
|
#include "wine/asm.h"
|
2002-10-29 01:41:42 +01:00
|
|
|
#include "wine/debug.h"
|
2003-01-24 00:07:38 +01:00
|
|
|
#include "winternl.h"
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(hook);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
|
|
|
|
2005-02-03 17:40:20 +01:00
|
|
|
struct hook_info
|
|
|
|
{
|
2006-10-04 07:06:30 +02:00
|
|
|
INT id;
|
2009-09-09 13:12:38 +02:00
|
|
|
void *proc;
|
2005-02-03 17:40:20 +01:00
|
|
|
void *handle;
|
2006-10-04 07:06:30 +02:00
|
|
|
DWORD pid, tid;
|
|
|
|
BOOL prev_unicode, next_unicode;
|
2005-02-03 17:40:20 +01:00
|
|
|
WCHAR module[MAX_PATH];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define WH_WINEVENT (WH_MAXHOOK+1)
|
|
|
|
|
|
|
|
static const char * const hook_names[WH_WINEVENT - WH_MINHOOK + 1] =
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
"WH_MSGFILTER",
|
|
|
|
"WH_JOURNALRECORD",
|
|
|
|
"WH_JOURNALPLAYBACK",
|
|
|
|
"WH_KEYBOARD",
|
|
|
|
"WH_GETMESSAGE",
|
|
|
|
"WH_CALLWNDPROC",
|
|
|
|
"WH_CBT",
|
|
|
|
"WH_SYSMSGFILTER",
|
|
|
|
"WH_MOUSE",
|
|
|
|
"WH_HARDWARE",
|
|
|
|
"WH_DEBUG",
|
|
|
|
"WH_SHELL",
|
|
|
|
"WH_FOREGROUNDIDLE",
|
|
|
|
"WH_CALLWNDPROCRET",
|
|
|
|
"WH_KEYBOARD_LL",
|
2005-02-03 17:40:20 +01:00
|
|
|
"WH_MOUSE_LL",
|
|
|
|
"WH_WINEVENT"
|
2002-10-29 01:41:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-07-11 23:55:58 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_ll_hook_timeout
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static UINT get_ll_hook_timeout(void)
|
|
|
|
{
|
|
|
|
/* FIXME: should retrieve LowLevelHooksTimeout in HKEY_CURRENT_USER\Control Panel\Desktop */
|
|
|
|
return 2000;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* set_windows_hook
|
|
|
|
*
|
|
|
|
* Implementation of SetWindowsHookExA and SetWindowsHookExW.
|
|
|
|
*/
|
|
|
|
static HHOOK set_windows_hook( INT id, HOOKPROC proc, HINSTANCE inst, DWORD tid, BOOL unicode )
|
|
|
|
{
|
|
|
|
HHOOK handle = 0;
|
2002-11-20 20:54:32 +01:00
|
|
|
WCHAR module[MAX_PATH];
|
2004-05-19 05:22:55 +02:00
|
|
|
DWORD len;
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2005-01-27 12:14:19 +01:00
|
|
|
if (!proc)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_FILTER_PROC );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
if (tid) /* thread-local hook */
|
|
|
|
{
|
|
|
|
if (id == WH_JOURNALRECORD ||
|
|
|
|
id == WH_JOURNALPLAYBACK ||
|
|
|
|
id == WH_KEYBOARD_LL ||
|
|
|
|
id == WH_MOUSE_LL ||
|
|
|
|
id == WH_SYSMSGFILTER)
|
|
|
|
{
|
|
|
|
/* these can only be global */
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* system-global hook */
|
|
|
|
{
|
2003-07-11 23:55:58 +02:00
|
|
|
if (id == WH_KEYBOARD_LL || id == WH_MOUSE_LL) inst = 0;
|
2007-08-22 11:59:21 +02:00
|
|
|
else if (!inst)
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
2005-01-27 12:14:19 +01:00
|
|
|
SetLastError( ERROR_HOOK_NEEDS_HMOD );
|
2002-10-29 01:41:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-22 11:59:21 +02:00
|
|
|
if (inst && (!(len = GetModuleFileNameW( inst, module, MAX_PATH )) || len >= MAX_PATH))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
SERVER_START_REQ( set_hook )
|
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
req->id = id;
|
|
|
|
req->pid = 0;
|
|
|
|
req->tid = tid;
|
|
|
|
req->event_min = EVENT_MIN;
|
|
|
|
req->event_max = EVENT_MAX;
|
|
|
|
req->flags = WINEVENT_INCONTEXT;
|
|
|
|
req->unicode = unicode;
|
2002-11-20 20:54:32 +01:00
|
|
|
if (inst) /* make proc relative to the module base */
|
|
|
|
{
|
2008-12-29 17:35:35 +01:00
|
|
|
req->proc = wine_server_client_ptr( (void *)((char *)proc - (char *)inst) );
|
2020-09-21 13:53:21 +02:00
|
|
|
wine_server_add_data( req, module, lstrlenW(module) * sizeof(WCHAR) );
|
2002-11-20 20:54:32 +01:00
|
|
|
}
|
2008-12-29 17:35:35 +01:00
|
|
|
else req->proc = wine_server_client_ptr( proc );
|
2002-11-20 20:54:32 +01:00
|
|
|
|
2005-05-11 15:03:15 +02:00
|
|
|
if (!wine_server_call_err( req ))
|
|
|
|
{
|
2008-12-08 16:58:20 +01:00
|
|
|
handle = wine_server_ptr_handle( reply->handle );
|
2005-05-11 15:03:15 +02:00
|
|
|
get_user_thread_info()->active_hooks = reply->active_hooks;
|
|
|
|
}
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE( "%s %p %x -> %p\n", hook_names[id-WH_MINHOOK], proc, tid, handle );
|
2002-10-29 01:41:42 +01:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2013-04-24 17:15:56 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
/* Some apps pass a non-stdcall proc to SetWindowsHookExA,
|
|
|
|
* so we need a small assembly wrapper to call the proc.
|
|
|
|
*/
|
|
|
|
extern LRESULT HOOKPROC_wrapper( HOOKPROC proc,
|
|
|
|
INT code, WPARAM wParam, LPARAM lParam );
|
|
|
|
__ASM_GLOBAL_FUNC( HOOKPROC_wrapper,
|
|
|
|
"pushl %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
|
|
|
"movl %esp,%ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
|
|
|
"pushl %edi\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
|
|
|
|
"pushl %esi\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
|
|
|
|
"pushl %ebx\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebx,-12\n\t")
|
|
|
|
"pushl 20(%ebp)\n\t"
|
|
|
|
"pushl 16(%ebp)\n\t"
|
|
|
|
"pushl 12(%ebp)\n\t"
|
|
|
|
"movl 8(%ebp),%eax\n\t"
|
|
|
|
"call *%eax\n\t"
|
|
|
|
"leal -12(%ebp),%esp\n\t"
|
|
|
|
"popl %ebx\n\t"
|
|
|
|
__ASM_CFI(".cfi_same_value %ebx\n\t")
|
|
|
|
"popl %esi\n\t"
|
|
|
|
__ASM_CFI(".cfi_same_value %esi\n\t")
|
|
|
|
"popl %edi\n\t"
|
|
|
|
__ASM_CFI(".cfi_same_value %edi\n\t")
|
|
|
|
"leave\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
|
|
|
"ret" )
|
|
|
|
#else
|
|
|
|
static inline LRESULT HOOKPROC_wrapper( HOOKPROC proc,
|
|
|
|
INT code, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
|
|
|
return proc( code, wParam, lParam );
|
|
|
|
}
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* call_hook_AtoW
|
|
|
|
*/
|
|
|
|
static LRESULT call_hook_AtoW( HOOKPROC proc, INT id, INT code, WPARAM wparam, LPARAM lparam )
|
|
|
|
{
|
|
|
|
LRESULT ret;
|
2003-01-24 00:07:38 +01:00
|
|
|
UNICODE_STRING usBuffer;
|
2013-04-24 17:15:56 +02:00
|
|
|
if (id != WH_CBT || code != HCBT_CREATEWND)
|
|
|
|
ret = HOOKPROC_wrapper( proc, code, wparam, lparam );
|
2002-10-29 01:41:42 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CBT_CREATEWNDA *cbtcwA = (CBT_CREATEWNDA *)lparam;
|
|
|
|
CBT_CREATEWNDW cbtcwW;
|
|
|
|
CREATESTRUCTW csW;
|
2006-11-18 15:23:01 +01:00
|
|
|
LPWSTR nameW = NULL;
|
|
|
|
LPWSTR classW = NULL;
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
cbtcwW.lpcs = &csW;
|
|
|
|
cbtcwW.hwndInsertAfter = cbtcwA->hwndInsertAfter;
|
|
|
|
csW = *(CREATESTRUCTW *)cbtcwA->lpcs;
|
|
|
|
|
2010-02-03 21:04:27 +01:00
|
|
|
if (!IS_INTRESOURCE(cbtcwA->lpcs->lpszName))
|
2003-01-24 00:07:38 +01:00
|
|
|
{
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&usBuffer,cbtcwA->lpcs->lpszName);
|
2006-11-18 15:23:01 +01:00
|
|
|
csW.lpszName = nameW = usBuffer.Buffer;
|
2003-01-24 00:07:38 +01:00
|
|
|
}
|
2010-02-03 21:04:27 +01:00
|
|
|
if (!IS_INTRESOURCE(cbtcwA->lpcs->lpszClass))
|
2003-01-24 00:07:38 +01:00
|
|
|
{
|
2003-10-15 22:50:38 +02:00
|
|
|
RtlCreateUnicodeStringFromAsciiz(&usBuffer,cbtcwA->lpcs->lpszClass);
|
2006-11-18 15:23:01 +01:00
|
|
|
csW.lpszClass = classW = usBuffer.Buffer;
|
2003-01-24 00:07:38 +01:00
|
|
|
}
|
2013-04-24 17:15:56 +02:00
|
|
|
ret = HOOKPROC_wrapper( proc, code, wparam, (LPARAM)&cbtcwW );
|
2002-10-29 01:41:42 +01:00
|
|
|
cbtcwA->hwndInsertAfter = cbtcwW.hwndInsertAfter;
|
2006-11-18 15:23:01 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, nameW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, classW );
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* call_hook_WtoA
|
|
|
|
*/
|
|
|
|
static LRESULT call_hook_WtoA( HOOKPROC proc, INT id, INT code, WPARAM wparam, LPARAM lparam )
|
|
|
|
{
|
|
|
|
LRESULT ret;
|
|
|
|
|
2013-04-24 17:15:56 +02:00
|
|
|
if (id != WH_CBT || code != HCBT_CREATEWND)
|
|
|
|
ret = HOOKPROC_wrapper( proc, code, wparam, lparam );
|
2002-10-29 01:41:42 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CBT_CREATEWNDW *cbtcwW = (CBT_CREATEWNDW *)lparam;
|
|
|
|
CBT_CREATEWNDA cbtcwA;
|
|
|
|
CREATESTRUCTA csA;
|
2005-01-03 17:07:37 +01:00
|
|
|
int len;
|
2006-11-18 15:23:01 +01:00
|
|
|
LPSTR nameA = NULL;
|
|
|
|
LPSTR classA = NULL;
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
cbtcwA.lpcs = &csA;
|
|
|
|
cbtcwA.hwndInsertAfter = cbtcwW->hwndInsertAfter;
|
|
|
|
csA = *(CREATESTRUCTA *)cbtcwW->lpcs;
|
|
|
|
|
2010-02-03 21:04:27 +01:00
|
|
|
if (!IS_INTRESOURCE(cbtcwW->lpcs->lpszName)) {
|
2005-01-03 17:07:37 +01:00
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, cbtcwW->lpcs->lpszName, -1, NULL, 0, NULL, NULL );
|
2006-11-18 15:23:01 +01:00
|
|
|
nameA = HeapAlloc( GetProcessHeap(), 0, len*sizeof(CHAR) );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, cbtcwW->lpcs->lpszName, -1, nameA, len, NULL, NULL );
|
|
|
|
csA.lpszName = nameA;
|
2005-01-03 17:07:37 +01:00
|
|
|
}
|
|
|
|
|
2010-02-03 21:04:27 +01:00
|
|
|
if (!IS_INTRESOURCE(cbtcwW->lpcs->lpszClass)) {
|
2005-01-03 17:07:37 +01:00
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, cbtcwW->lpcs->lpszClass, -1, NULL, 0, NULL, NULL );
|
2006-11-18 15:23:01 +01:00
|
|
|
classA = HeapAlloc( GetProcessHeap(), 0, len*sizeof(CHAR) );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, cbtcwW->lpcs->lpszClass, -1, classA, len, NULL, NULL );
|
|
|
|
csA.lpszClass = classA;
|
2005-01-03 17:07:37 +01:00
|
|
|
}
|
|
|
|
|
2013-04-24 17:15:56 +02:00
|
|
|
ret = HOOKPROC_wrapper( proc, code, wparam, (LPARAM)&cbtcwA );
|
2002-10-29 01:41:42 +01:00
|
|
|
cbtcwW->hwndInsertAfter = cbtcwA.hwndInsertAfter;
|
2006-11-18 15:23:01 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, nameA );
|
|
|
|
HeapFree( GetProcessHeap(), 0, classA );
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-10-04 07:06:30 +02:00
|
|
|
* call_hook_proc
|
2002-10-29 01:41:42 +01:00
|
|
|
*/
|
2006-10-04 07:06:30 +02:00
|
|
|
static LRESULT call_hook_proc( HOOKPROC proc, INT id, INT code, WPARAM wparam, LPARAM lparam,
|
|
|
|
BOOL prev_unicode, BOOL next_unicode )
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
LRESULT ret;
|
|
|
|
|
2017-11-25 11:48:02 +01:00
|
|
|
TRACE_(relay)( "\1Call hook proc %p (id=%s,code=%x,wp=%08lx,lp=%08lx)\n",
|
|
|
|
proc, hook_names[id-WH_MINHOOK], code, wparam, lparam );
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
if (!prev_unicode == !next_unicode) ret = proc( code, wparam, lparam );
|
|
|
|
else if (prev_unicode) ret = call_hook_WtoA( proc, id, code, wparam, lparam );
|
|
|
|
else ret = call_hook_AtoW( proc, id, code, wparam, lparam );
|
|
|
|
|
2017-11-25 11:48:02 +01:00
|
|
|
TRACE_(relay)( "\1Ret hook proc %p (id=%s,code=%x,wp=%08lx,lp=%08lx) retval=%08lx\n",
|
|
|
|
proc, hook_names[id-WH_MINHOOK], code, wparam, lparam, ret );
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-20 20:54:32 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* get_hook_proc
|
|
|
|
*
|
|
|
|
* Retrieve the hook procedure real value for a module-relative proc
|
|
|
|
*/
|
2014-06-13 20:35:41 +02:00
|
|
|
void *get_hook_proc( void *proc, const WCHAR *module, HMODULE *free_module )
|
2002-11-20 20:54:32 +01:00
|
|
|
{
|
|
|
|
HMODULE mod;
|
|
|
|
|
2014-06-13 20:35:41 +02:00
|
|
|
GetModuleHandleExW( 0, module, &mod );
|
|
|
|
*free_module = mod;
|
|
|
|
if (!mod)
|
2002-11-20 20:54:32 +01:00
|
|
|
{
|
|
|
|
TRACE( "loading %s\n", debugstr_w(module) );
|
|
|
|
/* FIXME: the library will never be freed */
|
2009-08-27 03:18:14 +02:00
|
|
|
if (!(mod = LoadLibraryExW(module, NULL, LOAD_WITH_ALTERED_SEARCH_PATH))) return NULL;
|
2002-11-20 20:54:32 +01:00
|
|
|
}
|
2005-02-03 17:40:20 +01:00
|
|
|
return (char *)mod + (ULONG_PTR)proc;
|
2002-11-20 20:54:32 +01:00
|
|
|
}
|
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
/***********************************************************************
|
2006-10-04 07:06:30 +02:00
|
|
|
* call_hook
|
|
|
|
*
|
|
|
|
* Call hook either in current thread or send message to the destination
|
|
|
|
* thread.
|
2002-10-29 01:41:42 +01:00
|
|
|
*/
|
2006-10-04 07:06:30 +02:00
|
|
|
static LRESULT call_hook( struct hook_info *info, INT code, WPARAM wparam, LPARAM lparam )
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
2005-07-06 12:36:28 +02:00
|
|
|
DWORD_PTR ret = 0;
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2006-10-04 07:06:30 +02:00
|
|
|
if (info->tid)
|
2003-07-11 23:55:58 +02:00
|
|
|
{
|
2006-10-05 05:27:09 +02:00
|
|
|
struct hook_extra_info h_extra;
|
|
|
|
h_extra.handle = info->handle;
|
|
|
|
h_extra.lparam = lparam;
|
|
|
|
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE( "calling hook in thread %04x %s code %x wp %lx lp %lx\n",
|
2006-10-04 07:06:30 +02:00
|
|
|
info->tid, hook_names[info->id-WH_MINHOOK], code, wparam, lparam );
|
2003-07-11 23:55:58 +02:00
|
|
|
|
2006-10-04 07:06:30 +02:00
|
|
|
switch(info->id)
|
2003-07-11 23:55:58 +02:00
|
|
|
{
|
|
|
|
case WH_KEYBOARD_LL:
|
2006-10-05 05:27:09 +02:00
|
|
|
MSG_SendInternalMessageTimeout( info->pid, info->tid, WM_WINE_KEYBOARD_LL_HOOK,
|
|
|
|
wparam, (LPARAM)&h_extra, SMTO_ABORTIFHUNG,
|
|
|
|
get_ll_hook_timeout(), &ret );
|
2003-07-11 23:55:58 +02:00
|
|
|
break;
|
|
|
|
case WH_MOUSE_LL:
|
2006-10-05 05:27:09 +02:00
|
|
|
MSG_SendInternalMessageTimeout( info->pid, info->tid, WM_WINE_MOUSE_LL_HOOK,
|
|
|
|
wparam, (LPARAM)&h_extra, SMTO_ABORTIFHUNG,
|
|
|
|
get_ll_hook_timeout(), &ret );
|
2003-07-11 23:55:58 +02:00
|
|
|
break;
|
2005-02-03 17:40:20 +01:00
|
|
|
default:
|
2006-10-04 07:06:30 +02:00
|
|
|
ERR("Unknown hook id %d\n", info->id);
|
2005-02-03 17:40:20 +01:00
|
|
|
assert(0);
|
|
|
|
break;
|
2003-07-11 23:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-04 07:06:30 +02:00
|
|
|
else if (info->proc)
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
2015-06-26 19:37:41 +02:00
|
|
|
struct user_thread_info *thread_info = get_user_thread_info();
|
2014-06-13 20:35:41 +02:00
|
|
|
HMODULE free_module = 0;
|
2015-06-26 19:37:41 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Windows protects from stack overflow in recursive hook calls. Different Windows
|
|
|
|
* allow different depths.
|
|
|
|
*/
|
|
|
|
if (thread_info->hook_call_depth >= 25)
|
|
|
|
{
|
|
|
|
WARN("Too many hooks called recursively, skipping call.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE( "calling hook %p %s code %x wp %lx lp %lx module %s\n",
|
2006-10-04 07:06:30 +02:00
|
|
|
info->proc, hook_names[info->id-WH_MINHOOK], code, wparam,
|
|
|
|
lparam, debugstr_w(info->module) );
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2006-10-04 07:06:30 +02:00
|
|
|
if (!info->module[0] ||
|
2014-06-13 20:35:41 +02:00
|
|
|
(info->proc = get_hook_proc( info->proc, info->module, &free_module )) != NULL)
|
2002-11-20 20:54:32 +01:00
|
|
|
{
|
2005-04-27 10:18:20 +02:00
|
|
|
HHOOK prev = thread_info->hook;
|
2006-10-05 14:04:25 +02:00
|
|
|
BOOL prev_unicode = thread_info->hook_unicode;
|
2006-10-04 07:06:30 +02:00
|
|
|
|
|
|
|
thread_info->hook = info->handle;
|
2006-10-05 14:04:25 +02:00
|
|
|
thread_info->hook_unicode = info->next_unicode;
|
2015-06-26 19:37:41 +02:00
|
|
|
thread_info->hook_call_depth++;
|
2009-03-02 10:24:30 +01:00
|
|
|
ret = call_hook_proc( info->proc, info->id, code, wparam, lparam,
|
2006-10-04 07:06:30 +02:00
|
|
|
info->prev_unicode, info->next_unicode );
|
2005-04-27 10:18:20 +02:00
|
|
|
thread_info->hook = prev;
|
2006-10-05 14:04:25 +02:00
|
|
|
thread_info->hook_unicode = prev_unicode;
|
2015-06-26 19:37:41 +02:00
|
|
|
thread_info->hook_call_depth--;
|
2014-06-13 20:35:41 +02:00
|
|
|
|
|
|
|
if (free_module) FreeLibrary(free_module);
|
2002-11-20 20:54:32 +01:00
|
|
|
}
|
2006-10-04 07:06:30 +02:00
|
|
|
}
|
2011-12-15 14:30:41 +01:00
|
|
|
|
|
|
|
if (info->id == WH_KEYBOARD_LL || info->id == WH_MOUSE_LL)
|
2020-05-02 15:10:10 +02:00
|
|
|
InterlockedIncrement( &global_key_state_counter ); /* force refreshing the key state cache */
|
2011-12-15 14:30:41 +01:00
|
|
|
|
2006-10-04 07:06:30 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-22 17:44:37 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HOOK_IsHooked
|
|
|
|
*/
|
|
|
|
static BOOL HOOK_IsHooked( INT id )
|
|
|
|
{
|
|
|
|
struct user_thread_info *thread_info = get_user_thread_info();
|
|
|
|
|
|
|
|
if (!thread_info->active_hooks) return TRUE;
|
|
|
|
return (thread_info->active_hooks & (1 << (id - WH_MINHOOK))) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-04 07:06:30 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HOOK_CallHooks
|
|
|
|
*/
|
|
|
|
LRESULT HOOK_CallHooks( INT id, INT code, WPARAM wparam, LPARAM lparam, BOOL unicode )
|
|
|
|
{
|
|
|
|
struct user_thread_info *thread_info = get_user_thread_info();
|
|
|
|
struct hook_info info;
|
2015-11-06 05:00:42 +01:00
|
|
|
DWORD_PTR ret;
|
2006-10-04 07:06:30 +02:00
|
|
|
|
|
|
|
USER_CheckNotLock();
|
|
|
|
|
|
|
|
if (!HOOK_IsHooked( id ))
|
|
|
|
{
|
|
|
|
TRACE( "skipping hook %s mask %x\n", hook_names[id-WH_MINHOOK], thread_info->active_hooks );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZeroMemory( &info, sizeof(info) - sizeof(info.module) );
|
|
|
|
info.prev_unicode = unicode;
|
|
|
|
info.id = id;
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2006-10-04 07:06:30 +02:00
|
|
|
SERVER_START_REQ( start_hook_chain )
|
|
|
|
{
|
|
|
|
req->id = info.id;
|
|
|
|
req->event = EVENT_MIN;
|
|
|
|
wine_server_set_reply( req, info.module, sizeof(info.module)-sizeof(WCHAR) );
|
|
|
|
if (!wine_server_call( req ))
|
|
|
|
{
|
|
|
|
info.module[wine_server_reply_size(req) / sizeof(WCHAR)] = 0;
|
2008-12-08 16:58:20 +01:00
|
|
|
info.handle = wine_server_ptr_handle( reply->handle );
|
2006-10-04 07:06:30 +02:00
|
|
|
info.pid = reply->pid;
|
|
|
|
info.tid = reply->tid;
|
2008-12-29 17:35:35 +01:00
|
|
|
info.proc = wine_server_get_ptr( reply->proc );
|
2006-10-04 07:06:30 +02:00
|
|
|
info.next_unicode = reply->unicode;
|
|
|
|
thread_info->active_hooks = reply->active_hooks;
|
|
|
|
}
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
2006-10-04 07:06:30 +02:00
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (!info.tid && !info.proc) return 0;
|
|
|
|
ret = call_hook( &info, code, wparam, lparam );
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2003-07-11 23:55:58 +02:00
|
|
|
SERVER_START_REQ( finish_hook_chain )
|
|
|
|
{
|
|
|
|
req->id = id;
|
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2002-10-29 01:41:42 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetWindowsHookA (USER32.@)
|
|
|
|
*/
|
|
|
|
HHOOK WINAPI SetWindowsHookA( INT id, HOOKPROC proc )
|
|
|
|
{
|
|
|
|
return SetWindowsHookExA( id, proc, 0, GetCurrentThreadId() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetWindowsHookW (USER32.@)
|
|
|
|
*/
|
|
|
|
HHOOK WINAPI SetWindowsHookW( INT id, HOOKPROC proc )
|
|
|
|
{
|
|
|
|
return SetWindowsHookExW( id, proc, 0, GetCurrentThreadId() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetWindowsHookExA (USER32.@)
|
|
|
|
*/
|
|
|
|
HHOOK WINAPI SetWindowsHookExA( INT id, HOOKPROC proc, HINSTANCE inst, DWORD tid )
|
|
|
|
{
|
|
|
|
return set_windows_hook( id, proc, inst, tid, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetWindowsHookExW (USER32.@)
|
|
|
|
*/
|
|
|
|
HHOOK WINAPI SetWindowsHookExW( INT id, HOOKPROC proc, HINSTANCE inst, DWORD tid )
|
|
|
|
{
|
|
|
|
return set_windows_hook( id, proc, inst, tid, TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnhookWindowsHook (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI UnhookWindowsHook( INT id, HOOKPROC proc )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE( "%s %p\n", hook_names[id-WH_MINHOOK], proc );
|
|
|
|
|
|
|
|
SERVER_START_REQ( remove_hook )
|
|
|
|
{
|
2002-11-24 23:15:01 +01:00
|
|
|
req->handle = 0;
|
2002-10-29 01:41:42 +01:00
|
|
|
req->id = id;
|
2008-12-29 17:35:35 +01:00
|
|
|
req->proc = wine_server_client_ptr( proc );
|
2002-10-29 01:41:42 +01:00
|
|
|
ret = !wine_server_call_err( req );
|
2005-05-11 15:03:15 +02:00
|
|
|
if (ret) get_user_thread_info()->active_hooks = reply->active_hooks;
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2005-02-03 17:40:20 +01:00
|
|
|
if (!ret && GetLastError() == ERROR_INVALID_HANDLE) SetLastError( ERROR_INVALID_HOOK_HANDLE );
|
2002-10-29 01:41:42 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnhookWindowsHookEx (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI UnhookWindowsHookEx( HHOOK hhook )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
SERVER_START_REQ( remove_hook )
|
|
|
|
{
|
2008-12-08 16:58:20 +01:00
|
|
|
req->handle = wine_server_user_handle( hhook );
|
2005-02-03 17:40:20 +01:00
|
|
|
req->id = 0;
|
2002-10-29 01:41:42 +01:00
|
|
|
ret = !wine_server_call_err( req );
|
2005-05-11 15:03:15 +02:00
|
|
|
if (ret) get_user_thread_info()->active_hooks = reply->active_hooks;
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2005-02-03 17:40:20 +01:00
|
|
|
if (!ret && GetLastError() == ERROR_INVALID_HANDLE) SetLastError( ERROR_INVALID_HOOK_HANDLE );
|
2002-10-29 01:41:42 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CallNextHookEx (USER32.@)
|
|
|
|
*/
|
|
|
|
LRESULT WINAPI CallNextHookEx( HHOOK hhook, INT code, WPARAM wparam, LPARAM lparam )
|
|
|
|
{
|
2005-04-27 10:18:20 +02:00
|
|
|
struct user_thread_info *thread_info = get_user_thread_info();
|
2006-10-04 07:06:30 +02:00
|
|
|
struct hook_info info;
|
|
|
|
|
|
|
|
ZeroMemory( &info, sizeof(info) - sizeof(info.module) );
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2006-10-05 14:05:48 +02:00
|
|
|
SERVER_START_REQ( get_hook_info )
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
2008-12-08 16:58:20 +01:00
|
|
|
req->handle = wine_server_user_handle( thread_info->hook );
|
2006-10-05 14:05:48 +02:00
|
|
|
req->get_next = 1;
|
2005-02-03 17:40:20 +01:00
|
|
|
req->event = EVENT_MIN;
|
2006-10-04 07:06:30 +02:00
|
|
|
wine_server_set_reply( req, info.module, sizeof(info.module)-sizeof(WCHAR) );
|
2002-10-29 01:41:42 +01:00
|
|
|
if (!wine_server_call_err( req ))
|
|
|
|
{
|
2006-10-04 07:06:30 +02:00
|
|
|
info.module[wine_server_reply_size(req) / sizeof(WCHAR)] = 0;
|
2008-12-08 16:58:20 +01:00
|
|
|
info.handle = wine_server_ptr_handle( reply->handle );
|
2006-10-04 07:06:30 +02:00
|
|
|
info.id = reply->id;
|
|
|
|
info.pid = reply->pid;
|
|
|
|
info.tid = reply->tid;
|
2008-12-29 17:35:35 +01:00
|
|
|
info.proc = wine_server_get_ptr( reply->proc );
|
2006-10-05 14:04:25 +02:00
|
|
|
info.next_unicode = reply->unicode;
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2002-11-20 20:54:32 +01:00
|
|
|
|
2006-10-05 14:04:25 +02:00
|
|
|
info.prev_unicode = thread_info->hook_unicode;
|
2006-10-04 07:06:30 +02:00
|
|
|
return call_hook( &info, code, wparam, lparam );
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-05 05:27:09 +02:00
|
|
|
LRESULT call_current_hook( HHOOK hhook, INT code, WPARAM wparam, LPARAM lparam )
|
|
|
|
{
|
|
|
|
struct hook_info info;
|
|
|
|
|
|
|
|
ZeroMemory( &info, sizeof(info) - sizeof(info.module) );
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_hook_info )
|
|
|
|
{
|
2008-12-08 16:58:20 +01:00
|
|
|
req->handle = wine_server_user_handle( hhook );
|
2006-10-05 05:27:09 +02:00
|
|
|
req->get_next = 0;
|
|
|
|
req->event = EVENT_MIN;
|
|
|
|
wine_server_set_reply( req, info.module, sizeof(info.module)-sizeof(WCHAR) );
|
|
|
|
if (!wine_server_call_err( req ))
|
|
|
|
{
|
|
|
|
info.module[wine_server_reply_size(req) / sizeof(WCHAR)] = 0;
|
2008-12-08 16:58:20 +01:00
|
|
|
info.handle = wine_server_ptr_handle( reply->handle );
|
2006-10-05 05:27:09 +02:00
|
|
|
info.id = reply->id;
|
|
|
|
info.pid = reply->pid;
|
|
|
|
info.tid = reply->tid;
|
2008-12-29 17:35:35 +01:00
|
|
|
info.proc = wine_server_get_ptr( reply->proc );
|
2006-10-05 05:27:09 +02:00
|
|
|
info.next_unicode = reply->unicode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
info.prev_unicode = TRUE; /* assume Unicode for this function */
|
|
|
|
return call_hook( &info, code, wparam, lparam );
|
|
|
|
}
|
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* CallMsgFilterA (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CallMsgFilterA( LPMSG msg, INT code )
|
|
|
|
{
|
|
|
|
if (HOOK_CallHooks( WH_SYSMSGFILTER, code, 0, (LPARAM)msg, FALSE )) return TRUE;
|
|
|
|
return HOOK_CallHooks( WH_MSGFILTER, code, 0, (LPARAM)msg, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CallMsgFilterW (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CallMsgFilterW( LPMSG msg, INT code )
|
|
|
|
{
|
|
|
|
if (HOOK_CallHooks( WH_SYSMSGFILTER, code, 0, (LPARAM)msg, TRUE )) return TRUE;
|
|
|
|
return HOOK_CallHooks( WH_MSGFILTER, code, 0, (LPARAM)msg, TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetWinEventHook [USER32.@]
|
|
|
|
*
|
|
|
|
* Set up an event hook for a set of events.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2005-02-03 17:40:20 +01:00
|
|
|
* event_min [I] Lowest event handled by pfnProc
|
|
|
|
* event_max [I] Highest event handled by pfnProc
|
|
|
|
* inst [I] DLL containing pfnProc
|
|
|
|
* proc [I] Callback event hook function
|
|
|
|
* pid [I] Process to get events from, or 0 for all processes
|
|
|
|
* tid [I] Thread to get events from, or 0 for all threads
|
|
|
|
* flags [I] Flags indicating the status of pfnProc
|
2002-10-29 01:41:42 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A handle representing the hook.
|
|
|
|
* Failure: A NULL handle.
|
|
|
|
*/
|
2005-02-03 17:40:20 +01:00
|
|
|
HWINEVENTHOOK WINAPI SetWinEventHook(DWORD event_min, DWORD event_max,
|
|
|
|
HMODULE inst, WINEVENTPROC proc,
|
|
|
|
DWORD pid, DWORD tid, DWORD flags)
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
HWINEVENTHOOK handle = 0;
|
|
|
|
WCHAR module[MAX_PATH];
|
|
|
|
DWORD len;
|
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("%d,%d,%p,%p,%08x,%04x,%08x\n", event_min, event_max, inst,
|
2005-02-03 17:40:20 +01:00
|
|
|
proc, pid, tid, flags);
|
|
|
|
|
|
|
|
if (inst)
|
|
|
|
{
|
|
|
|
if (!(len = GetModuleFileNameW(inst, module, MAX_PATH)) || len >= MAX_PATH)
|
|
|
|
inst = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & WINEVENT_INCONTEXT) && !inst)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_HOOK_NEEDS_HMOD);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event_min > event_max)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HOOK_FILTER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: what if the tid or pid belongs to another process? */
|
|
|
|
if (tid) /* thread-local hook */
|
|
|
|
inst = 0;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_hook )
|
|
|
|
{
|
|
|
|
req->id = WH_WINEVENT;
|
|
|
|
req->pid = pid;
|
|
|
|
req->tid = tid;
|
|
|
|
req->event_min = event_min;
|
|
|
|
req->event_max = event_max;
|
|
|
|
req->flags = flags;
|
|
|
|
req->unicode = 1;
|
|
|
|
if (inst) /* make proc relative to the module base */
|
|
|
|
{
|
2008-12-29 17:35:35 +01:00
|
|
|
req->proc = wine_server_client_ptr( (void *)((char *)proc - (char *)inst) );
|
2020-09-21 13:53:21 +02:00
|
|
|
wine_server_add_data( req, module, lstrlenW(module) * sizeof(WCHAR) );
|
2005-02-03 17:40:20 +01:00
|
|
|
}
|
2008-12-29 17:35:35 +01:00
|
|
|
else req->proc = wine_server_client_ptr( proc );
|
2005-02-03 17:40:20 +01:00
|
|
|
|
2005-05-11 15:03:15 +02:00
|
|
|
if (!wine_server_call_err( req ))
|
|
|
|
{
|
2008-12-08 16:58:20 +01:00
|
|
|
handle = wine_server_ptr_handle( reply->handle );
|
2005-05-11 15:03:15 +02:00
|
|
|
get_user_thread_info()->active_hooks = reply->active_hooks;
|
|
|
|
}
|
2005-02-03 17:40:20 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
TRACE("-> %p\n", handle);
|
|
|
|
return handle;
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnhookWinEvent [USER32.@]
|
|
|
|
*
|
|
|
|
* Remove an event hook for a set of events.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hEventHook [I] Event hook to remove
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE. The event hook has been removed.
|
|
|
|
* Failure: FALSE, if hEventHook is invalid.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI UnhookWinEvent(HWINEVENTHOOK hEventHook)
|
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
SERVER_START_REQ( remove_hook )
|
|
|
|
{
|
2008-12-08 16:58:20 +01:00
|
|
|
req->handle = wine_server_user_handle( hEventHook );
|
2005-02-03 17:40:20 +01:00
|
|
|
req->id = WH_WINEVENT;
|
|
|
|
ret = !wine_server_call_err( req );
|
2005-05-11 15:03:15 +02:00
|
|
|
if (ret) get_user_thread_info()->active_hooks = reply->active_hooks;
|
2005-02-03 17:40:20 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
2007-03-17 11:34:08 +01:00
|
|
|
static inline BOOL find_first_hook(DWORD id, DWORD event, HWND hwnd, LONG object_id,
|
2005-02-03 17:40:20 +01:00
|
|
|
LONG child_id, struct hook_info *info)
|
|
|
|
{
|
2005-05-11 15:03:15 +02:00
|
|
|
struct user_thread_info *thread_info = get_user_thread_info();
|
2005-02-03 17:40:20 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2005-05-11 15:03:15 +02:00
|
|
|
if (!HOOK_IsHooked( id ))
|
|
|
|
{
|
|
|
|
TRACE( "skipping hook %s mask %x\n", hook_names[id-WH_MINHOOK], thread_info->active_hooks );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-02-03 17:40:20 +01:00
|
|
|
SERVER_START_REQ( start_hook_chain )
|
|
|
|
{
|
|
|
|
req->id = id;
|
|
|
|
req->event = event;
|
2008-12-08 16:58:20 +01:00
|
|
|
req->window = wine_server_user_handle( hwnd );
|
2005-02-03 17:40:20 +01:00
|
|
|
req->object_id = object_id;
|
|
|
|
req->child_id = child_id;
|
|
|
|
wine_server_set_reply( req, info->module, sizeof(info->module)-sizeof(WCHAR) );
|
|
|
|
ret = !wine_server_call( req );
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
info->module[wine_server_reply_size(req) / sizeof(WCHAR)] = 0;
|
2008-12-08 16:58:20 +01:00
|
|
|
info->handle = wine_server_ptr_handle( reply->handle );
|
2008-12-29 17:35:35 +01:00
|
|
|
info->proc = wine_server_get_ptr( reply->proc );
|
2005-02-03 17:40:20 +01:00
|
|
|
info->tid = reply->tid;
|
2005-05-11 15:03:15 +02:00
|
|
|
thread_info->active_hooks = reply->active_hooks;
|
2005-02-03 17:40:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret && (info->tid || info->proc);
|
|
|
|
}
|
|
|
|
|
2007-03-17 11:34:08 +01:00
|
|
|
static inline BOOL find_next_hook(DWORD event, HWND hwnd, LONG object_id,
|
2005-02-03 17:40:20 +01:00
|
|
|
LONG child_id, struct hook_info *info)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
2006-10-05 14:05:48 +02:00
|
|
|
SERVER_START_REQ( get_hook_info )
|
2005-02-03 17:40:20 +01:00
|
|
|
{
|
2008-12-08 16:58:20 +01:00
|
|
|
req->handle = wine_server_user_handle( info->handle );
|
2006-10-05 14:05:48 +02:00
|
|
|
req->get_next = 1;
|
2005-02-03 17:40:20 +01:00
|
|
|
req->event = event;
|
2008-12-08 16:58:20 +01:00
|
|
|
req->window = wine_server_user_handle( hwnd );
|
2005-02-03 17:40:20 +01:00
|
|
|
req->object_id = object_id;
|
|
|
|
req->child_id = child_id;
|
|
|
|
wine_server_set_reply( req, info->module, sizeof(info->module)-sizeof(WCHAR) );
|
|
|
|
ret = !wine_server_call( req );
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
info->module[wine_server_reply_size(req) / sizeof(WCHAR)] = 0;
|
2008-12-08 16:58:20 +01:00
|
|
|
info->handle = wine_server_ptr_handle( reply->handle );
|
2008-12-29 17:35:35 +01:00
|
|
|
info->proc = wine_server_get_ptr( reply->proc );
|
2005-02-03 17:40:20 +01:00
|
|
|
info->tid = reply->tid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-03-17 11:34:08 +01:00
|
|
|
static inline void find_hook_close(DWORD id)
|
2005-02-03 17:40:20 +01:00
|
|
|
{
|
|
|
|
SERVER_START_REQ( finish_hook_chain )
|
|
|
|
{
|
|
|
|
req->id = id;
|
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NotifyWinEvent [USER32.@]
|
|
|
|
*
|
|
|
|
* Inform the OS that an event has occurred.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2005-02-03 17:40:20 +01:00
|
|
|
* event [I] Id of the event
|
|
|
|
* hwnd [I] Window holding the object that created the event
|
|
|
|
* object_id [I] Type of object that created the event
|
|
|
|
* child_id [I] Child object of nId, or CHILDID_SELF.
|
2002-10-29 01:41:42 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*/
|
2005-02-03 17:40:20 +01:00
|
|
|
void WINAPI NotifyWinEvent(DWORD event, HWND hwnd, LONG object_id, LONG child_id)
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
struct hook_info info;
|
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("%04x,%p,%d,%d\n", event, hwnd, object_id, child_id);
|
2005-02-03 17:40:20 +01:00
|
|
|
|
|
|
|
if (!hwnd)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-23 14:18:51 +01:00
|
|
|
USER_CheckNotLock();
|
|
|
|
|
2005-02-03 17:40:20 +01:00
|
|
|
#if 0
|
|
|
|
if (event & 0x80000000)
|
|
|
|
{
|
|
|
|
/* FIXME: on 64-bit platforms we need to invent some other way for
|
|
|
|
* passing parameters, nId and nChildId can't hold full [W|L]PARAM.
|
|
|
|
* struct call_hook *hook = (LRESULT *)hWnd;
|
|
|
|
* wparam = hook->wparam;
|
|
|
|
* lparam = hook->lparam;
|
|
|
|
*/
|
|
|
|
LRESULT *ret = (LRESULT *)hwnd;
|
|
|
|
INT id, code, unicode;
|
|
|
|
|
|
|
|
id = (dwEvent & 0x7fff0000) >> 16;
|
|
|
|
code = event & 0x7fff;
|
|
|
|
unicode = event & 0x8000;
|
|
|
|
*ret = HOOK_CallHooks(id, code, object_id, child_id, unicode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!find_first_hook(WH_WINEVENT, event, hwnd, object_id, child_id, &info)) return;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-09-09 13:12:38 +02:00
|
|
|
WINEVENTPROC proc = info.proc;
|
|
|
|
if (proc)
|
2005-02-03 17:40:20 +01:00
|
|
|
{
|
2014-06-13 20:35:41 +02:00
|
|
|
HMODULE free_module = 0;
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE( "calling WH_WINEVENT hook %p event %x hwnd %p %x %x module %s\n",
|
2009-09-09 13:12:38 +02:00
|
|
|
proc, event, hwnd, object_id, child_id, debugstr_w(info.module) );
|
2005-02-03 17:40:20 +01:00
|
|
|
|
2014-06-13 20:35:41 +02:00
|
|
|
if (!info.module[0] || (proc = get_hook_proc( proc, info.module, &free_module )) != NULL)
|
2005-02-03 17:40:20 +01:00
|
|
|
{
|
2017-11-25 11:48:02 +01:00
|
|
|
TRACE_(relay)( "\1Call winevent hook proc %p (hhook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%x,tid=%04x,time=%x)\n",
|
|
|
|
proc, info.handle, event, hwnd, object_id,
|
|
|
|
child_id, GetCurrentThreadId(), GetCurrentTime());
|
2005-02-03 17:40:20 +01:00
|
|
|
|
2009-09-09 13:12:38 +02:00
|
|
|
proc( info.handle, event, hwnd, object_id, child_id,
|
|
|
|
GetCurrentThreadId(), GetCurrentTime());
|
2005-02-03 17:40:20 +01:00
|
|
|
|
2017-11-25 11:48:02 +01:00
|
|
|
TRACE_(relay)( "\1Ret winevent hook proc %p (hhook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%x,tid=%04x,time=%x)\n",
|
|
|
|
proc, info.handle, event, hwnd, object_id,
|
2005-02-03 17:40:20 +01:00
|
|
|
child_id, GetCurrentThreadId(), GetCurrentTime());
|
2014-06-13 20:35:41 +02:00
|
|
|
|
|
|
|
if (free_module) FreeLibrary(free_module);
|
2005-02-03 17:40:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (find_next_hook(event, hwnd, object_id, child_id, &info));
|
|
|
|
|
|
|
|
find_hook_close(WH_WINEVENT);
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* IsWinEventHookInstalled [USER32.@]
|
|
|
|
*
|
|
|
|
* Determine if an event hook is installed for an event.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dwEvent [I] Id of the event
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE, If there are any hooks installed for the event.
|
|
|
|
* FALSE, Otherwise.
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Not implemented.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsWinEventHookInstalled(DWORD dwEvent)
|
|
|
|
{
|
2009-05-28 06:21:50 +02:00
|
|
|
/* FIXME: Needed by Office 2007 installer */
|
|
|
|
WARN("(%d)-stub!\n", dwEvent);
|
2002-10-29 01:41:42 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|