diff options
Diffstat (limited to 'installer/customactions.c')
-rw-r--r-- | installer/customactions.c | 94 |
1 files changed, 3 insertions, 91 deletions
diff --git a/installer/customactions.c b/installer/customactions.c index 981415e1..d3078a31 100644 --- a/installer/customactions.c +++ b/installer/customactions.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT /* - * Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved. + * Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved. */ #include <windows.h> @@ -96,7 +96,7 @@ __declspec(dllexport) UINT __stdcall CheckWow64(MSIHANDLE installer) log_errorf(installer, LOG_LEVEL_ERR, ret, TEXT("Failed to get kernel32.dll handle")); goto out; } - IsWow64Process2 = (void *)GetProcAddress(kernel32, "IsWow64Process2"); + *(FARPROC *)&IsWow64Process2 = GetProcAddress(kernel32, "IsWow64Process2"); if (IsWow64Process2) { if (!IsWow64Process2(GetCurrentProcess(), &process_machine, &native_machine)) { ret = GetLastError(); @@ -122,94 +122,6 @@ out: return ret; } -extern NTAPI __declspec(dllimport) void RtlGetNtVersionNumbers(DWORD *MajorVersion, DWORD *MinorVersion, DWORD *BuildNumber); - -static int message_box(MSIHANDLE installer, TCHAR *text, UINT type) -{ - TCHAR progressOnly[2]; - DWORD len; - MSIHANDLE record; - int ret; - - len = _countof(progressOnly); - if (MsiGetProperty(installer, TEXT("MsiUIProgressOnly"), progressOnly, &len) == ERROR_SUCCESS && _tcstoul(progressOnly, NULL, 10) == 1) - return MessageBox(GetForegroundWindow(), text, TEXT("WireGuard"), type); - record = MsiCreateRecord(2); - MsiRecordSetString(record, 0, TEXT("[1]")); - MsiRecordSetString(record, 1, text); - ret = MsiProcessMessage(installer, INSTALLMESSAGE_USER | type, record); - MsiCloseHandle(record); - return ret; -} - -__declspec(dllexport) UINT __stdcall CheckKB2921916(MSIHANDLE installer) -{ - bool is_com_initialized = SUCCEEDED(CoInitialize(NULL)); - UINT ret = ERROR_SUCCESS; - DWORD maj, min, build, len; - TCHAR uiLevel[10]; - TCHAR setupapi_path[MAX_PATH]; - HANDLE setupapi_handle = INVALID_HANDLE_VALUE; - HANDLE setupapi_filemapping = NULL; - const char *setupapi_bytes = NULL; - MEMORY_BASIC_INFORMATION setupapi_meminfo; - static const char setupapi_marker[] = "Signature Hash"; - - RtlGetNtVersionNumbers(&maj, &min, &build); - if (maj != 6 || min != 1) - goto out; - - ret = ERROR_INSTALL_FAILURE; - if (!GetSystemDirectory(setupapi_path, _countof(setupapi_path))) - goto out; - if (!PathAppend(setupapi_path, TEXT("setupapi.dll"))) - goto out; - setupapi_handle = CreateFile(setupapi_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (setupapi_handle == INVALID_HANDLE_VALUE) - goto out; - setupapi_filemapping = CreateFileMapping(setupapi_handle, NULL, PAGE_READONLY, 0, 0, NULL); - if (!setupapi_filemapping) - goto out; - setupapi_bytes = MapViewOfFile(setupapi_filemapping, FILE_MAP_READ, 0, 0, 0); - if (!setupapi_bytes) - goto out; - if (VirtualQuery(setupapi_bytes, &setupapi_meminfo, sizeof(setupapi_meminfo)) != sizeof(setupapi_meminfo)) - goto out; - if (setupapi_meminfo.RegionSize > strlen(setupapi_marker)) { - for (const char *p = setupapi_bytes + strlen(setupapi_marker) - 1; (p = memchr(p, 'h', setupapi_meminfo.RegionSize - (p - setupapi_bytes))); ++p) { - if (!memcmp(p - strlen(setupapi_marker) + 1, setupapi_marker, strlen(setupapi_marker))) { - ret = ERROR_SUCCESS; - goto out; - } - } - } - - len = _countof(uiLevel); - if (MsiGetProperty(installer, TEXT("UILevel"), uiLevel, &len) != ERROR_SUCCESS || _tcstoul(uiLevel, NULL, 10) < INSTALLUILEVEL_BASIC) { - log_messagef(installer, LOG_LEVEL_MSIERR, TEXT("Use of WireGuard on Windows 7 requires KB2921916.")); - goto out; - } -#ifdef _WIN64 - static const TCHAR url[] = TEXT("https://download.wireguard.com/windows-toolchain/distfiles/Windows6.1-KB2921916-x64.msu"); -#else - static const TCHAR url[] = TEXT("https://download.wireguard.com/windows-toolchain/distfiles/Windows6.1-KB2921916-x86.msu"); -#endif - if (message_box(installer, TEXT("Missing Windows Hotfix\n\nUse of WireGuard on Windows 7 requires KB2921916. Would you like to download the hotfix in your web browser?"), MB_ICONWARNING | MB_YESNO) == IDYES) - ShellExecute(GetForegroundWindow(), NULL, url, NULL, NULL, SW_SHOWNORMAL); - ret = ERROR_INSTALL_USEREXIT; - -out: - if (setupapi_bytes) - UnmapViewOfFile(setupapi_bytes); - if (setupapi_filemapping) - CloseHandle(setupapi_filemapping); - if (setupapi_handle != INVALID_HANDLE_VALUE) - CloseHandle(setupapi_handle); - if (is_com_initialized) - CoUninitialize(); - return ret; -} - static UINT insert_service_control(MSIHANDLE installer, MSIHANDLE view, const TCHAR *service_name, bool start) { static unsigned int index = 0; @@ -607,7 +519,7 @@ __declspec(dllexport) UINT __stdcall RemoveAdapters(MSIHANDLE installer) log_errorf(installer, LOG_LEVEL_WARN, GetLastError(), TEXT("SetHandleInformation failed")); goto cleanup_pipe_w; } - if (!CreateProcess(path, TEXT("wireguard /removealladapters"), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { + if (!CreateProcess(path, TEXT("wireguard /removedriver"), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { log_errorf(installer, LOG_LEVEL_WARN, GetLastError(), TEXT("Failed to create \"%1\" process"), path); goto cleanup_pipe_w; } |