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
+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,
|
||||
|
||||
Reference in new issue
Block a user