Помогите написать комментарии, в общем программа должна находить вирус в файлах, в архиве exampvir предоставлены 5 этих вирусов, в файле base база сигнатур
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, XPMan, StdCtrls, Buttons, ShellApi, ComCtrls, ExtCtrls, Grids;
type
TForm1 = class(TForm)
SButton2: TSpeedButton;
ODialog1: TOpenDialog;
XPManifest1: TXPManifest;
GroupBox1: TGroupBox;
ListBox2: TListBox;
SpeedButton1: TSpeedButton;
Label2: TLabel;
Label6: TLabel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
SBar1: TStatusBar;
SGrid1: TStringGrid;
pnl1: TPanel;
pnl2: TPanel;
pnl3: TPanel;
procedure SpeedButton1Click(Sender: TObject);
procedure SButton2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
Function ScanFile : Word;
public
{ Public declarations }
end;
Type
arr = array[1..20] of Byte;
arrptr = ^arr;
var
Form1: TForm1;
PrPath : String;
KolVirInBaze : Integer;
TF : File;
implementation
{$R *.dfm}
Function TForm1.ScanFile : Word;
Var ItF, Naid : Word;
F : TFileStream;
Buf, VirBuf : Arrptr;
I, T, J : Integer;
S : String;
PASS : Byte;
Error : Boolean;
begin
For ItF := 0 to ListBox2.Items.Count - 1 do
Begin
{$I-}
AssignFile(TF, PrPath+'base.vidb');
Reset(TF, 1);
{$I+}
If IOResult <> 0 then
Begin
SButton2.Enabled := True;
ShowMessage('Файл '+PrPath+'base.vidb'+' не найден.');
Exit
end;
New(VirBuf);
New(Buf);
T := 0;
Error := False;
Try
F := TFileStream.Create(ListBox2.Items[ItF], fmOpenRead);
except
Error := True;
end;
If Error = False then
begin
If F.Size > 90 then
Begin
For PASS := 1 to 4 do
Begin
Label2.Caption := ListBox2.Items[ItF];
Application.ProcessMessages;
If PASS = 1 then F.Seek(135, 0);
If PASS = 2 then F.Seek(2000, 0);
If PASS = 3 then F.Seek(7000, 0);
If PASS = 4 then F.Seek(10000, 0);
Try
F.ReadBuffer(Buf^, SizeOf(Buf^));
except
Error := True
end;
If Error = False then
Begin
For J := 1 to KolVirInBaze do
Begin
If J = 1 then Seek(TF, 0) else Seek(TF, J*2 * 10-20);
BlockRead(TF, VirBuf^, SizeOf(VirBuf^));
For I := 1 to 20 do If VirBuf^[I] = Buf^[I] then Inc(T) else T := 0;
If T = 20 then
Begin
S := '';
Case J of
1 : S := 'Worm.Win32.DipNet.f';
2 : S := 'Trojan.Win32.PdPinch.f';
3 : S := 'Trojan.DownLoader.1746';
4 : S := 'Trojan.Pinch';
5 : S := 'BackDoor.Haxdoor';
end;
Inc(Naid);
If Naid <= 4 then
Begin
SGrid1.Cells[0,Naid] := ExtractFileName(ListBox2.Items[ItF]);
SGrid1.Cells[1,Naid] := ExtractFilePath(ListBox2.Items[ItF]);
SGrid1.Cells[2,Naid] := S;
end
else
begin
SGrid1.RowCount := Naid+1;
SGrid1.Cells[0,Naid] := ExtractFileName(ListBox2.Items[ItF]);
SGrid1.Cells[1,Naid] := ExtractFilePath(ListBox2.Items[ItF]);
SGrid1.Cells[2,Naid] := S;
end;
end;
end;
end; //Error = True - Маленький размер
end;
end;
Dispose(VirBuf);
Dispose(Buf);
CloseFile(TF);
F.Free;
Label2.Caption := '';
end;
end;
SButton2.Enabled := True;
SBar1.Panels[1].Text := IntToStr(Naid);
SBar1.Panels[2].Text := IntToStr(ListBox2.Items.Count)
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
If ODialog1.Execute then ListBox2.Items := ODialog1.Files
end;
procedure TForm1.SButton2Click(Sender: TObject);
begin
If ListBox2.Items.Count <> 0 then
Begin
SButton2.Enabled := False;
ScanFile
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PrPath := ExtractFilePath(Application.EXEName);
{$I-}
AssignFile(TF, PrPath+'base.vidb');
Reset(TF, 1);
{$I+}
If IOResult <> 0 then
Begin
SButton2.Enabled := True;
ShowMessage('Файл '+PrPath+'base.vidb'+' не найден.');
Exit
end
else
Begin
KolVirInBaze := Trunc(FileSize(TF)/20);
SBar1.Panels[0].Text := 'В базе: '+IntToStr(KolVirInBaze)
end;
end;
end.