www.pudn.com > antinimda.zip > w32_nimda.cpp
// w32_nimda.cpp: implementation of the w32_nimda_a class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "w32_nimda.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define TEMP_FILENAME "c:\\temp.exe"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
VirusKiller::SCANRESULT w32_nimda_a::Clean(LPCTSTR file)
{
/* extract file name */
int brk;
CString filename(file);
if ((brk=filename.ReverseFind('\\'))==-1) brk=0;
filename=filename.Mid(brk+1);
/* automatically delete dlls that are pure virus */
filename.MakeLower();
if ((filename.Find("riched")!=-1) || (filename=="load.exe") || (filename=="load32.exe") || (filename.Find("tmp.exe")!=-1) )
{
if (DeleteFile(file))
return VIRUS_DELETED;
else
return VIRUS_ERR;
}
/* get a handle to the executable */
try{
HMODULE hfile = LoadLibrary(file);
if (hfile) {
/* if(!EnumResourceTypes(hfile,s_enumresourcetypes,(long)this))
return VirusKiller::ERR;
*/
/* find handle to resource containing origional code */
HRSRC src=FindResource(hfile, MAKEINTRESOURCE(0x66), MAKEINTRESOURCE(0x0A));
if (src) {
int origional_file_size=SizeofResource(hfile,src);
HGLOBAL origional_file=LoadResource(hfile,src);
/* save to temp file */
FILE* fp;
if (fp=fopen(TEMP_FILENAME,"wb")) {
if (fwrite(origional_file, 1, origional_file_size, fp)TAIL_BYTES_TO_READ)
VERIFY(f.Seek(-TAIL_BYTES_TO_READ,CFile::end));
/* read in the last TAIL_BYTES_TO_READ bytes */
char buffer[TAIL_BYTES_TO_READ+1];
int bytes_read;
if(bytes_read=f.Read(buffer,TAIL_BYTES_TO_READ)) {
/* find the position of the first ending */
char* first_close_head=stristr(buffer,"