Modify Compiled .Net Exe
Asked Answered
C

6

16

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.

Claw answered 26/8, 2013 at 5:10 Comment(0)
C
5

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.

Claw answered 6/4, 2015 at 14:30 Comment(0)
H
32

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

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

Heterodox answered 31/12, 2015 at 15:39 Comment(3)
Great find! The github page description looks like it's some crappy unmaintaned project, but the app itself is leagues ahead of any of the free alternatives.Odeliaodelinda
Wow, I'm impressed. This can actually recompile modified assemblies. I just wanted to changed a hard coded email address (sight) and this did the trick! Insane!Refutative
I was able to comment out a loop with this in less than a minute after having struggled with dotPeek extracted sources for an hour unsuccessfully trying to get it to compile.Friction
L
5

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.

Leschen answered 26/8, 2013 at 5:32 Comment(1)
Apart from legal matters, the source code is not obfuscated. I knew I could completely decompile, change, and compile again. But as you said, 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?Claw
C
5

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.

Claw answered 6/4, 2015 at 14:30 Comment(0)
R
3

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

Rennes answered 26/8, 2013 at 7:26 Comment(0)
I
1

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.

Isobath answered 26/8, 2013 at 5:47 Comment(0)
T
-2

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.

Trantham answered 26/8, 2013 at 5:35 Comment(1)
Would you mind reading the question again? We don't have any source code. Just compiled exe and dlls. And we need to change a few lines of code.Claw

© 2022 - 2024 — McMap. All rights reserved.