Programing

C # 컴파일러로 생성 된 MSIL / CIL을 어떻게 볼 수 있습니까?

lottogame 2020. 7. 17. 08:12
반응형

C # 컴파일러로 생성 된 MSIL / CIL을 어떻게 볼 수 있습니까? 왜 조립이라고 불리는가?


.NET C # 프로그래밍을 처음 사용합니다. 몇 권의 책을 따르고 있습니다. 이진 코드 (네이티브 코드)로 직접 컴파일하는 것이 아니라고합니다. 고급 코드는 중간 언어 (MSIL, 일명 CIL)로 변환됩니다. 그러나 컴파일 할 때 exe / Dll 파일을 얻습니다.

  1. 이 MSIL / CIL이이 exe / dll 파일에 포함되어 있습니까?
  2. 그 중간 언어 코드를보고 싶습니다. 그것의 존재를 느끼기 위해. 그것을 보는 방법?
  3. 그들은이 exe / dll 파일을이라고 부릅니다 assembly. 그들은이 "공상 단어"를 사용하여 이진 코드 (네이티브 코드)를 포함하는 exe / dll 파일과 구별 할 수 있습니까?

  1. .text, PE 파일섹션에 있습니다 (휴대용 실행 가능 = * .exe 또는 * .dll). 자세한 내용은 여기를 참조하십시오 .
  2. 최선의 선택은 ILSpy 를 사용하는 것입니다 (반사기는 더 이상 무료가 아닙니다). 어셈블리를 MSIL과 C #, VB로 어느 정도 분해 할 수있는 무료 디스어셈블러입니다. .NET Framework SDK에는 공식 MSIL dissasembler 인 ILDasm이 포함되어 있습니다.
  3. 기본적으로 그렇습니다. 어셈블리는 MSIL 코드와 해당 메타 데이터가 포함 된 파일입니다. 이것은 PE 파일 자체에만 국한되지 않지만 모든 현재 CLR 구현에서 사용됩니다.

그 문제에 대해서도 좋은 책을 추천한다면 Serge Lidin의 Expert .NET 2.0 IL 어셈블러입니다. 그는 MSIL을 디자인 한 사람입니다.


C # 스 니펫대해 IL을 보는 가장 좋아하는 방법 중 하나는 무료 LINQPad 도구 를 사용하는 것 입니다. 코드를 입력하고 상단의 "C # 문"(또는 "C # 프로그램"중 적합한 것)을 선택한 후 코드 입력 영역 아래에서 "IL"버튼을 클릭하면 생성 된 IL이 표시됩니다.

이를 위해 LINQPad를 사용하는 것은 Visual Studio를로드하거나 명령 줄에서 컴파일러를 실행 한 다음 ILDASM을로드하고 텍스트 편집기로 .il 파일을 여는 것보다 훨씬 편리합니다.


온라인으로 원한다면 .NET Fiddle 이 훌륭합니다. 코드를 붙여넣고 View IL오른쪽 상단의 옵션을 클릭하십시오 .


  1. 예, 조립 중입니다.
  2. .NET Reflector 또는 ILDasm 이 필요합니다 .
  3. 조립 점검에 대한 자세한 내용은 여기를 클릭하십시오 .

추신 당신이 어떤 책을 따르고 있으므로 C #을 통한 CLR을 강력히 추천합니다 .


다른 옵션 : ReSharper 사용

여기에 이미지 설명을 입력하십시오 소스 / IL 동기화보기 : 왼쪽 파란색 배경 라인이 오른쪽 IL 블록에 해당

Visual Studio에서 :

  • ReSharper를 선택하십시오 | 윈도우 | IL 뷰어
  • 또는 상황에 맞는 메뉴 : 탐색 | IL 코드

소스 코드와 IL의 동기화 된 뷰를 지원합니다. 소스에서 명령문을 클릭하면 IL의 해당 블록이 강조 표시됩니다 (반대도 마찬가지). Microsoft Developer Network의 IL 및 ECMA 표준 사양의 "CIL (Common Intermediate Language) 명령어 세트"에 대한 설명을 표시합니다.

Resharper 도움말의 IL (Intermediate Language)보기를 참조하십시오 . 위의 그림은 Resharper 도움말에서 가져온 것입니다.

무료 옵션은 Jetbrains dotPeek 를 사용하는 것입니다

또한보십시오 : "ReSharper와 dotPeek를 이용한 중급 언어 (IL) 탐구", Maarten Balliauw, 2017 년 1 월 19 일-Jetbrains Blog


나는 어셈블리 모듈의 집합이기 때문에 그들이 "어셈블리"라고 믿고 조립 매니페스트에 의해 함께가.

다중 파일 어셈블리
(출처 : microsoft.com )

자세한 내용조립 내용 을 참조하십시오.


여러 측면에서 .NET 어셈블리는 Java 바이트 코드 패키지와 유사합니다.

  1. 예. 또한 매니페스트 및 기타 데이터가 포함되어 있지만 CIL은 exe / dll의 일부입니다.
  2. Use ILDasm or Reflector - most people would say Reflector, as it is much more powerful. Both will show you what CIL was produced. Wikipedia has a list of all CIL instructions, for a better feel (it is assembly like).
  3. I guess it is meant as an assembly of code. A good way to differentiate it from native.

I have just spent a couple of hours searching for the best tool that could let me view the IL code directly inside Visual Studio.

The only solution I found so far is Msiler https://visualstudiogallery.msdn.microsoft.com/60fc53d4-e414-461b-a27c-3d5d2a53f637

it works quite well!

Otherwise the second best solution, but without visual studio integration, is JetBrains dotPeek, which is quite awesome to be honest.


I know this is an old question, and I'd prefer any of the tools above. However, in a pinch, there has been an MSIL viewer in the box with Visual Studio since at least Version 2005.

The tool is named ildasm.exe, and is located in the following folders after default Visual Studio installations:

Visual Studio 2005 "C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\ildasm.exe"

Visual Studio 2008 "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\ildasm.exe"

Visual Studio 2010 "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\ildasm.exe"

For more information, see: "How to: View Assembly Contents" in the MSDN Library.


From my experience the best source of IL-related knowledge is Andrew Troelsen “Pro C# and .NET Platform”. Starting from 3rd edition he has really, really outstanding chapter (approx 50 pages) on how to understand IL and even write your own code and use ILAsm. I’ve employed that information to investigate whether multiple inheritance exists in .NET world. Also you could try to employ some very interesting features in IL (e.g. filtering of exceptions which only exists in VB but not in C#).

I highly recommend to read that chapter.

Eventually, .NET Reflector is an enterprise standard for investigating IL code of assemblies and Richter's book is definitely "must read" stuff. But from other books like mentioned above you could reveal really useful things :)

Yes, each assembly in .NET world holds some IL code (alongsite with manifest) which could be viewed thru Reflector or ILDasm. Even more, Reflector could show you C# and VB optimized code. This means that any person could view the source code of an assembly and that's why in commercial products obfuscators are used.


I you want to view the intermediate language, Try downloading JustDecompile from Telerik (Which is currently free, requires a sign up though).

Drag in your DLL and choose IL from the drop down box at the top!


샤프 랩 sharplab is an online tool, great for simple use cases. Type your code on the left, IL shows up on the right.


이제 다른 옵션이 있습니다. 당신은이 작업을 수행 할 수 있습니다 VS 코드 와 함께 이 확장 로슬린로 만들었습니다. 이것은 현재 .NET Core로 제한됩니다 .

참고 : https://stackoverflow.com/questions/3326571/how-can-i-view-msil-cil-generated-by-c-sharp-compiler-why-is-it-called-assemb

반응형