Write a more general 32-bit Apihook function to avoid rewriting every time.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.