views:

1402

answers:

5

I'm well aware of Java tools for manipulating, generating, decompiling JVM bytecode (ASM, cglib, jad, etc). What similar tools exist for the CLR bytecode? Do people do bytecode manipulation for the CLR?

+4  A: 

ILDASM and Reflector come to mind.

Geoffrey Chetwood
+10  A: 

Reflector is always good, but Mono.Cecil is the best tool you can possibly ask for overall. It's invaluable for manipulating CIL in any way.

Cody Brocious
+5  A: 

Bytecode is a binary format. .NET assemblies work pretty different in terms of how they store the execution instructions.

Instead of compiling down to a bytecode-like structure, .NET languages are compiled into an Intermediate Language (in fact, it's called just that--IL).

This is a human readable language that looks sorta like an object-oriented version of assembler.

So in terms of examining or manipulating the IL for individual assemblies, tools like Reflector and ILDASM allow you to conveniently view the IL for any assembly.

Manipulation is a bit different, I'd suggest taking a look at some of the AOP tools in the .NET space. I'd also suggest taking a look at Phoenix, which is a compiler project that MS has in the works. It has some really cool post-compile manipulation features.

If you want to know more about the .NET AOP tools, I'd suggest opening another question (that's a whole other can of worms).

There are also several books that will teach you the ins and outs of IL. It's not a very complicated language to learn.

therealhoff
"NET assemblies work pretty different in terms of how they store the execution instructions" no they do not...everything is ultimately compiled down to a "binary format". This binary format has a 1 to 1 correspondence with IL.
SDX2000
+5  A: 

Mono.Cecil is a great tool like ASM. It's a subproject of Mono, and totally open source. It even provides better feature than System.Reflection.

Sun Liwen
+1  A: 

NDepend allows you to do .NET assemblies static analysis (code metrics, dependency analysis, etc.). NDepend is very useful to get an overview of the structure of your .NET assemblies using dependency matrix, dependency graphs and treemap metrics visualizations.

It is also integrated with Reflector: for example you can detect the important types and methods in your assemblies using respectively a Type/Method Rank metric (a code metric similar to Google Page Rank), and jump directly from NDepend to Reflector to get the disassembled code in C#, VB.NET, etc.

vaucouleur