public SafePointer RVA2VA(SafePointer rva)
{
// find which section is our rva in
SectionHeader ish = new SectionHeader();
foreach (SectionHeader sectionHeader in PEHeaders.SectionHeaders)
{
if ((rva.Address >= sectionHeader.VirtualAddress) &&
(rva.Address < sectionHeader.VirtualAddress + sectionHeader.SizeOfRawData))
{
ish = sectionHeader;
break;
}
}
if (ish.VirtualAddress == 0) throw new InvalidOperationException("RVA does not belong to any section");
// calculate the VA
rva.Address = (rva.Address - ish.VirtualAddress + ish.PointerToRawData);
return rva;
}