简体   繁体   English

修改编译的.Net Exe

[英]Modify Compiled .Net Exe

I have an application written in C# (without the source of course), that needs to be changed a little bit. 我有一个用C#编写的应用程序(当然没有源代码),需要稍微更改一下。 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. 我知道我可以使用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? Reflector(或任何其他产品)中是否有一种方法可以在没有此过程的情况下禁用/更改部分内容?

Thanks. 谢谢。

You might want to try dnSpy. 您可能想尝试dnSpy。 It is a .NET assembly editor, decompiler, and debugger forked from ILSpy. 它是一个从ILSpy派生的.NET程序集编辑器,反编译器和调试器。

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

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. 如果你真的需要这样做,你可以使用Reflector(或类似产品)对其进行反编译,然后使用它来尝试在.Net中重新创建一个可生成相同可执行文件的解决方案。

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. 因此,您无法访问源代码这一事实意味着您所做的建议可能并不合法。

Eventually I managed to "disable" a few lines of code in the compiled exe. 最终我设法在已编译的exe中“禁用”几行代码。

I used Reflector with Reflexil plugin installed. 我使用Reflector和Reflexil插件安装。 Reflexil allowed me to edit an MSIL instruction, and then save the result back to an exe file. Reflexil允许我编辑MSIL指令,然后将结果保存回exe文件。 So, it involved learning a few MSIL instructions, especially the "no operation" command (making a line of code do nothing). 因此,它涉及学习一些MSIL指令,尤其是“无操作”命令(使一行代码无效)。 To see the list of instructions and a tutorial, see here and here . 要查看说明列表和教程,请参阅此处此处

Hope it helps someone else. 希望它可以帮助别人。

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. 为了完整起见:另一个可能的解决方案是使用ildasm http://msdn.microsoft.com/en-US/library/f7dy01k1%28v=vs.80%29.aspx MSIL反汇编程序,编辑MSIL并将其提供给它回到了伊拉斯。

How practical this solution is, depends on you of course 这个解决方案的实用程度当然取决于你

This thread may help: dotnet dll decompile and change the code 这个线程可能会有所帮助: dotnet dll反编译并更改代码

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. 上次当我尝试使用反射对反射源进行反编译时,虽然dll没有被混淆,但是关于资源和其他潜艇的编译问题太多了。 So there could be things beyond just extracting the source and modifying in order to make your new dll work as the old one. 因此,除了提取源和修改之外,还有一些事情可以让你的新dll作为旧的dll工作。

SO I would suggest to go with direct dll manipulation using any of the options mentioned in the other thread. 所以我建议使用另一个线程中提到的任何选项进行直接dll操作。

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. 如果您在测试exe文件的同一台机器上有源代码,并且如果您在visual studio中对源代码进行了更改,那么在编译它时会自动反映在您的exe文件中。

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. 如果不是,那么只需在代码中进行更改并将debugg文件夹的新exe(带有debugg文件夹)粘贴到另一台具有所有最近更改的计算机上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM