Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
dncil — FLARE 团队的开源库,用于反汇编通用中间语言(CIL)指令。 | Kitploit
工具/GitHubGitHub/mandiant/dncil
逆向工程恶意软件分析二进制分析
GitHubmandiant/dncil

dncil

FLARE 团队的开源库,用于反汇编通用中间语言(CIL)指令。

查看仓库
1782019天前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

dncil

PyPI - Python Version Last release CI Downloads License

dncil 是一个用 Python 编写的公共中间语言(CIL)反汇编库,支持解析 .NET 托管方法的头、指令和异常处理程序。解析后的数据通过面向对象的 API 暴露,帮助您使用 dncil 快速开发 CIL 分析工具。

为什么选择 Python?现有的支持 CIL 反汇编的库,如 dnLib,是用 C# 编写的。要利用这些工具,您必须构建 C# 应用程序,这需要 C# 开发经验。使用 dncil(一个纯 Python 替代方案),您可以:

  1. 无需 C# 经验即可以编程方式分析 CIL。
  2. 快速开发和测试您的 CIL 分析工具。
  3. 轻松将您的 CIL 分析工具与现有的 Python 项目集成。

示例

示例脚本 print_cil_from_dn_file.py 使用 dncil 结合 .NET 分析库 dnfile 来反汇编 .NET 可执行文件中找到的托管方法。让我们看看它能做什么。

首先,我们编译以下 C# 源代码:

root@kitploit:~
using System;	

public class HelloWorld
{
    public static void Main(string[] args)
    {
        Console.WriteLine ("Hello World!");
    }
}

编译结果为包含 .NET 元数据的 PE 可执行文件,这些元数据告知 公共语言运行时(CLR)如何执行我们的代码。我们使用 dnfile 解析此元数据,从而获得托管方法 Main 的偏移量。然后我们使用 dncil 反汇编并显示存储在此位置的 CIL 指令。

让我们看看上面的实际效果:

root@kitploit:~
$ python scripts/print_cil_from_dn_file.py hello-world.exe 

Method: Main
0000    00                  nop            
0001    72 01 00 00 70      ldstr          "Hello World!"
0006    28 04 00 00 0a      call           System.Console::WriteLine
000B    00                  nop            
000C    2a                  ret            

我们的方法 Main 由 CilMethodBody 类表示。此类保存包含给定托管方法的头、CIL 指令和异常处理程序的数据。它还公开了各种辅助函数:

root@kitploit:~
>  main_method_body.flags
SmallFormat  :  false
TinyFormat   :  false
FatFormat    :  false
TinyFormat1  :  true
MoreSects    :  false
InitLocals   :  false
CompressedIL :  false
>  main_method_body.size
14
>  hexdump.hexdump(main_method_body.get_bytes())
00000000: 36 00 72 01 00 00 70 28  04 00 00 0A 00 2A        6.r...p(.....*
>  hexdump.hexdump(main_method_body.get_header_bytes())
00000000: 36                                                6
>  hexdump.hexdump(main_method_body.get_instruction_bytes())
00000000: 00 72 01 00 00 70 28 04  00 00 0A 00 2A           .r...p(.....*

在我们的托管方法 Main 中找到的每个 CIL 指令都由 Instruction 类表示。此类保存包含给定 CIL 指令的偏移量、助记符、操作码和操作数的数据。它还公开了各种辅助函数:

root@kitploit:~
>  len(main_method_body.instructions)
5
>  insn = main_method_body.instructions[1]
>  insn.offset
1
>  insn.mnemonic
'ldstr'
>  insn.operand
token(0x70000001)
>  insn.is_ldstr()
True
>  insn.size
5
>  hexdump.hexdump(insn.get_bytes())
00000000: 72 01 00 00 70                                    r...p
>  hexdump.hexdump(insn.get_opcode_bytes())
00000000: 72                                                r
>  hexdump.hexdump(insn.get_operand_bytes())
00000000: 01 00 00 70                                       ...p

安装

要安装 dncil,请使用 pip 获取 dncil 模块:

root@kitploit:~
$ pip install dncil

要运行示例脚本,请确保安装 dnfile。或者,按照下方 开发 部分所述,使用开发依赖项安装 dncil。

参见 print_cil_from_bytes.py 获取使用 dncil 打印包含 .NET 托管方法的字节流中 CIL 指令的快速示例。

开发

如果您想查看和修改 dncil 源代码,您需要从 GitHub 下载它并在本地安装。

使用以下命令在本地安装带开发依赖项的 dncil:

root@kitploit:~
$ pip install /local/path/to/src[dev]

您需要 dncil 的开发依赖项来运行下述测试和代码规范检查。

测试

使用以下命令运行测试:

root@kitploit:~
$ pytest /local/path/to/src/tests

代码规范检查

使用以下命令识别格式错误:

root@kitploit:~
$ black -l 120 -c /local/path/to/src
$ isort --profile black --length-sort --line-width 120 -c /local/path/to/src
$ mypy --config-file /local/path/to/src/.github/mypy/mypy.ini /local/path/to/src/dncil/ /local/path/to/src/scripts/ /local/path/to/src/tests/

致谢

dncil 基于 dnLib 中的 CIL 解析代码。

下载工具