Modify Compiled .Net Exe

39.4k views Asked by At

I have an application written in C# (without the source of course), that needs to be changed a little bit. For example, I need to stop a few lines of code that create an unnecessary menu. So I think I should comment them out.

The source code is not obfuscated. I know I can completely decompile, change, and compile again, using tools like Reflector/Reflexil. But everyone knows that by doing this, many parts of code won't compile again! Is there a way in Reflector (or any other product) that a part of could be disabled/changed without this process?

Thanks.

6

There are 6 answers

0
Delphi.Boy On BEST ANSWER

Eventually I managed to "disable" a few lines of code in the compiled exe.

I used Reflector with Reflexil plugin installed. Reflexil allowed me to edit an MSIL instruction, and then save the result back to an exe file. So, it involved learning a few MSIL instructions, especially the "no operation" command (making a line of code do nothing). To see the list of instructions and a tutorial, see here and here.

Hope it helps someone else.

1
Yaakov Ellis On

If you really needed to do this, you could decompile it with Reflector (or a similar product) and then use that to try to recreate a solution in .Net that will produce the same executable.

You may run into issues around:

  1. Obfuscated code
  2. Sections where the decompile shows you accurate code for specific sections, but for some reason it just doesn't work in your new solution (and then what do you do?)

This is not to mention the potential legal issues related to doing this. If the executable was released under a license that would permit you to do this, then you would most likely have access to the source code. So the fact that you do not have access to the source code implies that doing what you are suggesting might not be legal.

0
Samuel On

for the sake of completeness: Another possible solution is to use the ildasm http://msdn.microsoft.com/en-US/library/f7dy01k1%28v=vs.80%29.aspx MSIL Disassembler, edit the MSIL and feed it back to ilasm.

How practical this solution is, depends on you of course

1
C Sharper On

If you have source code on the same machine on which you are testing your exe file, and if you are making changes in your sourcecode in visual studio, then while compiling it will automatically get reflected in your exe file.

You need not do any special thing for it. And if it is not, then just make the changes in code and paste your debugg folder's new exe (with debugg folder) on another machine having all recent changes.

0
Krishna Sarma On

This thread may help: dotnet dll decompile and change the code

Last time When I tried with decompile the source using reflection, I got too many compilation issues with regarding to resources and other subs though the dll isn't obfuscated. So there could be things beyond just extracting the source and modifying in order to make your new dll work as the old one.

SO I would suggest to go with direct dll manipulation using any of the options mentioned in the other thread.

3
Milos On

You might want to try dnSpy. It is a .NET assembly editor, decompiler, and debugger forked from ILSpy.

https://github.com/0xd4d/dnSpy