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

[vhd] fix Rufus being unable to open .vhd images

* Due to a typo in vhd.c where the second safe_stricmp() should be against ".vhd" and not ".vhdx" again.
* Also enable the ignore boot marker bypass for VHD/VHDX/FFU and don't misreport those images as
  "compressed disk images".
* Closes #2309.
This commit is contained in:
Pete Batard 2023-08-20 13:12:38 +01:00
parent 5b6574d6f6
commit 9c6b1ad977
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
3 changed files with 17 additions and 11 deletions

View file

@ -1338,7 +1338,8 @@ DWORD WINAPI ImageScanThread(LPVOID param)
uprintf(" Image is a FORCED non-bootable image"); uprintf(" Image is a FORCED non-bootable image");
else else
uprintf(" Image is a %sbootable %s image", uprintf(" Image is a %sbootable %s image",
(img_report.compression_type != BLED_COMPRESSION_NONE) ? "compressed " : "", img_report.is_vhd ? "VHD" : "disk"); (img_report.compression_type != BLED_COMPRESSION_NONE && img_report.compression_type < BLED_COMPRESSION_MAX) ?
"compressed " : "", img_report.is_vhd ? "VHD" : "disk");
selection_default = BT_IMAGE; selection_default = BT_IMAGE;
} }

View file

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

View file

@ -101,13 +101,13 @@ static comp_assoc file_assoc[] = {
}; };
// Look for a boot marker in the MBR area of the image // Look for a boot marker in the MBR area of the image
static BOOL IsCompressedBootableImage(const char* path) static int8_t IsCompressedBootableImage(const char* path)
{ {
char *ext = NULL, *physical_disk = NULL; char *ext = NULL, *physical_disk = NULL;
unsigned char *buf = NULL; unsigned char *buf = NULL;
int i; int i;
FILE* fd = NULL; FILE* fd = NULL;
BOOL r = FALSE; BOOL r = 0;
int64_t dc = 0; int64_t dc = 0;
img_report.compression_type = BLED_COMPRESSION_NONE; img_report.compression_type = BLED_COMPRESSION_NONE;
@ -119,7 +119,7 @@ static BOOL IsCompressedBootableImage(const char* path)
img_report.compression_type = file_assoc[i].type; img_report.compression_type = file_assoc[i].type;
buf = malloc(MBR_SIZE); buf = malloc(MBR_SIZE);
if (buf == NULL) if (buf == NULL)
return FALSE; return 0;
FormatStatus = 0; FormatStatus = 0;
if (img_report.compression_type < BLED_COMPRESSION_MAX) { if (img_report.compression_type < BLED_COMPRESSION_MAX) {
bled_init(0, uprintf, NULL, NULL, NULL, NULL, &FormatStatus); bled_init(0, uprintf, NULL, NULL, NULL, NULL, &FormatStatus);
@ -138,6 +138,7 @@ static BOOL IsCompressedBootableImage(const char* path)
if (has_ffu_support) { if (has_ffu_support) {
fd = fopenU(path, "rb"); fd = fopenU(path, "rb");
if (fd != NULL) { if (fd != NULL) {
img_report.is_vhd = TRUE;
dc = fread(buf, 1, MBR_SIZE, fd); dc = fread(buf, 1, MBR_SIZE, fd);
fclose(fd); fclose(fd);
// The signature may not be constant, but since the only game in town to // The signature may not be constant, but since the only game in town to
@ -156,6 +157,7 @@ static BOOL IsCompressedBootableImage(const char* path)
} else { } else {
physical_disk = VhdMountImage(path); physical_disk = VhdMountImage(path);
if (physical_disk != NULL) { if (physical_disk != NULL) {
img_report.is_vhd = TRUE;
fd = fopenU(physical_disk, "rb"); fd = fopenU(physical_disk, "rb");
if (fd != NULL) { if (fd != NULL) {
dc = fread(buf, 1, MBR_SIZE, fd); dc = fread(buf, 1, MBR_SIZE, fd);
@ -168,7 +170,10 @@ static BOOL IsCompressedBootableImage(const char* path)
free(buf); free(buf);
return FALSE; return FALSE;
} }
r = (buf[0x1FE] == 0x55) && (buf[0x1FF] == 0xAA); if ((buf[0x1FE] == 0x55) && (buf[0x1FF] == 0xAA))
r = 1;
else if (ignore_boot_marker)
r = 2;
free(buf); free(buf);
return r; return r;
} }
@ -935,7 +940,7 @@ char* VhdMountImage(const char* path)
for (ext = (char*)&path[safe_strlen(path) - 1]; (*ext != '.') && (ext != path); ext--); for (ext = (char*)&path[safe_strlen(path) - 1]; (*ext != '.') && (ext != path); ext--);
if (safe_stricmp(ext, ".vhdx") == 0) if (safe_stricmp(ext, ".vhdx") == 0)
vtype.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_VHDX; vtype.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_VHDX;
else if (safe_stricmp(ext, ".vhdx") == 0) else if (safe_stricmp(ext, ".vhd") == 0)
vtype.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_VHD; vtype.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_VHD;
r = pfOpenVirtualDisk(&vtype, wpath, VIRTUAL_DISK_ACCESS_READ | VIRTUAL_DISK_ACCESS_GET_INFO, r = pfOpenVirtualDisk(&vtype, wpath, VIRTUAL_DISK_ACCESS_READ | VIRTUAL_DISK_ACCESS_GET_INFO,