[grub] force server download for nonstandard GRUB (Fedora 37, openSUSE Live, GeckoLinux)

* This reverts most of 3528ca773d in order to download 'core.img' from our server instead of patching it.
* Also solve the issue of downloading a custom 'core.img' for Fedora 37, that introduced
  a new 'grub_debug_is_enabled' symbol without altering their GRUB version string.
* This is accomplished by doing what the distro maintainers should have done on their
  own, by appending a custom suffix to the GRUB version string.
This commit is contained in:
Pete Batard 2022-10-06 23:39:32 +01:00
parent 8814944c35
commit fcae51a446
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
6 changed files with 48 additions and 125 deletions

View file

@ -74,7 +74,6 @@ extern uint32_t dur_mins, dur_secs;
extern uint32_t wim_nb_files, wim_proc_files, wim_extra_files;
extern BOOL force_large_fat32, enable_ntfs_compression, lock_drive, zero_drive, fast_zeroing, enable_file_indexing;
extern BOOL write_as_image, use_vds, write_as_esp, is_vds_available;
extern const grub_patch_t grub_patch[2];
uint8_t *grub2_buf = NULL, *sec_buf = NULL;
long grub2_len;
@ -911,8 +910,8 @@ static BOOL WriteSBR(HANDLE hPhysicalDrive)
{
// TODO: Do we need anything special for 4K sectors?
DWORD size, max_size, br_size = 0x200;
int i, j, r, sub_type = boot_type;
uint8_t *buf = NULL, *patched = NULL;
int r, sub_type = boot_type;
uint8_t *buf = NULL;
FAKE_FD fake_fd = { 0 };
FILE* fp = (FILE*)&fake_fd;
@ -955,32 +954,6 @@ static BOOL WriteSBR(HANDLE hPhysicalDrive)
return FALSE;
}
}
// TODO: Compute the projected increase in size instead of harcoding it
if (img_report.has_grub2 == 2 && ((patched = malloc(size + 16)) != NULL)) {
memcpy(patched, buf, size);
// Patch GRUB for nonstandard prefix directory
for (i = 0; i < ARRAYSIZE(grub_patch); i++) {
if (strcmp(img_report.grub2_version, grub_patch[i].version) == 0) {
for (j = 0; j < ARRAYSIZE(grub_patch[i].patch); j++) {
if (memcmp(&patched[grub_patch[i].patch[j].src->offset], grub_patch[i].patch[j].src->data,
grub_patch[i].patch[j].src->size) != 0) {
uprintf("ERROR: Did not find expected source data for GRUB patch");
free(patched);
return FALSE;
}
memcpy(&patched[grub_patch[i].patch[j].rep->offset], grub_patch[i].patch[j].rep->data,
grub_patch[i].patch[j].rep->size);
if (grub_patch[i].patch[j].rep->size > grub_patch[i].patch[j].src->size)
size += grub_patch[i].patch[j].rep->size - grub_patch[i].patch[j].src->size;
}
safe_free(grub2_buf);
grub2_buf = patched;
buf = grub2_buf;
uprintf("Patched Grub 2.0 SBR for NONSTANDARD prefix");
break;
}
}
}
break;
case BT_MAX:
uprintf("Writing protective message SBR");