📄 dataanylist.pas
字号:
unit DataAnylist;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cap_ip, Grids, ExtCtrls, StdCtrls, JvComponent, JvTransBtn,
JvComCtrls, DB, DBClient;
type
Tmy_data=record
buf:array of char;
end;
TDatany_f = class(TForm)
Panel1: TPanel;
grdDataList: TStringGrid;
Memo1: TMemo;
Memo2: TMemo;
btnStart: TJvTransparentButton;
btnStop: TJvTransparentButton;
btnPause: TJvTransparentButton;
Label1: TLabel;
edtAddr1: TJvIpAddress;
Label2: TLabel;
edtAddr2: TJvIpAddress;
Label3: TLabel;
edtPort1: TEdit;
Label4: TLabel;
edtPort2: TEdit;
Label5: TLabel;
cbbProtocol: TComboBox;
cdCapture: TClientDataSet;
OpenDialog1: TOpenDialog;
cdCapturecfProtocol: TStringField;
cdCapturecfSourceAddr: TStringField;
cdCapturecfSourcePort: TStringField;
cdCapturecfDestAddr: TStringField;
cdCapturecfDestPort: TStringField;
cdCapturecfDataSize: TIntegerField;
cdCapturecfData: TBlobField;
procedure grdDataListDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure cap_ip1Cap(ip, proto, sourceIP, destIP, SourcePort,
DestPort: String; header: PAnsiChar; header_size: Integer;
data: PAnsiChar; data_size: Integer);
procedure btnStartClick(Sender: TObject);
procedure grdDataListClick(Sender: TObject);
private
{ Private declarations }
public
buf_list:array of Tmy_data;
function checkFilter(proto, sourceIP, destIP, SourcePort,DestPort: String):Boolean;
{ Public declarations }
end;
var
Datany_f: TDatany_f;
implementation
{$R *.dfm}
procedure TDatany_f.grdDataListDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
i: integer;
begin
with grdDataList.Canvas do
begin
if ARow = 0 then
begin
Brush.Color := rgb(128, 128, 128);
FillRect(Rect);
Pen.Color := rgb(0, 0, 0);
for i := 0 to ((Rect.Bottom - Rect.Top) div 3) do
begin
MoveTo(Rect.Left, i * 3 + Rect.Top);
LineTo(Rect.Right, i * 3 + Rect.Top);
end;
Brush.Style := bsclear;
Font.Color := rgb(0, 0, 0);
TextOut(Rect.Left + 3, Rect.Top + 3, grdDataList.Cells[ACol, ARow]);
Font.Color := rgb(255, 255, 255);
TextOut(Rect.Left + 2, Rect.Top + 2, grdDataList.Cells[ACol, ARow]);
Brush.Style := bssolid;
end
else
begin
Brush.Style := bsSolid;
Brush.Color := RGB(0, 0, 0);
FillRect(rect);
if grdDataList.Cells[4, ARow] <> '脱机' then
Font.Color := clLime
else
Font.Color := clred;
TextOut(Rect.Left + 3, Rect.Top + 3, grdDataList.Cells[ACol, ARow]);
end;
end;
end;
procedure TDatany_f.FormCreate(Sender: TObject);
begin
grdDataList.Cells[0,0]:='Protocol';
grdDataList.Cells[1,0]:='Source Addr';
grdDataList.Cells[2,0]:='Source Port';
grdDataList.Cells[3,0]:='Dest Addr';
grdDataList.Cells[4,0]:='Dest Port';
grdDataList.Cells[5,0]:='Data Size';
grdDataList.Cells[6,0]:='Data';
end;
procedure TDatany_f.cap_ip1Cap(ip, proto, sourceIP, destIP,
SourcePort, DestPort: String; header: PAnsiChar; header_size: Integer;
data: PAnsiChar; data_size: Integer);
begin
if checkFilter(proto,sourceIP,destIP,SourcePort,DestPort) then
exit;
with grdDataList do
begin
Cells[0,grdDataList.RowCount-1]:=proto;
Cells[1,grdDataList.RowCount-1]:=sourceIP;
Cells[2,grdDataList.RowCount-1]:=SourcePort;
Cells[3,grdDataList.RowCount-1]:=destIP;
Cells[4,grdDataList.RowCount-1]:=DestPort;
Cells[5,grdDataList.RowCount-1]:=inttostr(data_size);
Cells[6,grdDataList.RowCount-1]:=data;
end;
setlength(buf_list[grdDataList.RowCount-2].buf,data_size);
copymemory(buf_list[grdDataList.RowCount-2].buf,data,data_size);
grdDataList.toprow:=grdDataList.RowCount- grdDataList.VisibleRowCount;
grdDataList.RowCount:=grdDataList.RowCount+1;
grdDataList.Rows[grdDataList.RowCount].Clear;
end;
procedure TDatany_f.btnStartClick(Sender: TObject);
var
I: Integer;
lbuf:pchar;
lStream:TMemoryStream;
begin
if OpenDialog1.Execute then
begin
cdCapture.LoadFromFile(OpenDialog1.FileName);
cdCapture.Active:=true;
grdDataList.RowCount:=2;
grdDataList.Rows[grdDataList.RowCount].Clear;
setlength(buf_list,cdCapture.RecordCount);
for I := 0 to cdCapture.RecordCount - 1 do // Iterate
begin
lStream:=TMemoryStream.Create;
cdCapturecfData.SaveToStream(lStream);
lStream.Position:=0;
if lStream.Size<>0 then
begin
GetMem(lbuf,lStream.size);
lStream.Read(lbuf^,lStream.Size);
end
else
begin
GetMem(lbuf,1);
lbuf^:=' ';
end;
cap_ip1Cap('',cdCapture.Fields.Fields[0].Asstring,cdCapture.Fields.Fields[1].Asstring,cdCapture.Fields.Fields[2].Asstring,cdCapture.Fields.Fields[3].Asstring,cdCapture.Fields.Fields[4].Asstring,'',0,lBuf,cdCapture.Fields.Fields[5].AsInteger);
if lStream.Size=0 then
FreeMem(lBuf,1)
else
FreeMem(lbuf,cdCapturecfDataSize.AsInteger);
lStream.Free;
cdCapture.Next;
end; // for
end;
end;
procedure TDatany_f.grdDataListClick(Sender: TObject);
var text_str,hex_str,all_str:string;
i:integer;
no: Integer;
begin
memo1.lines.Clear;
memo2.lines.Clear;
text_str:='';hex_str:='';all_str:='';
i:=0;
while i<= high(buf_list[grdDataList.Selection.Top-1].buf) do
begin
no:=ord(buf_list[grdDataList.Selection.Top-1].buf[i]);
hex_str:=hex_str+format('%0.2x',[no])+' ';
if no<20 then
begin
text_str:=text_str+'.';
all_str:=all_str+'.';
end else
begin
text_str:=text_str+buf_list[grdDataList.Selection.Top-1].buf[i];
all_str:=all_str+buf_list[grdDataList.Selection.Top-1].buf[i];
end;
if ((i mod 8)=7) then
begin
memo1.lines.add(hex_str+' | '+text_str);
text_str:='';hex_str:='';
end;
inc(i);
end;
if hex_str<>'' then
memo1.lines.add(hex_str+format('%'+inttostr(24-length(hex_str))+'s',[' '])+' | '+text_str);
memo2.lines.Add(all_str);
end;
function TDatany_f.checkFilter(proto, sourceIP, destIP, SourcePort,
DestPort: String): Boolean;
var
lUsed:Byte;
begin
Result:=true;
if (trim(cbbProtocol.Text)='') and (EdtAddr1.Text='0.0.0.0') and (EdtAddr2.Text='0.0.0.0') and
(StrToIntDef(edtPort1.Text,0)=0) and (StrToIntDef(EdtPort2.Text,0)=0) then
begin
Result:=false;
exit;
end;
if trim(cbbProtocol.Text)<>'' then
if Proto<>cbbProtocol.Text then
exit;
lUsed:=0;
if edtaddr1.Text<>'0.0.0.0' then
lUsed:=lUsed or 1;
if StrToIntDef(EdtPort1.Text,0)<>0 then
lUsed:=lUsed or 2;
if edtAddr2.Text<>'0.0.0.0' then
lUsed:=lused or 4;
if StrtoIntDef(EdtPort2.Text,0)<>0 then
lUsed:=lused or 8;
case lUsed of //
1:
if (sourceIP<>edtAddr1.Text) and (destIP<>edtAddr1.Text) then
exit;
2:
if (SourcePort<>edtPort1.Text) and (DestPort<>edtPort1.Text) then
exit;
3:
if not (((sourceIP=edtAddr1.Text) and (SourcePort=edtPort1.Text)) or ((destIP=edtAddr1.Text) and (DestPort=edtPort1.Text))) then
exit;
4:
if (sourceIP<>edtAddr2.Text) and (destIP<>edtAddr2.Text) then
exit;
5:
if not (((sourceIP=edtAddr1.Text) and (destIP=edtAddr2.Text)) or ((sourceIP=edtAddr2.Text) and (destIP=edtAddr1.Text))) then
exit;
6:
if not (((SourcePort=EdtPort1.Text) and (DestIP=EdtAddr2.Text)) or ((DestPort=EdtPort1.Text) and (SourceIP=edtAddr2.Text))) then
exit;
7:
if not (((SourceIP=EdtAddr1.Text) and (SourcePort=EdtPort1.Text) and (DestIP=edtAddr2.Text)) or
((DestIP=EdtAddr1.Text) and (DestPort=EdtPort1.Text) and (SourceIP=EdtAddr2.Text))) then
exit;
8:
if (SourcePort<>edtPort2.Text) and (DestPort<>edtPort2.Text) then
exit;
9:
if not (((SourcePort=EdtPort2.Text) and (DestIP=EdtAddr1.Text)) or ((DestPort=EdtPort2.Text) and (SourceIP=edtAddr1.Text))) then
exit;
10:
if not (((SourcePort=EdtPort1.Text) and (DestPort=EdtPort2.Text)) or ((DestPort=EdtPort1.Text) and (SourcePort=EdtPort2.Text))) then
exit;
11:
if not (((SourceIP=EdtAddr1.Text) and (SourcePort=EdtPort1.Text) and (DestPort=edtPort2.Text)) or
((DestIP=EdtAddr1.Text) and (DestPort=EdtPort1.Text) and (SourcePort=EdtPort2.Text))) then
exit;
12:
if not (((sourceIP=edtAddr2.Text) and (SourcePort=edtPort2.Text)) or ((destIP=edtAddr2.Text) and (DestPort=edtPort2.Text))) then
exit;
13:
if not (((SourceIP=EdtAddr2.Text) and (SourcePort=EdtPort2.Text) and (DestIP=edtAddr1.Text)) or
((DestIP=EdtAddr2.Text) and (DestPort=EdtPort2.Text) and (SourceIP=EdtAddr1.Text))) then
exit;
14:
if not (((SourceIP=EdtAddr2.Text) and (SourcePort=EdtPort2.Text) and (DestPort=edtPort1.Text)) or
((DestIP=EdtAddr2.Text) and (DestPort=EdtPort2.Text) and (SourcePort=EdtPort1.Text))) then
exit;
15:
if not (((SourceIP=EdtAddr1.Text) and (SourcePort=EdtPort1.Text) and (DestIP=EdtAddr2.Text) and (DestPort=EdtPort2.Text)) or
((SourceIP=EdtAddr2.Text) and (SourcePort=EdtPort2.Text) and (destIP=EdtAddr1.Text) and (DestPort=EdtPort1.Text))) then
exit;
end; // case
Result:=false;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -