Chinaunix首页 | 论坛 | 博客
  • 博客访问: 566948
  • 博文数量: 99
  • 博客积分: 3976
  • 博客等级: 中校
  • 技术积分: 1041
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-15 15:48
文章分类
文章存档

2009年(1)

2008年(5)

2007年(31)

2006年(58)

2005年(4)

分类:

2006-04-02 15:11:44

#include
FILE *in;
FILE *out;
int main(int argc, char *argv[])
{
 unsigned char ch;
 int    cnt = 0;
 if (argc < 4)
 {
  printf("usage: bin2c infile.bin outfile.h array_name\n");
  return -1;
 }
 if ((in = fopen(argv[1], "rb")) == NULL)
 {
  printf("Couldn't open data file.\n");
  return -1;
 }
 if ((out = fopen(argv[2], "wb")) == NULL)
 {
  printf("Couldn't open output file.\n");
  return -1;
 }
 fprintf(out, "unsigned char %s[] = {\n", argv[3]);
 ch = fgetc(in);
 while (!feof(in))
 {
  if (cnt != 0)
   fprintf(out, ", ");
  if (!(cnt % 16))
   fprintf(out, "\n");
  fprintf(out, "0x%02x", (int)ch);
  cnt++;
  ch = fgetc(in);
 }
 fprintf(out, "\n};\n");
 fclose(in);
 fclose(out);
 return 0;
}
 
 
这段代码可以实现将bin转成机器码!
 
 
 
阅读(1204) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~