diff --git a/LibCpp2IL/Elf/ElfFile.cs b/LibCpp2IL/Elf/ElfFile.cs index 65c5c997..7b5e4c11 100644 --- a/LibCpp2IL/Elf/ElfFile.cs +++ b/LibCpp2IL/Elf/ElfFile.cs @@ -691,6 +691,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)); }