From fa1c3551be5c383a277ee607a3d6c613b7d7e818 Mon Sep 17 00:00:00 2001 From: Netch Date: Sun, 1 Aug 2021 13:22:02 +0800 Subject: [PATCH] Add files via upload --- Redirector/Based.h | 23 +++ Redirector/DNSHandler.cpp | 203 ++++++++++++++++++-------- Redirector/DNSHandler.h | 31 ++-- Redirector/Data.cpp | 18 --- Redirector/Data.h | 26 ---- Redirector/EventHandler.cpp | 121 ++++++++------- Redirector/EventHandler.h | 6 +- Redirector/IPEventHandler.cpp | 40 ++++- Redirector/IPEventHandler.h | 4 +- Redirector/Redirector.cpp | 26 +++- Redirector/Redirector.vcxproj | 3 +- Redirector/Redirector.vcxproj.filters | 9 +- Redirector/TCPHandler.cpp | 160 +++++++++++++++++++- Redirector/TCPHandler.h | 23 ++- Redirector/UDPHandler.cpp | 10 ++ Redirector/UDPHandler.h | 12 ++ Redirector/Utils.cpp | 42 ------ Redirector/Utils.h | 4 - 18 files changed, 505 insertions(+), 256 deletions(-) create mode 100644 Redirector/Based.h delete mode 100644 Redirector/Data.cpp delete mode 100644 Redirector/Data.h diff --git a/Redirector/Based.h b/Redirector/Based.h new file mode 100644 index 00000000..1be579dd --- /dev/null +++ b/Redirector/Based.h @@ -0,0 +1,23 @@ +#pragma once +#ifndef BASED_H +#define BASED_H +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +using namespace std; +#endif diff --git a/Redirector/DNSHandler.cpp b/Redirector/DNSHandler.cpp index 11b50f8a..bca337b4 100644 --- a/Redirector/DNSHandler.cpp +++ b/Redirector/DNSHandler.cpp @@ -1,62 +1,8 @@ #include "DNSHandler.h" -#include "Data.h" #include "Utils.h" -#include - -#include - -DNSHandler::DNSHandler(string dnsHost, USHORT dnsPort) -{ - lock_guard lg(this->DNSLock); - - this->Started = TRUE; - this->DNSHost = dnsHost; - this->DNSPort = dnsPort; - - for (int i = 0; i < 4; i++) - { - thread(&DNSHandler::Worker, this).detach(); - } -} - -DNSHandler::~DNSHandler() -{ - lock_guard lg(this->DNSLock); - - this->Started = FALSE; - for (PDNSPKT i : this->DNSList) - { - this->Delete(i); - } - this->DNSList.clear(); -} - -void DNSHandler::Create(ENDPOINT_ID id, PBYTE target, ULONG targetLength, PCHAR buffer, ULONG bufferLength, PNF_UDP_OPTIONS option) -{ - if (!this->Started) - { - return; - } - - auto data = new DNSPKT(); - data->ID = id; - data->Target = new BYTE[targetLength](); - data->TargetLength = targetLength; - data->Buffer = new CHAR[bufferLength](); - data->BufferLength = bufferLength; - data->Option = new NF_UDP_OPTIONS(); - - memcpy(data->Target, target, targetLength); - memcpy(data->Buffer, buffer, bufferLength); - memcpy(data->Option, option, sizeof(NF_UDP_OPTIONS)); - - lock_guard lg(this->DNSLock); - this->DNSList.emplace_back(data); -} - -void DNSHandler::Delete(PDNSPKT i) +void dns_freePacket(PDNSPKT i) { if (i) { @@ -81,10 +27,151 @@ void DNSHandler::Delete(PDNSPKT i) i = NULL; } -void DNSHandler::Worker() +DNSHandler::DNSHandler(string dnsHost, USHORT dnsPort) { - while (this->Started) + this->dnsHost = dnsHost; + this->dnsPort = dnsPort; +} + +BOOL DNSHandler::init() +{ + this->Started = TRUE; + + WaitForSingleObject(this->dnsLock, INFINITE); + for (size_t i = 0; i < 4; i++) { - + this->dnsLoop[i] = thread(&DNSHandler::Thread, this); + } + ReleaseMutex(this->dnsLock); +} + +void DNSHandler::free() +{ + if (this->dnsLock) + { + WaitForSingleObject(this->dnsLock, INFINITE); + } + + this->Started = FALSE; + for (size_t i = 0; i < this->dnsLoop.size(); i++) + { + if (this->dnsLoop[i].joinable()) + { + this->dnsLoop[i].join(); + } + } + this->dnsLoop.clear(); + + auto size = this->dnsList.size(); + for (size_t i = 0; i < size; i++) + { + dns_freePacket(this->dnsList.front()); + } + + if (this->dnsLock) + { + CloseHandle(this->dnsLock); + this->dnsLock = NULL; } } + +void DNSHandler::Create(ENDPOINT_ID id, PBYTE target, ULONG targetLength, PCHAR buffer, ULONG bufferLength, PNF_UDP_OPTIONS option) +{ + if (!this->Started) + { + return; + } + + auto data = new DNSPKT(); + data->ID = id; + data->Target = new BYTE[targetLength](); + data->TargetLength = targetLength; + data->Buffer = new CHAR[bufferLength](); + data->BufferLength = bufferLength; + data->Option = new NF_UDP_OPTIONS(); + + memcpy(data->Target, target, targetLength); + memcpy(data->Buffer, buffer, bufferLength); + memcpy(data->Option, option, sizeof(NF_UDP_OPTIONS)); + + WaitForSingleObject(this->dnsLock, INFINITE); + this->dnsList.emplace(data); + ReleaseMutex(this->dnsLock); +} + +void DNSHandler::Thread() +{ + while (this->Started && this->dnsLock) + { + switch (WaitForSingleObject(this->dnsLock, 10)) + { + case WAIT_OBJECT_0: + this->Handle(); + break; + default: + continue; + } + } +} + +void DNSHandler::Handle() +{ + SOCKADDR_IN addr; + addr.sin_family = AF_INET; + addr.sin_port = htons(this->dnsPort); + if (!inet_pton(AF_INET, this->dnsHost.c_str(), &addr.sin_addr)) + { + ReleaseMutex(this->dnsLock); + return; + } + + auto data = this->dnsList.front(); + this->dnsList.pop(); + ReleaseMutex(this->dnsLock); + + auto client = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (!client) + { + dns_freePacket(data); + + printf("[Redirector][DNSHandler::Handle] Create socket failed: %d\n", WSAGetLastError()); + return; + } + + TIMEVAL tv; + tv.tv_sec = 4; + tv.tv_usec = 0; + + FD_SET fds; + FD_ZERO(&fds); + FD_SET(client, &fds); + + if (sendto(client, data->Buffer, data->BufferLength, 0, (PSOCKADDR)&addr, sizeof(SOCKADDR_IN))) + { + if (select(0, &fds, 0, 0, &tv)) + { + CHAR buffer[1024]; + auto length = recvfrom(client, buffer, sizeof(buffer), 0, NULL, NULL); + + if (length) + { + nf_udpPostReceive(data->ID, data->Target, buffer, length, data->Option); + } + else + { + printf("[Redirector][DNSHandler::Handle] Receive failed: %d\n", WSAGetLastError()); + } + } + else + { + puts("[Redirector][DNSHandler::Handle] Receive timed out"); + } + } + else + { + printf("[Redirector][DNSHandler::Handle] Send failed: %d\n", WSAGetLastError()); + } + + closesocket(client); + dns_freePacket(data); +} diff --git a/Redirector/DNSHandler.h b/Redirector/DNSHandler.h index 82e8e9da..0559faa7 100644 --- a/Redirector/DNSHandler.h +++ b/Redirector/DNSHandler.h @@ -1,15 +1,7 @@ #pragma once #ifndef DNSHANDLER_H #define DNSHANDLER_H -#include - -#include -#include -#include - -#include - -using namespace std; +#include "Based.h" typedef struct _DNSPKT { ENDPOINT_ID ID; @@ -24,20 +16,23 @@ typedef class DNSHandler { public: DNSHandler(string dnsHost, USHORT dnsPort); - ~DNSHandler(); + + BOOL init(); + void free(); void Create(ENDPOINT_ID id, PBYTE target, ULONG targetLength, PCHAR buffer, ULONG bufferLength, PNF_UDP_OPTIONS options); private: - void Delete(PDNSPKT i); - void Worker(); + void Thread(); + void Handle(); + + string dnsHost; + USHORT dnsPort = 0; + + HANDLE dnsLock; + queue dnsList; + vector dnsLoop; BOOL Started = FALSE; - - string DNSHost; - USHORT DNSPort = 0; - - mutex DNSLock; - vector DNSList; } *PDNSHandler; #endif diff --git a/Redirector/Data.cpp b/Redirector/Data.cpp deleted file mode 100644 index f6c0edb2..00000000 --- a/Redirector/Data.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "Data.h" - -#include -#include -#include - -using namespace std; - -BOOL Started = FALSE; -BOOL filterLoop = FALSE; -BOOL filterICMP = TRUE; -BOOL filterTCP = TRUE; -BOOL filterUDP = TRUE; -BOOL dnsHook = FALSE; -string dnsHost = ""; -USHORT dnsPort = 0; -USHORT tcpLisn = 0; -USHORT udpLisn = 0; diff --git a/Redirector/Data.h b/Redirector/Data.h deleted file mode 100644 index e3e01e08..00000000 --- a/Redirector/Data.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#ifndef DATA_H -#define DATA_H -#include - -#include - -typedef enum _AIO_TYPE { - AIO_FILTERLOOP, - AIO_FILTERICMP, - AIO_FILTERTCP, - AIO_FILTERUDP, - - AIO_CLRNAME, - AIO_ADDNAME, - AIO_BYPNAME, - - AIO_DNSHOOK, - AIO_DNSHOST, - AIO_DNSPORT, - - AIO_TCPPORT, - AIO_UDPPORT -} AIO_TYPE; - -#endif diff --git a/Redirector/EventHandler.cpp b/Redirector/EventHandler.cpp index 0d131cf5..6bb2e662 100644 --- a/Redirector/EventHandler.cpp +++ b/Redirector/EventHandler.cpp @@ -1,45 +1,31 @@ #include "EventHandler.h" -#include "Data.h" #include "DNSHandler.h" #include "TCPHandler.h" #include "UDPHandler.h" -#include - -#include -#include -#include -#include -#include - -using namespace std; - -extern BOOL dnsHook; -extern string dnsHost; -extern USHORT dnsPort; -extern USHORT tcpLisn; -extern USHORT udpLisn; - -typedef struct _TCPINFO { - DWORD PID; - PBYTE Target; -} TCPINFO, * PTCPINFO; - -typedef struct _UDPINFO { - SOCKET Socket; -} UDPINFO, * PUDPINFO; +BOOL Started = FALSE; +BOOL filterLoop = FALSE; +BOOL filterICMP = TRUE; +BOOL filterTCP = TRUE; +BOOL filterUDP = TRUE; +BOOL dnsHook = FALSE; +string dnsHost = ""; +USHORT dnsPort = 0; +USHORT tcpLisn = 0; +USHORT udpLisn = 0; vector handleList; vector bypassList; -mutex TCPLock; -mutex UDPLock; -map TCPContext; -map UDPContext; +mutex tcpLock; +mutex udpLock; +map tcpContext; +map udpContext; PDNSHandler dnsHandler = NULL; PTCPHandler tcpHandler = NULL; +PUDPHandler udpHandler = NULL; wstring getProcessName(DWORD id) { @@ -62,10 +48,10 @@ wstring getProcessName(DWORD id) } } - wchar_t result[MAX_PATH]; - if (GetLongPathNameW(name, result, MAX_PATH)) + wchar_t data[MAX_PATH]; + if (GetLongPathNameW(name, data, MAX_PATH)) { - return result; + return data; } return name; @@ -101,35 +87,32 @@ BOOL checkHandleName(DWORD id) return FALSE; } -void eh_init() +BOOL eh_init() { - if (dnsHandler == NULL) + dnsHandler = new DNSHandler(dnsHost, dnsPort); + tcpHandler = new TCPHandler(tcpLisn); + udpHandler = new UDPHandler(); + + if (!tcpHandler->init()) { - dnsHandler = new DNSHandler(dnsHost, dnsPort); + return FALSE; } - if (tcpHandler == NULL) - { - tcpHandler = new TCPHandler(); - } + return TRUE; } void eh_free() { - lock_guard tlg(TCPLock); - lock_guard ulg(UDPLock); + lock_guard tlg(tcpLock); + lock_guard ulg(udpLock); - for (auto& [k, v] : TCPContext) + for (auto& [k, v] : tcpContext) { - if (v->Target) - { - free(v->Target); - v->Target = NULL; - } + continue; } - TCPContext.clear(); + tcpContext.clear(); - for (auto& [k, v] : UDPContext) + for (auto& [k, v] : udpContext) { if (v->Socket) { @@ -137,19 +120,29 @@ void eh_free() v->Socket = NULL; } } - UDPContext.clear(); + udpContext.clear(); - if (dnsHandler != NULL) + if (dnsHandler) { + dnsHandler->free(); + delete dnsHandler; dnsHandler = NULL; } - if (tcpHandler != NULL) + if (tcpHandler) { + tcpHandler->free(); + delete tcpHandler; tcpHandler = NULL; } + + if (udpHandler) + { + delete udpHandler; + udpHandler = NULL; + } } void threadStart() @@ -164,7 +157,21 @@ void threadEnd() void tcpConnectRequest(ENDPOINT_ID id, PNF_TCP_CONN_INFO info) { - nf_tcpDisableFiltering(id); + if (checkBypassName(info->processId)) + { + nf_tcpDisableFiltering(id); + + printf("[Redirector][EventHandler][tcpConnectRequest][%llu] this->checkBypassName\n", id); + return; + } + + if (!checkHandleName(info->processId)) + { + nf_tcpDisableFiltering(id); + + printf("[Redirector][EventHandler][tcpConnectRequest][%llu] !this->checkHandleName\n", id); + return; + } } void tcpConnected(ENDPOINT_ID id, PNF_TCP_CONN_INFO info) @@ -196,7 +203,7 @@ void tcpReceive(ENDPOINT_ID id, const char* buffer, int length) void tcpClosed(ENDPOINT_ID id, PNF_TCP_CONN_INFO info) { - + printf("[Redirector][EventHandler][tcpClosed][%llu]\n", id); } void udpCreated(ENDPOINT_ID id, PNF_UDP_CONN_INFO info) @@ -232,5 +239,11 @@ void udpReceive(ENDPOINT_ID id, const unsigned char* target, const char* buffer, void udpClosed(ENDPOINT_ID id, PNF_UDP_CONN_INFO info) { + printf("[Redirector][EventHandler][udpClosed][%llu]\n", id); + lock_guard lg(udpLock); + if (udpContext.find(id) != udpContext.end()) + { + udpContext.erase(id); + } } diff --git a/Redirector/EventHandler.h b/Redirector/EventHandler.h index 7e04265a..c37c167e 100644 --- a/Redirector/EventHandler.h +++ b/Redirector/EventHandler.h @@ -1,11 +1,9 @@ #pragma once #ifndef EVENTHANDLER_H #define EVENTHANDLER_H -#include +#include "Based.h" -#include - -void eh_init(); +BOOL eh_init(); void eh_free(); void threadStart(); diff --git a/Redirector/IPEventHandler.cpp b/Redirector/IPEventHandler.cpp index 1fc1f7e4..b11f9839 100644 --- a/Redirector/IPEventHandler.cpp +++ b/Redirector/IPEventHandler.cpp @@ -2,9 +2,45 @@ #include "Utils.h" -#include +USHORT IPv4Checksum(PBYTE buffer, ULONG64 size) +{ + UINT32 sum = 0; + for (int i = 0; i < size; i += 2) + { + sum += (buffer[i] << 8) + buffer[i + 1]; + } -using namespace std; + if ((size % 2) == 1) + { + sum += buffer[size - 1] << 8; + } + + while (sum > 0xffff) + { + sum = (sum >> 16) + (sum & 0xffff); + } + + return ~sum & 0xffff; +} + +USHORT ICMPChecksum(PBYTE buffer, ULONG64 size) +{ + UINT32 sum = 0; + for (int i = 0; i < size; i += 2) + { + sum += buffer[i] + (buffer[i + 1] << 8); + } + + if ((size % 2) == 1) + { + sum += buffer[size - 1]; + } + + sum = (sum >> 16) + (sum & 0xffff); + sum += (sum >> 16); + + return ~sum & 0xffff; +} void ipSend(const char* buffer, int length, PNF_IP_PACKET_OPTIONS options) { diff --git a/Redirector/IPEventHandler.h b/Redirector/IPEventHandler.h index 8d7d8f86..d71a4a57 100644 --- a/Redirector/IPEventHandler.h +++ b/Redirector/IPEventHandler.h @@ -1,9 +1,7 @@ #pragma once #ifndef IPEVENTHANDLER_H #define IPEVENTHANDLER_H -#include - -#include +#include "Based.h" void ipSend(const char* buffer, int length, PNF_IP_PACKET_OPTIONS options); void ipReceive(const char* buffer, int length, PNF_IP_PACKET_OPTIONS options); diff --git a/Redirector/Redirector.cpp b/Redirector/Redirector.cpp index 9a5f7bd1..ae797b53 100644 --- a/Redirector/Redirector.cpp +++ b/Redirector/Redirector.cpp @@ -1,16 +1,26 @@ -#include "Data.h" +#include "Based.h" + #include "Utils.h" #include "EventHandler.h" #include "IPEventHandler.h" -#include +typedef enum _AIO_TYPE { + AIO_FILTERLOOP, + AIO_FILTERICMP, + AIO_FILTERTCP, + AIO_FILTERUDP, -#include -#include + AIO_CLRNAME, + AIO_ADDNAME, + AIO_BYPNAME, -#include + AIO_DNSHOOK, + AIO_DNSHOST, + AIO_DNSPORT, -using namespace std; + AIO_TCPPORT, + AIO_UDPPORT +} AIO_TYPE; extern BOOL filterLoop; extern BOOL filterICMP; @@ -92,13 +102,13 @@ extern "C" { __declspec(dllexport) BOOL __cdecl aio_init() { - nf_adjustProcessPriviledges(); - { WSADATA data; UNREFERENCED_PARAMETER(WSAStartup(MAKEWORD(2, 2), &data)); } + nf_adjustProcessPriviledges(); + return FALSE; } diff --git a/Redirector/Redirector.vcxproj b/Redirector/Redirector.vcxproj index 1ad57081..1d88782e 100644 --- a/Redirector/Redirector.vcxproj +++ b/Redirector/Redirector.vcxproj @@ -96,7 +96,6 @@ - @@ -106,10 +105,10 @@ - + diff --git a/Redirector/Redirector.vcxproj.filters b/Redirector/Redirector.vcxproj.filters index 7968361c..b954d1ac 100644 --- a/Redirector/Redirector.vcxproj.filters +++ b/Redirector/Redirector.vcxproj.filters @@ -17,9 +17,6 @@ Source - - Source - Source @@ -40,9 +37,6 @@ Header - - Header - Header @@ -58,6 +52,9 @@ Header + + Header + diff --git a/Redirector/TCPHandler.cpp b/Redirector/TCPHandler.cpp index 898ba724..e2de720b 100644 --- a/Redirector/TCPHandler.cpp +++ b/Redirector/TCPHandler.cpp @@ -1,21 +1,165 @@ #include "TCPHandler.h" -TCPHandler::TCPHandler() +TCPHandler::TCPHandler(USHORT tcpPort) { - -} - -TCPHandler::~TCPHandler() -{ - + this->tcpPort = tcpPort; } BOOL TCPHandler::init() { - return FALSE; + { + this->IPv4Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (!this->IPv4Socket) + { + printf("[Redirector][TCPHandler::init][IPv4] Create socket failed: %d\n", WSAGetLastError()); + return FALSE; + } + + SOCKADDR_IN addr; + addr.sin_family = AF_INET; + addr.sin_port = 0; + + if (bind(this->IPv4Socket, (PSOCKADDR)&addr, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) + { + printf("[Redirector][TCPHandler::init][IPv4] Bind socket failed: %d\n", WSAGetLastError()); + return FALSE; + } + + if (listen(this->IPv4Socket, 1024) == SOCKET_ERROR) + { + printf("[Redirector][TCPHandler::init][IPv4] Listen socket failed: %d\n", WSAGetLastError()); + return FALSE; + } + } + + { + this->IPv6Socket = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); + if (!this->IPv6Socket) + { + printf("[Redirector][TCPHandler::init][IPv6] Create socket failed: %d\n", WSAGetLastError()); + return FALSE; + } + + SOCKADDR_IN6 addr; + addr.sin6_family = AF_INET6; + addr.sin6_port = 0; + + if (bind(this->IPv6Socket, (PSOCKADDR)&addr, sizeof(SOCKADDR_IN6)) == SOCKET_ERROR) + { + printf("[Redirector][TCPHandler::init][IPv6] Bind socket failed: %d\n", WSAGetLastError()); + return FALSE; + } + + if (listen(this->IPv6Socket, 1024) == SOCKET_ERROR) + { + printf("[Redirector][TCPHandler::init][IPv6] Listen socket failed: %d\n", WSAGetLastError()); + return FALSE; + } + } + + this->tcpLock = CreateMutex(NULL, FALSE, NULL); + if (!this->tcpLock) + { + return FALSE; + } + + this->Started = TRUE; + thread(&TCPHandler::IPv4, this).detach(); + thread(&TCPHandler::IPv6, this).detach(); + return TRUE; } void TCPHandler::free() { + WaitForSingleObject(this->tcpLock, INFINITE); + if (this->IPv4Socket) + { + closesocket(this->IPv4Socket); + this->IPv4Socket = NULL; + } + + if (this->IPv6Socket) + { + closesocket(this->IPv6Socket); + this->IPv6Socket = NULL; + } + + for (auto& [k, v] : this->tcpContext) + { + continue; + } + this->tcpContext.clear(); + + if (this->tcpLock) + { + CloseHandle(this->tcpLock); + this->tcpLock = NULL; + } +} + +void TCPHandler::IPv4() +{ + while (this->Started && this->IPv4Socket) + { + SOCKADDR_IN addr; + int addrLength = 0; + + auto client = accept(this->IPv4Socket, (PSOCKADDR)&addr, &addrLength); + if (!client) + { + printf("[Redirector][TCPHandler::IPv4Handler] Accept client failed: %d\n", WSAGetLastError()); + return; + } + + WaitForSingleObject(this->tcpLock, INFINITE); + if (this->tcpContext.find(addr.sin_port) == this->tcpContext.end()) + { + ReleaseMutex(this->tcpLock); + + closesocket(client); + continue; + } + ReleaseMutex(this->tcpLock); + + thread(&TCPHandler::Handle, this, client, addr.sin_port).detach(); + } +} + +void TCPHandler::IPv6() +{ + while (this->Started && this->IPv6Socket) + { + + } +} + +void TCPHandler::Handle(SOCKET client, USHORT side) +{ + SOCKADDR_IN addr; + addr.sin_family = AF_INET; + addr.sin_addr.S_un.S_addr = htonl(INADDR_LOOPBACK); + addr.sin_port = htons(this->tcpPort); + + WaitForSingleObject(this->tcpLock, INFINITE); + auto data = this->tcpContext[side]; + ReleaseMutex(this->tcpLock); + + auto remote = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (!remote) + { + printf("[Redirector][TCPHandler::Handle] Create socket failed: %d\n", WSAGetLastError()); + + closesocket(client); + return; + } + + if (connect(remote, (PSOCKADDR)&addr, sizeof(SOCKADDR_IN)) != NO_ERROR) + { + printf("[Redirector][TCPHandler::Handle] Connect to remote failed: %d\n", WSAGetLastError()); + + closesocket(client); + closesocket(remote); + return; + } } diff --git a/Redirector/TCPHandler.h b/Redirector/TCPHandler.h index e92cd02d..d348dad4 100644 --- a/Redirector/TCPHandler.h +++ b/Redirector/TCPHandler.h @@ -1,16 +1,33 @@ #pragma once #ifndef TCPHANDLER_H #define TCPHANDLER_H -#include +#include "Based.h" + +typedef struct _TCPINFO { + DWORD PID; + SOCKADDR Target; +} TCPINFO, * PTCPINFO; typedef class TCPHandler { public: - TCPHandler(); - ~TCPHandler(); + TCPHandler(USHORT tcpPort); BOOL init(); void free(); + + HANDLE tcpLock = NULL; + map tcpContext; +private: + void IPv4(); + void IPv6(); + void Handle(SOCKET client, USHORT side); + + USHORT tcpPort = 0; + + BOOL Started = FALSE; + SOCKET IPv4Socket = NULL; + SOCKET IPv6Socket = NULL; } *PTCPHandler; #endif diff --git a/Redirector/UDPHandler.cpp b/Redirector/UDPHandler.cpp index 1e8da97e..4b6e4002 100644 --- a/Redirector/UDPHandler.cpp +++ b/Redirector/UDPHandler.cpp @@ -1 +1,11 @@ #include "UDPHandler.h" + +BOOL UDPHandler::init() +{ + return 0; +} + +void UDPHandler::free() +{ + +} diff --git a/Redirector/UDPHandler.h b/Redirector/UDPHandler.h index fa8cbfa8..a0e0e74c 100644 --- a/Redirector/UDPHandler.h +++ b/Redirector/UDPHandler.h @@ -1,5 +1,17 @@ #pragma once #ifndef UDPHANDLER_H #define UDPHANDLER_H +#include "Based.h" + +typedef struct _UDPINFO { + SOCKET Socket; +} UDPINFO, * PUDPINFO; + +typedef class UDPHandler +{ +public: + BOOL init(); + void free(); +} *PUDPHandler; #endif diff --git a/Redirector/Utils.cpp b/Redirector/Utils.cpp index 1d1ccbfa..bbd9f881 100644 --- a/Redirector/Utils.cpp +++ b/Redirector/Utils.cpp @@ -1,43 +1 @@ #include "Utils.h" - -#include "Data.h" - -USHORT IPv4Checksum(PBYTE buffer, ULONG64 size) -{ - UINT32 sum = 0; - for (int i = 0; i < size; i += 2) - { - sum += (buffer[i] << 8) + buffer[i + 1]; - } - - if ((size % 2) == 1) - { - sum += buffer[size - 1] << 8; - } - - while (sum > 0xffff) - { - sum = (sum >> 16) + (sum & 0xffff); - } - - return ~sum & 0xffff; -} - -USHORT ICMPChecksum(PBYTE buffer, ULONG64 size) -{ - UINT32 sum = 0; - for (int i = 0; i < size; i += 2) - { - sum += buffer[i] + (buffer[i + 1] << 8); - } - - if ((size % 2) == 1) - { - sum += buffer[size - 1]; - } - - sum = (sum >> 16) + (sum & 0xffff); - sum += (sum >> 16); - - return ~sum & 0xffff; -} diff --git a/Redirector/Utils.h b/Redirector/Utils.h index 37031eca..b1bddcfe 100644 --- a/Redirector/Utils.h +++ b/Redirector/Utils.h @@ -1,9 +1,5 @@ #pragma once #ifndef UTILS_H #define UTILS_H -#include - -USHORT IPv4Checksum(PBYTE buffer, ULONG64 size); -USHORT ICMPChecksum(PBYTE buffer, ULONG64 size); #endif