Note that there are some explanatory texts on larger screens.

plurals
  1. POWinsock recv hooking with Detours
    primarykey
    data
    text
    <p>I've got an application, which uses Winsock 2.0 <code>recv</code> function, and I can catch the output by Redox Packet Editor for example, it confirms that version is 2.0. </p> <p>I have this code to hook the function:</p> <pre><code>#define _CRT_SECURE_NO_DEPRECATE #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include &lt;windows.h&gt; #include &lt;WinSock2.h&gt; #include &lt;detours.h&gt; #include &lt;stdio.h&gt; #pragma comment(lib, "ws2_32.lib") FILE *pSendLogFile; FILE *pRecvLogFile; int (WINAPI *pSend)(SOCKET s, const char* buf, int len, int flags) = send; int WINAPI MySend(SOCKET s, const char* buf, int len, int flags); int (WINAPI *pRecv)(SOCKET s, char *buf, int len, int flags) = recv; int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags); INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved) { switch(Reason) { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hDLL); DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); DetourAttach(&amp;(PVOID&amp;)pSend, MySend); if(DetourTransactionCommit() == NO_ERROR) MessageBox(0,"send() detoured successfully","asd",MB_OK); DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); DetourAttach(&amp;(PVOID&amp;)pRecv, MyRecv); if(DetourTransactionCommit() == NO_ERROR) MessageBox(0,"recv() detoured successfully","asd",MB_OK); break; case DLL_PROCESS_DETACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: break; } return TRUE; } int WINAPI MySend(SOCKET s, const char* buf, int len, int flags) { MessageBox(0,"sent","sent",MB_OK); return pSend(s, buf, len, flags); } int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags) { MessageBox(0,"recvd","recvd",MB_OK); return pRecv(s, buf, len, flags); } </code></pre> <p>For <code>send</code>, everything works perfectly, but I don't get any output for <code>recv</code>. I tried in another application using 1.1 version of Winsock and it works ok. Tried to hook WSARecv, WSARecvEx without any luck.</p> <p>Checked the app with WinAPIOverride32, it clearly says that it using <code>recv</code> function, and successfuly logs the usage. Winsock Packet Editor is reading the data well too.</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload