Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C # Intermediate language and ILDASM tools

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail how to use the C# intermediate language and ILDASM tools, with detailed content, clear steps and proper handling of the details. I hope that this article "how to use the C# intermediate language and ILDASM tools" can help you solve your doubts.

What happens when we compile a .NET application?

When we compile any .NET application, it will generate an assembly that can be. DLL or. Exe .

For example, if you compile a window or console application, you get .exe, while if you compile a Web or class library project, you get .DLL.

Whether it is .DLL or .exe, an assembly consists of two things (manifest language and intermediate language).

Understand the intermediate language in C #

To understand the intermediate language in C #, let's create a simple console application. As shown below.

Now, build the application. After the application is generated, the above source code is compiled, an intermediate language is generated, and packaged into an assembly.

To view the assembly, simply right-click Project and select the Open folder in File Explorer option, then go to the bin = > debug folder, and you should see the assembly with the .exe extension, as shown below, because it is a console application.

How do I view the intermediate language code in C#?

The .NET Framework provides a beautiful tool called ILDASM (Intermediate language dismemberment) to view the code of an intermediate language. To use the ILDASM tool, you need to follow these steps.

Open the visual studio command prompt in administrator mode, as shown below.

After opening the Visual Studio command prompt, type the "Ildasm.exe C:\ your directory path\ your assembly .exe" command and press enter.

Here, you need to provide the exe path to generate the exe. My exe is generated in the path "C:\ Users\ zhouh\ source\ repos\ ILDASDemo\ ILDASDemo\ bin\ Debug\ ILDASDemo.exe", so I execute the following code at the command prompt:

After you enter the above command and press Enter, the following ILDASM window opens.

As you can see, an assembly consists of two things (a manifest language and an intermediate language). Let's first discuss intermediate language code, and then discuss what a listing is.

Now, let's extend ILDASDemo and compare it with the code. For a better understanding, please look at the picture below.

There is a constructor in ILDASM because by default, A. NET Framework provides a default constructor when there is no constructor in the class.

Now, click the main method in the ILDASM window to view the intermediate language generated for the Main method, as shown below.

What is a list?

The manifest contains metadata about the assembly, such as the name, version number, culture, and strong name information of the assembly, as shown in the following figure.

The metadata also contains information about referenced assemblies. Each reference includes the name of the dependent assembly, assembly metadata (version, culture, operating system, and so on), and the public key if the assembly is a strong name.

How do I change assembly information?

You can also use properties to change or modify some information in the assembly manifest. For example, if you want to change the version number, you need to perform the following steps.

Open the class file displayed under the AssemblyInfo.cs Properties folder, as shown below. Each project in .NET has a properties folder.

How do I export intermediate language code to a text file?

Select the file menu option from the ILDASM tool, then select dump, and you will see the dump options window, and then click the OK button on the dump options window, as shown below.

After clicking OK, you will be asked to specify a save path and fill in the name you need to save, and finally save the file at the end of the il file. When using notepad to open, you should see the assembly metadata and IL code.

How do I regenerate an assembly from a text file that contains a manifest and IL?

If you want to rebuild the assembly from IL code, you need to use a tool called ILASM.exe, as shown below, enter the address of the ILASM.exe space + il file

After pressing the Enter key, the intermediate language assembler will rebuild our il code into an assembly and generate the exe file in the specified path. As follows:

Therefore, we use ILASM.exe (an intermediate language assembler) to rebuild the assembly from a text file that contains the manifest and IL.

After reading this, the article "how to use C# Intermediate language and ILDASM tools" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 215

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report