mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[core] retrieve the VID:PID of the USB devices enumerated
This commit is contained in:
parent
9f76b758ad
commit
8d50a8491f
3 changed files with 56 additions and 10 deletions
47
src/rufus.c
47
src/rufus.c
|
@ -596,13 +596,16 @@ static BOOL GetUSBDevices(DWORD devnum)
|
|||
SP_DEVICE_INTERFACE_DATA devint_data;
|
||||
PSP_DEVICE_INTERFACE_DETAIL_DATA_A devint_detail_data;
|
||||
STORAGE_DEVICE_NUMBER_REDEF device_number;
|
||||
DWORD size, i, j, datatype;
|
||||
DEVINST parent_inst, device_inst;
|
||||
DWORD size, i, j, k, datatype;
|
||||
ULONG list_size;
|
||||
HANDLE hDrive;
|
||||
LONG maxwidth = 0;
|
||||
RECT rect;
|
||||
char drive_letter;
|
||||
char *label, *entry, buffer[MAX_PATH];
|
||||
char drive_letter, *devid, *devid_list = NULL;
|
||||
char *label, *entry, buffer[MAX_PATH], str[sizeof("0000:0000")+1];
|
||||
const char* usbstor_name = "USBSTOR";
|
||||
uint16_t vid, pid;
|
||||
GUID _GUID_DEVINTERFACE_DISK = // only known to some...
|
||||
{ 0x53f56307L, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b} };
|
||||
|
||||
|
@ -617,6 +620,18 @@ static BOOL GetUSBDevices(DWORD devnum)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
// Get a list of hardware IDs for all USB storage devices
|
||||
// This will be used to retrieve the VID:PID of our devices
|
||||
CM_Get_Device_ID_List_SizeA(&list_size, usbstor_name, CM_GETIDLIST_FILTER_SERVICE);
|
||||
if (list_size == 0)
|
||||
return FALSE;
|
||||
devid_list = (char*)malloc(list_size);
|
||||
if (devid_list == NULL) {
|
||||
uprintf("Could not allocate Dev ID list\n");
|
||||
return FALSE;
|
||||
}
|
||||
CM_Get_Device_ID_ListA(usbstor_name, devid_list, list_size, CM_GETIDLIST_FILTER_SERVICE);
|
||||
|
||||
dev_info_data.cbSize = sizeof(dev_info_data);
|
||||
for (i=0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) {
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
@ -629,13 +644,34 @@ static BOOL GetUSBDevices(DWORD devnum)
|
|||
if (safe_strcmp(buffer, usbstor_name) != 0)
|
||||
continue;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
vid = 0; pid = 0;
|
||||
if (!SetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_FRIENDLYNAME,
|
||||
&datatype, (LPBYTE)buffer, sizeof(buffer), &size)) {
|
||||
uprintf("SetupDiGetDeviceRegistryProperty (Friendly Name) failed: %s\n", WindowsErrorString());
|
||||
// We can afford a failure on this call - just replace the name
|
||||
// We can afford a failure on this call - just replace the name with "USB Storage Device (Generic)"
|
||||
safe_strcpy(buffer, sizeof(buffer), lmprintf(MSG_045));
|
||||
} else {
|
||||
// Get the VID:PID of the device. We could avoid doing this lookup every time by keeping
|
||||
// a lookup table, but there shouldn't be that many USB storage devices connected...
|
||||
for (devid = devid_list; *devid; devid += strlen(devid_list) + 1) {
|
||||
if ( (CM_Locate_DevNodeA(&parent_inst, devid, 0) == 0)
|
||||
&& (CM_Get_Child(&device_inst, parent_inst, 0) == 0)
|
||||
&& (device_inst == dev_info_data.DevInst) ) {
|
||||
for (j=0, k=0; (j<strlen(devid))&&(k<2); j++) {
|
||||
if (devid[j] == '_') {
|
||||
pid = (uint16_t)strtoul(&devid[j+1], NULL, 16);
|
||||
// We could have used a vid_pid[] table, but keeping vid/pid separate is clearer
|
||||
if (k++==0) vid = pid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
uprintf("Found device '%s'\n", buffer);
|
||||
if ((vid == 0) && (pid == 0))
|
||||
safe_strcpy(str, sizeof(str), "????:????"); // Couldn't figure VID:PID
|
||||
else
|
||||
safe_sprintf(str, sizeof(str), "%04X:%04X", vid, pid);
|
||||
uprintf("Found device '%s' (%s)\n", buffer, str);
|
||||
|
||||
devint_data.cbSize = sizeof(devint_data);
|
||||
hDrive = INVALID_HANDLE_VALUE;
|
||||
|
@ -738,6 +774,7 @@ static BOOL GetUSBDevices(DWORD devnum)
|
|||
SendMessage(hMainDialog, WM_COMMAND, (CBN_SELCHANGE<<16) | IDC_DEVICE, 0);
|
||||
SendMessage(hMainDialog, WM_COMMAND, (CBN_SELCHANGE<<16) | IDC_FILESYSTEM,
|
||||
ComboBox_GetCurSel(hFileSystem));
|
||||
safe_free(devid_list);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -449,3 +449,12 @@ typedef struct {
|
|||
#define _RT_ICON MAKEINTRESOURCEA(3)
|
||||
#define _RT_RCDATA MAKEINTRESOURCEA(10)
|
||||
#define _RT_GROUP_ICON MAKEINTRESOURCEA((ULONG_PTR)(MAKEINTRESOURCEA(3) + 11))
|
||||
|
||||
/* The CM calls used in GetUSBDevices() - from MinGW's cfgmgr32.h header */
|
||||
typedef DWORD CONFIGRET, DEVINST, *PDEVINST;
|
||||
typedef CHAR *DEVINSTID_A;
|
||||
#define CM_GETIDLIST_FILTER_SERVICE 2
|
||||
DECLSPEC_IMPORT CONFIGRET WINAPI CM_Get_Device_ID_List_SizeA(PULONG pulLen, PCSTR pszFilter, ULONG ulFlags);
|
||||
DECLSPEC_IMPORT CONFIGRET WINAPI CM_Get_Device_ID_ListA(PCSTR pszFilter, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags);
|
||||
DECLSPEC_IMPORT CONFIGRET WINAPI CM_Locate_DevNodeA(PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags);
|
||||
DECLSPEC_IMPORT CONFIGRET WINAPI CM_Get_Child(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags);
|
||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
|||
IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_APPWINDOW
|
||||
CAPTION "Rufus v1.4.0.313"
|
||||
CAPTION "Rufus v1.4.0.314"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
||||
|
@ -289,8 +289,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,4,0,313
|
||||
PRODUCTVERSION 1,4,0,313
|
||||
FILEVERSION 1,4,0,314
|
||||
PRODUCTVERSION 1,4,0,314
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -307,13 +307,13 @@ BEGIN
|
|||
BEGIN
|
||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||
VALUE "FileDescription", "Rufus"
|
||||
VALUE "FileVersion", "1.4.0.313"
|
||||
VALUE "FileVersion", "1.4.0.314"
|
||||
VALUE "InternalName", "Rufus"
|
||||
VALUE "LegalCopyright", "© 2011-2013 Pete Batard (GPL v3)"
|
||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||
VALUE "OriginalFilename", "rufus.exe"
|
||||
VALUE "ProductName", "Rufus"
|
||||
VALUE "ProductVersion", "1.4.0.313"
|
||||
VALUE "ProductVersion", "1.4.0.314"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
Loading…
Reference in a new issue