aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-12 11:48:18 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-16 18:17:05 +0100
commite92bb742a4666517a4b586d6dda7d1de8425164c (patch)
tree63a5b97ab070efec419f6fd840e917128dee72b1
parentbuild: make more robust to partial rebuilds (diff)
downloadwireguard-windows-e92bb742a4666517a4b586d6dda7d1de8425164c.tar.xz
wireguard-windows-e92bb742a4666517a4b586d6dda7d1de8425164c.zip
installer: prohibit Wow64 installs
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--installer/customactions.c46
-rw-r--r--installer/wireguard.wxs8
2 files changed, 53 insertions, 1 deletions
diff --git a/installer/customactions.c b/installer/customactions.c
index 2629cbc8..5fe94aec 100644
--- a/installer/customactions.c
+++ b/installer/customactions.c
@@ -17,7 +17,7 @@
#define MANAGER_SERVICE_NAME TEXT("WireGuardManager")
#define TUNNEL_SERVICE_PREFIX TEXT("WireGuardTunnel$")
-enum log_level { LOG_LEVEL_INFO, LOG_LEVEL_WARN, LOG_LEVEL_ERR };
+enum log_level { LOG_LEVEL_INFO, LOG_LEVEL_WARN, LOG_LEVEL_ERR, LOG_LEVEL_MSIERR };
static void log_messagef(MSIHANDLE installer, enum log_level level, const TCHAR *format, ...)
{
@@ -49,6 +49,10 @@ static void log_messagef(MSIHANDLE installer, enum log_level level, const TCHAR
template = TEXT("WireGuard error: [1]");
type = INSTALLMESSAGE_ERROR;
break;
+ case LOG_LEVEL_MSIERR:
+ template = TEXT("[1]");
+ type = INSTALLMESSAGE_ERROR;
+ break;
default:
goto out;
}
@@ -491,3 +495,43 @@ out:
CoUninitialize();
return ERROR_SUCCESS;
}
+
+__declspec(dllexport) UINT __stdcall CheckWow64(MSIHANDLE installer)
+{
+ UINT ret = ERROR_SUCCESS;
+ bool is_com_initialized = SUCCEEDED(CoInitialize(NULL));
+ HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
+ BOOL(WINAPI *IsWow64Process2)(HANDLE hProcess, USHORT *pProcessMachine, USHORT *pNativeMachine);
+ USHORT process_machine, native_machine;
+ BOOL is_wow64_process;
+
+ if (!kernel32) {
+ ret = GetLastError();
+ log_errorf(installer, LOG_LEVEL_ERR, ret, TEXT("Failed to get kernel32.dll handle"));
+ goto out;
+ }
+ IsWow64Process2 = (void *)GetProcAddress(kernel32, "IsWow64Process2");
+ if (IsWow64Process2) {
+ if (!IsWow64Process2(GetCurrentProcess(), &process_machine, &native_machine)) {
+ ret = GetLastError();
+ log_errorf(installer, LOG_LEVEL_ERR, ret, TEXT("Failed to determine Wow64 status from IsWow64Process2"));
+ goto out;
+ }
+ if (process_machine == IMAGE_FILE_MACHINE_UNKNOWN)
+ goto out;
+ } else {
+ if (!IsWow64Process(GetCurrentProcess(), &is_wow64_process)) {
+ ret = GetLastError();
+ log_errorf(installer, LOG_LEVEL_ERR, ret, TEXT("Failed to determine Wow64 status from IsWow64Process"));
+ goto out;
+ }
+ if (!is_wow64_process)
+ goto out;
+ }
+ log_messagef(installer, LOG_LEVEL_MSIERR, TEXT("You must use the native version of WireGuard on this computer."));
+ ret = ERROR_INSTALL_FAILURE;
+out:
+ if (is_com_initialized)
+ CoUninitialize();
+ return ret;
+}
diff --git a/installer/wireguard.wxs b/installer/wireguard.wxs
index 8b18189f..e675954a 100644
--- a/installer/wireguard.wxs
+++ b/installer/wireguard.wxs
@@ -92,6 +92,14 @@
</Feature>
<!--
+ Abort early if running under Wow64
+ -->
+ <CustomAction Id="CheckWow64" BinaryKey="customactions.dll" DllEntry="CheckWow64" />
+ <InstallExecuteSequence>
+ <Custom Action="CheckWow64" After="FindRelatedProducts" />
+ </InstallExecuteSequence>
+
+ <!--
Evaluate WireGuard services and populate ServiceControl table
-->
<CustomAction Id="EvaluateWireGuardServices" BinaryKey="customactions.dll" DllEntry="EvaluateWireGuardServices" />