1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[net] fix incorrect architectures when querying for updates

This commit is contained in:
Pete Batard 2023-04-16 19:47:54 +01:00
parent f27dda1164
commit 6280e8020a
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
5 changed files with 33 additions and 39 deletions

View file

@ -625,17 +625,16 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
int status = 0;
const char* server_url = RUFUS_URL "/";
int i, j, k, max_channel, verbose = 0, verpos[4];
static const char* archname[] = {"win_x86", "win_x64", "win_arm", "win_arm64", "win_none"};
static const char* channel[] = {"release", "beta", "test"}; // release channel
const char* accept_types[] = {"*/*\0", NULL};
static const char* channel[] = { "release", "beta", "test" }; // release channel
const char* accept_types[] = { "*/*\0", NULL };
char* buf = NULL;
char agent[64], hostname[64], urlpath[128], sigpath[256];
DWORD dwSize, dwDownloaded, dwTotalSize, dwStatus;
BYTE *sig = NULL;
OSVERSIONINFOA os_version = {sizeof(OSVERSIONINFOA), 0, 0, 0, 0, ""};
OSVERSIONINFOA os_version = { sizeof(OSVERSIONINFOA), 0, 0, 0, 0, "" };
HINTERNET hSession = NULL, hConnection = NULL, hRequest = NULL;
URL_COMPONENTSA UrlParts = {sizeof(URL_COMPONENTSA), NULL, 1, (INTERNET_SCHEME)0,
hostname, sizeof(hostname), 0, NULL, 1, urlpath, sizeof(urlpath), NULL, 1};
URL_COMPONENTSA UrlParts = { sizeof(URL_COMPONENTSA), NULL, 1, (INTERNET_SCHEME)0,
hostname, sizeof(hostname), 0, NULL, 1, urlpath, sizeof(urlpath), NULL, 1 };
SYSTEMTIME ServerTime, LocalTime;
FILETIME FileTime;
int64_t local_time = 0, reg_time, server_time, update_interval;
@ -734,10 +733,10 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
// and then remove each of the <os_> components until we find our match. For instance, we may first
// look for rufus_win_x64_6.2.ver (Win8 x64) but only get a match for rufus_win_x64_6.ver (Vista x64 or later)
// This allows sunsetting OS versions (eg XP) or providing different downloads for different archs/groups.
static_sprintf(urlpath, "%s%s%s_%s_%lu.%lu.ver", APPLICATION_NAME, (k==0)?"":"_",
(k==0)?"":channel[k], archname[GetCpuArch()], os_version.dwMajorVersion, os_version.dwMinorVersion);
static_sprintf(urlpath, "%s%s%s_win_%s_%lu.%lu.ver", APPLICATION_NAME, (k == 0) ? "": "_",
(k == 0) ? "" : channel[k], GetAppArchName(), os_version.dwMajorVersion, os_version.dwMinorVersion);
vuprintf("Base update check: %s", urlpath);
for (i=0, j=(int)safe_strlen(urlpath)-5; (j>0)&&(i<ARRAYSIZE(verpos)); j--) {
for (i = 0, j = (int)safe_strlen(urlpath) - 5; (j > 0) && (i < ARRAYSIZE(verpos)); j--) {
if ((urlpath[j] == '.') || (urlpath[j] == '_')) {
verpos[i++] = j;
}

View file

@ -1,7 +1,7 @@
/*
* Rufus: The Reliable USB Formatting Utility
* Elementary Unicode compliant find/replace parser
* Copyright © 2012-2022 Pete Batard <pete@akeo.ie>
* Copyright © 2012-2023 Pete Batard <pete@akeo.ie>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -914,14 +914,13 @@ void parse_update(char* buf, size_t len)
char allowed_rtf_chars[] = "abcdefghijklmnopqrstuvwxyz|~-_:*'";
char allowed_std_chars[] = "\r\n ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"$%^&+=<>(){}[].,;#@/?";
char download_url_name[24];
char *arch_names[5] = { "unknown", "x86", "x64", "arm", "arm64" };
// strchr includes the NUL terminator in the search, so take care of backslash before NUL
if ((buf == NULL) || (len < 2) || (len > 64 * KB) || (buf[len-1] != 0) || (buf[len-2] == '\\'))
return;
// Sanitize the data - Not a silver bullet, but it helps
len = safe_strlen(buf)+1; // Someone may be inserting NULs
for (i=0; i<len-1; i++) {
for (i = 0; i < len - 1; i++) {
// Check for valid RTF sequences as well as allowed chars if not RTF
if (buf[i] == '\\') {
// NB: we have a zero terminator, so we can afford a +1 without overflow
@ -933,25 +932,25 @@ void parse_update(char* buf, size_t len)
}
}
for (i=0; i<3; i++)
for (i = 0; i < 3; i++)
update.version[i] = 0;
update.platform_min[0] = 5;
update.platform_min[1] = 2; // XP or later
safe_free(update.download_url);
safe_free(update.release_notes);
if ((data = get_sanitized_token_data_buffer("version", 1, buf, len)) != NULL) {
for (i=0; (i<3) && ((token = strtok((i==0)?data:NULL, ".")) != NULL); i++) {
for (i = 0; (i < 3) && ((token = strtok((i == 0) ? data : NULL, ".")) != NULL); i++) {
update.version[i] = (uint16_t)atoi(token);
}
safe_free(data);
}
if ((data = get_sanitized_token_data_buffer("platform_min", 1, buf, len)) != NULL) {
for (i=0; (i<2) && ((token = strtok((i==0)?data:NULL, ".")) != NULL); i++) {
for (i = 0; (i < 2) && ((token = strtok((i == 0) ? data : NULL, ".")) != NULL); i++) {
update.platform_min[i] = (uint32_t)atoi(token);
}
safe_free(data);
}
static_sprintf(download_url_name, "download_url_%s", arch_names[GetCpuArch()]);
static_sprintf(download_url_name, "download_url_%s", GetAppArchName());
update.download_url = get_sanitized_token_data_buffer(download_url_name, 1, buf, len);
if (update.download_url == NULL)
update.download_url = get_sanitized_token_data_buffer("download_url", 1, buf, len);

View file

@ -557,8 +557,8 @@ extern char app_data_dir[MAX_PATH], *image_path, *fido_url;
*/
extern void GetWindowsVersion(void);
extern BOOL is_x64(void);
extern int GetCpuArch(void);
extern const char *WindowsErrorString(void);
extern const char* GetAppArchName(void);
extern const char* WindowsErrorString(void);
extern void DumpBufferHex(void *buf, size_t size);
extern void PrintStatusInfo(BOOL info, BOOL debug, unsigned int duration, int msg_id, ...);
#define PrintStatus(...) PrintStatusInfo(FALSE, FALSE, __VA_ARGS__)

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.23.2019"
CAPTION "Rufus 3.23.2020"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -392,8 +392,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,23,2019,0
PRODUCTVERSION 3,23,2019,0
FILEVERSION 3,23,2020,0
PRODUCTVERSION 3,23,2020,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -411,13 +411,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.23.2019"
VALUE "FileVersion", "3.23.2020"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2023 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.23.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.23.2019"
VALUE "ProductVersion", "3.23.2020"
END
END
BLOCK "VarFileInfo"

View file

@ -223,22 +223,18 @@ BOOL is_x64(void)
return ret;
}
int GetCpuArch(void)
{
SYSTEM_INFO info = { 0 };
GetNativeSystemInfo(&info);
switch (info.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64:
return ARCH_X86_64;
case PROCESSOR_ARCHITECTURE_INTEL:
return ARCH_X86_64;
case PROCESSOR_ARCHITECTURE_ARM64:
return ARCH_ARM_64;
case PROCESSOR_ARCHITECTURE_ARM:
return ARCH_ARM_32;
default:
return ARCH_UNKNOWN;
}
const char* GetAppArchName(void) {
#if defined(_M_AMD64)
return "x64";
#elif defined(_M_IX86)
return "x86";
#elif defined(_M_ARM64)
return "arm64";
#elif defined(_M_ARM)
return "arm";
#else
return "unknown";
#endif
}
static const char* GetEdition(DWORD ProductType)