#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char tmpBuf[256] = {0};
char target[256] = {0};
char target_data[16]={0xff,0xff,0xff,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00};
char *clip = "for /f \"delims=\" %%a in ('\"echo xp f=%s\"') do mshta vbscript:clipboardData.SetData(\"text\",\"%%a\")(window.close)";
char *cp_f = "copy %s C:\\ART2_Kingfisher.IOE.SDC.003.1\\bin";
int read_cfg(char *out_name)
{
char *cfg_name = "./conf.txt";
/*打开和创建配置文件*/
FILE *fp = fopen(cfg_name, "r");
if(fp == NULL){
printf("Create %s file!\n",cfg_name);
fp = fopen(cfg_name, "a");
fwrite("raw_sdkshell.bin", sizeof(char), strlen("raw_sdkshell.bin"), fp);
fclose(fp);
fp = fopen(cfg_name, "r");
}
/*判断文件大小*/
fseek( fp, 0L, SEEK_END);
if(ftell(fp) == 0){
printf("ERR: conf.txt is NULL\n");
return -1;
}
/*读取配置文件数据*/
fseek( fp, 0L, SEEK_SET); //将文件指针移动到文件头
while (!feof(fp)){
fgets(out_name, 32, fp); //读取文件中的一行到buf中,c++可以使用getline
}
fclose(fp);
return 0;
}
int main()
{
FILE *fp = NULL;
/*读取配置文件*/
if(read_cfg(target) == -1){
system("pause");
exit(0);
}
fp = fopen(target,"rb+"); //使用rb+模式,可以往半中间插入数据,而且是覆盖插入
if(fp == NULL){ //若使用"ab+"每次都插入到最后面,调用fseek也没用
printf("ERR: Can not open %s file!\n",target);
system("pause");
exit(0);
}
/*修改bin中的数据*/
fseek(fp, 0x3fff0, SEEK_CUR);
fwrite (target_data, sizeof(char), 16, fp);
fclose(fp);
//复制文件到下载目录
memset(tmpBuf, 0, sizeof(tmpBuf));
sprintf(tmpBuf, cp_f, target);
system(tmpBuf);
//复制内容到剪贴板
memset(tmpBuf, 0, sizeof(tmpBuf));
sprintf(tmpBuf, clip, target);
system(tmpBuf);
return 0;
}