69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <io.h>
#include <windows.h>
FILE *f;
char cmd[256];
char fn[256];
char fn_old[256];
char fn_new[256];
char *b,*p;
int fl,i;
int main() {
char a[]="hello world!1";
printf("%s",a);
GetModuleFileName(NULL,fn,256);
sprintf(fn_old,"%s_old",fn);
sprintf(fn_new,"%s_new",fn);
f=fopen(fn,"rb");
if (NULL==f) {
printf("Can not open file %s!\n",fn);
return 1;
}
fl=filelength(fileno(f));
b=(char *)malloc(fl);
fread(b,1,fl,f);
fclose(f);
for (i=0;i<fl-14;i++) {
if (0==memcmp(b+i,"hello world!",12) && b[i+12]) {
b[i+12]=0x63-b[i+12];
break;
}
}
f=fopen(fn_new,"wb");
if (NULL==f) {
printf("Can not create file %s!\n",fn_new);
free(b);
return 2;
}
fwrite(b,1,fl,f);
fclose(f);
free(b);
if (!access(fn_old,0)) remove(fn_old);
sprintf(cmd,"cmd.exe /c ren \"%s\" \"%s\"© \"%s\" \"%s\" >NUL 2>NUL",fn,strrchr(fn_old,'\\')+1,fn_new,fn);
WinExec(cmd,SW_HIDE);
return 0;
}
//C:\test>changemyself
//hello world!1
//c:\test>changemyself
//hello world!2
//c:\test>changemyself
//hello world!1
//c:\test>changemyself
//hello world!2