typedef int (__stdcall *send_) (socket, const char*, int, int), typedef int (__stdcall *RECV_) (socket, const char*, int, I NT); int __stdcall Fake_send (SOCKET s, const char* buf, int len, int flags) {return Old_send (S, buf, Len, flags);} int __stdcall Fake_recv (SOCKET s, const char* buf, int len, int flags) {int r = OLD_RECV (s, buf, Len, flags); return r;} void* hook_x86 (const char* dll,const char* func,void* fake_addr) {hinstance HInst =:: Getmodulehandlea (DLL); if (HInst = = NU LL) HInst = LoadLibraryA (DLL); if (hInst = = NULL) return null;char* p = (char*):: GetProcAddress (HInst, func); void* old = (voi d*) (p + 1);D word old = 0; VirtualProtect (p-10, Page_execute_readwrite, &old); *p++ = 0xeb;*p = 0xf9;p-= 6;*p = 0xe9;dword* t = (DWORD*) ++p ;D Word TA = (DWORD) fake_addr-((DWORD) t-1)-5;*t = TA; VirtualProtect (p-10, old, &old); Old_send = (send_) hook_x86 ("Ws2_32.dll", "send", fake_send); old_recv = (recv_) hook_x86 ("Ws2_32.dll", "recv", FAKE_RECV );
Welcome to add QQ Group: 333483823 for technical discussion.
Write a more general 32-bit Apihook function to avoid rewriting every time.