From a238a20a861acf49e15e6ed35312fc8b542a9b48 Mon Sep 17 00:00:00 2001 From: LTRData Date: Fri, 24 May 2024 14:09:24 +0200 Subject: [PATCH] Improved corruption resilient behavior --- Library/DiscUtils.Ntfs/NtfsFileSystem.cs | 18 +++++++++++++++--- .../DiscUtils.Ntfs/StructuredNtfsAttribute.cs | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Library/DiscUtils.Ntfs/NtfsFileSystem.cs b/Library/DiscUtils.Ntfs/NtfsFileSystem.cs index 14ec3a87f..d9aba7085 100644 --- a/Library/DiscUtils.Ntfs/NtfsFileSystem.cs +++ b/Library/DiscUtils.Ntfs/NtfsFileSystem.cs @@ -132,9 +132,21 @@ public NtfsFileSystem(Stream stream) if (VolumeInfo.Version >= VolumeInformation.VersionW2k) { _context.SecurityDescriptors = new SecurityDescriptors(GetFile(MasterFileTable.SecureIndex)); - _context.ObjectIds = new ObjectIds(GetFile(GetDirectoryEntry(@"$Extend\$ObjId").Value.Reference)); - _context.ReparsePoints = new ReparsePoints(GetFile(GetDirectoryEntry(@"$Extend\$Reparse").Value.Reference)); - _context.Quotas = new Quotas(GetFile(GetDirectoryEntry(@"$Extend\$Quota").Value.Reference)); + + if (GetDirectoryEntry(@"$Extend\$ObjId") is { } objIdFile) + { + _context.ObjectIds = new ObjectIds(GetFile(objIdFile.Reference)); + } + + if (GetDirectoryEntry(@"$Extend\$Reparse") is { } reparse) + { + _context.ReparsePoints = new ReparsePoints(GetFile(reparse.Reference)); + } + + if (GetDirectoryEntry(@"$Extend\$Quota") is { } quota) + { + _context.Quotas = new Quotas(GetFile(quota.Reference)); + } } #if false diff --git a/Library/DiscUtils.Ntfs/StructuredNtfsAttribute.cs b/Library/DiscUtils.Ntfs/StructuredNtfsAttribute.cs index d6ad567bc..4b66d3c4d 100644 --- a/Library/DiscUtils.Ntfs/StructuredNtfsAttribute.cs +++ b/Library/DiscUtils.Ntfs/StructuredNtfsAttribute.cs @@ -24,6 +24,7 @@ using System.Buffers; using System.IO; using DiscUtils.Streams; +using LTRData.Extensions.Formatting; namespace DiscUtils.Ntfs; @@ -96,11 +97,18 @@ public override string ToString() public override void Dump(TextWriter writer, string indent) { - Initialize(); - writer.WriteLine($"{indent}{AttributeTypeName} ATTRIBUTE ({(Name == null ? "No Name" : Name)})"); - _structure.Dump(writer, $"{indent} "); + try + { + Initialize(); + writer.WriteLine($"{indent}{AttributeTypeName} ATTRIBUTE ({Name ?? "No Name"})"); + _structure.Dump(writer, $"{indent} "); - _primaryRecord.Dump(writer, $"{indent} "); + _primaryRecord.Dump(writer, $"{indent} "); + } + catch (Exception ex) + { + writer.WriteLine($"{indent}{AttributeTypeName} ATTRIBUTE: {ex.JoinMessages()}"); + } } private void Initialize()