icsharpcode/ILSpy

Make it target a specific compiler, and add a tool to compare the recompiled IL to the original IL

H-A-M-G-E-R opened this issue · 6 comments

For decompiler accuracy checking, so I can decompile Axiom Verge for modding purposes

Just like UndertaleModTool's "CheckDecompiler.csx" script

Here's my plan: Disassemble the game to InlineIL-assemblable code (https://github.com/ltrzesniewski/InlineIL.Fody) and manually decompile it

The ILSpy decompiler engine was designed to preserve only the overall semantics; not to result in the exact same IL on recompilation. For example, look at the ExpressionBuilder post condition -- there's some serious flexibility there to allow the decompiler to deviate from the type sizes in the input IL, and create code that is easier to read while having the same end-result (but possibly different intermediate results).
This was especially important prior to C# 9 when we didn't have nint available, and had to emulate nint-sized computations with other types.
We also follow the same approach in other areas such as such as control flow transformations.

Your InlineIL.Fody idea seems like it would be an alternative output syntax for a disassembler; and wouldn't require a decompiler engine at all?

Yeah, to make it easy to start making a matching decomp of a non-obfuscated program
and gradually replace the IL code with bytematching decompiled C# code.

And add a feature to specify a compiler and let it try to compile the decompiled function and see the differences between the original IL and the recompiled IL, and manually correct the C# code to match the original IL.

This is something we do not intend to build, closing.