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?
问题:
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
ILDASM and Reflector come to mind.
回答5:
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.