Merge pull request #2832 from zeroZshadow/master
Properly scan for OpenVPN TAP adapters
This commit is contained in:
commit
90e05f7bea
|
@ -87,15 +87,19 @@ bool GetGUIDs(std::vector<std::basic_string<TCHAR>>& guids)
|
||||||
LONG status;
|
LONG status;
|
||||||
HKEY control_net_key;
|
HKEY control_net_key;
|
||||||
DWORD len;
|
DWORD len;
|
||||||
int i = 0;
|
DWORD cSubKeys = 0;
|
||||||
bool found_all = false;
|
|
||||||
|
|
||||||
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_READ, &control_net_key);
|
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_READ | KEY_QUERY_VALUE, &control_net_key);
|
||||||
|
|
||||||
if (status != ERROR_SUCCESS)
|
if (status != ERROR_SUCCESS)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while (!found_all)
|
status = RegQueryInfoKey(control_net_key, nullptr, nullptr, nullptr, &cSubKeys, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
|
||||||
|
|
||||||
|
if (status != ERROR_SUCCESS)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (DWORD i = 0; i < cSubKeys; i++)
|
||||||
{
|
{
|
||||||
TCHAR enum_name[256];
|
TCHAR enum_name[256];
|
||||||
TCHAR connection_string[256];
|
TCHAR connection_string[256];
|
||||||
|
@ -108,10 +112,8 @@ bool GetGUIDs(std::vector<std::basic_string<TCHAR>>& guids)
|
||||||
status = RegEnumKeyEx(control_net_key, i, enum_name,
|
status = RegEnumKeyEx(control_net_key, i, enum_name,
|
||||||
&len, nullptr, nullptr, nullptr, nullptr);
|
&len, nullptr, nullptr, nullptr, nullptr);
|
||||||
|
|
||||||
if (status == ERROR_NO_MORE_ITEMS)
|
if (status != ERROR_SUCCESS)
|
||||||
break;
|
continue;
|
||||||
else if (status != ERROR_SUCCESS)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_sntprintf(connection_string, sizeof(connection_string),
|
_sntprintf(connection_string, sizeof(connection_string),
|
||||||
_T("%s\\%s\\Connection"), NETWORK_CONNECTIONS_KEY, enum_name);
|
_T("%s\\%s\\Connection"), NETWORK_CONNECTIONS_KEY, enum_name);
|
||||||
|
@ -127,28 +129,23 @@ bool GetGUIDs(std::vector<std::basic_string<TCHAR>>& guids)
|
||||||
|
|
||||||
if (status != ERROR_SUCCESS || name_type != REG_SZ)
|
if (status != ERROR_SUCCESS || name_type != REG_SZ)
|
||||||
{
|
{
|
||||||
return false;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (IsTAPDevice(enum_name))
|
if (IsTAPDevice(enum_name))
|
||||||
{
|
{
|
||||||
guids.push_back(enum_name);
|
guids.push_back(enum_name);
|
||||||
//found_all = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RegCloseKey(connection_key);
|
RegCloseKey(connection_key);
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RegCloseKey(control_net_key);
|
RegCloseKey(control_net_key);
|
||||||
|
|
||||||
//if (!found_all)
|
return !guids.empty();
|
||||||
//return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenTAP(HANDLE& adapter, const std::basic_string<TCHAR>& device_guid)
|
bool OpenTAP(HANDLE& adapter, const std::basic_string<TCHAR>& device_guid)
|
||||||
|
@ -187,7 +184,7 @@ bool CEXIETHERNET::Activate()
|
||||||
if (Win32TAPHelper::OpenTAP(mHAdapter, device_guids.at(i)))
|
if (Win32TAPHelper::OpenTAP(mHAdapter, device_guids.at(i)))
|
||||||
{
|
{
|
||||||
INFO_LOG(SP1, "OPENED %s", device_guids.at(i).c_str());
|
INFO_LOG(SP1, "OPENED %s", device_guids.at(i).c_str());
|
||||||
i = device_guids.size();
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mHAdapter == INVALID_HANDLE_VALUE)
|
if (mHAdapter == INVALID_HANDLE_VALUE)
|
||||||
|
@ -248,19 +245,16 @@ bool CEXIETHERNET::SendFrame(u8 *frame, u32 size)
|
||||||
DEBUG_LOG(SP1, "SendFrame %x\n%s",
|
DEBUG_LOG(SP1, "SendFrame %x\n%s",
|
||||||
size, ArrayToString(frame, size, 0x10).c_str());
|
size, ArrayToString(frame, size, 0x10).c_str());
|
||||||
|
|
||||||
DWORD numBytesWrit;
|
|
||||||
OVERLAPPED overlap;
|
OVERLAPPED overlap;
|
||||||
ZeroMemory(&overlap, sizeof(overlap));
|
ZeroMemory(&overlap, sizeof(overlap));
|
||||||
|
|
||||||
if (!WriteFile(mHAdapter, frame, size, &numBytesWrit, &overlap))
|
//WriteFile will always return false because the TAP handle is async
|
||||||
{
|
WriteFile(mHAdapter, frame, size, NULL, &overlap);
|
||||||
DWORD res = GetLastError();
|
|
||||||
ERROR_LOG(SP1, "Failed to send packet with error 0x%X", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (numBytesWrit != size)
|
DWORD res = GetLastError();
|
||||||
|
if (res != ERROR_IO_PENDING)
|
||||||
{
|
{
|
||||||
ERROR_LOG(SP1, "BBA SendFrame %i only got %i bytes sent!", size, numBytesWrit);
|
ERROR_LOG(SP1, "Failed to send packet with error 0x%X", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always report the packet as being sent successfully, even though it might be a lie
|
// Always report the packet as being sent successfully, even though it might be a lie
|
||||||
|
|
Loading…
Reference in New Issue