typedef int(__stdcall *send_)(SOCKET , const char* , int , int ); typedef int(__stdcall *recv_)(SOCKET, const char*, int, int); 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 == NULL) hInst = LoadLibraryA(dll); if (hInst == NULL) return NULL; char* p = (char*)::GetProcAddress(hInst, func); void* old = (void*)(p + 1); DWORD Old = 0; VirtualProtect(p - 10, 20, PAGE_EXECUTE_READWRITE, &Old); *p++ = 0xEB; *p = 0xF9; p -= 6; *p = 0xE9; DWORD* t = (DWORD*)++p; DWORD ta = (DWORD)fake_addr - ((DWORD)t - 1) - 5; *t = ta; VirtualProtect(p - 10, 20, Old, &Old); return old; } old_send = (send_)hook_x86("ws2_32.dll", "send", fake_send); old_recv = (recv_)hook_x86("ws2_32.dll", "recv", fake_recv);
欢迎加QQ群:333483823进行技术讨论.
时间: 2024-10-15 23:49:07