diff --git a/Redirector/Based.cpp b/Redirector/Based.cpp index 63489962..6a187502 100644 --- a/Redirector/Based.cpp +++ b/Redirector/Based.cpp @@ -2,6 +2,7 @@ bool filterLoopback = false; bool filterIntranet = false; +bool filterParent = false; bool filterICMP = true; bool filterTCP = true; bool filterUDP = true; diff --git a/Redirector/Based.h b/Redirector/Based.h index bc907638..50db46a1 100644 --- a/Redirector/Based.h +++ b/Redirector/Based.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -26,6 +27,7 @@ using namespace std; typedef enum _AIO_TYPE { AIO_FILTERLOOPBACK, AIO_FILTERINTRANET, + AIO_FILTERPARENT, AIO_FILTERICMP, AIO_FILTERTCP, AIO_FILTERUDP, diff --git a/Redirector/EventHandler.cpp b/Redirector/EventHandler.cpp index a342062a..b5d19a3e 100644 --- a/Redirector/EventHandler.cpp +++ b/Redirector/EventHandler.cpp @@ -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; } diff --git a/Redirector/README.md b/Redirector/README.md index 3d604f60..12e20ede 100644 --- a/Redirector/README.md +++ b/Redirector/README.md @@ -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, diff --git a/Redirector/Redirector.cpp b/Redirector/Redirector.cpp index a53389c4..f0090cf6 100644 --- a/Redirector/Redirector.cpp +++ b/Redirector/Redirector.cpp @@ -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;