PeFileRvaToOffset
Description
Convert an RVA (offset from ImageBase) to a file offset by finding the section whose [VirtualAddress, VirtualAddress + VirtualSize) contains rva, then adding the in-section delta to the section’s PointerToRawData.
Success
Returns true; *out_offset is set.
Failure
Returns false when no section covers rva or the result would point past data_size.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Pe.c:194:
// The CodeView record sits at RVA 0x1020 -> file offset 0x420.
u64 off = 0;
bool ok = PeFileRvaToOffset(&pe, CV_REC_RVA, &off) && off == CV_REC_RAW_OFF;
// RVA outside any section should fail cleanly.
- In
Pe.c:198:
// RVA outside any section should fail cleanly.
u64 garbage = 0;
ok = ok && !PeFileRvaToOffset(&pe, 0xdead0000, &garbage);
PeFileDeinit(&pe);- In
Pe.c:291:
u64 dir_offset;
if (!PeFileRvaToOffset(ctx->out, (u32)ctx->debug_dir_rva, &dir_offset)) {
LOG_ERROR("PE: debug directory RVA not in any section");
return;- In
Pe.c:461:
}
bool PeFileRvaToOffset(const PeFile *self, u32 rva, u64 *out_offset) {
if (!self || !out_offset)
return false;
Last updated on