2002-10-29 01:41:42 +01:00
|
|
|
/*
|
|
|
|
* Server-side window hooks support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Alexandre Julliard
|
2005-02-03 17:40:20 +01:00
|
|
|
* Copyright (C) 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-10-29 01:41:42 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-10-29 01:41:42 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "winternl.h"
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
#include "object.h"
|
2003-07-11 23:55:58 +02:00
|
|
|
#include "process.h"
|
2002-10-29 01:41:42 +01:00
|
|
|
#include "request.h"
|
|
|
|
#include "user.h"
|
|
|
|
|
|
|
|
struct hook_table;
|
|
|
|
|
|
|
|
struct hook
|
|
|
|
{
|
|
|
|
struct list chain; /* hook chain entry */
|
|
|
|
user_handle_t handle; /* user handle for this hook */
|
2005-02-03 17:40:20 +01:00
|
|
|
struct process *process; /* process the hook is set to */
|
|
|
|
struct thread *thread; /* thread the hook is set to */
|
|
|
|
struct thread *owner; /* owner of the out of context hook */
|
2005-07-11 20:05:50 +02:00
|
|
|
struct hook_table *table; /* hook table that contains this hook */
|
2002-10-29 01:41:42 +01:00
|
|
|
int index; /* hook table index */
|
2005-02-03 17:40:20 +01:00
|
|
|
int event_min;
|
|
|
|
int event_max;
|
|
|
|
int flags;
|
2002-10-29 01:41:42 +01:00
|
|
|
void *proc; /* hook function */
|
|
|
|
int unicode; /* is it a unicode hook? */
|
2002-11-20 20:54:32 +01:00
|
|
|
WCHAR *module; /* module name for global hooks */
|
|
|
|
size_t module_size;
|
2002-10-29 01:41:42 +01:00
|
|
|
};
|
|
|
|
|
2005-02-03 17:40:20 +01:00
|
|
|
#define WH_WINEVENT (WH_MAXHOOK+1)
|
|
|
|
|
|
|
|
#define NB_HOOKS (WH_WINEVENT-WH_MINHOOK+1)
|
2002-10-29 01:41:42 +01:00
|
|
|
#define HOOK_ENTRY(p) LIST_ENTRY( (p), struct hook, chain )
|
|
|
|
|
|
|
|
struct hook_table
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct list hooks[NB_HOOKS]; /* array of hook chains */
|
|
|
|
int counts[NB_HOOKS]; /* use counts for each hook chain */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void hook_table_dump( struct object *obj, int verbose );
|
|
|
|
static void hook_table_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops hook_table_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct hook_table), /* size */
|
|
|
|
hook_table_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
2005-04-24 19:35:52 +02:00
|
|
|
no_signal, /* signal */
|
2002-10-29 01:41:42 +01:00
|
|
|
no_get_fd, /* get_fd */
|
2005-12-12 14:57:40 +01:00
|
|
|
no_map_access, /* map_access */
|
2005-11-22 15:55:42 +01:00
|
|
|
no_lookup_name, /* lookup_name */
|
2005-06-09 17:39:52 +02:00
|
|
|
no_close_handle, /* close_handle */
|
2002-10-29 01:41:42 +01:00
|
|
|
hook_table_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* create a new hook table */
|
|
|
|
static struct hook_table *alloc_hook_table(void)
|
|
|
|
{
|
|
|
|
struct hook_table *table;
|
|
|
|
int i;
|
|
|
|
|
2003-02-19 01:33:32 +01:00
|
|
|
if ((table = alloc_object( &hook_table_ops )))
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < NB_HOOKS; i++)
|
|
|
|
{
|
|
|
|
list_init( &table->hooks[i] );
|
|
|
|
table->counts[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2005-07-11 20:05:50 +02:00
|
|
|
static struct hook_table *get_global_hooks( struct thread *thread )
|
|
|
|
{
|
|
|
|
struct hook_table *table;
|
|
|
|
struct desktop *desktop = get_thread_desktop( thread, 0 );
|
|
|
|
|
|
|
|
if (!desktop) return NULL;
|
|
|
|
table = desktop->global_hooks;
|
|
|
|
release_object( desktop );
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
/* create a new hook and add it to the specified table */
|
2005-07-11 20:05:50 +02:00
|
|
|
static struct hook *add_hook( struct desktop *desktop, struct thread *thread, int index, int global )
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
struct hook *hook;
|
2005-07-11 20:05:50 +02:00
|
|
|
struct hook_table *table = global ? desktop->global_hooks : get_queue_hooks(thread);
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
if (!table)
|
|
|
|
{
|
|
|
|
if (!(table = alloc_hook_table())) return NULL;
|
2005-07-11 20:05:50 +02:00
|
|
|
if (global) desktop->global_hooks = table;
|
2003-07-11 23:55:58 +02:00
|
|
|
else set_queue_hooks( thread, table );
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
if (!(hook = mem_alloc( sizeof(*hook) ))) return NULL;
|
|
|
|
|
|
|
|
if (!(hook->handle = alloc_user_handle( hook, USER_HOOK )))
|
|
|
|
{
|
|
|
|
free( hook );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
hook->thread = thread ? (struct thread *)grab_object( thread ) : NULL;
|
2005-07-11 20:05:50 +02:00
|
|
|
hook->table = table;
|
2002-10-29 01:41:42 +01:00
|
|
|
hook->index = index;
|
|
|
|
list_add_head( &table->hooks[index], &hook->chain );
|
2005-06-28 21:37:52 +02:00
|
|
|
if (thread) thread->desktop_users++;
|
2002-10-29 01:41:42 +01:00
|
|
|
return hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free a hook, removing it from its chain */
|
|
|
|
static void free_hook( struct hook *hook )
|
|
|
|
{
|
|
|
|
free_user_handle( hook->handle );
|
2002-11-20 20:54:32 +01:00
|
|
|
if (hook->module) free( hook->module );
|
2005-06-28 21:37:52 +02:00
|
|
|
if (hook->thread)
|
|
|
|
{
|
|
|
|
assert( hook->thread->desktop_users > 0 );
|
|
|
|
hook->thread->desktop_users--;
|
|
|
|
release_object( hook->thread );
|
|
|
|
}
|
2005-02-03 17:40:20 +01:00
|
|
|
if (hook->process) release_object( hook->process );
|
|
|
|
release_object( hook->owner );
|
2002-10-29 01:41:42 +01:00
|
|
|
list_remove( &hook->chain );
|
|
|
|
free( hook );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find a hook from its index and proc */
|
|
|
|
static struct hook *find_hook( struct thread *thread, int index, void *proc )
|
|
|
|
{
|
|
|
|
struct list *p;
|
2003-07-03 20:16:48 +02:00
|
|
|
struct hook_table *table = get_queue_hooks( thread );
|
2002-10-29 01:41:42 +01:00
|
|
|
|
|
|
|
if (table)
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH( p, &table->hooks[index] )
|
|
|
|
{
|
|
|
|
struct hook *hook = HOOK_ENTRY( p );
|
|
|
|
if (hook->proc == proc) return hook;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the first hook in the chain */
|
|
|
|
inline static struct hook *get_first_hook( struct hook_table *table, int index )
|
|
|
|
{
|
|
|
|
struct list *elem = list_head( &table->hooks[index] );
|
|
|
|
return elem ? HOOK_ENTRY( elem ) : NULL;
|
|
|
|
}
|
|
|
|
|
2005-05-11 15:03:15 +02:00
|
|
|
/* check if a given hook should run in the current thread */
|
|
|
|
inline static int run_hook_in_current_thread( struct hook *hook )
|
|
|
|
{
|
|
|
|
if ((!hook->process || hook->process == current->process) &&
|
|
|
|
(!(hook->flags & WINEVENT_SKIPOWNPROCESS) || hook->process != current->process))
|
|
|
|
{
|
|
|
|
if ((!hook->thread || hook->thread == current) &&
|
|
|
|
(!(hook->flags & WINEVENT_SKIPOWNTHREAD) || hook->thread != current))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-20 20:54:32 +01:00
|
|
|
/* find the first non-deleted hook in the chain */
|
2005-02-03 17:40:20 +01:00
|
|
|
inline static struct hook *get_first_valid_hook( struct hook_table *table, int index,
|
|
|
|
int event, user_handle_t win,
|
|
|
|
int object_id, int child_id )
|
2002-11-20 20:54:32 +01:00
|
|
|
{
|
|
|
|
struct hook *hook = get_first_hook( table, index );
|
2005-02-03 17:40:20 +01:00
|
|
|
|
|
|
|
while (hook)
|
|
|
|
{
|
2005-05-11 15:03:15 +02:00
|
|
|
if (hook->proc && run_hook_in_current_thread( hook ))
|
2005-02-03 17:40:20 +01:00
|
|
|
{
|
2005-05-11 15:03:15 +02:00
|
|
|
if (event >= hook->event_min && event <= hook->event_max)
|
2005-02-03 17:40:20 +01:00
|
|
|
{
|
2005-05-11 15:03:15 +02:00
|
|
|
if (hook->flags & WINEVENT_INCONTEXT) return hook;
|
|
|
|
|
|
|
|
/* only winevent hooks may be out of context */
|
|
|
|
assert(hook->index + WH_MINHOOK == WH_WINEVENT);
|
|
|
|
post_win_event( hook->owner, event, win, object_id, child_id,
|
|
|
|
hook->proc, hook->module, hook->module_size,
|
|
|
|
hook->handle );
|
2005-02-03 17:40:20 +01:00
|
|
|
}
|
|
|
|
}
|
2002-11-20 20:54:32 +01:00
|
|
|
hook = HOOK_ENTRY( list_next( &table->hooks[index], &hook->chain ) );
|
2005-02-03 17:40:20 +01:00
|
|
|
}
|
2002-11-20 20:54:32 +01:00
|
|
|
return hook;
|
|
|
|
}
|
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
/* find the next hook in the chain, skipping the deleted ones */
|
2005-07-11 20:05:50 +02:00
|
|
|
static struct hook *get_next_hook( struct thread *thread, struct hook *hook, int event,
|
|
|
|
user_handle_t win, int object_id, int child_id )
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
2005-07-11 20:05:50 +02:00
|
|
|
struct hook_table *global_hooks, *table = hook->table;
|
2002-11-20 20:54:32 +01:00
|
|
|
int index = hook->index;
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2002-11-20 20:54:32 +01:00
|
|
|
while ((hook = HOOK_ENTRY( list_next( &table->hooks[index], &hook->chain ) )))
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
2005-05-11 15:03:15 +02:00
|
|
|
if (hook->proc && run_hook_in_current_thread( hook ))
|
2005-02-03 17:40:20 +01:00
|
|
|
{
|
2005-05-11 15:03:15 +02:00
|
|
|
if (event >= hook->event_min && event <= hook->event_max)
|
2005-02-03 17:40:20 +01:00
|
|
|
{
|
2005-05-11 15:03:15 +02:00
|
|
|
if (hook->flags & WINEVENT_INCONTEXT) return hook;
|
|
|
|
|
|
|
|
/* only winevent hooks may be out of context */
|
|
|
|
assert(hook->index + WH_MINHOOK == WH_WINEVENT);
|
|
|
|
post_win_event( hook->owner, event, win, object_id, child_id,
|
|
|
|
hook->proc, hook->module, hook->module_size,
|
|
|
|
hook->handle );
|
2005-02-03 17:40:20 +01:00
|
|
|
}
|
|
|
|
}
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
2005-07-11 20:05:50 +02:00
|
|
|
global_hooks = get_global_hooks( thread );
|
2002-11-20 20:54:32 +01:00
|
|
|
if (global_hooks && table != global_hooks) /* now search through the global table */
|
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
hook = get_first_valid_hook( global_hooks, index, event, win, object_id, child_id );
|
2002-11-20 20:54:32 +01:00
|
|
|
}
|
|
|
|
return hook;
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hook_table_dump( struct object *obj, int verbose )
|
|
|
|
{
|
2005-07-11 20:05:50 +02:00
|
|
|
/* struct hook_table *table = (struct hook_table *)obj; */
|
|
|
|
fprintf( stderr, "Hook table\n" );
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hook_table_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct hook *hook;
|
|
|
|
struct hook_table *table = (struct hook_table *)obj;
|
|
|
|
|
|
|
|
for (i = 0; i < NB_HOOKS; i++)
|
|
|
|
{
|
|
|
|
while ((hook = get_first_hook( table, i )) != NULL) free_hook( hook );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove a hook, freeing it if the chain is not in use */
|
|
|
|
static void remove_hook( struct hook *hook )
|
|
|
|
{
|
2005-07-11 20:05:50 +02:00
|
|
|
if (hook->table->counts[hook->index])
|
2002-10-29 01:41:42 +01:00
|
|
|
hook->proc = NULL; /* chain is in use, just mark it and return */
|
|
|
|
else
|
|
|
|
free_hook( hook );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release a hook chain, removing deleted hooks if the use count drops to 0 */
|
|
|
|
static void release_hook_chain( struct hook_table *table, int index )
|
|
|
|
{
|
|
|
|
if (!table->counts[index]) /* use count shouldn't already be 0 */
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!--table->counts[index])
|
|
|
|
{
|
|
|
|
struct hook *hook = get_first_hook( table, index );
|
|
|
|
while (hook)
|
|
|
|
{
|
|
|
|
struct hook *next = HOOK_ENTRY( list_next( &table->hooks[hook->index], &hook->chain ) );
|
|
|
|
if (!hook->proc) free_hook( hook );
|
|
|
|
hook = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-11 23:55:58 +02:00
|
|
|
/* remove all global hooks owned by a given thread */
|
|
|
|
void remove_thread_hooks( struct thread *thread )
|
|
|
|
{
|
2005-07-11 20:05:50 +02:00
|
|
|
struct hook_table *global_hooks = get_global_hooks( thread );
|
2003-07-11 23:55:58 +02:00
|
|
|
int index;
|
|
|
|
|
|
|
|
if (!global_hooks) return;
|
|
|
|
|
|
|
|
/* only low-level keyboard/mouse global hooks can be owned by a thread */
|
|
|
|
for (index = WH_KEYBOARD_LL - WH_MINHOOK; index <= WH_MOUSE_LL - WH_MINHOOK; index++)
|
|
|
|
{
|
|
|
|
struct hook *hook = get_first_hook( global_hooks, index );
|
|
|
|
while (hook)
|
|
|
|
{
|
|
|
|
struct hook *next = HOOK_ENTRY( list_next( &global_hooks->hooks[index], &hook->chain ) );
|
|
|
|
if (hook->thread == thread) remove_hook( hook );
|
|
|
|
hook = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2005-05-11 15:03:15 +02:00
|
|
|
/* get a bitmap of active hooks in a hook table */
|
|
|
|
static int is_hook_active( struct hook_table *table, int index )
|
|
|
|
{
|
|
|
|
struct hook *hook = get_first_hook( table, index );
|
|
|
|
|
|
|
|
while (hook)
|
|
|
|
{
|
|
|
|
if (hook->proc && run_hook_in_current_thread( hook )) return 1;
|
|
|
|
hook = HOOK_ENTRY( list_next( &table->hooks[index], &hook->chain ) );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get a bitmap of all active hooks for the current thread */
|
|
|
|
unsigned int get_active_hooks(void)
|
|
|
|
{
|
|
|
|
struct hook_table *table = get_queue_hooks( current );
|
2005-07-11 20:05:50 +02:00
|
|
|
struct hook_table *global_hooks = get_global_hooks( current );
|
2005-05-11 15:03:15 +02:00
|
|
|
unsigned int ret = 1 << 31; /* set high bit to indicate that the bitmap is valid */
|
|
|
|
int id;
|
|
|
|
|
|
|
|
for (id = WH_MINHOOK; id <= WH_WINEVENT; id++)
|
|
|
|
{
|
|
|
|
if ((table && is_hook_active( table, id - WH_MINHOOK )) ||
|
|
|
|
(global_hooks && is_hook_active( global_hooks, id - WH_MINHOOK )))
|
|
|
|
ret |= 1 << (id - WH_MINHOOK);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-10-29 01:41:42 +01:00
|
|
|
/* set a window hook */
|
|
|
|
DECL_HANDLER(set_hook)
|
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
struct process *process = NULL;
|
|
|
|
struct thread *thread = NULL;
|
2005-07-11 20:05:50 +02:00
|
|
|
struct desktop *desktop;
|
2002-10-29 01:41:42 +01:00
|
|
|
struct hook *hook;
|
2002-11-20 20:54:32 +01:00
|
|
|
WCHAR *module;
|
2003-07-11 23:55:58 +02:00
|
|
|
int global;
|
2002-11-20 20:54:32 +01:00
|
|
|
size_t module_size = get_req_data_size();
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2005-02-03 17:40:20 +01:00
|
|
|
if (!req->proc || req->id < WH_MINHOOK || req->id > WH_WINEVENT)
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return;
|
|
|
|
}
|
2005-02-03 17:40:20 +01:00
|
|
|
|
2005-07-11 20:05:50 +02:00
|
|
|
if (!(desktop = get_thread_desktop( current, DESKTOP_HOOKCONTROL ))) return;
|
|
|
|
|
|
|
|
if (req->pid && !(process = get_process_from_id( req->pid ))) goto done;
|
2005-02-03 17:40:20 +01:00
|
|
|
|
|
|
|
if (req->tid)
|
|
|
|
{
|
2005-07-11 20:05:50 +02:00
|
|
|
if (!(thread = get_thread_from_id( req->tid ))) goto done;
|
2005-02-03 17:40:20 +01:00
|
|
|
if (process && process != thread->process)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2005-07-11 20:05:50 +02:00
|
|
|
goto done;
|
2005-02-03 17:40:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-11 23:55:58 +02:00
|
|
|
if (req->id == WH_KEYBOARD_LL || req->id == WH_MOUSE_LL)
|
|
|
|
{
|
|
|
|
/* low-level hardware hooks are special: always global, but without a module */
|
|
|
|
thread = (struct thread *)grab_object( current );
|
|
|
|
module = NULL;
|
|
|
|
global = 1;
|
|
|
|
}
|
|
|
|
else if (!req->tid)
|
2002-11-20 20:54:32 +01:00
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
/* out of context hooks do not need a module handle */
|
|
|
|
if (!module_size && (req->flags & WINEVENT_INCONTEXT))
|
2002-11-20 20:54:32 +01:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2005-07-11 20:05:50 +02:00
|
|
|
goto done;
|
2002-11-20 20:54:32 +01:00
|
|
|
}
|
2005-07-11 20:05:50 +02:00
|
|
|
if (!(module = memdup( get_req_data(), module_size ))) goto done;
|
2003-07-11 23:55:58 +02:00
|
|
|
global = 1;
|
2002-11-20 20:54:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
module = NULL;
|
2003-07-11 23:55:58 +02:00
|
|
|
global = 0;
|
2002-11-20 20:54:32 +01:00
|
|
|
}
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2005-07-11 20:05:50 +02:00
|
|
|
if ((hook = add_hook( desktop, thread, req->id - WH_MINHOOK, global )))
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
hook->owner = (struct thread *)grab_object( current );
|
|
|
|
hook->process = process ? (struct process *)grab_object( process ) : NULL;
|
|
|
|
hook->event_min = req->event_min;
|
|
|
|
hook->event_max = req->event_max;
|
|
|
|
hook->flags = req->flags;
|
2002-11-20 20:54:32 +01:00
|
|
|
hook->proc = req->proc;
|
|
|
|
hook->unicode = req->unicode;
|
|
|
|
hook->module = module;
|
|
|
|
hook->module_size = module_size;
|
2002-10-29 01:41:42 +01:00
|
|
|
reply->handle = hook->handle;
|
2005-05-11 15:03:15 +02:00
|
|
|
reply->active_hooks = get_active_hooks();
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
2002-11-20 20:54:32 +01:00
|
|
|
else if (module) free( module );
|
|
|
|
|
2005-07-11 20:05:50 +02:00
|
|
|
done:
|
2005-02-03 17:40:20 +01:00
|
|
|
if (process) release_object( process );
|
2002-11-20 20:54:32 +01:00
|
|
|
if (thread) release_object( thread );
|
2005-07-11 20:05:50 +02:00
|
|
|
release_object( desktop );
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* remove a window hook */
|
|
|
|
DECL_HANDLER(remove_hook)
|
|
|
|
{
|
|
|
|
struct hook *hook;
|
|
|
|
|
2005-01-27 12:14:19 +01:00
|
|
|
if (req->handle)
|
|
|
|
{
|
|
|
|
if (!(hook = get_user_object( req->handle, USER_HOOK )))
|
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2005-01-27 12:14:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-10-29 01:41:42 +01:00
|
|
|
else
|
|
|
|
{
|
2005-02-03 17:40:20 +01:00
|
|
|
if (!req->proc || req->id < WH_MINHOOK || req->id > WH_WINEVENT)
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(hook = find_hook( current, req->id - WH_MINHOOK, req->proc )))
|
2005-01-27 12:14:19 +01:00
|
|
|
{
|
2002-10-29 01:41:42 +01:00
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2005-01-27 12:14:19 +01:00
|
|
|
return;
|
|
|
|
}
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
2005-01-27 12:14:19 +01:00
|
|
|
remove_hook( hook );
|
2005-05-11 15:03:15 +02:00
|
|
|
reply->active_hooks = get_active_hooks();
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* start calling a hook chain */
|
|
|
|
DECL_HANDLER(start_hook_chain)
|
|
|
|
{
|
|
|
|
struct hook *hook;
|
2003-07-03 20:16:48 +02:00
|
|
|
struct hook_table *table = get_queue_hooks( current );
|
2002-10-29 01:41:42 +01:00
|
|
|
|
2005-02-03 17:40:20 +01:00
|
|
|
if (req->id < WH_MINHOOK || req->id > WH_WINEVENT)
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return;
|
|
|
|
}
|
2002-11-20 20:54:32 +01:00
|
|
|
|
2005-05-11 15:03:15 +02:00
|
|
|
reply->active_hooks = get_active_hooks();
|
|
|
|
|
|
|
|
if (!table || !(hook = get_first_valid_hook( table, req->id - WH_MINHOOK, req->event,
|
|
|
|
req->window, req->object_id, req->child_id )))
|
2002-11-20 20:54:32 +01:00
|
|
|
{
|
|
|
|
/* try global table */
|
2005-07-11 20:05:50 +02:00
|
|
|
if (!(table = get_global_hooks( current )) ||
|
|
|
|
!(hook = get_first_valid_hook( table, req->id - WH_MINHOOK, req->event,
|
2005-05-11 15:03:15 +02:00
|
|
|
req->window, req->object_id, req->child_id )))
|
2002-11-20 20:54:32 +01:00
|
|
|
return; /* no hook set */
|
|
|
|
}
|
2003-07-11 23:55:58 +02:00
|
|
|
|
2005-02-03 17:40:20 +01:00
|
|
|
if (hook->thread && hook->thread != current) /* must run in other thread */
|
2003-07-11 23:55:58 +02:00
|
|
|
{
|
|
|
|
reply->pid = get_process_id( hook->thread->process );
|
|
|
|
reply->tid = get_thread_id( hook->thread );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reply->pid = 0;
|
|
|
|
reply->tid = 0;
|
|
|
|
}
|
2005-02-03 17:40:20 +01:00
|
|
|
reply->proc = hook->proc;
|
2002-10-29 01:41:42 +01:00
|
|
|
reply->handle = hook->handle;
|
|
|
|
reply->unicode = hook->unicode;
|
|
|
|
table->counts[hook->index]++;
|
2002-11-20 20:54:32 +01:00
|
|
|
if (hook->module) set_reply_data( hook->module, hook->module_size );
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* finished calling a hook chain */
|
|
|
|
DECL_HANDLER(finish_hook_chain)
|
|
|
|
{
|
2003-07-03 20:16:48 +02:00
|
|
|
struct hook_table *table = get_queue_hooks( current );
|
2005-07-11 20:05:50 +02:00
|
|
|
struct hook_table *global_hooks = get_global_hooks( current );
|
2002-10-29 01:41:42 +01:00
|
|
|
int index = req->id - WH_MINHOOK;
|
|
|
|
|
2005-02-03 17:40:20 +01:00
|
|
|
if (req->id < WH_MINHOOK || req->id > WH_WINEVENT)
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (table) release_hook_chain( table, index );
|
2002-11-20 20:54:32 +01:00
|
|
|
if (global_hooks) release_hook_chain( global_hooks, index );
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get the next hook to call */
|
|
|
|
DECL_HANDLER(get_next_hook)
|
|
|
|
{
|
|
|
|
struct hook *hook, *next;
|
|
|
|
|
|
|
|
if (!(hook = get_user_object( req->handle, USER_HOOK ))) return;
|
2002-11-20 20:54:32 +01:00
|
|
|
if (hook->thread && (hook->thread != current))
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
|
|
|
return;
|
|
|
|
}
|
2005-07-11 20:05:50 +02:00
|
|
|
if ((next = get_next_hook( current, hook, req->event, req->window, req->object_id, req->child_id )))
|
2002-10-29 01:41:42 +01:00
|
|
|
{
|
|
|
|
reply->next = next->handle;
|
|
|
|
reply->id = next->index + WH_MINHOOK;
|
|
|
|
reply->prev_unicode = hook->unicode;
|
|
|
|
reply->next_unicode = next->unicode;
|
2002-12-17 22:01:01 +01:00
|
|
|
if (next->module) set_reply_data( next->module, next->module_size );
|
2003-07-11 23:55:58 +02:00
|
|
|
if (next->thread && next->thread != current)
|
|
|
|
{
|
|
|
|
reply->pid = get_process_id( next->thread->process );
|
|
|
|
reply->tid = get_thread_id( next->thread );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reply->pid = 0;
|
|
|
|
reply->tid = 0;
|
|
|
|
}
|
2005-02-03 17:40:20 +01:00
|
|
|
reply->proc = next->proc;
|
2002-10-29 01:41:42 +01:00
|
|
|
}
|
|
|
|
}
|