icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
21.23k stars 3.33k forks source link

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

Closed H-A-M-G-E-R closed 1 week ago

H-A-M-G-E-R commented 2 weeks ago

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

H-A-M-G-E-R commented 2 weeks ago

Just like UndertaleModTool's "CheckDecompiler.csx" script

H-A-M-G-E-R commented 2 weeks ago

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

dgrunwald commented 1 week ago

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?

H-A-M-G-E-R commented 1 week ago

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.

H-A-M-G-E-R commented 1 week ago

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.

christophwille commented 1 week ago

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