DecoyMini 技术交流社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3586|回复: 0

[工具] 解析 .NET 可执行程序 —— dnfile

[复制链接]

172

主题

34

回帖

30

荣誉

Rank: 9Rank: 9Rank: 9

UID
2
积分
339
精华
1
沃币
2 枚
注册时间
2021-6-24

论坛管理

发表于 2022-12-5 09:15:35 | 显示全部楼层 |阅读模式

特性


  • 尽可能多地解析,即使文件部分格式错误;
  • 便于使用,开发时考虑了 IDE 自动完成功能;

快速开始


  1. pip install dnfile
复制代码

然后创建一个简单的程序来加载 .NET 二进制文件、解析它并显示有关流和元数据表的信息。

  1. import sys
  2. import dnfile

  3. filepath = sys.argv[1]

  4. pe = dnfile.dnPE(filepath)
  5. pe.print_info()
复制代码

一切都是对象,原始结构值存储在对象的 "struct" 属性中,可以从 dnPE 对象的 "net" 属性访问 CLR 目录条目对象。

  1. import dnfile
  2. import hashlib

  3. pe = dnfile.dnPE(FILEPATH)

  4. # access the directory entry raw structure values
  5. pe.net.struct

  6. # access the metadata raw structure values
  7. pe.net.metadata.struct

  8. # access the streams
  9. for s in pe.net.metadata.streams_list:
  10.     if isinstance(s, dnfile.stream.MetaDataTables):
  11.         # how many Metadata tables are defined in the binary?
  12.         num_of_tables = len(s.tables_list)

  13. # the last Metadata tables stream can also be accessed by a shortcut
  14. num_of_tables = len(pe.net.mdtables.tables_list)

  15. # create a set to hold the hashes of all resources
  16. res_hash = set()
  17. # access the resources
  18. for r in pe.net.resources:
  19.     # if resource data is a simple byte stream
  20.     if isinstance(r.data, bytes):
  21.         # hash it and add the hash to the set
  22.         res_hash.add(hashlib.sha256(r.data).hexdigest())
  23.     # if resource data is a ResourceSet, a dotnet-specific datatype
  24.     elif isinstance(r.data, dnfile.resource.ResourceSet):
  25.         # if there are no entries
  26.         if not r.data.entries:
  27.             # skip it
  28.             continue
  29.         # for each entry in the ResourceSet
  30.         for entry in r.data.entries:
  31.             # if it has data
  32.             if entry.data:
  33.                 # hash it and add the hash to the set
  34.                 res_hash.add(hashlib.sha256(entry.data).hexdigest())
复制代码

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|小黑屋|DecoyMini 技术交流社区 ( 京ICP备2021005070号 )

GMT+8, 2024-4-20 02:30 , Processed in 0.057331 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表