Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/install-helper/install-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,50 @@ DWORD StopXenbusMonitor()
return status;
}

/*
* Automatically accept the prompt for installing test-signed drivers.
*/
DWORD ApproveTestSign(void* param)
{
while (TRUE)
{
HWND window = FindWindow(NULL, L"Windows Security");
if (window)
{
DWORD fg_tid = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
DWORD tid = GetCurrentThreadId();
// Without this, focus-stealing mitigations can prevent activating the target window.
if (tid != fg_tid)
AttachThreadInput(fg_tid, tid, TRUE);

BringWindowToTop(window);
ShowWindow(window, SW_SHOW);

while (GetForegroundWindow() != window)
Sleep(100);

INPUT inputs[2];
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = 'i';
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[1].ki.wVk = 'i';
SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
break;
}
else
{
Sleep(100);
}
}
return 0;
}

int WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
{
(void)AddSymlinkRightToUsers();
HANDLE thread = CreateThread(NULL, 0, ApproveTestSign, NULL, 0, NULL);
if (WaitForSingleObject(thread, 30000) == WAIT_TIMEOUT)
TerminateThread(thread, 0);
return (int)StopXenbusMonitor();
}