Replace wsock32.dll

Source: Internet
Author: User
Tags htons
Replace wsock32.dll

// Wsock32.cpp: defines the entry point for the DLL application.
//:::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::: :::::::::::::

 

// Module: replaces wsock32.dll to implement packet interception.

// Author: shower

// Notes: compiled in VC ++ 6.0 XP

// Use the function forwarder to forward the export function that replaces wsock32.dll without intercept to syswsock32.dll (originally replaced wsock32.dll ),
// I have seen an article on the Internet replacing wsock32.dll, but I have not used a function forwarder, so it is complicated.

//:::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::: :::::::::::::

# Include "stdafx. H"

# Pragma comment (linker, "/export: accept = syswsock32.accept, @ 1 ")
# Pragma comment (linker, "/export: bind = syswsock32.bind, @ 2 ")
# Pragma comment (linker, "/export: closesocket = syswsock32.closesocket, @ 3 ")
# Pragma comment (linker, "/export: connect = syswsock32.connect, @ 4 ")
# Pragma comment (linker, "/export: getpeername = syswsock32.getpeername, @ 5 ")
# Pragma comment (linker, "/export: getsockname = syswsock32.getsockname, @ 6 ")
# Pragma comment (linker, "/export: getsockopt = syswsock32.getsockopt, @ 7 ")
# Pragma comment (linker, "/export: htons = syswsock32.htons, @ 9 ")
# Pragma comment (linker, "/export: htonl = syswsock32.htonl, @ 8 ")
# Pragma comment (linker, "/export: inet_addr = syswsock32.inet _ ADDR, @ 10 ")
# Pragma comment (linker, "/export: inet_ntoa = syswsock32.inet _ ntoa, @ 11 ")
# Pragma comment (linker, "/export: ioctlsocket = syswsock32.ioctlsocket, @ 12 ")
# Pragma comment (linker, "/export: Listen = syswsock32.listen, @ 13 ")
# Pragma comment (linker, "/export: ntohl = syswsock32.ntohl, @ 14 ")
# Pragma comment (linker, "/export: ntohs = syswsock32.ntohs, @ 15 ")
# Pragma comment (linker, "/export: Recv = _ Recv @ 16, @ 16 ")
# Pragma comment (linker, "/export: recvfrom = _ recvfrom @ 24, @ 17 ")
# Pragma comment (linker, "/export: Select = syswsock32.select, @ 18 ")
# Pragma comment (linker, "/export: Send = _ Send @ 16, @ 19 ")
# Pragma comment (linker, "/export: sendto = _ sendto @ 24, @ 20 ")
# Pragma comment (linker, "/export: setsockopt = syswsock32.setsockopt, @ 21 ")
# Pragma comment (linker, "/export: Socket = syswsock32.socket, @ 23 ")
# Pragma comment (linker, "/export: shutdown = syswsock32.shutdown, @ 22 ")
# Pragma comment (linker, "/export: migratewinsockconfiguration = syswsock32.migratewinsockconfiguration, @ 24 ")

# Pragma comment (linker, "/export: gethostbyname = syswsock32.gethostbyname, @ 52 ")
# Pragma comment (linker, "/export: gethostbyaddr = syswsock32.gethostbyaddr, @ 51 ")
# Pragma comment (linker, "/export: getprotobynumber = syswsock32.getprotobynumber, @ 54 ")
# Pragma comment (linker, "/export: getprotobyname = syswsock32.getprotobyname, @ 53 ")
# Pragma comment (linker, "/export: getservbyport = syswsock32.getservbyport, @ 56 ")
# Pragma comment (linker, "/export: getservbyname = syswsock32.getservbyname, @ 55 ")
# Pragma comment (linker, "/export: gethostname = syswsock32.gethostname, @ 57 ")

# Pragma comment (linker, "/export: wsaasyncselect = syswsock32.wsaasyncselect, @ 101 ")
# Pragma comment (linker, "/export: wsaasyncgethostbyname = syswsock32.wsaasyncgethostbyname, @ 103 ")
# Pragma comment (linker, "/export: wsaasyncgethostbyaddr = syswsock32.wsaasyncgethostbyaddr, @ 102 ")
# Pragma comment (linker, "/export: wsaasyncgetprotobynumber = syswsock32.wsaasyncgetprotobynumber, @ 104 ")
# Pragma comment (linker, "/export: wsaasyncgetprotobyname = syswsock32.wsaasyncgetprotobyname, @ 105 ")
# Pragma comment (linker, "/export: wsaasyncgetservbyport = syswsock32.wsaasyncgetservbyport, @ 106 ")
# Pragma comment (linker, "/export: wsaasyncgetservbyname = syswsock32.wsaasyncgetservbyname, @ 107 ")
# Pragma comment (linker, "/export: wsacancelasyncrequest = syswsock32.wsacancelasyncrequest, @ 108 ")
# Pragma comment (linker, "/export: wsasetblockinghook = syswsock32.wsasetblockinghook, @ 109 ")
# Pragma comment (linker, "/export: wsaunhookblockinghook = syswsock32.wsaunhookblockinghook, @ 110 ")
# Pragma comment (linker, "/export: wsagetlasterror = syswsock32.wsagetlasterror, @ 111 ")
# Pragma comment (linker, "/export: wsasetlasterror = syswsock32.wsasetlasterror, @ 112 ")
# Pragma comment (linker, "/export: wsacancelblockingcall = syswsock32.wsacancelblockingcall, @ 113 ")
# Pragma comment (linker, "/export: wsaisblocking = syswsock32.wsaisblocking, @ 114 ")
# Pragma comment (linker, "/export: wsastartup = syswsock32.wsastartup, @ 115 ")
# Pragma comment (linker, "/export: wsacleanup = syswsock32.wsacleanup, @ 116 ")
# Pragma comment (linker, "/export: ___ wsafdisset = syswsock32. _ wsafdisset, @ 151 ")

# Pragma comment (linker, "/export: wsarecvex = syswsock32.wsarecvex, @ 1107 ")
# Pragma comment (linker, "/export: wsapsetpostroutine = syswsock32.wsapsetpostroutine, @ 1000 ")
# Pragma comment (linker, "/export: WEP = syswsock32.wep, @ 500 ")
# Pragma comment (linker, "/export: transmitfile = syswsock32.transmitfile, @ 1140 ")
# Pragma comment (linker, "/export: setservicew = syswsock32.setservicew, @ 1118 ")
# Pragma comment (linker, "/export: setservicea = syswsock32.setservicea, @ 1117 ")
# Pragma comment (linker, "/export: sethostname = syswsock32.sethostname, @ 1105 ")

# Pragma comment (linker, "/export: s_perror = syswsock32.s _ perror, @ 1108 ")
# Pragma comment (linker, "/export: rresvport = syswsock32.rresvport, @ 1104 ")
# Pragma comment (linker, "/export: rexec = syswsock32.rexec, @ 1103 ")
# Pragma comment (linker, "/export: RCMD = syswsock32.rcmd, @ 1102 ")
# Pragma comment (linker, "/export: nploadnamespaces = syswsock32.nploadnamespaces, @ 1130 ")

# Pragma comment (linker, "/export: inet_network = syswsock32.inet _ network, @ 1100 ")
# Pragma comment (linker, "/export: gettypebynamew = syswsock32.gettypebynamew, @ 1114 ")
# Pragma comment (linker, "/export: gettypebynamea = syswsock32.gettypebynamea, @ 1113 ")
# Pragma comment (linker, "/export: getservicew = syswsock32.getservicew, @ 1120 ")
# Pragma comment (linker, "/export: getservicea = syswsock32.getservicea, @ 1119 ")
# Pragma comment (linker, "/export: getnetbyname = syswsock32.getnetbyname, @ 1101 ")
# Pragma comment (linker, "/export: getnamebytypew = syswsock32.getnamebytypew, @ 1116 ")
# Pragma comment (linker, "/export: getnamebytypea = syswsock32.getnamebytypea, @ 1115 ")
# Pragma comment (linker, "/export: getaddressbynamew = syswsock32.getaddressbynamew, @ 1110 ")
# Pragma comment (linker, "/export: getaddressbynamea = syswsock32.getaddressbynamea, @ 1109 ")
# Pragma comment (linker, "/export: getacceptexsockaddrs = syswsock32.getacceptexsockaddrs, @ 1142 ")
# Pragma comment (linker, "/export: enumprotocolsw = syswsock32.enumprotocolsw, @ 1112 ")
# Pragma comment (linker, "/export: enumprotocolsa = syswsock32.enumprotocolsa, @ 1111 ")
# Pragma comment (linker, "/export: dn_expand = syswsock32.dn _ expand, @ 1106 ")
# Pragma comment (linker, "/export: acceptex = syswsock32.acceptex, @ 1141 ")

 

Typedef int (winapi * pfun) (int s, const char * Buf, int Len, int flags );
Pfun mysend, myrecv;

Typedef int (winapi * pfun2) (int s, char * Buf, int Len, int flags, int to, int tolen );
Pfun2 mysendto, myrecvfrom;
Void senddata (INT cmd, int Len, char * pbuffer, int sendorrecv );

Hinstance hws2_32;
Hwnd serverhwnd;

Bool apientry dllmain (handle hmodule,
DWORD ul_reason_for_call,
Lpvoid lpreserved
)
{
Switch (ul_reason_for_call)
{
Case dll_process_attach:
Hws2_32 = loadlibrary ("ws2_32.dll ");
Mysend = (pfun) getprocaddress (hws2_32, "send ");
Myrecv = (pfun) getprocaddress (hws2_32, "Recv ");
Mysendto = (pfun2) getprocaddress (hws2_32, "sendto ");
Myrecvfrom = (pfun2) getprocaddress (hws2_32, "recvfrom ");
Serverhwnd = findwindow ("tform1", "server ");
Break;
Case dll_process_detach:
Break;
Case dll_thread_attach:
Break;
Case dll_thread_detach:
Break;
}
Return true;
}

Extern "C" _ declspec (dllexport) int winapi send (int s, char * Buf, int Len, int flags)
{

Senddata (S, Len, Buf, 1 );
Return mysend (S, Buf, Len, flags );
}
Extern "C" _ declspec (dllexport) int winapi sendto (int s, char * Buf, int Len, int flags, int to, int tolen)
{
Senddata (S, Len, Buf, 1 );
Return mysendto (S, Buf, Len, flags, to, tolen );
}
Extern "C" _ declspec (dllexport) int winapi Recv (int s, char * Buf, int Len, int flags)
{
Int RT;
RT = myrecv (S, Buf, Len, flags );
Senddata (S, RT, Buf, 0 );
Return RT;
}
Extern "C" _ declspec (dllexport) int winapi recvfrom (int s, char * Buf, int Len, int flags, int from, int fromlen)
{
Int RT;
RT = myrecvfrom (S, Buf, Len, flags, from, fromlen );
Senddata (S, RT, Buf, 0 );
Return RT;
}
//------------------------------------------------
Void senddata (INT cmd, int Len, char * pbuffer, int sendorrecv)
{
Copydatastruct copydata;
Copydata. dwdata = cmd;
Copydata. cbdata = Len;
Copydata. lpdata = pbuffer;
If (: iswindow (serverhwnd ))
{
: Sendmessage (serverhwnd, wm_copydata, sendorrecv, (lparam) & copydata );
}
}
The coloring effect of this Code is automatically completed by xtint.
Download xtint http: // 211.90.75.84/web/kanaun/download/xtint.rar

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.