From a75a271582dc8c8a755d1480a151a69e643e98e4 Mon Sep 17 00:00:00 2001 From: Schamper <1254028+Schamper@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:29:05 +0200 Subject: [PATCH] Make adding virtual NTFS filesystem more resilient --- dissect/target/helpers/loaderutil.py | 29 +++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/dissect/target/helpers/loaderutil.py b/dissect/target/helpers/loaderutil.py index 475cabb2a..fd7c2be93 100644 --- a/dissect/target/helpers/loaderutil.py +++ b/dissect/target/helpers/loaderutil.py @@ -42,9 +42,32 @@ def add_virtual_ntfs_filesystem( fh_sds = _try_open(fs, sds_path) if any([fh_boot, fh_mft]): - ntfs = NtfsFilesystem(boot=fh_boot, mft=fh_mft, usnjrnl=fh_usnjrnl, sds=fh_sds) - target.filesystems.add(ntfs) - fs.ntfs = ntfs.ntfs + ntfs = None + + try: + ntfs = NtfsFilesystem(boot=fh_boot, mft=fh_mft, usnjrnl=fh_usnjrnl, sds=fh_sds) + except Exception as e: + if fh_boot: + message = "Failed to load NTFS filesystem from %s, retrying without $Boot file" + else: + message = "Failed to load NTFS filesystem from %s, skipping" + + log.warning(message, fs) + log.debug("", exc_info=e) + + if fh_boot: + try: + # Try once more without the $Boot file + ntfs = NtfsFilesystem(mft=fh_mft, usnjrnl=fh_usnjrnl, sds=fh_sds) + except Exception: + log.warning("Failed to load NTFS filesystem from %s without $Boot file, skipping", fs) + + # Only add it if we have a valid NTFS with an MFT + if ntfs and ntfs.ntfs.mft: + target.filesystems.add(ntfs) + fs.ntfs = ntfs.ntfs + else: + log.warning("Failed to load NTFS filesystem from %s, skipping", fs) def _try_open(fs: Filesystem, path: str) -> BinaryIO: