Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4737529
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: LINUX

2009-08-22 10:53:40


test.c

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

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

  printf("hahah\n");
}

 

Makefile

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

 

objcopy很方便的可以把文本文件做成可以连接器可以连接的对象,进而链进可执行程序里面。

[root@kenthy c_par]# ./test
#include
#include

extern char* _binary_test_c_start;

int main()
{
  printf("%s", (char *)&_binary_test_c_start);
  printf("hahah\n");
  return 0;
}
hahah

有点小意思!!!都还没用过objcopy呢^_^


原文:http://blog.chinaunix.net/u/1574/showart_2032979.html

 

阅读(2559) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-08-27 12:59:00

ld -b binary -r -o test.bin test.c 好像也可以吧

whtech2009-08-26 16:51:07

有意思.