
An RVA (relative virtual address) identifies a location relative to the base of a loaded PE image. A file offset identifies a byte position in the file on disk. The two are not generally equal because Windows maps sections using virtual addresses that can differ from their raw file locations. Converting between them requires the section table and careful bounds checks.

Understand the three address types
| Address | Meaning | Example |
|---|---|---|
| File offset | Position in the on-disk file | 0x650 |
| RVA | Position relative to loaded image base | 0x1250 |
| VA | Virtual address in the loaded process | 0x140001250 |
The VA example assumes an image base of 0x140000000. Actual load addresses may differ from the preferred ImageBase because of relocation and ASLR. In an offline parser, do not confuse a preferred address with a runtime observation.
Work through a hexadecimal conversion
Imagine a PE section with VirtualAddress 0x1000, VirtualSize 0x900, PointerToRawData 0x400 and SizeOfRawData 0x800. We want the file offset for RVA 0x1250. Subtract the section virtual address to obtain the displacement, 0x250. Because that displacement is within both the declared virtual span and raw data size, add it to the raw pointer. The resulting file offset is 0x650.
Displacement = 0x1250 - 0x1000 = 0x250
File offset = 0x400 + 0x250 = 0x650
Now try RVA 0x1850. The displacement is 0x850, which lies within the example’s virtual size but beyond its raw data size. That location may represent zero-filled memory rather than an existing byte in the file. Returning 0xC50 as if it were valid raw data would be incorrect.
Handle exceptions before trusting the result
Header RVAs can map directly to header file offsets when the range is within valid, file-backed headers. The certificate table is a notable exception among data-directory entries: its address is a file offset, not an RVA. Section padding and alignment also matter. Some parsers use the greater of VirtualSize and SizeOfRawData to find a candidate section, but that alone does not prove that a requested byte exists both on disk and in the intended mapped region.
Validate every requested range against the actual file length and section bounds. Use checked arithmetic to prevent integer overflow. Reject or flag ambiguous mappings if malformed sections overlap. A parser should return a clear error or an unmapped result rather than silently choosing an arbitrary section.
FAQ
Can I add an RVA directly to the file start?
Only in cases where the file layout genuinely matches that address, such as valid header-backed ranges. It is not a general conversion rule.
Does AddressOfEntryPoint contain a file offset?
No. It is an RVA in the PE optional header.
Can every RVA be converted?
No. Unmapped and zero-filled locations may have no corresponding on-disk byte.
Analyst takeaway
Treat address translation as a validated operation, not merely a formula. Inspect the section table in the PEFile report before interpreting a directory or entry-point location. The numbers above are synthetic examples for learning, not results from a real executable.
You must be logged in to post a comment.