4

I maintain a C# program at work and due to a hard disk crash i lost a big chunk of code for an already deployed version (which is my own fault for not pushing the git repository often enough) and now i have to make some changes to the program. I have the source code of an older version of the program and i want to decompile the exe and merge it with the older source to restore the code i lost.

I know i can decompile with tools like the reflector, but i don't want to merge it with the old code by hand, as i then could just code the changes again (about 1-2 days of work). Is that possible or do i have to go through the code dump manually?

1
  • I don't know any automated decompilation utilities and I think there is actually no such utility available. Reflector by far is the best tool for .NET disassembly/decompilation and does it's job well... Commented Jan 11, 2011 at 7:11

2 Answers 2

7

I suggest you recompile the old code, and decompile that with reflector.

Then decompile the current executable with reflector, and diff those two. That way you'll only see the changes you made and you can apply those to your old source code, rather than just taking a diff between decompiled code and the original source - which will obviously throw up huge amounts of uninteresting differences (comments, for one thing!).

I can't see how it would get better than that, to be honest. It will be a manual process of course, but it should still save you some time.

Sign up to request clarification or add additional context in comments.

3 Comments

Very good suggestion. I'll leave the question for a while to wait for other suggestions, but i think i will accept this later.
Not necessarely, you can use patch to apply the diff, which is completely automatic. Of course, this assumes you approve to the entire diff, which he certainly won't.
I just had an identical situation and Reflector worked perfectly, Thanks!
0

I had to do this once, I recommend Dis#.

Edit:
Now, ILSpy is much better

2 Comments

Dis# doesn't seem to do more than the reflector to solve my problem and since i can't spend money on the problem i can only get the very limited trial of it.
I don't exactly know what reflector is capable of, but Dis# can not only create you all the source files at once (in C# or VB.NET or Delphi.NET), it also creates you the entire Visual Studio Project, and adds all references. Last time I tried, the project I decompiled compiled right away... PS: I told you I'd do it for you (if you want), In case of yes, just give me your email address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.