1.å¦ä½å¨delphiä¸ä½¿ç¨winpcapçä¾å
å¦ä½å¨delphiä¸ä½¿ç¨winpcapçä¾å
è®°å¾å½åè½å¤å¼å§å.1xç港湾ç»éå¨çº¯ç²¹æ¯å 为loserèªå·±æ¹å¥½äºpcap.pas,源码mysql gtid 源码æ以ææè½ç»§ç»çæpcapç代ç åä¸å»ãæè¿ç»§ç»ç 究delphiåwinpcapæ¯å 为ç°å¨radå¹³å°æ¯åçè¶æ¥è¶æ¼äº®äºï¼å ¶å®ç¨delphiçæ§ä»¶ççæ¥åæ们ççé¢ï¼èç¨vcæ¥åæ们ç主è¦åè½æ¨¡åä¸å¤±ä¸ºä¸ä¸ªå¥½çåæ³ã
ä½æ¯è½ç¶delphiç®åå¿«éï¼å¯æ¯æè¿æ¯è´¹äºä¸å°æ¶é´çï¼å¨vcä¸ä½ å¾å°å»å¤çé误类ï¼èå¨delphiä¸try expect è¿äºé误æè·ç代ç å¾å¤å¾å¤ï¼ä»ç®åçç解æ¥çï¼æ认为æ¯æéçå¤æ¬¡éæ¾ï¼æè éæ¯å¯¹è±¡çå¤æ¬¡éæ¯èå¼èµ·çï¼ä½æ¯ä¸ç®¡æä¹è¯´ï¼åæ¥æåäºè¿ä¸ªç»éå¨çæ¶åï¼ä»è¿æ¯ä¸ç¨³å®çï¼æ以è½ç¶å¼èµ·è½°å¨ï¼ä½æ¯å¾å¿«å°±æ²¡äºï¼æåä¸å¾å·²è转åvcå¼åã
winpcapçå 个å½æ°ç¸ä¿¡ä½ å·²ç»ç¥éäºï¼pcap.paså¨æçå客ä¸ä¹æ¾çå°ä»£ç ï¼é£ä¹å©ä¸çå°±èªå·±ççå¦å¦å§ï¼
procedure recvThread(myconfig:pconfigini);stdcall;
const
cStartPacket:array[0..] of Byte=($, $, $c2, $, $, $,
$ff, $ff, $ff, $ff, $ff, $ff,
$, $8e, $, $, $, $,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5);
cuserPacket :array[0..] of Byte = ($, $, $c2, $, $, $,
$ff, $ff, $ff, $ff, $ff, $ff,
$, $8e, $, $, $, $ff,
$, $, $, $ff, $, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5);
cResponseMD5 :array[0..] of Byte = ($, $, $c2, $, $, $,
$ff, $ff, $ff, $ff, $ff, $ff,
$, $8e, $, $, $, $ff,
$, $, $, $ff, $, $,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5);
cLogoffPacket :array[0..] of Byte = ($, $, $c2, $, $, $,
$ff, $ff, $ff, $ff, $ff, $ff,
$, $8e, $, $, $, $,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5, $a5, $a5,
$a5, $a5, $a5, $a5);
var
outnetbyte,innetbyte:int;
StartPacket,userPacket,ResponseMD5,LogoffPacket:array[0..] of Byte;
szMd5Buffer: Md5Buffer;
nLen: Integer;
md5Ctx: MD5Context;
md5Dig: MD5Digest;
mmcount:string;
pcap:ppcap;
mac:TMacAddr;//ç©çç½å¡å°å
user:string;
ErrStr:string;
errbuf:array[0..PCAP_ERRBUF_SIZE] of Char;
userlength,i:integer;
buftoint : array[0..3] of byte;
bufint:integer;
headlen2:integer;
pRecvBuf :array of Byte;
pRecvHeaderBuf :ppcap_pkthdr;
q_MD5Source:array[0..] of byte;
f:TextFile;
textstring:string;
begin
assignfile(f,'test.txt');
for i:=0 to do
begin
StartPacket[i]:=cStartPacket[i];
userPacket[i]:=cuserPacket[i];
ResponseMD5[i]:=cResponseMD5[i];
LogoffPacket[i]:=cLogoffPacket[i];
end;
buftoint[2]:=0;
buftoint[3]:=0;
try
pcap := pcap_open_live(PChar(myconfig^.ethname),
, PCAP_OPENFLAG_PROMISCUOUS, 1, errbuf);
except
showmessage('æå¼ç½å¡å¤±è´¥');
isloop:=false;
exit;
end;
// end;
if pcap<>nil then
begin
mac:=Pcap_GetMacAddress (Pcap, ErrStr) ;
end;
//å¡«åmacå°å
for i:=0 to 5 do
begin
StartPacket[i+6] := mac[i];
userPacket[i+6] := mac[i];
ResponseMD5[i+6] := mac[i];
LogoffPacket[i+6] := mac[i];
end;
//å¡«åè´¦å·
user:=myconfig^.username;
userlength:=5+length(user);
userPacket[]:=byte(userlength);
userPacket[]:=byte(userlength);
for i:= to length(user)+ do
begin
userpacket[i] := Str_HexToInt(InttoHex( ord(user[i-]) ,2));
end;
//åéå¼å§è®¤è¯å
pcap_sendpacket(pcap, @StartPacket, SizeOf(StartPacket)) ;
mmcount:=formatdatetime('ss',now());
while isloop=true do
begin
//
if (formatdatetime('ss',now()) <>mmcount) then
begin
try
PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 4, outnetbyte);
PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 5, innetbyte);
except
showmessage('å线ç¨åéæµéæ°æ®åºé');
end;
mmcount:=formatdatetime('ss',now());
end;
//å¼å§æå
try
i:= pcap_next_ex(pcap, @pRecvHeaderBuf, @pRecvBuf);
except
showmessage('æå å½æ°åºé');
end;
if( i>0 ) then
begin
if (pRecvBuf[] = $) and (pRecvBuf[] = $8e) then
begin
case precvbuf[] of
$:
begin
if (pRecvBuf[] = $) then //Request Identity
begin
//form1.Lab_login_state.Caption:='åéè´¦å·å ';
try
pcap_sendpacket(pcap, @userpacket, SizeOf(userpacket)) ;
except
showmessage('åéè´¦å·å åºé');
end;
end
else
begin
for i:=0 to do
begin
q_MD5Source[i] := pRecvBuf[i + ];
end;
PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 0, 0);
szMd5Buffer[0] := $;
nLen := 1;
CopyMemory(@szMd5Buffer[nLen], PChar(Trim(myconfig^.userpass)), Length(Trim(myconfig^.userpass))); // ç¨æ·å¯ç
nLen := nLen + Length(Trim(myconfig^.userpass));
CopyMemory(@szMd5Buffer[nLen], @q_MD5Source, ); // æå¡å¨è¿åå¯é¥
nLen := nLen + ;
for i:=0 to nlen-1 do
begin
textstring:=textstring+inttohex(szMd5Buffer[i],2)+' ';
end;
textstring:=textstring+##;
MD5Init(md5Ctx);
MD5Update(md5Ctx, @szMd5Buffer, nLen);
MD5Final(md5Ctx, md5Dig);
for i:= to do
begin
ResponseMD5[i] := md5dig[i-];
textstring:=textstring+inttohex(md5dig[i-],2)+' ';
end;
textstring:=textstring+##;
rewrite(f);
writeln(f,textstring);
responsemd5[]:=byte(length(myconfig^.username)+);
responsemd5[]:=byte(length(myconfig^.username)+);
for i:= to length(user)+ do
begin
ResponseMD5[i] := Str_HexToInt(InttoHex( ord(user[i-]) ,2));
end;
pcap_sendpacket(pcap, @ResponseMD5, SizeOf(ResponseMD5)) ;
end;
end;
$:
begin
PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 1, 0);
end;
$:
begin
PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 3, 0);
isloop:=false;
end;
end;
end;
if (pRecvBuf[] = $) and (pRecvBuf[] = $) then
begin
if (pRecvBuf[] = $) then //tcpå
begin
try
buftoint[0]:= pRecvBuf[];
buftoint[1]:= pRecvBuf[];
Bufint := integer(buftoint);
except
showmessage('tcpåè转åé误');
end;
headlen2:=;
case pRecvBuf[] of
$:headlen2:=;
$:headlen2:=;
$:headlen2:=;
$:headlen2:=;
$:headlen2:=;
$a0:headlen2:=;
$b0:headlen2:=;
$c0:headlen2:=;
end;
//if totalbyte< then totalbyte:=totalbyte+abuf^ - -headlen2;
if ((pRecvBuf[] = $c0) or (pRecvBuf[] = $ac) ) and ((pRecvBuf[] = $c0) or (pRecvBuf[] = $ac) ) then
begin
try
innetbyte:=innetbyte+ bufint - -headlen2;
except
showmessage('tcp计ç®åºéin');
end;
end
else
begin
try
outnetbyte:=outnetbyte+ bufint - -headlen2;
except
showmessage('tcp计ç®åºéout');
end;
end;
//if (pRecvBuf[] = $c0) and ( pRecvBuf[] <> $c0 ) and (pRecvBuf[] <> $ac) then outnetbyte:=outnetbyte+ abuf^ - -headlen2;
//if (pRecvBuf[] = $c0) and ( pRecvBuf[] <> $c0 ) and (pRecvBuf[] <> $ac) then outnetbyte:=outnetbyte+ abuf^ - -headlen2;
//if (pRecvBuf[] = $ac) and ( pRecvBuf[] <> $c0 ) and (pRecvBuf[] <> $ac) then outnetbyte:=outnetbyte+ abuf^ - -headlen2;
//if (pRecvBuf[] = $ac) and ( pRecvBuf[] <> $c0 ) and (pRecvBuf[] <> $ac) then outnetbyte:=outnetbyte+ abuf^ - -headlen2;
end;
if (pRecvBuf[] = $) then //udpå
begin
try
buftoint[0]:= pRecvBuf[];
buftoint[1]:= pRecvBuf[];
Bufint := integer(buftoint);
except
showmessage('udpåè转åé误');
end;
if ((pRecvBuf[] = $c0) or (pRecvBuf[] = $ac) ) and ((pRecvBuf[] = $c0) or (pRecvBuf[] = $ac) ) then
begin
try
innetbyte:=innetbyte+ bufint - ;
except
showmessage('udp计ç®åºéin');
end;
end
else
begin
try
outnetbyte:=outnetbyte+ bufint - ;
except
showmessage('udp计ç®åºéout');
end;
end;
end;
end;
end;
end;
pcap_sendpacket(pcap, @LogoffPacket, SizeOf(LogoffPacket)) ;
end;
转载