用C获取可执行文件的PE和VA
我想用 C 语言编写一个小程序来提取 COFF 可执行文件的 PE(入口点)和 VA(虚拟地址)。我怎样才能做到这一点?
I want to write a little program in C to extract the PE (Entry Point) and VA (Virtual Address) of a COFF executable. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://pastebin.com/LTN6VjJE
请检查上面的程序............ ...
http://pastebin.com/LTN6VjJE
Please check the above program..............
您想要的两个字段都位于可选标头中(可选,因为它不会出现在目标文件中 - 它在图像中是必需的)。文件中的第一个字节是 DOS 存根,但在 0x3c 处您将找到 PE 签名的偏移量。转到那里,您将找到 PE 签名 (
PE\0\0
)。紧接着是文件头,长度为 0x14 字节,之后是可选头。AddressOfEntryPoint
位于可选标头中的 0x10 字节处,跨越四个字节,BaseOfCode
紧随其后的 0x14(也是 4 个字节)。因此,简而言之:
(PE 签名偏移量)+0x28
开始读取 4 个字节——这是AddressOfEntryPoint
从(PE 签名偏移量)+0x28
BaseOfCode
请记住在必要时处理字节顺序
Both the fields you want are in the Optional Header (optional in that it doesn't appear in object files -- it's required in images). The first bytes in the file are the DOS stub, but at 0x3c you'll find the offset of the PE signature. Go there and you'll find the PE signature (
PE\0\0
). Immediately after that is the file header, which is 0x14 bytes long, and after that is the optional header.AddressOfEntryPoint
is 0x10 bytes into the optional header and spans four bytes, andBaseOfCode
is right after it at 0x14 (also 4 bytes).So, in short:
(PE signature offset)+0x28
-- this is theAddressOfEntryPoint
(PE signature offset)+0x2c
-- this is theBaseOfCode
Remember to deal with endianness if necessary