如何使用pefile从PE文件中获取.text部分

问题描述 投票:0回答:1

如何使用

.text
模块从 PE 获取
pefile
部分(或任何其他部分)的内容?

python python-2.7 portable-executable
1个回答
14
投票

sections
PE类实例的attr是sections列表,每一项都有get_data函数:

>>> import pefile
>>> pe = pefile.PE('./psfile.exe')

>>> for section in pe.sections:
...   print (section.Name, hex(section.VirtualAddress),
...     hex(section.Misc_VirtualSize), section.SizeOfRawData )
... 
('.text\x00\x00\x00', '0x1000', '0xd3e4', 57344)
('.rdata\x00\x00', '0xf000', '0x5504', 24576)
('.data\x00\x00\x00', '0x15000', '0x3684', 8192)
('.rsrc\x00\x00\x00', '0x19000', '0x444', 4096)

文本部分数据的前 10 个字节,例如:

>>> pe.sections[0].get_data()[:10]
'\x81\xec\x90\x00\x00\x00j>\x8dD'
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.