c语言小工具



#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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值