[Redirector] Support sub-process proxy

This commit is contained in:
Connection Refused
2021-10-04 22:06:41 +08:00
parent c0e35287af
commit a28f0dacf9
5 changed files with 54 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
bool filterLoopback = false;
bool filterIntranet = false;
bool filterParent = false;
bool filterICMP = true;
bool filterTCP = true;
bool filterUDP = true;

View File

@@ -17,6 +17,7 @@
#include <WinSock2.h>
#include <ws2ipdef.h>
#include <WS2tcpip.h>
#include <tlhelp32.h>
#include <Windows.h>
#include <nfapi.h>
@@ -26,6 +27,7 @@ using namespace std;
typedef enum _AIO_TYPE {
AIO_FILTERLOOPBACK,
AIO_FILTERINTRANET,
AIO_FILTERPARENT,
AIO_FILTERICMP,
AIO_FILTERTCP,
AIO_FILTERUDP,

View File

@@ -3,6 +3,7 @@
#include "DNSHandler.h"
#include "TCPHandler.h"
extern bool filterParent;
extern bool filterTCP;
extern bool filterUDP;
extern bool filterDNS;
@@ -82,16 +83,55 @@ bool checkBypassName(DWORD id)
bool checkHandleName(DWORD id)
{
auto name = GetProcessName(id);
for (size_t i = 0; i < handleList.size(); i++)
{
if (regex_search(name, wregex(handleList[i])))
auto name = GetProcessName(id);
for (size_t i = 0; i < handleList.size(); i++)
{
return true;
if (regex_search(name, wregex(handleList[i])))
{
return true;
}
}
}
if (filterParent)
{
PROCESSENTRY32W PE;
memset(&PE, 0, sizeof(PROCESSENTRY32W));
PE.dwSize = sizeof(PROCESSENTRY32W);
auto hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE)
{
return false;
}
if (!Process32FirstW(hSnapshot, &PE))
{
CloseHandle(hSnapshot);
return false;
}
do {
if (PE.th32ProcessID == id)
{
auto name = GetProcessName(PE.th32ParentProcessID);
for (size_t i = 0; i < handleList.size(); i++)
{
if (regex_search(name, wregex(handleList[i])))
{
CloseHandle(hSnapshot);
return true;
}
}
}
} while (Process32NextW(hSnapshot, &PE));
CloseHandle(hSnapshot);
}
return false;
}

View File

@@ -3,6 +3,7 @@
typedef enum _AIO_TYPE {
AIO_FILTERLOOPBACK,
AIO_FILTERINTRANET,
AIO_FILTERPARENT,
AIO_FILTERICMP,
AIO_FILTERTCP,
AIO_FILTERUDP,
@@ -37,6 +38,7 @@ private enum NameList : int
{
AIO_FILTERLOOPBACK,
AIO_FILTERINTRANET,
AIO_FILTERPARENT,
AIO_FILTERICMP,
AIO_FILTERTCP,
AIO_FILTERUDP,

View File

@@ -5,6 +5,7 @@
extern bool filterLoopback;
extern bool filterIntranet;
extern bool filterParent;
extern bool filterICMP;
extern bool filterTCP;
extern bool filterUDP;
@@ -80,6 +81,9 @@ extern "C" {
case AIO_FILTERINTRANET:
filterIntranet = (wstring(value).find(L"false") == string::npos);
break;
case AIO_FILTERPARENT:
filterParent = (wstring(value).find(L"false") == string::npos);
break;
case AIO_FILTERICMP:
filterICMP = (wstring(value).find(L"false") == string::npos);
break;