Click here to Skip to main content
16,022,352 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
We generally use ILDASM to disassemble the assembly using which we can view Assembly code of IL. Per my understanding, I see a risk in it (ofcourse it may not be since MS.NET allows us to do so). But my uncleared question is why should we disassemble an assembly make changes in IL code and reconstruct it?

Any practical scenario should definetly help me.

Thanks in advance to all tech gurus.
Posted

The good : adding metric producing code like logging etc. to method calls (aspect-oriented programing) so you don't have to change your original source code and make it unmanageable.

The bad
: generally for reverse engineering and changing the behavior of code that you don't have the source for.

The ugly : removing licensing/copyright protection
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 11-Feb-14 12:15pm    
Crystal clear classification, a 5. :-)
—SA
Mehdi Gholam 11-Feb-14 12:19pm    
Cheers Sergey!
Sergey Alexandrovich Kryukov 11-Feb-14 12:27pm    
Nevertheless, I managed to remember a couple of very different (and very interesting advanced) technique using disassembly; please see Solution 2...
—SA
Matt T Heffron 11-Feb-14 12:51pm    
+5 (If I could, I'd give an additional +1 for the movie reference ;) )
Mehdi Gholam 11-Feb-14 12:57pm    
Cheers Matt! :)
There can be some other reasons, except those listed in the excellent answer by Mehdi.

Some cases from my practice:

  • In some really advanced programming, you need to use IL or, in more practical cases, System.Reflection.Emit, to emit code on the fly, which is the key to some technologies, such as serialization, and, say, automatic generation of UI based on data or interfaces. Such work is pretty difficult and needs good knowledge of IL. Here is what I do: I create short code samples in C#, disassemble them and see how the compiler generates the IL code, to learn it and write correct Emit code.
  • In some works published on CodeProject, people developed very interesting technique of using .NET code in unmanaged code, without resorting to ugly COM components. The approach is based on adding special attributes to members to be exported to unmanaged, automatic assembling of the code, disassembling it, modification of it and assembling again. Please see:
    loading C# DLL in MFC[^],
    How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^],
    Call Managed DLL written in C# from Unmanged Code VC++[^],
    API's in .Net: Managed or UnManaged Code[^].
I would add that first case is just one of the cases where using disassember is useful for learning. IL documentation is not really good, the only real source is the ECMA standard on CLR, and Emit documentation is too brief.

Those are advanced rarely used techniques, but disassembly is also used rarely.

Finally, I would like to recommend wonderful open-source product which can be used for disassembly and translation between .NET languages:
http://www.ilspy.net[^],
see also http://en.wikipedia.org/wiki/.NET_Reflector[^], where ILSpy is mentioned, as well as some other products.

—SA
 
Share this answer
 
v3
Comments
Mehdi Gholam 11-Feb-14 12:33pm    
I agree wholeheartedly, 5'ed
Sergey Alexandrovich Kryukov 11-Feb-14 13:03pm    
Thank you very much, Mehdi.
—SA
Matt T Heffron 11-Feb-14 12:51pm    
+5
Sergey Alexandrovich Kryukov 11-Feb-14 13:05pm    
Thank you, Matt.
—SA
Member 10588642 19-Feb-14 4:15am    
Thank you very much for the clarification.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900