Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all, you do not see the original source code; you see reverse-engineered source code.</p> <p>If you are interested in programmatically modifying an assembly, have a look at these projects: * The <a href="http://ccimetadata.codeplex.com/" rel="nofollow noreferrer"><strong>Common Compiler Infrastructure (CCI) Metadata</strong></a> and <a href="http://cciast.codeplex.com/" rel="nofollow noreferrer">CCI AST</a> projects on CodePlex. That's exactly what they are for.</p> <blockquote> <p>"<em>[CCI] allows applications to efficiently analyze or modify .NET assemblies, modules, and debugging (PDB) files."</em> &mdash; from the project's website</p> </blockquote> <p>IIRC, CCI Metadata works at a fairly low level of abstraction. If you want to modify or insert code with it, you'll have to deal with Intermediate Language (IL). CCI AST provides higher-level abstractions (abstract syntax trees).</p> <p>(Btw. I suppose CCI won't allow you to tamper with strongly-named (signed) assemblies, since that would defeat their purpose.)</p> <ul> <li><p><a href="http://www.mono-project.com/Cecil" rel="nofollow noreferrer"><strong>Mono.Cecil</strong></a>. It was developed for Mono, but works on .NET too:</p> <blockquote> <p><em>"In simple English, with Cecil, you can load existing managed assemblies, browse all the contained types, modify them on the fly and save back to the disk the modified assembly."</em> &mdash; from the project's website</p> </blockquote></li> </ul> <p>Btw., there's a question here on Stack Overflow that asks for <a href="https://stackoverflow.com/questions/6727715/cci-vs-mono-cecil-advantages-and-disadvantages">a comparison of the two</a>.</p> <h2><strong>Other related libraries / frameworks:</strong></h2> <ul> <li><p><a href="http://msdn.microsoft.com/en-US/roslyn" rel="nofollow noreferrer"><strong>Roslyn</strong></a>. This project's focus is on the representation of source code as abstract syntax/parse trees, and allows you to do e.g. source code analysis and manipulation. It's also supposed to be able to compile source code for you. However, Roslyn is <em>not</em> specialized on assembly manipulation. (To summarise, you could think of Roslyn as a mix of System.CodeDom and System.Linq.Expressions, but much more powerful than either of these.)</p></li> <li><p><a href="https://stackoverflow.com/users/80572/kevin-montrose">Kevin Montrose</a> has written an IL-emitting library called <strong><a href="https://github.com/kevin-montrose/sigil" rel="nofollow noreferrer">Sigil</a></strong> which is "A fail-fast, validating helper for DynamicMethod and ILGenerator."</p></li> <li><p>You can use the <code>ildasm</code> (IL disassembler) and <code>ilasm</code> (IL assembler) to do something called "round-tripping" (read about it e.g. <a href="https://blogs.msdn.microsoft.com/jmstall/2006/01/13/debugabbility-with-roundtripping-assemblies/" rel="nofollow noreferrer">on Mike Stall's blog</a>):</p> <blockquote> <p>Round-tripping is where you decompile an app (perhaps via ILDasm), potentially edit the IL, and then recompile it (perhaps via ILAsm). This is the backbone for rewriting an assembly [...].</p> </blockquote></li> <li><p>A last option is the <a href="http://msdn.microsoft.com/de-de/library/system.reflection.aspx" rel="nofollow noreferrer"><strong>System.Reflection</strong></a> and <a href="http://msdn.microsoft.com/de-de/library/system.reflection.emit" rel="nofollow noreferrer"><strong>System.Reflection.Emit</strong></a> functionality in the .NET Base Class Library (BCL). The former allows you to inspect assemblies. The latter provides functionality to generate &amp; save new assemblies to disk. As with CCI, you'll have to deal with raw IL. Also, I don't think they allow you to modify an existing assembly easily.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload