一段本身打印本身的c程序 -linux

颇有趣,在一些场合也颇有用的东西,昨天从老张那里淘来了。

test.cspa

#include <stdio.h>
#include <stdlib.h>

extern char * _binary_test_c_start;
int main()
{
        printf("%s", (char *)&_binary_test_c_start);
}
code

 

Makefile对象

 

SRC = test.c
TAR = t
ALL:test.c
        objcopy -I binary -O elf32-i386 -B i386 test.c test.bin
        gcc -o t test.c test.bin
ci

 

objcopy很方便的能够把文本文件作成能够链接器能够链接的对象,进而链进可执行程序里面。io

相关文章
相关标签/搜索