From 37e383ade6eebe40c41f09f8f6b8f135118b4907 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Fri, 22 Nov 2024 00:03:13 +0000 Subject: [PATCH] [dev] add disk exclusion by GPT Disk GUID * Similar to what we already do with IgnoreUSB##, except this time, users can add REG_SZ keys IgnoreDisk01 to IgnoreDisk08, with a string like "{F333EC2E-25C9-488D-A7FC-9147C2367623}" to ignore a GPT disk with this specific GUID. * This may be useful for people who mount fixed virtual drives, or people who have enabled Hot Swap on their SATA storage, and who want to make sure they won't be able to inadvertently select that disk in Rufus. * Also set rufus-next to 4.7. --- configure | 20 ++++++++++---------- configure.ac | 2 +- src/dev.c | 3 +++ src/drive.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/drive.h | 1 + src/rufus.rc | 12 ++++++------ 6 files changed, 63 insertions(+), 17 deletions(-) diff --git a/configure b/configure index 667af6b2f0b..a385d034024 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.71 for rufus 4.6. +# Generated by GNU Autoconf 2.71 for rufus 4.7. # # Report bugs to . # @@ -611,8 +611,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='rufus' PACKAGE_TARNAME='rufus' -PACKAGE_VERSION='4.6' -PACKAGE_STRING='rufus 4.6' +PACKAGE_VERSION='4.7' +PACKAGE_STRING='rufus 4.7' PACKAGE_BUGREPORT='https://github.com/pbatard/rufus/issues' PACKAGE_URL='https://rufus.ie' @@ -1269,7 +1269,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures rufus 4.6 to adapt to many kinds of systems. +\`configure' configures rufus 4.7 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1336,7 +1336,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of rufus 4.6:";; + short | recursive ) echo "Configuration of rufus 4.7:";; esac cat <<\_ACEOF @@ -1428,7 +1428,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -rufus configure 4.6 +rufus configure 4.7 generated by GNU Autoconf 2.71 Copyright (C) 2021 Free Software Foundation, Inc. @@ -1504,7 +1504,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by rufus $as_me 4.6, which was +It was created by rufus $as_me 4.7, which was generated by GNU Autoconf 2.71. Invocation command line was $ $0$ac_configure_args_raw @@ -2767,7 +2767,7 @@ fi # Define the identity of the package. PACKAGE='rufus' - VERSION='4.6' + VERSION='4.7' printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h @@ -5309,7 +5309,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by rufus $as_me 4.6, which was +This file was extended by rufus $as_me 4.7, which was generated by GNU Autoconf 2.71. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5365,7 +5365,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -rufus config.status 4.6 +rufus config.status 4.7 configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 513ab26d6cf..c530cd1010d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([rufus], [4.6], [https://github.com/pbatard/rufus/issues], [rufus], [https://rufus.ie]) +AC_INIT([rufus], [4.7], [https://github.com/pbatard/rufus/issues], [rufus], [https://rufus.ie]) AM_INIT_AUTOMAKE([-Wno-portability foreign no-dist no-dependencies]) AC_CONFIG_SRCDIR([src/rufus.c]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/src/dev.c b/src/dev.c index 5ea2b2a06ab..a5768a8fb90 100644 --- a/src/dev.c +++ b/src/dev.c @@ -943,6 +943,9 @@ BOOL GetDevices(DWORD devnum) uprintf("Device eliminated because it was detected as a Microsoft Dev Drive"); safe_free(devint_detail_data); break; + } else if (IsFilteredDrive(drive_index)) { + safe_free(devint_detail_data); + break; } // Windows 10 19H1 mounts a 'PortableBaseLayer' for its Windows Sandbox feature => unlist those if (safe_strcmp(label, windows_sandbox_vhd_label) == 0) { diff --git a/src/drive.c b/src/drive.c index 5f378e2424a..6be48e3a877 100644 --- a/src/drive.c +++ b/src/drive.c @@ -2647,3 +2647,45 @@ BOOL IsMsDevDrive(DWORD DriveIndex) safe_closehandle(hPhysical); return ret; } + +/* + * Detect filtered drives, that have been added by users through the registry + * entries IgnoreDisk01 - IgnoreDisk08. These entries must contain *decorated* + * string GUIDs that match the GPT Disk GUID of the drive to filter out, as + * reported by Rufus, such as "{F333EC2E-25C9-488D-A7FC-9147C2367623}". + */ +BOOL IsFilteredDrive(DWORD DriveIndex) +{ + char setting_name[32]; + DWORD i, size = 0; + BOOL r, ret = FALSE; + HANDLE hPhysical = INVALID_HANDLE_VALUE; + BYTE layout[4096] = { 0 }; + PDRIVE_LAYOUT_INFORMATION_EX DriveLayout = (PDRIVE_LAYOUT_INFORMATION_EX)(void*)layout; + GUID* DiskGuid; + + hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE, TRUE); + if (hPhysical == INVALID_HANDLE_VALUE) + goto out; + + r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, NULL, 0, layout, sizeof(layout), &size, NULL); + if (!r || size <= 0) + goto out; + + // Only works for GPT drives + if (DriveLayout->PartitionStyle != PARTITION_STYLE_GPT) + goto out; + for (i = 1; i <= MAX_IGNORE_USB; i++) { + static_sprintf(setting_name, "IgnoreDisk%02d", i); + DiskGuid = StringToGuid(ReadSettingStr(setting_name)); + if (CompareGUID(&DriveLayout->Gpt.DiskId, DiskGuid)) { + uprintf("Device eliminated because it matches Disk GUID %s", GuidToString(DiskGuid, TRUE)); + ret = TRUE; + goto out; + } + } + +out: + safe_closehandle(hPhysical); + return ret; +} diff --git a/src/drive.h b/src/drive.h index 01e9c6b8acc..bee39f3915e 100644 --- a/src/drive.h +++ b/src/drive.h @@ -425,3 +425,4 @@ BOOL GetOpticalMedia(IMG_SAVE* img_save); uint64_t GetEspOffset(DWORD DriveIndex); BOOL ToggleEsp(DWORD DriveIndex, uint64_t PartitionOffset); BOOL IsMsDevDrive(DWORD DriveIndex); +BOOL IsFilteredDrive(DWORD DriveIndex); diff --git a/src/rufus.rc b/src/rufus.rc index 63419a76bce..6e5aacdf5ee 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 4.6.2208" +CAPTION "Rufus 4.7.2209" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -399,8 +399,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 4,6,2208,0 - PRODUCTVERSION 4,6,2208,0 + FILEVERSION 4,7,2209,0 + PRODUCTVERSION 4,7,2209,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -418,13 +418,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "4.6.2208" + VALUE "FileVersion", "4.7.2209" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2024 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" - VALUE "OriginalFilename", "rufus-4.6.exe" + VALUE "OriginalFilename", "rufus-4.7.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "4.6.2208" + VALUE "ProductVersion", "4.7.2209" END END BLOCK "VarFileInfo"