Skip to content

Commit

Permalink
ELF: Properly handle address outside of file-backed regions
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeFZ committed Jan 1, 2024
1 parent 00b0e70 commit 320bb2f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions LibCpp2IL/Elf/ElfFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 320bb2f

Please sign in to comment.