曾经,程序的自动改写是每个黑客必备的知识,因为这样可以有效的节约内存,下面是在现代的GNU/Linux 操作系统上实现的程序自我改写。
列一下环境:
speller@SHELL-LAB:~/code/c$ egrep "model name" /proc/cpuinfo | uniq -c
2 model name : Pentium(R) Dual-Core CPU E6300 @ 2.80GHz
speller@SHELL-LAB:~/code/c$ uname -sr
Linux 2.6.35.10-smp
speller@SHELL-LAB:~/code/c$ gcc --version | grep GCC
gcc (GCC) 4.4.4
speller@SHELL-LAB:~/code/c$
上代码:
列一下环境:
speller@SHELL-LAB:~/code/c$ egrep "model name" /proc/cpuinfo | uniq -c
2 model name : Pentium(R) Dual-Core CPU E6300 @ 2.80GHz
speller@SHELL-LAB:~/code/c$ uname -sr
Linux 2.6.35.10-smp
speller@SHELL-LAB:~/code/c$ gcc --version | grep GCC
gcc (GCC) 4.4.4
speller@SHELL-LAB:~/code/c$
上代码:
- /*
- * 文件名: self-modification.c
- * 备注: 一个可以修改自身代码的小程序 ;p
- */
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/mman.h>
- void func (void);
- int main
- (int argc, char *argv[]) {
-
- int count = 0;
- for (count = 0; count < 3

这是一个C语言程序,它能够修改自身的代码,在第二次及以后的执行中跳过特定的代码段,展示了程序的自我改写能力。
最低0.47元/天 解锁文章
980

被折叠的 条评论
为什么被折叠?



