PHP Code:
#include <windows.h>
#include <winsock.h>
#include "detours.h"
#pragma comment(lib, "detours.lib")
#pragma comment(lib, "Ws2_32.lib")
typedef int (WINAPI* tRecv)(SOCKET s, char* buf, int len, int Flag);
tRecv oRecv = NULL;
DWORD WINAPI SetHooks(LPVOID);
int WINAPI hRecv(SOCKET s, char* buf, int len, int Flag);
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(0, 0, SetHooks, 0, 0, 0);
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// Put me in a Thread;
DWORD WINAPI SetHooks(LPVOID) {
for (Sleep(1000); GetModuleHandle("Ws2_32.dll") == NULL; Sleep(1000))
continue;
oRecv = (tRecv)DetourFunction((PBYTE)Recv, hRecv);
}
int WINAPI hRecv(SOCKET s, char* buf, int len, int Flag) {
// do something b4 you call the RECV
int iRet = oRecv(s, buf, len, Flag); // call real function
// do something after you call RECV
return iRet;
}