-2

My goal is to decompile a C# libarabry and compare it to the source code of the same library in Github. I would like to research whether the given source code (after decompiling) is equal to the source code in Github.

I've used ILSpy to try to achieve this goal. I've download and decomplied the libarary "FluentScheduler" (v 5.5.1) - Nuget link: https://www.nuget.org/packages/FluentScheduler/

And I compared the given source code (in my case, I took MonthUnit.cs file) to the same one on Github (same version as well).

Github link:

I noticed the code is pretty similar, but not exactly, for example:

we can see the difference between the source code generated by ILSpy and the source code on Github

Is there any way to play with ILSpy conf to remove unnecessary parenthesis? one-liners? make it similar to the Github source code with an exact match? If not, should I use another tool that will decompile the file and result in the same result as Github?

Thanks a lot!

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 2
    What's the point of decompiling when you have _access to the source code on GitHub?_ In any event decompiling doesn't reveal everything and don't forget the binary has gone through some possible optimisations when it was compiled so again unlikely to be the same –  Jun 14 '21 at 08:49
  • The same thing happens when someone translates an English text into French and another translates it back into English: periods and commas may change, just like the arrangement of the words, the important thing being the meaning and the result. –  Jun 14 '21 at 08:49
  • 1
    @OlivierRogier good analogy. Another is _[xx whispers](https://en.wikipedia.org/wiki/Chinese_whispers)_ game :) –  Jun 14 '21 at 08:53

2 Answers2

1

Is there any way to play with ILSpy conf to remove unnecessary parenthesis? one-liners? make it similar to the Github source code with an exact match?

No, there is not. Things that are not neccessary (for example white space formatting or things that did not need to be in the final assembly like redundant statements) will not be there when you decompile it.

What you could do is use the same formatter that aggressively enforces a specific style (doesn't really matter which) on both the source code and the decompiled result. That should bring you closer. But it will likely not be 100% perfect.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
0

You could compile the code on GitHub to a .dll, then decompile both the .dlls with ILSpy and diff the two decompilation results.

Make sure that you consistently use debug/release builds for both .dlls; and that debug symbols (.pdb) are consistently present for both or neither .dlls.

This way all the stuff where the decompiler can choose between multiple ways to write the same code (formatting, control-flow arrangement, variable names, ...) should look the same way.

Note that you may still get some insignificant differences if the two .dlls were compiled with different compiler versions, as slight differences in the IL may lead ILSpy to make different choices during decompilation.

Daniel
  • 15,944
  • 2
  • 54
  • 60