Modify Compiled .Net Exe

2020-08-12 18:28发布

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条回答
别忘想泡老子
2楼-- · 2020-08-12 18:38

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.

查看更多
ら.Afraid
3楼-- · 2020-08-12 18:39

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.

查看更多
来,给爷笑一个
4楼-- · 2020-08-12 18:42

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.

查看更多
戒情不戒烟
5楼-- · 2020-08-12 18:43

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.

查看更多
可以哭但决不认输i
6楼-- · 2020-08-12 18:53

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

查看更多
啃猪蹄的小仙女
7楼-- · 2020-08-12 19:01

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

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

查看更多
登录 后发表回答