Разработка антивирусного монитора (listing prog)

Посмотреть архив целиком

Приложение 1: Листинг программы


Заголовочный файл основной формы (Unit1.h):


#ifndef Unit1H

#define Unit1H

//---------------------------------------------------------------------------

#include

#include

#include

#include

#include "cdiroutl.h"

#include

#include

#include

#include

#include

//---------------------------------------------------------------------------

class TForm1 : public TForm

{

__published: // IDE-managed Components

TCDirectoryOutline *CDirectoryOutline1;

TFileListBox *FileListBox1;

TDriveComboBox *DriveComboBox1;

TLabel *Label1;

TButton *Button1;

TButton *Button2;

TButton *Button3;

TButton *Button4;

TButton *Button5;

TButton *Button6;

TButton *Button7;

TTimer *Timer1;

TAnimate *Animate1;

TControlBar *ControlBar1;

TButton *Button8;

TButton *Button9;

void __fastcall Button7Click(TObject *Sender);

void __fastcall Button5Click(TObject *Sender);

void __fastcall Button3Click(TObject *Sender);

void __fastcall Button6Click(TObject *Sender);

void __fastcall Button1Click(TObject *Sender);

void __fastcall DriveComboBox1Change(TObject *Sender);

void __fastcall Button2Click(TObject *Sender);

void __fastcall Button4Click(TObject *Sender);

void __fastcall Timer1Timer(TObject *Sender);

void __fastcall Button8Click(TObject *Sender);

void __fastcall Button9Click(TObject *Sender);

private: // User declarations

void __fastcall OnClose(TWMClose& Message);

public: // User declarations

__fastcall TForm1(TComponent* Owner);

BEGIN_MESSAGE_MAP

MESSAGE_HANDLER(WM_CLOSE, TWMClose, OnClose)

END_MESSAGE_MAP(TComponent)

};

//---------------------------------------------------------------------------

extern PACKAGE TForm1 *Form1;

//---------------------------------------------------------------------------

#endif


C++ файл основной формы (Unit1.cpp)


#include

#pragma hdrstop


#include //

#include //

#include //

#include <fcntl.h> //для эксклюзивного доступа


#include

#include

#include


#include "Unit1.h"

#include "Unit2.h"

#include "Unit3.h"

#include "Unit4.h"

#include "Unit5.h"

#include "Unit6.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma link "cdiroutl"

#pragma resource "*.dfm"

TForm1 *Form1;

//---------------------------------------------------------------------------


String PathDir;

String PathToTraps=ExtractFileDir(GetCommandLine()).c_str()+1;


TFScan *SecondProcess;

int trapshnd[3];

int hndsys[3];

int M[2000]; //ограничение числа открываемых .EXE файлов

int glob=0;

String ZashDrives="";

int ZashFiles=0;

int ZashFolders=0;

int ExeFiles=0;

int ComFiles=0;


String Gammirovanie(String Stroka)

{

char Gamma[5]={'G','A','M','M','A'};

String SodegjVvoda="";

char simvol;

for(int s=1;s

{

if (s<=5)

{

simvol=Stroka[s];

if (((int)Gamma[s-1]+(int)simvol)>=255)

{

simvol=((char)((int)simvol+(int)Gamma[s-1]-255));

SodegjVvoda=SodegjVvoda+String((char)((int)simvol));

}

else

{

SodegjVvoda=SodegjVvoda+String((char)((int)Gamma[s-1]+(int)simvol));

}

}

}

return SodegjVvoda;

}

//---------------------------------------------------------------------------



String OpenAndReadFile(String FName)

{

String pas="";

String SoderjDiska="";

FILE *F;

F=fopen(FName.c_str(), "r");

if(FileExists(FName))

{

for(int s=0;!feof(F);s++)

{

SoderjDiska=pas;

pas=pas+(char)(getc(F));

}

}

fclose(F);

return SoderjDiska;

}

//---------------------------------------------------------------------------


void OpenAndWriteFile(String FName, String WordInFile)

{

String pas="";

String SoderjDiska="";

FILE *F;

F=fopen(FName.c_str(), "w");

if(FileExists(FName))

{

fputs(WordInFile.c_str(),F);

}

fclose(F);

}

//---------------------------------------------------------------------------


String DataBios(void)

{

String ItogData="";

unsigned char far * addr = (unsigned char far *) 0xffff5;

for(int s=0;s<8;s++)

{

ItogData=ItogData+(char)*addr;

*addr++;

}

return ItogData;

}

//---------------------------------------------------------------------------


void StelsProgram(void) //обеспечивает скрытость процесса от регистрации Windows

{

typedef DWORD (CALLBACK* LPFNDLLFUNC1)(DWORD,DWORD);

HINSTANCE hdll;

LPFNDLLFUNC1 f1;

hdll = LoadLibrary("Kernel32.dll");

f1 = (LPFNDLLFUNC1)GetProcAddress(hdll,"RegisterServiceProcess");

(f1)(0,1);

}

//---------------------------------------------------------------------------


void CloseTraps(void)

{

FileClose(trapshnd[0]);

FileClose(trapshnd[1]);

FileClose(trapshnd[2]);

}

//---------------------------------------------------------------------------



String PathTrapsDir(String Tr)

{

PathDir = PathToTraps+"\\Traps\\"+Tr;

return PathDir;

}

//---------------------------------------------------------------------------



void OpenTraps (void)

{

trapshnd[0]=FileOpen(PathTrapsDir("Trap1.exe"), fmShareExclusive);

trapshnd[1]=FileOpen(PathTrapsDir("Trap2.exe"), fmShareExclusive);

trapshnd[2]=FileOpen(PathTrapsDir("Trap3.exe"), fmShareExclusive);

}

//---------------------------------------------------------------------------


void ExclusiveOpenAllExeAndComFilesOnDrive(void)

{

CloseTraps();

for(int j=1; j<=Form1->CDirectoryOutline1->Lines->Count; j++)

{

if(Form1->CDirectoryOutline1->Items[j]->Expanded==false)

{

Form1->CDirectoryOutline1->Items[j]->Expand();

ZashFolders++;

}

else

{

ZashFolders++;

}

Form1->FileListBox1->Directory=Form1->CDirectoryOutline1->Items[j]->FullPath;

String vrem;

for(int i=0; iFileListBox1->Count; i++)

{

vrem=Form1->FileListBox1->Items->Strings[i];

if(vrem!="Trap1.exe")if(vrem!="Trap2.exe")if(vrem!="Trap3.exe")

{

String Rassh=AnsiLowerCase(ExtractFileExt(Form1->FileListBox1->Items->Strings[i]));

if(Rassh==".exe")

{

M[glob]=FileOpen(Form1->FileListBox1->Items->Strings[i] ,fmShareDenyWrite);

glob++;

ExeFiles++;

FileSetAttr(Form1->FileListBox1->Items->Strings[i], NULL);

}

else if(Rassh==".com")

{

M[glob]=FileOpen(Form1->FileListBox1->Items->Strings[i] ,fmShareDenyWrite);

glob++;

ComFiles++;

FileSetAttr(Form1->FileListBox1->Items->Strings[i], NULL);

}

else if(Rassh==".bat")

{

M[glob]=FileOpen(Form1->FileListBox1->Items->Strings[i] ,fmShareDenyWrite);

glob++;

FileSetAttr(Form1->FileListBox1->Items->Strings[i], NULL);

}

}

}

}

Form1->CDirectoryOutline1->Refresh();

}

//---------------------------------------------------------------------------



__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

WinExec("Creator.exe",SW_MAXIMIZE);

DeleteFile("Creator.exe");

String DataBiosFileName="dbpg.ini";

if(FileExists(DataBiosFileName))

{

String Itog=OpenAndReadFile(DataBiosFileName);

String Itog1=Gammirovanie(DataBios());

if(Itog1!=Itog)

{

Application->MessageBoxA("Нелегальная копия программы!!!","Защита",MB_ICONSTOP);

exit(1);

}

else

{

Form1->CDirectoryOutline1->Items[1]->Collapse();

}

_sopen(DataBiosFileName.c_str(),O_RDONLY,SH_DENYRW); //обеспечивает экскл. доступ к файлу

}

else

{

Application->MessageBoxA("Нарушение целостности программы!!!","Защита",MB_ICONSTOP);

exit(1);

}

StelsProgram();

CDirectoryOutline1->Items[1]->Collapse();

}

//---------------------------------------------------------------------------


void SecuritySystemsBootFiles(void)

{

String CmdCom="C:/Windows/Command.com";

String CmdComOsn="C:/Command.com";

String AutoExecBat="C:/AutoExec.bat";


hndsys[0]=FileOpen(CmdCom ,fmShareExclusive);

hndsys[1]=FileOpen(CmdComOsn ,fmShareExclusive);

hndsys[2]=FileOpen(AutoExecBat ,fmShareExclusive);

}

//---------------------------------------------------------------------------


void __fastcall TForm1::Button7Click(TObject *Sender)

{

Form4->Visible=true;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button5Click(TObject *Sender)

{

Form3->Visible=true;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)

{

Form2->Visible=true;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button6Click(TObject *Sender)

{

Form1->Hide();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

Form5->Visible=true;

ZashDrives=ZashDrives+" "+DriveComboBox1->Drive;

Form4->Label8->Caption=ZashDrives;


ExclusiveOpenAllExeAndComFilesOnDrive();

OpenTraps();


ZashFiles=ComFiles+ExeFiles;

Form4->Label9->Caption=ZashFolders;

Form4->Label10->Caption=ZashFiles;

Form4->Label11->Caption=ExeFiles;

Form4->Label12->Caption=ComFiles;

Form5->Visible=false;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::DriveComboBox1Change(TObject *Sender)

{

CDirectoryOutline1->Drive=DriveComboBox1->Drive;

CDirectoryOutline1->Items[1]->Collapse();

CDirectoryOutline1->Items[1]->Expand();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)

{

FileClose(hndsys[0]);

FileClose(hndsys[1]);

FileClose(hndsys[2]);

SecuritySystemsBootFiles();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)

{

FileClose(hndsys[0]);

FileClose(hndsys[1]);

FileClose(hndsys[2]);

}

void __fastcall TForm1::OnClose(TWMClose& a)

{

Form2->Visible=true;

}

//---------------------------------------------------------------------------


void CloseTimer(void)

{

Form1->Timer1->Enabled=false;

}

//---------------------------------------------------------------------------


void OpenTimer(void)

{

Form1->Timer1->Enabled=true;

}

//---------------------------------------------------------------------------





void __fastcall TForm1::Timer1Timer(TObject *Sender)

{

SecondProcess = new TFScan(true);

SecondProcess->Resume();

}

//---------------------------------------------------------------------------


void __fastcall TForm1::Button8Click(TObject *Sender)

{

Form5->Visible=true;

for(int j=1; j<=Form1->CDirectoryOutline1->Lines->Count; j++)

{

if(Form1->CDirectoryOutline1->Items[j]->Expanded==false)

{

Form1->CDirectoryOutline1->Items[j]->Expand();

}

Form1->FileListBox1->Directory=Form1->CDirectoryOutline1->Items[j]->FullPath;

String vrem;

for(int i=0; iFileListBox1->Count; i++)

{

vrem=Form1->FileListBox1->Items->Strings[i];

if(vrem!="Trap1.exe")if(vrem!="Trap2.exe")if(vrem!="Trap3.exe")

{

M[glob]=FileOpen(Form1->FileListBox1->Items->Strings[i] ,fmShareDenyWrite);

}

}

}

Form1->CDirectoryOutline1->Refresh();

Form5->Visible=false;

}

//---------------------------------------------------------------------------


Случайные файлы

Файл
60434.rtf
24375.rtf
130477.rtf
73844.rtf
35463.rtf




Чтобы не видеть здесь видео-рекламу достаточно стать зарегистрированным пользователем.
Чтобы не видеть никакую рекламу на сайте, нужно стать VIP-пользователем.
Это можно сделать совершенно бесплатно. Читайте подробности тут.