VISUAL BASIC 10
Tools and Utilities in the .NET Framework
VISUAL BASIC 10
November 07, 2019
In this article I will explain about the tools and utilities in the .NET Framework.
The .NET Framework Software Development Kit (SDK) installs a host of tools and utilities to help you program more efficiently. The SDK includes wrapper creation tools for interoperating with existing unmanaged code, tools that help you discover and use Web services that are based on Simple Object Access Protocol (SOAP), and tools that enable you to configure security for managed code. This section provides an overview of the Intermediate Language Disassembler (ILDASM) and other debugging tools provided with the .NET Framework.
Using ILDASM to Disassemble and Display .NET Metadata
All the languages on the .NET platform compile into MSIL and are subsequently compiled into native code at runtime by the JIT compiler. The Intermediate Language (IL) includes a very powerful feature for accessing its internal metadata called reflection. The Reflection API provided by the .NET runtime enables a programmer to discover and invoke public types of an assembly at runtime. The ILDASM tool can be used to view the metadata contained within a .NET file and to disassemble a .NET assembly or module into IL code.
Viewing the Contents of a .NET Portable Executable File
To start ILDASM, choose Run from the Start menu and type ILDASM. Once you've started the ILDASM tool, choose Open from the File menu. Navigate to the "Hello, VB" programs created earlier and select it. You should see a window similar to the one shown in Figure 4.1.
Figure 4.1: ILDASM Tool
The figure shows a couple of symbols along with some names. Table 4.1 lists all the symbols and their meanings. Once you have reviewed at them, you will understand some of the contents shown in Figure 4.1.
Table 4.1: ILDASM Symbols
To view the manifest of the assembly, double-click on the Manifest item in ILDASM. The resulting display is reproduced in Figure 4.2.
Figure 4.2: Hello, VB Class's Manifest
The manifest of a portable executable (PE) file provides some important information about the files dependencies, version, and culture. This metadata within the manifest makes every .NET PE file self-describing.
The first section of the manifest begins with .assembly extern mscorlib, indicating that the Hello class uses classes (e.g., System.Console) that are stored in the mscorlib assembly. The publickeytoken (a public key only available in cases of strong-named assemblies) and version of the mscorlib assembly are also embedded in this section of the manifest. Having this version information stored in the manifest solves some of the versioning problems otherwise encountered when different version of the same assembly is present. The .NET runtime can easily check the assembly manifest for version information and then load the correct version of the assembly.
The next section, which contains .assembly Hello, is the assembly manifest of the assembly Hello. This section is only present in assemblies, that is, modules do not have this section. The assembly manifest contains the culture, version, hash algorithm for encryption, publickeytoken, and other important metadata about the assembly. Since in this case we have not specified any special version or culture settings on the assembly, the default version of 0:0:0:0 is applied.
The section containing .module Hello.exe states that the assembly is stored within the PE file called Hello.exe. The remaining sections contain other relevant metadata used by the .NET runtime.
To explore the various contents of the assembly, click on Hello to expand and view its internal members. Figure 4.3 shows the contents of the Hello assembly.
Figure 4.3: Contents of the Assembly
From the figure we can make out that the assembly contains a single class called Hello. Double click the line that starts with .class private auto to find the definition of the Hello class, as presented in Figure 4.4. 38
Figure 4.4: Hello Class Definition
The figure shows that Hello is a private class that extends the System.Object class from the mscorlib assembly. You might remember that all classes in the .NET Framework extend the System.Object class directly or indirectly. Hence, even though the class is not explicitly extended in the source code, the VB compiler automatically extends the class from System.Object.
The next line in Figure 4.3 contains .ctor: void(), the default constructor for the class. The VB compiler automatically adds this line too, if you do not define a constructor for the class. The default constructor is always public and takes no parameters. Figure 4.5 shows the definition of the default constructor for the Hello class.
Figure 4.5: Default Constructor
The first section regarding code size indicates that the constructor occupies 7 bytes of MSIL. The .maxstack 1 section indicates that only one operand at a time can be pushed onto the virtual stack for computation. Next, the directive ldarg.0 loads the class's this pointer on the virtual stack. On line IL_0001, the System.Object class constructor (or base class constructor) is called. Finally, on line IL_0006, the method returns from the constructor.
Lastly, to examine the Main method of the class Hello, double-click the Main:: void() line from the screen shown in Figure 4.3. Perhaps you have already noticed the symbol to the left of this line that signifies the method is static.
Figure 4.6 shows the contents of the Main method.
Figure 4.6: Definition of the Main Method
You can see from the top line of the figure that Main is a private, static method that returns a void. The .entrypoint section tells the .NET runtime that this method is the entry point for the assembly and that the .NET runtime should begin executing code starting with this method. The // Code size section indicates that this method occupies 11 MSIL bytes, and the .maxstack section indicates that at a given time, a maximum of 1 byte can be loaded on the virtual stack. The line IL_0000 loads the string "Hello, C#!" on the virtual stack. (Because static methods don't have a this pointer, the variables get loaded on the stack first; otherwise, the this pointer is loaded first.) On line IL_0005, the WriteLine(string) method of the class System.Console from the mscorlib assembly is called and the string is displayed on the console. Finally, on line IL_000a, the method returns. Thus ends your brief tour of the Hello class.
Emitting IL from a .NET PE File
The ILDASM tool can also be used to emit the IL code from a .NET PE file. To decompile a file, load the file into ILDASM as indicated above and select Dump from the File menu. You are presented with a dialog box similar to that in Figure 4.7. From this dialog box, select the options you require (the default options are sufficient in most cases) and click OK.
Figure 4.7: Dump File Dialog Box
Next, you are presented with the File Save dialog box. Type an appropriate file name and click OK to save the IL code for your PE file. Two files get created when you click OK: the IL file (Hello.il) and a resource file containing resources for your assembly (Hello.res).
Now open the Hello.il file in notepad to view its contents. Within the Main method definition in this file, find the following line:
IL_0000: ldstr "Hello, VB!"
Change it to read as follows and save the file:
IL_0000: ldstr "Hello World"
Now bring up the command prompt window and navigate to the directory where you saved the Hello.il file. Run the ILASM tool (IL Assembler) to compile the IL file into a .NET PE file that contains the change you have made. Before you run the ILASM tool, be sure you have closed the ILDASM tool running on the Hello.exe file; otherwise, Hello.exe remains locked and the new file won't be generated. Issue the command ilasm hello.il to compile the IL code into a PE file. Finally, run the file Hello.exe to view the reflected changes you made in the IL (shown in Figure 4.8.).
Figure 4.8: Assembling Using ILASM Tool
Hope this article would have helped you in understanding tools and utilities in the .NET Framework. See my other articles on the website on .NET and VB.
Framework Security Tools in VB.NET
Utility Controls - Mobile Internet using VB.NET
How to use CASPOL Tool using VB.NET
SN Tool in VB.NET
Silverlight Tool Tips in VB.NET
ToolStrip Control in VB.NET
Tooltip Control in VB.NET
A glance at .NET Framework 3.0 in VB.NET
Create GDI+ Application in VB.NET
Shortcut Keys in Visual Basic .NET
ACTIVE DIRECTOTRY IN VB.NET
ALGORITHMS AND VB.NET
ARRAY IN VB.NET
ASP.NET AJAX IN VB.NET
ASP.NET USING VB.NET
ASSEMBLIES IN VB.NET
COM INTEROP IN VB.NET
CRYPTOGRAPHY IN VB.NET
CRYSTAL REPORTS IN VB.NET
DATABASE & DBA
DEPLOYMENT IN VB.NET
DESIGN & ARCHITECTURE
DIRECTX WITH VB.NET
FILE IN VB.NET
GAMES IN VB.NET
GDI+ IN VB.NET
LINQ WITH VB.NET
MOBILE DEV IN VB.NET
MULTITHREADING IN VB.NET
NETWORKIN WITH VB.NET
OFFICE AND VB.NET
PRINTING IN VB.NET
REMOTING IN VB.NET
REPORTS IN VB.NET
SECURITY IN VB.NET
SILVERLIGHT USING VB.NET
Speech in VB.NET
STRING IN VB.NET
VB.NET EXCEPTION HANDLING
VB.NET HOW DO I
VB.NET WINDOWS SERVICES
VISUAL BASIC 10
VISUAL BASIC LANGUAGE
WCF WITH VB.NET
WEB CONTROL IN VB.NET
WEB DEV IN VB.NET
WEB FORM WITH VB.NET
WEB SERVICES IN VB.NET
WINDOWS FORMS IN VB.NET
WORKFLOW IN VB.NET
WPF IN VB.NET
XAML IN VB.NET
XML IN VB.NET
Setup for a Windows Forms application using Visual Studio 2010 in VB.NET
How to Check Installed .NET Versions on Hosting Server in VB.NET
TabControl in a Windows Forms application in Visual Studio 2010 in VB.NET
Xml database in Windows Forms application using Visual Studio 2010 in VB.NET
Date and Time in Window Application in VB.NET
ListBox Behavior in VB.NET
Use of ThreeState property with CheckBox in VB.NET
Difference Between Interface And Abstract Class in VB.NET
Type Conversion in Calculation in VB.NET
String class in VB.NET- String.Compare method
Enumertors in VB.NET
How to use IDisposable interface in VB.NET
How to use IDisposable interface in VB.NET
Structure in VB.NET
ICloneable interface in VB.NET
Overriding in VB.NET
Use Indexer in VB.NET
How to change the Console display in VB.NET
Reflection in VB.NET
Method Parameter Types in VB.NET
How to Sort and Reverse of Array in VB.NET
Pass by Value and Pass by Reference in VB.NET
Use of IndexOf-Array in VB.NET
Authentication and Code Groups in VB.NET
Collections in VB.NET
Use of LowerBound and UpperBound with Array in VB.NET
Interface in VB.NET
Use of CreateInstance method to construct an array in VB.NET
HelpProvider control in VB.NET
How to Clone an Array in VB.NET
Registry.GetValue in VB.NET
Use the Err.Number in VB.NET
How to use Activator in VB.NET
Use of RegistryKeys in VB.NET
Use ControlChars.Lf in VB.NET
Visual Studio 2010 ErrorProvider control in VB.NET
Use of Registry.SetValue in VB.NET
Visual Studio 2010 CheckBox control in VB.NET
Use of Registry.CurrentUser in VB.NET
Ajax application with jscript file in VB.NET
Data Encryption in VB.NET using DES
Visual Studio 2010 ComboBox control in VB.NET
Working with AJAX Control in ASP.NET using VB.NET
Visual Studio 2010 Progress Bar control in VB.NET
Hashtable in VB.NET
Visual Studio 2010 Tooltip control in VB.NET
Use of IsNothing() function in VB.NET
Visual Studio 2010 Rich Textbox control in VB.NET
Use of IsDate() function in VB.NET
© 2020 DotNetHeaven. All rights reserved.
TERMS & CONDITIONS