SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Recompile decompiled program using VS 2010 (C#)?

Last post 06-08-2015 4:46 PM by klaymen. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-04-2015 3:38 PM

    Recompile decompiled program using VS 2010 (C#)?

    Hi,

     

    I'm trying to use the IlSpy output and recompile it again (C#). Unfortunately there are a heap of issues related to things that VS and IlSpy seem to interpret differently.

    The simplest, but still annoying issue is that IlSpy doesn't use parameter names in function declarations, eg:

    public static extern bool A(bool, string);

    VS does nto accept this; it does require parameter names, eg public static extern bool A(bool a1, string a2); The parameter names don't care and are completely ignored, but can't be skipped (yes, you can see this as VS bug, but that's the way it is). So having dummy parameter names in the output would be nice.

    Most annoying though is the heavy re-use of names in IlSpy. VS does not accept a class with the same name as one of it's method, or a method with the same name as a property/variable. So heavy refactoring is required, and often this also fails. It owuld be easiest if there's be an option in IlSpy to turn off re-use of variable names.

     

    Is there any easy solution/fix for that? Or would it be better to use a different decompiler, and if so, which one?

    Of course there are also other small things, like goto to wrong scopes, but these can usually be fixed manually. Above naming issue is huge and requires a lot of manual work ... :-(

    Thanks in advance,

     

    Andy

     

  • 06-08-2015 4:46 PM In reply to

    Re: Recompile decompiled program using VS 2010 (C#)?

    I managed to get back ac ompilable project, but with a lot of manual work (and not sure if it's bugfree)...

    First, I tried other Decompielrs (dotPeek, Reflector) - they all have the same issue of sharing names that VS can't seperate anymore.

    Then I tried ILSpy Next (http://ilspy-next.ml/) - actually I'm not sure what the status/difference/relation between ILSpy and ILSpy next exactly is. What the Next version offers that's helpful here is the ability to rename classes and class methods/properties, and I tried to rename them all with unique names. Unlike refactoring tools, ILSpy knows - or should know - precisely what resolves to what and does a much more consistent/reliable job than for instance Resharper (which didn't work for me). The main issue with this task is that it is a lot of manual work, as there's no hotkey on the rename'r (you always have to go via context menu), you need to click into the rename box, and not even "enter" works (you must click "OK" usign the mouse). I'd wish more hotkey support there. After this I still needed to fix the missing parameter names in declarations mentioned above, but for this I wrote a perl script. The main remaining problem were abstract/virtual methods. So, if a class A has some abstract methods f and B derived from A and then implements this method f, in my try to rename all methods individually, ILSpy next didn't notice that when f in A or B is renamed, the same method in the other class (and eventually other implementations of f) needed to be renamed too, so I ended in A with an abstract method f and B with the implementation named g, which I manually had to rename back to f. Fortunately this was manageable, but still this method is not optimal. I think it's a bug in ILSpy next.

    Also I missed a feature to save the modified code as a VS project (it exists in ILSpy, but not - yet - in ILSpy next), so I had to save every class into a file and build the project manually.

    If anybody knows a better method, this woudl be useful to know - for the next time .-)

     

    klaymen

     

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.