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

[core] add the ability to ignore USBs through VID:PID

* This enables the provision of Registry/Settings key IgnoreUsb01 to IgnoreUsb08 where
  one can specify a USB device to ignore by providing its VID:PID as a 32-bit hex value.
* Closes #1879.
* Also update rufus.ini sample for current Rufus version.
* Also fix status display for Alt-Q.
This commit is contained in:
Pete Batard 2022-06-14 23:29:33 +01:00
parent d8af83dd14
commit cd9d3737b1
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
5 changed files with 64 additions and 36 deletions

View file

@ -1,42 +1,51 @@
; The following is a sample INI file, as used by Rufus
; Whenever Rufus detects a 'rufus.ini' in the directory you launched it from
; (even an EMPTY ONE), it starts in portable mode, and store all its settings
; there, instead of the Registry.
; In most cases, you should never have to modify an INI file manually. But if
; needed, the format of the 'rufus.ini' is documented hereafter:
;; The following is a sample INI file, as used by Rufus
;; Whenever Rufus detects a 'rufus.ini' in the directory you launched it from
;; (even an EMPTY ONE), it starts in portable mode, and store all its settings
;; there, instead of the Registry.
;; In most cases, you should never have to modify an INI file manually. But if
;; needed, the format of the 'rufus.ini' is documented hereafter:
; The translation used by the Rufus to display its UI (RFC 1766)
;; The translation used by the Rufus to display its UI (RFC 1766)
Locale = en-US
; Internal, to confirm R/W access to these settings
CommCheck = 20089578
; Timestamp of the last update check
LastUpdateCheck = 13068056756
; Amount of time before Rufus checks for another update (in seconds)
;; Internal, to confirm R/W access to these settings
CommCheck64 = 317570234
;; Timestamp of the last update check
LastUpdateCheck = 13299289810
;; Amount of time before Rufus checks for another update (in seconds)
UpdateCheckInterval = 86400
; Whether the check for updates should also include new BETA releases
;; Whether the check for updates should also include new BETA releases
CheckForBetas = 1
; Use this to increase the log verbosity for the updates check (0-2)
;; Use this to increase the log verbosity for the updates check (0-2)
; VerboseUpdateCheck = 2
; If you are paranoid about apps writing to the registry, you can uncomment the
; following. It will disable the Local Group Policy calls that Rufus issues, to
; temporarily prevent the *annoying* notices Windows issues about new drives.
;; If you are paranoid about apps writing to the registry, you can uncomment the
;; following. It will disable the Local Group Policy calls that Rufus issues, to
;; temporarily prevent the *annoying* notices Windows issues about new drives.
; DisableLGP = 1
; Start with the 'Advanced Options' panel displayed
; AdvancedMode = 1
; Display extended information duringh USB enumeration (Alt-.)
;; Start with the Drive properties or Format options 'Advanced' panel displayed
; ShowAdvancedDriveProperties = 1
; ShowAdvancedFormatOptions = 1
;; Display extended information duringh USB enumeration (Alt-.)
; EnableUsbDebug = 1
; Don't perform a fake drive test during bad blocks check (Alt-B)
;; Don't perform a fake drive test during bad blocks check (Alt-B)
; DisableFakeDrivesCheck = 1
; Allow the creation of dual UEFI+BIOS bootable drives for Windows (Alt-E)
;; Allow the creation of dual UEFI+BIOS bootable drives for Windows (Alt-E)
; EnableWindowsDualUefiBiosMode = 1
; Also use RidgeCrop's Large FAT32 format algorithm when formatting smaller drives (Alt-L)
;; Force the use of RidgeCrop's Large FAT32 format algorithm when formatting smaller drives (Alt-L)
; ForceLargeFat32Formatting = 1
; Disable Windows file indexing on the newly formatted drive (Alt-Q)
; DisableFileIndexing = 1
; Have Rufus to preserve timestamps when copying files (Alt-T)
;; Enable Windows file indexing on the newly formatted drive (Alt-Q)
; EnableFileIndexing = 1
;; Preserve timestamps when copying files (Alt-T)
; PreserveTimestamps = 1
; Disable the whole Kibi/Gibi nonsense (Alt-U)
;; Disable the whole Kibi/Gibi nonsense (Alt-U)
; UseProperSizeUnits = 1
; Enable listing of VMWare's VMDK drives when used in a virtual machine (Alt-W)
;; Enable the listing of VMWare's VMDK drives when used in a virtual machine (Alt-W)
; EnableVmdkDetection = 1
;; Treat disk images as bootable even if they don't have a 0x55 0xAA marker at offset 0x1FE (Alt-M)
; IgnoreBootMarker = 1
;; Force the use of Windows' Virtual Disk Service (VDS) for formatting (Alt-V)
; UseVds = 1
;; Ignore specific USB devices when enumerating drives, by VID:PID, with up to 8 devices, from
;; 'IgnoreUsb01' to 'IgnoreUsb08', being able to be provided.
;; For instance, to prevent a USB flash drive with VID:PID 0781:5588 from being listed you would add:
;IgnoreUsb01 = 0x7815588

View file

@ -38,6 +38,7 @@
#include "rufus.h"
#include "missing.h"
#include "resource.h"
#include "settings.h"
#include "msapi_utf8.h"
#include "localization.h"
@ -475,6 +476,7 @@ BOOL GetDevices(DWORD devnum)
StrArray dev_if_path;
char letter_name[] = " (?:)";
char drive_name[] = "?:\\";
char setting_name[32];
char uefi_togo_check[] = "?:\\EFI\\Rufus\\ntfs_x64.efi";
char scsi_card_name_copy[16];
BOOL r = FALSE, found = FALSE, post_backslash;
@ -491,6 +493,7 @@ BOOL GetDevices(DWORD devnum)
int s, u, v, score, drive_number, remove_drive, num_drives = 0;
char drive_letters[27], *device_id, *devid_list = NULL, display_msg[128];
char *p, *label, *display_name, buffer[MAX_PATH], str[MAX_PATH], device_instance_id[MAX_PATH], *method_str, *hub_path;
uint32_t ignore_vid_pid[MAX_IGNORE_USB];
usb_device_props props;
IGNORE_RETVAL(ComboBox_ResetContent(hDeviceList));
@ -568,11 +571,17 @@ BOOL GetDevices(DWORD devnum)
full_list_size += list_size[s]-1; // remove extra NUL terminator
}
// Compute the card_start index
for (s=0; s<ARRAYSIZE(genstor_name); s++) {
for (s = 0; s < ARRAYSIZE(genstor_name); s++) {
if (strcmp(genstor_name[s], "SD") == 0)
card_start = s;
}
// Build the list of USB devices we may want to ignore
for (s = 0; s < ARRAYSIZE(ignore_vid_pid); s++) {
static_sprintf(setting_name, "IgnoreUsb%02d", s + 1);
ignore_vid_pid[s] = ReadSetting32(setting_name);
}
// Better safe than sorry. And yeah, we could have used arrays of
// arrays to avoid this, but it's more readable this way.
assert((uasp_start > 0) && (uasp_start < ARRAYSIZE(usbstor_name)));
@ -791,6 +800,7 @@ BOOL GetDevices(DWORD devnum)
}
static_strcpy(str, "????:????"); // Couldn't figure VID:PID
} else {
static_sprintf(str, "%04X:%04X", props.vid, props.pid);
// I *REALLY* don't want to erase the devices below by accident.
if (its_a_me_mario) {
if ((props.vid == 0x0525) && (props.pid == 0x622b))
@ -798,7 +808,15 @@ BOOL GetDevices(DWORD devnum)
if ((props.vid == 0x0781) && (props.pid == 0x75a0))
continue;
}
static_sprintf(str, "%04X:%04X", props.vid, props.pid);
// Also ignore USB devices that have been specifically flaggged by the user
for (s = 0; s < ARRAYSIZE(ignore_vid_pid); s++) {
if ((props.vid == (ignore_vid_pid[s] >> 16)) && (props.pid == (ignore_vid_pid[s] & 0xffff))) {
uprintf("Ignoring '%s' (%s), per user settings", buffer, str);
break;
}
}
if (s < ARRAYSIZE(ignore_vid_pid))
continue;
}
if (props.speed >= USB_SPEED_MAX)
props.speed = 0;

View file

@ -3866,7 +3866,7 @@ relaunch:
if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'Q')) {
enable_file_indexing = !enable_file_indexing;
WriteSettingBool(SETTING_ENABLE_FILE_INDEXING, enable_file_indexing);
PrintStatusTimeout(lmprintf(MSG_290), !enable_file_indexing);
PrintStatusTimeout(lmprintf(MSG_290), enable_file_indexing);
continue;
}
// Alt-R => Remove all the registry keys that may have been created by Rufus

View file

@ -75,6 +75,7 @@
#define MAX_GUID_STRING_LENGTH 40
#define MAX_PARTITIONS 16 // Maximum number of partitions we handle
#define MAX_ESP_TOGGLE 8 // Maximum number of entries we record to toggle GPT ESP back and forth
#define MAX_IGNORE_USB 8 // Maximum number of USB drives we want to ignore
#define MAX_ISO_TO_ESP_SIZE 512 // Maximum size we allow for the ISO → ESP option (in MB)
#define MAX_DEFAULT_LIST_CARD_SIZE 200 // Size above which we don't list a card without enable HDD or Alt-F (in GB)
#define MAX_SECTORS_TO_CLEAR 128 // nb sectors to zap when clearing the MBR/GPT (must be >34)

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.19.1896"
CAPTION "Rufus 3.19.1897"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -395,8 +395,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,19,1896,0
PRODUCTVERSION 3,19,1896,0
FILEVERSION 3,19,1897,0
PRODUCTVERSION 3,19,1897,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -414,13 +414,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.19.1896"
VALUE "FileVersion", "3.19.1897"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2022 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.19.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.19.1896"
VALUE "ProductVersion", "3.19.1897"
END
END
BLOCK "VarFileInfo"