From 4a2b36f07dcd65d134a7b8c5f10bab8ec7d8b360 Mon Sep 17 00:00:00 2001 From: Benjamin Moir Date: Sun, 22 Sep 2024 22:39:52 +1000 Subject: [PATCH] Support EOF data in debug data entries. --- .../Debug/SerializedDebugDataEntry.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/AsmResolver.PE/Debug/SerializedDebugDataEntry.cs b/src/AsmResolver.PE/Debug/SerializedDebugDataEntry.cs index 4711a6063..79a388274 100644 --- a/src/AsmResolver.PE/Debug/SerializedDebugDataEntry.cs +++ b/src/AsmResolver.PE/Debug/SerializedDebugDataEntry.cs @@ -43,17 +43,22 @@ public SerializedDebugDataEntry( /// protected override IDebugDataSegment? GetContents() { - if (_sizeOfData == 0) - return null; + BinaryStreamReader reader; - var reference = _context.File.GetReferenceToRva(_addressOfRawData); - if (!reference.CanRead) + if (_addressOfRawData == 0 || _context.File.MappingMode == File.PEMappingMode.Unmapped) + { + if (!_context.File.TryCreateReaderAtFileOffset(_pointerToRawData, out reader)) + { + _context.BadImage("Debug data entry contains an invalid file offset."); + return null; + } + } + else if (!_context.File.TryCreateReaderAtRva(_addressOfRawData, out reader)) { _context.BadImage("Debug data entry contains an invalid RVA."); return null; } - var reader = reference.CreateReader(); if (_sizeOfData > reader.Length) { _context.BadImage("Debug data entry contains a too large size.");