
Dissassembling an Assembly using Ildasm.exe
• The ildasm.exe utility ships with the .NET Framework SDK. Using this tool you are able to:
• View the internal CIL, manifest and metadata for a given assembly.
• Dump the assembly contents to a CIL source code file (*.il).
• Most .NET programmers leverage the GUI front end to ildasm.exe; however the tool can also be driven
entirely from the command line.
• Use the -? flag to see the list of all possible options.
• Assume you wish to disassembly the MySingleFileAsm.dll assembly created earlier in this chapter.
• First, navigate to the \bin\Debug subdirectory of your project.
• The /out flag dumps the CIL code to a specified *.il file.
• The same operation can be performed form the GUI front end to ildasm.exe using the File | Dump menu
option.
ildasm MySingleFileAsm.dll /out=MySingleFileAsm.il
• In either case, the MySingleFileAsm.il file can be edited using any text editor as you see fit:
• Note we just changed the magic value from ‘9’ to ‘FooBar’…security breech!
Compiling CIL Code using Ilasm.exe
• *.il files can be compiled into .NET assemblies using the CIL assembler, ilasm.exe:
• Supply the -? flag to see all command line options.
• To recompile the modified *.il file back into a executable assembly is quite simple:
• The /dll flag generates *.dll assembly.
• The /exe flag generates an *.exe assembly.
• The /output flag denotes the name of the output assembly.
ilasm /dll /output=MySingleFileAsm.dll MySingleFileAsm.il
• If you were to now open this modified version of MySingleFileAsm.dll using ildasm.exe, you would
find the new (incorrect) implementation of GetSensitiveInformation().
• Obviously, round trip engineering can be a major security problem.
Disassembling and Compiling
Table of Contents
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an
online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials