diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-02-16 15:26:47 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-02-17 13:02:40 +0100 |
| commit | 623a102b094ff85bcc98e60a424ff18df66cc747 (patch) | |
| tree | dfd0b18348400d40843afbe7d6c3bc8094a54659 /windows/nsis-plugins/src/os/update.cpp | |
| parent | 9f1eeca0791459be6d62bfd7ea687fdfc4833dc8 (diff) | |
| download | mullvadvpn-623a102b094ff85bcc98e60a424ff18df66cc747.tar.xz mullvadvpn-623a102b094ff85bcc98e60a424ff18df66cc747.zip | |
Add "os" NSIS plugin
Diffstat (limited to 'windows/nsis-plugins/src/os/update.cpp')
| -rw-r--r-- | windows/nsis-plugins/src/os/update.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/windows/nsis-plugins/src/os/update.cpp b/windows/nsis-plugins/src/os/update.cpp new file mode 100644 index 0000000000..2f349ac687 --- /dev/null +++ b/windows/nsis-plugins/src/os/update.cpp @@ -0,0 +1,40 @@ +#include <stdafx.h> +#include "update.h" +#include <libcommon/error.h> +#include <libcommon/filesystem.h> +#include <algorithm> +#include <fstream> +#include <filesystem> + +namespace +{ + +// Jason found this to be a reliable marker of the signature check fix: +// https://git.zx2c4.com/wireguard-windows/tree/installer/customactions.c#n145 +const char PATCH_MARKER[] = "Signature Hash"; + +} + +namespace update +{ + +bool HasSetupApiSha2Fix() +{ + common::fs::ScopedNativeFileSystem nativeFileSystem; + + const auto systemDir = common::fs::GetKnownFolderPath(FOLDERID_System, KF_FLAG_DEFAULT, NULL); + const auto setupApiPath = std::filesystem::path(systemDir).append(L"setupapi.dll"); + + std::ifstream ifs(setupApiPath, std::ios_base::binary); + if (!ifs) + { + // Maybe sketchy to rely on GLE here + THROW_WINDOWS_ERROR(GetLastError(), "Failed to open setupapi.dll"); + } + + const auto marker_end = PATCH_MARKER + sizeof(PATCH_MARKER) - sizeof('\0'); + const auto last = std::istreambuf_iterator<char>(); + return (last != std::search(std::istreambuf_iterator<char>(ifs), last, PATCH_MARKER, marker_end)); +} + +} |
