Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- _send pSend;
- _recv pRecv;
- char logfile[MAX_PATH];
- int WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
- {
- if (dwReason == DLL_PROCESS_ATTACH)
- {
- GetModuleFileNameA(NULL, logfile, MAX_PATH);
- lstrcatA(logfile, ".txt");
- MessageBoxA(0, logfile, "pp_capture.dll", 0);
- LogFile("DLL_PROCESS_ATTACH\n", 0);
- pSend = (_send)DetourFindFunction("ws2_32.dll", "send");
- pRecv = (_recv)DetourFindFunction("ws2_32.dll", "recv");
- DisableThreadLibraryCalls(hModule);
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourAttach(&(PVOID&)pSend, cSend);
- if (DetourTransactionCommit() == NO_ERROR)
- LogFile("send() detoured successfully\n", 0);
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourAttach(&(PVOID&)pRecv, cRecv);
- if (DetourTransactionCommit() == NO_ERROR)
- LogFile("recv() detoured successfully\n", 0);
- }
- else if (dwReason == DLL_PROCESS_DETACH)
- {
- LogFile("DLL_PROCESS_DETACH\n", 0);
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourDetach(&(PVOID&)pSend, cSend);
- if (DetourTransactionCommit() == NO_ERROR)
- LogFile("send() un-detoured successfully\n", 0);
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourDetach(&(PVOID&)pRecv, cRecv);
- if (DetourTransactionCommit() == NO_ERROR)
- LogFile("recv() un-detoured successfully\n", 0);
- }
- }
- int WINAPI cSend(SOCKET s, const char *buf, int len, int flags)
- {
- LogFile("[SEND]", 6);
- LogFile((char*)buf, len);
- LogFile("\n", 1);
- return pSend(s, buf, len, flags);
- }
- int WINAPI cRecv(SOCKET s, char *buf, int len, int flags)
- {
- LogFile("[RECV]", 6);
- LogFile(buf, len);
- LogFile("\n", 1);
- return pRecv(s, buf, len, flags);
- }
- void LogFile(char *str, int len)
- {
- HANDLE file = CreateFileA(logfile, FILE_APPEND_DATA,
- FILE_SHARE_READ, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
- if (file == INVALID_HANDLE_VALUE) return;
- DWORD dwBytesWritten;
- if (len == 0) len = lstrlenA(str);
- WriteFile(file, str, len, &dwBytesWritten, 0);
- CloseHandle(file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement