且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我们可以在没有源代码的情况下向dll添加命名空间或类。

更新时间:2023-12-06 17:19:22

没有修改DLL文件就没有办法做到这一点。这样的事情是 System.Reflection.Emit 和CodeDOM允许在运行时创建代码并将其添加到同一运行时的当前进程,但此代码应该是全新的程序集或者所谓的动态方法,而不是类型。



现在,问题可能是假设有问题的DLL是一些有效的.NET部件。更准确地说,它可能是汇编模块之一,很可能只是某些汇编的唯一主要模块。如果是这样,您可以轻松地(如果它不包括一些保护)对其进行反向工程,在源代码中添加新代码并再次构建它。优秀的开源工具是ILSpy:

http://en.wikipedia.org/ wiki / .NET_Reflector [ ^ ](参见其他本文中的产品),

http://www.ilspy.net/ [ ^ ]。



然而,制作确定这个动作是合法的。 在没有源代码的情况下可能非法使用集会的所有法律后果是您自己的责任。在大多数立法领域,这些事情在某些条件下是合法的,但您应该小心这一点。 />


-SA
There is no a way to do it without modifying the DLL file. Such things are System.Reflection.Emit and CodeDOM allow to create code during runtime and add it to your current process in the same runtime, but this code should be the whole new assembly or a so called dynamic method, not the type.

Now, the question probably assumes that the DLL in question is some valid .NET assembly. More exactly, it could be one of the assembly modules, most likely, just the only main module of some assembly. If so, you can easily (if it does not include some protection) reverse engineer it, add new code in source code and build it again. The excellent open-source tool for that is ILSpy:
http://en.wikipedia.org/wiki/.NET_Reflector[^] (see other products in this article),
http://www.ilspy.net/[^].

However, make sure this action is legitimate. All legal consequences of possible illegal use of the assembly which comes without source code is your sole responsibility. In most domains of legislation such things are legal under certain conditions, but you should be careful about that.

—SA