Trouble with WS2_32.DLL

c++ / delphi package - dll injection and api hooking
Post Reply
asterick
Posts: 1
Joined: Wed Apr 21, 2004 1:24 am

Trouble with WS2_32.DLL

Post by asterick »

I managed to get the program injected, and it appears to have attached fine, but any time I attempt to access namelen or *name in my hooked function, it causes a fault and crashes. it says buffer overrun.

Any help anyone could provide would be wonderful, here are the important bits:

Code: Select all

char CapturedData[0x10000];

typedef struct
{
   char ID;
   int Length;
   SOCKET Socket;
   char Name[14];
} CONNECT;

int (*connectNext)( SOCKET s, const struct sockaddr FAR *name, int namelen );
int connectHook( SOCKET s, const struct sockaddr FAR *name, int namelen )
{	
	CONNECT *cData = (CONNECT*)(&CapturedData[CaptureLength += sizeof(CONNECT)]);
	int i;

	cData->ID = SOCKET_CONNECT;
	cData->Length = sizeof(CONNECT);
	cData->Socket = s;
                for(i=0;i<namelen;i++) ; // this crashes

	return connectNext( s, name, namelen ) ;
}

    HookAPI("ws2_32.dll", "connect",	 connectHook,	  (PVOID*) &connectNext);
[/quote]
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

It seems to me that you forgot using the WINAPI calling convention.
Post Reply