📄 main.pas
字号:
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Snoop, StdCtrls;
type
TMainForm = class(TForm)
cbxAdapter: TComboBox;
Snoop1: TSnoop;
btnSend: TButton;
edBuffer: TEdit;
procedure FormCreate(Sender: TObject);
procedure btnSendClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.FormCreate(Sender: TObject);
begin
cbxAdapter.Items := Snoop1.AdapterDescriptions;
end;
procedure TMainForm.btnSendClick(Sender: TObject);
const
MAX_PACKET_SIZE = 1000;
var
i: Integer;
Size: Integer;
Buffer: array[0 .. MAX_PACKET_SIZE - 1] of Char;
BufferStr: String;
Ch: Byte;
begin
if not Snoop1.Active then
begin
Snoop1.AdapterIndex := cbxAdapter.ItemIndex;
Snoop1.Open;
end;
if not Snoop1.Active then
begin
ShowMessage(Snoop1.Error);
exit;
end;
BufferStr := edBuffer.Text;
Size := 0;
while BufferStr <> '' do
begin
i := Pos(' ', BufferStr);
if i = 0 then i := Length(BufferStr) + 1;
Ch := StrToInt('$' + Copy(BufferStr, 1, i - 1));
Buffer[Size] := Chr(Ch);
BufferStr := Copy(BufferStr, i + 1, Length(BufferStr) - i);
inc(Size);
end;
if snoopSendPacket(Snoop1.Pcap, Buffer, Size) = 0 then // if the packet is succesfully sent
ShowMessage('Packet is successfully sent')
else
ShowMessage('Fail to send packet');
Snoop1.Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -