How I can get the Winsock2 WSASend()
Buffer into a string?
This is the code I currently have, and it write only a lot of I
characters.
int WINAPI Hook_WSASend(SOCKET a0, LPWSABUF a1, DWORD a2, LPDWORD a3, DWORD a4, LPWSAOVERLAPPED a5, LPWSAOVERLAPPED_COMPLETION_ROUTINE a6)
{
int rv = 0;
char * buf = "";
WSABUF * wb = a1;
for(int i = 0; i == a2; i++){
strcpy_s(buf, wb[i].len, wb[i].buf);
}
fopen_s(&pWSASendLogFile, "C:\\WSASendLog.txt", "a+");
fprintf(pWSASendLogFile, "%s\n", buf);
fclose(pWSASendLogFile);
rv = Real_WSASend(a0,a1,a2,a3,a4,a5,a6);
return rv;
}
As Remy Lebeau asked, I'm adding more info on what i need to achieve.
I need to have the buffer inside a string because:
I have to search for a specific string inside the buffer, specifically before doing anything the string must start with
<TalkMsg
.Then, i have to send the buffer trough a NamedPipe, i already have my functions handling that.
Just to Explain better what i'm doing, this is the code i currently have for the Winsock send()
. I have to do the same thing with WSASend()
.
int WINAPI Hook_Send(SOCKET s, const char* buf, int len, int flags)
{
/*
fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
fprintf(pSendLogFile, "%s\n", buf);
fclose(pSendLogFile);
*/
curSocket = s;
if(Filtering){
PipeHeader ph;
string p(buf);
if(p.find("<TalkMsg") == 0){
ph.command = 5;
ph.sockid = s;
ph.datasize = len;
if(SendPipeHeader((char*)&ph, sizeof(ph))){
if(SendPipeData(buf, len)){
return len;
}
}
}
}
return Real_Send(s, buf, len, flags);
}