In that intercepted function below, I have buff as a pointer to buffer, how can I change data without creating new my own buffer?
int WINAPI OwnRecv(SOCKET s, char FAR *buff, int len, int flags)
{
if(s == ServerSocket)
{
int received = pTrampolineRecv(s, buff, len, flags);
if(received <= 0)
{
return received;
}
unsigned char ReceiveBuffer[1024]; // how can i avoid creatin this by changing buff directly?
do_decrypt((const unsigned char *) buff, ReceiveBuffer, received, KeyTest, NULL);
buff = (char *) ReceiveBuffer;
return received;
}
return pTrampolineRecv(s, buff, len, flags);
}
upd
I added my do_decrypt function
bool do_decrypt(const unsigned char *in, unsigned char *out, int inlen)
{
int buflen, tmplen;
if(!EVP_DecryptUpdate(&Decrypt_ctx, out, &buflen, in, inlen))
{
return false;
}
if(!EVP_DecryptFinal_ex(&Decrypt_ctx, out + buflen, &tmplen))
{
return false;
}
return true;
}
You should definitely take a look at C++ tutorial about pointers before jumping straight on WinAPI code.
Also, FAR keyword is deprecated.
The simplest idea would be
So basically – putting
buffas both input and output variable.But I DO NOT recommend using it, as I don’t know how
do_decryptfunction works – you might end messing up your own data when decrypting. Only use above if do_decrypt is using some sort of (possibly smaller) internal buffer.Maybe try to clarify the question a bit more, as now I won’t be able to give you any more advice on the question.
EDIT: So, thanks to other answers, you can use solution above when:
do_decryptfunction allows in situ operation – thus, modyfing data that’s being read.