I detoured recv function, i trying to decrypt buffer, but decrypt function change buffer size, and i think decryotion is invalid, code:
int WINAPI OwnRecv(SOCKET s, char FAR *buff, int len, int flags)
{
if(s == GameClientSocket)
{
int received = pTrampolineRecv(s, buff, len, flags);
if(received <= 0)
{
return received;
}
// now strlen(buff) is 2!!
char * plaintext;
plaintext = (char *)aes_decrypt(&Decrypt_Context, (unsigned char*)buff, &received);
(char *) buff = plaintext; // now strlen(buff) is 5!!
return received;
}
return pTrampolineRecv(s, buff, len, flags);
}
What’s wrong with my code?
Thanks!
You forgot to implement a protocol! Whatever protocol you use to encrypt and decrypt the data, you have to actually implement it. It has to define block sizes, padding, and so on. It won’t just work by magic. (Note that using a stream cipher will make this much easier than using a block cipher.)
Also, don’t call
strlenon arbitrary binary data! Thestrlenfunction is only for C-style strings.Also, this line of code doesn’t do what you think it does:
Changing the value of
buff, the variable that holds a pointer to the buffer, has no effect on the contents of the buffer. That’s all the caller cares about.