如何在.Net Core exe/assembly上运行ildasm? [英] How to run ildasm on .Net core exe/assembly?

查看:259
本文介绍了如何在.Net Core exe/assembly上运行ildasm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试针对.NetCore3.1控制台应用程序运行作为Visual Studio 2019的一部分安装的ildasm(中间语言反汇编程序).

I'm trying to run ildasm (Intermediate Language Disassembler) installed as part of Visual Studio 2019 against .NetCore3.1 console app.

使用Visual Studio 2019的Developer命令提示符并运行以下命令

Use Developer command prompt of Visual Studio 2019 and run following command

ildasm.exe D:\ DotNet \ IntroductionToCsharp \ IntroductionToCsharp \ bin \ Debug \ netcoreapp3.1 \ IntroductionToCsharp \ bin \ Debug \ netcoreapp3.1 \ IntroductionToCsharp.exe

ildasm.exe D:\DotNet\IntroductionToCsharp\IntroductionToCsharp\bin\Debug\netcoreapp3.1\IntroductionToCsharp\bin\Debug\netcoreapp3.1\IntroductionToCsharp.exe

但是发生以下错误:

'D:\ DotNet \ IntroductionToCsharp \ IntroductionToCsharp \ bin \ Debug \ netcoreapp3.1 \ IntroductionToCsharp.exe'没有有效的CLR标头,因此无法反汇编

'D:\DotNet\IntroductionToCsharp\IntroductionToCsharp\bin\Debug\netcoreapp3.1\ IntroductionToCsharp.exe' has no valid CLR header and cannot be disassembled

注意:在非核心(.Net Framework 4.x)exe上运行相同的命令可以正常工作.也许需要一些特别的东西来查看.Net Core中的IL?

Note: running the same command on non-Core (.Net Framework 4.x) exe works fine. Maybe there is something special needed to look at IL in .Net Core?

推荐答案

正如已经指出的那样,.NET Core中的.exe只不过是一个主机.唯一的目的是加载CoreCLR,然后JIT编译并执行程序集的Main方法.代码本身存储在.dll中.您可以使用自己喜欢的反汇编程序(ILDASM,JetBrains的dotPeek,ILSpy等)进行检查.

As it was pointed out already, the .exe in .NET Core is nothing more than a host. It's sole purpose is to get the CoreCLR loaded then JIT compile and execute your assembly's Main method. The code itself is stored within the .dll. You can check this with your favorite disassembler (ILDASM, JetBrains' dotPeek, ILSpy, etc).

为什么IL反汇编程序可以对.NET Framework中的.exe起作用?因为可执行文件是带有相应托管标头的托管程序集.与.NET Core不同,.NET Framework从Windows操作系统的Image Loader获得了广泛的支持,以进行所有设置,然后在可执行文件中运行托管代码.请参阅讨论的第二点此处.

Why could an IL disassembler work against an .exe in .NET Framework ? Because the executable would be a managed assembly, with a corresponding managed header. Unlike .NET Core, .NET Framework has extensive support from the Windows operating system's Image Loader to get everything set up and then run the managed code within the executable. See the second point discussed here.

这篇关于如何在.Net Core exe/assembly上运行ildasm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆