Skip to content

Commit

Permalink
[vhd] fix Rufus being unable to open .vhd images
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pbatard committed Aug 20, 2023
1 parent 5b6574d commit 9c6b1ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/rufus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,8 @@ DWORD WINAPI ImageScanThread(LPVOID param)
uprintf(" Image is a FORCED non-bootable image");
else
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;
}

Expand Down
10 changes: 5 additions & 5 deletions src/rufus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.2076"
CAPTION "Rufus 4.3.2077"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
Expand Down Expand Up @@ -392,8 +392,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,3,2076,0
PRODUCTVERSION 4,3,2076,0
FILEVERSION 4,3,2077,0
PRODUCTVERSION 4,3,2077,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -411,13 +411,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "4.3.2076"
VALUE "FileVersion", "4.3.2077"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "� 2011-2023 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-4.3.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "4.3.2076"
VALUE "ProductVersion", "4.3.2077"
END
END
BLOCK "VarFileInfo"
Expand Down
15 changes: 10 additions & 5 deletions src/vhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ static comp_assoc file_assoc[] = {
};

// 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;
unsigned char *buf = NULL;
int i;
FILE* fd = NULL;
BOOL r = FALSE;
BOOL r = 0;
int64_t dc = 0;

img_report.compression_type = BLED_COMPRESSION_NONE;
Expand All @@ -119,7 +119,7 @@ static BOOL IsCompressedBootableImage(const char* path)
img_report.compression_type = file_assoc[i].type;
buf = malloc(MBR_SIZE);
if (buf == NULL)
return FALSE;
return 0;
FormatStatus = 0;
if (img_report.compression_type < BLED_COMPRESSION_MAX) {
bled_init(0, uprintf, NULL, NULL, NULL, NULL, &FormatStatus);
Expand All @@ -138,6 +138,7 @@ static BOOL IsCompressedBootableImage(const char* path)
if (has_ffu_support) {
fd = fopenU(path, "rb");
if (fd != NULL) {
img_report.is_vhd = TRUE;
dc = fread(buf, 1, MBR_SIZE, fd);
fclose(fd);
// The signature may not be constant, but since the only game in town to
Expand All @@ -156,6 +157,7 @@ static BOOL IsCompressedBootableImage(const char* path)
} else {
physical_disk = VhdMountImage(path);
if (physical_disk != NULL) {
img_report.is_vhd = TRUE;
fd = fopenU(physical_disk, "rb");
if (fd != NULL) {
dc = fread(buf, 1, MBR_SIZE, fd);
Expand All @@ -168,7 +170,10 @@ static BOOL IsCompressedBootableImage(const char* path)
free(buf);
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);
return r;
}
Expand Down Expand Up @@ -935,7 +940,7 @@ char* VhdMountImage(const char* path)
for (ext = (char*)&path[safe_strlen(path) - 1]; (*ext != '.') && (ext != path); ext--);
if (safe_stricmp(ext, ".vhdx") == 0)
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;

r = pfOpenVirtualDisk(&vtype, wpath, VIRTUAL_DISK_ACCESS_READ | VIRTUAL_DISK_ACCESS_GET_INFO,
Expand Down

0 comments on commit 9c6b1ad

Please sign in to comment.