NET Framework built-in classes such as ILProcessor is sufficient to produce the IL code as in the following: It is, however, nearly the same process as in the earlier section implementation but this time we don't need to rely on or call on the AstBuilder class method in order to disassemble the code. In this segment, we convert the produced MSIL code from the selected method of the current assembly module. The previous demonstration of C# source code was pretty exhaustive rather than IL code producing. ast_Builder.GenerateCode( new PlainTextOutput(output)).StringWriter output = new StringWriter().foreach (var method in typeInAssembly.Methods).ast_Builder = new AstBuilder( new (assembly.MainModule) ).MethodDefinition method_definition = (MethodDefinition)enumerator2.Current.IEnumerator enumerator2 = td.Methods.GetEnumerator().TypeDefinition td = (TypeDefinition)enumerator.Current.var assembly = AssemblyDefinition.ReadAssembly(txtURL.Text).Hence, the very first line of code in the populateCsharpCode(), reading an assembly from the text box control into a dynamic type variable and later by using this variable, we are enumerating the main modules residing in the assembly using a loop while loop construct as in the following: We are, in fact, implementing the same functionality and features in our software. We would have seen the process of generating the original source code earlier in erstwhile popular disassembles, for instance ILSpy, ILPeek and Reflector. In this section we shall express the process of yielding C# source code from a selected method in the Treeview control. We have put two methods inside the tvMemebers_AfterSelect() as populateCsharpCode() that expressions the C# source code and the other one displays the MSIL code. MessageBox.Show( "Expand the Namespace" ).private void tvMembers_AfterSelect( object sender, TreeViewEventArgs e).Hence, we will create an AfterSelect event for the Treeview control and place the following code into it: The equivalent original source code (C# and MSIL) will appear in the Rich Text Box located in the Tab control. Here, we shall utilize the treeview control that streamlines our job in terms of when we select a specific method or the contents of the assembly. As per the proposed functionality of this paper, we need to show the corresponding source code of an assembly in the form of C# of IL language. NET built assembly, the Treeview control is activated and shall produce the entire contents of the assembly in terms of modules and methods. Although this software implements numerous forms controls, but depending on the requirement of these papers, we are elaborating on these necessary controls only that will be used in the code.
Before moving forward, it is necessary to come across with the controls that are being placed in the user interface design of this software because we shall need to direct a specific form control to respond to an event, for instance a Tree View control that displays an entire member's modules of the assembly, will display the corresponding MSIL or C# source during selection of any methods. In fact, our main goal is to implement the disassembling features. Though it doesn't matter how we design this software. NET clients for security purposes can also facilitate ensuring that the software does the expected tasks without hidden features such as spyware or adware. Disassembling can assist in the audit of the implementation of security sensitive features such as authentication, authorization and encryption. There are typically multiple reasons to disassemble code, ranging from interoperability purposes to recover lost source code or finding security vulnerabilities. As we know, code from these high-level languages are compiled into a common Intermediate Language (IL) that runs in the Common Language Runtime (CLR). Components written for example in VB.NET or C++, can easily be reprocessed in code written in another language, for instance C#. NET CLR provisions several programming languages such as C#, VisualBasic.NET, F# and managed C++. Now, we shall continue our voyage by explaining the process of obtaining the disassembled code in C# and the MSIL language. As we have stated earlier, the process involves making the custom disassembly using several layers of a development cycle and we have already covered the user interface design, the obtaining of the assembly origin information and the decompiling of assembly members in the previous article. The previous paper showcased the essential configuration in terms of importing the external DLLs into the solution and NuGet package installation. Before reading this article you must read: