 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sat May 10, 2008 3:23 am Post subject: [Help] Winsock RECV |
|
|
Im trying to code a packet sniffer, where itll record packet bytes.
This is my code so far :
| Code: |
var
isON : boolean = false;
isOFF : boolean = false;
WSADAT : WSADATA;
iResult, iRet, counter : integer;
SOCK : TSOCKET;
buf2: pchar;
host: Array[0..50] OF char;
buf, newbuf, storedbuf: Array[0..100] Of char;
sHost:string;
hostent: Phostent;
ip, port: ^integer;
ClientService : TSockAddr;
procedure TForm2.Button1Click(Sender: TObject);
begin
if(Length(edit1.text) <= 1) then begin
MessageBox(0, pchar(NO_IP),0,0);
end else
begin
button1.Visible := false;
button2.visible := true;
panel1.caption := 'Starting Winsock';
iResult := WSAStartup(MAKEWORD(2,1), &wsaDat);
if (iResult = NO_ERROR = false) then begin
ShowMessage('WSAStartup failed');
end;
panel1.caption := 'Creating Raw Socket';
Sock := socket(AF_INET, SOCK_RAW, IPPROTO_IP);
if (Sock = INVALID_SOCKET) then begin
ShowMessage('Error at socket()');
WSACleanup();
end;
shost := edit1.text;
hostent := gethostbyname(pchar(shost));
ip := @hostent.h_addr_list^[0];
clientService.sin_family := AF_INET;
clientService.sin_addr.s_addr := ip^;
clientService.sin_port := htons(6000);
bind(sock, &ClientService, sizeof(clientService));
iResult := connect(Sock, &clientService,(sizeof(clientService)));
if (iResult = SOCKET_ERROR) then begin
closesocket (Sock);
ShowMessage('Unable to connect to server');
WSACleanup();
end else
Panel1.caption := 'Socket Made, Sniffing.';
Timer1.enabled := true;
end;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
button1.Visible := true;
button2.visible := false;
Timer1.enabled := false;
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
FILLCHAR(Buf, 0, sizeof(Buf));
iRet := recv(Sock, buf, sizeof(buf), 0);
if(iRet = ERROR) then begin
ShowMessage('Error with Recv Winsock API!');
end else begin
if(counter = 1) then begin
if(sizeof(buf) = sizeof(storedbuf) = false) then begin
counter := 0;
end else
begin
end;
end;
if(counter = 0) then begin
storedbuf := buf;
showmessage(inttostr(sizeof(buf)) + '-' + buf);
//Treeview1.items.add(nil, inttostr(sizeof(buf)));
counter := 1;
end; |
My problem is, everything goes smooth, up until recv, then my program just freezes and doesn't respond. Can anyone help?
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Sat May 10, 2008 4:12 am Post subject: |
|
|
I tried the same thing, but my program didn't get further than bind....
As for the freezing... maybe it's just waiting for a packet? Probably it won't return until it has received a packet.
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sat May 10, 2008 9:59 am Post subject: |
|
|
| no, it's not that. There's an error, but I don't know what's wrong. All i know is that it freezes when my program calls recv
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Sat May 10, 2008 1:00 pm Post subject: |
|
|
| What about debugging it?(with OllyDbg) That's what I always do...
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sat May 10, 2008 1:33 pm Post subject: |
|
|
| I don't need to debug it, it's just the code. -_-
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|