Code:
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#include <winsock.h>
#include <iostream>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
Code:
#include "Intestazione.h"
typedef int(__stdcall *hsend)(SOCKET s, const char *buf, int len, int flags);
hsend osend;
int __stdcall msend(SOCKET s, const char *buf, int len, int flags)
{
cout << " SUCCESS" << endl;
return osend(s, buf, len,flags);
}
void *DetourCreate(BYTE *src, const BYTE *dst, unsigned int len)
{
BYTE * jmp = reinterpret_cast<BYTE*>(malloc(len + 5));
DWORD dwBack;
VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
memcpy(jmp, src, len);
jmp += len;
jmp[0] = 0xE9;
*reinterpret_cast<DWORD*>(jmp + 1) = (DWORD)(src + len - jmp) - 5;
src[0] = 0xE9;
*reinterpret_cast<DWORD*>(src + 1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwBack, &dwBack);
return jmp - len;
}
DWORD WINAPI Start(LPVOID lpArg)
{
AllocConsole();
SetConsoleTitle("Packet Manager v 1.0.0.0 [Alliance coder]");
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
cout << "Waiting module: ";
HMODULE hDll = NULL;
do
{
Sleep(300);
hDll = GetModuleHandle("ws2_32.dll");
} while (!hDll);
cout << " SUCCESS" << endl;
cout << "Waiting detour: ";
osend = (hsend)DetourCreate((BYTE*)reinterpret_cast<DWORD>(GetProcAddress(hDll,"send")), (BYTE*)msend, 5);
return EXIT_SUCCESS;
}
BOOL APIENTRY DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
CreateThread(NULL, NULL, Start, NULL, NULL, NULL);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
This is my project to hook send function , but don't work.I don't know what is the problem...someone can fix it if there are errors?