Commit Graph

234 Commits

Author SHA1 Message Date
Pete Batard 2a6df95cad
[iso] fix persistence option not being added for Ubuntu 24.04
* Ubuntu changed their GRUB config format yet again, so our search for the kernel
  config no longer works, and the 'persistent' option doesn't get added.
* Switch to a more generic '/casper/vmlinuz' search, though it might have unintended
  consequences...
* Also fix a possible double free in FormatExtFs().
2024-04-28 13:56:18 +01:00
Pete Batard 83e0bdad7a
[md5sum] fix unwanted partial matches in is_in_md5sum()
* is_in_md5sum() could partially match a string against another one, which, aside from matching
  unwanted files, could also lead to files not being identified as being in the md5sum.txt if
  the previous partial match happened to be with the current search target.
* Fix this by making sure that we always match a whole path followed by '/n', '/r' or '/0'.
2024-04-28 13:26:38 +01:00
Pete Batard 4ec57dc5d7
[iso] fix improper size being returned by ExtractISOFile()
* The call returned the size occupied in blocks rather than the actual file size,
  leading to issues such as Rufus not being able to identify the GRUB version used
  by Ubuntu 24.04.
2024-04-26 21:54:43 +01:00
Pete Batard 513c5f44a5
[misc] fix possible buffer overflows in _snprintf()
* _snprintf() is not always guaranteed to NUL terminate a string which could
  lead to  buffer overflows in iso_extract_files() and iso_extract_files().
* Fix this by switching to using the more secure _snprintf_s().
* Vulnerability discovered and reported by Mansour Gashasbi (@gashasbi).
* For good measure, we also switch to the strncat_s() where possible and also
  use memmove() instead of memcpy()/strcpy() as the behaviour of the latter on
  overlapping memory regions is undefined.
* Also fix some additional MinGW warnings regarding casts and nb_blocks.
2024-04-17 17:19:03 +01:00
Pete Batard 92ac1c770c
[wue] don't display WUE when '/sources/$OEM$/$$/Panther/unattend.xml' exists
* Closes #2451.
* Also update Coverity workflow to use latest actions/upload-artifact.
2024-04-15 16:35:52 +01:00
Pete Batard f813eb05d8
[iso] fix a buffer overflow in syslinux.c
* p[safe_strlen(p)] = 0; was pointless and could lead to a buffer overflow if
  the string was not already NUL terminated, so remove it and make sure we
  process a buffer that either contains legitimate Syslinux version strings
  (that are NUL terminated always) or that has been read through read_file()
  (that always adds a NUL terminator to the buffer).
* Also fix some whitespaces in related code sections and switch to using
  read_file() for GRUB version lookup.
* Vulnerability discovered and reported by Mansour Gashasbi (@gashasbi).
2024-04-10 10:26:31 +02:00
Pete Batard 5061af2b7c
[md5sum] compute and add md5sum_totalbytes to pre-existing md5sum.txt 2024-04-04 17:28:00 +01:00
Pete Batard dd8314b2f0
[ui] add runtime UEFI media validation as a selectable advanced option
* Also add Ctrl-A as a new cheat-mode to toggle the use of Rufus MBR (which is enabled by default)
  which replaces the previous UI checkbox. The Disk ID field is now completely removed as we now
  use the default values for XP and non XP installs, and will expect people with multiple disks to
  disconnect all except the one where they plan to install Windows.
2024-04-02 17:18:06 +01:00
Pete Batard 8a5a5a318a
[misc] improve readability of error code handling
* Also don't pass a read size value in WriteFileWithRetry() if we don't use it.
2024-04-01 02:16:41 +01:00
Pete Batard 52ca79816f
[md5sum] Add md5sum.txt creation and runtime UEFI validation
* This allows *runtime* validation of UEFI bootable media, such as Windows
  or Linux installers, which, considering the unreliability of USB flash
  drives, we assert is a a much better proposal than write-time validation
  that utilities like balenaEcther (and to a lesser extent MCT) provide.
* Based on uefi-md5sum (https://github.com/pbatard/uefi-md5sum).
* Unconditionally activated on ISO extraction for GPT targets for now.
  This will be changed to a user selectable option later.
2024-03-29 00:48:05 +00:00
Pete Batard 5eae8a6441
[cmp] Enable extraction of zip archives outside of ISO copy mode
* This enables the use of Ctrl-SELECT to also extract files from a .zip
  when using non-bootable, DOS, UEFI-NTFS, etc.
* Also clean up some uprintf line terminations and some additional code.
* Also fix some Coverity and MinGW warnings.
2024-03-12 17:41:27 +00:00
Pete Batard abc33122a0
[iso] increase write buffer size to work around a bug in the AMI UEFI NTFS driver
* The AMI UEFI NTFS driver (version 0x10000), which is used in many modern systems from
  ASUS, Gigabyte, intel and so on, has a major bug whereas depending on the size of the
  buffers that are used to write the data onto the NTFS volume from Windows, as well as
  read the data from the NTFS volume from UEFI, the data being read may be incorrect
  (for details on this, see https://github.com/pbatard/AmiNtfsBug).
* Especially, it appears that if the size of the buffer used to write data on Windows is
  smaller than the NTFS cluster size, the bug may be triggered.
* Because of this, we increase the size of ISO write buffer to 64 KB since, per
  https://support.microsoft.com/en-gb/topic/default-cluster-size-for-ntfs-fat-and-exfat-9772e6f1-e31a-00d7-e18f-73169155af95
  this is the maximum cluster size that can be used for NTFS volumes.
* This increase in size should also help with performance somewhat.
* Also add support for C11's _Static_assert() which may come handy.
2024-03-12 12:53:30 +00:00
Pete Batard 15e3886499
[iso] enable persistence support for Linux Mint
* Mint users sure are lucky that one of them *lied their way through* pretending that
  persistence actually used to work with previous version of Mint, when it never did,
  because they got us going through a whole refactor of the partition creation process
  just so we could make Mint persistence work.
* Closes #2428.
* Also fix a Coverity warning.
2024-02-09 16:59:28 +00:00
Pete Batard fff39c56e8
[misc] fix UEFI:NTFS partition not being added when needed in MBR mode
* Also add support for SD card readers identifying themselves as SDXC.
2024-01-17 14:10:46 +00:00
Pete Batard 710bfe7f4d
[iso] work around ISOs that use broken symbolic links for UEFI bootloaders
* Per linuxmint/linuxmint#622 some ISOs may have a /EFI/boot/bootx64.efi that
  is a symbolic to a nonexisting file.
* This is originally due to a Debian bug that was fixed in:
  5bff71fea2
* Work around this by trying to extract a working bootx64.efi from the El-Torito image.
* Also improve DumpFatDir() to not replace already existing files.
2024-01-16 17:27:37 +00:00
Pete Batard 89c1f8a72c
[iso] add BIOS support for Artix Linux
* Unfortunately, the Artix maintainers decided *NOT* to include the fat
  GRUB module for UEFI, so this will only work for BIOS boot...
2023-11-09 18:06:06 +00:00
Pete Batard 1630e912d4
[iso] add exception for Mint's LMDE
* Mint have decided to make their installation rely on a working /live/ ➔ /casper/ symlink for LMDE
  thereby breaking the promise of File System Transposition that all Debian derivatives should have.
* Because of this, trying to use FAT32 with LMDE will fail, as reported in linuxmint/live-installer#152.
* Therefore, now that we can replicate symlinks on NTFS, we add an exception to always enforce the use
  of NTFS for LMDE.
2023-10-12 18:28:56 +01:00
Pete Batard e9d588a6e0
[iso] add symlink support for target file systems that support it
* For now that means only NTFS. And we only do that for ISO-9660/Rock Ridge images.
2023-10-12 17:32:20 +01:00
Pete Batard 0bd38abd4e
[syslinux] improve support for Syslinux based Slax ISOs
* For some weird reason appending the base directory to the root syslinux.cfg
  we create does not appear to work with Slax. So we now always patch ldlinux.sys
  to include the base directory.
* Also add an exception to move the /slax/boot/EFI directory to /EFI.
* It should be noted that, as of slax-64bit-slackware-15.0.3.iso, the Slax UEFI
  Syslinux bootloaders appear to be broken (since creating a media without using
  Rufus at all per the Slax documentation does *not* produce a USB drive that was
  bootable in UEFI mode on 2 of the machines I tried).
* Also clean up some iso.c code and fix some unreachable code in ntfssect.c.
* Closes #2336.
* Closes #2338.
2023-10-11 20:46:46 +01:00
Pete Batard 8859c59548
[iso] count Rock Ridge duplicated files into the total size to process
* Duplicated symlinked Rock Ridge files were not counted into the total size needed
  to process the image and as a result, progress could go over 100% when extracting
  data (e.g. debian-live-12.1.0-amd64-lxqt.iso).
* Fix this by adding the duplicated files twice in the total block size.
2023-09-23 17:07:55 +01:00
Pete Batard 866aa22a8b
[iso] fix Debian 12 Live not using persistence in BIOS mode
* The Isolinux/Syslinux append line has been moved to /isolinux/live.cfg
  so make sure we patch that file when persistence is enabled.
2023-08-27 23:03:43 +01:00
Pete Batard 5bbcba8534
[vhd] add write support for .vhdx and .ffu images
* Also move VHD mounting function calls from iso.c to vhd.c and remove unused VHD footer elements.
2023-07-06 19:47:26 +01:00
Pete Batard ef345bf106
[uefi] fix UEFI bootloader extraction when case doesn't match
* With ISO-9660 being case sensitive, we could end up in situations where trying to extract
  '/efi/boot/bootx64.efi' for revocation validation would fail if the file on the image was
  stored as '/EFI/boot/bootx64.efi' (e.g. Debian 12).
* Fox this by storing the exact UEFI bootloader path we detected during ISO scan, and using
  this path for file extraction.
* Also add a Cancel choice to the revocation dialog and harmonize whitespaces.
2023-07-04 18:05:30 +01:00
Pete Batard 0b1c68635a
[vhd] add experimental save to Full Flash Update (FFU) image support
* Full Flash Update (FFU) image support was added to dism with Windows 10 1709
  and is an alternate way to save a virtual hard disk for restoration.
* While more modern than VHD/VHDX, FFU creation only works for drives with file
  systems that Windows natively recognizes (FAT, NTFS) and that look like Windows
  installation media, so you can forget about FFU'ing a Linux disk.
* The other *intentional* drawback that Microsoft added is that they don't want
  anybody but themselves being able to create and restore FFU images, so, even
  as they have nice FfuApplyImage()/FfuCaptureImage() calls in FfuProvider.dll
  they have decided not to make these public.
* This means that, since we don't have time to spend on figuring and direct
  hooking internal DLL calls for x86_32, x86_64, ARM and ARM64 (and worrying
  that Microsoft may ever so slightly change their DLL between revs to break
  our hooks), we just call on dism.exe behind the scenes to create the FFU.
2023-07-03 23:57:04 +01:00
Pete Batard f9370e002e
[iso] fix a crash when parsing Windows ISOs with MinGW x86_32
* MinGW32's delay loading functionality is not yet up to par with MSVC's and especially, for
  some libraries (wininet, virtdisk) attempting to delay load them simply crashes the runtime.
* This results in the MinGW32 version of the app crashing when selecting a Windows ISO, as we
  will then try to mount the ISO using virtdisk to poke the build version. Note that this crash
  does not happen with the MinGW64 version or with MSVC.
* Closes #2272.
* Also fix a Coverity warning in SaveImageThread() and improve the VHD saving code.
2023-07-02 13:15:51 +01:00
Pete Batard d4c9f2dfa1
[vhd] enable saving device to compressed VHDX
* Now that we don't have to deal with Windows 7, we can use CreateVirtualDisk() to
  automatically dump a physical disk to VHD/VHDX, so do just that
* Also move the relevant VHD/ISO imaging call to the appropriate source.
2023-07-01 20:43:26 +01:00
Pete Batard c47ee4c435
[cmp] update Bled to latest
* Adds the provision of default buffer size in bled_init()
2023-06-30 13:05:42 +01:00
Pete Batard 7eb9a6f16b
[misc] fix some benign Coverity warnings 2023-06-18 19:09:15 +02:00
Pete Batard 43764268de
[uefi] add detection and warning for revoked bootloaders
* Considering that alerting users to potential security breaches that may be
  exploited by boot media should also be performed by application that create
  them, we add detection for all the currently known revoked UEFI bootloaders,
  be it the ones from the official UEFI DBX as well as the ones from Windows'
  SkuSiPolicy.p7b, and warn the user when one such bootloader is detected on
  their source media.
* Note that, to actually be revoked, the bootloaders flagged through SkuSiPolicy
  require the copying of the .p7b to the boot media, which we are currently
  not enacting but will perform in a subsequent commit.
* Also fix a Coverity warning in hash.c.
2023-06-16 20:36:50 +02:00
Pete Batard 090bfb9770
[misc] rename checksum.c to hash.c 2023-06-11 16:18:26 +01:00
Pete Batard 3e81b38c2d
[misc] try to support folks who use a symlink for their temp dir
* Microsoft's WIM mounting APIs can't use symlinked directories and
  some folks want to use a symlinked temp dir...
* Closes #2084
2023-06-05 14:08:25 +01:00
Pete Batard 3a0f7d3813
[iso] attempt to fix the clusterfuck of GRUB 2.06 incompatible versions
* As was *ENTIRELY PREDICTIBLE*, the lack of timely releases from the GRUB
  project has resulted in distro maintainers (Ubuntu, Fedora, etc.) taking
  matters in their own hand and applying patches on top of their 2.06 version.
  However, these patches result in 2.06 bootloaders that are incompatible
  with 2.06 modules that don't have the same patches applied. Especially this
  now results in the infamous "452: out of range pointer" error message when
  using patched modules with unpatched bootloader or unpatched modules with
  patched bootloaders.
* Making this issue worse, we also have distro maintainers who won't add a
  suffix to their GRUB version, AS ONE SHOULD DO WHEN ONE APPLIES TONS OF
  PATCHES ON TOP OF A PROJECT'S SOURCE, and MISreport their non 2.06 GRUB as
  "2.06", and, because we can't detect what patches are needed from modules
  themselves (unlike what is the case for grub_debug_is_enabled), we have no
  way of telling incompatible GRUB 2.06 binaries from one another.
* As a result, we have no choice but to append a sanitized version of the ISO
  label to the GRUB version, as a means to differentiate between incompatible
  versions, and tweak our existing bootloader download mechanism to *ATTEMPT*
  to download a compatible 'core.img' from our server... where we will have
  to waste a lot of time adding new binaries and symlinks to try to make all
  these GRUB "2.06" based images work, and will probably miss quite few with
  the end results that users who are just trying to install Linux will be left
  stranded.
* Again, I have to point out how the end result of regular users wanting to
  try Linux and being unable to do so is the *DIRECT* result of the GRUB project
  maintainers having sat on a 2-year influx of CONTINUOUS patches, and thinking
  that "Release Early, Release Often" is only a gimmick, and not something that
  should apply to their project, even as they have been warned before, by yours
  truly, that *NOT* releasing on a timely basis is causing actual grievances...
  That's because, had the GRUB maintainers released on a timely basis (at least
  once a year) Fedora and Ubuntu would be using vanilla GRUB 2.07 with the memory
  patches, and we wouldn't be trying to mix that with old GRUB 2.06 binaries.
* For more on this, see #2233, noting that we will need to apply a compatibility
  breaking change during the 4.1 release, to revert the patches we applied to
  the default 2.06 'core.img' in pbatard/rufus-web@320b800592.
2023-05-16 14:05:28 +01:00
Pete Batard 0df68b6af9
[misc] further Windows 7 specifics removals
* Also remove some unused code in stdlg.c
* Note that virtdisk appears to be a vulnerable library, so we go
  through delay loading yet again...
2023-04-28 17:46:05 +01:00
Pete Batard 3177e70e25
[misc] fix CodeQL warnings 2023-04-22 16:36:27 +01:00
Pete Batard d18260bec3
[misc] update version to 4.0
* With the removal of Windows 7 support, wrong platform archs in the check for updates
  (that has now been fixed) and switch to an x86_64 default MinGW binary, we have enough
  breaking changes to warrant a version bump for the major. So just do that.
* Also fix a couple Coverity warnings and update a URL.
2023-04-22 15:46:03 +01:00
Pete Batard 41ebb9d9ca
[iso] fix persistence support for Ubuntu 23.04
* Closes #2231
2023-04-22 12:46:45 +01:00
Pete Batard 9285313f28
[iso] fix a possible buffer overflow in GetGrubVersion()
* Also increase the size for "probably a flash drive if under" from 32 GB to 128 GB.
2023-04-01 14:39:25 +02:00
Pete Batard 365449fcce
[iso] revert processing of menu.lst
* Usage scenario is too limited and the cost of doing so is simply too high.
* This reverts the relevant changes from 737db33f9c.
2023-03-22 16:52:39 +00:00
Pete Batard 737db33f9c
[iso] enable menu.lst patching
* Closes #2183
* Also improve safe_strdup() and "update" Grub4DOS to latest
  (NB: grldr.mbr has not changed in the last few years)
2023-03-18 14:20:39 +00:00
Pete Batard 6c44dccc10
[iso] duplicate Rock Ridge symbolic links for Debian non-free firmware ISOs
* Note that, because of an unrelated libcdio bug where it does not properly
  detect Rock Ridge symbolic links, some files may still not be instantiated.
* Also remove unneeded checks for ISO9660/UDF function cleanup and remove
  a workaround for an issue that has since been fixed in libcdio.
2023-02-27 17:43:39 +00:00
Pete Batard b969b7ec42
[iso] add yet another exception for Red Hat derivatives
* Fedora 37 netinst requires special handling and I don't have all day.
* Closes #2179.
* Also fix a small typo in Italian translations. Closes #2180.
2023-02-21 19:57:27 +00:00
Pete Batard c2fe08080a
[core] add provision for Windows 7 sunsetting
* Update the relevant loc messages.
* Also add a -z commandline option to force the Windows version (but without letting
  this option work as an override, if running on an unsupported platform).
* Also fix typos and broken URLs.
2022-11-22 13:35:50 +00:00
Pete Batard a6769e4fb2
[core] don't process DBT_DEVNODES_CHANGED when scanning an image
* Since 8814944c35 we may mount an ISO for the lookup of the Windows version,
  which produces DBT_DEVNODES_CHANGED messages being issued when the virtual DVD is being created or removed
* This in turn leads to unwanted device refreshes.
* This patch makes sure we ignore DBT_DEVNODES_CHANGED while scanning.
* Also improve comments in iso.c.
2022-11-16 16:50:53 +00:00
Pete Batard 165127d221
[iso] fix GRUB boot for newer Arch and derivatives
* Arch recently added a "search --no-floppy --set=root --label <LABEL>" into their
  grub.cfg, which we didn't have provision for patching, which means that, as soon
  as the user changed the label or used an Arch derivative with a label that isn't
  compliant with FAT (e.g. Athena Linux), search, and therefore boot would fail.
* Also alter the code so that we modify for more than one token if needed.
* Closes #2086
2022-11-13 20:57:26 +00:00
Pete Batard fcae51a446
[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.
2022-10-06 23:39:32 +01:00
Pete Batard 8814944c35
[wue] improve Windows version reporting from ISO/.wim
* Pick the version and build number directly from the install[.wim|.esd] XML index.
  This forces us to mount the ISO during scan, but it's the only way to get an accurate Build number...
* Also drop linking to version.dll (along with the whole version.dll delay-loading shenanigans).
2022-10-04 11:58:30 +01:00
Pete Batard 2cf183e9f1
[misc] fix Y2K38 related Coverity warnings 2022-09-14 10:58:18 +02:00
Pete Batard d9e8b8caeb
[iso] fix incorrect detection of GRUB with nonstandard prefixes
* Existing code was trying to detect if GRUB patching was needed for GRUB bootloaders
  even if they were using standard prefixes, and as a result dropped GRUB support for
  any versions that wasn't 2.04 or 2.06, since we don't have a patch for those.
* This patch restores the expected behaviour to ensure that we don't disable GRUB if
  a standard prefix is being used, regardless of the version being reported.
* Note that this issue only affected BIOS GRUB boot. UEFI GRUB boot was unaffected.
* Also set rufus-next to 3.21.
2022-09-07 18:10:30 +01:00
Pete Batard eda1f59a38
[iso] fix GRUB version detection for Fedora Rawhide
* How nice of "Open Source proponent" IBM/Red-Hat/Fedora to fix double space typos while making sure the
  provenance of the software they are using is hidden:
  https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/0024-Don-t-say-GNU-Linux-in-generated-menus.patch
* Long story short: Fedora fixed the double space in "GRUB  version", but of course they didn't upstream
  this change since it is part of a patch that removes every possible mention of GNU. This made our GRUB
  version detection break, since it relies on finding a "GRUB  version" string.
* Fix this by looking for both "GRUB  version" and "GRUB version".
* This, however, does not fix Fedora Rawhide BIOS boot, since they also added custom GRUB calls such as
  'grub_debug_is_enabled', which we don't have in our vanilla produced GRUB binary.
* Closes #2002.
2022-07-28 15:47:05 +01:00
Pete Batard 2b7b81808f
[misc] improve/factorize '/' ↔ '\' conversions 2022-07-09 18:16:42 +01:00