From 4f64be278cf706aba504ffee54bd543ef53a872f Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 7 Mar 2017 09:11:44 -0800 Subject: [PATCH] UI/updater: Ignore 64bit files on 32bit windows This would cause people to download the 64bit files when they were on the 32bit version of windows, even though those files aren't meant to be installed. --- UI/win-update/updater/updater.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/UI/win-update/updater/updater.cpp b/UI/win-update/updater/updater.cpp index 23409d39f..ca0c44889 100644 --- a/UI/win-update/updater/updater.cpp +++ b/UI/win-update/updater/updater.cpp @@ -580,6 +580,27 @@ static bool NonCorePackageInstalled(const char *name) return false; } +static inline bool is_64bit_windows(void) +{ +#ifdef _WIN64 + return true; +#else + BOOL x86 = false; + bool success = !!IsWow64Process(GetCurrentProcess(), &x86); + return success && !!x86; +#endif +} + +static inline bool is_64bit_file(const char *file) +{ + if (!file) + return false; + + return strstr(file, "64bit") != nullptr || + strstr(file, "64.dll") != nullptr || + strstr(file, "64.exe") != nullptr; +} + #define UTF8ToWideBuf(wide, utf8) UTF8ToWide(wide, _countof(wide), utf8) #define WideToUTF8Buf(utf8, wide) WideToUTF8(utf8, _countof(utf8), wide) @@ -592,6 +613,8 @@ static bool AddPackageUpdateFiles(json_t *root, size_t idx, json_t *name = json_object_get(package, "name"); json_t *files = json_object_get(package, "files"); + bool isWin64 = is_64bit_windows(); + if (!json_is_array(files)) return true; if (!json_is_string(name)) @@ -628,6 +651,9 @@ static bool AddPackageUpdateFiles(json_t *root, size_t idx, if (strlen(hashUTF8) != BLAKE2_HASH_LENGTH * 2) continue; + if (!isWin64 && is_64bit_file(fileUTF8)) + continue; + /* convert strings to wide */ wchar_t sourceURL[1024];