【问题标题】:How do I find the offset and signature of the PE header in python?如何在 python 中找到 PE 标头的偏移量和签名?
【发布时间】:2015-07-16 14:18:20
【问题描述】:
我不知道该怎么做。我知道签名是 50 45 00 00 但我不确定如何获取 .exe 文件并计算它在 python 中的使用次数。
最后,它应该有幻数,PE头的偏移量,PE签名,入口点,图像库,带有PE的部分数,带有偏移量的每个部分的名称。
这是我目前所拥有的(仅适用于幻数):
def sig(content):
content = content.encode("hex")
content = str(content)
signature = content[0:2].upper()
sig2 = content[2:4].upper()
print "Magic Number: " + str(signature) + " " + str(sig2)
如果你能帮忙,请告诉我!
【问题讨论】:
标签:
python
file
portable-executable
【解决方案1】:
除了偏移之外的一切
import struct
import pefile
import pydasm
pe = pefile.PE(filename)
print "PE Signature: " + hex(pe.VS_FIXEDFILEINFO.Signature)
print "Image Base: " + hex(pe.OPTIONAL_HEADER.ImageBase)
print "Address of EntryPoint: " + hex(pe.OPTIONAL_HEADER.AddressOfEntryPoint)
print "RVA Number and Size: " + hex(pe.OPTIONAL_HEADER.NumberOfRvaAndSizes)
print "Number of Sections within PE: " + hex(pe.FILE_HEADER.NumberOfSections)
for section in pe.sections:
print 'Section Name: ' + (section.Name)