Click here to Skip to main content
11,923,948 members (64,709 online)
Click here to Skip to main content
Add your own
alternative version


92 bookmarked

NetDasm - A tool to disassemble and patch .NET assemblies

, 22 Apr 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Disassemble and patch .NET assemblies using the Mono.Cecil library.

Screenshot - Screen.jpg


This article illustrates a little tool for disassembling a .NET assembly IL code and making some patches.


For my application, I have used Mono.Cecil, a very powerful library for modifying IL code. If you want more info, visit the Cecil homepage.

Another Cecil article I found to be helpful is the one by ronnyek: MonoCecilChapter1.asp.

Using the code

You only need to load an assembly and look at all the types that it contains. When you click on one type, its methods and some information appear in the right. You can delete a type, delete a method, or edit the code of a method. In the Edit Code form, you can watch the IL code, remove a sentence, or insert a new sentence.

The basic code for using Cecil is:

AssemblyDefinition assembly = AssemblyFactory.GetAssembly("assembly.exe");
//Gets all types of the MainModule of the assembly

foreach(TypeDefinition type in assembly.MainModule.Types)
    if(type.Name != "<Module>")
        //Gets all methods of the current type

        foreach(MethodDefinition method in type.Methods)
            //Gets the CilWorker of the method for working with CIL instructions

            CilWorker worker = method.Body.CilWorker;
            //Creates the MSIL instruction for inserting the sentence

                   Instruction insertSentence = worker.Create(OpCodes.Ldstr, "Text");
            //Inserts the insertSentence instruction before the first //instruction

        //Import the modifying type into the AssemblyDefinition

//Save the new assembly

AssemblyFactory.SaveAssembly(assembly, "new.exe");

Points of Interest

I want to improve the program and add some more options like methods insertion, feature to show C# code (like Reflector), and an improved instructions insertion.


  •  22/04/2013 - Created github repository 
  • 2/06/2007 - Update version
    • Code for IL tool added (only C# code)
    • Support for edit instructions
    • Filter for instructions
    • Some minor changes and bugs fixed
  • 1/06/2007 - Update version
    • Instructions documentation and auto-complete
    • Some interface changes
    • Multi-instructions remover
  • 31/05/2007 - First version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Fco. Javier Marin
Spain Spain
I'm a young entrepreneur from Cartagena (Spain). I'm the creator and owner of some popular websites like Chuletas and Wikiteka.

Currently, I'm working on Ideatic, a company for Internet and software develop.

You may also be interested in...

Comments and Discussions

Question!!! Pin
alejandro29A22-Nov-12 3:08
memberalejandro29A22-Nov-12 3:08 
GeneralNew Line / Multiple Lines Pin
tekhead12-Jan-09 22:08
membertekhead12-Jan-09 22:08 
GeneralRe: New Line / Multiple Lines Pin
rongchaua17-Apr-09 10:58
memberrongchaua17-Apr-09 10:58 
GeneralRe: New Line / Multiple Lines Pin
RandolphC27-Sep-11 22:54
memberRandolphC27-Sep-11 22:54 
It does not save any changes made... :(
Questioni cant insert instruction Pin
sujithkumarsl17-Apr-08 19:38
membersujithkumarsl17-Apr-08 19:38 
GeneralGodd stuff Pin
hhir122-Oct-07 0:05
memberhhir122-Oct-07 0:05 
QuestionReplace Method??? Pin
rongchaua15-Jul-07 13:40
memberrongchaua15-Jul-07 13:40 
AnswerRe: Replace Method??? Pin
jonbratz18-Jul-07 22:23
memberjonbratz18-Jul-07 22:23 
GeneralRe: Replace Method??? Pin
jonbratz24-Jul-07 6:31
memberjonbratz24-Jul-07 6:31 
GeneralTry Reflexil Pin
jonbratz2-Jul-07 23:01
memberjonbratz2-Jul-07 23:01 
GeneralRe: Try Reflexil Pin
RandolphC27-Sep-11 22:53
memberRandolphC27-Sep-11 22:53 
Questionmeta-data corruption? Pin
Philox6-Jun-07 3:06
memberPhilox6-Jun-07 3:06 
AnswerRe: meta-data corruption? Pin
Fco. Javier Marin6-Jun-07 3:09
memberFco. Javier Marin6-Jun-07 3:09 
GeneralRe: meta-data corruption? Pin
Philox6-Jun-07 23:43
memberPhilox6-Jun-07 23:43 
GeneralMore Function Please Pin
rongchaua1-Jun-07 8:55
memberrongchaua1-Jun-07 8:55 
GeneralRe: More Function Please Pin
Fco. Javier Marin2-Jun-07 6:33
memberFco. Javier Marin2-Jun-07 6:33 
QuestionPatching signed assemblies ? Pin
Vertyg031-May-07 21:57
memberVertyg031-May-07 21:57 
AnswerRe: Patching signed assemblies ? Pin
Fco. Javier Marin1-Jun-07 0:59
memberFco. Javier Marin1-Jun-07 0:59 
GeneralSecuring my Application Pin
jfdoubell31-May-07 20:50
memberjfdoubell31-May-07 20:50 
GeneralRe: Securing my Application Pin
Fco. Javier Marin1-Jun-07 0:54
memberFco. Javier Marin1-Jun-07 0:54 
GeneralNice work Pin
David Sleeckx31-May-07 12:21
memberDavid Sleeckx31-May-07 12:21 
GeneralRe: Nice work [modified] Pin
Fco. Javier Marin31-May-07 12:24
memberFco. Javier Marin31-May-07 12:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151125.3 | Last Updated 22 Apr 2013
Article Copyright 2007 by Fco. Javier Marin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid