代码拉取完成,页面将自动刷新
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>
int main(int argc, char * argv[])
{
FILE * fp_in, * fp_out;
unsigned int length, left;
char fname[256], * p;
uint8_t buffer[256];
if(argc != 3)
{
printf("Usage: %s <binary file> <c file>\n", argv[0]);
exit(-1);
}
fp_in = fopen(argv[1], "rb");
if(fp_in == NULL)
{
printf("Failed to open file %s for reading\n", argv[1]);
exit(-1);
}
fp_out = fopen(argv[2], "wt");
if(fp_out == NULL)
{
printf("Failed to open file %s for output\n", argv[2]);
exit(-1);
}
fseek(fp_in, 0, SEEK_END);
length = ftell(fp_in);
fseek(fp_in, 0, SEEK_SET);
left = length;
fprintf(fp_out, "/* Automatically generated file from %s */\n", argv[1]);
strcpy(fname, argv[1]);
for(p = fname; *p; p++)
if(!isalnum(*p))
*p = '_';
fprintf(fp_out, "unsigned int %s_len = %d;\n", fname, length);
fprintf(fp_out, "unsigned char %s[] = {\n\t", fname);
while(left)
{
int to_read = left < sizeof(buffer) ? left : sizeof(buffer);
int bytes = fread(buffer, 1, to_read, fp_in);
int i;
for(i = 0; i < bytes; i++)
fprintf(fp_out, "0x%02x%s", buffer[i], (i % 16) == 15 ? ",\n\t" : ", ");
left -= bytes;
}
fprintf(fp_out, "\n\t};\n");
fclose(fp_in);
fclose(fp_out);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。