曾经,程序的自动改写是每个黑客必备的知识,因为这样可以有效的节约内存,下面是在现代的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