📄 u_debugpacket.pas
字号:
(*
* One Way Network Sniffer (OWNS)
* Copyright (C) 2001-2002 OWNS
*
* http://owns.sourceforge.net/
* http://www.owns.st
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)
unit u_DebugPacket;
interface
uses classes, SysUtils, u_EthernetFrame, u_TCPPacket,u_IPPacket;
type
TDebugPacket = class
private
FFileName : String;
FFileStream : TFileStream;
public
procedure writeString(p_String : String);
procedure debugPacket(p_Packet : TEthernetFrame;p_MomentReception : Cardinal);
procedure writeData(p_String : String; p_Data : PChar; p_DataLength : Integer);
constructor Create(p_FileName : String);
destructor destroy; override;
end;
var
g_DebugPacket : TDebugPacket;
implementation
constructor TDebugPacket.Create(p_FileName : string);
begin
FFileName := p_FileName;
// fmCreate : Create a file with the given name. If a file with the given name exists, open the file in write mode.
FFilestream := TFileStream.create(FFileName,fmCreate);
FFileStream.Seek(0,soFromEnd);
end;
destructor TDebugPacket.destroy;
begin
FFileStream.free;
inherited;
end;
// 閏rit une chaine dans le fichier
procedure TDebugPacket.writeString(p_String : String);
var l_String : String;
begin
l_String := p_String + #13 + #10;
FFileStream.write(PChar(l_String)^,length(l_String));
end;
// 閏rit des donn閑s dans le fichier pr閏閐閑s par un message et la date
procedure TDebugPacket.writeData(p_String : String; p_Data : PChar; p_DataLength : Integer);
begin
writeString('');
writeString(DateTimeToStr(Now) + '-' + p_String);
FFileStream.write(p_Data^,p_DataLength);
writeString('');
writeString('*******************************************');
end;
// 閏rit le debug du packet
procedure TDebugPacket.debugPacket(p_Packet : TEthernetFrame;p_MomentReception : Cardinal);
var
l_IPPacket : TIPPacket;
l_TCPPacket : TTCPPacket;
begin
writeString('');
writeString('Moment recept : '+IntToStr(p_MomentReception));
if (p_Packet is TTCPPacket) then
begin
l_TCPPacket := p_Packet as TTCPPacket;
writestring('TCP');
writestring('src : ' + IPToStr(l_TCPPacket.IPSourceAddr)+':'+IntToSTr(l_TCPPacket.TCPSourcePort));
writestring('dest : ' + IPToStr(l_TCPPacket.IPDestAddr)+':'+IntToSTr(l_TCPPacket.TCPDestPort));
writeString('flag : ' + TCPFlagToStr(l_TCPPacket.TCPFlag));
writeString('seq : ' + IntToSTr(l_TCPPacket.TCPSeqNum));
writeString('taille : ' + IntToSTr(l_TCPPacket.TCPDataLength));
FFileStream.write(l_TCPPacket.TCPData^,l_TCPPacket.TCPDataLength);
end
else
if (p_Packet is TIPPacket) then
begin
l_IPPacket := p_Packet as TIPPacket;
writestring('IP');
writestring('src : ' + IPToStr(l_IPPacket.IPSourceAddr));
writestring('dest : ' + IPToStr(l_IPPacket.IPDestAddr));
FFileStream.write(l_IPPacket.IPData^,l_IPPacket.IPDataLength);
end;
writeString('');
writeString('*******************************************');
end;
initialization
g_DebugPacket := TDebugPacket.create('debug.bug');
finalization
g_DebugPacket.free;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -