Preserve staged helper builds and exclude hooks before attachment
This commit is contained in:
1 parent
0db42de77e
commit
989ecb681d
12 files changed
+267
-38
No files matched your search
@@ -117,6 +117,13 @@ if(BUILD_TESTING)
|
||||
else()
|
||||
set(fixture_compiler "${MINGW_C_COMPILER}")
|
||||
endif()
|
||||
set(exclusions_test "${CMAKE_CURRENT_BINARY_DIR}/hook-exclusions${arch}.exe")
|
||||
add_custom_command(OUTPUT "${exclusions_test}"
|
||||
COMMAND "${fixture_compiler}" -std=c11 -O2 -Wall -Wextra
|
||||
-o "${exclusions_test}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/hook_exclusions_test.c" -luser32
|
||||
DEPENDS tests/hook_exclusions_test.c foreground_hooks.h bootstrapper_hook.h VERBATIM)
|
||||
add_custom_target(hook-exclusions${arch} ALL DEPENDS "${exclusions_test}")
|
||||
add_wine_test(hook-exclusions${arch} 35 wine "${exclusions_test}")
|
||||
set(hook_fixture "${CMAKE_CURRENT_BINARY_DIR}/hook-safety-fixture${arch}.exe")
|
||||
add_custom_command(OUTPUT "${hook_fixture}"
|
||||
COMMAND "${fixture_compiler}" -std=c11 -O2 -Wall -Wextra -Wl,--stack,1048576
|
||||
|
||||
@@ -356,22 +356,26 @@ What a supervisor must get right for Proton prefixes:
|
||||
The home directory is bound at the same path in both namespaces: a
|
||||
user-local installation under `~/.local/libexec` works as-is, and the
|
||||
Orca extension stages a copy of a system installation under
|
||||
`~/.local/state/orca-wine-access/helper/` for such prefixes.
|
||||
`~/.local/state/orca-wine-access/helper/<content-hash>/` for such prefixes.
|
||||
Each staged directory contains a complete helper set and is left unchanged
|
||||
while older helpers or application hooks may still use it.
|
||||
|
||||
The Orca extension in this repository implements all of this. Cthulhu's
|
||||
supervisor needs the equivalent loader resolution in Cthulhu itself; until
|
||||
then, Protontricks-launched applications do not get a Cthulhu helper. To
|
||||
start the helper manually for a running game, use its Proton build and
|
||||
prefix, for example:
|
||||
prefix. Install the complete helper set under the user-local path first.
|
||||
Set `gameEsync` and `gameFsync` to the running game process's `WINEESYNC`
|
||||
and `WINEFSYNC` values (use an empty value when absent), for example:
|
||||
|
||||
```sh
|
||||
WINEPREFIX="$HOME/.local/share/Steam/steamapps/compatdata/<appid>/pfx" \
|
||||
WINELOADER="$HOME/.local/share/Steam/steamapps/common/Proton 11.0/files/bin/wine" \
|
||||
WINEESYNC=1 WINEFSYNC=1 \
|
||||
/usr/libexec/wine-access/wine-access.exe
|
||||
WINEESYNC="$gameEsync" WINEFSYNC="$gameFsync" \
|
||||
"$HOME/.local/libexec/wine-access/wine-access.exe"
|
||||
```
|
||||
|
||||
(add the reader options from above for Orca). Flatpak builds of Steam or
|
||||
Add the reader options from above for Orca. Flatpak builds of Steam or
|
||||
Protontricks are not supported: their sandboxes hide both the host helper
|
||||
installation and the game processes from the reader.
|
||||
|
||||
|
||||
+29
-1
@@ -17,6 +17,34 @@ static inline void wine_access_release_hooks(WineAccessForegroundHooks *hooks) {
|
||||
hooks->thread = 0;
|
||||
}
|
||||
|
||||
// Read the process image before injecting. A configured exclusion list also
|
||||
// fails closed if the target image cannot be identified. Both architectures
|
||||
// use this guard, independently of the reader's slower /proc discovery.
|
||||
static inline BOOL wine_access_hooks_allowed(HANDLE process) {
|
||||
WCHAR excluded[32768];
|
||||
SetLastError(ERROR_SUCCESS);
|
||||
DWORD count = GetEnvironmentVariableW(L"WINE_ACCESS_EXCLUDED_HOOK_PROGRAMS",
|
||||
excluded, 32768);
|
||||
if (!count) return GetLastError() == ERROR_ENVVAR_NOT_FOUND;
|
||||
if (count >= 32768) return FALSE;
|
||||
WCHAR image[32768];
|
||||
DWORD length = 32768;
|
||||
if (!process || !QueryFullProcessImageNameW(process, 0, image, &length)) return FALSE;
|
||||
const WCHAR *name = image;
|
||||
for (DWORD index = 0; index < length; ++index)
|
||||
if (image[index] == L'\\' || image[index] == L'/') name = image + index + 1;
|
||||
WCHAR *entry = excluded;
|
||||
for (WCHAR *cursor = excluded; ; ++cursor) {
|
||||
if (*cursor != L'\n' && *cursor) continue;
|
||||
BOOL last = !*cursor;
|
||||
*cursor = 0;
|
||||
if (*entry && !lstrcmpiW(name, entry)) return FALSE;
|
||||
if (last) break;
|
||||
entry = cursor + 1;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Global hooks cross the 32/64-bit boundary through the installing thread.
|
||||
// Avoid that synchronous traffic and hook only the matching foreground UI
|
||||
// thread. Both hosts use the same detach/retry rules.
|
||||
@@ -25,7 +53,7 @@ static inline void wine_access_update_hooks(WineAccessForegroundHooks *hooks, BO
|
||||
DWORD thread = GetWindowThreadProcessId(GetForegroundWindow(), &pid);
|
||||
HANDLE process = pid ? OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid) : NULL;
|
||||
BOOL wow64 = FALSE;
|
||||
BOOL known = process && IsWow64Process(process, &wow64);
|
||||
BOOL known = process && IsWow64Process(process, &wow64) && wine_access_hooks_allowed(process);
|
||||
if (process) CloseHandle(process);
|
||||
if (!known || wow64 != target_wow64) thread = 0;
|
||||
if (thread == hooks->thread) return;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <deque>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
// Read directly by readers without starting Wine or initializing a prefix.
|
||||
@@ -1146,7 +1147,20 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, char *, int) {
|
||||
bool validEndpoint = true;
|
||||
std::string readerPath, readerInterface;
|
||||
bool dialogReaderEnabled = true, controllerEnabled = true;
|
||||
// Winelib WCHAR is 16-bit; avoid the host libc's wide-string ABI.
|
||||
std::vector<wchar_t> excludedHookPrograms;
|
||||
bool validHookExclusions = true;
|
||||
for (int index = 1; index < argumentCount; ++index) {
|
||||
if (lstrcmpW(arguments[index], L"--exclude-hook-program") == 0) {
|
||||
if (++index == argumentCount || !arguments[index][0]) { validHookExclusions = false; break; }
|
||||
for (const wchar_t *letter = arguments[index]; *letter; ++letter)
|
||||
if (*letter == L'\n' || *letter == L'\r' || *letter == L'/' || *letter == L'\\')
|
||||
validHookExclusions = false;
|
||||
excludedHookPrograms.insert(excludedHookPrograms.end(), arguments[index],
|
||||
arguments[index] + lstrlenW(arguments[index]));
|
||||
excludedHookPrograms.push_back(L'\n');
|
||||
continue;
|
||||
}
|
||||
if (lstrcmpW(arguments[index], L"--no-dialog-reader") == 0) {
|
||||
dialogReaderEnabled = false;
|
||||
continue;
|
||||
@@ -1178,6 +1192,21 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, char *, int) {
|
||||
else { validReader = false; break; }
|
||||
}
|
||||
LocalFree(arguments);
|
||||
if (!validHookExclusions) {
|
||||
std::fprintf(stderr, "wine-access: --exclude-hook-program requires an executable basename\n");
|
||||
return 1;
|
||||
}
|
||||
// The companion inherits this private list. Set it before launching either
|
||||
// hook host, and reject oversized lists instead of silently losing protection.
|
||||
if (!excludedHookPrograms.empty()) excludedHookPrograms.push_back(0);
|
||||
if (excludedHookPrograms.empty())
|
||||
SetEnvironmentVariableW(L"WINE_ACCESS_EXCLUDED_HOOK_PROGRAMS", nullptr);
|
||||
if (excludedHookPrograms.size() >= 32767 ||
|
||||
(!excludedHookPrograms.empty() && !SetEnvironmentVariableW(
|
||||
L"WINE_ACCESS_EXCLUDED_HOOK_PROGRAMS", excludedHookPrograms.data()))) {
|
||||
std::fprintf(stderr, "wine-access: cannot configure hook exclusions\n");
|
||||
return 1;
|
||||
}
|
||||
if (!validReader) {
|
||||
std::fprintf(stderr, "wine-access: --reader requires cthulhu or orca\n");
|
||||
return 1;
|
||||
|
||||
+12
-3
@@ -95,7 +95,8 @@ with the program's own loader, display and bus, and
|
||||
loader is resolved to the game's real Proton `files/bin/wine` (Protontricks'
|
||||
proxy `WINELOADER` is bypassed), the game's `WINEESYNC`/`WINEFSYNC` are
|
||||
forwarded so the helper joins the running server, and the helper set is
|
||||
staged under the state directory because the container's wineserver cannot
|
||||
staged as complete sets in separate content-hash directories under the
|
||||
state directory because the container's wineserver cannot
|
||||
see a system `/usr/libexec` installation; see the main README's Steam
|
||||
section.
|
||||
|
||||
@@ -108,8 +109,16 @@ preferences offer controller-only mode: helpers run with
|
||||
`--no-dialog-reader`, injecting nothing and polling no controls, while
|
||||
NVDA/Tolk speech and braille keep working. Enable it for all
|
||||
applications there, or list executable names (e.g. `Diablo IV.exe`) to
|
||||
apply it per game. Settings are read when a helper starts, so neither
|
||||
Orca nor the reader needs a restart; relaunch the game to switch modes.
|
||||
apply it per game. Every helper receives the full list at startup; both
|
||||
native hook hosts check the target executable before attachment, including
|
||||
when a game starts after its launcher. The supervisor also switches the
|
||||
prefix's helper to controller-only when it discovers a listed game.
|
||||
|
||||
Settings apply to newly started helpers. After changing the list, close the
|
||||
affected Wine applications, restart Orca to replace existing helpers, and then
|
||||
relaunch the applications. Restarting only the helper cannot remove hook DLLs
|
||||
already pinned inside an application. Names are matched case-insensitively by
|
||||
executable basename; directory paths are not accepted.
|
||||
`WINE_ACCESS_NO_DIALOG_READER=1` in Orca's environment forces the same
|
||||
mode for every helper, for testing.
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"""Prefix discovery and helper supervision against a fake /proc."""
|
||||
|
||||
import os
|
||||
import mmap
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -115,13 +116,14 @@ class DiscoveryTests(unittest.TestCase):
|
||||
def test_controller_only_arguments_accepts_tuple(self):
|
||||
# GSettings layers may hand string arrays back as tuples.
|
||||
self.assertEqual(controller_only_arguments({"game.exe"}, ("Game.EXE",), False),
|
||||
["--no-dialog-reader"])
|
||||
["--exclude-hook-program", "game.exe", "--no-dialog-reader"])
|
||||
|
||||
def test_controller_only_arguments_matching(self):
|
||||
self.assertEqual(controller_only_arguments({"game.exe"}, [], False), [])
|
||||
self.assertEqual(controller_only_arguments({"game.exe"}, ["Game.EXE"], False),
|
||||
["--no-dialog-reader"])
|
||||
self.assertEqual(controller_only_arguments({"other.exe"}, ["game.exe"], False), [])
|
||||
["--exclude-hook-program", "game.exe", "--no-dialog-reader"])
|
||||
self.assertEqual(controller_only_arguments({"other.exe"}, ["game.exe"], False),
|
||||
["--exclude-hook-program", "game.exe"])
|
||||
self.assertEqual(controller_only_arguments(set(), [], True),
|
||||
["--no-dialog-reader"])
|
||||
|
||||
@@ -308,6 +310,7 @@ class SupervisionTests(unittest.TestCase):
|
||||
self.assertEqual(helper.env["WINEFSYNC"], "1")
|
||||
|
||||
def test_steam_game_helper_uses_host_bus_not_container_proxy(self):
|
||||
self.make_helper()
|
||||
wine, preloader = self.fake.proton()
|
||||
self.fake.remove(20)
|
||||
self.fake.add_path(24, preloader, {
|
||||
@@ -348,20 +351,58 @@ class SupervisionTests(unittest.TestCase):
|
||||
}, r"S:\games\game.exe")
|
||||
self.manager.poll()
|
||||
self.assertEqual(len(self.spawned), 1)
|
||||
staged = self.fake.root / "logs" / "helper" / "wine-access.exe"
|
||||
self.assertEqual(self.spawned[0].command[0], str(staged))
|
||||
staged = Path(self.spawned[0].command[0])
|
||||
self.assertEqual(staged.parent.parent, self.fake.root / "logs" / "helper")
|
||||
self.assertEqual((staged.parent / "wine-access.exe.so").read_text(),
|
||||
"content of wine-access.exe.so")
|
||||
self.assertEqual((staged.parent / "wine-access-menu.dll").read_text(),
|
||||
"content of wine-access-menu.dll")
|
||||
|
||||
def make_helper(self):
|
||||
origin = self.fake.root / "installed"
|
||||
origin.mkdir()
|
||||
for name in ("wine-access.exe", "wine-access.exe.so", *manager_module.HELPER_SIBLINGS):
|
||||
(origin / name).write_bytes(b"old-build-content")
|
||||
(origin / name).chmod(0o755)
|
||||
self.manager.helper = str(origin / "wine-access.exe")
|
||||
return origin
|
||||
|
||||
def test_staging_update_preserves_running_mapping_and_complete_old_set(self):
|
||||
origin = self.make_helper()
|
||||
source = {"PRESSURE_VESSEL_RUNTIME": "steamrt4"}
|
||||
old = Path(self.manager._helper_for(source))
|
||||
self.assertEqual(self.manager._helper_for(source), str(old))
|
||||
with (old.parent / "wine-access.exe.so").open("rb") as file:
|
||||
with mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as mapping:
|
||||
for path in origin.iterdir():
|
||||
path.write_bytes(b"NEW-build-content")
|
||||
new = Path(self.manager._helper_for(source))
|
||||
self.assertNotEqual(old.parent, new.parent)
|
||||
self.assertEqual(mapping[:], b"old-build-content")
|
||||
for path in new.parent.iterdir():
|
||||
self.assertEqual(path.read_bytes(), b"NEW-build-content")
|
||||
for path in old.parent.iterdir():
|
||||
self.assertEqual(path.read_bytes(), b"old-build-content")
|
||||
|
||||
def test_missing_helper_sibling_prevents_spawn_and_backs_off(self):
|
||||
origin = self.make_helper()
|
||||
self.manager._helper_for({"PRESSURE_VESSEL_RUNTIME": "steamrt4"})
|
||||
(origin / "wine-access-menu32.dll").unlink()
|
||||
self.fake.remove(20)
|
||||
self.fake.add(20, "wine", {"WINEPREFIX": "/p/game", "DISPLAY": ":7",
|
||||
"PRESSURE_VESSEL_RUNTIME": "steamrt4"})
|
||||
self.manager.poll()
|
||||
self.assertEqual(self.spawned, [])
|
||||
self.assertGreater(self.manager.prefixes[self.prefix].next_start, self.now)
|
||||
|
||||
def test_listed_program_starts_controller_only_helper(self):
|
||||
self.manager.arguments_for = (
|
||||
lambda programs: controller_only_arguments(programs, ["App.EXE"]))
|
||||
self.manager.poll()
|
||||
self.assertEqual(len(self.spawned), 1)
|
||||
self.assertEqual(self.spawned[0].command,
|
||||
["/helper.exe", "--reader", "orca", "--no-dialog-reader"])
|
||||
["/helper.exe", "--reader", "orca", "--exclude-hook-program",
|
||||
"app.exe", "--no-dialog-reader"])
|
||||
|
||||
def test_listed_program_appearing_later_restarts_controller_only(self):
|
||||
# A loader process can be discovered before the game itself, so a
|
||||
@@ -372,6 +413,8 @@ class SupervisionTests(unittest.TestCase):
|
||||
self.manager.poll()
|
||||
self.assertEqual(len(self.spawned), 1)
|
||||
self.assertNotIn("--no-dialog-reader", self.spawned[0].command)
|
||||
self.assertEqual(self.spawned[0].command[-2:],
|
||||
["--exclude-hook-program", "game.exe"])
|
||||
self.fake.add(26, "wine", {"WINEPREFIX": "/p/game", "DISPLAY": ":7"},
|
||||
r"S:\games\Game.exe")
|
||||
self.manager.poll()
|
||||
|
||||
@@ -67,7 +67,8 @@ class WineAccess(Extension):
|
||||
"Controller-only helpers serve NVDA/Tolk speech without "
|
||||
"injecting hooks or reading standard controls. Use it for "
|
||||
"games whose anti-tamper code objects to injected hooks. "
|
||||
"Changes apply the next time a helper starts."),
|
||||
"Changes apply to new helpers. Close Wine applications and restart Orca "
|
||||
"before relaunching them to apply a changed list."),
|
||||
]
|
||||
|
||||
def _helper_arguments(self, programs: set[str]) -> list[str]:
|
||||
|
||||
+41
-19
@@ -16,6 +16,7 @@ from pathlib import Path
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
from typing import Callable
|
||||
|
||||
@@ -98,10 +99,17 @@ def controller_only_arguments(programs: set[str], listed,
|
||||
"""
|
||||
|
||||
names = {name.lower() for name in listed
|
||||
if isinstance(name, str)} if isinstance(listed, (list, tuple)) else set()
|
||||
if isinstance(name, str) and name and not any(
|
||||
char in name for char in "\n\r\0/\\")
|
||||
} if isinstance(listed, (list, tuple)) else set()
|
||||
# Every helper must know the exclusions before a game exists in /proc.
|
||||
# The native hosts check these names before injecting either hook.
|
||||
arguments = []
|
||||
for name in sorted(names):
|
||||
arguments.extend(("--exclude-hook-program", name))
|
||||
if always or programs & names:
|
||||
return ["--no-dialog-reader"]
|
||||
return []
|
||||
arguments.append("--no-dialog-reader")
|
||||
return arguments
|
||||
|
||||
|
||||
def find_helper() -> str | None:
|
||||
@@ -369,22 +377,36 @@ class HelperManager:
|
||||
if "PRESSURE_VESSEL_RUNTIME" not in source:
|
||||
return self.helper
|
||||
origin = Path(self.helper)
|
||||
stage = self.log_directory / "helper"
|
||||
try:
|
||||
stage.mkdir(parents=True, exist_ok=True)
|
||||
names = [origin.name, origin.name + ".so", *HELPER_SIBLINGS]
|
||||
for name in names:
|
||||
source_file = origin.parent / name
|
||||
target = stage / name
|
||||
if not source_file.is_file():
|
||||
continue
|
||||
if target.is_file() and target.read_bytes() == source_file.read_bytes():
|
||||
continue
|
||||
shutil.copy2(source_file, target)
|
||||
except OSError:
|
||||
return self.helper
|
||||
staged = stage / origin.name
|
||||
return str(staged) if staged.is_file() else self.helper
|
||||
names = [origin.name, origin.name + ".so", *HELPER_SIBLINGS]
|
||||
# Read the complete set before publishing anything. Missing files are
|
||||
# a failed start, never a reason to reuse stale staged siblings.
|
||||
contents = {name: (origin.parent / name).read_bytes() for name in names}
|
||||
digest = hashlib.sha256()
|
||||
for name, data in contents.items():
|
||||
digest.update(name.encode() + b"\0")
|
||||
digest.update(len(data).to_bytes(8, "big"))
|
||||
digest.update(data)
|
||||
stageRoot = self.log_directory / "helper"
|
||||
stageRoot.mkdir(parents=True, exist_ok=True)
|
||||
stage = stageRoot / digest.hexdigest()
|
||||
if not stage.exists():
|
||||
with tempfile.TemporaryDirectory(prefix=".stage-", dir=stageRoot) as temporary:
|
||||
pending = Path(temporary) / "complete"
|
||||
pending.mkdir()
|
||||
for name, data in contents.items():
|
||||
target = pending / name
|
||||
target.write_bytes(data)
|
||||
target.chmod(0o755 if os.access(origin.parent / name, os.X_OK) else 0o644)
|
||||
try:
|
||||
pending.rename(stage)
|
||||
except OSError:
|
||||
# Another supervisor may have published the identical set.
|
||||
if not stage.is_dir():
|
||||
raise
|
||||
for name, data in contents.items():
|
||||
if (stage / name).read_bytes() != data:
|
||||
raise OSError("Incomplete or modified staged Wine Access helper")
|
||||
return str(stage / origin.name)
|
||||
|
||||
def _command(self, source: dict[str, str], programs: set[str]) -> list[str]:
|
||||
return [self._helper_for(source), *self.reader_arguments,
|
||||
|
||||
@@ -829,3 +829,39 @@ D-Bus events do not establish audible speech or physical Braille acceptance.
|
||||
If the helper reports that the reader service is unavailable, verify its
|
||||
session bus matches Cthulhu's, even when the application was launched from a
|
||||
different bus. The reader's helper launcher owns that environment policy.
|
||||
|
||||
## Proton staging and pre-attachment exclusions
|
||||
|
||||
Run `python3 -m unittest discover -s orca/tests -p 'test_*.py'` for manager,
|
||||
installed-Orca lifecycle, and existing presentation/review checks. Manager
|
||||
regressions cover complete staged sets, preservation of an older memory-mapped
|
||||
sidecar across an update, missing-file startup failure/backoff, and passing
|
||||
exclusions to a launcher helper before a listed game is discovered.
|
||||
|
||||
Build normally, then run `xvfb-run -a ctest --test-dir build --output-on-failure`.
|
||||
The hook-exclusions32/64 fixtures exercise actual process-image lookup,
|
||||
case-insensitive basename matching, multiple entries, and refusal when a
|
||||
configured target cannot be identified. These check the shared guard used by
|
||||
both native hook hosts; they do not establish anti-tamper compatibility.
|
||||
|
||||
Run the actual attachment checks sequentially on a private display:
|
||||
|
||||
```sh
|
||||
xvfb-run -a python3 tests/menu_integration.py --build-dir build --fixture hooks --exclude-hooks
|
||||
xvfb-run -a python3 tests/menu_integration.py --build-dir build --fixture hooks --exclude-hooks --32-bit
|
||||
```
|
||||
|
||||
These start a full helper before an excluded executable, exercise foreground
|
||||
switches, and assert that neither native hook DLL is loaded into that process.
|
||||
The executable name contains a space and differs in case from the exclusion.
|
||||
Run the same checks without `--exclude-hooks` to verify normal attachment.
|
||||
|
||||
For live acceptance, configure an exclusion before starting helpers, launch a
|
||||
game through its launcher, and verify that its process never loads either
|
||||
Wine Access hook DLL while NVDA/Tolk announcements continue. Check both
|
||||
architectures where available. Also test two Proton prefixes across a helper
|
||||
upgrade: the earlier process must retain its original files while the later
|
||||
one uses a separate complete set. Check ordinary Wine menus, editor navigation,
|
||||
password exclusion, speech and Braille separately. After changing exclusions,
|
||||
close affected applications and restart Orca before relaunching them; pinned
|
||||
DLLs cannot be removed by a helper restart.
|
||||
@@ -0,0 +1,33 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#include "../foreground_hooks.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
HANDLE process = GetCurrentProcess();
|
||||
WCHAR image[32768];
|
||||
DWORD length = 32768;
|
||||
assert(QueryFullProcessImageNameW(process, 0, image, &length));
|
||||
WCHAR *name = image;
|
||||
for (DWORD index = 0; index < length; ++index)
|
||||
if (image[index] == L'\\' || image[index] == L'/') name = image + index + 1;
|
||||
|
||||
SetEnvironmentVariableW(L"WINE_ACCESS_EXCLUDED_HOOK_PROGRAMS", NULL);
|
||||
assert(wine_access_hooks_allowed(process));
|
||||
assert(SetEnvironmentVariableW(L"WINE_ACCESS_EXCLUDED_HOOK_PROGRAMS", L"Other Game.exe\n"));
|
||||
assert(wine_access_hooks_allowed(process));
|
||||
assert(!wine_access_hooks_allowed(NULL));
|
||||
assert(SetEnvironmentVariableW(L"WINE_ACCESS_EXCLUDED_HOOK_PROGRAMS", name));
|
||||
assert(!wine_access_hooks_allowed(process));
|
||||
CharUpperBuffW(name, lstrlenW(name));
|
||||
assert(SetEnvironmentVariableW(L"WINE_ACCESS_EXCLUDED_HOOK_PROGRAMS", name));
|
||||
assert(!wine_access_hooks_allowed(process));
|
||||
WCHAR listed[32768] = L"Other Game.exe\n";
|
||||
lstrcatW(listed, name);
|
||||
lstrcatW(listed, L"\nThird Game.exe\n");
|
||||
assert(SetEnvironmentVariableW(L"WINE_ACCESS_EXCLUDED_HOOK_PROGRAMS", listed));
|
||||
assert(!wine_access_hooks_allowed(process));
|
||||
SetEnvironmentVariableW(L"WINE_ACCESS_EXCLUDED_HOOK_PROGRAMS", NULL);
|
||||
puts("PASS: hook exclusions check the actual process before attachment");
|
||||
return 0;
|
||||
}
|
||||
@@ -72,6 +72,9 @@ int main(void) {
|
||||
pump(600);
|
||||
BOOL restored = GetForegroundWindow() == window && attached_on_focus(window);
|
||||
BOOL detached = !SendMessageW(worker_window, WM_APP, 0, 0);
|
||||
BOOL excluded = GetEnvironmentVariableA("WINE_ACCESS_EXPECT_NO_HOOKS", NULL, 0) != 0;
|
||||
BOOL loaded = GetModuleHandleW(L"wine-access-menu.dll") != NULL ||
|
||||
GetModuleHandleW(L"wine-access-menu32.dll") != NULL;
|
||||
printf("hook scope: initial=%d background=%d switched=%d old-thread=%d restored=%d detached=%d\n",
|
||||
first, background, switched, old_thread, restored, detached);
|
||||
PostMessageW(worker_window, WM_CLOSE, 0, 0);
|
||||
@@ -79,5 +82,9 @@ int main(void) {
|
||||
CloseHandle(thread);
|
||||
CloseHandle(ready);
|
||||
DestroyWindow(window);
|
||||
if (excluded) {
|
||||
printf("excluded process: hook DLL loaded=%d\n", loaded);
|
||||
return !first && !background && !switched && !old_thread && !restored && detached && !loaded ? 0 : 5;
|
||||
}
|
||||
return first && !background && switched && !old_thread && restored && detached ? 0 : 4;
|
||||
}
|
||||
@@ -26,8 +26,11 @@ parser.add_argument("--goldwave-exe", type=Path)
|
||||
parser.add_argument("--32-bit", dest="is32Bit", action="store_true")
|
||||
parser.add_argument("--late-helper", action="store_true")
|
||||
parser.add_argument("--restart-helper", action="store_true")
|
||||
parser.add_argument("--exclude-hooks", action="store_true")
|
||||
add_test_options(parser)
|
||||
args = parser.parse_args()
|
||||
if args.exclude_hooks and args.fixture != "hooks":
|
||||
parser.error("--exclude-hooks requires --fixture hooks")
|
||||
if args.is32Bit and args.fixture not in ("menu", "edit", "hooks", "winforms", "list", "listbox", "delphi", "controls", "foobar-controls", "bootstrapper"):
|
||||
parser.error("32-bit checks currently require --fixture menu, edit, hooks, winforms, list, listbox, delphi, controls or bootstrapper")
|
||||
if (args.late_helper or args.restart_helper) and args.fixture not in ("edit", "winforms", "scintilla"):
|
||||
@@ -47,13 +50,16 @@ if not args.session:
|
||||
*(["--goldwave-exe", str(args.goldwave_exe.resolve())] if args.goldwave_exe else []),
|
||||
*(["--32-bit"] if args.is32Bit else []),
|
||||
*(["--late-helper"] if args.late_helper else []),
|
||||
*(["--restart-helper"] if args.restart_helper else [])], build, "menu_integration",
|
||||
*(["--restart-helper"] if args.restart_helper else []),
|
||||
*(["--exclude-hooks"] if args.exclude_hooks else [])], build, "menu_integration",
|
||||
keep=args.keep, keepOnFailure=args.keepOnFailure))
|
||||
|
||||
busName = "org.gnome.Orca1.Service" if args.reader == "orca" else "org.stormux.Cthulhu1.Service"
|
||||
interface = busName.rsplit(".", 1)[0] + ".WineAccess" if args.extension_endpoint else busName
|
||||
object_path = "/" + busName.replace(".", "/") + ("/WineAccess" if args.extension_endpoint else "")
|
||||
readerArguments = ["--reader", args.reader] if args.reader else []
|
||||
if args.exclude_hooks:
|
||||
readerArguments += ["--exclude-hook-program", "EXCLUDED GAME.EXE"]
|
||||
if args.extension_endpoint:
|
||||
readerArguments += ["--reader-path", object_path, "--reader-interface", interface]
|
||||
xml = '<node><interface name="' + interface + '"><method name="PresentAccessibleEvent">'
|
||||
@@ -103,7 +109,10 @@ with wine_test_directory(prefix="wine-access-menus-") as temporary:
|
||||
"x" * 1100000 + "\r\n" + "x" * 1022 + "😀tail").encode("utf-8"))
|
||||
env["WINE_ACCESS_NOTEPADPP_EXE"] = "Z:" + str(appDir / args.notepadpp_exe.name).replace("/", "\\")
|
||||
env["WINE_ACCESS_SCINTILLA_DOCUMENT"] = "Z:" + str(document).replace("/", "\\")
|
||||
fixture = Path(temporary) / ("foobar2000.exe" if args.fixture == "foobar-controls" else "menu-fixture.exe")
|
||||
fixture = Path(temporary) / ("Excluded Game.exe" if args.exclude_hooks else
|
||||
"foobar2000.exe" if args.fixture == "foobar-controls" else "menu-fixture.exe")
|
||||
if args.exclude_hooks:
|
||||
env["WINE_ACCESS_EXPECT_NO_HOOKS"] = "1"
|
||||
compiler = "i686-w64-mingw32-gcc" if args.is32Bit or args.fixture == "goldwave" else "x86_64-w64-mingw32-gcc"
|
||||
sourceName = "edit" if args.fixture == "winforms" else "controls" if args.fixture == "foobar-controls" else args.fixture
|
||||
if args.fixture == "delphi":
|
||||
@@ -158,7 +167,8 @@ with wine_test_directory(prefix="wine-access-menus-") as temporary:
|
||||
pass
|
||||
time.sleep(0.01)
|
||||
if args.fixture == "hooks":
|
||||
print("PASS: hooks follow only the foreground UI thread, detach and reattach")
|
||||
print("PASS: excluded process never loads hook DLLs" if args.exclude_hooks else
|
||||
"PASS: hooks follow only the foreground UI thread, detach and reattach")
|
||||
sys.exit(0)
|
||||
focused = None
|
||||
for event in events:
|
||||
|
||||
Reference in new issue
Block a user