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.
67 lines
2.8 KiB
C
67 lines
2.8 KiB
C
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
#include "menu_bridge.h"
|
|
#include "foreground_hooks.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
static WineAccessHookExclusions hookExclusions;
|
|
static WCHAR hookExclusionsValue[32767];
|
|
|
|
// Hook DLLs must match the application's architecture. This small PE host
|
|
// supplies 32-bit menu/editor hooks without requiring 32-bit Linux GLib/Winelib.
|
|
int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR args, int show) {
|
|
(void)instance; (void)previous; (void)show;
|
|
char *end;
|
|
DWORD parentId = strtoul(args, &end, 10);
|
|
HWND bridge = (HWND)(UINT_PTR)strtoul(end, &end, 10);
|
|
DWORD bridgeProcess = 0;
|
|
GetWindowThreadProcessId(bridge, &bridgeProcess);
|
|
if (!parentId || bridgeProcess != parentId) return 1;
|
|
HANDLE parent = OpenProcess(SYNCHRONIZE, FALSE, parentId);
|
|
if (!parent) return 1;
|
|
// The parent helper publishes its --exclude-hook-program list here. An
|
|
// unreadable list must not silently un-exclude a program: run no hooks.
|
|
DWORD exclusionsLength = GetEnvironmentVariableW(
|
|
L"WINE_ACCESS_EXCLUDE_HOOK_PROGRAMS", hookExclusionsValue, ARRAYSIZE(hookExclusionsValue));
|
|
if (exclusionsLength >= ARRAYSIZE(hookExclusionsValue)) {
|
|
fprintf(stderr, "wine-access: 32-bit hook exclusions unavailable\n");
|
|
CloseHandle(parent);
|
|
return 1;
|
|
}
|
|
if (exclusionsLength) wine_access_hook_exclusions_parse(&hookExclusions, hookExclusionsValue);
|
|
|
|
WCHAR path[4096] = {0};
|
|
DWORD length = GetModuleFileNameW(NULL, path, 4096);
|
|
WCHAR *name = NULL;
|
|
for (DWORD i = 0; i < length && i < 4096; ++i)
|
|
if (path[i] == L'\\' || path[i] == L'/') name = path + i + 1;
|
|
if (!length || length >= 4096 || !name ||
|
|
name - path + lstrlenW(L"wine-access-menu32.dll") >= 4096) {
|
|
CloseHandle(parent);
|
|
return 1;
|
|
}
|
|
lstrcpyW(name, L"wine-access-menu32.dll");
|
|
HMODULE module = LoadLibraryW(path);
|
|
HOOKPROC callback = module ? (HOOKPROC)GetProcAddress(module, "WineAccessMenuHook") : NULL;
|
|
HOOKPROC inputCallback = module ? (HOOKPROC)GetProcAddress(module, "WineAccessInputHook") : NULL;
|
|
WineAccessForegroundHooks hooks = {module, callback, inputCallback, NULL, NULL, 0, &hookExclusions};
|
|
if (!callback || !inputCallback)
|
|
fprintf(stderr, "wine-access: 32-bit menu/editor hooks unavailable (error %lu)\n", GetLastError());
|
|
if (callback && inputCallback) {
|
|
while (IsWindow(bridge)) {
|
|
wine_access_update_hooks(&hooks, TRUE);
|
|
DWORD result = MsgWaitForMultipleObjects(1, &parent, FALSE, 100, QS_ALLINPUT);
|
|
if (result == WAIT_OBJECT_0 || result == WAIT_FAILED) break;
|
|
MSG message;
|
|
while (PeekMessageW(&message, NULL, 0, 0, PM_REMOVE)) {
|
|
TranslateMessage(&message);
|
|
DispatchMessageW(&message);
|
|
}
|
|
}
|
|
wine_access_release_hooks(&hooks);
|
|
}
|
|
if (module) FreeLibrary(module);
|
|
CloseHandle(parent);
|
|
return callback && inputCallback ? 0 : 1;
|
|
}
|