69,369
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int main()
{
FILE *pflIO = NULL;
FILE *pflOut = NULL;
pflOut = fopen("test.bin", "wb");
if (NULL ==pflOut)
{
printf("创建文件失败");
return -1;
}
else
{
for (char ch= 0; ch<100; ch++)
{
fwrite(&ch, 1, 1, pflOut);
}
fclose(pflOut);
}
pflIO = fopen("test.bin", "rb+");
if (NULL == pflIO)
{
printf("打开要修改的文件错误");
}
else
{
fseek(pflIO, 10, SEEK_SET);
char ch = 0;
fwrite(&ch, 1, 1, pflIO);
fclose(pflIO);
}
return 0;
}
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
FILE *f;
char ln[64+1];//Because sscanf(argv[66],"%hx",&ln[66-3]); modify ln[63] and ln[64] !
int i;
__int64 hexoffset64;
void main(int argc,char *argv[]) {
if (argc<=3) {
cprintf("Locate & Replace, designed by zhao4zhong1@163.com\n\r");
HELP:
cprintf("Usage: LR filename.ext hexoffset64 byte1 byte2 byte3 ...");
return;
}
if (argc>64+3) {
cprintf("Up to 64 bytes\a");
return;
}
if ((f=fopen(argv[1],"r+b"))==NULL) {
cprintf("Can not open %s\a",argv[1]);
return;
}
if (1!=sscanf(argv[2],"%I64x",&hexoffset64)) {fclose(f);goto HELP;}
if (hexoffset64>=_filelengthi64(_fileno(f))) {
cprintf("hexoffset64==%016I64x >= %016I64x==_filelengthi64 of file %s\a",hexoffset64,_filelengthi64(_fileno(f)),argv[1]);
fclose(f);
return;
}
for (i=3;i<argc;i++) {
if (1!=sscanf(argv[i],"%hx",&ln[i-3])) {fclose(f);goto HELP;}
}
if (hexoffset64!=_lseeki64(_fileno(f),hexoffset64,SEEK_SET)) {
cprintf("_lseeki64 to %I64x fail\a",hexoffset64);
fclose(f);
return;
}
if ((int)fwrite(ln,1,argc-3,f)!=argc-3) {
cprintf("fwrite %d bytes fail\a",argc-3);
fclose(f);
return;
}
fclose(f);
}