Quote:
PHP Code:
/***********************************
Credits to .....?! I don't know o.O
************************************/
int ASyncPos = 0;
int FinalSize = 0;
int WINAPI FilterRecv(SOCKET Socket,char *Buffer, int iLength, int iFlags)
{
if (ASyncPos==FinalSize && FinalSize>0)
{
MyRecv(Buffer, ASyncPos);
ASyncPos = 0;
}
int RecvRET = DetourRecv(Socket, Buffer, iLength, iFlags);
if (RecvRET<0)
{
return RecvRET;
}
if (ASyncPos==0)
FinalSize = *((short int*) Buffer);
ASyncPos+=RecvRET;
return RecvRET;
}
|
That would be my "MagicRecv" :P
About receive:
Received packets are encrypted. Server sends data size first, then a packet with the data then an unknown packet (sometimes more).
int RecvRET = DetourRecv(Socket, Buffer, iLength, iFlags);
RecvRET returns < 0 (I believe -1) for the unknown packets.
Luckily for most people here, the decrypted packet is stored in the same memory as the encrypted packet (Encrypted data gets replaced by decrypted data).
My MagicRecv waits for the unknown packet to be received before the buffer gets analysed. This gives the kal client enough time to decrypt the received packet.
This way you get a small delay in packet handling, but... imho, it is the next best solution after decrypting the packet yourself :)
btw..
My original release of the code was:
PHP Code:
int ASyncPos=0;
int FinalSize=0;
int WINAPI __stdcall MyMagicRecv(SOCKET s, const unsigned char* buf, int len, int flags)
{
if (ASyncPos==FinalSize && FinalSize>0)
{
HandlePacket(buf, ASyncPos);
ASyncPos = 0;
}
int ret = OrigRecv(s,buf,len,flags);
if (ret<0)
{
return ret;
}
if (ASyncPos==0)
FinalSize = *((short int*) buf);
ASyncPos+=ret;
return ret;
}
[Only registered and activated users can see links. Click Here To Register...]