Share via


Preventing ildasm from disassembling your assembly

The MSIL Disassembler (ildasm.exe) is a neat tool that can be used to view the MSIL code of a .Net assembly/dll. Many of you should have used it to peek into assemblies while debugging/troubleshooting.

assembly

I use it a lot to check assembly namespaces and stuff while debugging. But when I tried to disassemble one particular module I received the following error "Protected module -- cannot disassemble"

ildasm

After a little digging around I found that with .NET 2.0 a new attribute has been introduced that can prevent the MSIL Disassembler from disassembling your module. The SuppressIldasmAttribute available in the System.Runtime.CompilerServices namespace can be used to specify that a module should not be disassembled. And here is how you code it. I am just specifying the SuppressIldasmAttribute for my namespace.

 

Code

If you compile the above code and try to open the assembly using ildasm.exe you will receive the error message "Protected module -- cannot disassemble"

Remember that the attribute only prevents the ildasm.exe from disassembling the module you can still use Reflector to view the decompiled code. Here is the Reflector view of assembly that has used the SupressIldasmAttribute.

reflector

Bookmark and Share

Comments

  • Anonymous
    December 05, 2007
    This is probably one of the most dangerous attributes ever concieved. I have ben contracted by multiple clients who thought their intectual property was SECURE because of this attribute (some even INSISTED it was) Their shock when I was alble to quickly produce their code from the assemblies was significant.

  • Anonymous
    December 05, 2007
    Very misleading attribute

  • Anonymous
    March 05, 2009
    The comment has been removed

  • Anonymous
    March 22, 2009
    Hello Vijay, Nice one. Did you find anything else on the topic that can probably prevent .Net Reflector from disassembling? I will post a message if I find anything on it.

  • Anonymous
    September 09, 2009
    Open the .dll/.exe in hexeditor... find for "SuppressIldasmAttribute." and replace it by spaces "20"

  • Anonymous
    October 11, 2009
    The bets way to address IL theft is to obfuscate your library using obfuscation tools before you make your libraries public. Check following links for more details http://www.preemptive.com/dotfuscator.html http://msdn.microsoft.com/en-us/library/ms227276(VS.80).aspx

  • Anonymous
    May 07, 2010
    NO dotnet assembly is safe :)