[md5sum] fix bootloaders not being extracted unless referenced in md5sum.txt

* Not all md5sum.txt (e.g. Ubuntu 24.04) will reference the UEFI bootloader,
  so we can't rely on using that data for the bootloader extraction.
* Instead, formally test for the presence of the bootloader on disk.
This commit is contained in:
Pete Batard 2024-04-27 18:21:57 +01:00
parent 4ec57dc5d7
commit df9e333f3a
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
2 changed files with 44 additions and 41 deletions

View File

@ -2196,48 +2196,51 @@ void UpdateMD5Sum(const char* dest_dir, const char* md5sum_name)
d = new_data;
}
s = md5_data;
// Extract the MD5Sum bootloader(s)
for (i = 1; i < ARRAYSIZE(efi_bootname); i++) {
static_sprintf(path1, "%s\\efi\\boot\\%s", dest_dir, efi_bootname[i]);
if (!PathFileExistsA(path1))
continue;
res_data = (BYTE*)GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_MD5_BOOT + i),
_RT_RCDATA, efi_bootname[i], &res_size, FALSE);
static_strcpy(path2, path1);
path2[strlen(path2) - 4] = 0;
static_strcat(path2, "_original.efi");
if (res_data == NULL || !MoveFileU(path1, path2)) {
uprintf("Could not rename: %s → %s", path1, path2);
continue;
}
uprintf("Renamed: %s → %s", path1, path2);
hFile = CreateFileA(path1, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if ((hFile == NULL) || (hFile == INVALID_HANDLE_VALUE)) {
uprintf("Could not create '%s': %s.", path1, WindowsErrorString());
MoveFileU(path2, path1);
continue;
}
if (!WriteFileWithRetry(hFile, res_data, res_size, NULL, WRITE_RETRIES)) {
uprintf("Could not write '%s': %s.", path1, WindowsErrorString());
safe_closehandle(hFile);
MoveFileU(path2, path1);
continue;
}
safe_closehandle(hFile);
uprintf("Created: %s (%s)", path1, SizeToHumanReadable(res_size, FALSE, FALSE));
}
// Rename the original bootloaders if present in md5sum.txt
for (p = md5_data; (p = StrStrIA(p, " ./efi/boot/boot")) != NULL; ) {
for (i = 1; i < ARRAYSIZE(efi_bootname); i++) {
if (p[12 + strlen(efi_bootname[i])] != 0x0a)
continue;
p[12 + strlen(efi_bootname[i])] = 0;
if (lstrcmpiA(&p[12], efi_bootname[i]) == 0) {
res_data = (BYTE*)GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_MD5_BOOT + i),
_RT_RCDATA, efi_bootname[i], &res_size, FALSE);
static_sprintf(path1, "%s\\%s", dest_dir, &p[3]);
for (j = 0; j < strlen(path1); j++)
if (path1[j] == '/') path1[j] = '\\';
static_strcpy(path2, path1);
path2[strlen(path2) - 4] = 0;
static_strcat(path2, "_original.efi");
if (res_data != NULL && MoveFileU(path1, path2)) {
uprintf("Renamed: %s → %s", path1, path2);
hFile = CreateFileA(path1, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if ((hFile == NULL) || (hFile == INVALID_HANDLE_VALUE)) {
uprintf("Could not create '%s': %s.", path1, WindowsErrorString());
MoveFileU(path2, path1);
continue;
}
if (!WriteFileWithRetry(hFile, res_data, res_size, NULL, WRITE_RETRIES)) {
uprintf("Could not write '%s': %s.", path1, WindowsErrorString());
safe_closehandle(hFile);
MoveFileU(path2, path1);
continue;
}
safe_closehandle(hFile);
uprintf("Created: %s (%s)", path1, SizeToHumanReadable(res_size, FALSE, FALSE));
size = (uint32_t)(p - s) + 12 + (uint32_t)strlen(efi_bootname[i]) - 4;
memcpy(d, s, size);
d = &d[size];
strcpy(d, "_original.efi\n");
new_size += 9;
d = &d[14];
s = &p[12 + strlen(efi_bootname[i]) + 1];
// TODO: Update sources/boot.wim if we modified it
// Also, we'll need to keep a copy of the size of boot.wim BEFORE we alter it
// so we can adjust md5sum_totalbytes
}
size = (uint32_t)(p - s) + 12 + (uint32_t)strlen(efi_bootname[i]) - 4;
memcpy(d, s, size);
d = &d[size];
strcpy(d, "_original.efi\n");
new_size += 9;
d = &d[14];
s = &p[12 + strlen(efi_bootname[i]) + 1];
}
p[12 + strlen(efi_bootname[i])] = 0x0a;
}

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 4.5.2145"
CAPTION "Rufus 4.5.2146"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -397,8 +397,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,5,2145,0
PRODUCTVERSION 4,5,2145,0
FILEVERSION 4,5,2146,0
PRODUCTVERSION 4,5,2146,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -416,13 +416,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "4.5.2145"
VALUE "FileVersion", "4.5.2146"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "<22> 2011-2024 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-4.5.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "4.5.2145"
VALUE "ProductVersion", "4.5.2146"
END
END
BLOCK "VarFileInfo"