神刀安全网

Disassembling the .NET code using ILSpy

There have been many occasions where we want to see the code of .NET assembly to check what is happening inside or to reverse engineer the dll or disassembling the assembly. Though we can easily see the IL(Intermediate language) code of any assembly using the ILdasm tool which is provided with the visual studio installation. The location of the ILdasm on computer is C:/Program Files (x86)/Microsoft SDKs/Windows/v10.0A/bin/NETFX 4.6 Tools at my system.

Knowing IL (Intermediate Language)

As we are talking about disassembling and re engineering of the assembly that is why we should know a bit about the IL code  . IL code is the intermediate code which is generated while .NET code is compiled using the Visual Studio or using the command line using the Csharp compiler or VB compiler based on the language we are working on, while run time this IL code is converted to machine readable code or native code using Just In Time (JIT) debugging with the help of CLR and this is the code which is executed on the target machines processor.

Now there can be chance where we have only the assembly or the dll and there is no source code provided. ILSpy can be used to decompile or get the high level language code like C# or VB from the assembly provided which in turn can help us to dig into the working of the code without inspecting the IL code. We can download the ILSpy code and binaries from their website .

Example Using the ILSpy for Disassembling

Here I want to demonstrate how we can use the ILSpy tool to regenerate the C# code. Here I have written a “Hello World” code using the console application.

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

Once we download the binaries for the ILSpy from their website we have to open the ILSpy.exe as shown in the below figure.

Disassembling the .NET code using ILSpy

Once the exe is launched we can see the following UI where we can locate and open(File > Open) the dll which we want to disassemble and change the desired language in which we want to see the code of the assembly from the drop down present in the UI as shown in the following figure.

Disassembling the .NET code using ILSpy

As we know that I have created this particular program in the C# language but while disassembling in the IL, I am able to see in the VB.

Similarly we can see the disassembled code of any assembly which is developed using the .NET framework using the IlSpy. As shown in the above figure ILSpy automatically loads some of the come namespaces of the .NET framework when it is opened for the first time.

This tool can be very useful for checking the code of the assemblies for which we do not have the source code and help us to understand the workings that is why I have discussed about this tool today. I hope this article will be helpful for you to understand about the tool.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Disassembling the .NET code using ILSpy

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮