.net - 我们可以反汇编(使用 ILDasm)一个 NGen 编辑的程序集吗?

标签 .net ngen ildasm

如果我 NGen 一个程序集,ildasm 仍然分解它是否正常?

好的。我编写了一个 HelloWorld 类库,随后的 dll 被命名为 NGenILDasmTest.dll。
--> 针对 .Net fw 4。

从 Vs 2010 命令提示符,我做了

gacutil -i NGenILDasmTest.dll

我可以看到安装在 GAC 中的程序集。我运行 ildasm 以便我可以查看 IL。
到目前为止一切顺利。

然后我跑
ngen NGenILDasmTest.dll

(我没有为 ngen 指定任何选项)。这个程序集成功编译。我在文件夹下找到了一个名为 NGenILDasmTest.ni.dll 的文件
C:\Windows\Assembly\NativeImages_v4.0.30319_32\NGenILDasmTest\81d49dd4c7df22fb3df530402b58ffc9

现在,当我像下面这样运行 ildasm
ildasm "C:\Windows\Assembly\NativeImages_v4.0.30319_32\NGenILDasmTest\81d49dd4c7df22fb3df530402b58ffc9\NGenILDasmTest.ni.dll"

我可以看到 Ngen-ed 程序集的内容。这正常吗?。

从技术上讲,Ngen 为 IL 生成 native CPU 指令(显然将它放在 C:\windows\Assembly\NativeImages_V4.#####_32 下 - 在我的情况下)。如果是这种情况,我如何仍然能够使用 ILDasm 将 NGen 编辑的程序集视为 IL?

请帮助我理解我在这里遗漏的“小东西”。

最佳答案

NGEN 的程序集是 IL 加上 native 代码。 IL 没有被剥离。 NGen 程序集仅包含 native 镜像,这常常令人困惑。元数据仍然需要原始信息。

Microsoft 似乎没有关于 NGen 程序集内部结构的非常具体的信息。我们知道的大多数信息都来自逆向工程。

编辑 :

安装 .NET Framework 1.1 (yay..) 之后 - 看起来 .NET 1.1 NGen 确实去掉了 IL。看起来像是从 v2 开始 - IL 被保留。这似乎就是为什么存在相互矛盾的信息。做出这种改变的确切原因似乎并不为人所知。

这里有一篇关于 ngen 内部结构的好文章(以及它如何是一个非常糟糕的混淆想法):http://www.woodmann.com/forum/entry.php?68-Rebuilding-native-.NET-exes-into-managed-.NET-exes-by-Exploiting-lefotver-IL ...

Now, the interesting thing about Ngen is that it does not eliminate the IL or the metadata, because while the IL code is not needed for execution, the metadata is, because all the strings and other relevant data that the program needs are contained within the metadata. So, Ngen copies all the metadata to the .IL section of the native exe, and copies the IL code as an afterthought

关于.net - 我们可以反汇编(使用 ILDasm)一个 NGen 编辑的程序集吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7373169/

相关文章:

c# - 执行 Ngen 后,我在哪里可以找到生成文件的位置?

c# - ILDasm Visual Studio 2010

c# - 如何将 WindowsIdentity 转换为 NetworkCredential?

c# - 有效地使用 XmlDocument.Save()

.net - 分发预 NGEN 编辑的程序集是否有意义?

c# - 从不同机器上的相同 C# 源代码可重复构建

c# - 未优化的 MSIL 中多余的 NOP 和分支

c# - 当我将一个类声明为内部类时,为什么 IL 将其显示为私有(private)类?

c# - 如何使用图形库 C# 在图像上绘制小图像?

.net - 如何确定装配是否已被 ngen'd?