Solved Receiving nothing when hooking

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

iVision

Newbie
Jun 10, 2012
17
252
0
Hey, I followed the tutorial from hooking. But there is problem, only the send hook does it thing. While receiving is just plain/empty:


Here is the full code :
C++:
#include <Windows.h>
#include <Winsock.h>
#include "detours.h"

#pragma comment (lib, "detours.lib")
#pragma comment (lib, "ws2_32.lib")

using namespace std;

int (__stdcall *send_o)(__in SOCKET s, __in const char *buf, __in int len, __in int flags);
int (__stdcall *recv_o)(__in SOCKET s, __out const char *buf, __in int len, __in int flags);
char logBuffer[4096] = "\0";

int __stdcall send_h(__in SOCKET s, __in const char *buf, __in int len, __in int flags)
{
	strcat(logBuffer, "Sent:\n");
	strcat(logBuffer, buf);
	
  return send_o(s, buf, len, flags);
}

int __stdcall recv_h(__in SOCKET s, __out const char *buf, __in int len, __in int flags)
{
	strcat(logBuffer, "Receive:\n");
	strcat(logBuffer, buf);

  return recv_o(s, buf, len, flags);
}

DWORD WINAPI HookApi(LPVOID lpParam)
{
	HANDLE h_adrSend = GetProcAddress(GetModuleHandle("ws2_32.dll"), "send");	
	HANDLE h_adrRecv = GetProcAddress(GetModuleHandle("ws2_32.dll"), "recv");
	if (h_adrSend)
		send_o = (int (__stdcall *)( __in SOCKET s, __in const char *buf, __in int len, __in int flags ))DetourFunction((PBYTE)h_adrSend,(PBYTE)send_h);
		
	if (h_adrRecv)
	  recv_o = (int (__stdcall *)( __in SOCKET s, __out const char *buf, __in int len, __in int flags ))DetourFunction((PBYTE)h_adrRecv,(PBYTE)recv_h);
		
	WSADATA      wsaData;
  SOCKET       sock;
  SOCKADDR_IN    servAddr;
  int        nPort = 1111;

  //Initialize winsock 2.2
  WSAStartup(MAKEWORD(2, 2), &wsaData);

  //Create socket to connect
  sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

  //Initialize SocketAddress
  servAddr.sin_family = AF_INET;
  servAddr.sin_port = htons(nPort);
  servAddr.sin_addr.s_addr = inet_addr("127.0.0.1");

  //Connect to our server
  connect(sock, (sockaddr *)&servAddr, sizeof(servAddr));

	while (true)
	{
		if (logBuffer[0] != '\0')
		{
			send_o(sock, logBuffer, strlen(logBuffer), NULL);
			logBuffer[0] = '\0';
			Sleep(200);
		}
	}
	return 0;
}

BOOL APIENTRY DllMain (HINSTANCE hInst,DWORD reason,LPVOID reserved)   
{
	if (reason == DLL_PROCESS_ATTACH)
	{
		DisableThreadLibraryCalls(hInst);
		CreateThread(0,0,HookApi,0,0,NULL);

		return true;
	}

	return TRUE;
}
btw I inject this into the msn process.

Regards
 

konsowa

Coder
Full Member
Nobleman
May 24, 2012
178
753
3
Did u check if it uses the recv function or are u doing this and just hoping the process uses this function?
 

iVision

Newbie
Jun 10, 2012
17
252
0
I was just hoping, but do you mean that its likely using WSARecv or other methods for receiving? Is there a way to see that? Maybe with olly and see the api calls?
Edit: he calls the recv function otherwisethat shouldn't be called I think.
 

iVision

Newbie
Jun 10, 2012
17
252
0
Well after opening some other dlls from msn I came across with this:

It uses recv and recvfrom also it uses send and sendto. But I thought the from/to versions of receive/send are for the DGRAM protocol?
Is it possible that is uses the recv to check whether something is going to be received and then use the recvfrom that contains the data that is send?
Well I just check out and post my results to get some tips/ideas :)
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods League of Legends Accounts