Skip to content

Commit

Permalink
Increment MaxNumFilters registry key if necessary. nmap/nmap#572
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Apr 19, 2018
1 parent d96fa32 commit 0b09cbe
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packetWin7/NPFInstall/NPFInstall/NPFInstall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ int _tmain(int argc, _TCHAR* argv[])
{
if (strArgs[1] == _T("-i"))
{
BOOL first_try = TRUE;
tryagain_i:
bWiFiService = FALSE;
bSuccess = PacketInstallDriver60();
if (bSuccess)
Expand All @@ -344,6 +346,11 @@ int _tmain(int argc, _TCHAR* argv[])
DWORD err = GetLastError();
if (err == NETCFG_E_MAX_FILTER_LIMIT) {
_tprintf(_T("Too many filters installed!\n"));
if (first_try && IncrementRegistryDword(_T("SYSTEM\\CurrentControlSet\\Control\\Network"), _T("MaxNumFilters"), 14))
{
first_try = FALSE;
goto tryagain_i;
}
}
else {
_tprintf(_T("Unknown error! %x\n"), err);
Expand All @@ -355,6 +362,8 @@ int _tmain(int argc, _TCHAR* argv[])
}
if (strArgs[1] == _T("-i2"))
{
BOOL first_try = TRUE;
tryagain_i2:
bWiFiService = TRUE;
bSuccess = PacketInstallDriver60();
if (bSuccess)
Expand All @@ -368,6 +377,11 @@ int _tmain(int argc, _TCHAR* argv[])
DWORD err = GetLastError();
if (err == NETCFG_E_MAX_FILTER_LIMIT) {
_tprintf(_T("Too many filters installed!\n"));
if (first_try && IncrementRegistryDword(_T("SYSTEM\\CurrentControlSet\\Control\\Network"), _T("MaxNumFilters"), 14))
{
first_try = FALSE;
goto tryagain_i2;
}
}
else {
_tprintf(_T("Unknown error! %x\n"), err);
Expand Down
52 changes: 52 additions & 0 deletions packetWin7/NPFInstall/NPFInstall/RegUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,58 @@ BOOL WriteStrToRegistry(LPCTSTR strSubKey, LPCTSTR strValueName, LPCTSTR strDevi
return TRUE;
}

BOOL IncrementRegistryDword(LPCTSTR strSubKey, LPCTSTR strValueName, DWORD maxValue)
{
LONG Status;
HKEY hNpcapKey;
DWORD dwCurrent;
DWORD dwSize;
dwSize = sizeof(dwCurrent);

TRACE_ENTER();
TRACE_PRINT2("IncrementRegistryDword: executing, strSubKey = %s, strValueName = %s",
strSubKey, strValueName);

Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strSubKey, 0, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hNpcapKey);
if (Status == ERROR_SUCCESS)
{
Status = RegGetValue(hNpcapKey, NULL, strValueName, RRF_RT_REG_DWORD, NULL, &dwCurrent, &dwSize);
if (Status != ERROR_SUCCESS)
{
TRACE_PRINT1("RegGetValue: error, errCode = 0x%08x.", Status);
RegCloseKey(hNpcapKey);
TRACE_EXIT();
return FALSE;
}
if (dwCurrent >= maxValue)
{
TRACE_PRINT2("Current value %d is greater than max value %d", dwCurrent, maxValue);
RegCloseKey(hNpcapKey);
TRACE_EXIT();
return FALSE;
}
dwCurrent += 1;
Status = RegSetValueEx(hNpcapKey, strValueName, 0, REG_DWORD, (PBYTE)&dwCurrent, sizeof(dwCurrent));
if (Status != ERROR_SUCCESS)
{
TRACE_PRINT1("RegSetValueEx: error, errCode = 0x%08x.", Status);
RegCloseKey(hNpcapKey);
TRACE_EXIT();
return FALSE;
}
RegCloseKey(hNpcapKey);
}
else
{
TRACE_PRINT1("RegOpenKeyEx: error, errCode = 0x%08x.", Status);
TRACE_EXIT();
return FALSE;
}

TRACE_EXIT();
return TRUE;
}

BOOL DeleteValueFromRegistry(LPCTSTR strSubKey, LPCTSTR strValueName)
{
LONG Status;
Expand Down
1 change: 1 addition & 0 deletions packetWin7/NPFInstall/NPFInstall/RegUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef std::basic_string<TCHAR> tstring;

BOOL WriteStrToRegistry(LPCTSTR strSubKey, LPCTSTR strValueName, LPCTSTR strDeviceName, DWORD dwSamDesired);
BOOL DeleteValueFromRegistry(LPCTSTR strSubKey, LPCTSTR strValueName);
BOOL IncrementRegistryDword(LPCTSTR strSubKey, LPCTSTR strValueName, DWORD maxValue);

tstring printAdapterNames(vector<tstring> nstr);

Expand Down

0 comments on commit 0b09cbe

Please sign in to comment.