I tested this code but not working
Code:
#include "stdafx.h" #include <iostream> #include <detours.h> #include <vector> #include <io.h> #include <fcntl.h> using namespace std; typedef int(__fastcall * tHookPacketFunction)(int, int, unsigned int, long**a3); // int __thiscall sub_52AA90(int this, unsigned int a2, const void *a3) tHookPacketFunction oHookPacketFunction; void OpenConsole(); void OpenConsole() { int hCrtIn, hCrtOut; FILE *conIn, *conOut; AllocConsole(); hCrtIn = _open_osfhandle((intptr_t) GetStdHandle(STD_INPUT_HANDLE), _O_TEXT); hCrtOut = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT); conIn = _fdopen(hCrtIn, "r"); conOut = _fdopen(hCrtOut, "w"); *stdin = *conIn; *stdout = *conOut; } int __fastcall hHookPacketFunction(int a1, int ebx, unsigned int a2, long **a3) { //int iVal = static_cast<int>(reinterpret_cast<BYTE*>(a3)[0]); for (long i = 0; i < sizeof(a3); i++){ if (i == sizeof(a3) - 1) cout << static_cast<int>(reinterpret_cast<BYTE*>(a3)[i]) << endl; else if (i == 0) cout << "Packet header : " << static_cast<int>(reinterpret_cast<BYTE*>(a3)[i]) << ", "; else cout << static_cast<int>(reinterpret_cast<BYTE*>(a3)[i]) << ", "; } return oHookPacketFunction(a1, ebx, a2, a3); } extern "C" __declspec(dllexport) void __cdecl Initialize() { OpenConsole(); oHookPacketFunction = (tHookPacketFunction) DetourFunction((PBYTE) 0x0052AA90, (PBYTE) hHookPacketFunction); } BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: CreateThread(NULL, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(Initialize), NULL, 0, NULL); break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; } return TRUE; }