Unit CollectThread;

{
  V tomt osouboru se nachazi implementace vlakna,
  ktere neustale sbira zaznamy o systemovych
  volanich od ovladace syscallmon.sys.

  Vlakno jednou za vterinu vyprazdni seznam
  udaju o systemovych volani v ovladaci a pomoci
  metody Synchronize je zobrazi do ovladaciho
  prvku ListView hlavniho formulare aplikace.
}

Interface

Uses
  Classes, MainForm;

Type
  TCollectThread = Class (TThread)
    Private
      FList : TList;
      Function GetRecord(AList:TList):Boolean;
      Procedure SynchronizeWithForm;
    Protected
      Procedure Execute; Override;
    end;

Implementation

Uses
  DriverCommands, Windows;

Function TCollectThread.GetRecord(AList:TList):Boolean;
{
  Odebere jeden zaznam ze seznamu ovladace syscallmon.sys a
  prida jej do interniho seznamu sbiraciho vlakna.
}
Var
  SR : PSYSCALL_RECORD;
  Dummy : DWORD;
begin
SR := HeapAlloc(GetProcessHeap, 0, SizeOf(SYSCALL_RECORD));
Result := SyscallmonDriverGetEvent(SR);
If Result Then
  AList.Add(SR)
Else HeapFree(GetProcessHeap, 0, SR);
end;

Procedure TCollectThread.Execute;
{
  Hlavni smycka sbiraciho vlakna.
}
Var
  Ret : Boolean;
begin
FreeOnTerminate := False;
FList := TList.Create;
While Not Terminated do
  begin
  // Nasbirani vsechn dostupnych udaju o systemovych volani
  Ret := True;
  While Ret Do
    Ret := GetRecord(FList);

  // Zobrazeni
  Synchronize(SynchronizeWithForm);
  // Cekani, nez se naakumuluji dalsi udaje
  Sleep(1000);
  end;

FList.Free;
end;

Procedure TCollectThread.SynchronizeWithForm;
{
  Tato rutina je volana v ramci metody Synchronize
  sbiraciho vlakna. Nejprve prenese aktualne nasbirane
  udaje o systemovych volanich do seznamu ve formulari
   a nasledne jej (formular) donuti tyto udaje vykreslit
   pomoci zvyseni poctu polozek v ovladacim prvku ListView.
}
Var
  I : Integer;
begin
For I := 0 To FList.Count - 1 Do
  Form1.Records.Add(FList[I]);

Form1.ListView1.Items.Count := Form1.Records.Count;
FList.Clear;
end;

End.

