#c #dll #proxy
#c #dll #полномочие
Вопрос:
Я пытаюсь подготовить вспомогательную прокси-библиотеку dll, которая может считывать пакеты, отправленные с клиента на моем компьютере на сервер, и изменять содержимое пакетов перед отправкой пакета или иногда останавливать отправку пакетов.
Проведя исследование по этому вопросу, я подготовил рабочую библиотеку dll прокси. Но так как dll прокси, которую я подготовил, 64-разрядная, я понятия не имею, как организовать функцию send() в соответствии с моими потребностями. Не так много примеров для 64-разрядной версии. Кстати, я думаю, что мне все равно придется вызвать исходную функцию send() после редактирования.
Я хотел бы получить помощь от любого, у кого есть мнение по этому вопросу.
Прокси-DLL:
struct wsock32_dll { HMODULE dll; FARPROC oAcceptEx; FARPROC oEnumProtocolsA; FARPROC oEnumProtocolsW; FARPROC oGetAcceptExSockaddrs; FARPROC oGetAddressByNameA; FARPROC oGetAddressByNameW; FARPROC oGetNameByTypeA; FARPROC oGetNameByTypeW; FARPROC oGetServiceA; FARPROC oGetServiceW; FARPROC oGetTypeByNameA; FARPROC oGetTypeByNameW; FARPROC oMigrateWinsockConfiguration; FARPROC oNPLoadNameSpaces; FARPROC oSetServiceA; FARPROC oSetServiceW; FARPROC oTransmitFile; FARPROC oWEP; FARPROC oWSAAsyncGetHostByAddr; FARPROC oWSAAsyncGetHostByName; FARPROC oWSAAsyncGetProtoByName; FARPROC oWSAAsyncGetProtoByNumber; FARPROC oWSAAsyncGetServByName; FARPROC oWSAAsyncGetServByPort; FARPROC oWSAAsyncSelect; FARPROC oWSACancelAsyncRequest; FARPROC oWSACancelBlockingCall; FARPROC oWSACleanup; FARPROC oWSAGetLastError; FARPROC oWSAIsBlocking; FARPROC oWSARecvEx; FARPROC oWSASetBlockingHook; FARPROC oWSASetLastError; FARPROC oWSAStartup; FARPROC oWSAUnhookBlockingHook; FARPROC oWSApSetPostRoutine; FARPROC o__WSAFDIsSet; FARPROC oaccept; FARPROC obind; FARPROC oclosesocket; FARPROC oconnect; FARPROC odn_expand; FARPROC ogethostbyaddr; FARPROC ogethostbyname; FARPROC ogethostname; FARPROC ogetnetbyname; FARPROC ogetpeername; FARPROC ogetprotobyname; FARPROC ogetprotobynumber; FARPROC ogetservbyname; FARPROC ogetservbyport; FARPROC ogetsockname; FARPROC ogetsockopt; FARPROC ohtonl; FARPROC ohtons; FARPROC oinet_addr; FARPROC oinet_network; FARPROC oinet_ntoa; FARPROC oioctlsocket; FARPROC olisten; FARPROC ontohl; FARPROC ontohs; FARPROC orcmd; FARPROC orecv; FARPROC orecvfrom; FARPROC orexec; FARPROC orresvport; FARPROC os_perror; FARPROC oselect; FARPROC osend; FARPROC osendto; FARPROC osethostname; FARPROC osetsockopt; FARPROC oshutdown; FARPROC osocket;} wsock32; extern "C" { FARPROC PA = 0; int runASM(); void fAcceptEx() { PA = wsock32.oAcceptEx; runASM(); } void fEnumProtocolsA() { PA = wsock32.oEnumProtocolsA; runASM(); } void fEnumProtocolsW() { PA = wsock32.oEnumProtocolsW; runASM(); } void fGetAcceptExSockaddrs() { PA = wsock32.oGetAcceptExSockaddrs; runASM(); } void fGetAddressByNameA() { PA = wsock32.oGetAddressByNameA; runASM(); } void fGetAddressByNameW() { PA = wsock32.oGetAddressByNameW; runASM(); } void fGetNameByTypeA() { PA = wsock32.oGetNameByTypeA; runASM(); } void fGetNameByTypeW() { PA = wsock32.oGetNameByTypeW; runASM(); } void fGetServiceA() { PA = wsock32.oGetServiceA; runASM(); } void fGetServiceW() { PA = wsock32.oGetServiceW; runASM(); } void fGetTypeByNameA() { PA = wsock32.oGetTypeByNameA; runASM(); } void fGetTypeByNameW() { PA = wsock32.oGetTypeByNameW; runASM(); } void fMigrateWinsockConfiguration() { PA = wsock32.oMigrateWinsockConfiguration; runASM(); } void fNPLoadNameSpaces() { PA = wsock32.oNPLoadNameSpaces; runASM(); } void fSetServiceA() { PA = wsock32.oSetServiceA; runASM(); } void fSetServiceW() { PA = wsock32.oSetServiceW; runASM(); } void fTransmitFile() { PA = wsock32.oTransmitFile; runASM(); } void fWEP() { PA = wsock32.oWEP; runASM(); } void fWSAAsyncGetHostByAddr() { PA = wsock32.oWSAAsyncGetHostByAddr; runASM(); } void fWSAAsyncGetHostByName() { PA = wsock32.oWSAAsyncGetHostByName; runASM(); } void fWSAAsyncGetProtoByName() { PA = wsock32.oWSAAsyncGetProtoByName; runASM(); } void fWSAAsyncGetProtoByNumber() { PA = wsock32.oWSAAsyncGetProtoByNumber; runASM(); } void fWSAAsyncGetServByName() { PA = wsock32.oWSAAsyncGetServByName; runASM(); } void fWSAAsyncGetServByPort() { PA = wsock32.oWSAAsyncGetServByPort; runASM(); } void fWSAAsyncSelect() { PA = wsock32.oWSAAsyncSelect; runASM(); } void fWSACancelAsyncRequest() { PA = wsock32.oWSACancelAsyncRequest; runASM(); } void fWSACancelBlockingCall() { PA = wsock32.oWSACancelBlockingCall; runASM(); } void fWSACleanup() { PA = wsock32.oWSACleanup; runASM(); } void fWSAGetLastError() { PA = wsock32.oWSAGetLastError; runASM(); } void fWSAIsBlocking() { PA = wsock32.oWSAIsBlocking; runASM(); } void fWSARecvEx() { PA = wsock32.oWSARecvEx; runASM(); } void fWSASetBlockingHook() { PA = wsock32.oWSASetBlockingHook; runASM(); } void fWSASetLastError() { PA = wsock32.oWSASetLastError; runASM(); } void fWSAStartup() { PA = wsock32.oWSAStartup; runASM(); } void fWSAUnhookBlockingHook() { PA = wsock32.oWSAUnhookBlockingHook; runASM(); } void fWSApSetPostRoutine() { PA = wsock32.oWSApSetPostRoutine; runASM(); } void f__WSAFDIsSet() { PA = wsock32.o__WSAFDIsSet; runASM(); } void faccept() { PA = wsock32.oaccept; runASM(); } void fbind() { PA = wsock32.obind; runASM(); } void fclosesocket() { PA = wsock32.oclosesocket; runASM(); } void fconnect() { PA = wsock32.oconnect; runASM(); } void fdn_expand() { PA = wsock32.odn_expand; runASM(); } void fgethostbyaddr() { PA = wsock32.ogethostbyaddr; runASM(); } void fgethostbyname() { PA = wsock32.ogethostbyname; runASM(); } void fgethostname() { PA = wsock32.ogethostname; runASM(); } void fgetnetbyname() { PA = wsock32.ogetnetbyname; runASM(); } void fgetpeername() { PA = wsock32.ogetpeername; runASM(); } void fgetprotobyname() { PA = wsock32.ogetprotobyname; runASM(); } void fgetprotobynumber() { PA = wsock32.ogetprotobynumber; runASM(); } void fgetservbyname() { PA = wsock32.ogetservbyname; runASM(); } void fgetservbyport() { PA = wsock32.ogetservbyport; runASM(); } void fgetsockname() { PA = wsock32.ogetsockname; runASM(); } void fgetsockopt() { PA = wsock32.ogetsockopt; runASM(); } void fhtonl() { PA = wsock32.ohtonl; runASM(); } void fhtons() { PA = wsock32.ohtons; runASM(); } void finet_addr() { PA = wsock32.oinet_addr; runASM(); } void finet_network() { PA = wsock32.oinet_network; runASM(); } void finet_ntoa() { PA = wsock32.oinet_ntoa; runASM(); } void fioctlsocket() { PA = wsock32.oioctlsocket; runASM(); } void flisten() { PA = wsock32.olisten; runASM(); } void fntohl() { PA = wsock32.ontohl; runASM(); } void fntohs() { PA = wsock32.ontohs; runASM(); } void frcmd() { PA = wsock32.orcmd; runASM(); } void frecv() { PA = wsock32.orecv; runASM(); } void frecvfrom() { PA = wsock32.orecvfrom; runASM(); } void frexec() { PA = wsock32.orexec; runASM(); } void frresvport() { PA = wsock32.orresvport; runASM(); } void fs_perror() { PA = wsock32.os_perror; runASM(); } void fselect() { PA = wsock32.oselect; runASM(); } void fsend() { PA = wsock32.osend; runASM(); } void fsendto() { PA = wsock32.osendto; runASM(); } void fsethostname() { PA = wsock32.osethostname; runASM(); } void fsetsockopt() { PA = wsock32.osetsockopt; runASM(); } void fshutdown() { PA = wsock32.oshutdown; runASM(); } void fsocket() { PA = wsock32.osocket; runASM(); }} void setupFunctions() { wsock32.oAcceptEx = GetProcAddress(wsock32.dll, "AcceptEx"); wsock32.oEnumProtocolsA = GetProcAddress(wsock32.dll, "EnumProtocolsA"); wsock32.oEnumProtocolsW = GetProcAddress(wsock32.dll, "EnumProtocolsW"); wsock32.oGetAcceptExSockaddrs = GetProcAddress(wsock32.dll, "GetAcceptExSockaddrs"); wsock32.oGetAddressByNameA = GetProcAddress(wsock32.dll, "GetAddressByNameA"); wsock32.oGetAddressByNameW = GetProcAddress(wsock32.dll, "GetAddressByNameW"); wsock32.oGetNameByTypeA = GetProcAddress(wsock32.dll, "GetNameByTypeA"); wsock32.oGetNameByTypeW = GetProcAddress(wsock32.dll, "GetNameByTypeW"); wsock32.oGetServiceA = GetProcAddress(wsock32.dll, "GetServiceA"); wsock32.oGetServiceW = GetProcAddress(wsock32.dll, "GetServiceW"); wsock32.oGetTypeByNameA = GetProcAddress(wsock32.dll, "GetTypeByNameA"); wsock32.oGetTypeByNameW = GetProcAddress(wsock32.dll, "GetTypeByNameW"); wsock32.oMigrateWinsockConfiguration = GetProcAddress(wsock32.dll, "MigrateWinsockConfiguration"); wsock32.oNPLoadNameSpaces = GetProcAddress(wsock32.dll, "NPLoadNameSpaces"); wsock32.oSetServiceA = GetProcAddress(wsock32.dll, "SetServiceA"); wsock32.oSetServiceW = GetProcAddress(wsock32.dll, "SetServiceW"); wsock32.oTransmitFile = GetProcAddress(wsock32.dll, "TransmitFile"); wsock32.oWEP = GetProcAddress(wsock32.dll, "WEP"); wsock32.oWSAAsyncGetHostByAddr = GetProcAddress(wsock32.dll, "WSAAsyncGetHostByAddr"); wsock32.oWSAAsyncGetHostByName = GetProcAddress(wsock32.dll, "WSAAsyncGetHostByName"); wsock32.oWSAAsyncGetProtoByName = GetProcAddress(wsock32.dll, "WSAAsyncGetProtoByName"); wsock32.oWSAAsyncGetProtoByNumber = GetProcAddress(wsock32.dll, "WSAAsyncGetProtoByNumber"); wsock32.oWSAAsyncGetServByName = GetProcAddress(wsock32.dll, "WSAAsyncGetServByName"); wsock32.oWSAAsyncGetServByPort = GetProcAddress(wsock32.dll, "WSAAsyncGetServByPort"); wsock32.oWSAAsyncSelect = GetProcAddress(wsock32.dll, "WSAAsyncSelect"); wsock32.oWSACancelAsyncRequest = GetProcAddress(wsock32.dll, "WSACancelAsyncRequest"); wsock32.oWSACancelBlockingCall = GetProcAddress(wsock32.dll, "WSACancelBlockingCall"); wsock32.oWSACleanup = GetProcAddress(wsock32.dll, "WSACleanup"); wsock32.oWSAGetLastError = GetProcAddress(wsock32.dll, "WSAGetLastError"); wsock32.oWSAIsBlocking = GetProcAddress(wsock32.dll, "WSAIsBlocking"); wsock32.oWSARecvEx = GetProcAddress(wsock32.dll, "WSARecvEx"); wsock32.oWSASetBlockingHook = GetProcAddress(wsock32.dll, "WSASetBlockingHook"); wsock32.oWSASetLastError = GetProcAddress(wsock32.dll, "WSASetLastError"); wsock32.oWSAStartup = GetProcAddress(wsock32.dll, "WSAStartup"); wsock32.oWSAUnhookBlockingHook = GetProcAddress(wsock32.dll, "WSAUnhookBlockingHook"); wsock32.oWSApSetPostRoutine = GetProcAddress(wsock32.dll, "WSApSetPostRoutine"); wsock32.o__WSAFDIsSet = GetProcAddress(wsock32.dll, "__WSAFDIsSet"); wsock32.oaccept = GetProcAddress(wsock32.dll, "accept"); wsock32.obind = GetProcAddress(wsock32.dll, "bind"); wsock32.oclosesocket = GetProcAddress(wsock32.dll, "closesocket"); wsock32.oconnect = GetProcAddress(wsock32.dll, "connect"); wsock32.odn_expand = GetProcAddress(wsock32.dll, "dn_expand"); wsock32.ogethostbyaddr = GetProcAddress(wsock32.dll, "gethostbyaddr"); wsock32.ogethostbyname = GetProcAddress(wsock32.dll, "gethostbyname"); wsock32.ogethostname = GetProcAddress(wsock32.dll, "gethostname"); wsock32.ogetnetbyname = GetProcAddress(wsock32.dll, "getnetbyname"); wsock32.ogetpeername = GetProcAddress(wsock32.dll, "getpeername"); wsock32.ogetprotobyname = GetProcAddress(wsock32.dll, "getprotobyname"); wsock32.ogetprotobynumber = GetProcAddress(wsock32.dll, "getprotobynumber"); wsock32.ogetservbyname = GetProcAddress(wsock32.dll, "getservbyname"); wsock32.ogetservbyport = GetProcAddress(wsock32.dll, "getservbyport"); wsock32.ogetsockname = GetProcAddress(wsock32.dll, "getsockname"); wsock32.ogetsockopt = GetProcAddress(wsock32.dll, "getsockopt"); wsock32.ohtonl = GetProcAddress(wsock32.dll, "htonl"); wsock32.ohtons = GetProcAddress(wsock32.dll, "htons"); wsock32.oinet_addr = GetProcAddress(wsock32.dll, "inet_addr"); wsock32.oinet_network = GetProcAddress(wsock32.dll, "inet_network"); wsock32.oinet_ntoa = GetProcAddress(wsock32.dll, "inet_ntoa"); wsock32.oioctlsocket = GetProcAddress(wsock32.dll, "ioctlsocket"); wsock32.olisten = GetProcAddress(wsock32.dll, "listen"); wsock32.ontohl = GetProcAddress(wsock32.dll, "ntohl"); wsock32.ontohs = GetProcAddress(wsock32.dll, "ntohs"); wsock32.orcmd = GetProcAddress(wsock32.dll, "rcmd"); wsock32.orecv = GetProcAddress(wsock32.dll, "recv"); wsock32.orecvfrom = GetProcAddress(wsock32.dll, "recvfrom"); wsock32.orexec = GetProcAddress(wsock32.dll, "rexec"); wsock32.orresvport = GetProcAddress(wsock32.dll, "rresvport"); wsock32.os_perror = GetProcAddress(wsock32.dll, "s_perror"); wsock32.oselect = GetProcAddress(wsock32.dll, "select"); wsock32.osend = GetProcAddress(wsock32.dll, "send"); wsock32.osendto = GetProcAddress(wsock32.dll, "sendto"); wsock32.osethostname = GetProcAddress(wsock32.dll, "sethostname"); wsock32.osetsockopt = GetProcAddress(wsock32.dll, "setsockopt"); wsock32.oshutdown = GetProcAddress(wsock32.dll, "shutdown"); wsock32.osocket = GetProcAddress(wsock32.dll, "socket");} BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: char path[MAX_PATH]; GetWindowsDirectory(path, sizeof(path)); // Example: "\System32\version.dll" strcat_s(path, "C:\Windows\System32\wsock32.dll"); wsock32.dll = LoadLibrary(path); setupFunctions(); break; case DLL_PROCESS_DETACH: FreeLibrary(wsock32.dll); break; } return 1;}