一个用于解析可移植可执行文件的轻量级Python模块。

pereader的Python项目详细描述


游牧者

一个用于解析可移植可执行文件的轻量级Python模块。解析器报告PE文件异常和畸形的警告,这些异常和畸形可能表示格式错误。Windows定义的结构可以作为PE对象(winnt.h约定)上的属性访问,并提供额外的元数据,例如哈希、熵、set标志和解释字符串。请查看文件calc.exeaadauthhelper.dll和{a3},以了解解析器的特性和功能。在

发展

我们目前正在讨论Corkami project的建议,以增加其与Windows加载器的相似性。若要请求新的解析器功能或报告错误,请提交问题。请随时为这个项目捐款。在

安装

pip install pereader

使用

解析计算.exe来自文件:

^{pr2}$

功能和API

结构以大写字母的形式命名,字段在pascalase中被设置为相应结构的属性。字段名可以在源代码中找到。存储结构的容器和列表以snake_case命名,解释字段使用匈牙利符号的变体设置。下面是一个包含API最有用部分的图表。下面列出的一些模式使访问特定的结构和字段更容易。在

特点:

在相应的头上将标志设置为布尔值,真标志存储在.Flags中。在

熵:

对于非常大的文件,在节标题上设置的熵计算可能会很慢。要关闭它们:

pe = pereader.PE('calc.exe', is_entropy=False)

导出访问模式:

for exp in pe.directory_entry_export.symbols:
    print(hex(exp.address), exp.name, exp.ordinal)

地址也直接设置在符号上。在

print(pe.directory_entry_export.symbols.CreateTokenAuthBuffer)

导入访问模式:

for dll in pe.directory_entry_import.dlls:
    print(dll.name)
    for imp in dll:
	print(hex(imp.address), imp.name)

地址也可以直接在DLL上设置。在

for dll in pe.directory_entry_import.dlls:
    if hasattr(dll, 'memmove'):
        print(dll.memmove)

字符串表访问模式(使用快捷方式):

for entry in pe.directory_entry_resource.resource_directory.entries:
    if entry.RESOURCE_DIRECTORY_ENTRY.str_Type == 'RT_STRING':
        for k in entry.strings:
	    print(k, entry.strings[k])

版本信息访问模式(使用快捷方式):

for entry in pe.directory_entry_resource.resource_directory.entries:
    if entry.RESOURCE_DIRECTORY_ENTRY.str_Type == 'RT_VERSION':
    	version = entry.version

	for e in version.stringfileinfo:
	    for stringtable in e.stringtables:
	        for string in stringtable.strings:
		    print(string.str_szKey, string.str_Value)

	for e in version.varfileinfo:
	    for var in e.vars:
	        for w1, w2 in var.translations:
		    print(w1, w2)

重新定位访问模式:

for reloc in pe.directory_entry_basereloc.relocations:
    for target in reloc.targets:
        print(target.Value, target.str_Type)

调试访问模式:

for entry in pe.directory_entry_debug.entries:
    print(entry.DEBUG_DIRECTORY.str_Type)
    print(entry.ENTRY)

线程本地存储访问模式:

print(pe.directory_entry_tls.TLS_DIRECTORY)

加载配置访问模式:

print(pe.directory_entry_load_config.LOAD_CONFIG_DIRECTORY)

绑定导入访问模式:

for desc in pe.directory_entry_bound_import.descriptors:
    print(desc.str_Name, desc)

延迟加载访问模式:

for dll in pe.directory_entry_delay_import.dlls:
    print(dll.name)
    for imp in dll:
	print(hex(imp.address), imp.name)

资源

Windows开发人员中心规范-https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
Win32定义-https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-tools/widl/include/winnt.h
体育课程-http://opensecuritytraining.info/LifeOfBinaries.html
资源目录-http://www.skynet.ie/~caolan/publink/winresdump/winresdump/doc/resfmt.txt
版本信息-http://blog.dkbza.org/2007/02/pefile-parsing-version-information-from.html?view=classic
调试目录-http://www.debuginfo.com/articles/debuginfomatch.html

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java时区。getTimeZone()返回给定空字符串的GTC区域,是否不需要?   java如何向用户显示更改的字符串   Eclipse中的java Python路径不工作   Java对象数组行为异常?   java工具,可以在不完全覆盖异常状态的情况下查找代码片段   oauth使用Xero的Java SDK支持多个私有应用的身份验证?   java无法从远程方法获取值   java如何使用Hibernate将父对象映射到子对象?   java如何导入Eclipse警告?   api最佳3D Java引擎   java如何在Rest客户端使用的Json序列化程序上设置特定格式的表示?   java在EclipseRCP4中使用默认命令。十、   java JBoss v.s.Tomcat JDBC驱动程序注册差异   java如何在JDesktopPane的后台创建JLabel?   java I在静态main方法和输入非静态值方面有问题