Infinite detour?
Having a little trouble with this hook I'm trying to fix. This is my first time using the detours library by the way. Here's what I got so far.
As you can see, every time "send" is called it detours the function to my own. The problem is that I my function also calls "send". So this just creates an infinite loop of detours. What confuses me is that whenever "send" is called, the program with this DLL injected into it immediately closes. If you put a message box at the beginning of my function it DOES do an infinite loop sort of thing, the message box keeps appearing over and over again.
So, what I'm asking for is, is there anyway to NOT detour "send" when I call it? Or, if you have another method of doing this.
What I'm trying to accomplish with this is just to get a hold of the socket.
Note: I tryed hardcoding it... didn't go so well. Don't suggest hardcoding it as another possible method please.
Last thing, I'm injecting this into my own client which is connected to my own server, so I'm sure I'm hooking the right function.
Code:
#include "stdafx.h"
#include <detours.h>
#include <winsock2.h>
int(WINAPI* OriginalSend)(SOCKET s,const char* buf,int len,int flags) = send;
SOCKET SocketHook;
int WINAPI MySendHook(SOCKET s,const char* buf,int len,int flags)
{
SocketHook = s;
return OriginalSend(s,buf,len,flags);
}
BOOL WINAPI DllMain(HINSTANCE hInstance,DWORD Reason,void* Reserved)
{
if(Reason == DLL_PROCESS_ATTACH)
{
DetourFunction((PBYTE)OriginalSend,(PBYTE)MySendHook);
}
return true;
}
So, what I'm asking for is, is there anyway to NOT detour "send" when I call it? Or, if you have another method of doing this.
What I'm trying to accomplish with this is just to get a hold of the socket.
Note: I tryed hardcoding it... didn't go so well. Don't suggest hardcoding it as another possible method please.

Last thing, I'm injecting this into my own client which is connected to my own server, so I'm sure I'm hooking the right function.
