反射是逆向工程吗?
您可以通过反射了解应用程序内部的大量信息,它由 .NET BCL(基类库)公开,并且使得检索任何 .NET 方法的实际 IL 变得微不足道。
维基百科上的逆向工程:
逆向工程是 发现的过程 设备的技术原理, 通过分析对象或系统 其结构、功能和操作。
作为结构分析,反思肯定会令人满意。 但内省和实际逆向工程之间的界限在哪里? 从法律的角度来看,反射是逆向工程吗?
You can find out a great deal about the internals of an application through reflection, it's exposed by the .NET BCL (base class library) and it makes it trivial to retrieve actual IL for any .NET method.
Reverse engineering on Wikipedia:
Reverse engineering is the
process of discovering the
technological principles of a device,
object or system through analysis of
its structure, function and operation.
Reflection would certainly satisfy as analysis of structure. But where do you draw the line between introspection and actual reverse engineering? And from a legal standpoint, is reflection reverse engineering?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
这完全取决于你反思的程度。 如果您使用像 Reflector 这样的工具,或者自己编写类似的代码,那么这将是逆向工程,因为您实际上正在获取源代码。
正如 Don 所说,反射可用于调用方法或查看属性,但它也可用于分析程序集的结构,甚至可以查看底层 MSIL 代码的内部。 因此,反射的一种用途可能是无害的,另一种用途就是逆向工程。
It all depends on the extent you take reflection. If you use a tool like Reflector, or code up something like that yourself, then that would be reverse engineering as you are actually getting to the source code.
Reflection can be used to invoke methods or look at attributes as Don said, but it can also be used to analyze the structure of an assembly and even peek inside to the underlying MSIL code. So one use of reflection might be innocent, and one would be reverse engineering.
反射是一个通用的计算机科学术语,在引入Microsoft .Net 框架(比 SUN JVM)。 这个想法并非旨在逆向工程应用。 在特定的上下文中它可以用于此目的只是偶然的。 正如其他人所写,反思是一种“工具”。
Reflection is a general computer science term that was in use decades before the introduction of Microsoft .Net framework (than SUN JVM). The idea was not aimed to reverse engineering application. That in specific contexts it can be used for this purpose is just accidental. As others have written, reflection is a "tool".
许多语言(例如 .NET 和 Java)中的反射都是针对不良语法的补丁,这些语法不允许您与对象自由交互。
在真正的面向对象语言(如 Smalltak 或 Self)中,您几乎不需要反射,并且如果需要的话,它到目前为止比 .NET 和 Java 提供的功能更强大。
话虽如此,我确实相信反射是逆向工程,考虑到 RE 更像是理解代码并用它来做某事,而不是破坏其他人的保护。
我目前正在大量使用 Drupal(基于 PHP),它使用丑陋的东西,例如将模块名称连接到预定义的钩子名称来查找该函数是否存在,以便稍后调用它(例如 module_hook_name)。
它非常方便,但我相信在真正的面向对象语言中,可以通过子类化一个可以回答任何消息的抽象类来避免这种情况,并且子类可以覆盖它。
除非在极端情况下才应该使用反射,在这种情况下你可以看到编程语言的缺陷。
Reflection in many languages like .NET and Java are patches for poor syntaxes that doesn't allow you to interact freely with Objects.
In really Object Oriented languages like Smalltak or Self, you hardly ever need reflection and, if needed, it's by far more powerful than those offered by .NET and Java.
Having said that, I do believe reflection is reverse engineering, considering RE is more like understanding code to do something with it rather than breaking other's protections.
I'm currently working a lot with Drupal (PHP-based), which uses ugly things like concatenating module's names to predefined hook names to find if that function exists, so it can be called later (e.g. module_hook_name).
It's very handy, but I believe in real OO languages that can be avoided by sub-classing an abstract class that can answer any message and subclasses could override that.
Reflection should not be used except for extreme circumstances, which is where you can see flaws of programming languages.
两者之间的界限似乎确实很模糊。 从道德上讲,我会限制程序员的动机。
如果他使用反射来构建一个库、工具或类似的软件,这些库、工具或类似的软件应该与满足某些标准的任何第三方代码进行交互,我不会将其视为逆向工程。
例如,我最近正在为 Linq2SQL 数据层编写一个通用基类。 基类使用反射来深入了解数据库布局并正确处理嵌套业务实体的更新。 如果其他人将我的基类用于他的 Web 应用程序,我将无法获得有关他的源代码的任何知识。 这种反射的使用当然不是逆向工程。
另一方面,如果程序员试图使用反射来理解竞争对手软件的内部工作原理,那么他就是在对其进行逆向工程。
The border between the two does seem blurred. Ethically I would draw the line in the programmer's motivation.
If he is using reflection to build a library, tool or similar software that is supposed to interact with any 3rd party code that satisfies certain criteria, I would not see it as reverse engineering.
For example, I was recently writing a generic base class for Linq2SQL data layers. The base class uses reflection to gain insight into the database layout and properly handle updates of nested business entities. If someone else uses my bases class for his web application, I would not gain any knowledge about the his source code. This usage of reflection is certainly no reverse engineering.
If, on the other hand, the programmer is trying to understand the inner workings by a competitor's software using reflection, he is reverse engineering it.
当轻松反编译语言的能力是语言(如反射)的一部分时,我们必须对逆向工程的定义提出质疑。
有了像 .NET Reflector 这样的工具,我觉得界限真的开始模糊了!
使用 SO 本身的一个例子,他们最近对源代码进行了去混淆大规模杀伤性武器编辑器。 我认为这比反射更能定义逆向工程。
One must call into question the definition of Reverse Engineering when the ability to easily decompile the language is a part of the language ala Reflection.
With a tool like .NET Reflector I feel like the lines really start to blur!
Using an example from SO itself, they recently de-obfuscated the source code for their WMD Editor. I would argue that this defines Reverse Engineering more so than Reflection does.
反射只是从程序集中读取信息的工具,因此它本身并不是逆向工程。
如果您随后使用此信息来了解程序集是如何创建的,例如使用 .NET Reflector 生成可以生成相同 IL 代码的可读源代码,这就是逆向工程。
Reflection is just a tool to read information from an assembly, so that by itself is not reverse engineering.
If you then use this information to find out how the assembly was created, for example using .NET reflector to produce readable source code that could generate the same IL code, that is reverse engineering.
我想说反射只是一个工具。 使用反射并不一定意味着逆向工程。
例如,如果您使用反射来发现程序集中所有公共和受保护方法的签名,这并不意味着逆向工程。
至于法律的立场,我建议你必须看看你所担心的法律来找到逆向工程的定义。
I would say Reflection is merely a tool. The use of reflection doesn't necessarily mean reverse engineering.
For example, if you use reflection to discover the signatures of all the public and protected methods in an assembly that wouldn't mean reverse engineering.
As for a legal standpoint, I suggest you have to look at the law you are worried about to find the definition of reverse engineering.
反射是一种可用于许多事情的工具,包括代码的逆向工程。 反射也可以用于许多其他目的,例如,由于反射,实现动态语言要容易得多。
对于逆向工程来说,仅靠反射也是不够的。 您可以通过这种方式找到有关程序结构的信息,但您仍然需要反编译代码。 像 Reflector 这样的工具确实添加了这个功能。
Reflection is a tool that can be used for many things, including reverse engineering of code. Reflection can be used for many other purposes too, implementing dynamic languages is much easier thanks to reflection for example.
Reflection alone is also not enough for reverse engineering. You can find information on program structure that way but you still need to decompile the code. Tools like reflector do add this functionality.
实际上,这与逆向工程完全相反。
正确地说,“逆向工程”是查看过程的结果,然后逆向工作,以确定它是如何到达那里的。 一般来说,它是在不了解原始代码的情况下完成的,并且通常会产生一个非常不同的过程。
尽管版权所有者发出可怕的威胁,但它是完全合法的。
“反汇编”(又名“反射”)只是读取硬盘上的字节并为其赋予含义的操作。 这正是 CPU 运行代码时所做的事情。 在这里,我们只是让它变得人类可读。 再说一次,尽管版权所有者发出可怕的威胁,但它是完全合法的。
以某种方式出售他人的代码(或自己使用)以避免版权所有者从其作品中获利,是非法的,但我们在这里不讨论这一点。
Actually, it's the direct opposite of reverse engineering.
Properly, "reverse engineering" is to look at the results of a process, and work backward, to determine how it got there. Generally, it's done without any knowledge of the original code and generally yields a very different process.
Despite scary threats by copyright holders, it's perfectly legal.
"Disassembly" (aka "Reflection") is just the action of reading bytes on your hard disk, and assigning meaning to them. This is precisely what the CPU does when it runs the code. Here, we are just making it human readable. Again, despite scary threats by copyright holders, it's perfectly legal.
Selling someone else's code (or using it yourself) in a way which avoids the copyright holder from profiting from his work, is illegal, but we're not talking about that here.
我认为您在这里讨论的是两个不同的事情:
从法律的角度来看,如果您将反射用于逆向工程,这取决于您的目标。
当然是IANAL,但我相信逆向工程本身并不违法。 它可能成为代理的非法活动,即通过侵犯版权等方式进行。
I think you are talking about two different things here:
From a legal point of view, it depends on your goal, if you are using reflection for the purpose of reverse engineering.
Of course IANAL, but I believe that reverse engineering is not illegal by itself. It can become an illegal activity by proxy, i.e. through violation of copyrights etc.
不。通过反射,您通常只是谈论调用方法的不同方式,或者可能查看方法属性。
相比之下,我希望逆向工程的产品能够生成源代码,我可以通过查看源代码来了解作者的算法和想法,这通常是他们试图保护的内容。
No. With reflection, you're typically just talking about a different way of invoking methods, or possibly looking at method attributes.
By way of contrast, I expect the product of reverse engineering to produce source code that I can look at to understand the author's algorithms and ideas, which is typically what they're trying to protect.
法律问题必须询问律师。 律师要收钱。 如果您因未请律师而被起诉,则不聘请律师可能会花费更多费用。
最好的选择:不需要问。 微软已经发布了很多.NET 的源代码。 请参阅http://www.microsoft.com/resources/sharedsource/default.mspx。
Legal questions must be asked of lawyers. Lawyers charge money. Not hiring lawyers can cost even more money if you get sued for not asking a lawyer.
Best bet: don't need to ask. Microsoft has already released source for a lot of .NET. See http://www.microsoft.com/resources/sharedsource/default.mspx.