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

标签 python python-2.7 portable-executable

<分区>

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

最佳答案

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'

关于python - 如何使用 pefile 从 PE 文件中获取 .text 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20027990/

相关文章:

c - C语言中如何获取每个PE段的起始地址?

python - 如何限制基类方法只运行一次

python - 使用 python 生成 RA vs DEC 赤道坐标图

python - 使用 Selenium 和partial_link_text 抓取 html 元素

python - 如何修改PE文件头中的TimeDateStamp字段?

windows - 替换现有 Win32 .exe 中的 PE stub

python - 我的 python 脚本的 CX_Freeze——修复模块错误?

php - 如何更新 Excel 数据? (刷新所有查询)

python - 问题读取 csv 文件

python - 带有外部库 psycopg2 的 lambda python 函数 - 没有名为 psycopg2 的模块