From 6109d91c3870cfe0157b11490554a3974326b911 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Mon, 22 Oct 2018 17:42:40 +0100 Subject: [PATCH] [net] add automated update support for ARM/ARM64 --- src/net.c | 8 ++++---- src/parser.c | 9 +++++++-- src/rufus.c | 2 +- src/rufus.h | 13 +++++++++++++ src/rufus.rc | 10 +++++----- src/stdfn.c | 20 +++++++++++++++++++- 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/net.c b/src/net.c index e550118f..1ae3eb9d 100644 --- a/src/net.c +++ b/src/net.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * Networking functionality (web file download, check for update, etc.) - * Copyright © 2012-2016 Pete Batard + * Copyright © 2012-2018 Pete Batard * * 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 @@ -531,7 +531,7 @@ 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"}; + 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}; DWORD dwFlags, dwSize, dwDownloaded, dwTotalSize, dwStatus; @@ -636,11 +636,11 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param) uprintf("Checking %s channel...", channel[k]); // At this stage we can query the server for various update version files. // We first try to lookup for "___.ver" - // and then remove each each of the components until we find our match. For instance, we may first + // and then remove each of the 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[is_x64()?1:0], os_version.dwMajorVersion, os_version.dwMinorVersion); + (k==0)?"":channel[k], archname[GetCpuArch()], os_version.dwMajorVersion, os_version.dwMinorVersion); vuprintf("Base update check: %s", urlpath); for (i=0, j=(int)safe_strlen(urlpath)-5; (j>0)&&(i + * Copyright © 2012-2018 Pete Batard * * 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 @@ -903,6 +903,8 @@ void parse_update(char* buf, size_t len) char *data = NULL, *token; char allowed_rtf_chars[] = "abcdefghijklmnopqrstuvwxyz|~-_:*'"; char allowed_std_chars[] = "\r\n ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"$%^&+=<>(){}[].,;#@/?"; + char download_url_name[24]; + char *arch_names[CPU_ARCH_MAX] = { "x86", "x64", "arm", "arm64", "none" }; // strchr includes the NUL terminator in the search, so take care of backslash before NUL if ((buf == NULL) || (len < 2) || (len > 65536) || (buf[len-1] != 0) || (buf[len-2] == '\\')) @@ -939,7 +941,10 @@ void parse_update(char* buf, size_t len) } safe_free(data); } - update.download_url = get_sanitized_token_data_buffer("download_url", 1, buf, len); + static_sprintf(download_url_name, "download_url_%s", arch_names[GetCpuArch()]); + 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); update.release_notes = get_sanitized_token_data_buffer("release_notes", 1, buf, len); } diff --git a/src/rufus.c b/src/rufus.c index d60923d3..079084e2 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -1876,7 +1876,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA case WM_COMMAND: #ifdef RUFUS_TEST if (LOWORD(wParam) == IDC_TEST) { - DownloadSignedFile(FILES_URL "/gendb.sh", "C:\\Downloads\\gendb.sh", hProgress, TRUE); + uprintf("CPU ARCH: %d", GetCpuArch()); break; } #endif diff --git a/src/rufus.h b/src/rufus.h index 5a81107a..12bd0dc3 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -82,7 +82,11 @@ #define UBUFFER_SIZE 2048 #define RSA_SIGNATURE_SIZE 256 #define CBN_SELCHANGE_INTERNAL (CBN_SELCHANGE + 256) +#if defined(RUFUS_TEST) +#define RUFUS_URL "http://pi3" +#else #define RUFUS_URL "https://rufus.ie" +#endif #define DOWNLOAD_URL RUFUS_URL "/downloads" #define FILES_URL RUFUS_URL "/files" #define SEVENZIP_URL "https://www.7-zip.org" @@ -397,6 +401,14 @@ enum WindowsVersion { WINDOWS_MAX }; +enum CpuArch { + CPU_ARCH_X86_32 = 0, + CPU_ARCH_X86_64, + CPU_ARCH_ARM_32, + CPU_ARCH_ARM_64, + CPU_ARCH_UNDEFINED, + CPU_ARCH_MAX +}; /* * Globals @@ -430,6 +442,7 @@ extern char* image_path; extern uint8_t popcnt8(uint8_t val); extern void GetWindowsVersion(void); extern BOOL is_x64(void); +extern BOOL GetCpuArch(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, ...); diff --git a/src/rufus.rc b/src/rufus.rc index 2aa080f5..ada7aa95 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -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.4.1411" +CAPTION "Rufus 3.4.1412" 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,4,1411,0 - PRODUCTVERSION 3,4,1411,0 + FILEVERSION 3,4,1412,0 + PRODUCTVERSION 3,4,1412,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -411,13 +411,13 @@ BEGIN VALUE "Comments", "https://akeo.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "3.4.1411" + VALUE "FileVersion", "3.4.1412" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus-3.4.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "3.4.1411" + VALUE "ProductVersion", "3.4.1412" END END BLOCK "VarFileInfo" diff --git a/src/stdfn.c b/src/stdfn.c index be1c6c8c..c94de25d 100644 --- a/src/stdfn.c +++ b/src/stdfn.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * Standard Windows function calls - * Copyright © 2013-2017 Pete Batard + * Copyright © 2013-2018 Pete Batard * * 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 @@ -230,6 +230,24 @@ BOOL is_x64(void) return ret; } +int GetCpuArch(void) +{ + SYSTEM_INFO info = { 0 }; + GetNativeSystemInfo(&info); + switch (info.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: + return CPU_ARCH_X86_64; + case PROCESSOR_ARCHITECTURE_INTEL: + return CPU_ARCH_X86_64; + case PROCESSOR_ARCHITECTURE_ARM64: + return CPU_ARCH_ARM_64; + case PROCESSOR_ARCHITECTURE_ARM: + return CPU_ARCH_ARM_32; + default: + return CPU_ARCH_UNDEFINED; + } +} + // From smartmontools os_win32.cpp void GetWindowsVersion(void) {