I'm trying to hook the recv() function and that works perfectly. It's not shown here, but the hooked function prints what it recieves into the console.
Now, I'm trying to unhook the function on a keypress, but it obviously doesn't work since new recieved packets still get printed to the console so the function is probably still hooked. I've tried switching and changing stuff to make DetourRemove work but it just doesn't if anyone can help, I'd be thankful. The basic code is down below.
int(__stdcall *recv_orig)(SOCKET s, char *buf, int len, int flags);
int __stdcall recv_hook(SOCKET s, char *buf, int len, int flags)
{
return recv_orig(s, buf, len, flags);
}
///DETOUR
recv_orig = (int(__stdcall *)(SOCKET s, char *buf, int len, int flags))DetourFunction(reinterpret_cast<BYTE*>(GetProcAddress(GetModuleHandleW(L"Ws2_32.dll"), "recv")), reinterpret_cast<BYTE*>(recv_hook));
///REMOVE
DetourRemove(reinterpret_cast<BYTE*>(GetProcAddress(GetModuleHandleW(L"Ws2_32.dll"), "recv")), reinterpret_cast<BYTE*>(recv_hook));