Add native per-program hook exclusions
Parse --exclude-hook-program in the helper, gate foreground hooks and dialog reading by program, and forward the list to the 32-bit hook host. Emit the flags from the Orca extension and cover the matching, validation, and manager behavior with regression tests.
This commit is contained in:
1 parent
0db42de77e
commit
78b70e1ab9
11 files changed
+278
-8
No files matched your search
@@ -0,0 +1,80 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
|
||||
// Programs whose threads must never receive the native menu/input hooks,
|
||||
// named by executable file name. Readers pass one --exclude-hook-program
|
||||
// argument per program; the 64-bit helper forwards the same list to the
|
||||
// 32-bit hook host through WINE_ACCESS_EXCLUDE_HOOK_PROGRAMS (';'-joined),
|
||||
// an internal channel the reader never sets. The bounds mirror the
|
||||
// readers' own validation so either side rejects the same names.
|
||||
#define WINE_ACCESS_MAX_HOOK_EXCLUSIONS 256
|
||||
#define WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH 255
|
||||
|
||||
typedef struct WineAccessHookExclusions {
|
||||
WCHAR names[WINE_ACCESS_MAX_HOOK_EXCLUSIONS][WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH + 1];
|
||||
int count;
|
||||
} WineAccessHookExclusions;
|
||||
|
||||
static inline BOOL wine_access_hook_exclusion_valid(const WCHAR *name) {
|
||||
if (!name) return FALSE;
|
||||
int length = 0;
|
||||
while (length <= WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH && name[length]) ++length;
|
||||
if (!length || length > WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH) return FALSE;
|
||||
if (name[0] <= L' ' || name[length - 1] <= L' ') return FALSE;
|
||||
for (int index = 0; index < length; ++index)
|
||||
if (name[index] < L' ' || name[index] == L'/' || name[index] == L'\\') return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static inline BOOL wine_access_hook_exclusions_add(WineAccessHookExclusions *list,
|
||||
const WCHAR *name) {
|
||||
if (!list || !wine_access_hook_exclusion_valid(name)) return FALSE;
|
||||
for (int index = 0; index < list->count; ++index)
|
||||
if (!lstrcmpiW(list->names[index], name)) return TRUE;
|
||||
if (list->count >= WINE_ACCESS_MAX_HOOK_EXCLUSIONS) return FALSE;
|
||||
lstrcpyW(list->names[list->count++], name);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static inline BOOL wine_access_hook_exclusions_match(const WineAccessHookExclusions *list,
|
||||
const WCHAR *program) {
|
||||
if (!list || !program) return FALSE;
|
||||
const WCHAR *name = program;
|
||||
for (const WCHAR *cursor = program; *cursor; ++cursor)
|
||||
if (*cursor == L'\\' || *cursor == L'/') name = cursor + 1;
|
||||
if (!*name) return FALSE;
|
||||
for (int index = 0; index < list->count; ++index)
|
||||
if (!lstrcmpiW(list->names[index], name)) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline int wine_access_hook_exclusions_parse(WineAccessHookExclusions *list,
|
||||
const WCHAR *value) {
|
||||
if (!list || !value) return 0;
|
||||
const int before = list->count;
|
||||
const WCHAR *start = value;
|
||||
for (;;) {
|
||||
const WCHAR *end = start;
|
||||
while (*end && *end != L';') ++end;
|
||||
const int length = (int)(end - start);
|
||||
if (length && length <= WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH) {
|
||||
WCHAR name[WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH + 1];
|
||||
for (int index = 0; index < length; ++index) name[index] = start[index];
|
||||
name[length] = 0;
|
||||
wine_access_hook_exclusions_add(list, name);
|
||||
}
|
||||
if (!*end) break;
|
||||
start = end + 1;
|
||||
}
|
||||
return list->count - before;
|
||||
}
|
||||
|
||||
static inline BOOL wine_access_process_hook_excluded(const WineAccessHookExclusions *list,
|
||||
HANDLE process) {
|
||||
if (!list || !list->count || !process) return FALSE;
|
||||
WCHAR path[4096];
|
||||
DWORD length = ARRAYSIZE(path);
|
||||
if (!QueryFullProcessImageNameW(process, 0, path, &length)) return FALSE;
|
||||
return wine_access_hook_exclusions_match(list, path);
|
||||
}
|
||||
Reference in new issue
Block a user