Addresses in reverse engineering
2023年7月17日
Relative Virtual Address (RVA)
RVA通常用module name + 地址
表示。如图,CheatEngine的Memory Viewer显示的是RVA。

v2game.exe+563d47
in CheatEngine notationx64dbg可以转换各种地址。在CPU tab,右击选择Go to -> Expression (ctrl+G),输入module name + 地址
[1],下方会显示section offset。x64dbg不显示.exe
。点击OK,CPU tab就会显示那一行代码。注意下方的status bar,第一个地址是section offset,第二个是RVA,第三个是file offset。

.text:010b3d47
是section offset,v2game.exe:$563D47
是RVA,#563147
是file offset。
IDA不能直接读取RVA。如果要把RVA转换为VA,在执行代码的功能里(图)贴上下面的Python代码,把362E10改为你要转换的RVA。代码里的ea指的是va。print的结果显示在输出窗口。
static main()
{
auto rva = xtol("362E10");
auto base = get_imagebase();
auto ea = rva + base;
Message("Section offset is %08X\n", ea);
}
该数值被IDA叫做current address,实际是VA,与section offset相同。
相反,如果要把(current) address转换为RVA,用以下代码。
rva = int("b23fa7", 16)
base = idaapi.get_imagebase()
ea = rva + base
print('RVA=' + hex(ea))
Virtual Address (VA)
RVA + ImageBase = VA
VA不经常用到。
注意,《The IDA Pro Book, 2nd Edition: The Unofficial Guide to the World’s Most Popular Disassembler》(Chapter 5.1)把virtual address当作section offset。
Section offset
PE文件格式定义了多个sections,包括.text
, .data
, .rdata
, .idata
, .reloc
, .rsrc
, .debug
等。[2] .text
指的是程序代码。
所以Section offset .text:010b3d47
指的是在.text
section里的第010b3d47行。
File offset
File offset指的是一行代码在整个exe文件中的位置。
在IDA Interactive Disassembler,用file offset跳转比较方便。在菜单选择 Jump -> Jump to file offset,然后输入地址,这里不需要输入module name。点击OK,当前view就会跳转到那一行。
在Disassembly view,左边是section offset,下面状态栏的第一个地址是file offset。

Hex Editor一般显示的是file offset。我用HxD Hex Editor搜索字符串teleport,发现其中一个位置是9ee880。这是file offset。把该地址输入IDA, Jump to file offset,发现该地址是在.rdata
section。
References
- . Values. x64dbg documentation. [2023-07-18].↑
- SATYAJIT DAULAGUPHU. A Comprehensive Guide To PE Structure, The Layman’s Way. . 2022-08-15 [2023-07-18].↑
[…] Section offset B84F3A calls function readFromLua. It reads pops.MIL_HAS_EVERYDAY_NEED. readFromLua multiplies a Lua number by 32768, then round it. Hence [latex]round(-0.1 times 32768)=-3277[/latex]. […]