mirror of
https://github.com/bol-van/zapret.git
synced 2024-11-26 20:20:53 +03:00
Compare commits
No commits in common. "0d0fe6060ee43028be4e86cfea23f3e5529c508f" and "d165c410ec40384d1ef940a39ba42c651486dc4f" have entirely different histories.
0d0fe6060e
...
d165c410ec
Binary file not shown.
Binary file not shown.
120
nfq/darkmagic.c
120
nfq/darkmagic.c
@ -963,7 +963,8 @@ void tcp_rewrite_winsize(struct tcphdr *tcp, uint16_t winsize, uint8_t scale_fac
|
|||||||
|
|
||||||
static HANDLE w_filter = NULL;
|
static HANDLE w_filter = NULL;
|
||||||
static OVERLAPPED ovl = { .hEvent = NULL };
|
static OVERLAPPED ovl = { .hEvent = NULL };
|
||||||
static const struct str_list_head *wlan_filter_ssid = NULL, *nlm_filter_net = NULL;
|
static const struct str_list_head *wlan_filter_ssid = NULL;
|
||||||
|
static const struct str_list_head *nlm_filter_net = NULL;
|
||||||
static DWORD logical_net_filter_tick=0;
|
static DWORD logical_net_filter_tick=0;
|
||||||
uint32_t w_win32_error=0;
|
uint32_t w_win32_error=0;
|
||||||
INetworkListManager* pNetworkListManager=NULL;
|
INetworkListManager* pNetworkListManager=NULL;
|
||||||
@ -990,81 +991,22 @@ static bool str2guid(const char* str, GUID *guid)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *sNetworkCards="SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
|
|
||||||
// get adapter name from guid string
|
|
||||||
static bool AdapterID2Name(const GUID *guid,char *name,DWORD name_len)
|
|
||||||
{
|
|
||||||
char sguid[39],sidx[32],val[256];
|
|
||||||
HKEY hkNetworkCards,hkCard;
|
|
||||||
DWORD dwIndex,dwLen;
|
|
||||||
bool bRet = false;
|
|
||||||
|
|
||||||
if (name_len<2) return false;
|
|
||||||
|
|
||||||
if ((w_win32_error = RegOpenKeyExA(HKEY_LOCAL_MACHINE,sNetworkCards,0,KEY_ENUMERATE_SUB_KEYS,&hkNetworkCards)) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
guid2str(guid, sguid+1);
|
|
||||||
sguid[0]='{';
|
|
||||||
sguid[37]='}';
|
|
||||||
sguid[38]='\0';
|
|
||||||
|
|
||||||
for (dwIndex=0;;dwIndex++)
|
|
||||||
{
|
|
||||||
dwLen=sizeof(sidx)-1;
|
|
||||||
w_win32_error = RegEnumKeyExA(hkNetworkCards,dwIndex,sidx,&dwLen,NULL,NULL,NULL,NULL);
|
|
||||||
if (w_win32_error == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
sidx[dwLen]='\0';
|
|
||||||
|
|
||||||
if ((w_win32_error = RegOpenKeyExA(hkNetworkCards,sidx,0,KEY_QUERY_VALUE,&hkCard)) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
dwLen=sizeof(val)-1;
|
|
||||||
if ((w_win32_error = RegQueryValueExA(hkCard,"ServiceName",NULL,NULL,val,&dwLen)) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
val[dwLen]='\0';
|
|
||||||
if (!strcmp(val,sguid))
|
|
||||||
{
|
|
||||||
name_len--;
|
|
||||||
if ((w_win32_error = RegQueryValueExA(hkCard,"Description",NULL,NULL,name,&name_len)) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
name[name_len]='\0';
|
|
||||||
bRet = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RegCloseKey(hkCard);
|
|
||||||
}
|
|
||||||
if (bRet) break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
RegCloseKey(hkNetworkCards);
|
|
||||||
}
|
|
||||||
|
|
||||||
return bRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool win_dark_init(const struct str_list_head *ssid_filter, const struct str_list_head *nlm_filter)
|
bool win_dark_init(const struct str_list_head *ssid_filter, const struct str_list_head *nlm_filter)
|
||||||
{
|
{
|
||||||
win_dark_deinit();
|
win_dark_deinit();
|
||||||
if (LIST_EMPTY(ssid_filter)) ssid_filter=NULL;
|
wlan_filter_ssid = LIST_EMPTY(ssid_filter) ? NULL : ssid_filter;
|
||||||
if (LIST_EMPTY(nlm_filter)) nlm_filter=NULL;
|
nlm_filter_net = LIST_EMPTY(nlm_filter) ? NULL : nlm_filter;
|
||||||
if (nlm_filter)
|
if (nlm_filter_net)
|
||||||
{
|
{
|
||||||
if (SUCCEEDED(w_win32_error = CoInitialize(NULL)))
|
if (SUCCEEDED(w_win32_error = CoInitialize(NULL)))
|
||||||
{
|
{
|
||||||
if (FAILED(w_win32_error = CoCreateInstance(&CLSID_NetworkListManager, NULL, CLSCTX_ALL, &IID_INetworkListManager, (LPVOID*)&pNetworkListManager)))
|
if (FAILED(w_win32_error = CoCreateInstance(&CLSID_NetworkListManager, NULL, CLSCTX_ALL, &IID_INetworkListManager, (LPVOID*)&pNetworkListManager)))
|
||||||
{
|
{
|
||||||
CoUninitialize();
|
win_dark_deinit();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
nlm_filter_net = nlm_filter;
|
|
||||||
wlan_filter_ssid = ssid_filter;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool win_dark_deinit(void)
|
bool win_dark_deinit(void)
|
||||||
@ -1088,64 +1030,40 @@ bool nlm_list(bool bAll)
|
|||||||
INetworkListManager* pNetworkListManager;
|
INetworkListManager* pNetworkListManager;
|
||||||
if (SUCCEEDED(w_win32_error = CoCreateInstance(&CLSID_NetworkListManager, NULL, CLSCTX_ALL, &IID_INetworkListManager, (LPVOID*)&pNetworkListManager)))
|
if (SUCCEEDED(w_win32_error = CoCreateInstance(&CLSID_NetworkListManager, NULL, CLSCTX_ALL, &IID_INetworkListManager, (LPVOID*)&pNetworkListManager)))
|
||||||
{
|
{
|
||||||
IEnumNetworks* pEnumNetworks;
|
IEnumNetworks* pEnum;
|
||||||
if (SUCCEEDED(w_win32_error = pNetworkListManager->lpVtbl->GetNetworks(pNetworkListManager, NLM_ENUM_NETWORK_ALL, &pEnumNetworks)))
|
if (SUCCEEDED(w_win32_error = pNetworkListManager->lpVtbl->GetNetworks(pNetworkListManager, NLM_ENUM_NETWORK_ALL, &pEnum)))
|
||||||
{
|
{
|
||||||
INetwork *pNet;
|
INetwork* pNet;
|
||||||
INetworkConnection *pConn;
|
|
||||||
IEnumNetworkConnections *pEnumConnections;
|
|
||||||
VARIANT_BOOL bIsConnected, bIsConnectedInet;
|
VARIANT_BOOL bIsConnected, bIsConnectedInet;
|
||||||
NLM_NETWORK_CATEGORY category;
|
GUID idNet;
|
||||||
GUID idNet, idAdapter;
|
|
||||||
BSTR bstrName;
|
BSTR bstrName;
|
||||||
char Name[128],Name2[128];
|
char Name[128];
|
||||||
int connected;
|
int connected;
|
||||||
for (connected = 1; connected >= !bAll; connected--)
|
for (connected = 1; connected >= !bAll; connected--)
|
||||||
{
|
{
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (FAILED(w_win32_error = pEnumNetworks->lpVtbl->Next(pEnumNetworks, 1, &pNet, NULL)))
|
if (FAILED(w_win32_error = pEnum->lpVtbl->Next(pEnum, 1, &pNet, NULL)))
|
||||||
{
|
{
|
||||||
bRet = false;
|
bRet = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (w_win32_error != S_OK) break;
|
if (!pNet) break;
|
||||||
if (SUCCEEDED(w_win32_error = pNet->lpVtbl->get_IsConnected(pNet, &bIsConnected)) &&
|
if (SUCCEEDED(w_win32_error = pNet->lpVtbl->get_IsConnected(pNet, &bIsConnected)) &&
|
||||||
SUCCEEDED(w_win32_error = pNet->lpVtbl->get_IsConnectedToInternet(pNet, &bIsConnectedInet)) &&
|
SUCCEEDED(w_win32_error = pNet->lpVtbl->get_IsConnectedToInternet(pNet, &bIsConnectedInet)) &&
|
||||||
SUCCEEDED(w_win32_error = pNet->lpVtbl->GetNetworkId(pNet, &idNet)) &&
|
SUCCEEDED(w_win32_error = pNet->lpVtbl->GetNetworkId(pNet, &idNet)) &&
|
||||||
SUCCEEDED(w_win32_error = pNet->lpVtbl->GetCategory(pNet, &category)) &&
|
|
||||||
SUCCEEDED(w_win32_error = pNet->lpVtbl->GetName(pNet, &bstrName)))
|
SUCCEEDED(w_win32_error = pNet->lpVtbl->GetName(pNet, &bstrName)))
|
||||||
{
|
{
|
||||||
if (!!bIsConnected == connected)
|
if (!!bIsConnected == connected)
|
||||||
{
|
{
|
||||||
if (WideCharToMultiByte(CP_UTF8, 0, bstrName, -1, Name, sizeof(Name), NULL, NULL))
|
if (WideCharToMultiByte(CP_UTF8, 0, bstrName, -1, Name, sizeof(Name), NULL, NULL))
|
||||||
{
|
{
|
||||||
printf("Name : %s", Name);
|
printf("Name : %s", Name);
|
||||||
if (bIsConnected) printf(" (connected)");
|
if (bIsConnected) printf(" (connected)");
|
||||||
if (bIsConnectedInet) printf(" (inet)");
|
if (bIsConnectedInet) printf(" (inet)");
|
||||||
printf(" (%s)\n",
|
printf("\n");
|
||||||
category==NLM_NETWORK_CATEGORY_PUBLIC ? "public" :
|
|
||||||
category==NLM_NETWORK_CATEGORY_PRIVATE ? "private" :
|
|
||||||
category==NLM_NETWORK_CATEGORY_DOMAIN_AUTHENTICATED ? "domain" :
|
|
||||||
"unknown");
|
|
||||||
guid2str(&idNet, Name);
|
guid2str(&idNet, Name);
|
||||||
printf("NetID : %s\n", Name);
|
printf("NetID : %s\n", Name);
|
||||||
if (connected && SUCCEEDED(w_win32_error = pNet->lpVtbl->GetNetworkConnections(pNet, &pEnumConnections)))
|
|
||||||
{
|
|
||||||
while ((w_win32_error = pEnumConnections->lpVtbl->Next(pEnumConnections, 1, &pConn, NULL))==S_OK)
|
|
||||||
{
|
|
||||||
if (SUCCEEDED(w_win32_error = pConn->lpVtbl->GetAdapterId(pConn,&idAdapter)))
|
|
||||||
{
|
|
||||||
guid2str(&idAdapter, Name);
|
|
||||||
if (AdapterID2Name(&idAdapter,Name2,sizeof(Name2)))
|
|
||||||
printf("Adapter : %s (%s)\n", Name2, Name);
|
|
||||||
else
|
|
||||||
printf("Adapter : %s\n", Name);
|
|
||||||
}
|
|
||||||
pConn->lpVtbl->Release(pConn);
|
|
||||||
}
|
|
||||||
pEnumConnections->lpVtbl->Release(pEnumConnections);
|
|
||||||
}
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1162,9 +1080,9 @@ bool nlm_list(bool bAll)
|
|||||||
if (!bRet) break;
|
if (!bRet) break;
|
||||||
}
|
}
|
||||||
if (!bRet) break;
|
if (!bRet) break;
|
||||||
pEnumNetworks->lpVtbl->Reset(pEnumNetworks);
|
pEnum->lpVtbl->Reset(pEnum);
|
||||||
}
|
}
|
||||||
pEnumNetworks->lpVtbl->Release(pEnumNetworks);
|
pEnum->lpVtbl->Release(pEnum);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
bRet = false;
|
bRet = false;
|
||||||
@ -1206,7 +1124,7 @@ static bool nlm_filter_match(const struct str_list_head *nlm_list)
|
|||||||
bRet = false;
|
bRet = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (w_win32_error != S_OK) break;
|
if (!pNet) break;
|
||||||
if (SUCCEEDED(w_win32_error = pNet->lpVtbl->GetNetworkId(pNet, &idNet)) &&
|
if (SUCCEEDED(w_win32_error = pNet->lpVtbl->GetNetworkId(pNet, &idNet)) &&
|
||||||
SUCCEEDED(w_win32_error = pNet->lpVtbl->GetName(pNet, &bstrName)))
|
SUCCEEDED(w_win32_error = pNet->lpVtbl->GetName(pNet, &bstrName)))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user