The Open Source. Net decompilation tool. Net il debugging tool is recommended to learn the excellent tool DOTNET il editor of Microsoft intermediate language (msil ).

Source: Internet
Author: User
ArticleDirectory
    • Exploring the mysteries of. Net code
    • Debug il code
    • Learning the Il Instruction Set
    • Command Line call

DOTNET il editor is a. NET platform decompilation tool that can decompile. net.ProgramSet file to IlCodeAnd can be executed. debug the Il code generated after decompilation. Its design starting point is intuitive. You can create a project, add an assembly file, set a breakpoint (F9), and then debug the decompiled Assembly file, step into, step out, based on this principle, you can find the bottleneck code of the system, or learn the msil Microsoft intermediate language in depth.

Create a C # console project, design a method for adding numbers, and call it in the main method.

The program has less than 10 lines in total. It adds numbers 1 and 2 and outputs them to the console.

  Public   class  testeditor { Public   static   int  sum ( int ,  int  B) { return  A + B ;}  Public   static   void  main ( string  [] ARGs) {console. writeline (sum (1, 2); console. readline () ;}

Execute the program dile.exe to create a project. Right-click the project browser to add an assembly and expand the Assembly layer by layer, as shown in

Similar to Visual Studio's solution browser, it expands by namespace and lists the methods in the Assembly. Double-click the method to open il in the editor.Source codeThe IL editor window is read-only.

 

Exploring the mysteries of. Net code

Remember. net textbook has a principle knowledge, the type is inherited from the object class by default, when the type definition constructor is not ,. net compiler will generate a default constructor for it, which does not contain parameters. If you are blocking the default constructor, you only need to define a method for the type to block this behavior of the compiler.

Why don't you try to see if this principle is missing or what is missing. Then, modify the type definition method and add a constructor with parameters to it. This method is an empty method, and the parameter is used to determine whether it is generated by. Net or manually added. The source code is like this.

 
 Public ClassTesteditor {PublicTesteditor (StringStr ){}Public Static IntSum (IntA,IntB ){ReturnA + B ;}Public Static VoidMain (String[] ARGs) {console. writeline (sum (1, 2); console. Readline ();}}

The testeditor type now has a custom constructor with a string parameter. Open it again in the Il editor and check the Il code it generates.

Indeed, there is no default constructor in the generated il code. Instead, we define the constructor.

 

Then, let's verify a knowledge point. A const constant will be compiled into a program set in the form of a constant, so it is very efficient. Modify the C # source code, compile it, and open it in the Il editor. The C # source code now looks like this.

Public   Class Testeditor { Public    Const   String Productname = "Enterprise Solution" ; Public Testeditor ( String Str ){} Public   Static   Int Sum ( Int A, Int B ){ Return A + B ;} Public  Static   Void Main ( String [] ARGs ){ String Productionname = productname; console. writeline (productionname); console. writeline (sum (1, 2); console. Readline ();}}

Let's take a look at the generated il code. The result is as follows:

The Decompilation result is the same as the knowledge point we have seen before, and it verifies that what we have learned is correct.

In the source code, in the console's main method, it calls the method of 1 + 2 summation, and also compiles it into the assembly in the form of constants.

 
Console. writeline (sum (1, 2 ));

The corresponding. Net il code is

 
LDC. i4.1 LDC. i4.2 call int32 ileditorlibrary. testeditor: sum (int32, int32) CallVoid[Mscorlib] system. Console: writeline (int32)

Il is a stack-based language. It first presses the value 1, then the value 2, then sums the two, and finally displays the call method on the console.

 

Debug il code

The debugging function of IL editor is one of its highlights. You can directly set a breakpoint (F9, toogle breakpoint) in the opened il code, and then click Run in the toolbar to start debugging. The main points of the program debugging are Stack stack, variable value watch, and IL editor.

Il Stack window

The IL parameter window displays the input parameters of the currently called method.

Il Watch window

Expressions support custom expressions. This function is similar to the real-time window in vs. The input table quantity or expression outputs the result on the right side.

The author of IL editor lists some tested and demonstrated Expression Code. They are

5 *-61 + 2*3-10/5*5 (1 + 2*3-10/5*5). tostring () (-5). tostring () New   Object () + ""  "ABC" . Length. tostring () system. type. GetType ( "System. String" ). Guid. tobytearray () testapplication. debugtest. createoperatortest4 ( "OP1" ) |True Testapplication. debugtest. paramstest2 () testapplication. debugtest. paramstest2 (5, 6) system. String. Format ( "{0} {1} {2} {3} {4 }" , "" , "B" , "C" , "D" , "E" ) New   Object [] {4, "" , 5} (system. Exception) {exception}). messagetestapplication. genericclass < Int , System. datetime>. staticmethod < String > ( "Test" )New Testapplication. testclass < Int , String > [] { New Testapplication. testclass < Int , String > (1, "One" )} Testapplication. genericclass < Int , String >. Nestedgenericclass <system. type>. staticmixedmethod <system. datetime> (system. datetime. Now, 5, Null )

Yes, you can enter it directly in the window. Il evaluates the expression and the returned result is displayed on the right.

 

Finally, the execution result is displayed.

The output value is displayed on the control, which is identical to the experience of debugging C # source code in.

 

Learning the Il Instruction Set

The author of IL editor must think that the Il language is not easy to remember and be familiar with. When you move the mouse in Il Editor, The IL code displayed in the current line of the mouse varies, In the Il instructions window, the method comments are displayed in time and the msdn address is displayed. You can click to enter the document of this il method.

The design is very considerate.

Click here to go to The msdn web page.

Http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.Nop.aspx

For the language we are used to, we have not seen any relevant settings, which can be used to set the jump to the Chinese version of msdn.


 

Command Line call

Il Editor supports command line calling. The command line parameter list is as follows:

Dile [/P "project name"] [/a "assembly path"] [/L "project name. dileproj"]

/P optional. When dile is loaded, a new project will be created with the given name.

/A optional, can be repeated. When dile is loaded, a new project will be created and the given assemblies will be added to it.

/L optional. dile will load the given dileproj file. if this parameter is given then/P and/A will be ignored. if a parameter is followed by a name/path which contains spaces then it shoshould be written between quotes

Create a project for the test project

Dile/P "Test Project"

 

Create a project named test project and add an assembly to it.

Dile/P "test project"/A testassembly.exe

 

Create a new project and load the Assembly from two different places

Dile/A testassembly.exe/a "C: \ assemblies \ my test. dll"

 

Load an existing project

Dile/L testproject. dileproj

 

Finally, add the project home address

Project home: http://dile.sourceforge.net/

Author blog: http://pzsolt.blogspot.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.