diff --git a/LibCpp2IL/Elf/ElfFile.cs b/LibCpp2IL/Elf/ElfFile.cs index 905d0001..8e067fe7 100644 --- a/LibCpp2IL/Elf/ElfFile.cs +++ b/LibCpp2IL/Elf/ElfFile.cs @@ -685,6 +685,13 @@ public override long MapVirtualAddressToRaw(ulong addr, bool throwOnError = true throw new InvalidOperationException($"No entry in the Elf PHT contains virtual address 0x{addr:X}"); else return VirtToRawInvalidNoMatch; + + if (addr >= section.VirtualAddress + section.RawSize) + if (throwOnError) + throw new InvalidOperationException( + $"Virtual address {section.VirtualAddress:X} is located outside of the file-backed portion of Elf PHT section at 0x{section.VirtualAddress:X}"); + else + return VirtToRawInvalidOutOfBounds; return (long) (addr - (section.VirtualAddress - section.RawAddress)); }