Preventing ildasm from disassembling your assembly

Preventing ildasm from disassembling your assembly

  • Comments 7

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
Leave a Comment
  • Please add 8 and 7 and type the answer here:
  • Post
  • 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.

  • Very misleading attribute

  • Hmm, I've had troubles using reflector to view such assemblies as well as ILDASM.  Maybe its the newer version from Red Gate...  Any other tricks I could try?  fschwiet (at) gmail

  • 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.

  • Open the .dll/.exe in hexeditor... find for "SuppressIldasmAttribute." and replace it by spaces "20"

  • 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

  • *NO* dotnet assembly is safe :)

Page 1 of 1 (7 items)