有没有真正的应用程序可以自我修改代码?
网络上很少有示例演示如何编写自修改代码。但它们只是例子。我想知道是否有任何真正的应用程序可以自我修改代码。谢谢!
There are few examples on the web demonstrating how to write a self-modifying code. But they're just examples. I would like to know if there is any real application being self modifying code. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
首先想到的是病毒、木马之类的。
自修改代码使防病毒应用程序更难将您的应用程序识别为恶意应用程序。
使用自修改代码的另一个领域是 遗传编程
还有一个 维基百科文章涵盖了您的问题。
The first thing that comes to mind are viruses, trojaners and the likes.
Self-modifying code makes it harder for anti-virus applications to identify your application as malicious.
Another area were self-modifying code is used is genetic programming
There's also a Wikipedia article covering your question.
我可以参考其他架构吗?因为,当您使用较弱的系统(例如嵌入式应用程序)时,经常使用 SMC,因为只有有限数量的 RAM 可用于程序运行。
此外,维基百科有一个相当不错的 列表。
Am I allowed to reference other architectures? Because, when you're working with weaker systems, like embedded applications, SMC is often used, since there is only a limited amount of RAM available for the programs to run in.
Also, wikipedia has quite a nice list.
“自修改代码”也可能指 Java 中的字节码修改。许多框架(如 Guice、JPA、EJB 和 Web 容器)以及几乎所有 AOP(面向方面编程)框架都使用它。
基本上,它们在 JVM 加载和执行字节码之前对其进行修改。所有这些框架都试图向类添加行为,而不需要手动编写横切关注点。事务控制、依赖注入、作用域或上下文注入是常见的嫌疑对象。
'Self modifying code' may also refer to bytecode modifications in Java. This is used by many frameworks like Guice, JPA, EJB- and Webcontainers and almost all AOP (Aspect Oriented Programming) frameworks.
Basically they modify the bytecode before it is loaded and executed by the JVM. All those frameworks try to add behaviour to the class without the need to code cross-cutting concerns by hand. Transaction control, dependency injection, scope or context injection are the usual suspects.
我知道一个程序包含自修改代码(作为保护方案),它的作用是在输入正确的密码时解密自身,并且解密的代码在将打开的文件保存到磁盘方面发挥着重要作用,该程序称为“WinHEX”.. 您可以在虚拟保护调用的正上方找到 SMC 代码,如果输入正确的密码,程序将调用写入进程内存 api 来解密该部分,并最终将文件保存到磁盘。
I know a program that contains a self modifying code (works as a protection scheme), it's role is to decrypt itself if the right password was entered and the decrypted code plays a big role into saving the opened file to disk, this program is called 'WinHEX'.. you can find the SMC code right above the call to virtual protect, and if the right password is entered, the program calls the write process memory api to decrypt the section, and to eventually save the file to disk.
动态语言运行时 (DLR) 使用自修改代码来优化给定调用站点的常见类型。
假设您正在 .NET 之上编写动态类型语言,并且您的语言的源代码如下:
现在,在静态类型语言中,
x
和的类型y
可以在编译时确定 - 假设x
和y
是int
,那么x + y< /code> 将使用 IL“add”指令。
但在动态类型语言中,这个分辨率每次都可能不同。下次,
x
和y
可以是字符串,在这种情况下,此调用站点的值解析将使用 String.Concat。但决定使用哪种 IL 的成本可能会非常高。事实上,如果在调用站点的第一次命中中,x
和y
是一对int
,则很可能连续命中该调用站点也将带有一对 int 。因此,DLR 进行如下迭代: 调用站点的编译代码如下所示:
第一次传入一组给定类型(例如,一对
int
)时,Update 方法将变为语言实现来确定哪个方法/指令应该与一对 int 和一个 + 一起使用。然后这些规则被重新编译到调用站点中;生成的编译代码看起来像这样:对
int
的连续调用使编译的代码保持不变。如果遇到新的类型对,代码会自行重写为如下内容:
有关其工作原理的详细信息,请参阅 Jim Hugunin 在 PDC 2008 上关于动态语言的演讲 和 DLR 设计文档,位于 DLR 项目。
The Dynamic Language Runtime (DLR) uses self-modifying code to optimize for the common types of a given call site.
Let's say you're writing a dynamically typed language on top of .NET, and you have source code in your language as follows:
Now, in a statically typed language, the types of
x
andy
can be determined at compile time -- sayx
andy
areint
s, thenx + y
will use the IL "add" instruction.But in a dynamically typed language, this resolution could be different every time. Next time,
x
andy
could be strings, in which case the value resolution for this call site would use String.Concat. But resolving which IL to use is liable to be very costly. In fact, if in the first hit of the call sitex
andy
are a pair ofint
s, it's highly likely that successive hits on this call site will also be with a pair ofint
s.So the DLR iterates as follows: The compiled code of the callsite looks like this:
The first time a given set of types is passed in -- say, a pair of
int
s, the Update method turns to the language implementation to resolve which method/instruction should be used with a pair ofint
s and a+
. Those rules are then recompiled into the callsite; the resulting compiled code looks something like this:Successive calls with pairs of
int
s leave the compiled code unchanged.If a new type pair is encountered, the code self-rewrites into something like this:
For more information on how this works, see Jim Hugunin's talk at PDC 2008 on dynamic languages and the DLR design documentation at the DLR project.