📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  Debuggers  >>  How can we map RVA (Relative Virtual Address) of a location to PE file offset?

Topic created on: December 24, 2010 01:01 CST by Usman .

Hello,

I need to map RVA (Relative virtual address that's taken from pdb file) to PE file(EXE) offset when reading PE file from a disk location. For this I need to convert RVA to file offset so that I can read out GUIDS(CLSID,IID's) from that location.


Regards
Usman

  cseagle     December 24, 2010 11:48.20 CST
Very roughly:

IMAGE_SECTION_HEADER *s;
//initialize s to point to section header array
//or read one section header at a time fro the file
...
//n is the number of sections as specified in the
//pe headers
DWORD fileOffset = 0;
for (int i = 0; i < n; i++) {
   DWORD end = s[i].VirtualAddress + s[i].Misc.VirtualSize;
   if (myRVA >= s[i].VirtualAddress && myRVA < end) {
      fileOffset = myRVA - s[i].VirtualAddress + s[i].PointerToRawData;
      break;
   }
}
if (fileOffset) {
   //do something
}

I leave it to you to fill in the holes.  There are plenty of references on the PE file format out there.

  yuansunxue     December 27, 2010 02:18.39 CST
maybe you can use LoadPE.EXE

  Usman     December 28, 2010 01:53.21 CST
@cseagle: Can you please give me your mailing id so that I can give you complete detail about RVA which's I am getting in case of EXE from pdb,  and GUID value that I want read from binary by reading it as binary file. Because this code is not returning correct Offset which's required, it's just returning some other arbitrary value. I have CFF explorer which' displaying different offset location in the PE file rather than this code returning.(Might be image base RVA needs to be subtracted from its given offset...?)

  RabidCicada     January 6, 2011 11:29.40 CST
Hey there.  There are lots of extremely good documentations of the PE file format.  I suggest you read Matt Pietreks articles.  RVA's are simple to calculate but getting it done right is just a matter of tedium and propper offsetting.

You need to understand how a file on disk is laid out versus how it is laid out in memory.  You need to pay close attention to alignment values for in-memory versus in-file.  You also need to be aware that some files move code around (don't know your RE target).

Resources:
http://msdn.microsoft.com/en-us/magazine/cc301805.aspx
http://msdn.microsoft.com/en-us/magazine/cc301808.aspx
http://msdn.microsoft.com/en-us/magazine/ms809762.aspx
https://www.openrce.org/reference_library/files/reference/PE%20Format.pdf

  savagefarmer     August 26, 2011 10:28.28 CDT
Sorry to bump, but I found a decent article on the differences between Relative Virtual Addresses (RVAs) and PE file offsets--and how to translate between them-- that I thought I'd share.

It can be found here.

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit