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,71 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#include "../hook_exclusions.h"
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
static bool check(bool value, const char *message) {
|
||||
if (!value) std::fprintf(stderr, "FAIL: %s\n", message);
|
||||
return value;
|
||||
}
|
||||
|
||||
int main() {
|
||||
bool ok = true;
|
||||
static WineAccessHookExclusions exclusions;
|
||||
ok &= check(!wine_access_hook_exclusions_match(&exclusions, L"Game.exe"),
|
||||
"empty list excludes nothing");
|
||||
ok &= check(wine_access_hook_exclusions_add(&exclusions, L"Diablo IV.exe"),
|
||||
"valid exclusion is stored");
|
||||
ok &= check(wine_access_hook_exclusions_add(&exclusions, L"diablo iv.EXE"),
|
||||
"duplicate exclusion is accepted");
|
||||
ok &= check(exclusions.count == 1, "duplicate exclusion is stored once");
|
||||
ok &= check(wine_access_hook_exclusions_match(&exclusions, L"Diablo IV.exe"),
|
||||
"exclusion matches its file name");
|
||||
ok &= check(wine_access_hook_exclusions_match(
|
||||
&exclusions, L"C:\\Program Files\\Diablo IV\\Diablo IV.exe"),
|
||||
"exclusion matches a Windows path by file name");
|
||||
ok &= check(wine_access_hook_exclusions_match(
|
||||
&exclusions, L"Z:/games/diablo iv.exe"),
|
||||
"exclusion matches a forward-slash path by file name");
|
||||
ok &= check(!wine_access_hook_exclusions_match(&exclusions, L"Diablo IV Launcher.exe"),
|
||||
"exclusion does not match a different program");
|
||||
ok &= check(!wine_access_hook_exclusions_match(&exclusions, nullptr),
|
||||
"exclusion does not match a missing program");
|
||||
ok &= check(!wine_access_hook_exclusions_add(&exclusions, L""),
|
||||
"empty exclusion is rejected");
|
||||
ok &= check(!wine_access_hook_exclusions_add(&exclusions, L"../Game.exe"),
|
||||
"exclusion with a forward slash is rejected");
|
||||
ok &= check(!wine_access_hook_exclusions_add(&exclusions, L"C:\\Game.exe"),
|
||||
"exclusion with a backslash is rejected");
|
||||
ok &= check(!wine_access_hook_exclusions_add(&exclusions, L" Game.exe"),
|
||||
"exclusion with leading whitespace is rejected");
|
||||
ok &= check(!wine_access_hook_exclusions_add(&exclusions, L"Game.exe "),
|
||||
"exclusion with trailing whitespace is rejected");
|
||||
std::vector<WCHAR> oversized(WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH + 2, L'a');
|
||||
oversized.back() = 0;
|
||||
ok &= check(!wine_access_hook_exclusions_add(&exclusions, oversized.data()),
|
||||
"oversized exclusion is rejected");
|
||||
oversized[WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH] = 0;
|
||||
ok &= check(wine_access_hook_exclusions_add(&exclusions, oversized.data()),
|
||||
"maximum-size exclusion is accepted");
|
||||
|
||||
static WineAccessHookExclusions parsed;
|
||||
const int added = wine_access_hook_exclusions_parse(
|
||||
&parsed, L"One.exe;two.exe;C:\\bad.exe;;Two.EXE");
|
||||
ok &= check(added == 2 && parsed.count == 2,
|
||||
"semicolon list keeps valid unique exclusions");
|
||||
ok &= check(wine_access_hook_exclusions_match(&parsed, L"ONE.EXE"),
|
||||
"parsed exclusion matches its program");
|
||||
|
||||
static WineAccessHookExclusions full;
|
||||
WCHAR name[32];
|
||||
bool filled = true;
|
||||
for (int index = 0; index < WINE_ACCESS_MAX_HOOK_EXCLUSIONS; ++index) {
|
||||
wsprintfW(name, L"game%d.exe", index);
|
||||
filled &= wine_access_hook_exclusions_add(&full, name);
|
||||
}
|
||||
ok &= check(filled && full.count == WINE_ACCESS_MAX_HOOK_EXCLUSIONS,
|
||||
"exclusion list fills to its bound");
|
||||
ok &= check(!wine_access_hook_exclusions_add(&full, L"overflow.exe"),
|
||||
"exclusion past the bound is rejected");
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user