由于对EXE文件结构的不了解,特用txt文件对其阐述。
希望高手能给我一些帮助。
下面是原代。
#include<stdio.h>
#include<stdlib.h>
int type1(FILE *Q,char *a);//返回文件大小
main()
{
FILE *B;\\感染主程序
FILE *GR;\\感染对象
FILE *C;\\感染后的文件
char c;
int i = 0 , size;
char *s = "GR.txt";
size = type1(GR,s);
if((B = fopen("B1.txt","rb")) != NULL && (GR = fopen("GR.txt","rb"))!=NULL&& (C = fopen("1.txt","wb") )!=NULL ){
fseek(B,8L,0);
printf("%d",size);
while(!feof(GR))
{
i ++ ;
fread(&c,1,1,GR);
fwrite(&c,1,1,C);
if(i == size-7){
break;
}
}
fclose(GR);
while(!feof(B))\\插入感染代码
{
fread(&c,1,1,B);
fwrite(&c,1,1,C);
}
fclose(B);
fclose(C);}
system("del GR.txt");
system("copy 1.txt GR.txt");
system("del 1.txt");
}
int type1(FILE *Q,char *a)
{
int i = 0;
char d;
if((Q = fopen(a,"rb")) != NULL){
while(!feof(Q))
{i++;
fread(&d,1,1,Q);
}
}
fclose(Q);
return i;
}