diff --git a/src/controls.c b/src/controls.c
index e7c12742..f5a6183b 100644
--- a/src/controls.c
+++ b/src/controls.c
@@ -14,8 +14,7 @@ VOID _app_getapptooltipstring (
R_STRINGBUILDER sb;
PR_STRING path = NULL;
PITEM_APP ptr_app;
- PR_STRING string;
- PR_STRING value;
+ PR_STRING string, value;
ptr_app = _app_getappitem (app_hash);
@@ -51,12 +50,11 @@ VOID _app_getapptooltipstring (
if (path)
{
_r_obj_appendstringbuilder2 (buffer, &path->sr);
-
_r_obj_appendstringbuilder (buffer, SZ_CRLF);
}
// file information
- _r_obj_initializestringbuilder (&sb, 512);
+ _r_obj_initializestringbuilder (&sb, 0);
// file display name
if (ptr_app)
@@ -186,7 +184,7 @@ VOID _app_getapptooltipstring (
// app notes
if (ptr_app)
{
- _r_obj_initializestringbuilder (&sb, 512);
+ _r_obj_initializestringbuilder (&sb, 0);
// app type
if (ptr_app->type == DATA_APP_NETWORK)
@@ -242,10 +240,9 @@ VOID _app_getapptooltipstring (
if (!_r_obj_isstringempty2 (string))
{
- _r_obj_insertstringbuilder (&sb, 0, L":\r\n");
- _r_obj_insertstringbuilder (&sb, 0, _r_locale_getstring (IDS_NOTES));
+ _r_obj_insertstringbuilderformat (&sb, 0, L"%s:\r\n", _r_locale_getstring (IDS_NOTES));
- _r_obj_appendstringbuilder2 (buffer, &string->sr);
+ _r_obj_appendstringbuilder2 (buffer, &sb.string->sr);
}
_r_obj_deletestringbuilder (&sb);
@@ -298,16 +295,15 @@ PR_STRING _app_gettooltipbylparam (
_In_ LONG_PTR lparam
)
{
- R_STRINGBUILDER sb;
+ PR_STRING string1, string2;
PITEM_NETWORK ptr_network;
+ R_STRINGBUILDER sb;
PITEM_RULE ptr_rule;
- PR_STRING string1;
- PR_STRING string2;
PITEM_LOG ptr_log;
UNREFERENCED_PARAMETER (hwnd);
- _r_obj_initializestringbuilder (&sb, 512);
+ _r_obj_initializestringbuilder (&sb, 0);
switch (listview_id)
{
@@ -331,8 +327,8 @@ PR_STRING _app_gettooltipbylparam (
break;
// rule address
- string1 = _app_rulesexpandrules (ptr_rule->rule_remote, SZ_CRLF SZ_TAB);
- string2 = _app_rulesexpandrules (ptr_rule->rule_local, SZ_CRLF SZ_TAB);
+ string1 = _app_rulesexpandrules (ptr_rule->rule_remote);
+ string2 = _app_rulesexpandrules (ptr_rule->rule_local);
_r_obj_appendstringbuilderformat (
&sb,
@@ -356,7 +352,7 @@ PR_STRING _app_gettooltipbylparam (
_r_obj_dereference (string2);
// rule apps
- if (ptr_rule->is_forservices || !_r_obj_isempty (ptr_rule->apps))
+ if (ptr_rule->is_fordriver || ptr_rule->is_forservice || !_r_obj_isempty (ptr_rule->apps))
{
string1 = _app_rulesexpandapps (ptr_rule, TRUE, SZ_TAB_CRLF);
@@ -389,7 +385,6 @@ PR_STRING _app_gettooltipbylparam (
);
_r_obj_appendstringbuilder2 (&sb, &string1->sr);
-
_r_obj_appendstringbuilder2 (&sb, &ptr_rule->comment->sr);
_r_obj_dereference (string1);
@@ -455,7 +450,7 @@ PR_STRING _app_gettooltipbylparam (
return NULL;
}
-VOID _app_settab_id (
+BOOLEAN _app_settab_id (
_In_ HWND hwnd,
_In_ INT page_id
)
@@ -464,62 +459,54 @@ VOID _app_settab_id (
HWND hctrl;
if (!page_id)
- return;
+ return FALSE;
hctrl = GetDlgItem (hwnd, page_id);
if (!hctrl)
- return;
+ return FALSE;
tab_context = _app_listview_getcontext (hwnd, INT_ERROR);
if (!tab_context || (tab_context->listview_id == page_id && _r_wnd_isvisible (hctrl, FALSE)))
- return;
+ return FALSE;
for (INT i = 0; i < _r_tab_getitemcount (hwnd, IDC_TAB); i++)
{
tab_context = _app_listview_getcontext (hwnd, i);
if (tab_context && tab_context->listview_id == page_id)
- {
- _r_tab_selectitem (hwnd, IDC_TAB, i);
-
- return;
- }
+ return (_r_tab_selectitem (hwnd, IDC_TAB, i) != INT_ERROR);
}
if (page_id != IDC_APPS_PROFILE)
- _app_settab_id (hwnd, IDC_APPS_PROFILE);
+ return _app_settab_id (hwnd, IDC_APPS_PROFILE);
+
+ return FALSE;
}
-LPWSTR _app_getstateaction (
+LPCWSTR _app_getstateaction (
_In_ ENUM_INSTALL_TYPE install_type
)
{
- UINT locale_id;
-
switch (install_type)
{
+ case INSTALL_DISABLED:
+ {
+ return _r_locale_getstring (IDS_TRAY_START);
+ }
+
case INSTALL_ENABLED:
case INSTALL_ENABLED_TEMPORARY:
{
- locale_id = IDS_TRAY_STOP;
- break;
- }
-
- case INSTALL_DISABLED:
- {
- locale_id = IDS_TRAY_START;
- break;
+ return _r_locale_getstring (IDS_TRAY_STOP);
}
default:
{
- return NULL;
+ return NULL; // never match!
}
}
-
- return _r_locale_getstring (locale_id);
}
HBITMAP _app_getstatebitmap (
@@ -528,27 +515,35 @@ HBITMAP _app_getstatebitmap (
{
switch (install_type)
{
+ case INSTALL_DISABLED:
+ {
+ return config.hbmp_enable;
+ }
+
case INSTALL_ENABLED:
case INSTALL_ENABLED_TEMPORARY:
{
return config.hbmp_disable;
}
- case INSTALL_DISABLED:
+ default:
{
- return config.hbmp_enable;
+ return NULL; // never match!
}
}
-
- return NULL;
}
-INT _app_getstateicon (
+LONG _app_getstateicon (
_In_ ENUM_INSTALL_TYPE install_type
)
{
switch (install_type)
{
+ case INSTALL_DISABLED:
+ {
+ return IDI_INACTIVE;
+ }
+
case INSTALL_ENABLED:
case INSTALL_ENABLED_TEMPORARY:
{
@@ -566,42 +561,38 @@ LPCWSTR _app_getstatelocale (
_In_ ENUM_INSTALL_TYPE install_type
)
{
- UINT locale_id;
-
switch (install_type)
{
+ case INSTALL_DISABLED:
+ {
+ return _r_locale_getstring (IDS_STATUS_FILTERS_INACTIVE);
+ }
+
case INSTALL_ENABLED:
{
- locale_id = IDS_STATUS_FILTERS_ACTIVE;
- break;
+ return _r_locale_getstring (IDS_STATUS_FILTERS_ACTIVE);
}
case INSTALL_ENABLED_TEMPORARY:
{
- locale_id = IDS_STATUS_FILTERS_ACTIVE_TEMP;
- break;
- }
-
- case INSTALL_DISABLED:
- {
- locale_id = IDS_STATUS_FILTERS_INACTIVE;
- break;
+ return _r_locale_getstring (IDS_STATUS_FILTERS_ACTIVE_TEMP);
}
default:
{
- return NULL;
+ return NULL; // never match!
}
}
-
- return _r_locale_getstring (locale_id);
}
BOOLEAN _app_initinterfacestate (
- _In_ HWND hwnd,
+ _In_opt_ HWND hwnd,
_In_ BOOLEAN is_forced
)
{
+ if (!hwnd)
+ return FALSE;
+
if (is_forced || _r_toolbar_isenabled (config.hrebar, IDC_TOOLBAR, IDM_TRAY_START))
{
_r_toolbar_enablebutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_START, FALSE);
@@ -616,21 +607,17 @@ BOOLEAN _app_initinterfacestate (
}
VOID _app_restoreinterfacestate (
- _In_ HWND hwnd,
+ _In_opt_ HWND hwnd,
_In_ BOOLEAN is_enabled
)
{
- ENUM_INSTALL_TYPE install_type;
-
- if (!is_enabled)
+ if (!hwnd || !is_enabled)
return;
- install_type = _wfp_getinstalltype ();
-
_r_toolbar_enablebutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_START, TRUE);
_r_toolbar_enablebutton (config.hrebar, IDC_TOOLBAR, IDM_REFRESH, TRUE);
- _r_status_settext (hwnd, IDC_STATUSBAR, 0, _app_getstatelocale (install_type));
+ _r_status_settext (hwnd, IDC_STATUSBAR, 0, _app_getstatelocale (_wfp_getinstalltype ()));
}
VOID _app_setinterfacestate (
@@ -639,11 +626,8 @@ VOID _app_setinterfacestate (
)
{
ENUM_INSTALL_TYPE install_type;
- HICON hico_sm;
- HICON hico_big;
- LONG icon_small;
- LONG icon_large;
- INT icon_id;
+ HICON hico_big, hico_small;
+ LONG icon_id, icon_large, icon_small;
BOOLEAN is_filtersinstalled;
install_type = _wfp_getinstalltype ();
@@ -654,12 +638,12 @@ VOID _app_setinterfacestate (
icon_id = _app_getstateicon (install_type);
- hico_sm = _r_sys_loadsharedicon (_r_sys_getimagebase (), MAKEINTRESOURCE (icon_id), icon_small);
+ hico_small = _r_sys_loadsharedicon (_r_sys_getimagebase (), MAKEINTRESOURCE (icon_id), icon_small);
hico_big = _r_sys_loadsharedicon (_r_sys_getimagebase (), MAKEINTRESOURCE (icon_id), icon_large);
- _r_wnd_seticon (hwnd, hico_sm, hico_big);
+ _r_wnd_seticon (hwnd, hico_small, hico_big);
- //_r_status_seticon (hwnd, IDC_STATUSBAR, 0, hico_sm);
+ //_r_status_seticon (hwnd, IDC_STATUSBAR, 0, hico_small);
if (!_wfp_isfiltersapplying ())
_r_status_settext (hwnd, IDC_STATUSBAR, 0, _app_getstatelocale (install_type));
@@ -674,17 +658,13 @@ VOID _app_settrayicon (
_In_ ENUM_INSTALL_TYPE install_type
)
{
- HICON current_handle;
- HICON new_handle;
- LONG dpi_value;
- LONG icon_size;
- INT icon_id;
+ HICON current_handle, new_handle;
+ LONG icon_id, icon_size;
- dpi_value = _r_dc_gettaskbardpi ();
- icon_size = _r_dc_getsystemmetrics (SM_CXSMICON, dpi_value);
+ icon_size = _r_dc_getsystemmetrics (SM_CXSMICON, _r_dc_gettaskbardpi ());
icon_id = _app_getstateicon (install_type);
- current_handle = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.htray_icon, NULL, config.htray_icon);
+ current_handle = (HICON)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.htray_icon, NULL, config.htray_icon);
if (current_handle)
DestroyIcon (current_handle);
@@ -693,7 +673,7 @@ VOID _app_settrayicon (
_r_tray_setinfo (hwnd, &GUID_TrayIcon, new_handle, _r_app_getname ());
- current_handle = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.htray_icon, new_handle, NULL);
+ current_handle = (HICON)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.htray_icon, new_handle, NULL);
if (current_handle)
DestroyIcon (current_handle);
@@ -704,63 +684,45 @@ VOID _app_imagelist_init (
_In_ LONG dpi_value
)
{
- UINT toolbar_ids[] = {
- IDP_SHIELD_ENABLE,
- IDP_SHIELD_DISABLE,
- IDP_REFRESH,
- IDP_SETTINGS,
- IDP_NOTIFICATIONS,
- IDP_LOG,
- IDP_LOGOPEN,
- IDP_LOGCLEAR,
- IDP_ADD,
- IDP_DONATE,
- IDP_LOGUI,
- };
-
- ULONG rules_ids[] = {
- IDP_ALLOW,
- IDP_BLOCK
- };
-
+ ULONG toolbar_ids[] = {IDP_SHIELD_ENABLE, IDP_SHIELD_DISABLE, IDP_REFRESH, IDP_SETTINGS, IDP_NOTIFICATIONS, IDP_LOG, IDP_LOGOPEN, IDP_LOGCLEAR, IDP_ADD, IDP_DONATE, IDP_LOGUI};
+ ULONG rules_ids[] = {IDP_ALLOW, IDP_BLOCK};
HBITMAP hbitmap;
- LONG icon_size_toolbar;
- LONG icon_small;
- LONG icon_large;
+ LONG size_large, size_small, size_toolbar;
+ NTSTATUS status;
SAFE_DELETE_OBJECT (config.hbmp_enable);
SAFE_DELETE_OBJECT (config.hbmp_disable);
SAFE_DELETE_OBJECT (config.hbmp_allow);
SAFE_DELETE_OBJECT (config.hbmp_block);
- icon_small = _r_dc_getsystemmetrics (SM_CXSMICON, dpi_value);
- icon_large = _r_dc_getsystemmetrics (SM_CXICON, dpi_value);
+ size_small = _r_dc_getsystemmetrics (SM_CXSMICON, dpi_value);
+ size_large = _r_dc_getsystemmetrics (SM_CXICON, dpi_value);
- icon_size_toolbar = _r_calc_clamp (_r_dc_getdpi (_r_config_getlong (L"ToolbarSize", PR_SIZE_ITEMHEIGHT, NULL), dpi_value), icon_small, icon_large);
+ size_toolbar = _r_calc_clamp (_r_dc_getdpi (_r_config_getlong (L"ToolbarSize", PR_SIZE_ITEMHEIGHT, NULL), dpi_value), size_small, size_large);
- _r_res_loadimage (&config.hbmp_enable, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (IDP_SHIELD_ENABLE), &GUID_ContainerFormatPng, icon_small, icon_small);
- _r_res_loadimage (&config.hbmp_disable, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (IDP_SHIELD_DISABLE), &GUID_ContainerFormatPng, icon_small, icon_small);
+ _r_res_loadimage (&config.hbmp_enable, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (IDP_SHIELD_ENABLE), &GUID_ContainerFormatPng, size_small, size_small);
+ _r_res_loadimage (&config.hbmp_disable, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (IDP_SHIELD_DISABLE), &GUID_ContainerFormatPng, size_small, size_small);
- _r_res_loadimage (&config.hbmp_allow, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (IDP_ALLOW), &GUID_ContainerFormatPng, icon_small, icon_small);
- _r_res_loadimage (&config.hbmp_block, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (IDP_BLOCK), &GUID_ContainerFormatPng, icon_small, icon_small);
+ _r_res_loadimage (&config.hbmp_allow, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (IDP_ALLOW), &GUID_ContainerFormatPng, size_small, size_small);
+ _r_res_loadimage (&config.hbmp_block, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (IDP_BLOCK), &GUID_ContainerFormatPng, size_small, size_small);
// toolbar imagelist
if (config.himg_toolbar)
{
- _r_imagelist_setsize (config.himg_toolbar, icon_size_toolbar);
+ _r_imagelist_setsize (config.himg_toolbar, size_toolbar, size_toolbar);
}
else
{
- _r_imagelist_create (&config.himg_toolbar, icon_size_toolbar, icon_size_toolbar, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, RTL_NUMBER_OF (toolbar_ids), RTL_NUMBER_OF (toolbar_ids));
+ _r_imagelist_create (&config.himg_toolbar, size_toolbar, size_toolbar, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, RTL_NUMBER_OF (toolbar_ids), RTL_NUMBER_OF (toolbar_ids));
}
if (config.himg_toolbar)
{
for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (toolbar_ids); i++)
{
- _r_res_loadimage (&hbitmap, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (toolbar_ids[i]), &GUID_ContainerFormatPng, icon_size_toolbar, icon_size_toolbar);
+ status = _r_res_loadimage (&hbitmap, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (toolbar_ids[i]), &GUID_ContainerFormatPng, size_toolbar, size_toolbar);
- if (hbitmap)
+ if (NT_SUCCESS (status))
_r_imagelist_add (config.himg_toolbar, hbitmap, NULL, NULL);
}
}
@@ -771,20 +733,20 @@ VOID _app_imagelist_init (
// rules imagelist (small)
if (config.himg_rules_small)
{
- _r_imagelist_setsize (config.himg_rules_small, icon_small);
+ _r_imagelist_setsize (config.himg_rules_small, size_small, size_small);
}
else
{
- _r_imagelist_create (&config.himg_rules_small, icon_small, icon_small, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, RTL_NUMBER_OF (rules_ids), RTL_NUMBER_OF (rules_ids));
+ _r_imagelist_create (&config.himg_rules_small, size_small, size_small, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, RTL_NUMBER_OF (rules_ids), RTL_NUMBER_OF (rules_ids));
}
if (config.himg_rules_small)
{
for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (rules_ids); i++)
{
- _r_res_loadimage (&hbitmap, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (rules_ids[i]), &GUID_ContainerFormatPng, icon_small, icon_small);
+ status = _r_res_loadimage (&hbitmap, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (rules_ids[i]), &GUID_ContainerFormatPng, size_small, size_small);
- if (hbitmap)
+ if (NT_SUCCESS (status))
_r_imagelist_add (config.himg_rules_small, hbitmap, NULL, NULL);
}
}
@@ -792,20 +754,20 @@ VOID _app_imagelist_init (
// rules imagelist (large)
if (config.himg_rules_large)
{
- _r_imagelist_setsize (config.himg_rules_large, icon_large);
+ _r_imagelist_setsize (config.himg_rules_large, size_large, size_large);
}
else
{
- _r_imagelist_create (&config.himg_rules_large, icon_large, icon_large, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, RTL_NUMBER_OF (rules_ids), RTL_NUMBER_OF (rules_ids));
+ _r_imagelist_create (&config.himg_rules_large, size_large, size_large, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, RTL_NUMBER_OF (rules_ids), RTL_NUMBER_OF (rules_ids));
}
if (config.himg_rules_large)
{
for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (rules_ids); i++)
{
- _r_res_loadimage (&hbitmap, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (rules_ids[i]), &GUID_ContainerFormatPng, icon_large, icon_large);
+ status = _r_res_loadimage (&hbitmap, _r_sys_getimagebase (), L"PNG", MAKEINTRESOURCE (rules_ids[i]), &GUID_ContainerFormatPng, size_large, size_large);
- if (hbitmap)
+ if (NT_SUCCESS (status))
_r_imagelist_add (config.himg_rules_large, hbitmap, NULL, NULL);
}
}
@@ -813,13 +775,11 @@ VOID _app_imagelist_init (
HFONT _app_createfont (
_Inout_ PLOGFONT logfont,
- _In_ LONG size,
+ _In_opt_ LONG size,
_In_ BOOLEAN is_underline,
_In_ LONG dpi_value
)
{
- HFONT hfont;
-
if (size)
logfont->lfHeight = _r_dc_fontsizetoheight (size, dpi_value);
@@ -827,9 +787,7 @@ HFONT _app_createfont (
logfont->lfCharSet = DEFAULT_CHARSET;
logfont->lfQuality = DEFAULT_QUALITY;
- hfont = CreateFontIndirectW (logfont);
-
- return hfont;
+ return CreateFontIndirectW (logfont);
}
VOID _app_windowloadfont (
@@ -884,29 +842,19 @@ VOID _app_toolbar_init (
_r_toolbar_setimagelist (config.htoolbar, 0, config.himg_toolbar);
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_START, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, I_IMAGENONE);
-
_r_toolbar_addseparator (config.hrebar, IDC_TOOLBAR);
-
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_OPENRULESEDITOR, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, 8);
-
_r_toolbar_addseparator (config.hrebar, IDC_TOOLBAR);
-
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLENOTIFICATIONS_CHK, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, 4);
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLELOG_CHK, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, 5);
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLEUILOG_CHK, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, 10);
-
_r_toolbar_addseparator (config.hrebar, IDC_TOOLBAR);
-
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_REFRESH, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, 2);
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_SETTINGS, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, 3);
-
_r_toolbar_addseparator (config.hrebar, IDC_TOOLBAR);
-
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGSHOW, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, 6);
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGCLEAR, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, 7);
-
_r_toolbar_addseparator (config.hrebar, IDC_TOOLBAR);
-
_r_toolbar_addbutton (config.hrebar, IDC_TOOLBAR, IDM_DONATE, BTNS_BUTTON | BTNS_AUTOSIZE, NULL, TBSTATE_ENABLED, 9);
_r_toolbar_resize (config.hrebar, IDC_TOOLBAR);
@@ -951,20 +899,17 @@ VOID _app_toolbar_resize (
REBARBANDINFOW rbi;
SIZE ideal_size = {0};
ULONG button_size;
- UINT rebar_count;
_app_toolbar_setfont ();
_r_toolbar_resize (config.htoolbar, 0);
- rebar_count = _r_rebar_getcount (config.hrebar, 0);
-
- for (UINT i = 0; i < rebar_count; i++)
+ for (ULONG i = 0; i < _r_rebar_getcount (config.hrebar, 0); i++)
{
RtlZeroMemory (&rbi, sizeof (REBARBANDINFOW));
rbi.cbSize = sizeof (REBARBANDINFOW);
- rbi.fMask = RBBIM_ID | RBBIM_CHILD | RBBIM_IDEALSIZE | RBBIM_CHILDSIZE;
+ rbi.fMask = RBBIM_CHILD | RBBIM_ID | RBBIM_CHILDSIZE | RBBIM_IDEALSIZE;
if (!_r_rebar_getinfo (config.hrebar, 0, i, &rbi))
continue;
@@ -976,21 +921,13 @@ VOID _app_toolbar_resize (
button_size = _r_toolbar_getbuttonsize (config.hrebar, IDC_TOOLBAR);
- rbi.cxIdeal = (UINT)ideal_size.cx;
rbi.cxMinChild = LOWORD (button_size);
rbi.cyMinChild = HIWORD (button_size);
+ rbi.cxIdeal = (UINT)ideal_size.cx;
}
else if (rbi.wID == REBAR_SEARCH_ID)
{
- if (_r_wnd_isvisible (rbi.hwndChild, FALSE))
- {
- rbi.cxIdeal = (UINT)_r_dc_getdpi (180, dpi_value);
- }
- else
- {
- rbi.cxIdeal = 0;
- }
-
+ rbi.cxIdeal = _r_wnd_isvisible (rbi.hwndChild, FALSE) ? (UINT)_r_dc_getdpi (180, dpi_value) : 0;
rbi.cxMinChild = rbi.cxIdeal;
rbi.cyMinChild = 20;
}
@@ -1041,27 +978,8 @@ VOID _app_window_resize (
if (hdefer)
{
- hdefer = DeferWindowPos (
- hdefer,
- config.hrebar,
- NULL,
- 0,
- 0,
- rect->right,
- rebar_height,
- SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER
- );
-
- hdefer = DeferWindowPos (
- hdefer,
- GetDlgItem (hwnd, IDC_TAB),
- NULL,
- 0,
- rebar_height,
- rect->right,
- rect->bottom - rebar_height - statusbar_height,
- SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER
- );
+ hdefer = DeferWindowPos (hdefer, config.hrebar, NULL, 0, 0, rect->right, rebar_height, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
+ hdefer = DeferWindowPos (hdefer, GetDlgItem (hwnd, IDC_TAB), NULL, 0, rebar_height, rect->right, rect->bottom - rebar_height - statusbar_height, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
EndDeferWindowPos (hdefer);
}
@@ -1088,10 +1006,7 @@ VOID _app_refreshstatus (
{
ITEM_STATUS status = {0};
PR_STRING string[STATUSBAR_PARTS_COUNT] = {0};
- LONG parts[STATUSBAR_PARTS_COUNT] = {0};
- LONG size[STATUSBAR_PARTS_COUNT] = {0};
- LONG calculated_width = 0;
- LONG spacing;
+ LONG calculated_width = 0, parts[STATUSBAR_PARTS_COUNT] = {0}, size[STATUSBAR_PARTS_COUNT] = {0}, spacing;
HWND hstatus;
HDC hdc;
LONG dpi_value;
@@ -1106,7 +1021,7 @@ VOID _app_refreshstatus (
if (!hdc)
return;
- _r_dc_fixfont (hdc, hwnd, IDC_STATUSBAR); // fix
+ _r_dc_fixfont (hdc, hwnd, IDC_STATUSBAR); // fix font
_app_getcount (&status);
diff --git a/src/controls.h b/src/controls.h
index 7fb7feb7..1256fa22 100644
--- a/src/controls.h
+++ b/src/controls.h
@@ -12,12 +12,12 @@ PR_STRING _app_gettooltipbylparam (
_In_ LONG_PTR lparam
);
-VOID _app_settab_id (
+BOOLEAN _app_settab_id (
_In_ HWND hwnd,
_In_ INT page_id
);
-LPWSTR _app_getstateaction (
+LPCWSTR _app_getstateaction (
_In_ ENUM_INSTALL_TYPE install_type
);
@@ -25,7 +25,7 @@ HBITMAP _app_getstatebitmap (
_In_ ENUM_INSTALL_TYPE install_type
);
-INT _app_getstateicon (
+LONG _app_getstateicon (
_In_ ENUM_INSTALL_TYPE install_type
);
@@ -34,12 +34,12 @@ LPCWSTR _app_getstatelocale (
);
BOOLEAN _app_initinterfacestate (
- _In_ HWND hwnd,
+ _In_opt_ HWND hwnd,
_In_ BOOLEAN is_forced
);
VOID _app_restoreinterfacestate (
- _In_ HWND hwnd,
+ _In_opt_ HWND hwnd,
_In_ BOOLEAN is_enabled
);
@@ -60,7 +60,7 @@ VOID _app_imagelist_init (
HFONT _app_createfont (
_Inout_ PLOGFONT logfont,
- _In_ LONG size,
+ _In_opt_ LONG size,
_In_ BOOLEAN is_underline,
_In_ LONG dpi_value
);
diff --git a/src/db.c b/src/db.c
index 7323b0ea..c5db8092 100644
--- a/src/db.c
+++ b/src/db.c
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2019-2025 Henry++
+// Copyright (c) 2019-2026 Henry++
#include "global.h"
@@ -41,7 +41,7 @@ NTSTATUS _app_db_encrypt (
if (!NT_SUCCESS (status))
return status;
- _r_obj_initializebyteref (&key, PROFILE2_KEY);
+ _r_obj_initializebyteref (&key, PROFILE2_KEY_DEPRECATED);
status = _r_crypt_generatekey (&crypt_context, &key);
@@ -74,7 +74,7 @@ NTSTATUS _app_db_decrypt (
if (!NT_SUCCESS (status))
return status;
- _r_obj_initializebyteref (&key, PROFILE2_KEY);
+ _r_obj_initializebyteref (&key, PROFILE2_KEY_DEPRECATED);
status = _r_crypt_generatekey (&crypt_context, &key);
@@ -133,9 +133,12 @@ BYTE _app_getprofiletype ()
{
return PROFILE2_ID_ENCRYPTED;
}
- }
- return PROFILE2_ID_PLAIN;
+ default:
+ {
+ return PROFILE2_ID_PLAIN;
+ }
+ }
}
_Success_ (NT_SUCCESS (return))
@@ -152,14 +155,7 @@ NTSTATUS _app_db_ishashvalid (
if (!NT_SUCCESS (status))
return status;
- if (RtlEqualMemory (hash_bytes->buffer, new_hash_bytes->buffer, new_hash_bytes->length))
- {
- status = STATUS_SUCCESS;
- }
- else
- {
- status = STATUS_INVALID_IMAGE_HASH;
- }
+ status = RtlEqualMemory (hash_bytes->buffer, new_hash_bytes->buffer, min (hash_bytes->length, new_hash_bytes->length)) ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_HASH;
_r_obj_dereference (new_hash_bytes);
@@ -169,25 +165,19 @@ NTSTATUS _app_db_ishashvalid (
_Success_ (NT_SUCCESS (return))
NTSTATUS _app_db_openfrombuffer (
_Inout_ PDB_INFORMATION db_info,
- _In_ PR_STORAGE buffer,
- _In_ ENUM_VERSION_XML min_version,
+ _In_ PR_STORAGE storage,
_In_ ENUM_TYPE_XML type
)
{
- NTSTATUS status;
+ _r_obj_movereference ((PVOID_PTR)&db_info->bytes, _r_obj_createbyte4 (storage));
- _r_obj_movereference ((PVOID_PTR)&db_info->bytes, _r_obj_createbyte4 (buffer));
-
- status = _app_db_decodebuffer (db_info, type, min_version);
-
- return status;
+ return _app_db_decodebuffer (db_info, type);
}
_Success_ (NT_SUCCESS (return))
NTSTATUS _app_db_openfromfile (
_Inout_ PDB_INFORMATION db_info,
_In_ PR_STRING path,
- _In_ ENUM_VERSION_XML min_version,
_In_ ENUM_TYPE_XML type
)
{
@@ -197,21 +187,15 @@ NTSTATUS _app_db_openfromfile (
if (db_info->bytes)
_r_obj_clearreference ((PVOID_PTR)&db_info->bytes);
- status = _r_fs_openfile (&hfile, &path->sr, GENERIC_READ, FILE_SHARE_READ, 0, FALSE);
+ status = _r_fs_openfile (&hfile, &path->sr, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, FALSE);
if (!NT_SUCCESS (status))
return status;
status = _r_fs_readbytes (hfile, &db_info->bytes);
- if (!NT_SUCCESS (status))
- {
- NtClose (hfile);
-
- return status;
- }
-
- status = _app_db_decodebuffer (db_info, type, min_version);
+ if (NT_SUCCESS (status))
+ status = _app_db_decodebuffer (db_info, type);
NtClose (hfile);
@@ -223,48 +207,48 @@ VOID _app_db_parse_app (
)
{
PITEM_APP ptr_app;
- PR_STRING string;
- PR_STRING path;
- PR_STRING dos_path;
- LONG64 timestamp;
- LONG64 timer;
- ULONG app_hash;
- BOOLEAN is_undeletable;
- BOOLEAN is_enabled;
- BOOLEAN is_silent;
+ PR_STRING path, string;
+ LONG64 timer, timestamp;
+ NTSTATUS status;
path = _r_xml_getattribute_string (&db_info->xml_library, L"path");
if (_r_obj_isstringempty (path))
return;
- // workaround for native paths
- // https://github.com/henrypp/simplewall/issues/817
- if (_r_str_isstartswith2 (&path->sr, L"\\device\\", TRUE))
+ if (_r_str_findchar (&path->sr, L'%', FALSE) != SIZE_MAX)
{
- dos_path = _r_path_dospathfromnt (&path->sr);
+ status = _r_str_environmentexpandstring (&string, NULL, &path->sr);
- if (dos_path)
- _r_obj_movereference ((PVOID_PTR)&path, dos_path);
+ if (NT_SUCCESS (status))
+ _r_obj_movereference ((PVOID_PTR)&path, string);
}
+ // workaround for native paths (#817)
+ if (_r_str_isstartswith2 (&path->sr, L"\\device\\", TRUE))
+ _r_obj_movereference ((PVOID_PTR)&path, _r_path_dospathfromnt (&path->sr));
+
if (!_r_obj_isstringempty2 (path))
{
- app_hash = _app_addapplication (NULL, DATA_UNKNOWN, path, NULL, NULL);
+ ptr_app = _app_addapplication (NULL, DATA_UNKNOWN, path, NULL, NULL);
- if (app_hash)
+ if (ptr_app)
{
- ptr_app = _app_getappitem (app_hash);
-
- if (ptr_app)
{
- is_enabled = _r_xml_getattribute_boolean (&db_info->xml_library, L"is_enabled");
- is_silent = _r_xml_getattribute_boolean (&db_info->xml_library, L"is_silent");
- is_undeletable = _r_xml_getattribute_boolean (&db_info->xml_library, L"is_undeletable");
+ _app_setappinfo (ptr_app, INFO_IS_ENABLED, LongToPtr (_r_xml_getattribute_boolean (&db_info->xml_library, L"is_enabled")));
+ _app_setappinfo (ptr_app, INFO_IS_SILENT, LongToPtr (_r_xml_getattribute_boolean (&db_info->xml_library, L"is_silent")));
+ _app_setappinfo (ptr_app, INFO_IS_UNDELETABLE, LongToPtr (_r_xml_getattribute_boolean (&db_info->xml_library, L"is_undeletable")));
timestamp = _r_xml_getattribute_long64 (&db_info->xml_library, L"timestamp");
+
+ if (timestamp)
+ _app_setappinfo (ptr_app, INFO_TIMESTAMP, ×tamp);
+
timer = _r_xml_getattribute_long64 (&db_info->xml_library, L"timer");
+ if (timer)
+ _app_setappinfo (ptr_app, INFO_TIMER, &timer);
+
string = _r_xml_getattribute_string (&db_info->xml_library, L"hash");
if (string)
@@ -293,21 +277,6 @@ VOID _app_db_parse_app (
}
}
- if (is_silent)
- _app_setappinfo (ptr_app, INFO_IS_SILENT, LongToPtr (is_silent));
-
- if (is_enabled)
- _app_setappinfo (ptr_app, INFO_IS_ENABLED, LongToPtr (is_enabled));
-
- if (is_undeletable)
- _app_setappinfo (ptr_app, INFO_IS_UNDELETABLE, LongToPtr (is_undeletable));
-
- if (timestamp)
- _app_setappinfo (ptr_app, INFO_TIMESTAMP, ×tamp);
-
- if (timer)
- _app_setappinfo (ptr_app, INFO_TIMER, &timer);
-
_r_obj_dereference (ptr_app);
}
}
@@ -321,37 +290,26 @@ VOID _app_db_parse_rule (
_In_ ENUM_TYPE_DATA type
)
{
+ PR_STRING comment, path_string = NULL, rule_name, rule_local, rule_remote, string;
PITEM_RULE_CONFIG ptr_config = NULL;
+ R_STRINGREF first_part, sr;
R_STRINGBUILDER sb;
- R_STRINGREF first_part;
- R_STRINGREF sr;
- PR_STRING rule_name;
- PR_STRING rule_remote;
- PR_STRING rule_local;
- PR_STRING path_string;
- PR_STRING comment;
- PR_STRING string;
- LONG blocklist_spy_state;
- LONG blocklist_update_state;
- LONG blocklist_extra_state;
+ PITEM_RULE ptr_rule;
+ PITEM_APP ptr_app;
+ LONG blocklist_extra_state, blocklist_spy_state, blocklist_update_state;
+ ULONG app_hash;
FWP_DIRECTION direction;
FWP_ACTION_TYPE action;
- UINT8 protocol;
ADDRESS_FAMILY af;
- PITEM_RULE ptr_rule;
- ULONG rule_hash;
- ULONG app_hash;
+ UINT8 protocol;
BOOLEAN is_internal;
NTSTATUS status;
// check support version
status = _r_xml_getattribute (&db_info->xml_library, L"os_version", &sr);
- if (SUCCEEDED (status))
- {
- if (!_app_isrulesupportedbyos (&sr))
- return;
- }
+ if (SUCCEEDED (status) && !_app_isrulesupportedbyos (&sr))
+ return;
rule_name = _r_xml_getattribute_string (&db_info->xml_library, L"name");
@@ -368,16 +326,6 @@ VOID _app_db_parse_rule (
ptr_rule = _app_addrule (rule_name, rule_remote, rule_local, direction, action, protocol, af);
- _r_obj_dereference (rule_name);
-
- if (rule_remote)
- _r_obj_dereference (rule_remote);
-
- if (rule_local)
- _r_obj_dereference (rule_local);
-
- rule_hash = _r_str_gethash (&ptr_rule->name->sr, TRUE);
-
if (!_r_obj_isstringempty (comment))
{
_r_obj_movereference ((PVOID_PTR)&ptr_rule->comment, comment);
@@ -388,30 +336,31 @@ VOID _app_db_parse_rule (
_r_obj_dereference (comment);
}
- ptr_rule->type = (type == DATA_RULE_SYSTEM_USER) ? DATA_RULE_USER : type;
- ptr_rule->is_forservices = _r_xml_getattribute_boolean (&db_info->xml_library, L"is_services");
- ptr_rule->is_readonly = (type != DATA_RULE_USER);
+ ptr_rule->is_forservice = _r_xml_getattribute_boolean (&db_info->xml_library, L"is_services");
+ ptr_rule->is_fordriver = _r_xml_getattribute_boolean (&db_info->xml_library, L"is_kernel");
ptr_rule->is_enabled = _r_xml_getattribute_boolean (&db_info->xml_library, L"is_enabled");
+ ptr_rule->type = (type == DATA_RULE_SYSTEM_USER) ? DATA_RULE_USER : type;
+ ptr_rule->is_readonly = (type != DATA_RULE_USER);
// calculate rule weight
if (type == DATA_RULE_BLOCKLIST)
{
- ptr_rule->weight = FW_WEIGHT_RULE_BLOCKLIST;
+ ptr_rule->weight = FWW_RULE_BLOCKLIST;
}
else if (type == DATA_RULE_SYSTEM || type == DATA_RULE_SYSTEM_USER)
{
- ptr_rule->weight = FW_WEIGHT_RULE_SYSTEM;
+ ptr_rule->weight = FWW_RULE_SYSTEM;
}
else if (type == DATA_RULE_USER)
{
- ptr_rule->weight = (ptr_rule->action == FWP_ACTION_BLOCK) ? FW_WEIGHT_RULE_USER_BLOCK : FW_WEIGHT_RULE_USER;
+ ptr_rule->weight = (ptr_rule->action == FWP_ACTION_BLOCK) ? FWW_RULE_USER_BLOCK : FWW_RULE_USER;
}
if (type == DATA_RULE_BLOCKLIST)
{
- blocklist_spy_state = _r_calc_clamp (_r_config_getlong (L"BlocklistSpyState", 2, NULL), 0, 2);
blocklist_update_state = _r_calc_clamp (_r_config_getlong (L"BlocklistUpdateState", 0, NULL), 0, 2);
blocklist_extra_state = _r_calc_clamp (_r_config_getlong (L"BlocklistExtraState", 0, NULL), 0, 2);
+ blocklist_spy_state = _r_calc_clamp (_r_config_getlong (L"BlocklistSpyState", 2, NULL), 0, 2);
_app_ruleblocklistsetstate (ptr_rule, blocklist_spy_state, blocklist_update_state, blocklist_extra_state);
}
@@ -426,14 +375,14 @@ VOID _app_db_parse_rule (
if (is_internal)
{
// internal rules
- ptr_config = _app_getruleconfigitem (rule_hash);
+ ptr_config = _app_getruleconfigitem (ptr_rule->rule_hash);
if (ptr_config)
ptr_rule->is_enabled = ptr_config->is_enabled;
}
// load apps
- _r_obj_initializestringbuilder (&sb, 256);
+ _r_obj_initializestringbuilder (&sb, 0);
string = _r_xml_getattribute_string (&db_info->xml_library, L"apps");
@@ -457,7 +406,7 @@ VOID _app_db_parse_rule (
if (!_r_obj_isstringempty2 (string))
{
if (db_info->version < XML_VERSION_3)
- _r_str_replacechar (&string->sr, DIVIDER_RULE[0], DIVIDER_APP[0]);
+ _r_str_replacechar (&string->sr, DIVIDER_RULE[0], DIVIDER_APP[0]); // replace old profile divider ; to |
_r_obj_initializestringref2 (&sr, &string->sr);
@@ -465,24 +414,32 @@ VOID _app_db_parse_rule (
{
_r_str_splitatchar (&sr, DIVIDER_APP[0], &first_part, &sr);
- status = _r_str_environmentexpandstring (NULL, &first_part, &path_string);
+ status = _r_str_environmentexpandstring (&path_string, NULL, &first_part);
if (status != STATUS_SUCCESS)
- path_string = _r_obj_createstring2 (&first_part);
+ _r_obj_movereference ((PVOID_PTR)&path_string, _r_obj_createstring2 (&first_part));
app_hash = _r_str_gethash (&path_string->sr, TRUE);
if (app_hash)
{
- if (ptr_rule->is_forservices && _app_issystemhash (app_hash))
+ if ((ptr_rule->is_fordriver || ptr_rule->is_forservice) && _app_issystemhash (app_hash))
{
_r_obj_dereference (path_string);
-
continue;
}
if (!_app_isappfound (app_hash))
- app_hash = _app_addapplication (NULL, DATA_UNKNOWN, path_string, NULL, NULL);
+ {
+ ptr_app = _app_addapplication (NULL, DATA_UNKNOWN, path_string, NULL, NULL);
+
+ if (ptr_app)
+ {
+ app_hash = ptr_app->app_hash;
+
+ _r_obj_dereference (ptr_app);
+ }
+ }
if (app_hash)
{
@@ -497,11 +454,8 @@ VOID _app_db_parse_rule (
}
// check if no app is added into rule, then disable it!
- if (ptr_rule->is_enabled)
- {
- if (_r_obj_isempty (ptr_rule->apps))
- ptr_rule->is_enabled = FALSE;
- }
+ if (ptr_rule->is_enabled && _r_obj_isempty (ptr_rule->apps))
+ ptr_rule->is_enabled = FALSE;
}
_r_queuedlock_acquireexclusive (&lock_rules);
@@ -509,6 +463,14 @@ VOID _app_db_parse_rule (
_r_queuedlock_releaseexclusive (&lock_rules);
_r_obj_deletestringbuilder (&sb);
+
+ if (rule_remote)
+ _r_obj_dereference (rule_remote);
+
+ if (rule_local)
+ _r_obj_dereference (rule_local);
+
+ _r_obj_dereference (rule_name);
}
VOID _app_db_parse_ruleconfig (
@@ -546,7 +508,7 @@ VOID _app_db_parse_ruleconfig (
ptr_config->apps = _r_xml_getattribute_string (&db_info->xml_library, L"apps");
if (ptr_config->apps && db_info->version < XML_VERSION_3)
- _r_str_replacechar (&ptr_config->apps->sr, DIVIDER_RULE[0], DIVIDER_APP[0]);
+ _r_str_replacechar (&ptr_config->apps->sr, DIVIDER_RULE[0], DIVIDER_APP[0]); // replace old profile divider ; to |
}
}
@@ -558,8 +520,7 @@ NTSTATUS _app_db_decodebody (
_Inout_ PDB_INFORMATION db_info
)
{
- USHORT format[] = {COMPRESSION_FORMAT_LZNT1, COMPRESSION_FORMAT_XPRESS};
- USHORT architecture;
+ USHORT architecture, format[] = {COMPRESSION_FORMAT_LZNT1, COMPRESSION_FORMAT_XPRESS};
PR_BYTE new_bytes;
BYTE profile_type;
NTSTATUS status;
@@ -567,10 +528,10 @@ NTSTATUS _app_db_decodebody (
if (db_info->bytes->length < PROFILE2_HEADER_LENGTH)
return STATUS_SUCCESS;
- if (!RtlEqualMemory (db_info->bytes->buffer, profile2_fourcc, sizeof (profile2_fourcc)) || !RtlEqualMemory (db_info->bytes->buffer, profile2_fourcc, sizeof (profile2_fourcc_old)))
+ if (!RtlEqualMemory (db_info->bytes->buffer, profile2_fourcc, sizeof (profile2_fourcc)))
return STATUS_SUCCESS;
- profile_type = db_info->bytes->buffer[sizeof (profile2_fourcc)];
+ profile_type = db_info->bytes->buffer[PROFILE2_FOURCC];
// skip fourcc
_r_obj_skipbytelength (&db_info->bytes->sr, PROFILE2_FOURCC_LENGTH);
@@ -593,7 +554,6 @@ NTSTATUS _app_db_decodebody (
if (NT_SUCCESS (status))
{
_r_obj_movereference ((PVOID_PTR)&db_info->bytes, new_bytes);
-
break;
}
}
@@ -606,10 +566,8 @@ NTSTATUS _app_db_decodebody (
// decrypt bytes
status = _app_db_decrypt (&db_info->bytes->sr, &new_bytes);
- if (!NT_SUCCESS (status))
- return status;
-
- _r_obj_movereference ((PVOID_PTR)&db_info->bytes, new_bytes);
+ if (NT_SUCCESS (status))
+ _r_obj_movereference ((PVOID_PTR)&db_info->bytes, new_bytes);
break;
}
@@ -623,10 +581,10 @@ NTSTATUS _app_db_decodebody (
if (!NT_SUCCESS (status))
return status;
- if (RtlEqualMemory (db_info->bytes->buffer, profile2_fourcc, sizeof (profile2_fourcc)) || RtlEqualMemory (db_info->bytes->buffer, profile2_fourcc_old, sizeof (profile2_fourcc_old)))
+ if (RtlEqualMemory (db_info->bytes->buffer, profile2_fourcc, sizeof (profile2_fourcc)))
return STATUS_MORE_PROCESSING_REQUIRED;
- // fix arm64 crash that was introduced by Micro$oft (issue #1228)
+ // fix ARM64 crash that was introduced by M$ (issue #1228)
if (NT_SUCCESS (_r_sys_getprocessorinformation (&architecture, NULL, NULL)))
{
if (architecture == PROCESSOR_ARCHITECTURE_ARM || architecture == PROCESSOR_ARCHITECTURE_ARM64)
@@ -635,7 +593,7 @@ NTSTATUS _app_db_decodebody (
// validate hash
if (db_info->hash)
- status = _app_db_ishashvalid (&db_info->bytes->sr, &db_info->hash->sr);
+ return _app_db_ishashvalid (&db_info->bytes->sr, &db_info->hash->sr);
return status;
}
@@ -647,10 +605,7 @@ NTSTATUS _app_db_encodebody (
_Out_ PR_BYTE_PTR out_buffer
)
{
- PR_BYTE body_bytes;
- PR_BYTE hash_value;
- PR_BYTE new_bytes;
- PR_BYTE bytes;
+ PR_BYTE body_bytes, bytes, hash_value, new_bytes = NULL;
NTSTATUS status;
*out_buffer = NULL;
@@ -664,12 +619,7 @@ NTSTATUS _app_db_encodebody (
status = _app_db_gethash (&bytes->sr, &hash_value);
if (!NT_SUCCESS (status))
- {
- _r_obj_dereference (hash_value);
- _r_obj_dereference (bytes);
-
- return status;
- }
+ goto CleanupExit;
switch (profile_type)
{
@@ -686,12 +636,7 @@ NTSTATUS _app_db_encodebody (
status = _r_sys_compressbuffer (&new_bytes, COMPRESSION_FORMAT_LZNT1 | COMPRESSION_ENGINE_MAXIMUM, &bytes->sr);
if (!NT_SUCCESS (status))
- {
- _r_obj_dereference (hash_value);
- _r_obj_dereference (bytes);
-
- return status;
- }
+ goto CleanupExit;
break;
}
@@ -702,19 +647,16 @@ NTSTATUS _app_db_encodebody (
status = _app_db_encrypt (&bytes->sr, &new_bytes);
if (!NT_SUCCESS (status))
- {
- _r_obj_dereference (hash_value);
- _r_obj_dereference (bytes);
-
- return status;
- }
+ goto CleanupExit;
break;
}
default:
{
- return STATUS_FILE_NOT_SUPPORTED;
+ status = STATUS_FILE_NOT_SUPPORTED;
+
+ goto CleanupExit;
}
}
@@ -724,6 +666,8 @@ NTSTATUS _app_db_encodebody (
*out_buffer = body_bytes;
+CleanupExit:
+
_r_obj_dereference (hash_value);
_r_obj_dereference (bytes);
@@ -754,9 +698,9 @@ NTSTATUS _app_db_generatebody (
{
bytes = _r_obj_createbyte_ex (NULL, PROFILE2_HEADER_LENGTH + buffer->length);
- RtlCopyMemory (bytes->buffer, profile2_fourcc, sizeof (profile2_fourcc));
+ RtlCopyMemory (bytes->buffer, profile2_fourcc, PROFILE2_FOURCC);
- ptr = PTR_ADD_OFFSET (bytes->buffer, sizeof (profile2_fourcc));
+ ptr = PTR_ADD_OFFSET (bytes->buffer, PROFILE2_FOURCC);
RtlCopyMemory (ptr, &profile_type, sizeof (BYTE));
ptr = PTR_ADD_OFFSET (bytes->buffer, PROFILE2_FOURCC_LENGTH);
@@ -784,15 +728,18 @@ NTSTATUS _app_db_generatebody (
_Success_ (NT_SUCCESS (return))
NTSTATUS _app_db_decodebuffer (
_Inout_ PDB_INFORMATION db_info,
- _In_ ENUM_TYPE_XML type,
- _In_ ENUM_VERSION_XML min_version
+ _In_ ENUM_TYPE_XML type
)
{
ULONG attempts = 6;
NTSTATUS status;
- if (!db_info->bytes)
- return STATUS_BUFFER_ALL_ZEROS;
+ if (_r_obj_isbyteempty (db_info->bytes))
+ return STATUS_NO_DATA_DETECTED;
+
+ // check for large buffer size
+ if (db_info->bytes->length >= PR_SIZE_BUFFER_MINIMUM)
+ return STATUS_BUFFER_OVERFLOW; // STATUS_FILE_TOO_LARGE
do
{
@@ -814,14 +761,16 @@ NTSTATUS _app_db_decodebuffer (
if (!_r_xml_findchildbytagname (&db_info->xml_library, L"root"))
return STATUS_DATA_ERROR;
+ db_info->version = (ENUM_VERSION_XML)_r_xml_getattribute_long (&db_info->xml_library, L"version");
+ db_info->type = (ENUM_TYPE_XML)_r_xml_getattribute_long (&db_info->xml_library, L"type");
db_info->timestamp = _r_xml_getattribute_long64 (&db_info->xml_library, L"timestamp");
- db_info->type = _r_xml_getattribute_long (&db_info->xml_library, L"type");
- db_info->version = _r_xml_getattribute_long (&db_info->xml_library, L"version");
+ // validate type
if (db_info->type != type)
- return STATUS_NDIS_INVALID_DATA;
+ return STATUS_OBJECT_TYPE_MISMATCH;
- if (db_info->version < min_version)
+ // validate version range
+ if (db_info->version < XML_VERSION_MINIMAL && db_info->version > XML_VERSION_MAXIMUM)
return STATUS_FILE_NOT_SUPPORTED;
return STATUS_SUCCESS;
@@ -916,13 +865,12 @@ NTSTATUS _app_db_savetofile (
{
NTSTATUS status;
- status = _r_xml_createstream (&db_info->xml_library, NULL, 1024);
+ status = _r_xml_createstream (&db_info->xml_library, NULL, 0x400);
if (FAILED (status))
return status;
_r_xml_writestartdocument (&db_info->xml_library);
-
_r_xml_writestartelement (&db_info->xml_library, L"root");
_r_xml_setattribute_long (&db_info->xml_library, L"version", version);
@@ -949,8 +897,18 @@ NTSTATUS _app_db_save_streamtofile (
{
PR_BYTE new_bytes;
HANDLE hfile;
+ ULONG attributes;
NTSTATUS status;
+ // HACK!!! remove read-only attribute to fix STATUS_ACCESS_DENIED (issue #2048) [thx @jekesx]
+ if (_r_fs_isexists (&path->sr))
+ {
+ _r_fs_getattributes (&path->sr, &attributes);
+
+ if ((attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY)
+ _r_fs_setattributes (&path->sr, NULL, attributes & ~FILE_ATTRIBUTE_READONLY);
+ }
+
status = _r_fs_createfile (&hfile, &path->sr, FILE_OVERWRITE_IF, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_ATTRIBUTE_NORMAL, 0, FALSE, NULL);
if (!NT_SUCCESS (status))
@@ -976,7 +934,6 @@ FORCEINLINE VOID _app_db_writeelementstart (
)
{
_r_xml_writewhitespace (&db_info->xml_library, L"\r\n\t");
-
_r_xml_writestartelement (&db_info->xml_library, name);
}
@@ -985,7 +942,6 @@ FORCEINLINE VOID _app_db_writeelementend (
)
{
_r_xml_writewhitespace (&db_info->xml_library, L"\r\n\t");
-
_r_xml_writeendelement (&db_info->xml_library);
}
@@ -994,9 +950,9 @@ VOID _app_db_save_app (
)
{
PITEM_APP ptr_app = NULL;
+ PR_STRING expanded_path;
ULONG_PTR enum_key = 0;
BOOLEAN is_keepunusedapps;
- BOOLEAN is_usedapp;
is_keepunusedapps = _r_config_getboolean (L"IsKeepUnusedApps", TRUE, NULL);
@@ -1009,20 +965,28 @@ VOID _app_db_save_app (
if (_r_obj_isstringempty (ptr_app->original_path))
continue;
- is_usedapp = _app_isappused (ptr_app);
-
// do not save unused apps/uwp apps...
- if (!is_usedapp && (!is_keepunusedapps || (ptr_app->type == DATA_APP_SERVICE || ptr_app->type == DATA_APP_UWP)))
+ if (!_app_isappused (ptr_app) && (!is_keepunusedapps || (ptr_app->type == DATA_APP_SERVICE || ptr_app->type == DATA_APP_UWP)))
{
//_app_deleteappitem (_r_app_gethwnd (), ptr_app->type, ptr_app->app_hash);
-
continue;
}
_r_xml_writewhitespace (&db_info->xml_library, L"\r\n\t\t");
_r_xml_writestartelement (&db_info->xml_library, L"item");
- _r_xml_setattribute (&db_info->xml_library, L"path", ptr_app->original_path->buffer);
+ if (_r_config_getboolean (L"IsSaveAppsWithEnvironment", TRUE, NULL))
+ {
+ expanded_path = _r_str_environmentunexpandstring (&ptr_app->original_path->sr);
+
+ _r_xml_setattribute (&db_info->xml_library, L"path", expanded_path->buffer);
+
+ _r_obj_dereference (expanded_path);
+ }
+ else
+ {
+ _r_xml_setattribute (&db_info->xml_library, L"path", ptr_app->original_path->buffer);
+ }
if (!_r_obj_isstringempty (ptr_app->hash) && _r_config_getboolean (L"IsHashesEnabled", FALSE, NULL))
_r_xml_setattribute (&db_info->xml_library, L"hash", ptr_app->hash->buffer);
@@ -1071,13 +1035,12 @@ VOID _app_db_save_rule (
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
- if (!ptr_rule || ptr_rule->is_readonly || _r_obj_isstringempty (ptr_rule->name))
+ if (!ptr_rule || ptr_rule->is_readonly)
continue;
_r_xml_writewhitespace (&db_info->xml_library, L"\r\n\t\t");
-
_r_xml_writestartelement (&db_info->xml_library, L"item");
_r_xml_setattribute (&db_info->xml_library, L"name", ptr_rule->name->buffer);
@@ -1139,7 +1102,7 @@ VOID _app_db_save_ruleconfig (
PITEM_RULE ptr_rule;
PR_STRING apps_string;
ULONG_PTR enum_key = 0;
- ULONG_PTR rule_hash;
+ ULONG rule_hash;
BOOLEAN is_enabled_default;
_app_db_writeelementstart (db_info, L"rules_config");
@@ -1173,7 +1136,6 @@ VOID _app_db_save_ruleconfig (
continue;
_r_xml_writewhitespace (&db_info->xml_library, L"\r\n\t\t");
-
_r_xml_writestartelement (&db_info->xml_library, L"item");
_r_xml_setattribute (&db_info->xml_library, L"name", ptr_config->name->buffer);
@@ -1182,7 +1144,7 @@ VOID _app_db_save_ruleconfig (
{
_r_xml_setattribute (&db_info->xml_library, L"apps", apps_string->buffer);
- _r_obj_clearreference ((PVOID_PTR)&apps_string);
+ _r_obj_dereference (apps_string);
}
_r_xml_setattribute_boolean (&db_info->xml_library, L"is_enabled", ptr_config->is_enabled);
@@ -1237,9 +1199,10 @@ LPCWSTR _app_db_getconnectionstatename (
case MIB_TCP_STATE_DELETE_TCB:
return L"Delete TCB";
- }
- return NULL;
+ default:
+ return NULL;
+ }
}
_Ret_maybenull_
@@ -1251,56 +1214,29 @@ PR_STRING _app_db_getdirectionname (
{
LPCWSTR text = NULL;
- if (is_localized)
+ switch (direction)
{
- switch (direction)
+ case FWP_DIRECTION_OUTBOUND:
{
- case FWP_DIRECTION_OUTBOUND:
- {
- text = _r_locale_getstring (IDS_DIRECTION_1);
-
- break;
- }
-
- case FWP_DIRECTION_INBOUND:
- {
- text = _r_locale_getstring (IDS_DIRECTION_2);
-
- break;
- }
-
- case FWP_DIRECTION_MAX:
- {
- text = _r_locale_getstring (IDS_ANY);
-
- break;
- }
+ text = is_localized ? _r_locale_getstring (IDS_DIRECTION_1) : SZ_DIRECTION_OUT;
+ break;
}
- }
- else
- {
- switch (direction)
+
+ case FWP_DIRECTION_INBOUND:
{
- case FWP_DIRECTION_OUTBOUND:
- {
- text = SZ_DIRECTION_OUT;
+ text = is_localized ? _r_locale_getstring (IDS_DIRECTION_2) : SZ_DIRECTION_IN;
+ break;
+ }
- break;
- }
+ case FWP_DIRECTION_MAX:
+ {
+ text = is_localized ? _r_locale_getstring (IDS_ANY) : SZ_DIRECTION_ANY;
+ break;
+ }
- case FWP_DIRECTION_INBOUND:
- {
- text = SZ_DIRECTION_IN;
-
- break;
- }
-
- case FWP_DIRECTION_MAX:
- {
- text = SZ_DIRECTION_ANY;
-
- break;
- }
+ default:
+ {
+ return NULL; // unknown direction
}
}
@@ -1315,7 +1251,8 @@ PR_STRING _app_db_getdirectionname (
LPCWSTR _app_db_getprotoname (
_In_ ULONG proto,
- _In_ ADDRESS_FAMILY af
+ _In_ ADDRESS_FAMILY af,
+ _In_opt_ LPCWSTR default_value
)
{
switch (proto)
@@ -1384,6 +1321,18 @@ LPCWSTR _app_db_getprotoname (
case IPPROTO_DSTOPTS:
return L"ipv6-opts";
+ case IPPROTO_ND:
+ return L"nd";
+
+ case IPPROTO_ICLFXBM:
+ return L"wideband-monitoring";
+
+ case IPPROTO_PIM:
+ return L"pim";
+
+ case IPPROTO_PGM:
+ return L"pgm";
+
case IPPROTO_L2TP:
return L"l2tp";
@@ -1394,9 +1343,10 @@ LPCWSTR _app_db_getprotoname (
return L"raw";
}
- return L"n/a";
+ return default_value;
}
+// source: https://github.com/nmap/nmap/blob/master/nmap-services
_Ret_maybenull_
LPCWSTR _app_db_getservicename (
_In_ UINT16 port,
@@ -3329,7 +3279,7 @@ LPCWSTR _app_db_getservicename (
}
else if (proto == IPPROTO_UDP)
{
- return L"opsmgr"; // Microsoft Operations Manager
+ return L"opsmgr"; // M$ Operations Manager
}
break;
@@ -3569,7 +3519,7 @@ LPCWSTR _app_db_getservicename (
return L"dpi-proxy";
case 1801:
- return L"msmq"; // Microsoft Message Queuing
+ return L"msmq"; // M$ Message Queuing
case 1833:
return L"udpradio";
@@ -3686,22 +3636,22 @@ LPCWSTR _app_db_getservicename (
return L"raw-serial"; // Raw Async Serial Link
case 2171:
- return L"msfw-storage"; // MS Firewall Storage
+ return L"msfw-storage"; // M$ Firewall Storage
case 2172:
- return L"msfw-s-storage"; // MS Firewall SecureStorage
+ return L"msfw-s-storage"; // M$ Firewall SecureStorage
case 2173:
- return L"msfw-replica"; // MS Firewall Replication
+ return L"msfw-replica"; // M$ Firewall Replication
case 2174:
- return L"msfw-array"; // MS Firewall Intra Array
+ return L"msfw-array"; // M$ Firewall Intra Array
case 2175:
- return L"ms-airsync"; // Microsoft Desktop AirSync Protocol
+ return L"ms-airsync"; // M$ Desktop AirSync Protocol
case 2179:
- return L"ms-vmrdp"; // Microsoft RDP for virtual machines
+ return L"ms-vmrdp"; // M$ RDP for virtual machines
case 2191:
return L"tvbus";
@@ -3754,13 +3704,13 @@ LPCWSTR _app_db_getservicename (
}
case 2382:
- return L"ms-olap3"; // Microsoft OLAP
+ return L"ms-olap3"; // M$ OLAP
case 2383:
- return L"ms-olap4"; // Microsoft OLAP
+ return L"ms-olap4"; // M$ OLAP
case 2525:
- return L"ms-v-worlds"; // MS V-Worlds
+ return L"ms-v-worlds"; // M$ V-Worlds
case 2679:
return L"syncserverssl";
@@ -3851,7 +3801,7 @@ LPCWSTR _app_db_getservicename (
return L"ssql"; // Scalable SQL
case 3389:
- return L"ms-wbt-server"; // Microsoft Remote Display Protocol (aka ms-term-serv, microsoft-rdp)
+ return L"ms-wbt-server"; // M$ Remote Display Protocol (aka ms-term-serv, microsoft-rdp)
case 3407:
return L"ldap-admin";
@@ -3927,7 +3877,7 @@ LPCWSTR _app_db_getservicename (
}
case 4554:
- return L"msfrs"; // MS FRS Replication
+ return L"msfrs"; // M$ FRS Replication
case 4687:
return L"nst"; // Network Scanner Tool FTP
@@ -3999,7 +3949,7 @@ LPCWSTR _app_db_getservicename (
return L"ms-s-sideshow";
case 5362:
- return L"serverwsd2"; // Microsoft Windows Server WSD2 Service
+ return L"serverwsd2"; // M$ Windows Server WSD2 Service
case 5432:
return L"postgresql";
@@ -4150,12 +4100,12 @@ LPCWSTR _app_db_getservicename (
return L"x11";
case 6074:
- return L"max"; // Microsoft Max
+ return L"max"; // M$ Max
case 6076:
{
if (proto == IPPROTO_TCP)
- return L"msft-dpm-cert"; // Microsoft DPM WCF Certificates
+ return L"msft-dpm-cert"; // M$ DPM WCF Certificates
break;
}
@@ -4198,7 +4148,6 @@ LPCWSTR _app_db_getservicename (
break;
}
-
case 6881:
{
if (proto == IPPROTO_TCP)
diff --git a/src/db.h b/src/db.h
index 5cd584a7..6b92ff9c 100644
--- a/src/db.h
+++ b/src/db.h
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2019-2025 Henry++
+// Copyright (c) 2019-2026 Henry++
#pragma once
@@ -21,6 +21,9 @@ typedef enum _ENUM_VERSION_XML
// v3.7: added hashes support, use encrypted file format and added comments for apps/rules
XML_VERSION_5 = 5,
+
+ // v4.0: added file rules support, added correct encryption with password, store path with environment variables, now rules for services and drivers are separated
+ XML_VERSION_6 = 6,
} ENUM_VERSION_XML;
typedef struct _DB_INFORMATION
@@ -39,21 +42,16 @@ typedef struct _DB_INFORMATION
// Offset Length Description
// ------------------------------------------
// 0 3 FOURCC string 'SWC'
-// 4 1 Body information flag
+// 4 1 Body information flag (PROFILE2_ID_PLAIN, PROFILE2_ID_COMPRESSED or PROFILE2_ID_ENCRYPTED)
// 36 32 SHA256 checksum of the decrypted bytes
-// 68 whole Body contained specified data
-
+// 68
Body contained specified data
static const BYTE profile2_fourcc[] = {
0x53, 0x57, 0x43, // 'S', 'W', 'C'
};
-static const BYTE profile2_fourcc_old[] = {
- 0x73, 0x77, 0x63, // 's', 'w', 'c'
-};
-
#define XML_VERSION_MINIMAL XML_VERSION_3
-#define XML_VERSION_CURRENT XML_VERSION_4
-#define XML_VERSION_MAXIMUM XML_VERSION_5
+#define XML_VERSION_CURRENT XML_VERSION_5
+#define XML_VERSION_MAXIMUM XML_VERSION_6
#define XML_PROFILE_FILE L"profile.xml"
#define XML_PROFILE_INTERNAL L"profile_internal.xml"
@@ -62,9 +60,10 @@ static const BYTE profile2_fourcc_old[] = {
#define PROFILE2_ID_COMPRESSED ((BYTE)(0x31))
#define PROFILE2_ID_ENCRYPTED ((BYTE)(0x32))
-#define PROFILE2_KEY "Gc(j1EptodnKP?{ZT!SlMVip[fJIs&Ci3fOqjATfp@h,q0(]QVaGs5Iht3)/b:Ll"
+#define PROFILE2_KEY_DEPRECATED "Gc(j1EptodnKP?{ZT!SlMVip[fJIs&Ci3fOqjATfp@h,q0(]QVaGs5Iht3)/b:Ll"
-#define PROFILE2_FOURCC_LENGTH sizeof (profile2_fourcc) + sizeof (BYTE)
+#define PROFILE2_FOURCC sizeof (profile2_fourcc)
+#define PROFILE2_FOURCC_LENGTH PROFILE2_FOURCC + sizeof (BYTE)
#define PROFILE2_SHA256_LENGTH 32UL
#define PROFILE2_HEADER_LENGTH (PROFILE2_FOURCC_LENGTH + PROFILE2_SHA256_LENGTH)
@@ -86,7 +85,7 @@ NTSTATUS _app_db_encrypt (
_Success_ (NT_SUCCESS (return))
NTSTATUS _app_db_decrypt (
- _In_ PR_BYTEREF buffer,
+ _In_ PR_BYTEREF bytes,
_Out_ PR_BYTE_PTR out_buffer
);
@@ -107,8 +106,7 @@ NTSTATUS _app_db_ishashvalid (
_Success_ (NT_SUCCESS (return))
NTSTATUS _app_db_openfrombuffer (
_Inout_ PDB_INFORMATION db_info,
- _In_ PR_STORAGE buffer,
- _In_ ENUM_VERSION_XML min_version,
+ _In_ PR_STORAGE storage,
_In_ ENUM_TYPE_XML type
);
@@ -116,7 +114,6 @@ _Success_ (NT_SUCCESS (return))
NTSTATUS _app_db_openfromfile (
_Inout_ PDB_INFORMATION db_info,
_In_ PR_STRING path,
- _In_ ENUM_VERSION_XML min_version,
_In_ ENUM_TYPE_XML type
);
@@ -143,8 +140,7 @@ NTSTATUS _app_db_generatebody (
_Success_ (NT_SUCCESS (return))
NTSTATUS _app_db_decodebuffer (
_Inout_ PDB_INFORMATION db_info,
- _In_ ENUM_TYPE_XML type,
- _In_ ENUM_VERSION_XML min_version
+ _In_ ENUM_TYPE_XML type
);
BOOLEAN _app_db_parse (
@@ -203,10 +199,10 @@ PR_STRING _app_db_getdirectionname (
_In_ BOOLEAN is_loopback,
_In_ BOOLEAN is_localized
);
-
LPCWSTR _app_db_getprotoname (
_In_ ULONG proto,
- _In_ ADDRESS_FAMILY af
+ _In_ ADDRESS_FAMILY af,
+ _In_opt_ LPCWSTR default_value
);
_Ret_maybenull_
diff --git a/src/editor.c b/src/editor.c
index 3b43c570..5926eb3e 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -1,11 +1,11 @@
// simplewall
-// Copyright (c) 2016-2025 Henry++
+// Copyright (c) 2016-2026 Henry++
#include "global.h"
_Ret_maybenull_
PEDITOR_CONTEXT _app_editor_createwindow (
- _In_ HWND hwnd,
+ _In_opt_ HWND hwnd,
_In_ PVOID lparam,
_In_ INT page_id,
_In_ BOOLEAN is_settorules
@@ -13,9 +13,17 @@ PEDITOR_CONTEXT _app_editor_createwindow (
{
PEDITOR_CONTEXT context;
- context = _r_mem_allocate (sizeof (EDITOR_CONTEXT));
+ context = (PEDITOR_CONTEXT)_r_mem_allocate (sizeof (EDITOR_CONTEXT));
+
+ if (is_settorules)
+ {
+ context->ptr_rule = (PITEM_RULE)lparam;
+ }
+ else
+ {
+ context->ptr_app = (PITEM_APP)lparam;
+ }
- context->ptr_app = lparam;
context->page_id = page_id;
context->is_settorules = is_settorules;
@@ -27,23 +35,12 @@ PEDITOR_CONTEXT _app_editor_createwindow (
return NULL;
}
-VOID _app_editor_deletewindow (
- _In_ PEDITOR_CONTEXT context
-)
-{
- _r_mem_free (context);
-}
-
_Ret_maybenull_
PEDITOR_CONTEXT _app_editor_getcontext (
_In_ HWND hwnd
)
{
- PEDITOR_CONTEXT context;
-
- context = _r_wnd_getcontext (hwnd, SHORT_MAX);
-
- return context;
+ return (PEDITOR_CONTEXT)_r_wnd_getcontext (hwnd, SHORT_MAX);
}
VOID _app_editor_setcontext (
@@ -72,9 +69,9 @@ VOID _app_editor_addtabitem (
_r_tab_adjustchild (hwnd, IDC_TAB, htab);
- BringWindowToTop (htab); // HACK!!!
-
_r_wnd_sendmessage (htab, 0, RM_INITIALIZE, 0, 0);
+
+ BringWindowToTop (htab); // HACK!!!
}
VOID _app_editor_settabtitle (
@@ -82,11 +79,10 @@ VOID _app_editor_settabtitle (
_In_ INT listview_id
)
{
- WCHAR buffer[128];
+ WCHAR buffer[0x80];
HWND hparent;
- UINT locale_id;
- INT checked_count;
- INT tab_id;
+ ULONG locale_id;
+ INT checked_count, tab_id;
if (listview_id == IDC_RULE_APPS_ID)
{
@@ -100,7 +96,7 @@ VOID _app_editor_settabtitle (
}
else
{
- return;
+ return; // unknown listview
}
hparent = GetParent (hwnd);
@@ -129,10 +125,11 @@ PR_STRING _app_editor_getrulesfromlistview (
item_count = _r_listview_getitemcount (hwnd, ctrl_id);
+ // there is no items
if (!item_count)
return NULL;
- _r_obj_initializestringbuilder (&sb, 512);
+ _r_obj_initializestringbuilder (&sb, 0);
for (INT i = 0; i < item_count; i++)
{
@@ -151,7 +148,6 @@ PR_STRING _app_editor_getrulesfromlistview (
if ((_r_str_getlength2 (&sb.string->sr) + _r_str_getlength2 (&string->sr)) > RULE_RULE_CCH_MAX)
{
_r_obj_dereference (string);
-
break;
}
@@ -180,32 +176,40 @@ PR_STRING _app_editor_getrulesfromlistview (
VOID _app_editor_setrulestolistview (
_In_ HWND hwnd,
_In_ INT ctrl_id,
- _In_ PR_STRING rule
+ _In_opt_ PR_STRING rule
)
{
+ R_STRINGREF first_part, remaining_part;
+ ITEM_ADDRESS address_checker;
PR_STRING rule_string;
- R_STRINGREF first_part;
- R_STRINGREF remaining_part;
INT item_id = 0;
+ if (_r_obj_isstringempty (rule)) // there is no data
+ return;
+
_r_obj_initializestringref2 (&remaining_part, &rule->sr);
+ _app_listview_lock (hwnd, ctrl_id);
+
while (remaining_part.length != 0)
{
_r_str_splitatchar (&remaining_part, DIVIDER_RULE[0], &first_part, &remaining_part);
+ if (!_app_parserulestring (&first_part, &address_checker))
+ continue; // do not add to listview when it cannot be parsed!
+
rule_string = _r_obj_createstring2 (&first_part);
- _app_listview_lock (hwnd, ctrl_id, TRUE);
_r_listview_additem (hwnd, ctrl_id, item_id, rule_string->buffer, I_DEFAULT, I_DEFAULT, I_DEFAULT);
- _app_listview_lock (hwnd, ctrl_id, FALSE);
-
- item_id += 1;
_r_obj_dereference (rule_string);
+
+ item_id += 1;
}
- _r_listview_setcolumn (hwnd, ctrl_id, 0, NULL, -100);
+ _app_listview_unlock (hwnd, ctrl_id);
+
+ _r_listview_setcolumn (hwnd, ctrl_id, 0, NULL, -100); // change column width to 100%
}
INT_PTR CALLBACK EditorRuleProc (
@@ -227,6 +231,7 @@ INT_PTR CALLBACK EditorRuleProc (
_app_editor_setcontext (hwnd, context);
+ // center window
_r_wnd_center (hwnd, GetParent (hwnd));
// localize window
@@ -261,15 +266,10 @@ INT_PTR CALLBACK EditorRuleProc (
L"eg. 20-21; 49152-65534;\r\neg. 21; 80; 443\r\n"
);
- _r_ctrl_setstring (
- hwnd,
- IDC_SAVE,
- _r_locale_getstring (context->item_id != INT_ERROR ? IDS_SAVE : IDS_ADD)
- );
-
+ _r_ctrl_setstring (hwnd, IDC_SAVE, _r_locale_getstring (context->item_id != INT_ERROR ? IDS_SAVE : IDS_ADD));
_r_ctrl_setstring (hwnd, IDC_CLOSE, _r_locale_getstring (IDS_CLOSE));
- // enable save button
+ // enable save button when rule name is not empty
_r_ctrl_enable (hwnd, IDC_SAVE, _r_ctrl_getstringlength (hwnd, IDC_RULE_ID) != 0);
_r_theme_initialize (hwnd);
@@ -281,7 +281,7 @@ INT_PTR CALLBACK EditorRuleProc (
case WM_CLOSE:
{
- EndDialog (hwnd, FALSE);
+ EndDialog (hwnd, 0);
break;
}
@@ -321,13 +321,14 @@ INT_PTR CALLBACK EditorRuleProc (
if (notify_code == EN_CHANGE)
{
- // enable save button
+ // enable save button when rule name is not empty
_r_ctrl_enable (hwnd, IDC_SAVE, _r_ctrl_getstringlength (hwnd, IDC_RULE_ID) != 0);
return FALSE;
}
else if (notify_code == EN_MAXTEXT)
{
+ // show limit was reached ballon tip
_r_ctrl_showballoontip (hwnd, ctrl_id, 0, NULL, _r_locale_getstring (IDS_LIMIT_REACHED));
return FALSE;
@@ -338,10 +339,9 @@ INT_PTR CALLBACK EditorRuleProc (
case IDOK: // process Enter key
case IDC_SAVE:
{
+ R_STRINGREF first_part, remaining_part;
+ WCHAR rule_string[0x100];
ITEM_ADDRESS address;
- R_STRINGREF remaining_part;
- R_STRINGREF first_part;
- WCHAR rule_string[256];
PR_STRING string;
INT item_id;
@@ -381,14 +381,12 @@ INT_PTR CALLBACK EditorRuleProc (
if (!_app_parserulestring (&first_part, &address))
{
_r_ctrl_showballoontip (hwnd, IDC_RULE_ID, 0, NULL, _r_locale_getstring (IDS_STATUS_SYNTAX_ERROR));
-
_r_ctrl_enable (hwnd, IDC_SAVE, FALSE);
return FALSE;
}
_r_str_copystring (rule_string, RTL_NUMBER_OF (rule_string), &first_part);
-
_r_listview_additem (context->hwnd, context->listview_id, item_id, rule_string, I_DEFAULT, I_DEFAULT, I_DEFAULT);
item_id += 1;
@@ -407,7 +405,7 @@ INT_PTR CALLBACK EditorRuleProc (
case IDCANCEL: // process Esc key
case IDC_CLOSE:
{
- EndDialog (hwnd, FALSE);
+ EndDialog (hwnd, 0);
break;
}
}
@@ -432,13 +430,13 @@ INT_PTR CALLBACK EditorPagesProc (
{
case WM_INITDIALOG:
{
- WCHAR buffer[256];
+ WCHAR buffer[0x100];
PITEM_APP ptr_app = NULL;
PITEM_RULE ptr_rule;
PR_STRING string;
HWND hctrl;
- INT i;
ULONG_PTR enum_key;
+ INT i;
BOOLEAN is_enabled;
context = (PEDITOR_CONTEXT)lparam;
@@ -447,15 +445,7 @@ INT_PTR CALLBACK EditorPagesProc (
EnableThemeDialogTexture (hwnd, ETDT_ENABLETAB);
- SetWindowPos (
- hwnd,
- HWND_TOP,
- 0,
- 0,
- 0,
- 0,
- SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED
- );
+ _r_wnd_topzoder (hwnd, TRUE);
// name
if (GetDlgItem (hwnd, IDC_RULE_NAME_ID))
@@ -463,7 +453,7 @@ INT_PTR CALLBACK EditorPagesProc (
_r_ctrl_setstringformat (hwnd, IDC_RULE_NAME, L"%s:", _r_locale_getstring (IDS_NAME));
if (!_r_obj_isstringempty (context->ptr_rule->name))
- _r_ctrl_setstring (hwnd, IDC_RULE_NAME_ID, context->ptr_rule->name->buffer);
+ _r_ctrl_setstringlength (hwnd, IDC_RULE_NAME_ID, &context->ptr_rule->name->sr);
_r_ctrl_setreadonly (hwnd, IDC_RULE_NAME_ID, !!context->ptr_rule->is_readonly);
_r_ctrl_settextlimit (hwnd, IDC_RULE_NAME_ID, RULE_NAME_CCH_MAX - 1);
@@ -475,7 +465,7 @@ INT_PTR CALLBACK EditorPagesProc (
_r_ctrl_setstringformat (hwnd, IDC_RULE_COMMENT, L"%s:", _r_locale_getstring (IDS_COMMENT));
if (!_r_obj_isstringempty (context->ptr_rule->comment))
- _r_ctrl_setstring (hwnd, IDC_RULE_COMMENT_ID, context->ptr_rule->comment->buffer);
+ _r_ctrl_setstringlength (hwnd, IDC_RULE_COMMENT_ID, &context->ptr_rule->comment->sr);
_r_ctrl_enable (hwnd, IDC_RULE_COMMENT_ID, !context->ptr_rule->is_readonly);
_r_ctrl_settextlimit (hwnd, IDC_RULE_COMMENT_ID, RULE_RULE_CCH_MAX - 1);
@@ -514,15 +504,36 @@ INT_PTR CALLBACK EditorPagesProc (
UINT8 protos[] = {
IPPROTO_ICMP,
IPPROTO_IGMP,
+ IPPROTO_GGP,
IPPROTO_IPV4,
+ IPPROTO_ST,
IPPROTO_TCP,
+ IPPROTO_CBT,
+ IPPROTO_EGP,
+ IPPROTO_IGP,
+ IPPROTO_PUP,
IPPROTO_UDP,
+ IPPROTO_IDP,
IPPROTO_RDP,
IPPROTO_IPV6,
+ IPPROTO_ROUTING,
+ IPPROTO_FRAGMENT,
+ IPPROTO_ESP,
+ IPPROTO_AH,
IPPROTO_ICMPV6,
+ IPPROTO_DSTOPTS,
+ IPPROTO_ND,
+ IPPROTO_ICLFXBM,
+ IPPROTO_PIM,
+ IPPROTO_PGM,
IPPROTO_L2TP,
IPPROTO_SCTP,
IPPROTO_RAW,
+ // reserved for internal use by M$
+ //IPPROTO_RESERVED_RAW,
+ //IPPROTO_RESERVED_IPSEC,
+ //IPPROTO_RESERVED_IPSECOFFLOAD,
+ //IPPROTO_RESERVED_WNV,
};
_r_ctrl_setstringformat (hwnd, IDC_RULE_PROTOCOL, L"%s:", _r_locale_getstring (IDS_PROTOCOL));
@@ -531,7 +542,9 @@ INT_PTR CALLBACK EditorPagesProc (
for (i = 0; i < RTL_NUMBER_OF (protos); i++)
{
- _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"%s (%" TEXT (PRIu8) L")", _app_db_getprotoname (protos[i], AF_UNSPEC), protos[i]);
+ _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"ptr_rule->protocol != 0)
{
- _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"%s (%" TEXT (PRIu8) L")", _app_db_getprotoname (context->ptr_rule->protocol, AF_UNSPEC), context->ptr_rule->protocol);
+ _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L" (% " TEXT (PRIu8) L")", protos[i]);
+
+ _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"%s (%" TEXT (PRIu8) L")", _app_db_getprotoname (context->ptr_rule->protocol, AF_UNSPEC, buffer), context->ptr_rule->protocol);
_r_combobox_insertitem (hwnd, IDC_RULE_PROTOCOL_ID, i + 1, buffer, (LPARAM)context->ptr_rule->protocol);
}
@@ -568,21 +583,11 @@ INT_PTR CALLBACK EditorPagesProc (
{
_r_ctrl_setstringformat (hwnd, IDC_RULE_REMOTE, L"%s (%s):", _r_locale_getstring (IDS_RULE), _r_locale_getstring (IDS_DIRECTION_REMOTE));
- _r_listview_setstyle (
- hwnd,
- IDC_RULE_REMOTE_ID,
- LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP,
- FALSE
- );
+ _r_listview_setstyle (hwnd, IDC_RULE_REMOTE_ID, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_DOUBLEBUFFER | LVS_EX_LABELTIP, FALSE);
_r_listview_addcolumn (hwnd, IDC_RULE_REMOTE_ID, 0, NULL, -100, 0);
- if (!_r_obj_isstringempty (context->ptr_rule->rule_remote))
- {
- _app_editor_setrulestolistview (hwnd, IDC_RULE_REMOTE_ID, context->ptr_rule->rule_remote);
-
- _r_listview_setcolumn (hwnd, IDC_RULE_REMOTE_ID, 0, NULL, -100);
- }
+ _app_editor_setrulestolistview (hwnd, IDC_RULE_REMOTE_ID, context->ptr_rule->rule_remote);
_r_ctrl_setstringformat (hwnd, IDC_RULE_REMOTE_ADD, L"%s...", _r_locale_getstring (IDS_ADD));
_r_ctrl_setstringformat (hwnd, IDC_RULE_REMOTE_EDIT, L"%s...", _r_locale_getstring (IDS_EDIT2));
@@ -598,21 +603,11 @@ INT_PTR CALLBACK EditorPagesProc (
{
_r_ctrl_setstringformat (hwnd, IDC_RULE_LOCAL, L"%s (%s):", _r_locale_getstring (IDS_RULE), _r_locale_getstring (IDS_DIRECTION_LOCAL));
- _r_listview_setstyle (
- hwnd,
- IDC_RULE_LOCAL_ID,
- LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP,
- FALSE
- );
+ _r_listview_setstyle (hwnd, IDC_RULE_LOCAL_ID, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_DOUBLEBUFFER | LVS_EX_LABELTIP, FALSE);
_r_listview_addcolumn (hwnd, IDC_RULE_LOCAL_ID, 0, NULL, 100, 0);
- if (!_r_obj_isstringempty (context->ptr_rule->rule_local))
- {
- _app_editor_setrulestolistview (hwnd, IDC_RULE_LOCAL_ID, context->ptr_rule->rule_local);
-
- _r_listview_setcolumn (hwnd, IDC_RULE_LOCAL_ID, 0, NULL, -100);
- }
+ _app_editor_setrulestolistview (hwnd, IDC_RULE_LOCAL_ID, context->ptr_rule->rule_local);
_r_ctrl_setstringformat (hwnd, IDC_RULE_LOCAL_ADD, L"%s...", _r_locale_getstring (IDS_ADD));
_r_ctrl_setstringformat (hwnd, IDC_RULE_LOCAL_EDIT, L"%s...", _r_locale_getstring (IDS_EDIT2));
@@ -630,7 +625,7 @@ INT_PTR CALLBACK EditorPagesProc (
{
_app_search_create (hctrl);
- SetWindowPos (hctrl, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED); // HACK!!!
+ _r_wnd_topzoder (hctrl, FALSE); // HACK!!!
}
// apps
@@ -638,20 +633,14 @@ INT_PTR CALLBACK EditorPagesProc (
{
_app_listview_setview (hwnd, IDC_RULE_APPS_ID);
- _r_listview_setstyle (
- hwnd,
- IDC_RULE_APPS_ID,
- LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_CHECKBOXES,
- TRUE
- );
+ _r_listview_setstyle (hwnd, IDC_RULE_APPS_ID, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_DOUBLEBUFFER, TRUE);
_r_listview_addcolumn (hwnd, IDC_RULE_APPS_ID, 0, _r_locale_getstring (IDS_NAME), 100, LVCFMT_LEFT);
_r_listview_addgroup (hwnd, IDC_RULE_APPS_ID, 0, L"", 0, LVGS_COLLAPSIBLE, LVGS_COLLAPSIBLE);
_r_listview_addgroup (hwnd, IDC_RULE_APPS_ID, 1, L"", 0, LVGS_COLLAPSIBLE, LVGS_COLLAPSIBLE);
_r_listview_addgroup (hwnd, IDC_RULE_APPS_ID, 2, L"", 0, LVGS_COLLAPSIBLE, LVGS_COLLAPSIBLE);
-
- _r_listview_addgroup (hwnd, IDC_RULE_APPS_ID, LV_HIDDEN_GROUP_ID, L"", 3, LVGS_HIDDEN, LVGS_HIDDEN);
+ _r_listview_addgroup (hwnd, IDC_RULE_APPS_ID, LV_HIDDEN_GROUP_ID, L"", 0, LVGS_COLLAPSED | LVGS_HIDDEN, LVGS_COLLAPSED | LVGS_HIDDEN);
// apps (apply to)
enum_key = 0;
@@ -661,20 +650,19 @@ INT_PTR CALLBACK EditorPagesProc (
while (_r_obj_enumhashtablepointer (apps_table, (PVOID_PTR)&ptr_app, NULL, &enum_key))
{
// check for services
- is_enabled = ((_r_obj_findhashtable (context->ptr_rule->apps, ptr_app->app_hash)) || (context->ptr_rule->is_forservices && _app_issystemhash (ptr_app->app_hash)));
+ is_enabled = ((_r_obj_findhashtable (context->ptr_rule->apps, ptr_app->app_hash)) || (context->ptr_rule->is_forservice && _app_issystemhash (ptr_app->app_hash)));
- _app_listview_lock (hwnd, IDC_RULE_APPS_ID, TRUE);
+ _app_listview_lock (hwnd, IDC_RULE_APPS_ID);
_r_listview_additem (hwnd, IDC_RULE_APPS_ID, 0, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_listview_createcontext (ptr_app->app_hash));
-
_r_listview_setitemcheck (hwnd, IDC_RULE_APPS_ID, 0, is_enabled);
- _app_listview_lock (hwnd, IDC_RULE_APPS_ID, FALSE);
+ _app_listview_unlock (hwnd, IDC_RULE_APPS_ID);
}
_r_queuedlock_releaseshared (&lock_apps);
- // resize column
+ // resize column to 100%
_r_listview_setcolumn (hwnd, IDC_RULE_APPS_ID, 0, NULL, -100);
// localize groups
@@ -701,7 +689,7 @@ INT_PTR CALLBACK EditorPagesProc (
{
context->hicon = _app_icons_getsafeapp_hicon (context->ptr_app->app_hash);
- _r_wnd_sendmessage (hwnd, IDC_APP_ICON_ID, STM_SETICON, (WPARAM)context->hicon, 0);
+ _r_ctrl_seticon2 (hwnd, IDC_APP_ICON_ID, context->hicon);
}
// app display name
@@ -711,7 +699,7 @@ INT_PTR CALLBACK EditorPagesProc (
if (string)
{
- _r_ctrl_setstring (hwnd, IDC_APP_NAME_ID, string->buffer);
+ _r_ctrl_setstringlength (hwnd, IDC_APP_NAME_ID, &string->sr);
_r_obj_dereference (string);
}
@@ -743,7 +731,6 @@ INT_PTR CALLBACK EditorPagesProc (
);
_r_ctrl_settextmargin (hwnd, IDC_APP_NAME_ID, 0, 0);
-
_r_ctrl_settextmargin (hwnd, IDC_APP_SIGNATURE_ID, 0, 0);
if (string)
@@ -755,7 +742,7 @@ INT_PTR CALLBACK EditorPagesProc (
{
if (_app_isappvalidpath (context->ptr_app->real_path))
{
- _r_ctrl_setstring (hwnd, IDC_APP_PATH_ID, context->ptr_app->real_path->buffer);
+ _r_ctrl_setstringlength (hwnd, IDC_APP_PATH_ID, &context->ptr_app->real_path->sr);
}
else
{
@@ -773,44 +760,38 @@ INT_PTR CALLBACK EditorPagesProc (
// configure listview
_app_listview_setview (hwnd, IDC_APP_RULES_ID);
- _r_listview_setstyle (
- hwnd,
- IDC_APP_RULES_ID,
- LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_CHECKBOXES,
- TRUE
- );
+ _r_listview_setstyle (hwnd, IDC_APP_RULES_ID, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_DOUBLEBUFFER, TRUE);
_r_listview_addcolumn (hwnd, IDC_APP_RULES_ID, 0, _r_locale_getstring (IDS_NAME), 100, LVCFMT_LEFT);
_r_listview_addgroup (hwnd, IDC_APP_RULES_ID, 0, _r_locale_getstring (IDS_TRAY_SYSTEM_RULES), 0, LVGS_COLLAPSIBLE, LVGS_COLLAPSIBLE);
_r_listview_addgroup (hwnd, IDC_APP_RULES_ID, 1, _r_locale_getstring (IDS_TRAY_USER_RULES), 0, LVGS_COLLAPSIBLE, LVGS_COLLAPSIBLE);
- _r_listview_addgroup (hwnd, IDC_APP_RULES_ID, LV_HIDDEN_GROUP_ID, L"", 2, LVGS_COLLAPSED, LVGS_COLLAPSED);
+ _r_listview_addgroup (hwnd, IDC_APP_RULES_ID, LV_HIDDEN_GROUP_ID, L"", 0, LVGS_COLLAPSED | LVGS_HIDDEN, LVGS_COLLAPSED | LVGS_HIDDEN);
// initialize
_r_queuedlock_acquireshared (&lock_rules);
+ _app_listview_lock (hwnd, IDC_APP_RULES_ID);
+
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
if (!ptr_rule || ptr_rule->type != DATA_RULE_USER)
continue;
// check for services
- is_enabled = ((ptr_rule->is_forservices && _app_issystemhash (context->ptr_app->app_hash)) || _r_obj_findhashtable (ptr_rule->apps, context->ptr_app->app_hash));
-
- _app_listview_lock (hwnd, IDC_APP_RULES_ID, TRUE);
+ is_enabled = (((ptr_rule->is_fordriver || ptr_rule->is_forservice) && _app_issystemhash (context->ptr_app->app_hash)) || _r_obj_findhashtable (ptr_rule->apps, context->ptr_app->app_hash));
_r_listview_additem (hwnd, IDC_APP_RULES_ID, 0, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_listview_createcontext ((ULONG)i));
-
_r_listview_setitemcheck (hwnd, IDC_APP_RULES_ID, 0, is_enabled);
-
- _app_listview_lock (hwnd, IDC_APP_RULES_ID, FALSE);
}
+ _app_listview_unlock (hwnd, IDC_APP_RULES_ID);
+
_r_queuedlock_releaseshared (&lock_rules);
- // resize column
+ // resize column to 100%
_r_listview_setcolumn (hwnd, IDC_APP_RULES_ID, 0, NULL, -100);
// localize groups
@@ -821,12 +802,12 @@ INT_PTR CALLBACK EditorPagesProc (
}
// hints
- if (GetDlgItem (hwnd, IDC_RULE_HINT))
- _r_ctrl_setstring (hwnd, IDC_RULE_HINT, _r_locale_getstring (IDS_RULE_HINT));
-
if (GetDlgItem (hwnd, IDC_RULE_APPS_HINT))
_r_ctrl_setstring (hwnd, IDC_RULE_APPS_HINT, _r_locale_getstring (IDS_RULE_APPS_HINT));
+ if (GetDlgItem (hwnd, IDC_RULE_HINT))
+ _r_ctrl_setstring (hwnd, IDC_RULE_HINT, _r_locale_getstring (IDS_RULE_HINT));
+
if (GetDlgItem (hwnd, IDC_APP_HINT))
_r_ctrl_setstring (hwnd, IDC_APP_HINT, _r_locale_getstring (IDS_APP_HINT));
@@ -858,10 +839,7 @@ INT_PTR CALLBACK EditorPagesProc (
context = _app_editor_getcontext (hwnd);
- if (!context)
- break;
-
- if (context->hicon)
+ if (context && context->hicon)
DestroyIcon (context->hicon);
break;
@@ -869,14 +847,8 @@ INT_PTR CALLBACK EditorPagesProc (
case WM_SIZE:
{
- INT listview_ids[] = {
- IDC_RULE_APPS_ID,
- IDC_APP_RULES_ID,
- IDC_RULE_REMOTE_ID,
- IDC_RULE_LOCAL_ID,
- };
-
HWND hlistview;
+ INT listview_ids[] = {IDC_RULE_APPS_ID, IDC_APP_RULES_ID, IDC_RULE_REMOTE_ID, IDC_RULE_LOCAL_ID};
for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (listview_ids); i++)
{
@@ -908,52 +880,36 @@ INT_PTR CALLBACK EditorPagesProc (
case NM_DBLCLK:
{
- LPNMITEMACTIVATE lpnmlv;
- ULONG command_id = 0;
- INT listview_id;
-
- lpnmlv = (LPNMITEMACTIVATE)lparam;
+ LPNMITEMACTIVATE lpnmlv = (LPNMITEMACTIVATE)lparam;
if (lpnmlv->iItem == INT_ERROR)
break;
- listview_id = (INT)(INT_PTR)(lpnmlv->hdr.idFrom);
-
- if (listview_id == IDC_RULE_REMOTE_ID)
+ if (lpnmlv->hdr.idFrom == IDC_RULE_REMOTE_ID)
{
- command_id = IDC_RULE_REMOTE_EDIT;
+ _r_wnd_sendcommand (hwnd, IDC_RULE_REMOTE_EDIT, 0);
}
- else if (listview_id == IDC_RULE_LOCAL_ID)
+ else if (lpnmlv->hdr.idFrom == IDC_RULE_LOCAL_ID)
{
- command_id = IDC_RULE_LOCAL_EDIT;
+ _r_wnd_sendcommand (hwnd, IDC_RULE_LOCAL_EDIT, 0);
}
- else if (listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID)
+ else if (lpnmlv->hdr.idFrom == IDC_RULE_APPS_ID || lpnmlv->hdr.idFrom == IDC_APP_RULES_ID)
{
- command_id = IDM_PROPERTIES;
+ _r_wnd_sendcommand (hwnd, IDM_PROPERTIES, 0);
}
- if (command_id)
- _r_ctrl_sendcommand (hwnd, command_id, 0);
-
break;
}
case NM_RCLICK:
{
- LPNMITEMACTIVATE lpnmlv;
- HMENU hsubmenu;
+ LPNMITEMACTIVATE lpnmlv = (LPNMITEMACTIVATE)lparam;
PR_STRING localized_string = NULL;
- UINT id_add;
- UINT id_edit;
- UINT id_delete;
- INT listview_id;
- BOOLEAN is_remote;
- BOOLEAN is_selected;
+ HMENU hsubmenu;
+ ULONG id_add, id_delete, id_edit;
+ BOOLEAN is_remote, is_selected;
- lpnmlv = (LPNMITEMACTIVATE)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- if (listview_id != IDC_RULE_REMOTE_ID && listview_id != IDC_RULE_LOCAL_ID && listview_id != IDC_RULE_APPS_ID && listview_id != IDC_APP_RULES_ID)
+ if (lpnmlv->hdr.idFrom != IDC_RULE_REMOTE_ID && lpnmlv->hdr.idFrom != IDC_RULE_LOCAL_ID && lpnmlv->hdr.idFrom != IDC_RULE_APPS_ID && lpnmlv->hdr.idFrom != IDC_APP_RULES_ID)
break;
context = _app_editor_getcontext (hwnd);
@@ -966,11 +922,11 @@ INT_PTR CALLBACK EditorPagesProc (
if (!hsubmenu)
break;
- is_selected = _r_listview_getselectedcount (hwnd, listview_id) != 0;
+ is_selected = _r_listview_getselectedcount (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom) != 0;
- if (listview_id == IDC_RULE_REMOTE_ID || listview_id == IDC_RULE_LOCAL_ID)
+ if (lpnmlv->hdr.idFrom == IDC_RULE_REMOTE_ID || lpnmlv->hdr.idFrom == IDC_RULE_LOCAL_ID)
{
- is_remote = (listview_id == IDC_RULE_REMOTE_ID);
+ is_remote = (lpnmlv->hdr.idFrom == IDC_RULE_REMOTE_ID);
id_add = is_remote ? IDC_RULE_REMOTE_ADD : IDC_RULE_LOCAL_ADD;
id_edit = is_remote ? IDC_RULE_REMOTE_EDIT : IDC_RULE_LOCAL_EDIT;
@@ -1002,7 +958,7 @@ INT_PTR CALLBACK EditorPagesProc (
_r_obj_dereference (localized_string);
}
- else if (listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID)
+ else if (lpnmlv->hdr.idFrom == IDC_RULE_APPS_ID || lpnmlv->hdr.idFrom == IDC_APP_RULES_ID)
{
_r_menu_additem (hsubmenu, IDM_CHECK, _r_locale_getstring (IDS_CHECK));
_r_menu_additem (hsubmenu, IDM_UNCHECK, _r_locale_getstring (IDS_UNCHECK));
@@ -1023,7 +979,7 @@ INT_PTR CALLBACK EditorPagesProc (
}
}
- _r_menu_popup (hsubmenu, hwnd, NULL, TRUE);
+ _r_menu_popup (hsubmenu, hwnd, NULL, 0);
DestroyMenu (hsubmenu);
@@ -1032,59 +988,41 @@ INT_PTR CALLBACK EditorPagesProc (
case LVN_DELETEITEM:
{
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
PITEM_LISTVIEW_CONTEXT listview_context;
- LPNMLISTVIEW lpnmlv;
- INT listview_id;
- lpnmlv = (LPNMLISTVIEW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- if (!(listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID))
+ if (!(lpnmlv->hdr.idFrom == IDC_RULE_APPS_ID || lpnmlv->hdr.idFrom == IDC_APP_RULES_ID))
break;
listview_context = (PITEM_LISTVIEW_CONTEXT)lpnmlv->lParam;
- if (!listview_context)
- break;
-
- _app_listview_destroycontext (listview_context);
+ if (listview_context)
+ _app_listview_destroycontext (listview_context);
break;
}
case LVN_GETDISPINFO:
{
- LPNMLVDISPINFOW lpnmlv;
- INT listview_id;
+ LPNMLVDISPINFOW lpnmlv = (LPNMLVDISPINFOW)lparam;
- lpnmlv = (LPNMLVDISPINFOW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- _app_message_displayinfo (hwnd, listview_id, lpnmlv);
+ _app_message_displayinfo (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lpnmlv);
break;
}
case LVN_COLUMNCLICK:
{
- LPNMLISTVIEW lpnmlv;
- INT listview_id;
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
- lpnmlv = (LPNMLISTVIEW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- _app_listview_sort (hwnd, listview_id, lpnmlv->iSubItem, TRUE);
+ _app_listview_sort (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lpnmlv->iSubItem, TRUE);
break;
}
case LVN_ITEMCHANGING:
{
- LPNMLISTVIEW lpnmlv;
- INT listview_id;
-
- lpnmlv = (LPNMLISTVIEW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
context = _app_editor_getcontext (hwnd);
@@ -1093,7 +1031,7 @@ INT_PTR CALLBACK EditorPagesProc (
if ((lpnmlv->uChanged & LVIF_STATE) != 0)
{
- if (listview_id == IDC_RULE_APPS_ID)
+ if (lpnmlv->hdr.idFrom == IDC_RULE_APPS_ID)
{
if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (1) || ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2)))
{
@@ -1113,11 +1051,9 @@ INT_PTR CALLBACK EditorPagesProc (
case LVN_ITEMCHANGED:
{
LPNMLISTVIEW lpnmlv;
- INT listview_id;
BOOLEAN is_selected;
lpnmlv = (LPNMLISTVIEW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
context = _app_editor_getcontext (hwnd);
@@ -1126,20 +1062,20 @@ INT_PTR CALLBACK EditorPagesProc (
if ((lpnmlv->uChanged & LVIF_STATE) != 0)
{
- if (listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID)
+ if (lpnmlv->hdr.idFrom == IDC_RULE_APPS_ID || lpnmlv->hdr.idFrom == IDC_APP_RULES_ID)
{
if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (1) || ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2)))
{
if (_app_listview_islocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom))
break;
- _app_editor_settabtitle (hwnd, listview_id);
+ _app_editor_settabtitle (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom);
- _app_listview_refreshgroups (hwnd, listview_id);
- _app_listview_sort (hwnd, listview_id, INT_ERROR, FALSE);
+ _app_listview_refreshgroups (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom);
+ _app_listview_sort (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, INT_ERROR, FALSE);
}
}
- else if (listview_id == IDC_RULE_REMOTE_ID || listview_id == IDC_RULE_LOCAL_ID)
+ else if (lpnmlv->hdr.idFrom == IDC_RULE_REMOTE_ID || lpnmlv->hdr.idFrom == IDC_RULE_LOCAL_ID)
{
if ((lpnmlv->uOldState & LVIS_SELECTED) != 0 || (lpnmlv->uNewState & LVIS_SELECTED) != 0)
{
@@ -1147,12 +1083,12 @@ INT_PTR CALLBACK EditorPagesProc (
{
is_selected = (lpnmlv->uNewState & LVIS_SELECTED) != 0;
- if (listview_id == IDC_RULE_REMOTE_ID)
+ if (lpnmlv->hdr.idFrom == IDC_RULE_REMOTE_ID)
{
_r_ctrl_enable (hwnd, IDC_RULE_REMOTE_EDIT, is_selected);
_r_ctrl_enable (hwnd, IDC_RULE_REMOTE_DELETE, is_selected);
}
- else if (listview_id == IDC_RULE_LOCAL_ID)
+ else if (lpnmlv->hdr.idFrom == IDC_RULE_LOCAL_ID)
{
_r_ctrl_enable (hwnd, IDC_RULE_LOCAL_EDIT, is_selected);
_r_ctrl_enable (hwnd, IDC_RULE_LOCAL_DELETE, is_selected);
@@ -1167,20 +1103,16 @@ INT_PTR CALLBACK EditorPagesProc (
case LVN_GETINFOTIP:
{
- LPNMLVGETINFOTIPW lpnmlv;
+ LPNMLVGETINFOTIPW lpnmlv = (LPNMLVGETINFOTIPW)lparam;
PR_STRING string;
ULONG_PTR context;
- INT listview_id;
- lpnmlv = (LPNMLVGETINFOTIPW)lparam;
- listview_id = (INT)lpnmlv->hdr.idFrom;
-
- if (listview_id != IDC_RULE_APPS_ID && listview_id != IDC_APP_RULES_ID)
+ if (lpnmlv->hdr.idFrom != IDC_RULE_APPS_ID && lpnmlv->hdr.idFrom != IDC_APP_RULES_ID)
break;
- context = _app_listview_getitemcontext (hwnd, listview_id, lpnmlv->iItem);
+ context = _app_listview_getitemcontext (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lpnmlv->iItem);
- string = _app_gettooltipbylparam (hwnd, listview_id, context);
+ string = _app_gettooltipbylparam (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, context);
if (!string)
break;
@@ -1265,9 +1197,8 @@ INT_PTR CALLBACK EditorPagesProc (
case IDC_RULE_LOCAL_EDIT:
{
PR_STRING string;
- ULONG_PTR current_length;
- INT listview_id;
- INT item_id;
+ ULONG_PTR current_length = 0;
+ INT item_id, listview_id;
if (!_r_ctrl_isenabled (hwnd, ctrl_id))
break;
@@ -1296,10 +1227,6 @@ INT_PTR CALLBACK EditorPagesProc (
_r_obj_dereference (string);
}
- else
- {
- current_length = 0;
- }
if (ctrl_id == IDC_RULE_REMOTE_ADD || ctrl_id == IDC_RULE_LOCAL_ADD)
{
@@ -1329,15 +1256,11 @@ INT_PTR CALLBACK EditorPagesProc (
case IDC_RULE_REMOTE_DELETE:
case IDC_RULE_LOCAL_DELETE:
{
- INT listview_id;
- INT selected_count;
- INT item_count;
+ INT item_count, listview_id;
listview_id = ((ctrl_id == IDC_RULE_REMOTE_DELETE) ? IDC_RULE_REMOTE_ID : IDC_RULE_LOCAL_ID);
- selected_count = _r_listview_getselectedcount (hwnd, listview_id);
-
- if (!selected_count)
+ if (!_r_listview_getselectedcount (hwnd, listview_id))
break;
if (_r_show_message (hwnd, MB_YESNO | MB_ICONEXCLAMATION, NULL, _r_locale_getstring (IDS_QUESTION_DELETE)) != IDYES)
@@ -1359,8 +1282,7 @@ INT_PTR CALLBACK EditorPagesProc (
case IDM_CHECK:
case IDM_UNCHECK:
{
- INT listview_id;
- INT item_id = INT_ERROR;
+ INT item_id = INT_ERROR, listview_id;
BOOLEAN new_val;
if (GetDlgItem (hwnd, IDC_RULE_APPS_ID))
@@ -1378,14 +1300,14 @@ INT_PTR CALLBACK EditorPagesProc (
new_val = (ctrl_id == IDM_CHECK);
- _app_listview_lock (hwnd, listview_id, TRUE);
+ _app_listview_lock (hwnd, listview_id);
while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != INT_ERROR)
{
_r_listview_setitemcheck (hwnd, listview_id, item_id, new_val);
}
- _app_listview_lock (hwnd, listview_id, FALSE);
+ _app_listview_unlock (hwnd, listview_id);
_app_listview_refreshgroups (hwnd, listview_id);
_app_listview_sort (hwnd, listview_id, INT_ERROR, FALSE);
@@ -1397,10 +1319,7 @@ INT_PTR CALLBACK EditorPagesProc (
{
context = _app_editor_getcontext (hwnd);
- if (!context)
- break;
-
- if (_app_isappvalidpath (context->ptr_app->real_path))
+ if (context && _app_isappvalidpath (context->ptr_app->real_path))
_r_shell_showfile (&context->ptr_app->real_path->sr);
break;
@@ -1430,15 +1349,19 @@ INT_PTR CALLBACK EditorPagesProc (
NtClose (hfile);
}
+ else
+ {
+ _r_show_errormessage (hwnd, L"Could not open file!", status, context->ptr_app->real_path->buffer, ET_NATIVE);
+ }
break;
}
case IDM_PROPERTIES:
{
+ HWND hmain;
ULONG_PTR index;
- INT listview_id;
- INT item_id;
+ INT item_id, listview_id;
if (GetDlgItem (hwnd, IDC_RULE_APPS_ID))
{
@@ -1459,7 +1382,10 @@ INT_PTR CALLBACK EditorPagesProc (
{
index = _app_listview_getitemcontext (hwnd, listview_id, item_id);
- _app_listview_showitemby_param (_r_app_gethwnd (), index, (listview_id == IDC_RULE_APPS_ID));
+ hmain = _r_app_gethwnd ();
+
+ if (hmain)
+ _app_listview_showitemby_param (hmain, index, (listview_id == IDC_RULE_APPS_ID));
}
break;
@@ -1470,8 +1396,7 @@ INT_PTR CALLBACK EditorPagesProc (
R_STRINGBUILDER sb;
PR_STRING string;
HWND hlistview;
- INT listview_id;
- INT item_id = INT_ERROR;
+ INT item_id = INT_ERROR, listview_id;
hlistview = GetFocus ();
@@ -1483,7 +1408,7 @@ INT_PTR CALLBACK EditorPagesProc (
if (!listview_id || !_r_listview_getitemcount (hwnd, listview_id))
break;
- _r_obj_initializestringbuilder (&sb, 512);
+ _r_obj_initializestringbuilder (&sb, 0);
while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != INT_ERROR)
{
@@ -1530,7 +1455,7 @@ INT_PTR CALLBACK EditorProc (
{
case WM_INITDIALOG:
{
- WCHAR title[128] = {0};
+ WCHAR title[0x80] = {0};
PR_STRING string;
context = (PEDITOR_CONTEXT)lparam;
@@ -1540,7 +1465,7 @@ INT_PTR CALLBACK EditorProc (
// configure tabs
if (context->is_settorules)
{
- _r_str_copy (title, RTL_NUMBER_OF (title), _r_obj_getstringorempty (context->ptr_rule->name));
+ _r_str_copy (title, RTL_NUMBER_OF (title), _r_obj_getstringordefault (context->ptr_rule->name, L""));
if (context->ptr_rule->is_readonly)
_r_str_appendformat (title, RTL_NUMBER_OF (title), L" (%s)", _r_locale_getstring (IDS_INTERNAL_RULE));
@@ -1558,12 +1483,10 @@ INT_PTR CALLBACK EditorProc (
{
string = _app_getappdisplayname (context->ptr_app, TRUE);
- if (string)
- {
- _r_str_copy (title, RTL_NUMBER_OF (title), string->buffer);
+ _r_str_copy (title, RTL_NUMBER_OF (title), _r_obj_getstringordefault (string, L""));
+ if (string)
_r_obj_dereference (string);
- }
_app_editor_addtabitem (hwnd, IDS_SETTINGS_GENERAL, IDD_EDITOR_APPINFO, context);
_app_editor_addtabitem (hwnd, IDS_TRAY_RULES, IDD_EDITOR_APPRULES, context);
@@ -1577,11 +1500,11 @@ INT_PTR CALLBACK EditorProc (
// initialize layout
_r_layout_initializemanager (&context->layout_manager, hwnd);
- _r_wnd_top (hwnd, TRUE);
+ _r_wnd_top (hwnd, TRUE); // set on top
+ _r_wnd_center (hwnd, GetParent (hwnd)); // center window
+ _r_window_restoreposition (hwnd, L"editor"); // restore window
- _r_wnd_center (hwnd, GetParent (hwnd));
-
- _r_window_restoreposition (hwnd, L"editor");
+ EnableWindow (GetParent (hwnd), TRUE); // don't lock parent
// set window title
_r_ctrl_setstring (hwnd, 0, title);
@@ -1610,7 +1533,7 @@ INT_PTR CALLBACK EditorProc (
case WM_CLOSE:
{
- EndDialog (hwnd, FALSE);
+ EndDialog (hwnd, 0);
break;
}
@@ -1728,18 +1651,15 @@ INT_PTR CALLBACK EditorProc (
case IDOK: // process Enter key
case IDC_SAVE:
{
- HWND hpage_general;
- HWND hpage_rule;
- HWND hpage_apps;
- PR_STRING string;
+
+ HWND hmain, hpage_apps, hpage_general, hpage_rule;
PR_LIST rules = NULL;
PITEM_RULE ptr_rule;
- HANDLE hengine;
+ PR_STRING string;
+ WCHAR buffer[0x80];
ULONG_PTR rule_idx;
ULONG app_hash;
- INT listview_id;
- INT item_id;
- BOOLEAN is_enable;
+ INT item_id, listview_id;
context = _app_editor_getcontext (hwnd);
@@ -1780,6 +1700,8 @@ INT_PTR CALLBACK EditorProc (
_r_obj_movereference ((PVOID_PTR)&context->ptr_rule->name, string);
+ context->ptr_rule->rule_hash = _r_str_gethash (&context->ptr_rule->name->sr, TRUE); // change rule hash if it is changed
+
// comment
string = _r_ctrl_getstring (hpage_general, IDC_RULE_COMMENT_ID);
@@ -1791,14 +1713,10 @@ INT_PTR CALLBACK EditorProc (
if (hpage_rule)
{
// rule (remote)
- string = _app_editor_getrulesfromlistview (hpage_rule, IDC_RULE_REMOTE_ID, INT_ERROR);
-
- _r_obj_movereference ((PVOID_PTR)&context->ptr_rule->rule_remote, string);
+ _r_obj_movereference ((PVOID_PTR)&context->ptr_rule->rule_remote, _app_editor_getrulesfromlistview (hpage_rule, IDC_RULE_REMOTE_ID, INT_ERROR));
// rule (local)
- string = _app_editor_getrulesfromlistview (hpage_rule, IDC_RULE_LOCAL_ID, INT_ERROR);
-
- _r_obj_movereference ((PVOID_PTR)&context->ptr_rule->rule_local, string);
+ _r_obj_movereference ((PVOID_PTR)&context->ptr_rule->rule_local, _app_editor_getrulesfromlistview (hpage_rule, IDC_RULE_LOCAL_ID, INT_ERROR));
}
item_id = _r_combobox_getcurrentitem (hpage_general, IDC_RULE_PROTOCOL_ID);
@@ -1809,7 +1727,9 @@ INT_PTR CALLBACK EditorProc (
context->ptr_rule->af = (ADDRESS_FAMILY)_r_combobox_getitemlparam (hpage_general, IDC_RULE_VERSION_ID, item_id);
- _r_obj_movereference ((PVOID_PTR)&context->ptr_rule->protocol_str, _r_obj_createstring (_app_db_getprotoname (context->ptr_rule->protocol, context->ptr_rule->af)));
+ _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L" (% " TEXT (PRIu8) L")", context->ptr_rule->protocol);
+
+ _r_obj_movereference ((PVOID_PTR)&context->ptr_rule->protocol_str, _r_obj_createstring (_app_db_getprotoname (context->ptr_rule->protocol, context->ptr_rule->af, buffer)));
item_id = _r_combobox_getcurrentitem (hpage_general, IDC_RULE_DIRECTION_ID);
@@ -1820,16 +1740,7 @@ INT_PTR CALLBACK EditorProc (
context->ptr_rule->action = (FWP_ACTION_TYPE)_r_combobox_getitemlparam (hpage_general, IDC_RULE_ACTION_ID, item_id);
if (context->ptr_rule->type == DATA_RULE_USER)
- {
- if (context->ptr_rule->action == FWP_ACTION_BLOCK)
- {
- context->ptr_rule->weight = FW_WEIGHT_RULE_USER_BLOCK;
- }
- else
- {
- context->ptr_rule->weight = FW_WEIGHT_RULE_USER;
- }
- }
+ context->ptr_rule->weight = (context->ptr_rule->action == FWP_ACTION_BLOCK) ? FWW_RULE_USER_BLOCK : FWW_RULE_USER;
}
// save rule apps
@@ -1844,7 +1755,7 @@ INT_PTR CALLBACK EditorProc (
app_hash = (ULONG)_app_listview_getitemcontext (hpage_apps, IDC_RULE_APPS_ID, i);
- if (context->ptr_rule->is_forservices && _app_issystemhash (app_hash))
+ if ((context->ptr_rule->is_fordriver || context->ptr_rule->is_forservice) && _app_issystemhash (app_hash))
continue;
if (_app_isappfound (app_hash))
@@ -1883,19 +1794,24 @@ INT_PTR CALLBACK EditorProc (
for (INT i = 0; i < _r_listview_getitemcount (hpage_rule, IDC_APP_RULES_ID); i++)
{
rule_idx = _app_listview_getitemcontext (hpage_rule, IDC_APP_RULES_ID, i);
- ptr_rule = _r_obj_getlistitem (rules_list, rule_idx);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, rule_idx);
if (!ptr_rule)
continue;
- listview_id = _app_listview_getbytype (ptr_rule->type);
- item_id = _app_listview_finditem (_r_app_gethwnd (), listview_id, rule_idx);
+ hmain = _r_app_gethwnd ();
- if (item_id != INT_ERROR)
+ if (hmain)
{
- is_enable = _r_listview_isitemchecked (hpage_rule, IDC_APP_RULES_ID, i);
+ listview_id = _app_listview_getbytype (ptr_rule->type);
- _app_setruletoapp (_r_app_gethwnd (), ptr_rule, item_id, context->ptr_app, is_enable);
+ if (listview_id != 0)
+ {
+ item_id = _app_listview_finditem (hmain, listview_id, rule_idx);
+
+ if (item_id != INT_ERROR)
+ _app_setruletoapp (hmain, ptr_rule, item_id, context->ptr_app, _r_listview_isitemchecked (hpage_rule, IDC_APP_RULES_ID, i));
+ }
}
}
@@ -1908,33 +1824,31 @@ INT_PTR CALLBACK EditorProc (
{
if (!_r_obj_isempty2 (rules) && _wfp_isfiltersinstalled ())
{
- hengine = _wfp_getenginehandle ();
-
if (context->is_settorules)
{
- _wfp_create4filters (hengine, rules, DBG_ARG, FALSE);
+ _wfp_createrulefilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
}
else
{
- _wfp_create3filters (hengine, rules, DBG_ARG, FALSE);
+ _wfp_createappfilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
}
}
_r_obj_dereference (rules);
}
- EndDialog (hwnd, TRUE);
+ EndDialog (hwnd, 1);
break;
}
case IDCANCEL: // process Esc key
{
- HWND hpage;
- HWND hsearch;
+ HWND hpage, hsearch;
INT item_id;
item_id = _r_tab_getcurrentitem (hwnd, IDC_TAB);
+
hpage = (HWND)_r_tab_getitemlparam (hwnd, IDC_TAB, item_id);
if (hpage)
@@ -1959,7 +1873,7 @@ INT_PTR CALLBACK EditorProc (
case IDC_CLOSE:
{
- EndDialog (hwnd, FALSE);
+ EndDialog (hwnd, 0);
break;
}
}
diff --git a/src/editor.h b/src/editor.h
index 9b6896bc..16311336 100644
--- a/src/editor.h
+++ b/src/editor.h
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2016-2025 Henry++
+// Copyright (c) 2016-2026 Henry++
#pragma once
@@ -12,8 +12,8 @@ typedef struct _EDITOR_CONTEXT
union
{
- PITEM_APP ptr_app;
PITEM_RULE ptr_rule;
+ PITEM_APP ptr_app;
};
struct
@@ -28,18 +28,21 @@ typedef struct _EDITOR_CONTEXT
BOOLEAN is_settorules;
} EDITOR_CONTEXT, *PEDITOR_CONTEXT;
+FORCEINLINE VOID _app_editor_deletewindow (
+ _In_ _Frees_ptr_ _Post_invalid_ PEDITOR_CONTEXT context
+)
+{
+ _r_mem_free (context);
+}
+
_Ret_maybenull_
PEDITOR_CONTEXT _app_editor_createwindow (
- _In_ HWND hwnd,
+ _In_opt_ HWND hwnd,
_In_ PVOID lparam,
_In_ INT page_id,
_In_ BOOLEAN is_settorules
);
-VOID _app_editor_deletewindow (
- _In_ PEDITOR_CONTEXT context
-);
-
_Ret_maybenull_
PEDITOR_CONTEXT _app_editor_getcontext (
_In_ HWND hwnd
@@ -72,7 +75,7 @@ PR_STRING _app_editor_getrulesfromlistview (
VOID _app_editor_setrulestolistview (
_In_ HWND hwnd,
_In_ INT ctrl_id,
- _In_ PR_STRING rule
+ _In_opt_ PR_STRING rule
);
INT_PTR CALLBACK EditorRuleProc (
diff --git a/src/helper.c b/src/helper.c
index 4479bb87..e42dbcc5 100644
--- a/src/helper.c
+++ b/src/helper.c
@@ -7,25 +7,23 @@ VOID NTAPI _app_dereferenceapp (
_In_ PVOID entry
)
{
- PITEM_APP ptr_item;
-
- ptr_item = entry;
+ PITEM_APP ptr_item = (PITEM_APP)entry;
if (ptr_item->display_name)
_r_obj_dereference (ptr_item->display_name);
- if (ptr_item->real_path)
- _r_obj_dereference (ptr_item->real_path);
-
- if (ptr_item->short_name)
- _r_obj_dereference (ptr_item->short_name);
-
if (ptr_item->original_path)
_r_obj_dereference (ptr_item->original_path);
if (ptr_item->notification)
_r_obj_dereference (ptr_item->notification);
+ if (ptr_item->short_name)
+ _r_obj_dereference (ptr_item->short_name);
+
+ if (ptr_item->real_path)
+ _r_obj_dereference (ptr_item->real_path);
+
if (ptr_item->guids)
_r_obj_dereference (ptr_item->guids);
}
@@ -34,27 +32,23 @@ VOID NTAPI _app_dereferenceappinfo (
_In_ PVOID entry
)
{
- PITEM_APP_INFO ptr_item;
-
- ptr_item = entry;
-
- if (ptr_item->path)
- _r_obj_dereference (ptr_item->path);
+ PITEM_APP_INFO ptr_item = (PITEM_APP_INFO)entry;
if (ptr_item->signature_info)
_r_obj_dereference (ptr_item->signature_info);
if (ptr_item->version_info)
_r_obj_dereference (ptr_item->version_info);
+
+ if (ptr_item->path)
+ _r_obj_dereference (ptr_item->path);
}
VOID NTAPI _app_dereferenceruleconfig (
_In_ PVOID entry
)
{
- PITEM_RULE_CONFIG ptr_item;
-
- ptr_item = entry;
+ PITEM_RULE_CONFIG ptr_item = (PITEM_RULE_CONFIG)entry;
if (ptr_item->name)
_r_obj_dereference (ptr_item->name);
@@ -67,78 +61,70 @@ VOID NTAPI _app_dereferencelog (
_In_ PVOID entry
)
{
- PITEM_LOG ptr_item;
+ PITEM_LOG ptr_item = (PITEM_LOG)entry;
- ptr_item = entry;
+ if (ptr_item->remote_host_str)
+ _r_obj_dereference (ptr_item->remote_host_str);
- if (ptr_item->path)
- _r_obj_dereference (ptr_item->path);
+ if (ptr_item->local_host_str)
+ _r_obj_dereference (ptr_item->local_host_str);
+
+ if (ptr_item->remote_addr_str)
+ _r_obj_dereference (ptr_item->remote_addr_str);
+
+ if (ptr_item->local_addr_str)
+ _r_obj_dereference (ptr_item->local_addr_str);
+
+ if (ptr_item->protocol_str)
+ _r_obj_dereference (ptr_item->protocol_str);
if (ptr_item->filter_name)
_r_obj_dereference (ptr_item->filter_name);
if (ptr_item->layer_name)
+
_r_obj_dereference (ptr_item->layer_name);
if (ptr_item->username)
_r_obj_dereference (ptr_item->username);
- if (ptr_item->protocol_str)
- _r_obj_dereference (ptr_item->protocol_str);
-
- if (ptr_item->local_addr_str)
- _r_obj_dereference (ptr_item->local_addr_str);
-
- if (ptr_item->remote_addr_str)
- _r_obj_dereference (ptr_item->remote_addr_str);
-
- if (ptr_item->local_host_str)
- _r_obj_dereference (ptr_item->local_host_str);
-
- if (ptr_item->remote_host_str)
- _r_obj_dereference (ptr_item->remote_host_str);
+ if (ptr_item->path)
+ _r_obj_dereference (ptr_item->path);
}
VOID NTAPI _app_dereferencenetwork (
_In_ PVOID entry
)
{
- PITEM_NETWORK ptr_item;
+ PITEM_NETWORK ptr_item = (PITEM_NETWORK)entry;
- ptr_item = entry;
-
- if (ptr_item->path)
- _r_obj_dereference (ptr_item->path);
-
- if (ptr_item->protocol_str)
- _r_obj_dereference (ptr_item->protocol_str);
-
- if (ptr_item->local_addr_str)
- _r_obj_dereference (ptr_item->local_addr_str);
-
- if (ptr_item->remote_addr_str)
- _r_obj_dereference (ptr_item->remote_addr_str);
+ if (ptr_item->remote_host_str)
+ _r_obj_dereference (ptr_item->remote_host_str);
if (ptr_item->local_host_str)
_r_obj_dereference (ptr_item->local_host_str);
- if (ptr_item->remote_host_str)
- _r_obj_dereference (ptr_item->remote_host_str);
+ if (ptr_item->remote_addr_str)
+ _r_obj_dereference (ptr_item->remote_addr_str);
+
+ if (ptr_item->local_addr_str)
+ _r_obj_dereference (ptr_item->local_addr_str);
+
+ if (ptr_item->protocol_str)
+ _r_obj_dereference (ptr_item->protocol_str);
+
+ if (ptr_item->path)
+ _r_obj_dereference (ptr_item->path);
}
VOID NTAPI _app_dereferencerule (
_In_ PVOID entry
)
{
- PITEM_RULE ptr_item;
+ PITEM_RULE ptr_item = (PITEM_RULE)entry;
- ptr_item = entry;
-
- if (ptr_item->apps)
- _r_obj_dereference (ptr_item->apps);
-
- if (ptr_item->name)
- _r_obj_dereference (ptr_item->name);
+ if (ptr_item->protocol_str)
+ _r_obj_dereference (ptr_item->protocol_str);
if (ptr_item->rule_remote)
_r_obj_dereference (ptr_item->rule_remote);
@@ -146,18 +132,21 @@ VOID NTAPI _app_dereferencerule (
if (ptr_item->rule_local)
_r_obj_dereference (ptr_item->rule_local);
- if (ptr_item->protocol_str)
- _r_obj_dereference (ptr_item->protocol_str);
-
if (ptr_item->guids)
_r_obj_dereference (ptr_item->guids);
+
+ if (ptr_item->apps)
+ _r_obj_dereference (ptr_item->apps);
+
+ if (ptr_item->name)
+ _r_obj_dereference (ptr_item->name);
}
VOID _app_addcachetable (
_Inout_ PR_HASHTABLE hashtable,
_In_ ULONG hash_code,
_In_ PR_QUEUED_LOCK spin_lock,
- _In_opt_ PR_STRING string
+ _In_opt_ PVOID string
)
{
BOOLEAN is_exceed;
@@ -175,6 +164,43 @@ VOID _app_addcachetable (
_r_queuedlock_releaseexclusive (spin_lock);
}
+BOOLEAN _app_checkipisnotlocal (
+ _In_ ADDRESS_FAMILY af,
+ _In_ LPCVOID address
+)
+{
+ PIN6_ADDR p6addr;
+ PIN_ADDR p4addr;
+
+ switch (af)
+ {
+ case AF_INET:
+ {
+ p4addr = (const PIN_ADDR)address;
+
+ if (IN4_IS_ADDR_UNSPECIFIED (p4addr) || IN4_IS_ADDR_LOOPBACK (p4addr) || IN4_IS_ADDR_RFC1918 (p4addr))
+ return FALSE;
+
+ return TRUE;
+ }
+
+ case AF_INET6:
+ {
+ p6addr = (const PIN6_ADDR)address;
+
+ if (IN6_IS_ADDR_UNSPECIFIED (p6addr) || IN6_IS_ADDR_LOOPBACK (p6addr) || IN6_IS_ADDR_LINKLOCAL (p6addr) || IN6_IS_ADDR_SITELOCAL (p6addr) || IN6_IS_ADDR_ULA (p6addr))
+ return FALSE;
+
+ return TRUE;
+ }
+
+ default:
+ {
+ return FALSE; // unknown address family
+ }
+ }
+}
+
BOOLEAN _app_getcachetable (
_Inout_ PR_HASHTABLE cache_table,
_In_ ULONG hash_code,
@@ -185,12 +211,12 @@ BOOLEAN _app_getcachetable (
PR_OBJECT_POINTER object_ptr;
_r_queuedlock_acquireshared (spin_lock);
- object_ptr = _r_obj_findhashtable (cache_table, hash_code);
+ object_ptr = (PR_OBJECT_POINTER)_r_obj_findhashtable (cache_table, hash_code);
_r_queuedlock_releaseshared (spin_lock);
- if (object_ptr)
+ if (object_ptr && object_ptr->object_body)
{
- *string = _r_obj_referencesafe (object_ptr->object_body);
+ *string = _r_obj_reference (object_ptr->object_body);
return TRUE;
}
@@ -209,7 +235,7 @@ PR_STRING _app_formatarpa (
PIN6_ADDR p6addr;
PIN_ADDR p4addr;
- _r_obj_initializestringbuilder (&formatted_address, 256);
+ _r_obj_initializestringbuilder (&formatted_address, 0);
switch (af)
{
@@ -217,15 +243,7 @@ PR_STRING _app_formatarpa (
{
p4addr = (const PIN_ADDR)address;
- _r_obj_appendstringbuilderformat (
- &formatted_address,
- L"%hhu.%hhu.%hhu.%hhu.%s",
- p4addr->s_impno,
- p4addr->s_lh,
- p4addr->s_host,
- p4addr->s_net,
- DNS_IP4_REVERSE_DOMAIN_STRING_W
- );
+ _r_obj_appendstringbuilderformat (&formatted_address, L"%hhu.%hhu.%hhu.%hhu.%s", p4addr->s_impno, p4addr->s_lh, p4addr->s_host, p4addr->s_net, DNS_IP4_REVERSE_DOMAIN_STRING_W);
break;
}
@@ -236,18 +254,19 @@ PR_STRING _app_formatarpa (
for (INT i = sizeof (IN6_ADDR) - 1; i >= 0; i--)
{
- _r_obj_appendstringbuilderformat (
- &formatted_address,
- L"%hhx.%hhx.",
- p6addr->s6_addr[i] & 0xF,
- (p6addr->s6_addr[i] >> 4) & 0xF
- );
+ _r_obj_appendstringbuilderformat (&formatted_address, L"%hhx.%hhx.", p6addr->s6_addr[i] & 0xF, (p6addr->s6_addr[i] >> 4) & 0xF);
}
_r_obj_appendstringbuilder (&formatted_address, DNS_IP6_REVERSE_DOMAIN_STRING_W);
break;
}
+
+ default:
+ {
+ _r_obj_appendstringbuilderformat (&formatted_address, L"", af);
+ break;
+ }
}
return _r_obj_finalstringbuilder (&formatted_address);
@@ -267,20 +286,20 @@ PR_STRING _app_formataddress (
LPCWSTR string;
NTSTATUS status;
- _r_obj_initializestringbuilder (&formatted_address, 0x100);
+ _r_obj_initializestringbuilder (&formatted_address, 0);
if (flags & FMTADDR_USE_PROTOCOL)
{
- string = _app_db_getprotoname (proto, af);
+ string = _app_db_getprotoname (proto, af, NULL);
- if (_r_str_compare (string, L"n/a", FALSE) != 0)
+ if (string)
{
_r_obj_appendstringbuilder (&formatted_address, string);
_r_obj_appendstringbuilder (&formatted_address, L"://");
}
}
- status = _app_formatip (af, address, addr_str, RTL_NUMBER_OF (addr_str), !!(flags & FMTADDR_AS_RULE));
+ status = _app_formatip (addr_str, RTL_NUMBER_OF (addr_str), af, address, !!(flags & FMTADDR_AS_RULE));
if (NT_SUCCESS (status))
{
@@ -310,22 +329,21 @@ PR_STRING _app_formataddress (
}
PR_STRING _app_formataddress_interlocked (
- _In_ PVOID volatile *string,
+ _In_ volatile PVOID_PTR string,
_In_ ADDRESS_FAMILY af,
_In_ LPCVOID address
)
{
- PR_STRING current_string;
- PR_STRING new_string;
+ PR_STRING current_string, new_string;
- current_string = _InterlockedCompareExchangePointer (string, NULL, NULL);
+ current_string = (PR_STRING)_InterlockedCompareExchangePointer (string, NULL, NULL);
if (current_string)
return current_string;
new_string = _app_formataddress (af, 0, address, 0, 0);
- current_string = _InterlockedCompareExchangePointer (string, new_string, NULL);
+ current_string = (PR_STRING)_InterlockedCompareExchangePointer (string, new_string, NULL);
if (!current_string)
{
@@ -342,22 +360,23 @@ PR_STRING _app_formataddress_interlocked (
_Success_ (NT_SUCCESS (return))
NTSTATUS _app_formatip (
- _In_ ADDRESS_FAMILY af,
- _In_ LPCVOID address,
_Out_writes_to_ (buffer_length, buffer_length) LPWSTR buffer,
_In_ ULONG buffer_length,
+ _In_ ADDRESS_FAMILY af,
+ _In_ LPCVOID address,
_In_ BOOLEAN is_checkempty
)
{
- PIN_ADDR p4addr;
PIN6_ADDR p6addr;
- NTSTATUS status;
+ PIN_ADDR p4addr;
+
+ RtlZeroMemory (buffer, buffer_length * sizeof (WCHAR));
switch (af)
{
case AF_INET:
{
- p4addr = (PIN_ADDR)address;
+ p4addr = (const PIN_ADDR)address;
if (is_checkempty)
{
@@ -365,14 +384,12 @@ NTSTATUS _app_formatip (
return STATUS_INVALID_ADDRESS_COMPONENT;
}
- status = RtlIpv4AddressToStringExW (p4addr, 0, buffer, &buffer_length);
-
- return status;
+ return RtlIpv4AddressToStringExW (p4addr, 0, buffer, &buffer_length);
}
case AF_INET6:
{
- p6addr = (PIN6_ADDR)address;
+ p6addr = (const PIN6_ADDR)address;
if (is_checkempty)
{
@@ -380,13 +397,14 @@ NTSTATUS _app_formatip (
return STATUS_INVALID_ADDRESS_COMPONENT;
}
- status = RtlIpv6AddressToStringExW (p6addr, 0, 0, buffer, &buffer_length);
+ return RtlIpv6AddressToStringExW (p6addr, 0, 0, buffer, &buffer_length);
+ }
- return status;
+ default:
+ {
+ return STATUS_INVALID_PARAMETER; // unknown address family
}
}
-
- return STATUS_INVALID_PARAMETER;
}
PR_STRING _app_formatport (
@@ -412,7 +430,7 @@ PITEM_APP_INFO _app_getappinfobyhash2 (
PITEM_APP_INFO ptr_app_info;
_r_queuedlock_acquireshared (&lock_cache_information);
- ptr_app_info = _r_obj_findhashtablepointer (cache_information, app_hash);
+ ptr_app_info = (PITEM_APP_INFO)_r_obj_findhashtablepointer (cache_information, app_hash);
_r_queuedlock_releaseshared (&lock_cache_information);
return ptr_app_info;
@@ -550,20 +568,17 @@ BOOLEAN _app_isappvalidbinary (
if (!_app_isappvalidpath (path))
return FALSE;
- if (_r_str_isendsswith2 (&path->sr, L".exe", TRUE))
- return TRUE;
-
- return FALSE;
+ return _r_str_isendsswith2 (&path->sr, L".exe", TRUE);
}
BOOLEAN _app_isappvalidpath (
_In_opt_ PR_STRING path
)
{
- if (!path)
+ if (_r_obj_isstringempty (path))
return FALSE;
- if (path->length <= (3 * sizeof (WCHAR)))
+ if (path->length <= (4 * sizeof (WCHAR)))
return FALSE;
if (path->buffer[1] != L':' || path->buffer[2] != L'\\')
@@ -609,14 +624,13 @@ PR_STRING _app_getappdisplayname (
}
default:
+ {
break;
+ }
}
- if (is_shortened || _r_config_getboolean (L"ShowFilenames", TRUE, NULL))
- {
- if (!_r_obj_isstringempty (ptr_app->short_name))
- return _r_obj_reference (ptr_app->short_name);
- }
+ if ((is_shortened || _r_config_getboolean (L"ShowFilenames", TRUE, NULL)) && !_r_obj_isstringempty (ptr_app->short_name))
+ return _r_obj_reference (ptr_app->short_name);
if (!_r_obj_isstringempty (ptr_app->real_path))
return _r_obj_reference (ptr_app->real_path);
@@ -626,33 +640,31 @@ PR_STRING _app_getappdisplayname (
_Ret_maybenull_
PR_STRING _app_getapppath (
- _In_ PITEM_APP ptr_app,
- _In_ BOOLEAN is_returnshort
+ _In_ PITEM_APP ptr_app
)
{
- PR_STRING path = NULL;
- PR_STRING string;
+ PR_STRING path = NULL, string;
- if (ptr_app->type == DATA_APP_UWP || ptr_app->type == DATA_APP_SERVICE)
+ if (ptr_app->type == DATA_APP_SERVICE || ptr_app->type == DATA_APP_UWP)
{
if (ptr_app->real_path)
- path = _r_obj_reference (ptr_app->real_path);
+ _r_obj_movereference ((PVOID_PTR)&path, _r_obj_reference (ptr_app->real_path));
if (ptr_app->display_name)
- path = _r_obj_reference (ptr_app->display_name);
+ _r_obj_movereference ((PVOID_PTR)&path, _r_obj_reference (ptr_app->display_name));
}
if (ptr_app->original_path)
- path = _r_obj_reference (ptr_app->original_path);
+ _r_obj_movereference ((PVOID_PTR)&path, _r_obj_reference (ptr_app->original_path));
if (ptr_app->real_path)
- path = _r_obj_reference (ptr_app->real_path);
+ _r_obj_movereference ((PVOID_PTR)&path, _r_obj_reference (ptr_app->real_path));
- if (is_returnshort && path)
+ if (path && _r_config_getboolean (L"IsShortPath", TRUE, NULL))
{
string = _r_str_environmentunexpandstring (&path->sr);
- _r_obj_movereference ((PVOID_PTR)&path, _r_path_compact (&string->sr, 64));
+ _r_obj_movereference ((PVOID_PTR)&path, _r_path_compact (&string->sr, 0x40));
_r_obj_dereference (string);
}
@@ -665,11 +677,8 @@ VOID _app_getfileicon (
)
{
LONG icon_id = 0;
- BOOLEAN is_iconshidded;
- is_iconshidded = _r_config_getboolean (L"IsIconsHidden", FALSE, NULL);
-
- if (is_iconshidded || !_app_isappvalidbinary (ptr_app_info->path))
+ if (_r_config_getboolean (L"IsIconsHidden", FALSE, NULL) || !_app_isappvalidbinary (ptr_app_info->path))
{
_app_icons_loadfromfile (NULL, ptr_app_info->type, &icon_id, NULL, TRUE);
}
@@ -685,9 +694,9 @@ _Success_ (return)
BOOLEAN _app_calculatefilehash (
_In_ HANDLE hfile,
_In_opt_ LPCWSTR algorithm_id,
- _Out_ PVOID_PTR file_hash_ptr,
- _Out_ PULONG file_hash_length_ptr,
- _Out_ HCATADMIN_PTR hcat_admin_ptr
+ _Out_ PVOID_PTR out_file_hash,
+ _Out_ PULONG out_file_hash_length,
+ _Out_ HCATADMIN_PTR out_hcat_admin
)
{
static R_INITONCE init_once = PR_INITONCE_INIT;
@@ -696,9 +705,9 @@ BOOLEAN _app_calculatefilehash (
GUID DriverActionVerify = DRIVER_ACTION_VERIFY;
HCATADMIN hcat_admin;
- PVOID hwintrust;
+ HINSTANCE hwintrust;
PBYTE file_hash;
- ULONG file_hash_length = 32;
+ ULONG file_hash_length = 0x20;
NTSTATUS status;
if (_r_initonce_begin (&init_once))
@@ -710,16 +719,20 @@ BOOLEAN _app_calculatefilehash (
_CryptCATAdminCalcHashFromFileHandle2 = (CCAHFFH2)_r_sys_getprocaddress (hwintrust, "CryptCATAdminCalcHashFromFileHandle2", 0);
_CryptCATAdminAcquireContext2 = (CCAAC2)_r_sys_getprocaddress (hwintrust, "CryptCATAdminAcquireContext2", 0);
- // _r_sys_freelibrary (hwintrust, FALSE);
+ //_r_sys_freelibrary (hwintrust);
}
_r_initonce_end (&init_once);
}
- if (_CryptCATAdminAcquireContext2)
+ // init as null
+ *out_file_hash_length = 0;
+ *out_hcat_admin = NULL;
+ *out_file_hash = NULL;
+
+ if (_CryptCATAdminAcquireContext2 && !_CryptCATAdminAcquireContext2 (&hcat_admin, &DriverActionVerify, algorithm_id, NULL, 0))
{
- if (!_CryptCATAdminAcquireContext2 (&hcat_admin, &DriverActionVerify, algorithm_id, NULL, 0))
- return FALSE;
+ return FALSE;
}
else
{
@@ -727,29 +740,26 @@ BOOLEAN _app_calculatefilehash (
return FALSE;
}
- file_hash = _r_mem_allocate (file_hash_length);
+ file_hash = (PBYTE)_r_mem_allocate (file_hash_length);
- if (_CryptCATAdminCalcHashFromFileHandle2)
+ if (_CryptCATAdminCalcHashFromFileHandle2 && !_CryptCATAdminCalcHashFromFileHandle2 (hcat_admin, hfile, &file_hash_length, file_hash, 0))
{
+ file_hash = (PBYTE)_r_mem_reallocate (file_hash, file_hash_length);
+
if (!_CryptCATAdminCalcHashFromFileHandle2 (hcat_admin, hfile, &file_hash_length, file_hash, 0))
{
- file_hash = _r_mem_reallocate (file_hash, file_hash_length);
+ CryptCATAdminReleaseContext (hcat_admin, 0);
- if (!_CryptCATAdminCalcHashFromFileHandle2 (hcat_admin, hfile, &file_hash_length, file_hash, 0))
- {
- CryptCATAdminReleaseContext (hcat_admin, 0);
+ _r_mem_free (file_hash);
- _r_mem_free (file_hash);
-
- return FALSE;
- }
+ return FALSE;
}
}
else
{
if (!CryptCATAdminCalcHashFromFileHandle (hfile, &file_hash_length, file_hash, 0))
{
- file_hash = _r_mem_reallocate (file_hash, file_hash_length);
+ file_hash = (PBYTE)_r_mem_reallocate (file_hash, file_hash_length);
if (!CryptCATAdminCalcHashFromFileHandle (hfile, &file_hash_length, file_hash, 0))
{
@@ -762,9 +772,9 @@ BOOLEAN _app_calculatefilehash (
}
}
- *file_hash_ptr = file_hash;
- *file_hash_length_ptr = file_hash_length;
- *hcat_admin_ptr = hcat_admin;
+ *out_file_hash_length = file_hash_length;
+ *out_hcat_admin = hcat_admin;
+ *out_file_hash = file_hash;
return TRUE;
}
@@ -774,12 +784,11 @@ PR_STRING _app_verifygetstring (
_In_ HANDLE state_data
)
{
- PCRYPT_PROVIDER_DATA prov_data;
PCRYPT_PROVIDER_SGNR prov_signer;
+ PCRYPT_PROVIDER_DATA prov_data;
PCRYPT_PROVIDER_CERT prov_cert;
PR_STRING string;
- ULONG length;
- ULONG idx = 0;
+ ULONG idx = 0, length;
prov_data = WTHelperProvDataFromStateData (state_data);
@@ -828,7 +837,7 @@ LONG _app_verifyfromfile (
WINTRUST_DATA trust_data = {0};
LONG status;
- trust_data.cbStruct = sizeof (trust_data);
+ trust_data.cbStruct = sizeof (WINTRUST_DATA);
trust_data.dwUIChoice = WTD_UI_NONE;
trust_data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
trust_data.pPolicyCallbackData = policy_callback;
@@ -836,10 +845,20 @@ LONG _app_verifyfromfile (
trust_data.dwStateAction = WTD_STATEACTION_VERIFY;
trust_data.dwProvFlags = WTD_SAFER_FLAG | WTD_DISABLE_MD2_MD4;
- trust_data.pFile = union_data;
+ if (union_choice == WTD_CHOICE_FILE)
+ {
+ trust_data.pFile = (PWINTRUST_FILE_INFO)union_data;
+ }
+ else if (union_choice == WTD_CHOICE_CATALOG)
+ {
+ trust_data.pCatalog = (PWINTRUST_CATALOG_INFO)union_data;
+ }
+ else
+ {
+ *signature_string = NULL;
- if (union_choice == WTD_CHOICE_CATALOG)
- trust_data.pCatalog = union_data;
+ return STATUS_INVALID_PARAMETER;
+ }
if (_r_config_getboolean (L"IsOCSPEnabled", FALSE, NULL))
{
@@ -855,16 +874,9 @@ LONG _app_verifyfromfile (
trust_data.dwStateAction = WTD_STATEACTION_VERIFY;
status = WinVerifyTrust (INVALID_HANDLE_VALUE, action_id, &trust_data);
- if (status == ERROR_SUCCESS && trust_data.hWVTStateData)
- {
- *signature_string = _app_verifygetstring (trust_data.hWVTStateData);
- }
- else
- {
- *signature_string = NULL;
- }
+ *signature_string = (status == ERROR_SUCCESS && trust_data.hWVTStateData) ? _app_verifygetstring (trust_data.hWVTStateData) : NULL;
- // Close state data
+ // close state data
trust_data.dwStateAction = WTD_STATEACTION_CLOSE;
WinVerifyTrust (INVALID_HANDLE_VALUE, action_id, &trust_data);
@@ -882,10 +894,9 @@ NTSTATUS _app_verifyfilefromcatalog (
WINTRUST_CATALOG_INFO catalog_info = {0};
DRIVER_VER_INFO ver_info = {0};
CATALOG_INFO ci = {0};
+ PR_STRING file_hash_tag, string = NULL;
HCATADMIN hcat_admin;
HCATINFO hcat_info;
- PR_STRING string = NULL;
- PR_STRING file_hash_tag;
PVOID file_hash;
LONG64 file_size;
ULONG file_hash_length;
@@ -909,23 +920,23 @@ NTSTATUS _app_verifyfilefromcatalog (
if (_app_calculatefilehash (hfile, algorithm_id, &file_hash, &file_hash_length, &hcat_admin))
{
- hcat_info = CryptCATAdminEnumCatalogFromHash (hcat_admin, file_hash, file_hash_length, 0, NULL);
+ hcat_info = CryptCATAdminEnumCatalogFromHash (hcat_admin, (PBYTE)file_hash, file_hash_length, 0, NULL);
if (hcat_info)
{
- file_hash_tag = _r_str_fromhex (file_hash, file_hash_length, TRUE);
+ file_hash_tag = _r_str_fromhex ((PUCHAR)file_hash, file_hash_length, TRUE);
if (CryptCATCatalogInfoFromContext (hcat_info, &ci, 0))
{
- // Disable OS version checking by passing in a DRIVER_VER_INFO structure.
+ // disable OS version checking by passing in a DRIVER_VER_INFO structure
ver_info.cbStruct = sizeof (DRIVER_VER_INFO);
- catalog_info.cbStruct = sizeof (catalog_info);
+ catalog_info.cbStruct = sizeof (WINTRUST_CATALOG_INFO);
catalog_info.pcwszCatalogFilePath = ci.wszCatalogFile;
catalog_info.pcwszMemberFilePath = path;
catalog_info.hMemberFile = hfile;
catalog_info.pcwszMemberTag = file_hash_tag->buffer;
- catalog_info.pbCalculatedFileHash = file_hash;
+ catalog_info.pbCalculatedFileHash = (PBYTE)file_hash;
catalog_info.cbCalculatedFileHash = file_hash_length;
catalog_info.hCatAdmin = hcat_admin;
@@ -950,7 +961,7 @@ NTSTATUS _app_verifyfilefromcatalog (
{
*signature_string = NULL;
- status = TRUST_E_SUBJECT_FORM_UNKNOWN;
+ return TRUST_E_SUBJECT_FORM_UNKNOWN;
}
return status;
@@ -966,6 +977,7 @@ VOID _app_getfilesignatureinfo (
PR_STRING string = NULL;
LONG status;
+ // clean value
__try
{
if (ptr_app_info->signature_info)
@@ -976,7 +988,7 @@ VOID _app_getfilesignatureinfo (
NOTHING;
}
- file_info.cbStruct = sizeof (file_info);
+ file_info.cbStruct = sizeof (WINTRUST_FILE_INFO);
file_info.pcwszFilePath = ptr_app_info->path->buffer;
file_info.hFile = hfile;
@@ -984,14 +996,7 @@ VOID _app_getfilesignatureinfo (
if (status == TRUST_E_NOSIGNATURE)
{
- if (_r_sys_isosversiongreaterorequal (WINDOWS_8))
- {
- status = _app_verifyfilefromcatalog (hfile, ptr_app_info->path->buffer, BCRYPT_SHA256_ALGORITHM, &string);
- }
- else
- {
- status = _app_verifyfilefromcatalog (hfile, ptr_app_info->path->buffer, NULL, &string);
- }
+ status = _app_verifyfilefromcatalog (hfile, ptr_app_info->path->buffer, _r_sys_isosversiongreaterorequal (WINDOWS_8) ? BCRYPT_SHA256_ALGORITHM : NULL, &string);
if (status == TRUST_E_NOSIGNATURE)
_app_verifyfilefromcatalog (hfile, ptr_app_info->path->buffer, BCRYPT_SHA1_ALGORITHM, &string);
@@ -1013,11 +1018,11 @@ VOID _app_getfileversioninfo (
{
VS_FIXEDFILEINFO *ver_info = NULL;
PR_STRING version_string = NULL;
+ R_STORAGE ver_block = {0};
R_STRINGBUILDER sb;
- R_STORAGE ver_block;
+ HINSTANCE hlibrary;
PR_STRING string;
- PVOID hlibrary;
- ULONG lcid;
+ LCID lcid;
NTSTATUS status;
// clean value
@@ -1041,7 +1046,7 @@ VOID _app_getfileversioninfo (
if (!NT_SUCCESS (status))
goto CleanupExit;
- _r_obj_initializestringbuilder (&sb, 0x100);
+ _r_obj_initializestringbuilder (&sb, 0);
lcid = _r_res_querytranslation (ver_block.buffer);
@@ -1060,7 +1065,6 @@ VOID _app_getfileversioninfo (
if (_r_res_queryversion ((PVOID_PTR)&ver_info, ver_block.buffer))
{
_r_obj_appendstringbuilder (&sb, _r_obj_isstringempty2 (sb.string) ? SZ_TAB : L" ");
-
_r_obj_appendstringbuilderformat (&sb, L"%d.%d", HIWORD (ver_info->dwFileVersionMS), LOWORD (ver_info->dwFileVersionMS));
if (HIWORD (ver_info->dwFileVersionLS) || LOWORD (ver_info->dwFileVersionLS))
@@ -1146,13 +1150,14 @@ ULONG _app_addcolor (
return hash_code;
}
+_Success_ (return != 0)
COLORREF _app_getcolorvalue (
_In_ ULONG color_hash
)
{
PITEM_COLOR ptr_clr;
- ptr_clr = _r_obj_findhashtable (colors_table, color_hash);
+ ptr_clr = (PITEM_COLOR)_r_obj_findhashtable (colors_table, color_hash);
if (ptr_clr)
return ptr_clr->new_clr ? ptr_clr->new_clr : ptr_clr->default_clr;
@@ -1160,141 +1165,6 @@ COLORREF _app_getcolorvalue (
return 0;
}
-VOID _app_generate_rulescontrol (
- _In_ HMENU hsubmenu,
- _In_ ULONG app_hash,
- _In_opt_ PITEM_LOG ptr_log
-)
-{
- ITEM_STATUS status = {0};
- WCHAR buffer[128];
- PITEM_RULE ptr_rule;
- ULONG_PTR limit_group;
- ULONG i;
- BOOLEAN is_global;
- BOOLEAN is_enabled;
-
- _app_getcount (&status);
-
- if (!status.rules_count)
- {
- _r_menu_additem_ex (hsubmenu, IDX_RULES_SPECIAL, _r_locale_getstring (IDS_STATUS_EMPTY), MF_DISABLED);
- }
- else
- {
- for (UINT8 type = 0; type < 2; type++)
- {
- if (type == 0)
- {
- if (!status.rules_predefined_count)
- continue;
- }
- else
- {
- if (!status.rules_user_count)
- continue;
- }
-
- for (UINT8 loop = 0; loop < 2; loop++)
- {
- limit_group = 14; // limit rules
-
- _r_queuedlock_acquireshared (&lock_rules);
-
- for (i = 0; i < (ULONG)_r_obj_getlistsize (rules_list) && limit_group; i++)
- {
- ptr_rule = _r_obj_getlistitem (rules_list, i);
-
- if (!ptr_rule)
- continue;
-
- is_global = (ptr_rule->is_enabled && _r_obj_isempty (ptr_rule->apps));
- is_enabled = is_global || (ptr_rule->is_enabled && (_r_obj_findhashtable (ptr_rule->apps, app_hash)));
-
- if (ptr_rule->type != DATA_RULE_USER)
- continue;
-
- if ((type == 0 && (!ptr_rule->is_readonly || is_global)) || (type == 1 && (ptr_rule->is_readonly || is_global)))
- continue;
-
- if ((loop == 0 && !is_enabled) || (loop == 1 && is_enabled))
- continue;
-
- _r_str_printf (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_RULE_APPLY_2), _r_obj_getstring (ptr_rule->name));
-
- if (ptr_rule->is_readonly)
- _r_str_append (buffer, RTL_NUMBER_OF (buffer), SZ_RULE_INTERNAL_MENU);
-
- _r_menu_additem_ex (hsubmenu, IDX_RULES_SPECIAL + i, buffer, is_enabled ? MF_CHECKED : MF_UNCHECKED);
-
- limit_group -= 1;
- }
-
- _r_queuedlock_releaseshared (&lock_rules);
- }
-
- if (!type)
- _r_menu_addseparator (hsubmenu);
- }
-
- if (ptr_log)
- {
- _r_menu_addseparator (hsubmenu);
-
- _r_str_printf (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_RULE_APPLY_2), _r_obj_getstring (ptr_log->remote_addr_str));
-
- _r_menu_additem (hsubmenu, (IDX_RULES_SPECIAL + i) + 1, buffer);
- }
- }
-
- _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"%s...", _r_locale_getstring (IDS_OPENRULESEDITOR));
-
- _r_menu_additem (hsubmenu, IDM_OPENRULESEDITOR, buffer);
-}
-
-VOID _app_generate_timerscontrol (
- _In_ HMENU hsubmenu,
- _In_ ULONG app_hash
-)
-{
- LONG64 current_time;
- LONG64 app_time = 0;
- LONG64 timestamp;
- PR_STRING string;
- ULONG index;
- BOOLEAN is_checked = FALSE;
-
- current_time = _r_unixtime_now ();
-
- _app_getappinfobyhash (app_hash, INFO_TIMER, &app_time, sizeof (LONG64));
-
- for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (timer_array); i++)
- {
- timestamp = timer_array[i];
-
- string = _r_format_interval (timestamp);
-
- if (!string)
- continue;
-
- index = IDX_TIMER + (ULONG)i;
-
- _r_menu_additem (hsubmenu, index, string->buffer);
-
- if (!is_checked && (app_time > current_time) && (app_time <= (current_time + timestamp)))
- {
- _r_menu_checkitem (hsubmenu, IDX_TIMER, index, MF_BYCOMMAND, index);
-
- is_checked = TRUE;
- }
-
- _r_obj_dereference (string);
- }
-
- if (!is_checked)
- _r_menu_checkitem (hsubmenu, IDM_DISABLETIMER, IDM_DISABLETIMER, MF_BYCOMMAND, IDM_DISABLETIMER);
-}
-
BOOLEAN _app_setruletoapp (
_In_ HWND hwnd,
_Inout_ PITEM_RULE ptr_rule,
@@ -1305,7 +1175,7 @@ BOOLEAN _app_setruletoapp (
{
INT listview_id;
- if (ptr_rule->is_forservices && _app_issystemhash (ptr_app->app_hash))
+ if ((ptr_rule->is_fordriver || ptr_rule->is_forservice) && _app_issystemhash (ptr_app->app_hash))
return FALSE;
if (is_enable == (_r_obj_findhashtable (ptr_rule->apps, ptr_app->app_hash) != NULL))
@@ -1329,7 +1199,8 @@ BOOLEAN _app_setruletoapp (
{
listview_id = _app_listview_getbytype (ptr_rule->type);
- _app_listview_updateitemby_param (hwnd, _app_listview_getitemcontext (hwnd, listview_id, item_id), FALSE);
+ if (listview_id != 0)
+ _app_listview_updateitemby_param (hwnd, _app_listview_getitemcontext (hwnd, listview_id, item_id), FALSE);
}
_app_listview_updateitemby_param (hwnd, ptr_app->app_hash, TRUE);
@@ -1339,31 +1210,39 @@ BOOLEAN _app_setruletoapp (
_Success_ (return)
BOOLEAN _app_parsenetworkstring (
- _In_ LPCWSTR network_string,
+ _In_ PCR_STRINGREF network_string,
_Inout_ PITEM_ADDRESS address
)
{
- NET_ADDRESS_INFO ni;
- NET_ADDRESS_INFO ni_end;
- ULONG mask;
- ULONG types;
- USHORT range_port1 = 0;
- USHORT range_port2 = 0;
- USHORT port;
+ NET_ADDRESS_INFO ni, ni_end;
+ WCHAR rule_string[0x100];
+ ULONG mask, types;
+ USHORT port = 0, range_port1 = 0, range_port2 = 0;
BYTE prefix_length;
ULONG status;
- types = NET_STRING_IP_ADDRESS_NO_SCOPE | NET_STRING_IP_SERVICE | NET_STRING_IP_NETWORK | NET_STRING_IP_ADDRESS_NO_SCOPE | NET_STRING_IP_ADDRESS;
+ types = NET_STRING_IP_ADDRESS | NET_STRING_IP_ADDRESS_NO_SCOPE | NET_STRING_IP_SERVICE | NET_STRING_IP_NETWORK;
if (address->is_range)
{
status = ParseNetworkString (address->range_start, types, &ni, &range_port1, NULL);
if (status != ERROR_SUCCESS)
- goto CleanupExit;
+ {
+ _r_log (LOG_LEVEL_INFO, NULL, L"ParseNetworkString", status, address->range_start);
+
+ return FALSE;
+ }
status = ParseNetworkString (address->range_end, types, &ni_end, &range_port2, NULL);
+ if (status != ERROR_SUCCESS)
+ {
+ _r_log (LOG_LEVEL_INFO, NULL, L"ParseNetworkString", status, address->range_end);
+
+ return FALSE;
+ }
+
if (range_port2)
{
port = range_port2;
@@ -1379,11 +1258,17 @@ BOOLEAN _app_parsenetworkstring (
}
else
{
- status = ParseNetworkString (network_string, types, &ni, &port, &prefix_length);
- }
+ _r_str_copystring (rule_string, RTL_NUMBER_OF (rule_string), network_string);
- if (status != ERROR_SUCCESS)
- goto CleanupExit;
+ status = ParseNetworkString (rule_string, types, &ni, &port, &prefix_length);
+
+ if (status != ERROR_SUCCESS)
+ {
+ _r_log (LOG_LEVEL_INFO, NULL, L"ParseNetworkString", status, rule_string);
+
+ return FALSE;
+ }
+ }
address->format = ni.Format;
address->port = port;
@@ -1418,12 +1303,12 @@ BOOLEAN _app_parsenetworkstring (
address->range.valueLow.type = FWP_BYTE_ARRAY16_TYPE;
RtlCopyMemory (address->addr6_low, ni.Ipv6Address.sin6_addr.u.Byte, FWP_V6_ADDR_SIZE);
- address->range.valueLow.byteArray16 = (FWP_BYTE_ARRAY16 *)address->addr6_low;
+ address->range.valueLow.byteArray16 = (FWP_BYTE_ARRAY16*)address->addr6_low;
address->range.valueHigh.type = FWP_BYTE_ARRAY16_TYPE;
RtlCopyMemory (address->addr6_high, ni_end.Ipv6Address.sin6_addr.u.Byte, FWP_V6_ADDR_SIZE);
- address->range.valueHigh.byteArray16 = (FWP_BYTE_ARRAY16 *)address->addr6_high;
+ address->range.valueHigh.byteArray16 = (FWP_BYTE_ARRAY16*)address->addr6_high;
}
else
{
@@ -1433,21 +1318,21 @@ BOOLEAN _app_parsenetworkstring (
return TRUE;
}
-
-CleanupExit:
-
- _r_log (LOG_LEVEL_INFO, NULL, L"ParseNetworkString", status, network_string);
+ else
+ {
+ // unknown address family
+ }
return FALSE;
}
_Success_ (return)
BOOLEAN _app_preparserulestring (
- _In_ PR_STRINGREF rule,
+ _In_ PCR_STRINGREF rule,
_Out_ PITEM_ADDRESS address
)
{
- static WCHAR valid_chars[] = {
+ WCHAR valid_chars[] = {
L'.',
L':',
L'[',
@@ -1457,12 +1342,12 @@ BOOLEAN _app_preparserulestring (
L'/',
};
- R_STRINGREF range_start_part;
- R_STRINGREF range_end_part;
- WCHAR rule_string[256];
+ R_STRINGREF range_start_part, range_end_part;
+ WCHAR rule_string[0x100];
ULONG_PTR length;
ULONG types;
BOOLEAN is_valid;
+ ULONG status;
length = _r_str_getlength2 (rule);
@@ -1478,7 +1363,6 @@ BOOLEAN _app_preparserulestring (
if (rule->buffer[i] == valid_chars[j])
{
is_valid = TRUE;
-
break;
}
}
@@ -1511,7 +1395,6 @@ BOOLEAN _app_preparserulestring (
if (!_r_str_isdigit (rule->buffer[i]) && rule->buffer[i] != DIVIDER_RULE_RANGE)
{
address->type = DATA_UNKNOWN;
-
break;
}
}
@@ -1520,28 +1403,48 @@ BOOLEAN _app_preparserulestring (
if (address->type != DATA_UNKNOWN)
return TRUE;
- _r_str_copystring (rule_string, RTL_NUMBER_OF (rule_string), rule);
-
types = NET_STRING_IP_ADDRESS | NET_STRING_IP_SERVICE | NET_STRING_IP_NETWORK | NET_STRING_IP_ADDRESS_NO_SCOPE | NET_STRING_IP_SERVICE_NO_SCOPE;
// check rule for ip address
if (address->is_range)
{
- if (ParseNetworkString (address->range_start, types, NULL, NULL, NULL) == ERROR_SUCCESS &&
- ParseNetworkString (address->range_end, types, NULL, NULL, NULL) == ERROR_SUCCESS)
+ status = ParseNetworkString (address->range_start, types, NULL, NULL, NULL);
+
+ if (status != ERROR_SUCCESS)
+ {
+ _r_log (LOG_LEVEL_INFO, NULL, L"ParseNetworkString", status, address->range_start);
+
+ return FALSE;
+ }
+
+ status = ParseNetworkString (address->range_end, types, NULL, NULL, NULL);
+
+ if (status != ERROR_SUCCESS)
+ {
+ _r_log (LOG_LEVEL_INFO, NULL, L"ParseNetworkString", status, address->range_end);
+
+ return FALSE;
+ }
+
+ address->type = DATA_TYPE_IP;
+
+ return TRUE;
+ }
+ else
+ {
+ _r_str_copystring (rule_string, RTL_NUMBER_OF (rule_string), rule);
+
+ status = ParseNetworkString (rule_string, types, NULL, NULL, NULL);
+
+ if (status == ERROR_SUCCESS)
{
address->type = DATA_TYPE_IP;
return TRUE;
}
- }
- else
- {
- if (ParseNetworkString (rule_string, types, NULL, NULL, NULL) == ERROR_SUCCESS)
+ else
{
- address->type = DATA_TYPE_IP;
-
- return TRUE;
+ _r_log (LOG_LEVEL_INFO, NULL, L"ParseNetworkString", status, rule_string);
}
}
@@ -1550,11 +1453,10 @@ BOOLEAN _app_preparserulestring (
_Success_ (return)
BOOLEAN _app_parserulestring (
- _In_opt_ PR_STRINGREF rule,
+ _In_opt_ PCR_STRINGREF rule,
_Out_ PITEM_ADDRESS address
)
{
- WCHAR rule_string[256];
R_STRINGREF sr;
RtlZeroMemory (address, sizeof (ITEM_ADDRESS));
@@ -1562,7 +1464,7 @@ BOOLEAN _app_parserulestring (
if (_r_obj_isstringempty (rule))
return TRUE;
- // parse rule type
+ // parse rule string
if (!_app_preparserulestring (rule, address))
return FALSE;
@@ -1581,10 +1483,7 @@ BOOLEAN _app_parserulestring (
address->range.valueHigh.type = FWP_UINT16;
address->range.valueHigh.uint16 = (UINT16)_r_str_toulong (&sr);
- if (address->range.valueLow.uint16 < 1)
- return FALSE;
-
- if (address->range.valueHigh.uint16 > 65535)
+ if (address->range.valueLow.uint16 < 1 || address->range.valueHigh.uint16 > 65535)
return FALSE;
if (address->range.valueLow.uint16 >= address->range.valueHigh.uint16)
@@ -1597,10 +1496,7 @@ BOOLEAN _app_parserulestring (
// ...port
address->port = (UINT16)_r_str_toulong (rule);
- if (address->port < 1)
- return FALSE;
-
- if (address->port > 65535)
+ if (address->port < 1 || address->port > 65535)
return FALSE;
return TRUE;
@@ -1608,10 +1504,7 @@ BOOLEAN _app_parserulestring (
}
else if (address->type == DATA_TYPE_IP)
{
- _r_str_copystring (rule_string, RTL_NUMBER_OF (rule_string), rule);
-
- if (!_app_parsenetworkstring (rule_string, address))
- return FALSE;
+ return _app_parsenetworkstring (rule, address);
}
return TRUE;
@@ -1623,11 +1516,10 @@ PR_STRING _app_resolveaddress (
_In_ LPCVOID address
)
{
+ PR_STRING arpa_string, string = NULL;
PDNS_RECORD dns_records = NULL;
- PR_STRING string = NULL;
- PR_STRING arpa_string;
- DNS_STATUS status;
ULONG arpa_hash;
+ DNS_STATUS status;
arpa_string = _app_formatarpa (af, address);
arpa_hash = _r_str_gethash (&arpa_string->sr, TRUE);
@@ -1650,7 +1542,6 @@ PR_STRING _app_resolveaddress (
if (dns_record->wType == DNS_TYPE_PTR)
{
string = _r_obj_createstring (dns_record->Data.PTR.pNameHost);
-
break;
}
}
@@ -1667,16 +1558,15 @@ PR_STRING _app_resolveaddress (
}
PR_STRING _app_resolveaddress_interlocked (
- _In_ PVOID volatile *string,
+ _In_ volatile PVOID_PTR string,
_In_ ADDRESS_FAMILY af,
_In_ LPCVOID address,
_In_ BOOLEAN is_resolutionenabled
)
{
- PR_STRING current_string;
- PR_STRING new_string;
+ PR_STRING current_string, new_string;
- current_string = _InterlockedCompareExchangePointer (string, NULL, NULL);
+ current_string = (PR_STRING)_InterlockedCompareExchangePointer (string, NULL, NULL);
if (current_string)
return current_string;
@@ -1693,7 +1583,7 @@ PR_STRING _app_resolveaddress_interlocked (
new_string = _r_obj_referenceemptystring ();
}
- current_string = _InterlockedCompareExchangePointer (string, new_string, NULL);
+ current_string = (PR_STRING)_InterlockedCompareExchangePointer (string, new_string, NULL);
if (!current_string)
{
@@ -1709,23 +1599,17 @@ PR_STRING _app_resolveaddress_interlocked (
VOID _app_fileloggingenable ()
{
- BOOLEAN is_enable;
- NTSTATUS status;
-
- is_enable = _r_config_getboolean (L"IsEnableAppMonitor", FALSE, NULL);
-
- if (is_enable)
+ if (_r_config_getboolean (L"IsEnableAppMonitor", FALSE, NULL))
{
- status = _r_sys_createthread (&config.hmonitor_thread, NtCurrentProcess (), &_app_timercallback, NULL, NULL, L"FileMonitor");
-
- if (NT_SUCCESS (status))
+ // TODO! rewrite this and watch FS changes through NtNotifyChangeDirectoryFile, then read file hash!
+ if (NT_SUCCESS (_r_sys_createthread (&config.hmonitor_thread, NtCurrentProcess (), &_app_timercallback, NULL, NULL, L"FileMonitor")))
NtResumeThread (config.hmonitor_thread, NULL);
}
else
{
if (config.hmonitor_thread)
{
- NtTerminateThread (config.hmonitor_thread, 0);
+ _r_sys_terminatethread (config.hmonitor_thread, STATUS_CANCELLED);
NtClose (config.hmonitor_thread);
config.hmonitor_thread = NULL;
@@ -1750,10 +1634,7 @@ VOID NTAPI _app_timercallback (
while (_r_obj_enumhashtablepointer (apps_table, (PVOID_PTR)&ptr_app, NULL, &enum_key))
{
- if (!ptr_app->hash || !_app_isappvalidbinary (ptr_app->real_path))
- continue;
-
- if (!_app_isappused (ptr_app))
+ if (!ptr_app->hash || !_app_isappvalidbinary (ptr_app->real_path) || !_app_isappused (ptr_app))
continue;
status = _r_crypt_getfilehash (&string, BCRYPT_SHA256_ALGORITHM, &ptr_app->real_path->sr, NULL);
@@ -1788,24 +1669,23 @@ VOID _app_getfileinformation (
{
PITEM_APP_INFO ptr_app_info;
- ptr_app_info = _app_getappinfobyhash2 (app_hash);
-
if (_r_obj_isstringempty (path))
return;
+ ptr_app_info = _app_getappinfobyhash2 (app_hash);
+
if (ptr_app_info)
{
- // all information is already set
+ // all information are already set!
if (ptr_app_info->is_loaded)
{
_r_obj_dereference (ptr_app_info);
-
return;
}
}
else
{
- ptr_app_info = _r_obj_allocate (sizeof (ITEM_APP_INFO), &_app_dereferenceappinfo);
+ ptr_app_info = (PITEM_APP_INFO)_r_obj_allocate (sizeof (ITEM_APP_INFO), &_app_dereferenceappinfo);
ptr_app_info->path = _r_obj_reference (path);
ptr_app_info->app_hash = app_hash;
@@ -1813,27 +1693,31 @@ VOID _app_getfileinformation (
ptr_app_info->listview_id = listview_id;
_r_queuedlock_acquireexclusive (&lock_cache_information);
-
_r_obj_addhashtablepointer (cache_information, app_hash, _r_obj_reference (ptr_app_info));
-
_r_queuedlock_releaseexclusive (&lock_cache_information);
}
// check for binary path is valid
if (_app_isappvalidbinary (path))
+ {
_r_workqueue_queueitem (&file_queue, &_app_queue_fileinformation, ptr_app_info);
+ }
+ else
+ {
+ _r_obj_dereference (ptr_app_info); // cleanup!
+ }
}
VOID _app_queue_resolver (
_In_ HWND hwnd,
_In_ INT listview_id,
- _In_ ULONG_PTR hash_code,
+ _In_ ULONG hash_code,
_In_ PVOID base_address
)
{
PITEM_CONTEXT context;
- context = _r_freelist_allocateitem (&context_free_list);
+ context = (PITEM_CONTEXT)_r_freelist_allocateitem (&context_free_list);
context->hwnd = hwnd;
context->listview_id = listview_id;
@@ -1852,12 +1736,13 @@ VOID NTAPI _app_queue_fileinformation (
HWND hwnd;
NTSTATUS status;
- ptr_app_info = arglist;
- hwnd = _r_app_gethwnd ();
+ ptr_app_info = (PITEM_APP_INFO)arglist;
if (ptr_app_info->is_loaded)
return;
+ hwnd = _r_app_gethwnd ();
+
status = _r_fs_openfile (&hfile, &ptr_app_info->path->sr, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE, 0, FALSE);
if (!NT_SUCCESS (status))
@@ -1883,7 +1768,7 @@ VOID NTAPI _app_queue_fileinformation (
_app_getfilehashinfo (hfile, ptr_app_info->app_hash);
// redraw listview
- if (_r_wnd_isvisible (hwnd, FALSE))
+ if (hwnd && _r_wnd_isvisible (hwnd, FALSE) && ptr_app_info->listview_id != 0)
_r_listview_redraw (hwnd, ptr_app_info->listview_id);
ptr_app_info->is_loaded = TRUE;
@@ -1897,13 +1782,10 @@ VOID NTAPI _app_queue_notifyinformation (
_In_ PVOID arglist
)
{
+ PR_STRING address_str, host_str = NULL, localized_string, signature_str = NULL;
PITEM_APP_INFO ptr_app_info;
PITEM_CONTEXT context;
PITEM_LOG ptr_log;
- PR_STRING signature_str = NULL;
- PR_STRING host_str = NULL;
- PR_STRING localized_string;
- PR_STRING address_str;
HANDLE hfile;
HICON hicon;
HDWP hdefer;
@@ -1911,20 +1793,15 @@ VOID NTAPI _app_queue_notifyinformation (
BOOLEAN is_iconset = FALSE;
NTSTATUS status;
- context = arglist;
+ context = (PITEM_CONTEXT)arglist;
- ptr_log = context->base_address;
-
- // query address string
- address_str = _app_formataddress (ptr_log->af, ptr_log->protocol, &ptr_log->remote_addr, 0, FMTADDR_USE_PROTOCOL);
+ ptr_log = (PITEM_LOG)context->base_address;
// query notification host name
- if (_r_config_getboolean (L"IsNetworkResolutionsEnabled", FALSE, NULL))
+ if (_r_config_getboolean (L"IsNetworkResolutionsEnabled", TRUE, NULL))
{
host_str = _app_resolveaddress_interlocked ((volatile PVOID_PTR)&ptr_log->remote_host_str, ptr_log->af, &ptr_log->remote_addr, TRUE);
-
- if (host_str)
- host_str = _r_obj_reference (host_str);
+ host_str = _r_obj_reference (host_str);
}
// query signature
@@ -1971,9 +1848,9 @@ VOID NTAPI _app_queue_notifyinformation (
do
{
- if (!_app_getappinfoparam2 (ptr_log->app_hash, 0, INFO_SIGNATURE_STRING, &signature_str, sizeof (signature_str)))
+ if (!_app_getappinfoparam2 (ptr_log->app_hash, 0, INFO_SIGNATURE_STRING, &signature_str, sizeof (PR_STRING)))
{
- _r_sys_sleep (250);
+ _r_sys_sleep (250); // wait
}
else
{
@@ -1990,6 +1867,9 @@ VOID NTAPI _app_queue_notifyinformation (
// set signature string
_r_ctrl_settablestring (context->hwnd, &hdefer, IDC_SIGNATURE_ID, &localized_string->sr, IDC_SIGNATURE_TEXT, &signature_str->sr);
+ // query address string
+ address_str = _app_formataddress (ptr_log->af, ptr_log->protocol, &ptr_log->remote_addr, 0, FMTADDR_USE_PROTOCOL);
+
// set address string
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_ADDRESS), L":"));
@@ -2008,6 +1888,9 @@ VOID NTAPI _app_queue_notifyinformation (
_r_obj_dereference (localized_string);
+ if (address_str)
+ _r_obj_dereference (address_str);
+
if (hdefer)
EndDeferWindowPos (hdefer);
}
@@ -2021,9 +1904,6 @@ VOID NTAPI _app_queue_notifyinformation (
if (signature_str)
_r_obj_dereference (signature_str);
- if (address_str)
- _r_obj_dereference (address_str);
-
if (host_str)
_r_obj_dereference (host_str);
@@ -2039,31 +1919,30 @@ VOID NTAPI _app_queue_resolveinformation (
PITEM_LOG ptr_log;
BOOLEAN is_resolutionenabled;
- context = arglist;
+ context = (PITEM_CONTEXT)arglist;
- is_resolutionenabled = _r_config_getboolean (L"IsNetworkResolutionsEnabled", FALSE, NULL);
+ is_resolutionenabled = _r_config_getboolean (L"IsNetworkResolutionsEnabled", TRUE, NULL);
switch (context->listview_id)
{
case IDC_LOG:
{
- ptr_log = context->base_address;
+ ptr_log = (PITEM_LOG)context->base_address;
- _app_resolveaddress_interlocked ((volatile PVOID_PTR)&ptr_log->local_host_str, ptr_log->af, &ptr_log->local_addr, is_resolutionenabled);
_app_resolveaddress_interlocked ((volatile PVOID_PTR)&ptr_log->remote_host_str, ptr_log->af, &ptr_log->remote_addr, is_resolutionenabled);
+ _app_resolveaddress_interlocked ((volatile PVOID_PTR)&ptr_log->local_host_str, ptr_log->af, &ptr_log->local_addr, is_resolutionenabled);
break;
}
case IDC_NETWORK:
{
- ptr_network = context->base_address;
+ ptr_network = (PITEM_NETWORK)context->base_address;
- _app_formataddress_interlocked ((volatile PVOID_PTR)&ptr_network->local_addr_str, ptr_network->af, &ptr_network->local_addr);
_app_formataddress_interlocked ((volatile PVOID_PTR)&ptr_network->remote_addr_str, ptr_network->af, &ptr_network->remote_addr);
-
- _app_resolveaddress_interlocked ((volatile PVOID_PTR)&ptr_network->local_host_str, ptr_network->af, &ptr_network->local_addr, is_resolutionenabled);
+ _app_formataddress_interlocked ((volatile PVOID_PTR)&ptr_network->local_addr_str, ptr_network->af, &ptr_network->local_addr);
_app_resolveaddress_interlocked ((volatile PVOID_PTR)&ptr_network->remote_host_str, ptr_network->af, &ptr_network->remote_addr, is_resolutionenabled);
+ _app_resolveaddress_interlocked ((volatile PVOID_PTR)&ptr_network->local_host_str, ptr_network->af, &ptr_network->local_addr, is_resolutionenabled);
break;
}
@@ -2080,20 +1959,10 @@ VOID NTAPI _app_queue_resolveinformation (
BOOLEAN _app_wufixenabled ()
{
- WCHAR file_path[256];
- R_STRINGREF sr;
-
if (!_r_config_getboolean (L"IsWUFixEnabled", FALSE, NULL))
return FALSE;
- _r_str_printf (file_path, RTL_NUMBER_OF (file_path), L"%s\\wusvc.exe", _r_sys_getsystemdirectory ()->buffer);
-
- _r_obj_initializestringref (&sr, file_path);
-
- if (_r_fs_isexists (&sr))
- return TRUE;
-
- return FALSE;
+ return _r_fs_isexists (&config.wusvc_path->sr);
}
VOID _app_wufixhelper (
@@ -2104,8 +1973,7 @@ VOID _app_wufixhelper (
)
{
SERVICE_STATUS svc_status;
- WCHAR reg_value[128];
- WCHAR reg_key[128];
+ WCHAR reg_key[0x80], reg_value[0x80];
PR_STRING image_path;
SC_HANDLE hsvc;
HANDLE hkey;
@@ -2117,7 +1985,10 @@ VOID _app_wufixhelper (
status = _r_reg_openkey (&hkey, HKEY_LOCAL_MACHINE, reg_key, 0, KEY_READ | KEY_WRITE);
if (!NT_SUCCESS (status))
+ {
+ _r_log (LOG_LEVEL_INFO, NULL, L"_r_reg_openkey", status, reg_key);
return;
+ }
// query service path
status = _r_reg_querystring (hkey, L"ImagePath", &image_path, NULL);
@@ -2161,7 +2032,8 @@ VOID _app_wufixenable (
)
{
SC_HANDLE hsvcmgr;
- ULONG app_hash;
+ PITEM_APP ptr_app;
+ PR_LIST rules;
NTSTATUS status;
hsvcmgr = OpenSCManagerW (NULL, NULL, SC_MANAGER_CONNECT | SERVICE_QUERY_STATUS | SERVICE_START | SERVICE_STOP);
@@ -2172,34 +2044,46 @@ VOID _app_wufixenable (
if (is_enable)
{
if (_r_fs_isexists (&config.wusvc_path->sr))
- _r_fs_deleterecycle (&config.wusvc_path->sr);
+ _r_fs_deletefile (&config.wusvc_path->sr, NULL);
+ // TODO: windows cannot create symbolic link for another symlink, rewrite this
status = _r_fs_createhardlink (&config.svchost_path->sr, &config.wusvc_path->sr);
if (!NT_SUCCESS (status))
_r_fs_copyfile (&config.svchost_path->sr, &config.wusvc_path->sr, FALSE);
- app_hash = _app_addapplication (hwnd, DATA_UNKNOWN, config.wusvc_path, NULL, NULL);
+ ptr_app = _app_addapplication (hwnd, DATA_UNKNOWN, config.wusvc_path, NULL, NULL);
- if (app_hash)
+ if (ptr_app)
{
- _app_setappinfobyhash (app_hash, INFO_IS_ENABLED, LongToPtr (TRUE));
- _app_setappinfobyhash (app_hash, INFO_IS_UNDELETABLE, LongToPtr (TRUE));
+ _app_setappinfo (ptr_app, INFO_IS_ENABLED, LongToPtr (TRUE));
+ _app_setappinfo (ptr_app, INFO_IS_UNDELETABLE, LongToPtr (TRUE));
+
+ rules = _r_obj_createlist (0x02, NULL);
+
+ _r_obj_addlistitem (rules, ptr_app, NULL);
+
+ _wfp_createappfilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
+
+ _r_obj_dereference (ptr_app);
+ _r_obj_dereference (rules);
}
}
else
{
if (_r_fs_isexists (&config.wusvc_path->sr))
{
- app_hash = _r_str_gethash (&config.wusvc_path->sr, TRUE);
+ ptr_app = _app_getappitem (_r_str_gethash (&config.wusvc_path->sr, TRUE));
- if (app_hash)
+ if (ptr_app)
{
- _app_setappinfobyhash (app_hash, INFO_IS_ENABLED, LongToPtr (FALSE));
- _app_setappinfobyhash (app_hash, INFO_IS_UNDELETABLE, LongToPtr (FALSE));
+ _app_setappinfo (ptr_app, INFO_DISABLE, LongToPtr (FALSE));
+ _app_setappinfo (ptr_app, INFO_IS_UNDELETABLE, LongToPtr (FALSE));
+
+ _r_obj_dereference (ptr_app);
}
- _r_fs_deleterecycle (&config.wusvc_path->sr);
+ _r_fs_deletefile (&config.wusvc_path->sr, NULL);
}
}
diff --git a/src/helper.h b/src/helper.h
index 83e679f5..e0dceaa1 100644
--- a/src/helper.h
+++ b/src/helper.h
@@ -36,6 +36,7 @@ VOID NTAPI _app_dereferencenetwork (
VOID NTAPI _app_dereferencelog (
_In_ PVOID entry
);
+
VOID NTAPI _app_dereferencerule (
_In_ PVOID entry
);
@@ -44,7 +45,12 @@ VOID _app_addcachetable (
_Inout_ PR_HASHTABLE hashtable,
_In_ ULONG hash_code,
_In_ PR_QUEUED_LOCK spin_lock,
- _In_opt_ PR_STRING string
+ _In_opt_ PVOID string
+);
+
+BOOLEAN _app_checkipisnotlocal (
+ _In_ ADDRESS_FAMILY af,
+ _In_ LPCVOID address
);
BOOLEAN _app_getcachetable (
@@ -69,17 +75,17 @@ PR_STRING _app_formataddress (
);
PR_STRING _app_formataddress_interlocked (
- _In_ PVOID volatile *string,
+ _In_ volatile PVOID_PTR string,
_In_ ADDRESS_FAMILY af,
_In_ LPCVOID address
);
_Success_ (NT_SUCCESS (return))
NTSTATUS _app_formatip (
- _In_ ADDRESS_FAMILY af,
- _In_ LPCVOID address,
_Out_writes_to_ (buffer_length, buffer_length) LPWSTR buffer,
_In_ ULONG buffer_length,
+ _In_ ADDRESS_FAMILY af,
+ _In_ LPCVOID address,
_In_ BOOLEAN is_checkempty
);
@@ -122,8 +128,7 @@ PR_STRING _app_getappdisplayname (
_Ret_maybenull_
PR_STRING _app_getapppath (
- _In_ PITEM_APP ptr_app,
- _In_ BOOLEAN is_returnshort
+ _In_ PITEM_APP ptr_app
);
VOID _app_getfileicon (
@@ -153,21 +158,11 @@ ULONG _app_addcolor (
_In_ BOOLEAN is_enabled
);
+_Success_ (return != 0)
COLORREF _app_getcolorvalue (
_In_ ULONG color_hash
);
-VOID _app_generate_rulescontrol (
- _In_ HMENU hsubmenu,
- _In_ ULONG app_hash,
- _In_opt_ PITEM_LOG ptr_log
-);
-
-VOID _app_generate_timerscontrol (
- _In_ HMENU hsubmenu,
- _In_ ULONG app_hash
-);
-
BOOLEAN _app_setruletoapp (
_In_ HWND hwnd,
_Inout_ PITEM_RULE ptr_rule,
@@ -178,19 +173,13 @@ BOOLEAN _app_setruletoapp (
_Success_ (return)
BOOLEAN _app_parsenetworkstring (
- _In_ LPCWSTR network_string,
+ _In_ PCR_STRINGREF network_string,
_Inout_ PITEM_ADDRESS address
);
-_Success_ (return)
-BOOLEAN _app_preparserulestring (
- _In_ PR_STRINGREF rule,
- _Out_ PITEM_ADDRESS address
-);
-
_Success_ (return)
BOOLEAN _app_parserulestring (
- _In_opt_ PR_STRINGREF rule,
+ _In_opt_ PCR_STRINGREF rule,
_Out_ PITEM_ADDRESS address
);
@@ -201,7 +190,7 @@ PR_STRING _app_resolveaddress (
);
PR_STRING _app_resolveaddress_interlocked (
- _In_ PVOID volatile *string,
+ _In_ volatile PVOID_PTR string,
_In_ ADDRESS_FAMILY af,
_In_ LPCVOID address,
_In_ BOOLEAN is_resolutionenabled
@@ -223,7 +212,7 @@ VOID _app_getfileinformation (
VOID _app_queue_resolver (
_In_ HWND hwnd,
_In_ INT listview_id,
- _In_ ULONG_PTR hash_code,
+ _In_ ULONG hash_code,
_In_ PVOID base_address
);
diff --git a/src/icons.c b/src/icons.c
index b125870b..79e3168a 100644
--- a/src/icons.c
+++ b/src/icons.c
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2016-2025 Henry++
+// Copyright (c) 2016-2026 Henry++
#include "global.h"
@@ -12,29 +12,21 @@ PICON_INFORMATION _app_icons_getdefault ()
if (_r_initonce_begin (&init_once))
{
- // load default icons
- path = _r_obj_concatstrings (
- 2,
- _r_sys_getsystemdirectory ()->buffer,
- PATH_SVCHOST
- );
-
- _app_icons_loadfromfile (path, 0, &icon_info.app_icon_id, &icon_info.app_hicon, FALSE);
-
- // load default service icons
- _r_obj_dereference (path);
+ // load default app icon
+ _app_icons_loadfromfile (config.svchost_path, DATA_UNKNOWN, &icon_info.app_icon_id, &icon_info.app_hicon, FALSE);
+ // load service icon
path = _r_obj_concatstrings (
2,
_r_sys_getsystemdirectory ()->buffer,
L"\\shell32.dll"
);
- _app_icons_loadfromfile (path, 0, &icon_info.service_icon_id, &icon_info.service_hicon, FALSE);
+ _app_icons_loadfromfile (path, DATA_UNKNOWN, &icon_info.service_icon_id, &icon_info.service_hicon, FALSE);
_r_obj_dereference (path);
- // load uwp icons
+ // load uwp icon
if (_r_sys_isosversiongreaterorequal (WINDOWS_8))
{
path = _r_obj_concatstrings (
@@ -43,7 +35,7 @@ PICON_INFORMATION _app_icons_getdefault ()
L"\\wsreset.exe"
);
- _app_icons_loadfromfile (path, 0, &icon_info.uwp_icon_id, &icon_info.uwp_hicon, FALSE);
+ _app_icons_loadfromfile (path, DATA_UNKNOWN, &icon_info.uwp_icon_id, &icon_info.uwp_hicon, FALSE);
_r_obj_dereference (path);
}
@@ -61,10 +53,7 @@ HICON _app_icons_getdefaultapp_hicon ()
icon_info = _app_icons_getdefault ();
- if (icon_info->app_hicon)
- return CopyIcon (icon_info->app_hicon);
-
- return NULL;
+ return icon_info->app_hicon ? CopyIcon (icon_info->app_hicon) : NULL;
}
_Ret_maybenull_
@@ -83,10 +72,8 @@ HICON _app_icons_getdefaulttype_hicon (
if (icon_info->uwp_hicon)
return CopyIcon (icon_info->uwp_hicon);
}
- if (icon_info->app_hicon)
- return CopyIcon (icon_info->app_hicon);
- return NULL;
+ return icon_info->app_hicon ? CopyIcon (icon_info->app_hicon) : NULL;
}
LONG _app_icons_getdefaultapp_id (
@@ -118,22 +105,17 @@ HICON _app_icons_getsafeapp_hicon (
PITEM_APP ptr_app;
HICON hicon;
LONG icon_id;
- BOOLEAN is_iconshidded;
icon_info = _app_icons_getdefault ();
ptr_app = _app_getappitem (app_hash);
if (!ptr_app)
- {
- if (icon_info->app_hicon)
- return CopyIcon (icon_info->app_hicon);
+ return icon_info->app_hicon ? CopyIcon (icon_info->app_hicon) : NULL;
+ if (_r_obj_isstringempty (ptr_app->real_path))
return NULL;
- }
- is_iconshidded = _r_config_getboolean (L"IsIconsHidden", FALSE, NULL);
-
- if (is_iconshidded || !_app_isappvalidbinary (ptr_app->real_path))
+ if (_r_config_getboolean (L"IsIconsHidden", FALSE, NULL) || !_app_isappvalidbinary (ptr_app->real_path))
{
hicon = _app_icons_getdefaulttype_hicon (ptr_app->type, icon_info);
@@ -144,7 +126,7 @@ HICON _app_icons_getsafeapp_hicon (
_app_icons_loadfromfile (ptr_app->real_path, ptr_app->type, &icon_id, &hicon, TRUE);
- if (!icon_id || ((ptr_app->type == DATA_APP_UWP || ptr_app->type == DATA_APP_SERVICE) && icon_id == icon_info->app_icon_id))
+ if (!icon_id || ((ptr_app->type == DATA_APP_SERVICE || ptr_app->type == DATA_APP_UWP) && icon_id == icon_info->app_icon_id))
{
if (hicon)
DestroyIcon (hicon);
@@ -159,46 +141,46 @@ HICON _app_icons_getsafeapp_hicon (
VOID _app_icons_loaddefaults (
_In_ ENUM_TYPE_DATA type,
- _Inout_opt_ HICON_PTR hicon_ptr,
- _Inout_opt_ PLONG icon_id_ptr
+ _Inout_opt_ HICON_PTR out_hicon,
+ _Inout_opt_ PLONG out_icon_id
)
{
PICON_INFORMATION icon_info;
icon_info = _app_icons_getdefault ();
- if (icon_id_ptr)
+ if (out_hicon)
{
- if (*icon_id_ptr == 0 || (type == DATA_APP_UWP && *icon_id_ptr == icon_info->app_icon_id) || (type == DATA_APP_SERVICE && *icon_id_ptr == icon_info->app_icon_id))
- {
- if (type == DATA_APP_UWP)
- {
- *icon_id_ptr = icon_info->uwp_icon_id;
- }
- else if (type == DATA_APP_SERVICE)
- {
- *icon_id_ptr = icon_info->service_icon_id;
- }
- else
- {
- *icon_id_ptr = icon_info->app_icon_id;
- }
- }
- }
-
- if (hicon_ptr)
- {
- if (*hicon_ptr == NULL || type == DATA_APP_UWP)
+ if (*out_hicon == NULL && type == DATA_APP_UWP)
{
if (type == DATA_APP_UWP)
{
if (icon_info->uwp_hicon)
- *hicon_ptr = CopyIcon (icon_info->uwp_hicon);
+ *out_hicon = CopyIcon (icon_info->uwp_hicon);
}
else
{
if (icon_info->app_hicon)
- *hicon_ptr = CopyIcon (icon_info->app_hicon);
+ *out_hicon = CopyIcon (icon_info->app_hicon);
+ }
+ }
+ }
+
+ if (out_icon_id)
+ {
+ if (*out_icon_id == 0 || ((type == DATA_APP_SERVICE && *out_icon_id == icon_info->app_icon_id) || (type == DATA_APP_UWP && *out_icon_id == icon_info->app_icon_id)))
+ {
+ if (type == DATA_APP_SERVICE)
+ {
+ *out_icon_id = icon_info->service_icon_id;
+ }
+ else if (type == DATA_APP_UWP)
+ {
+ *out_icon_id = icon_info->uwp_icon_id;
+ }
+ else
+ {
+ *out_icon_id = icon_info->app_icon_id;
}
}
}
@@ -207,23 +189,23 @@ VOID _app_icons_loaddefaults (
VOID _app_icons_loadfromfile (
_In_opt_ PR_STRING path,
_In_ ENUM_TYPE_DATA type,
- _Out_opt_ PLONG icon_id_ptr,
- _Out_opt_ HICON_PTR hicon_ptr,
+ _Out_opt_ PLONG out_icon_id,
+ _Out_opt_ HICON_PTR out_hicon,
_In_ BOOLEAN is_loaddefaults
)
{
- if (!icon_id_ptr && !hicon_ptr)
+ if (!out_icon_id && !out_hicon)
return;
- if (icon_id_ptr)
- *icon_id_ptr = 0;
+ if (out_icon_id)
+ *out_icon_id = 0;
- if (hicon_ptr)
- *hicon_ptr = NULL;
+ if (out_hicon)
+ *out_hicon = NULL;
if (!_r_obj_isstringempty (path))
- _r_path_geticon (&path->sr, hicon_ptr, icon_id_ptr);
+ _r_path_geticon (&path->sr, out_hicon, out_icon_id);
if (is_loaddefaults)
- _app_icons_loaddefaults (type, hicon_ptr, icon_id_ptr);
+ _app_icons_loaddefaults (type, out_hicon, out_icon_id);
}
diff --git a/src/icons.h b/src/icons.h
index 2106ca8c..4ac0a444 100644
--- a/src/icons.h
+++ b/src/icons.h
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2016-2025 Henry++
+// Copyright (c) 2016-2026 Henry++
#pragma once
@@ -25,14 +25,14 @@ HICON _app_icons_getsafeapp_hicon (
VOID _app_icons_loaddefaults (
_In_ ENUM_TYPE_DATA type,
- _Inout_opt_ HICON_PTR hicon_ptr,
- _Inout_opt_ PLONG icon_id_ptr
+ _Inout_opt_ HICON_PTR out_hicon,
+ _Inout_opt_ PLONG out_icon_id
);
VOID _app_icons_loadfromfile (
_In_opt_ PR_STRING path,
_In_ ENUM_TYPE_DATA type,
- _Out_opt_ PLONG icon_id_ptr,
- _Out_opt_ HICON_PTR hicon_ptr,
+ _Out_opt_ PLONG out_icon_id,
+ _Out_opt_ HICON_PTR out_hicon,
_In_ BOOLEAN is_loaddefaults
);
diff --git a/src/listview.c b/src/listview.c
index cfdd7754..9f4cbb47 100644
--- a/src/listview.c
+++ b/src/listview.c
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2016-2025 Henry++
+// Copyright (c) 2016-2026 Henry++
#include "global.h"
@@ -74,11 +74,8 @@ VOID _app_listview_additems (
{
PITEM_APP ptr_app = NULL;
PITEM_RULE ptr_rule;
- LONG64 current_time;
ULONG_PTR enum_key = 0;
- current_time = _r_unixtime_now ();
-
// add apps
_r_queuedlock_acquireshared (&lock_apps);
@@ -87,8 +84,8 @@ VOID _app_listview_additems (
_app_listview_addappitem (hwnd, ptr_app);
// install timer
- if (ptr_app->timer)
- _app_timer_set (hwnd, ptr_app, ptr_app->timer - current_time);
+ if (ptr_app->timer > 0)
+ _app_timer_set (hwnd, ptr_app, ptr_app->timer - _r_unixtime_now ());
}
_r_queuedlock_releaseshared (&lock_apps);
@@ -98,32 +95,21 @@ VOID _app_listview_additems (
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
if (ptr_rule)
- _app_listview_addruleitem (hwnd, ptr_rule, (ULONG)i, FALSE);
+ _app_listview_addruleitem (hwnd, ptr_rule, i, FALSE);
}
_r_queuedlock_releaseshared (&lock_rules);
}
-VOID _app_listview_clearitems (
- _In_ HWND hwnd
-)
-{
- for (INT i = IDC_APPS_PROFILE; i <= IDC_RULES_CUSTOM; i++)
- {
- _r_listview_deleteallitems (hwnd, i);
- }
-}
-
VOID _app_listview_addappitem (
_In_ HWND hwnd,
_In_ PITEM_APP ptr_app
)
{
- INT listview_id;
- INT item_id;
+ INT item_id, listview_id;
listview_id = _app_listview_getbytype (ptr_app->type);
@@ -132,13 +118,12 @@ VOID _app_listview_addappitem (
item_id = _r_listview_getitemcount (hwnd, listview_id);
- _app_listview_lock (hwnd, listview_id, TRUE);
+ _app_listview_lock (hwnd, listview_id);
_r_listview_additem (hwnd, listview_id, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_listview_createcontext (ptr_app->app_hash));
-
_app_setappiteminfo (hwnd, listview_id, item_id, ptr_app);
- _app_listview_lock (hwnd, listview_id, FALSE);
+ _app_listview_unlock (hwnd, listview_id);
}
VOID _app_listview_addruleitem (
@@ -148,8 +133,7 @@ VOID _app_listview_addruleitem (
_In_ BOOLEAN is_forapp
)
{
- INT listview_id;
- INT item_id;
+ INT item_id, listview_id;
listview_id = _app_listview_getbytype (ptr_rule->type);
@@ -158,13 +142,12 @@ VOID _app_listview_addruleitem (
item_id = _r_listview_getitemcount (hwnd, listview_id);
- _app_listview_lock (hwnd, listview_id, TRUE);
+ _app_listview_lock (hwnd, listview_id);
_r_listview_additem (hwnd, listview_id, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_listview_createcontext (rule_idx));
-
_app_setruleiteminfo (hwnd, listview_id, item_id, ptr_rule, is_forapp);
- _app_listview_lock (hwnd, listview_id, FALSE);
+ _app_listview_unlock (hwnd, listview_id);
}
VOID _app_listview_addnetworkitem (
@@ -189,39 +172,41 @@ VOID _app_listview_addlogitem (
_r_listview_additem (hwnd, IDC_LOG, INT_ERROR, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, 0, _app_listview_createcontext (log_hash));
}
+VOID _app_listview_clearitems (
+ _In_ HWND hwnd
+)
+{
+ for (INT i = IDC_APPS_PROFILE; i <= IDC_RULES_CUSTOM; i++)
+ {
+ _r_listview_deleteallitems (hwnd, i);
+ }
+}
+
BOOLEAN _app_listview_islocked (
_In_ HWND hwnd,
_In_ INT ctrl_id
)
{
- PVOID context;
- ULONG property_id;
-
- property_id = (USHORT_MAX - ctrl_id);
-
- context = _r_wnd_getcontext (hwnd, property_id);
-
- return (context != NULL);
+ return (_r_wnd_getcontext (hwnd, (USHORT_MAX - ctrl_id)) != NULL);
}
-VOID _app_listview_lock (
+BOOLEAN _app_listview_lock (
_In_ HWND hwnd,
- _In_ INT ctrl_id,
- _In_ BOOLEAN is_lock
+ _In_ INT ctrl_id
)
{
- ULONG property_id;
+ if (_app_listview_islocked (hwnd, ctrl_id)) // check first!
+ return TRUE;
- property_id = (USHORT_MAX - ctrl_id);
+ return _r_wnd_setcontext (hwnd, (USHORT_MAX - ctrl_id), INVALID_HANDLE_VALUE);
+}
- if (is_lock)
- {
- _r_wnd_setcontext (hwnd, property_id, INVALID_HANDLE_VALUE);
- }
- else
- {
- _r_wnd_removecontext (hwnd, property_id);
- }
+BOOLEAN _app_listview_unlock (
+ _In_ HWND hwnd,
+ _In_ INT ctrl_id
+)
+{
+ return _r_wnd_removecontext (hwnd, (USHORT_MAX - ctrl_id));
}
LONG_PTR _app_listview_createcontext (
@@ -230,7 +215,7 @@ LONG_PTR _app_listview_createcontext (
{
PITEM_LISTVIEW_CONTEXT context;
- context = _r_freelist_allocateitem (&listview_free_list);
+ context = (PITEM_LISTVIEW_CONTEXT)_r_freelist_allocateitem (&listview_free_list);
context->id_code = id_code;
@@ -248,9 +233,7 @@ ULONG_PTR _app_listview_getcontextcode (
_In_ LONG_PTR lparam
)
{
- PITEM_LISTVIEW_CONTEXT context;
-
- context = (PITEM_LISTVIEW_CONTEXT)lparam;
+ PITEM_LISTVIEW_CONTEXT context = (PITEM_LISTVIEW_CONTEXT)lparam;
return context->id_code;
}
@@ -264,21 +247,21 @@ ULONG _app_listview_getappcontext (
{
PITEM_NETWORK ptr_network;
PITEM_LOG ptr_log;
- LONG_PTR context;
- ULONG app_hash = 0;
+ LPARAM lparam;
+ ULONG app_hash = 0, context;
- context = _r_listview_getitemlparam (hwnd, listview_id, item_id);
+ lparam = _r_listview_getitemlparam (hwnd, listview_id, item_id);
- if (!context)
+ if (lparam == 0)
return 0;
- context = _app_listview_getcontextcode (context);
+ context = (ULONG)_app_listview_getcontextcode (lparam);
switch (listview_id)
{
case IDC_NETWORK:
{
- ptr_network = _app_network_getitem ((ULONG)context);
+ ptr_network = _app_network_getitem (context);
if (ptr_network)
{
@@ -292,7 +275,7 @@ ULONG _app_listview_getappcontext (
case IDC_LOG:
{
- ptr_log = _app_getlogitem ((ULONG)context);
+ ptr_log = _app_getlogitem (context);
if (ptr_log)
{
@@ -306,7 +289,7 @@ ULONG _app_listview_getappcontext (
default:
{
- app_hash = (ULONG)context;
+ app_hash = context;
break;
}
}
@@ -314,6 +297,7 @@ ULONG _app_listview_getappcontext (
return app_hash;
}
+_Success_ (return != 0)
ULONG_PTR _app_listview_getitemcontext (
_In_ HWND hwnd,
_In_ INT listview_id,
@@ -324,19 +308,14 @@ ULONG_PTR _app_listview_getitemcontext (
lparam = _r_listview_getitemlparam (hwnd, listview_id, item_id);
- if (!lparam)
- return 0;
-
- return _app_listview_getcontextcode (lparam);
+ return (!lparam) ? 0 : _app_listview_getcontextcode (lparam);
}
BOOLEAN _app_listview_isitemhidden (
_In_ LPARAM lparam
)
{
- PITEM_LISTVIEW_CONTEXT context;
-
- context = (PITEM_LISTVIEW_CONTEXT)lparam;
+ PITEM_LISTVIEW_CONTEXT context = (PITEM_LISTVIEW_CONTEXT)lparam;
if (!context)
return FALSE;
@@ -352,13 +331,10 @@ INT _app_listview_finditem (
)
{
ULONG_PTR current_code;
- INT item_count;
if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_LOG) || listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID)
{
- item_count = _r_listview_getitemcount (hwnd, listview_id);
-
- for (INT i = 0; i < item_count; i++)
+ for (INT i = 0; i < _r_listview_getitemcount (hwnd, listview_id); i++)
{
current_code = _app_listview_getitemcontext (hwnd, listview_id, i);
@@ -374,34 +350,11 @@ INT _app_listview_finditem (
return INT_ERROR;
}
-VOID _app_listview_removeitem (
- _In_ HWND hwnd,
- _In_ ULONG_PTR id_code,
- _In_ ENUM_TYPE_DATA type
-)
-{
- INT listview_id;
- INT item_id;
-
- if (!hwnd)
- return;
-
- listview_id = _app_listview_getbytype (type);
-
- if (!listview_id)
- return;
-
- item_id = _app_listview_finditem (hwnd, listview_id, id_code);
-
- if (item_id != INT_ERROR)
- _r_listview_deleteitem (hwnd, listview_id, item_id);
-}
-
VOID _app_listview_showitemby_id (
_In_ HWND hwnd,
_In_ INT listview_id,
_In_ INT item_id,
- _In_ INT scroll_pos
+ _In_opt_ LONG scroll_pos
)
{
INT total_count;
@@ -432,31 +385,25 @@ VOID _app_listview_showitemby_param (
)
{
PITEM_TAB_CONTEXT tab_context;
- INT listview_id = 0;
- INT item_id;
+ INT item_id, listview_id = 0;
if (is_app)
{
- _app_getappinfobyhash ((ULONG)lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT));
+ if (!_app_getappinfobyhash ((ULONG)lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT)))
+ return;
}
else
{
- _app_getruleinfobyid (lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT));
+ if (!_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT)))
+ return;
}
- if (!listview_id)
- return;
-
tab_context = _app_listview_getcontext (hwnd, INT_ERROR);
- if (tab_context)
+ if (tab_context && listview_id != tab_context->listview_id)
{
- if (listview_id != tab_context->listview_id)
- {
- _app_listview_sort (hwnd, listview_id, INT_ERROR, FALSE);
-
- _app_listview_resize (hwnd, listview_id, FALSE);
- }
+ _app_listview_sort (hwnd, listview_id, INT_ERROR, FALSE);
+ _app_listview_resize (hwnd, listview_id, FALSE);
}
item_id = _app_listview_finditem (hwnd, listview_id, lparam);
@@ -486,16 +433,12 @@ VOID _app_listview_updateby_id (
if (flags & PR_UPDATE_TYPE)
{
- type = lparam;
+ type = (ENUM_TYPE_DATA)lparam;
- if (type == DATA_LISTVIEW_CURRENT)
- {
- listview_id = tab_context->listview_id;
- }
- else
- {
- listview_id = _app_listview_getbytype (type);
- }
+ listview_id = (type == DATA_LISTVIEW_CURRENT) ? tab_context->listview_id : _app_listview_getbytype (type);
+
+ if (listview_id == 0)
+ return;
}
else
{
@@ -510,7 +453,6 @@ VOID _app_listview_updateby_id (
if (!(flags & PR_UPDATE_NOSETVIEW))
{
_app_listview_setfont (hwnd, listview_id);
-
_app_listview_setview (hwnd, listview_id);
}
@@ -539,16 +481,15 @@ VOID _app_listview_updateby_param (
if (is_app)
{
- _app_getappinfobyhash ((ULONG)lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT));
+ if (!_app_getappinfobyhash ((ULONG)lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT)))
+ return;
}
else
{
- _app_getruleinfobyid (lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT));
+ if (!_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT)))
+ return;
}
- if (!listview_id)
- return;
-
if ((flags & PR_SETITEM_UPDATE))
_app_listview_updateby_id (hwnd, listview_id, 0);
@@ -572,21 +513,19 @@ VOID _app_listview_updateitemby_param (
{
PITEM_RULE ptr_rule;
PITEM_APP ptr_app;
- INT listview_id = 0;
- INT item_id;
+ INT item_id, listview_id = 0;
if (is_app)
{
- _app_getappinfobyhash ((ULONG)lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT));
+ if (!_app_getappinfobyhash ((ULONG)lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT)))
+ return;
}
else
{
- _app_getruleinfobyid (lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT));
+ if (!_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID, &listview_id, sizeof (INT)))
+ return;
}
- if (!listview_id)
- return;
-
item_id = _app_listview_finditem (hwnd, listview_id, lparam);
if (item_id == INT_ERROR)
@@ -599,9 +538,9 @@ VOID _app_listview_updateitemby_param (
if (!ptr_app)
return;
- _app_listview_lock (hwnd, listview_id, TRUE);
+ _app_listview_lock (hwnd, listview_id);
_app_setappiteminfo (hwnd, listview_id, item_id, ptr_app);
- _app_listview_lock (hwnd, listview_id, FALSE);
+ _app_listview_unlock (hwnd, listview_id);
_r_obj_dereference (ptr_app);
}
@@ -612,9 +551,9 @@ VOID _app_listview_updateitemby_param (
if (!ptr_rule)
return;
- _app_listview_lock (hwnd, listview_id, TRUE);
+ _app_listview_lock (hwnd, listview_id);
_app_setruleiteminfo (hwnd, listview_id, item_id, ptr_rule, FALSE);
- _app_listview_lock (hwnd, listview_id, FALSE);
+ _app_listview_unlock (hwnd, listview_id);
_r_obj_dereference (ptr_rule);
}
@@ -651,20 +590,9 @@ VOID _app_listview_refreshgroups (
_In_ INT listview_id
)
{
- WCHAR buffer1[128];
- WCHAR buffer2[128];
- UINT group1_title;
- UINT group2_title;
- UINT group3_title;
- UINT group4_title;
- UINT group5_title;
- INT total_count;
- INT group1_count = 0;
- INT group2_count = 0;
- INT group3_count = 0;
- INT group4_count = 0;
- INT group5_count = 0;
- INT group_id;
+ WCHAR buffer1[0x80], buffer2[0x80];
+ ULONG group1_title = 0, group2_title = 0, group3_title = 0, group4_title = 0, group5_title = 0;
+ INT group1_count = 0, group2_count = 0, group3_count = 0, group4_count = 0, group5_count = 0, total_count, group_id;
BOOLEAN is_rules;
if (!_r_listview_isgroupviewenabled (hwnd, listview_id))
@@ -685,28 +613,21 @@ VOID _app_listview_refreshgroups (
group1_title = IDS_GROUP_ENABLED;
group2_title = IDS_GROUP_ENABLED;
group3_title = IDS_GROUP_DISABLED;
- group4_title = 0;
- group5_title = 0;
}
else if (listview_id == IDC_RULE_APPS_ID || listview_id == IDC_NETWORK)
{
group1_title = IDS_TAB_APPS;
group2_title = IDS_TAB_SERVICES;
group3_title = IDS_TAB_PACKAGES;
- group4_title = 0;
- group5_title = 0;
}
else if (listview_id == IDC_APP_RULES_ID)
{
group1_title = IDS_TRAY_SYSTEM_RULES;
group2_title = IDS_TRAY_USER_RULES;
- group3_title = 0;
- group4_title = 0;
- group5_title = 0;
}
else
{
- return;
+ return; // unknown listview!
}
total_count = _r_listview_getitemcount (hwnd, listview_id);
@@ -747,7 +668,7 @@ VOID _app_listview_refreshgroups (
if (total_count)
{
- // set group titles
+ // set group 1 and 2 titles
if (is_rules)
{
_r_str_printf (buffer1, RTL_NUMBER_OF (buffer1), L"%s (%d/%d) [%s]", _r_locale_getstring (group1_title), group1_count, total_count, _r_locale_getstring (IDS_RULE_FOR_ALL));
@@ -762,6 +683,7 @@ VOID _app_listview_refreshgroups (
_r_listview_setgroup (hwnd, listview_id, 0, buffer1, 0, 0);
_r_listview_setgroup (hwnd, listview_id, 1, buffer2, 0, 0);
+ // set group 3 title
if (group3_title)
{
_r_str_printf (buffer1, RTL_NUMBER_OF (buffer1), L"%s (%d/%d)", _r_locale_getstring (group3_title), group3_count, total_count);
@@ -769,6 +691,7 @@ VOID _app_listview_refreshgroups (
_r_listview_setgroup (hwnd, listview_id, 2, buffer1, 0, 0);
}
+ // set group 4 title
if (group4_title)
{
_r_str_printf (buffer1, RTL_NUMBER_OF (buffer1), L"%s (%d/%d)", _r_locale_getstring (group4_title), group4_count, total_count);
@@ -776,7 +699,7 @@ VOID _app_listview_refreshgroups (
_r_listview_setgroup (hwnd, listview_id, 3, buffer1, 0, 0);
}
- // set group #5 title
+ // set group 5 title
if (group5_title)
{
_r_str_printf (buffer1, RTL_NUMBER_OF (buffer1), L"%s (%d/%d) [silent]", _r_locale_getstring (group5_title), group5_count, total_count);
@@ -792,21 +715,11 @@ VOID _app_listview_resize (
_In_ BOOLEAN is_forced
)
{
+ HDC hdc_listview = NULL, hdc_header = NULL;
+ HWND header = NULL, hlistview;
PR_STRING string;
- HWND hlistview;
- HWND header = NULL;
- HDC hdc_listview = NULL;
- HDC hdc_header = NULL;
LONG column_general_id = 0; // set general column id
- LONG calculated_width = 0;
- LONG column_count;
- LONG column_width;
- LONG total_width;
- LONG item_count;
- LONG text_width;
- LONG dpi_value;
- LONG max_width;
- LONG spacing;
+ LONG calculated_width = 0, column_count, column_width, dpi_value, item_count, spacing, text_width, total_width, max_width;
BOOLEAN is_tableview;
if (!is_forced && !_r_config_getboolean (L"AutoSizeColumns", TRUE, NULL))
@@ -838,8 +751,8 @@ VOID _app_listview_resize (
if (!hdc_header)
goto CleanupExit;
- _r_dc_fixfont (hdc_listview, hwnd, listview_id); // fix font set
- _r_dc_fixfont (hdc_header, header, 0); // fix font set
+ _r_dc_fixfont (hdc_listview, hwnd, listview_id); // fix font!
+ _r_dc_fixfont (hdc_header, header, 0); // fix font!
is_tableview = (_r_listview_getview (hwnd, listview_id) == LV_VIEW_DETAILS);
@@ -851,9 +764,6 @@ VOID _app_listview_resize (
total_width = _r_ctrl_getwidth (hwnd, listview_id);
item_count = _r_listview_getitemcount (hwnd, listview_id);
- if (listview_id == IDC_LOG)
- column_general_id = 1;
-
for (LONG i = 0; i < column_count; i++)
{
if (i == column_general_id)
@@ -901,7 +811,6 @@ VOID _app_listview_resize (
if (text_width >= max_width)
{
column_width = max_width;
-
break;
}
@@ -943,40 +852,17 @@ VOID _app_listview_setview (
)
{
HIMAGELIST himg = NULL;
- LONG view_type;
- LONG icons_size;
+ LONG icons_size, view_type;
BOOLEAN is_mainview;
- is_mainview = (listview_id >= IDC_APPS_PROFILE) && (listview_id <= IDC_RULES_CUSTOM);
+ is_mainview = (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_RULES_CUSTOM);
- if (is_mainview)
- {
- view_type = _r_calc_clamp (_r_config_getlong (L"ViewType", LV_VIEW_DETAILS, NULL), LV_VIEW_ICON, LV_VIEW_MAX);
- }
- else
- {
- view_type = LV_VIEW_DETAILS;
- }
-
- if (is_mainview)
- {
- icons_size = _r_calc_clamp (_r_config_getlong (L"IconSize", SHIL_SMALL, NULL), SHIL_LARGE, SHIL_LAST);
- }
- else
- {
- icons_size = SHIL_SMALL;
- }
+ view_type = is_mainview ? _r_calc_clamp (_r_config_getlong (L"ViewType", LV_VIEW_DETAILS, NULL), LV_VIEW_ICON, LV_VIEW_MAX) : LV_VIEW_DETAILS;
+ icons_size = is_mainview ? _r_calc_clamp (_r_config_getlong (L"IconSize", SHIL_SMALL, NULL), SHIL_LARGE, SHIL_LAST) : SHIL_SMALL;
if ((listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM) || listview_id == IDC_APP_RULES_ID)
{
- if (icons_size == SHIL_SMALL || icons_size == SHIL_SYSSMALL)
- {
- himg = config.himg_rules_small;
- }
- else
- {
- himg = config.himg_rules_large;
- }
+ himg = (icons_size == SHIL_SMALL || icons_size == SHIL_SYSSMALL) ? config.himg_rules_small : config.himg_rules_large;
}
else
{
@@ -995,26 +881,15 @@ INT CALLBACK _app_listview_compare_callback (
_In_ LPARAM lparam
)
{
- PR_STRING item_text_1;
- PR_STRING item_text_2;
- PITEM_LOG ptr_log1;
- PITEM_LOG ptr_log2;
- WCHAR section_name[128];
+ PR_STRING item_text_1, item_text_2;
+ PITEM_LOG ptr_log1, ptr_log2;
+ WCHAR section_name[0x80];
HWND hwnd;
- LONG64 timestamp1 = 0;
- LONG64 timestamp2 = 0;
- ULONG context1;
- ULONG context2;
+ LONG64 timestamp1 = 0, timestamp2 = 0;
+ ULONG context1, context2;
LONG column_id;
- INT listview_id;
- INT result = 0;
- INT item_id1;
- INT item_id2;
- BOOLEAN is_success1;
- BOOLEAN is_success2;
- BOOLEAN is_checked1;
- BOOLEAN is_checked2;
- BOOLEAN is_descend;
+ INT item_id1, item_id2, listview_id, result = 0;
+ BOOLEAN is_checked1, is_checked2, is_descend;
hwnd = GetParent ((HWND)lparam);
@@ -1031,8 +906,8 @@ INT CALLBACK _app_listview_compare_callback (
_r_str_printf (section_name, RTL_NUMBER_OF (section_name), L"listview\\%04" TEXT (PRIX32), listview_id);
- column_id = _r_config_getlong (L"SortColumn", 0, section_name);
is_descend = _r_config_getboolean (L"SortIsDescending", FALSE, section_name);
+ column_id = _r_config_getlong (L"SortColumn", 0, section_name);
if ((_r_listview_getstyle_ex (hwnd, listview_id) & LVS_EX_CHECKBOXES) != 0)
{
@@ -1060,10 +935,8 @@ INT CALLBACK _app_listview_compare_callback (
// timestamp sorting
if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) && column_id == 1)
{
- is_success1 = _app_getappinfobyhash (context1, INFO_TIMESTAMP, ×tamp1, sizeof (LONG64));
- is_success2 = _app_getappinfobyhash (context2, INFO_TIMESTAMP, ×tamp2, sizeof (LONG64));
-
- if (is_success1 && is_success2)
+ if (_app_getappinfobyhash (context1, INFO_TIMESTAMP, ×tamp1, sizeof (LONG64)) &&
+ _app_getappinfobyhash (context2, INFO_TIMESTAMP, ×tamp2, sizeof (LONG64)))
{
if (timestamp1 < timestamp2)
{
@@ -1125,21 +998,20 @@ VOID _app_listview_sort (
_In_ BOOLEAN is_notifycode
)
{
- WCHAR config_name[128];
+ WCHAR config_name[0x80];
HWND hlistview;
INT column_count;
BOOLEAN is_descend;
hlistview = GetDlgItem (hwnd, listview_id);
- if (!hlistview)
- return;
-
- if ((GetWindowLongPtrW (hlistview, GWL_STYLE) & (LVS_NOSORTHEADER | LVS_OWNERDATA)) != 0)
+ // there is no sort header, so don't sort!
+ if ((!hlistview || _r_wnd_getstyle (hlistview, GWL_STYLE) & (LVS_NOSORTHEADER | LVS_OWNERDATA)) != 0)
return;
column_count = _r_listview_getcolumncount (hwnd, listview_id);
+ // there is no columns, so don't sort!
if (!column_count)
return;
@@ -1162,7 +1034,9 @@ VOID _app_listview_sort (
}
for (INT i = 0; i < column_count; i++)
+ {
_r_listview_setcolumnsortindex (hwnd, listview_id, i, 0);
+ }
_r_listview_setcolumnsortindex (hwnd, listview_id, column_id, is_descend ? -1 : 1);
diff --git a/src/listview.h b/src/listview.h
index 58c72cb8..2191f6bc 100644
--- a/src/listview.h
+++ b/src/listview.h
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2016-2025 Henry++
+// Copyright (c) 2016-2026 Henry++
#pragma once
@@ -40,10 +40,6 @@ VOID _app_listview_additems (
_In_ HWND hwnd
);
-VOID _app_listview_clearitems (
- _In_ HWND hwnd
-);
-
VOID _app_listview_addappitem (
_In_ HWND hwnd,
_In_ PITEM_APP ptr_app
@@ -67,15 +63,23 @@ VOID _app_listview_addlogitem (
_In_ ULONG log_hash
);
+VOID _app_listview_clearitems (
+ _In_ HWND hwnd
+);
+
BOOLEAN _app_listview_islocked (
_In_ HWND hwnd,
_In_ INT ctrl_id
);
-VOID _app_listview_lock (
+BOOLEAN _app_listview_lock (
_In_ HWND hwnd,
- _In_ INT ctrl_id,
- _In_ BOOLEAN is_lock
+ _In_ INT ctrl_id
+);
+
+BOOLEAN _app_listview_unlock (
+ _In_ HWND hwnd,
+ _In_ INT ctrl_id
);
LONG_PTR _app_listview_createcontext (
@@ -97,6 +101,7 @@ ULONG _app_listview_getappcontext (
_In_ INT item_id
);
+_Success_ (return != 0)
ULONG_PTR _app_listview_getitemcontext (
_In_ HWND hwnd,
_In_ INT listview_id,
@@ -114,17 +119,11 @@ INT _app_listview_finditem (
_In_ ULONG_PTR id_code
);
-VOID _app_listview_removeitem (
- _In_ HWND hwnd,
- _In_ ULONG_PTR id_code,
- _In_ ENUM_TYPE_DATA type
-);
-
VOID _app_listview_showitemby_id (
_In_ HWND hwnd,
_In_ INT listview_id,
_In_ INT item_id,
- _In_ INT scroll_pos
+ _In_opt_ LONG scroll_pos
);
VOID _app_listview_showitemby_param (
diff --git a/src/log.c b/src/log.c
index 1bbcb104..3714de4a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -7,8 +7,7 @@ VOID _app_loginit (
_In_ BOOLEAN is_install
)
{
- HANDLE current_handle;
- HANDLE new_handle;
+ HANDLE current_handle, new_handle;
PR_STRING log_path;
NTSTATUS status;
@@ -50,18 +49,14 @@ VOID _app_loginitfile (
_r_fs_getsize (NULL, hfile, &file_size);
- if (!file_size)
+ if (file_size == 0)
{
- // write utf-16 le byte order mask
- _r_fs_writefile (hfile, bom, sizeof (bom));
-
- // write csv header
- _r_fs_writefile (hfile, SZ_LOG_TITLE, (ULONG)(_r_str_getlength (SZ_LOG_TITLE) * sizeof (WCHAR)));
+ _r_fs_writefile (hfile, bom, sizeof (bom)); // write utf-16 le byte order mask
+ _r_fs_writefile (hfile, SZ_LOG_TITLE, (ULONG)(_r_str_getlength (SZ_LOG_TITLE) * sizeof (WCHAR))); // write csv header
}
else
{
- // move to eof
- _r_fs_setpos (hfile, file_size);
+ _r_fs_setpos (hfile, file_size); // move to eof
}
}
@@ -69,37 +64,29 @@ ULONG _app_getloghash (
_In_ PITEM_LOG ptr_log
)
{
- PR_STRING string;
- ULONG log_hash;
+ WCHAR buffer[0x100];
- string = _r_format_string (
- L"%" TEXT (PRIu8) L"_%" TEXT (PR_ULONG) L"_%" TEXT (PRIu8) L"_%" \
- TEXT (PRIu8) L"_%" TEXT (PRIu16) L"_%" TEXT (PRIu16) L"_%s_%s_IJAHudm4*^(uaokUH_!&%#!",
+ _r_str_printf (
+ buffer,
+ RTL_NUMBER_OF (buffer),
+ L"%" TEXT (PRIu8) L"_%" TEXT (PR_ULONG) L"_%" TEXT (PRIu8) L"_%" TEXT (PRIu8) L"_%" TEXT (PRIu16) L"_%" TEXT (PRIu16) L"_%s_%s_*#JFS$_(@$)@($+&+_@_LF",
ptr_log->af,
ptr_log->app_hash,
ptr_log->protocol,
ptr_log->direction,
- ptr_log->local_port,
ptr_log->remote_port,
- _r_obj_getstring (ptr_log->local_addr_str),
- _r_obj_getstring (ptr_log->remote_addr_str)
+ ptr_log->local_port,
+ _r_obj_getstring (ptr_log->remote_addr_str),
+ _r_obj_getstring (ptr_log->local_addr_str)
);
- log_hash = _r_str_gethash (&string->sr, TRUE);
-
- _r_obj_dereference (string);
-
- return log_hash;
+ return _r_str_gethash2 (buffer, TRUE);
}
_Ret_maybenull_
PR_STRING _app_getlogpath ()
{
- PR_STRING path;
-
- path = _r_config_getstringexpand (L"LogPath", LOG_PATH_DEFAULT, NULL);
-
- return path;
+ return _r_config_getstringexpand (L"LogPath", LOG_PATH_DEFAULT, NULL);
}
_Ret_maybenull_
@@ -117,7 +104,7 @@ PR_STRING _app_getlogviewer ()
_r_obj_initializestringref (&sr, LOG_VIEWER_DEFAULT);
- _r_str_environmentexpandstring (NULL, &sr, &path);
+ _r_str_environmentexpandstring (&path, NULL, &sr);
}
return path;
@@ -140,8 +127,7 @@ BOOLEAN _app_logislimitreached (
_In_ HANDLE hfile
)
{
- LONG64 file_size;
- LONG64 limit;
+ LONG64 file_size, limit;
limit = _r_config_getlong64 (L"LogSizeLimitKb", LOG_SIZE_LIMIT_DEFAULT, NULL);
@@ -195,12 +181,7 @@ VOID _app_logwrite (
_In_ PITEM_LOG ptr_log
)
{
- PR_STRING remote_port_string;
- PR_STRING local_port_string;
- PR_STRING direction_string;
- PR_STRING date_string;
- PR_STRING path = NULL;
- PR_STRING buffer;
+ PR_STRING buffer, date_string, direction_string, local_port_string, remote_port_string, path = NULL;
PITEM_APP ptr_app;
HANDLE current_handle;
@@ -214,17 +195,17 @@ VOID _app_logwrite (
if (ptr_app)
{
- path = _app_getapppath (ptr_app, _r_config_getboolean (L"IsShortPath", TRUE, NULL));
+ path = _app_getapppath (ptr_app);
_r_obj_dereference (ptr_app);
}
+ direction_string = _app_db_getdirectionname (ptr_log->direction, ptr_log->is_loopback, FALSE);
+
date_string = _r_format_unixtime (ptr_log->timestamp, FDTF_SHORTDATE | FDTF_LONGTIME);
- local_port_string = _app_formatport (ptr_log->local_port, ptr_log->protocol);
remote_port_string = _app_formatport (ptr_log->remote_port, ptr_log->protocol);
-
- direction_string = _app_db_getdirectionname (ptr_log->direction, ptr_log->is_loopback, FALSE);
+ local_port_string = _app_formatport (ptr_log->local_port, ptr_log->protocol);
buffer = _r_format_string (
SZ_LOG_BODY,
@@ -232,14 +213,14 @@ VOID _app_logwrite (
_r_obj_getstringordefault (ptr_log->username, _r_locale_getstring (IDS_STATUS_EMPTY)),
_r_obj_getstringordefault (path, _r_locale_getstring (IDS_STATUS_EMPTY)),
_r_obj_getstringordefault (ptr_log->local_addr_str, _r_locale_getstring (IDS_STATUS_EMPTY)),
- local_port_string->buffer,
+ _r_obj_getstringordefault (local_port_string, L""),
_r_obj_getstringordefault (ptr_log->remote_addr_str, _r_locale_getstring (IDS_STATUS_EMPTY)),
- remote_port_string->buffer,
+ _r_obj_getstringordefault (remote_port_string, L""),
_r_obj_getstringordefault (ptr_log->protocol_str, SZ_DIRECTION_ANY),
- _r_obj_getstringordefault (ptr_log->layer_name, _r_locale_getstring (IDS_STATUS_EMPTY)),
- _r_obj_getstringordefault (ptr_log->filter_name, _r_locale_getstring (IDS_STATUS_EMPTY)),
+ _r_obj_getstringordefault (ptr_log->layer_name, L""),
+ _r_obj_getstringordefault (ptr_log->filter_name, L""),
ptr_log->filter_id,
- _r_obj_getstringordefault (direction_string, _r_locale_getstring (IDS_STATUS_EMPTY)),
+ _r_obj_getstringordefault (direction_string, L""),
(ptr_log->is_allow ? SZ_STATE_ALLOW : SZ_STATE_BLOCK)
);
@@ -248,12 +229,12 @@ VOID _app_logwrite (
_r_fs_writefile (current_handle, buffer->buffer, (ULONG)buffer->length);
- if (date_string)
- _r_obj_dereference (date_string);
-
if (direction_string)
_r_obj_dereference (direction_string);
+ if (date_string)
+ _r_obj_dereference (date_string);
+
if (path)
_r_obj_dereference (path);
@@ -269,8 +250,7 @@ VOID _app_logwrite_ui (
)
{
ULONG_PTR table_size;
- ULONG log_hash;
- ULONG hash_code;
+ ULONG hash_code, log_hash;
INT item_id;
log_hash = _app_getloghash (ptr_log);
@@ -326,10 +306,8 @@ VOID _wfp_logsubscribe (
FWPM_NET_EVENT_ENUM_TEMPLATE0 enum_template = {0};
FWPM_NET_EVENT_SUBSCRIPTION0 subscription = {0};
- HANDLE new_handle = NULL;
- HANDLE current_handle;
- PVOID hfwpuclnt;
- BOOLEAN is_success = FALSE;
+ HANDLE current_handle, new_handle = NULL;
+ HINSTANCE hfwpuclnt;
NTSTATUS status;
current_handle = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnetevent, NULL, NULL);
@@ -348,7 +326,7 @@ VOID _wfp_logsubscribe (
_FwpmNetEventSubscribe2 = (FWPMNES2)_r_sys_getprocaddress (hfwpuclnt, "FwpmNetEventSubscribe2", 0);
_FwpmNetEventSubscribe1 = (FWPMNES1)_r_sys_getprocaddress (hfwpuclnt, "FwpmNetEventSubscribe1", 0);
- _r_sys_freelibrary (hfwpuclnt);
+ //_r_sys_freelibrary (hfwpuclnt);
}
else
{
@@ -365,52 +343,34 @@ VOID _wfp_logsubscribe (
_r_initonce_end (&init_once);
}
- subscription.enumTemplate = &enum_template;
subscription.sessionKey = config.session_key;
+ subscription.enumTemplate = &enum_template;
- // win10rs3+
- if (!is_success && _FwpmNetEventSubscribe4)
- {
+ status = ERROR_SERVICE_NOT_ACTIVE;
+
+ // win10rs5+
+ if (_FwpmNetEventSubscribe4)
status = _FwpmNetEventSubscribe4 (engine_handle, &subscription, &_wfp_logcallback4, NULL, &new_handle);
- is_success = (status == STATUS_SUCCESS);
- }
-
- // win10rs1+
- if (!is_success && _FwpmNetEventSubscribe3)
- {
+ // win10rs4+
+ if ((status != ERROR_SUCCESS) && _FwpmNetEventSubscribe3)
status = _FwpmNetEventSubscribe3 (engine_handle, &subscription, &_wfp_logcallback3, NULL, &new_handle);
- is_success = (status == STATUS_SUCCESS);
- }
-
- // win10rs1+
- if (!is_success && _FwpmNetEventSubscribe2)
- {
+ // win10th1+
+ if ((status != ERROR_SUCCESS) && _FwpmNetEventSubscribe2)
status = _FwpmNetEventSubscribe2 (engine_handle, &subscription, &_wfp_logcallback2, NULL, &new_handle);
- is_success = (status == STATUS_SUCCESS);
- }
-
// win8+
- if (!is_success && _FwpmNetEventSubscribe1)
- {
+ if ((status != ERROR_SUCCESS) && _FwpmNetEventSubscribe1)
status = _FwpmNetEventSubscribe1 (engine_handle, &subscription, &_wfp_logcallback1, NULL, &new_handle);
- is_success = (status == STATUS_SUCCESS);
- }
-
// win7+
- if (!is_success)
- {
+ if (status != ERROR_SUCCESS)
status = FwpmNetEventSubscribe0 (engine_handle, &subscription, &_wfp_logcallback0, NULL, &new_handle);
- is_success = (status == STATUS_SUCCESS);
- }
-
- if (!is_success)
+ if (status != ERROR_SUCCESS)
{
- if (hwnd && status != ERROR_PATH_NOT_FOUND)
+ if (hwnd)
{
_r_show_errormessage (hwnd, L"Log subscribe failed. Try again later!", status, NULL, ET_WINDOWS);
}
@@ -420,9 +380,9 @@ VOID _wfp_logsubscribe (
}
}
- _r_toolbar_enablebutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLENOTIFICATIONS_CHK, is_success);
- _r_toolbar_enablebutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLELOG_CHK, is_success);
- _r_toolbar_enablebutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLEUILOG_CHK, is_success);
+ _r_toolbar_enablebutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLENOTIFICATIONS_CHK, (status == ERROR_SUCCESS));
+ _r_toolbar_enablebutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLEUILOG_CHK, (status == ERROR_SUCCESS));
+ _r_toolbar_enablebutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLELOG_CHK, (status == ERROR_SUCCESS));
current_handle = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnetevent, new_handle, NULL);
@@ -469,22 +429,19 @@ VOID _wfp_logsetoption (
if (!_r_sys_isosversiongreaterorequal (WINDOWS_8))
return;
- // add allowed connections monitor
- if (!_r_config_getboolean (L"IsExcludeClassifyAllow", TRUE, NULL))
- mask |= FWPM_NET_EVENT_KEYWORD_CLASSIFY_ALLOW;
-
// add inbound multicast and broadcast connections monitor
if (!_r_config_getboolean (L"IsExcludeInbound", FALSE, NULL))
mask |= FWPM_NET_EVENT_KEYWORD_INBOUND_MCAST | FWPM_NET_EVENT_KEYWORD_INBOUND_BCAST;
- // add port scanning drop connections monitor (19H1+)
- if (_r_sys_isosversiongreaterorequal (WINDOWS_10_19H1))
- {
- if (!_r_config_getboolean (L"IsExcludePortScanningDrop", FALSE, NULL))
- mask |= FWPM_NET_EVENT_KEYWORD_PORT_SCANNING_DROP;
- }
+ // add allowed connections monitor
+ if (!_r_config_getboolean (L"IsExcludeClassifyAllow", TRUE, NULL))
+ mask |= FWPM_NET_EVENT_KEYWORD_CLASSIFY_ALLOW;
- // the filter engine will collect wfp network events that match any supplied key words
+ // add port scanning drop connections monitor (win10 19H1+)
+ if (_r_sys_isosversiongreaterorequal (WINDOWS_10_19H1) && !_r_config_getboolean (L"IsExcludePortScanningDrop", FALSE, NULL))
+ mask |= FWPM_NET_EVENT_KEYWORD_PORT_SCANNING_DROP;
+
+ // the filter engine will collect WFP network events that match any supplied key words
RtlZeroMemory (&val, sizeof (FWP_VALUE0));
val.type = FWP_UINT32;
@@ -511,36 +468,36 @@ VOID CALLBACK _wfp_logcallback (
_In_ PITEM_LOG_CALLBACK log
)
{
- HANDLE engine_handle;
+ PR_STRING filter_name = NULL, layer_name, path, sid_string = NULL;
+ FWPM_FILTER0 *filter_ptr = NULL;
+ FWPM_LAYER0 *layer_ptr = NULL;
PITEM_LOG ptr_log;
+ WCHAR buffer[0x80];
GUID layer_guid;
- PR_STRING filter_name = NULL;
- PR_STRING sid_string = NULL;
- PR_STRING resolved_path;
- PR_STRING layer_name;
- PR_STRING path;
- FWPM_FILTER0 *filter_ptr;
- FWPM_LAYER0 *layer_ptr;
- UINT8 filter_weight = 0;
+ ULONG filter_weight = 0;
BOOLEAN is_myprovider = FALSE;
- NTSTATUS status;
+ ULONG status;
- if (!log->filter_id || !log->layer_id)
+ if ((log->filter_id) == 0 || (log->layer_id) == 0)
return;
if (log->is_allow && _r_config_getboolean (L"IsExcludeClassifyAllow", TRUE, NULL))
return;
- engine_handle = _wfp_getenginehandle ();
+ status = FwpmLayerGetById0 (_wfp_getenginehandle (), log->layer_id, &layer_ptr);
+
+ if (status != ERROR_SUCCESS || !layer_ptr)
+ {
+ if (status != ERROR_SUCCESS && status != FWP_E_LAYER_NOT_FOUND)
+ _r_log (LOG_LEVEL_WARNING, NULL, L"FwpmLayerGetById0", status, NULL);
- // do not parse when tcp connection has been established, or when non-tcp traffic has been authorized
- if (FwpmLayerGetById0 (engine_handle, log->layer_id, &layer_ptr) != ERROR_SUCCESS || !layer_ptr)
return;
+ }
+ // do not process when tcp connection has been established, or when non-tcp traffic has been authorized
if (IsEqualGUID (&layer_ptr->layerKey, &FWPM_LAYER_ALE_FLOW_ESTABLISHED_V4) || IsEqualGUID (&layer_ptr->layerKey, &FWPM_LAYER_ALE_FLOW_ESTABLISHED_V6))
{
FwpmFreeMemory0 ((PVOID_PTR)&layer_ptr);
-
return;
}
@@ -552,8 +509,15 @@ VOID CALLBACK _wfp_logcallback (
FwpmFreeMemory0 ((PVOID_PTR)&layer_ptr);
// get filter information
- if (FwpmFilterGetById0 (engine_handle, log->filter_id, &filter_ptr) != ERROR_SUCCESS || !filter_ptr)
+ status = FwpmFilterGetById0 (_wfp_getenginehandle (), log->filter_id, &filter_ptr);
+
+ if (status != ERROR_SUCCESS || !filter_ptr) // stupid M$ returns NULL filter_ptr when status is ERROR_SUCCESS (LOGIC over 9999)! without Billy they lose everything, stupid fucking cunts!
+ {
+ if (status != ERROR_SUCCESS && status != FWP_E_FILTER_NOT_FOUND)
+ _r_log (LOG_LEVEL_WARNING, NULL, L"FwpmFilterGetById0", status, NULL);
+
return;
+ }
layer_name = _wfp_getlayername (&layer_guid);
@@ -567,7 +531,21 @@ VOID CALLBACK _wfp_logcallback (
}
if (filter_ptr->weight.type == FWP_UINT8)
- filter_weight = filter_ptr->weight.uint8;
+ {
+ filter_weight = (ULONG)(filter_ptr->weight.uint8);
+ }
+ else if (filter_ptr->weight.type == FWP_UINT16)
+ {
+ filter_weight = (ULONG)(filter_ptr->weight.uint16);
+ }
+ else if (filter_ptr->weight.type == FWP_UINT32)
+ {
+ filter_weight = (ULONG)(filter_ptr->weight.uint32);
+ }
+ //else if (filter_ptr->weight.type == FWP_UINT64)
+ //{
+ // filter_weight = (ULONG)*(filter_ptr->weight.uint64);
+ //}
if (filter_ptr->providerKey)
{
@@ -578,7 +556,7 @@ VOID CALLBACK _wfp_logcallback (
FwpmFreeMemory0 ((PVOID_PTR)&filter_ptr);
// allocate log object
- ptr_log = _r_obj_allocate (sizeof (ITEM_LOG), &_app_dereferencelog);
+ ptr_log = (PITEM_LOG)_r_obj_allocate (sizeof (ITEM_LOG), &_app_dereferencelog);
// copy date and time
ptr_log->timestamp = _r_unixtime_from_filetime (&log->timestamp);
@@ -596,9 +574,7 @@ VOID CALLBACK _wfp_logcallback (
// get package id (win8+)
if ((log->flags & FWPM_NET_EVENT_FLAG_PACKAGE_ID_SET) == FWPM_NET_EVENT_FLAG_PACKAGE_ID_SET && log->package_id)
{
- status = _r_str_fromsid (&sid_string, log->package_id);
-
- if (NT_SUCCESS (status))
+ if (NT_SUCCESS (_r_str_fromsid (&sid_string, log->package_id)))
{
if (!_app_package_isnotexists (sid_string))
_r_obj_clearreference ((PVOID_PTR)&sid_string);
@@ -616,17 +592,11 @@ VOID CALLBACK _wfp_logcallback (
{
path = _r_obj_createstring ((LPCWSTR)(log->app_id));
- resolved_path = _r_path_dospathfromnt (&path->sr);
+ _r_obj_movereference ((PVOID_PTR)&ptr_log->path, _r_path_dospathfromnt (&path->sr));
- if (resolved_path)
- _r_obj_movereference ((PVOID_PTR)&path, resolved_path);
+ ptr_log->app_hash = _r_str_gethash (&ptr_log->path->sr, TRUE);
- if (path)
- {
- _r_obj_movereference ((PVOID_PTR)&ptr_log->path, path);
-
- ptr_log->app_hash = _r_str_gethash (&ptr_log->path->sr, TRUE);
- }
+ _r_obj_dereference (path);
}
else
{
@@ -644,14 +614,13 @@ VOID CALLBACK _wfp_logcallback (
{
ptr_log->af = AF_INET;
- // local address
- if ((log->flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- ptr_log->local_addr.S_un.S_addr = _r_byteswap_ulong ((ULONG)log->local_addr4);
-
// remote address
if ((log->flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
- ptr_log->remote_addr.S_un.S_addr = _r_byteswap_ulong ((ULONG)log->remote_addr4);
+ ptr_log->remote_addr.S_un.S_addr = _r_byteswap_ulong (log->remote_addr4);
+ // local address
+ if ((log->flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ ptr_log->local_addr.S_un.S_addr = _r_byteswap_ulong (log->local_addr4);
}
else if (log->version == FWP_IP_VERSION_V6)
{
@@ -665,42 +634,48 @@ VOID CALLBACK _wfp_logcallback (
if ((log->flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET && log->local_addr6)
RtlCopyMemory (ptr_log->local_addr6.u.Byte, log->local_addr6->byteArray16, FWP_V6_ADDR_SIZE);
}
+ else
+ {
+ //ptr_log->af = ;
+ }
}
// ports
- if ((log->flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
- ptr_log->local_port = log->local_port;
-
if ((log->flags & FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET) == FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET)
ptr_log->remote_port = log->remote_port;
+ if ((log->flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
+ ptr_log->local_port = log->local_port;
+
// protocol
if ((log->flags & FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET) == FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET)
{
ptr_log->protocol = log->protocol;
- ptr_log->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_log->protocol, ptr_log->af));
- }
+ _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L" (% " TEXT (PRIu8) L")", ptr_log->protocol);
- // indicates FWPM_NET_EVENT_TYPE_CLASSIFY_ALLOW state
- ptr_log->is_allow = log->is_allow;
+ ptr_log->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_log->protocol, ptr_log->af, buffer));
+ }
// indicates whether the packet originated from (or was heading to) the loopback adapter
ptr_log->is_loopback = log->is_loopback;
+ // indicates FWPM_NET_EVENT_TYPE_CLASSIFY_ALLOW state
+ ptr_log->is_allow = log->is_allow;
+
// set filter information
+ ptr_log->is_custom = (filter_weight == FWW_RULE_USER) || (filter_weight == FWW_RULE_USER_BLOCK);
+ ptr_log->is_system = (filter_weight == FWW_HIGHEST) || (filter_weight == FWW_IMPORTANT);
+ ptr_log->is_blocklist = (filter_weight == FWW_RULE_BLOCKLIST);
+
+ ptr_log->direction = (FWP_DIRECTION)log->direction;
ptr_log->filter_id = log->filter_id;
- ptr_log->direction = log->direction;
ptr_log->is_myprovider = is_myprovider;
ptr_log->filter_name = filter_name;
ptr_log->layer_name = layer_name;
- ptr_log->is_blocklist = (filter_weight == FW_WEIGHT_RULE_BLOCKLIST);
- ptr_log->is_system = (filter_weight == FW_WEIGHT_HIGHEST) || (filter_weight == FW_WEIGHT_HIGHEST_IMPORTANT);
- ptr_log->is_custom = (filter_weight == FW_WEIGHT_RULE_USER) || (filter_weight == FW_WEIGHT_RULE_USER_BLOCK);
-
_r_workqueue_queueitem (&log_queue, &_app_logthread, ptr_log);
if (sid_string)
@@ -717,9 +692,9 @@ FORCEINLINE BOOLEAN log_struct_to_f (
switch (version)
{
- case WINDOWS_10_RS3:
+ case WINDOWS_10_RS5:
{
- const FWPM_NET_EVENT5 *evt = event_data;
+ const FWPM_NET_EVENT5 *evt = (const FWPM_NET_EVENT5*)event_data;
if (evt->type == FWPM_NET_EVENT_TYPE_CLASSIFY_DROP && evt->classifyDrop)
{
@@ -789,36 +764,40 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->package_id = evt->header.packageSid;
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_USER_ID_SET) == FWPM_NET_EVENT_FLAG_USER_ID_SET)
- log->user_id = evt->header.userId;
+ log->user_id = (PSID)(evt->header.userId);
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET) == FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET)
log->protocol = evt->header.ipProtocol;
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
- log->local_port = evt->header.localPort;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET) == FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET)
log->remote_port = evt->header.remotePort;
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
+ log->local_port = evt->header.localPort;
+
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_VERSION_SET) == FWPM_NET_EVENT_FLAG_IP_VERSION_SET)
{
log->version = evt->header.ipVersion;
if (evt->header.ipVersion == FWP_IP_VERSION_V4)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr4 = evt->header.localAddrV4;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr4 = evt->header.remoteAddrV4;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr4 = evt->header.localAddrV4;
}
else if (evt->header.ipVersion == FWP_IP_VERSION_V6)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr6 = &evt->header.localAddrV6;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr6 = &evt->header.remoteAddrV6;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr6 = &evt->header.localAddrV6;
+ }
+ else
+ {
+ log->version = FWP_IP_VERSION_NONE;
}
}
else
@@ -826,10 +805,10 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->version = FWP_IP_VERSION_NONE;
}
- break;
+ return TRUE;
}
- case WINDOWS_10_RS1:
+ case WINDOWS_10_RS4:
{
const FWPM_NET_EVENT4 *evt = (const FWPM_NET_EVENT4*)event_data;
@@ -901,36 +880,40 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->package_id = evt->header.packageSid;
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_USER_ID_SET) == FWPM_NET_EVENT_FLAG_USER_ID_SET)
- log->user_id = evt->header.userId;
+ log->user_id = (PSID)(evt->header.userId);
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET) == FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET)
log->protocol = evt->header.ipProtocol;
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
- log->local_port = evt->header.localPort;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET) == FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET)
log->remote_port = evt->header.remotePort;
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
+ log->local_port = evt->header.localPort;
+
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_VERSION_SET) == FWPM_NET_EVENT_FLAG_IP_VERSION_SET)
{
log->version = evt->header.ipVersion;
if (evt->header.ipVersion == FWP_IP_VERSION_V4)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr4 = evt->header.localAddrV4;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr4 = evt->header.remoteAddrV4;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr4 = evt->header.localAddrV4;
}
else if (evt->header.ipVersion == FWP_IP_VERSION_V6)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr6 = &evt->header.localAddrV6;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr6 = &evt->header.remoteAddrV6;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr6 = &evt->header.localAddrV6;
+ }
+ else
+ {
+ log->version = FWP_IP_VERSION_NONE;
}
}
else
@@ -938,12 +921,12 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->version = FWP_IP_VERSION_NONE;
}
- break;
+ return TRUE;
}
- case WINDOWS_10_RS2:
+ case WINDOWS_10_TH1:
{
- const FWPM_NET_EVENT3 *evt = event_data;
+ const FWPM_NET_EVENT3 *evt = (const FWPM_NET_EVENT3*)event_data;
if (evt->type == FWPM_NET_EVENT_TYPE_CLASSIFY_DROP && evt->classifyDrop)
{
@@ -1013,36 +996,40 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->package_id = evt->header.packageSid;
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_USER_ID_SET) == FWPM_NET_EVENT_FLAG_USER_ID_SET)
- log->user_id = evt->header.userId;
+ log->user_id = (PSID)(evt->header.userId);
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET) == FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET)
log->protocol = evt->header.ipProtocol;
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
- log->local_port = evt->header.localPort;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET) == FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET)
log->remote_port = evt->header.remotePort;
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
+ log->local_port = evt->header.localPort;
+
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_VERSION_SET) == FWPM_NET_EVENT_FLAG_IP_VERSION_SET)
{
log->version = evt->header.ipVersion;
if (evt->header.ipVersion == FWP_IP_VERSION_V4)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr4 = evt->header.localAddrV4;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr4 = evt->header.remoteAddrV4;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr4 = evt->header.localAddrV4;
}
else if (evt->header.ipVersion == FWP_IP_VERSION_V6)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr6 = &evt->header.localAddrV6;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr6 = &evt->header.remoteAddrV6;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr6 = &evt->header.localAddrV6;
+ }
+ else
+ {
+ log->version = FWP_IP_VERSION_NONE;
}
}
else
@@ -1050,12 +1037,12 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->version = FWP_IP_VERSION_NONE;
}
- break;
+ return TRUE;
}
case WINDOWS_8:
{
- const FWPM_NET_EVENT2 *evt = event_data;
+ const FWPM_NET_EVENT2 *evt = (const FWPM_NET_EVENT2*)event_data;
if (evt->type == FWPM_NET_EVENT_TYPE_CLASSIFY_DROP && evt->classifyDrop)
{
@@ -1125,36 +1112,40 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->package_id = evt->header.packageSid;
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_USER_ID_SET) == FWPM_NET_EVENT_FLAG_USER_ID_SET)
- log->user_id = evt->header.userId;
+ log->user_id = (PSID)(evt->header.userId);
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET) == FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET)
log->protocol = evt->header.ipProtocol;
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
- log->local_port = evt->header.localPort;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET) == FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET)
log->remote_port = evt->header.remotePort;
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
+ log->local_port = evt->header.localPort;
+
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_VERSION_SET) == FWPM_NET_EVENT_FLAG_IP_VERSION_SET)
{
log->version = evt->header.ipVersion;
if (evt->header.ipVersion == FWP_IP_VERSION_V4)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr4 = evt->header.localAddrV4;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr4 = evt->header.remoteAddrV4;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr4 = evt->header.localAddrV4;
}
else if (evt->header.ipVersion == FWP_IP_VERSION_V6)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr6 = &evt->header.localAddrV6;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr6 = &evt->header.remoteAddrV6;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr6 = &evt->header.localAddrV6;
+ }
+ else
+ {
+ log->version = FWP_IP_VERSION_NONE;
}
}
else
@@ -1162,12 +1153,12 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->version = FWP_IP_VERSION_NONE;
}
- break;
+ return TRUE;
}
case WINDOWS_7:
{
- const FWPM_NET_EVENT1 *evt = event_data;
+ const FWPM_NET_EVENT1 *evt = (const FWPM_NET_EVENT1*)event_data;
if (evt->type == FWPM_NET_EVENT_TYPE_CLASSIFY_DROP && evt->classifyDrop)
{
@@ -1218,36 +1209,40 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->app_id = evt->header.appId.data;
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_USER_ID_SET) == FWPM_NET_EVENT_FLAG_USER_ID_SET)
- log->user_id = evt->header.userId;
+ log->user_id = (PSID)(evt->header.userId);
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET) == FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET)
log->protocol = evt->header.ipProtocol;
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
- log->local_port = evt->header.localPort;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET) == FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET)
log->remote_port = evt->header.remotePort;
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET) == FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET)
+ log->local_port = evt->header.localPort;
+
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_IP_VERSION_SET) == FWPM_NET_EVENT_FLAG_IP_VERSION_SET)
{
log->version = evt->header.ipVersion;
if (evt->header.ipVersion == FWP_IP_VERSION_V4)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr4 = evt->header.localAddrV4;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr4 = evt->header.remoteAddrV4;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr4 = evt->header.localAddrV4;
}
else if (evt->header.ipVersion == FWP_IP_VERSION_V6)
{
- if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
- log->local_addr6 = &evt->header.localAddrV6;
-
if ((evt->header.flags & FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET) == FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET)
log->remote_addr6 = &evt->header.remoteAddrV6;
+
+ if ((evt->header.flags & FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET) == FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET)
+ log->local_addr6 = &evt->header.localAddrV6;
+ }
+ else
+ {
+ log->version = FWP_IP_VERSION_NONE;
}
}
else
@@ -1255,16 +1250,16 @@ FORCEINLINE BOOLEAN log_struct_to_f (
log->version = FWP_IP_VERSION_NONE;
}
- break;
+ return TRUE;
}
default:
{
+ _r_log (LOG_LEVEL_INFO, NULL, TEXT (__FUNCTION__), STATUS_UNKNOWN_REVISION, NULL);
+
return FALSE;
}
}
-
- return TRUE;
}
// win7+ callback
@@ -1291,7 +1286,7 @@ VOID CALLBACK _wfp_logcallback1 (
_wfp_logcallback (&log);
}
-// win10rs1+ callback
+// win10th1+ callback
VOID CALLBACK _wfp_logcallback2 (
_Inout_ PVOID context,
_In_ const FWPM_NET_EVENT3* event_data
@@ -1299,11 +1294,11 @@ VOID CALLBACK _wfp_logcallback2 (
{
ITEM_LOG_CALLBACK log;
- if (log_struct_to_f (&log, WINDOWS_10_RS1, event_data))
+ if (log_struct_to_f (&log, WINDOWS_10_TH1, event_data))
_wfp_logcallback (&log);
}
-// win10rs1+ callback
+// win10rs4+ callback
VOID CALLBACK _wfp_logcallback3 (
_Inout_ PVOID context,
_In_ const FWPM_NET_EVENT4* event_data
@@ -1311,11 +1306,11 @@ VOID CALLBACK _wfp_logcallback3 (
{
ITEM_LOG_CALLBACK log;
- if (log_struct_to_f (&log, WINDOWS_10_RS2, event_data))
+ if (log_struct_to_f (&log, WINDOWS_10_RS4, event_data))
_wfp_logcallback (&log);
}
-// win10rs3+ callback
+// win10rs5+ callback
VOID CALLBACK _wfp_logcallback4 (
_Inout_ PVOID context,
_In_ const FWPM_NET_EVENT5* event_data
@@ -1323,7 +1318,7 @@ VOID CALLBACK _wfp_logcallback4 (
{
ITEM_LOG_CALLBACK log;
- if (log_struct_to_f (&log, WINDOWS_10_RS3, event_data))
+ if (log_struct_to_f (&log, WINDOWS_10_RS5, event_data))
_wfp_logcallback (&log);
}
@@ -1334,31 +1329,24 @@ VOID NTAPI _app_logthread (
PITEM_APP ptr_app = NULL;
PITEM_LOG ptr_log;
HWND hwnd;
- BOOLEAN is_notificationenabled;
- BOOLEAN is_exludeblocklist;
- BOOLEAN is_exludestealth;
- BOOLEAN is_loguienabled;
- BOOLEAN is_exludeallow;
- BOOLEAN is_silent = FALSE;
- BOOLEAN is_logenabled;
- BOOLEAN is_notexist;
+ BOOLEAN is_exludeallow, is_exludeblocklist, is_exludestealth, is_logenabled, is_loguienabled, is_notexist, is_notificationenabled, is_silent = FALSE;
hwnd = _r_app_gethwnd ();
- ptr_log = arglist;
+ ptr_log = (PITEM_LOG)arglist;
// apps collector
is_notexist = ptr_log->app_hash && !ptr_log->is_allow && !_app_isappfound (ptr_log->app_hash);
if (is_notexist)
{
- ptr_log->app_hash = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_log->path, NULL, NULL);
+ ptr_app = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_log->path, NULL, NULL);
- if (ptr_log->app_hash)
+ if (ptr_app)
{
- ptr_app = _app_getappitem (ptr_log->app_hash);
+ ptr_log->app_hash = ptr_app->app_hash;
- if (ptr_app)
+ if (hwnd)
_app_listview_updateby_id (hwnd, ptr_app->type, PR_UPDATE_TYPE);
_app_profile_save (hwnd);
@@ -1368,9 +1356,9 @@ VOID NTAPI _app_logthread (
if (!ptr_app)
ptr_app = _app_getappitem (ptr_log->app_hash);
- is_logenabled = _r_config_getboolean (L"IsLogEnabled", FALSE, NULL);
- is_loguienabled = _r_config_getboolean (L"IsLogUiEnabled", FALSE, NULL);
is_notificationenabled = _r_config_getboolean (L"IsNotificationsEnabled", TRUE, NULL);
+ is_loguienabled = _r_config_getboolean (L"IsLogUiEnabled", FALSE, NULL);
+ is_logenabled = _r_config_getboolean (L"IsLogEnabled", FALSE, NULL);
is_exludeallow = !(ptr_log->is_allow && _r_config_getboolean (L"IsExcludeClassifyAllow", TRUE, NULL));
is_exludestealth = !(ptr_log->is_system && _r_config_getboolean (L"IsExcludeStealth", TRUE, NULL));
@@ -1384,29 +1372,19 @@ VOID NTAPI _app_logthread (
ptr_log->local_addr_str = _app_formataddress (ptr_log->af, ptr_log->protocol, &ptr_log->local_addr, 0, 0);
// display notification
- if (is_notificationenabled)
+ if (is_notificationenabled && ptr_app && !ptr_log->is_allow && is_exludeblocklist)
{
- if (ptr_app && !ptr_log->is_allow && is_exludeblocklist)
- {
- if (_app_getappinfo (ptr_app, INFO_IS_SILENT, &is_silent, sizeof (BOOLEAN)))
- {
- if (!is_silent)
- _app_notify_addobject (hwnd, ptr_log, ptr_app);
- }
- }
+ if (_app_getappinfo (ptr_app, INFO_IS_SILENT, &is_silent, sizeof (BOOLEAN)) && !is_silent)
+ _app_notify_addobject (hwnd, ptr_log, ptr_app);
}
// write log to a file
if (is_logenabled)
_app_logwrite (ptr_log);
- // only for my own provider
- if (ptr_log->is_myprovider)
- {
- // write log to a ui
- if (is_loguienabled)
- _app_logwrite_ui (hwnd, ptr_log); // write to a ui
- }
+ // only for my own provider write log to a ui
+ if (ptr_log->is_myprovider && is_loguienabled)
+ _app_logwrite_ui (hwnd, ptr_log);
}
if (ptr_app)
diff --git a/src/log.h b/src/log.h
index 52759808..0355f39d 100644
--- a/src/log.h
+++ b/src/log.h
@@ -21,7 +21,7 @@ typedef ULONG (WINAPI *FWPMNES3)(
_Out_ PHANDLE events_handle
);
-// FwpmNetEventSubscribe2 (win10rs1+)
+// FwpmNetEventSubscribe2 (win10th1+)
typedef ULONG (WINAPI *FWPMNES2)(
_In_ HANDLE engine_handle,
_In_ const FWPM_NET_EVENT_SUBSCRIPTION0 *subscription,
@@ -117,7 +117,7 @@ VOID CALLBACK _wfp_logcallback2 (
_In_ const FWPM_NET_EVENT3* event_data
);
-// win10rs4+ callback
+// win10rs2+ callback
VOID CALLBACK _wfp_logcallback3 (
_Inout_ PVOID context,
_In_ const FWPM_NET_EVENT4* event_data
diff --git a/src/main.c b/src/main.c
index 5a11b9a5..632cc64a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -23,7 +23,7 @@ BOOLEAN _app_changefilters (
{
_app_initinterfacestate (hwnd, TRUE);
- context = _r_freelist_allocateitem (&context_free_list);
+ context = (PITEM_CONTEXT)_r_freelist_allocateitem (&context_free_list);
context->hwnd = hwnd;
context->is_install = is_install;
@@ -46,16 +46,9 @@ BOOLEAN _app_installmessage (
)
{
TASKDIALOGCONFIG tdc = {0};
- WCHAR str_main[256];
- WCHAR radio_text_1[128];
- WCHAR radio_text_2[128];
- WCHAR str_flag[128];
- WCHAR str_button_text_1[64];
- WCHAR str_button_text_2[64];
- TASKDIALOG_BUTTON td_buttons[2] = {0};
- TASKDIALOG_BUTTON td_radios[2] = {0};
- INT command_id;
- INT radio_id;
+ WCHAR str_button_text_1[0x40], str_button_text_2[0x40], str_flag[0x80], str_main[0x100], radio_text_1[0x80], radio_text_2[0x80];
+ TASKDIALOG_BUTTON td_buttons[2] = {0}, td_radios[2] = {0};
+ INT command_id, radio_id;
BOOL is_flagchecked;
HRESULT status;
@@ -66,7 +59,7 @@ BOOLEAN _app_installmessage (
tdc.pszMainIcon = is_install ? TD_INFORMATION_ICON : TD_WARNING_ICON;
//tdc.dwCommonButtons = TDCBF_YES_BUTTON | TDCBF_NO_BUTTON;
tdc.pfCallback = &_r_msg_callback;
- tdc.lpCallbackData = MAKELONG (0, TRUE); // on top
+ tdc.nDefaultButton = IDYES;
if (_r_config_getboolean (L"WF_State", TRUE, NULL))
tdc.dwFlags |= TDF_VERIFICATION_FLAG_CHECKED;
@@ -74,14 +67,7 @@ BOOLEAN _app_installmessage (
tdc.pButtons = td_buttons;
tdc.cButtons = RTL_NUMBER_OF (td_buttons);
- tdc.nDefaultButton = IDYES;
-
- _r_str_copy (
- str_button_text_1,
- RTL_NUMBER_OF (str_button_text_1),
- _app_getstateaction (is_install ? INSTALL_DISABLED : INSTALL_ENABLED)
- );
-
+ _r_str_copy (str_button_text_1, RTL_NUMBER_OF (str_button_text_1), _app_getstateaction (is_install ? INSTALL_DISABLED : INSTALL_ENABLED));
_r_str_copy (str_button_text_2, RTL_NUMBER_OF (str_button_text_2), _r_locale_getstring (IDS_CLOSE));
td_buttons[0].nButtonID = IDYES;
@@ -257,7 +243,7 @@ VOID _app_config_apply (
case IDC_USENETWORKRESOLUTION_CHK:
case IDM_USENETWORKRESOLUTION_CHK:
{
- new_val = !_r_config_getboolean (L"IsNetworkResolutionsEnabled", FALSE, NULL);
+ new_val = !_r_config_getboolean (L"IsNetworkResolutionsEnabled", TRUE, NULL);
break;
}
@@ -442,7 +428,6 @@ VOID _app_config_apply (
{
PITEM_APP ptr_app = NULL;
ULONG_PTR enum_key = 0;
- INT listview_id;
_r_config_setboolean (L"IsCertificatesEnabled", new_val, NULL);
@@ -454,12 +439,7 @@ VOID _app_config_apply (
while (_r_obj_enumhashtablepointer (apps_table, (PVOID_PTR)&ptr_app, NULL, &enum_key))
{
- if (!ptr_app->real_path)
- continue;
-
- listview_id = _app_listview_getbytype (ptr_app->type);
-
- _app_getfileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, listview_id);
+ _app_getfileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, _app_listview_getbytype (ptr_app->type));
}
_r_queuedlock_releaseshared (&lock_apps);
@@ -482,12 +462,10 @@ VOID _app_config_apply (
{
PITEM_APP ptr_app = NULL;
ULONG_PTR enum_key = 0;
- INT listview_id;
_r_config_setboolean (L"IsHashesEnabled", new_val, NULL);
_r_menu_checkitem (hmenu, IDM_USEHASHES_CHK, 0, MF_BYCOMMAND, new_val);
-
_r_menu_enableitem (hmenu, IDM_USEAPPMONITOR_CHK, FALSE, new_val);
if (new_val)
@@ -496,12 +474,7 @@ VOID _app_config_apply (
while (_r_obj_enumhashtablepointer (apps_table, (PVOID_PTR)&ptr_app, NULL, &enum_key))
{
- if (!ptr_app->real_path)
- continue;
-
- listview_id = _app_listview_getbytype (ptr_app->type);
-
- _app_getfileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, listview_id);
+ _app_getfileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, _app_listview_getbytype (ptr_app->type));
}
_r_queuedlock_releaseshared (&lock_apps);
@@ -566,6 +539,11 @@ VOID _app_config_apply (
{
return;
}
+
+ default:
+ {
+ break;
+ }
}
if (_wfp_isfiltersinstalled ())
@@ -620,7 +598,7 @@ INT_PTR CALLBACK SettingsProc (
_r_ctrl_checkbutton (hwnd, IDC_INSTALLBOOTTIMEFILTERS_CHK, _r_config_getboolean (L"InstallBoottimeFilters", TRUE, NULL));
_r_ctrl_checkbutton (hwnd, IDC_USECERTIFICATES_CHK, _r_config_getboolean (L"IsCertificatesEnabled", TRUE, NULL));
_r_ctrl_checkbutton (hwnd, IDC_USEHASHES_CHK, _r_config_getboolean (L"IsHashesEnabled", FALSE, NULL));
- _r_ctrl_checkbutton (hwnd, IDC_USENETWORKRESOLUTION_CHK, _r_config_getboolean (L"IsNetworkResolutionsEnabled", FALSE, NULL));
+ _r_ctrl_checkbutton (hwnd, IDC_USENETWORKRESOLUTION_CHK, _r_config_getboolean (L"IsNetworkResolutionsEnabled", TRUE, NULL));
htip = _r_ctrl_createtip (hwnd);
@@ -673,7 +651,6 @@ INT_PTR CALLBACK SettingsProc (
{
PITEM_COLOR ptr_clr = NULL;
ULONG_PTR enum_key = 0;
- BOOLEAN val;
LONG icon_id;
INT item_id = 0;
@@ -689,30 +666,19 @@ INT_PTR CALLBACK SettingsProc (
icon_id = _app_icons_getdefaultapp_id (DATA_APP_REGULAR);
- _app_listview_lock (hwnd, IDC_COLORS, TRUE);
+ _app_listview_lock (hwnd, IDC_COLORS);
while (_r_obj_enumhashtable (colors_table, (PVOID_PTR)&ptr_clr, NULL, &enum_key))
{
ptr_clr->new_clr = _r_config_getulong (ptr_clr->config_value->buffer, ptr_clr->default_clr, L"colors");
- _r_listview_additem (
- hwnd,
- IDC_COLORS,
- item_id,
- _r_locale_getstring (ptr_clr->locale_id),
- icon_id,
- I_GROUPIDNONE,
- (LPARAM)ptr_clr
- );
-
- val = _r_config_getboolean (ptr_clr->config_name->buffer, ptr_clr->is_enabled, L"colors");
-
- _r_listview_setitemcheck (hwnd, IDC_COLORS, item_id, val);
+ _r_listview_additem (hwnd, IDC_COLORS, item_id, _r_locale_getstring (ptr_clr->locale_id), icon_id, I_GROUPIDNONE, (LPARAM)ptr_clr);
+ _r_listview_setitemcheck (hwnd, IDC_COLORS, item_id, _r_config_getboolean (ptr_clr->config_name->buffer, ptr_clr->is_enabled, L"colors"));
item_id += 1;
}
- _app_listview_lock (hwnd, IDC_COLORS, FALSE);
+ _app_listview_unlock (hwnd, IDC_COLORS);
break;
}
@@ -725,10 +691,9 @@ INT_PTR CALLBACK SettingsProc (
_r_ctrl_checkbutton (hwnd, IDC_NOTIFICATIONONTRAY_CHK, _r_config_getboolean (L"IsNotificationsOnTray", FALSE, NULL));
_r_updown_setrange (hwnd, IDC_NOTIFICATIONTIMEOUT, 0, _r_calc_days2seconds (7));
-
_r_updown_setvalue (hwnd, IDC_NOTIFICATIONTIMEOUT, _r_config_getulong (L"NotificationsTimeout", NOTIFY_TIMEOUT_DEFAULT, NULL));
- _r_ctrl_sendcommand (hwnd, IDC_ENABLENOTIFICATIONS_CHK, WM_APP);
+ _r_wnd_sendcommand (hwnd, IDC_ENABLENOTIFICATIONS_CHK, WM_APP);
break;
}
@@ -760,12 +725,11 @@ INT_PTR CALLBACK SettingsProc (
_r_ctrl_setacceleration (hwnd, IDC_LOGSIZELIMIT, 64); // set step to 64kb
_r_updown_setrange (hwnd, IDC_LOGSIZELIMIT, 64, _r_calc_kilobytes2bytes (512));
-
_r_updown_setvalue (hwnd, IDC_LOGSIZELIMIT, _r_config_getulong (L"LogSizeLimitKb", LOG_SIZE_LIMIT_DEFAULT, NULL));
_r_ctrl_checkbutton (hwnd, IDC_ENABLEUILOG_CHK, _r_config_getboolean (L"IsLogUiEnabled", FALSE, NULL));
- _r_ctrl_sendcommand (hwnd, IDC_ENABLELOG_CHK, WM_APP);
+ _r_wnd_sendcommand (hwnd, IDC_ENABLELOG_CHK, WM_APP);
break;
}
@@ -795,109 +759,21 @@ INT_PTR CALLBACK SettingsProc (
INT dialog_id = (INT)wparam;
// localize titles
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_GENERAL,
- L"%s:",
- _r_locale_getstring (IDS_TITLE_GENERAL)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_LANGUAGE,
- L"%s: (Language)",
- _r_locale_getstring (IDS_TITLE_LANGUAGE)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_BLOCKLIST_SPY,
- L"%s:",
- _r_locale_getstring (IDS_BLOCKLIST_SPY)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_BLOCKLIST_UPDATE,
- L"%s:",
- _r_locale_getstring (IDS_BLOCKLIST_UPDATE)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_BLOCKLIST_EXTRA,
- L"%s: (Skype, Bing, Live, Outlook, etc.)",
- _r_locale_getstring (IDS_BLOCKLIST_EXTRA)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_CONNECTIONS,
- L"%s:",
- _r_locale_getstring (IDS_TAB_NETWORK)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_SECURITY,
- L"%s:",
- _r_locale_getstring (IDS_TITLE_SECURITY)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_CONFIRMATIONS,
- L"%s:",
- _r_locale_getstring (IDS_TITLE_CONFIRMATIONS)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_TRAY,
- L"%s:",
- _r_locale_getstring (IDS_TITLE_TRAY)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_HIGHLIGHTING,
- L"%s:",
- _r_locale_getstring (IDS_TITLE_HIGHLIGHTING)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_LOGVIEWER,
- L"%s:",
- _r_locale_getstring (IDS_LOGVIEWER_HINT)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_INTERFACE,
- L"%s:",
- _r_locale_getstring (IDS_TITLE_INTERFACE)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_NOTIFICATIONS,
- L"%s:",
- _r_locale_getstring (IDS_TITLE_NOTIFICATIONS)
- );
-
- _r_ctrl_setstringformat (
- hwnd, IDC_TITLE_LOGGING,
- L"%s:",
- _r_locale_getstring (IDS_TITLE_LOGGING)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_TITLE_ADVANCED,
- L"%s:",
- _r_locale_getstring (IDS_TITLE_ADVANCED)
- );
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_GENERAL, L"%s:", _r_locale_getstring (IDS_TITLE_GENERAL));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_LANGUAGE, L"%s: (Language)", _r_locale_getstring (IDS_TITLE_LANGUAGE));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_BLOCKLIST_SPY, L"%s:", _r_locale_getstring (IDS_BLOCKLIST_SPY));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_BLOCKLIST_UPDATE, L"%s:", _r_locale_getstring (IDS_BLOCKLIST_UPDATE));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_BLOCKLIST_EXTRA, L"%s: (Skype, Bing, Live, Outlook, etc.)", _r_locale_getstring (IDS_BLOCKLIST_EXTRA));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_CONNECTIONS, L"%s:", _r_locale_getstring (IDS_TAB_NETWORK));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_SECURITY, L"%s:", _r_locale_getstring (IDS_TITLE_SECURITY));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_CONFIRMATIONS, L"%s:", _r_locale_getstring (IDS_TITLE_CONFIRMATIONS));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_TRAY, L"%s:", _r_locale_getstring (IDS_TITLE_TRAY));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_HIGHLIGHTING, L"%s:", _r_locale_getstring (IDS_TITLE_HIGHLIGHTING));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_LOGVIEWER, L"%s:", _r_locale_getstring (IDS_LOGVIEWER_HINT));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_INTERFACE, L"%s:", _r_locale_getstring (IDS_TITLE_INTERFACE));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_NOTIFICATIONS, L"%s:", _r_locale_getstring (IDS_TITLE_NOTIFICATIONS));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_LOGGING, L"%s:", _r_locale_getstring (IDS_TITLE_LOGGING));
+ _r_ctrl_setstringformat (hwnd, IDC_TITLE_ADVANCED, L"%s:", _r_locale_getstring (IDS_TITLE_ADVANCED));
switch (dialog_id)
{
@@ -920,117 +796,40 @@ INT_PTR CALLBACK SettingsProc (
recommended_string = _r_locale_getstring (IDS_RECOMMENDED);
- _r_ctrl_setstringformat (
- hwnd,
- IDC_RULE_BLOCKOUTBOUND,
- L"%s (%s)",
- _r_locale_getstring (IDS_RULE_BLOCKOUTBOUND),
- recommended_string
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_RULE_BLOCKINBOUND,
- L"%s (%s)",
- _r_locale_getstring (IDS_RULE_BLOCKINBOUND),
- recommended_string
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_RULE_ALLOWLOOPBACK,
- L"%s (%s)",
- _r_locale_getstring (IDS_RULE_ALLOWLOOPBACK),
- recommended_string
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_RULE_ALLOW6TO4,
- L"%s (%s)",
- _r_locale_getstring (IDS_RULE_ALLOW6TO4),
- recommended_string
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_USESTEALTHMODE_CHK,
- L"%s (%s)",
- _r_locale_getstring (IDS_USESTEALTHMODE_CHK),
- recommended_string
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_INSTALLBOOTTIMEFILTERS_CHK,
- L"%s (%s)",
- _r_locale_getstring (IDS_INSTALLBOOTTIMEFILTERS_CHK),
- recommended_string
- );
+ _r_ctrl_setstringformat (hwnd, IDC_RULE_BLOCKOUTBOUND, L"%s (%s)", _r_locale_getstring (IDS_RULE_BLOCKOUTBOUND), recommended_string);
+ _r_ctrl_setstringformat (hwnd, IDC_RULE_BLOCKINBOUND, L"%s (%s)", _r_locale_getstring (IDS_RULE_BLOCKINBOUND), recommended_string);
+ _r_ctrl_setstringformat (hwnd, IDC_RULE_ALLOWLOOPBACK, L"%s (%s)", _r_locale_getstring (IDS_RULE_ALLOWLOOPBACK), recommended_string);
+ _r_ctrl_setstringformat (hwnd, IDC_RULE_ALLOW6TO4, L"%s (%s)", _r_locale_getstring (IDS_RULE_ALLOW6TO4), recommended_string);
+ _r_ctrl_setstringformat (hwnd, IDC_USESTEALTHMODE_CHK, L"%s (%s)", _r_locale_getstring (IDS_USESTEALTHMODE_CHK), recommended_string);
+ _r_ctrl_setstringformat (hwnd, IDC_INSTALLBOOTTIMEFILTERS_CHK, L"%s (%s)", _r_locale_getstring (IDS_INSTALLBOOTTIMEFILTERS_CHK), recommended_string);
_r_ctrl_setstring (hwnd, IDC_USECERTIFICATES_CHK, _r_locale_getstring (IDS_USECERTIFICATES_CHK));
_r_ctrl_setstring (hwnd, IDC_USEHASHES_CHK, _r_locale_getstring (IDS_USEHASHES_CHK));
-
- _r_ctrl_setstring (
- hwnd,
- IDC_USENETWORKRESOLUTION_CHK,
- _r_locale_getstring (IDS_USENETWORKRESOLUTION_CHK)
- );
+ _r_ctrl_setstring (hwnd, IDC_USENETWORKRESOLUTION_CHK, _r_locale_getstring (IDS_USENETWORKRESOLUTION_CHK));
break;
}
case IDD_SETTINGS_BLOCKLIST:
{
- LPCWSTR recommended_string;
- LPCWSTR disable_string;
- LPCWSTR allow_string;
- LPCWSTR block_string;
-
- recommended_string = _r_locale_getstring (IDS_RECOMMENDED);
- disable_string = _r_locale_getstring (IDS_DISABLE);
- allow_string = _r_locale_getstring (IDS_ACTION_ALLOW);
- block_string = _r_locale_getstring (IDS_ACTION_BLOCK);
+ LPCWSTR recommended_string = _r_locale_getstring (IDS_RECOMMENDED);
+ LPCWSTR disable_string = _r_locale_getstring (IDS_DISABLE);
+ LPCWSTR allow_string = _r_locale_getstring (IDS_ACTION_ALLOW);
+ LPCWSTR block_string = _r_locale_getstring (IDS_ACTION_BLOCK);
_r_ctrl_setstring (hwnd, IDC_BLOCKLIST_SPY_DISABLE, disable_string);
_r_ctrl_setstring (hwnd, IDC_BLOCKLIST_SPY_ALLOW, allow_string);
+ _r_ctrl_setstringformat (hwnd, IDC_BLOCKLIST_SPY_BLOCK, L"%s (%s)", block_string, recommended_string);
- _r_ctrl_setstringformat (
- hwnd,
- IDC_BLOCKLIST_SPY_BLOCK,
- L"%s (%s)",
- block_string,
- recommended_string
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_BLOCKLIST_UPDATE_DISABLE,
- L"%s (%s)",
- disable_string,
- recommended_string
- );
-
+ _r_ctrl_setstringformat (hwnd, IDC_BLOCKLIST_UPDATE_DISABLE, L"%s (%s)", disable_string, recommended_string);
_r_ctrl_setstring (hwnd, IDC_BLOCKLIST_UPDATE_ALLOW, allow_string);
_r_ctrl_setstring (hwnd, IDC_BLOCKLIST_UPDATE_BLOCK, block_string);
- _r_ctrl_setstringformat (
- hwnd,
- IDC_BLOCKLIST_EXTRA_DISABLE,
- L"%s (%s)",
- disable_string,
- recommended_string
- );
-
+ _r_ctrl_setstringformat (hwnd, IDC_BLOCKLIST_EXTRA_DISABLE, L"%s (%s)", disable_string, recommended_string);
_r_ctrl_setstring (hwnd, IDC_BLOCKLIST_EXTRA_ALLOW, allow_string);
_r_ctrl_setstring (hwnd, IDC_BLOCKLIST_EXTRA_BLOCK, block_string);
- _r_ctrl_setstringformat (
- hwnd,
- IDC_BLOCKLIST_INFO,
- L"Author: WindowsSpyBlocker - block spying and tracking on Windows systems.",
- WINDOWSSPYBLOCKER_URL
- );
+ _r_ctrl_setstringformat (hwnd, IDC_BLOCKLIST_INFO, WINDOWSSPYBLOCKER_TITLE, WINDOWSSPYBLOCKER_URL);
break;
}
@@ -1041,12 +840,7 @@ INT_PTR CALLBACK SettingsProc (
_r_ctrl_setstring (hwnd, IDC_CONFIRMEXITTIMER_CHK, _r_locale_getstring (IDS_CONFIRMEXITTIMER_CHK));
_r_ctrl_setstring (hwnd, IDC_CONFIRMLOGCLEAR_CHK, _r_locale_getstring (IDS_CONFIRMLOGCLEAR_CHK));
_r_ctrl_setstring (hwnd, IDC_CONFIRMALLOW_CHK, _r_locale_getstring (IDS_CONFIRMALLOW_CHK));
-
- _r_ctrl_setstring (
- hwnd,
- IDC_TRAYICONSINGLECLICK_CHK,
- _r_locale_getstring (IDS_TRAYICONSINGLECLICK_CHK)
- );
+ _r_ctrl_setstring (hwnd, IDC_TRAYICONSINGLECLICK_CHK, _r_locale_getstring (IDS_TRAYICONSINGLECLICK_CHK));
break;
}
@@ -1072,35 +866,11 @@ INT_PTR CALLBACK SettingsProc (
case IDD_SETTINGS_NOTIFICATIONS:
{
- _r_ctrl_setstring (
- hwnd,
- IDC_ENABLENOTIFICATIONS_CHK,
- _r_locale_getstring (IDS_ENABLENOTIFICATIONS_CHK)
- );
-
- _r_ctrl_setstring (
- hwnd,
- IDC_NOTIFICATIONSOUND_CHK,
- _r_locale_getstring (IDS_NOTIFICATIONSOUND_CHK)
- );
-
- _r_ctrl_setstring (
- hwnd,
- IDC_NOTIFICATIONFULLSCREENSILENTMODE_CHK,
- _r_locale_getstring (IDS_NOTIFICATIONFULLSCREENSILENTMODE_CHK)
- );
-
- _r_ctrl_setstring (
- hwnd,
- IDC_NOTIFICATIONONTRAY_CHK,
- _r_locale_getstring (IDS_NOTIFICATIONONTRAY_CHK)
- );
-
- _r_ctrl_setstring (
- hwnd,
- IDC_NOTIFICATIONTIMEOUT_HINT,
- _r_locale_getstring (IDS_NOTIFICATIONTIMEOUT_HINT)
- );
+ _r_ctrl_setstring (hwnd, IDC_ENABLENOTIFICATIONS_CHK, _r_locale_getstring (IDS_ENABLENOTIFICATIONS_CHK));
+ _r_ctrl_setstring (hwnd, IDC_NOTIFICATIONSOUND_CHK, _r_locale_getstring (IDS_NOTIFICATIONSOUND_CHK));
+ _r_ctrl_setstring (hwnd, IDC_NOTIFICATIONFULLSCREENSILENTMODE_CHK, _r_locale_getstring (IDS_NOTIFICATIONFULLSCREENSILENTMODE_CHK));
+ _r_ctrl_setstring (hwnd, IDC_NOTIFICATIONONTRAY_CHK, _r_locale_getstring (IDS_NOTIFICATIONONTRAY_CHK));
+ _r_ctrl_setstring (hwnd, IDC_NOTIFICATIONTIMEOUT_HINT, _r_locale_getstring (IDS_NOTIFICATIONTIMEOUT_HINT));
break;
}
@@ -1108,53 +878,18 @@ INT_PTR CALLBACK SettingsProc (
case IDD_SETTINGS_LOGGING:
{
_r_ctrl_setstring (hwnd, IDC_ENABLELOG_CHK, _r_locale_getstring (IDS_ENABLELOG_CHK));
-
_r_ctrl_setstring (hwnd, IDC_LOGSIZELIMIT_HINT, _r_locale_getstring (IDS_LOGSIZELIMIT_HINT));
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_ENABLEUILOG_CHK,
- L"%s (%s)",
- _r_locale_getstring (IDS_ENABLEUILOG_CHK),
- _r_locale_getstring (IDS_SESSION_ONLY)
- );
+ _r_ctrl_setstringformat (hwnd, IDC_ENABLEUILOG_CHK, L"%s (%s)", _r_locale_getstring (IDS_ENABLEUILOG_CHK), _r_locale_getstring (IDS_SESSION_ONLY));
break;
}
case IDD_SETTINGS_EXCLUDE:
{
- _r_ctrl_setstringformat (
- hwnd,
- IDC_EXCLUDEBLOCKLIST_CHK,
- L"%s %s",
- _r_locale_getstring (IDS_TITLE_EXCLUDE),
- _r_locale_getstring (IDS_EXCLUDEBLOCKLIST_CHK)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_EXCLUDECUSTOM_CHK,
- L"%s %s",
- _r_locale_getstring (IDS_TITLE_EXCLUDE),
- _r_locale_getstring (IDS_EXCLUDECUSTOM_CHK)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_EXCLUDESTEALTH_CHK,
- L"%s %s",
- _r_locale_getstring (IDS_TITLE_EXCLUDE),
- _r_locale_getstring (IDS_EXCLUDESTEALTH_CHK)
- );
-
- _r_ctrl_setstringformat (
- hwnd,
- IDC_EXCLUDECLASSIFYALLOW_CHK,
- L"%s %s [win8+]",
- _r_locale_getstring (IDS_TITLE_EXCLUDE),
- _r_locale_getstring (IDS_EXCLUDECLASSIFYALLOW_CHK)
- );
+ _r_ctrl_setstringformat (hwnd, IDC_EXCLUDEBLOCKLIST_CHK, L"%s %s", _r_locale_getstring (IDS_TITLE_EXCLUDE), _r_locale_getstring (IDS_EXCLUDEBLOCKLIST_CHK));
+ _r_ctrl_setstringformat (hwnd, IDC_EXCLUDECUSTOM_CHK, L"%s %s", _r_locale_getstring (IDS_TITLE_EXCLUDE), _r_locale_getstring (IDS_EXCLUDECUSTOM_CHK));
+ _r_ctrl_setstringformat (hwnd, IDC_EXCLUDESTEALTH_CHK, L"%s %s", _r_locale_getstring (IDS_TITLE_EXCLUDE), _r_locale_getstring (IDS_EXCLUDESTEALTH_CHK));
+ _r_ctrl_setstringformat (hwnd, IDC_EXCLUDECLASSIFYALLOW_CHK, L"%s %s [win8+]", _r_locale_getstring (IDS_TITLE_EXCLUDE), _r_locale_getstring (IDS_EXCLUDECLASSIFYALLOW_CHK));
break;
}
@@ -1182,22 +917,17 @@ INT_PTR CALLBACK SettingsProc (
case WM_VSCROLL:
case WM_HSCROLL:
{
- LONG value;
INT ctrl_id;
ctrl_id = GetDlgCtrlID ((HWND)lparam);
if (ctrl_id == IDC_LOGSIZELIMIT)
{
- value = _r_updown_getvalue (hwnd, ctrl_id);
-
- _r_config_setlong (L"LogSizeLimitKb", value, NULL);
+ _r_config_setlong (L"LogSizeLimitKb", _r_updown_getvalue (hwnd, ctrl_id), NULL);
}
else if (ctrl_id == IDC_NOTIFICATIONTIMEOUT)
{
- value = _r_updown_getvalue (hwnd, ctrl_id);
-
- _r_config_setlong (L"NotificationsTimeout", value, NULL);
+ _r_config_setlong (L"NotificationsTimeout", _r_updown_getvalue (hwnd, ctrl_id), NULL);
}
break;
@@ -1205,17 +935,14 @@ INT_PTR CALLBACK SettingsProc (
case WM_NOTIFY:
{
- LPNMHDR nmlp;
-
- nmlp = (LPNMHDR)lparam;
+ LPNMHDR nmlp = (LPNMHDR)lparam;
switch (nmlp->code)
{
case TTN_GETDISPINFO:
{
LPNMTTDISPINFOW lpnmdi = (LPNMTTDISPINFOW)lparam;
- WCHAR buffer[1024] = {0};
- INT locale_id;
+ WCHAR buffer[0x400] = {0};
INT ctrl_id;
if ((lpnmdi->uFlags & TTF_IDISHWND) != TTF_IDISHWND)
@@ -1225,31 +952,29 @@ INT_PTR CALLBACK SettingsProc (
if (ctrl_id == IDC_RULE_BLOCKOUTBOUND)
{
- locale_id = IDS_RULE_BLOCKOUTBOUND;
+ _r_str_copy (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_RULE_BLOCKOUTBOUND));
}
else if (ctrl_id == IDC_RULE_BLOCKINBOUND)
{
- locale_id = IDS_RULE_BLOCKINBOUND;
+ _r_str_copy (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_RULE_BLOCKINBOUND));
}
else if (ctrl_id == IDC_RULE_ALLOWLOOPBACK)
{
- locale_id = IDS_RULE_ALLOWLOOPBACK_HINT;
+ _r_str_copy (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_RULE_ALLOWLOOPBACK_HINT));
}
else if (ctrl_id == IDC_USESTEALTHMODE_CHK)
{
- locale_id = IDS_USESTEALTHMODE_HINT;
+ _r_str_copy (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_USESTEALTHMODE_HINT));
}
else if (ctrl_id == IDC_INSTALLBOOTTIMEFILTERS_CHK)
{
- locale_id = IDS_INSTALLBOOTTIMEFILTERS_HINT;
+ _r_str_copy (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_INSTALLBOOTTIMEFILTERS_HINT));
}
else
{
break;
}
- _r_str_copy (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (locale_id));
-
lpnmdi->lpszText = buffer;
break;
@@ -1257,16 +982,13 @@ INT_PTR CALLBACK SettingsProc (
case LVN_ITEMCHANGED:
{
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
PITEM_TAB_CONTEXT tab_context;
- LPNMLISTVIEW lpnmlv;
PITEM_COLOR ptr_clr;
- INT listview_id;
+ HWND hmain;
BOOLEAN is_enabled;
- lpnmlv = (LPNMLISTVIEW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- if (listview_id != IDC_COLORS)
+ if (lpnmlv->hdr.idFrom != IDC_COLORS)
break;
if ((lpnmlv->uChanged & LVIF_STATE) == 0)
@@ -1285,10 +1007,15 @@ INT_PTR CALLBACK SettingsProc (
_r_config_setboolean (ptr_clr->config_name->buffer, is_enabled, L"colors");
- tab_context = _app_listview_getcontext (_r_app_gethwnd (), INT_ERROR);
+ hmain = _r_app_gethwnd ();
- if (tab_context)
- _r_listview_redraw (_r_app_gethwnd (), tab_context->listview_id);
+ if (hmain)
+ {
+ tab_context = _app_listview_getcontext (hmain, INT_ERROR);
+
+ if (tab_context)
+ _r_listview_redraw (hmain, tab_context->listview_id);
+ }
}
}
@@ -1297,9 +1024,7 @@ INT_PTR CALLBACK SettingsProc (
case NM_CUSTOMDRAW:
{
- LONG_PTR result;
-
- result = _app_message_custdraw (hwnd, (LPNMLVCUSTOMDRAW)lparam);
+ LONG_PTR result = _app_message_custdraw (hwnd, (LPNMLVCUSTOMDRAW)lparam);
SetWindowLongPtrW (hwnd, DWLP_MSGRESULT, result);
@@ -1308,26 +1033,18 @@ INT_PTR CALLBACK SettingsProc (
case NM_DBLCLK:
{
- LPNMITEMACTIVATE lpnmlv;
+ LPNMITEMACTIVATE lpnmlv = (LPNMITEMACTIVATE)lparam;
PITEM_TAB_CONTEXT tab_context;
- PITEM_COLOR ptr_clr_crnt;
- PITEM_COLOR ptr_clr = NULL;
+ PITEM_COLOR ptr_clr = NULL, ptr_clr_crnt;
CHOOSECOLOR cc = {0};
- COLORREF cust[16] = {0};
- ULONG_PTR enum_key = 0;
- ULONG_PTR index = 0;
- INT listview_id;
+ COLORREF cust[0x10] = {0};
+ HWND hmain;
+ ULONG_PTR enum_key = 0, index = 0;
- lpnmlv = (LPNMITEMACTIVATE)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- if (lpnmlv->iItem == INT_ERROR)
+ if (lpnmlv->iItem == INT_ERROR || lpnmlv->hdr.idFrom != IDC_COLORS)
break;
- if (listview_id != IDC_COLORS)
- break;
-
- ptr_clr_crnt = (PITEM_COLOR)_r_listview_getitemlparam (hwnd, listview_id, lpnmlv->iItem);
+ ptr_clr_crnt = (PITEM_COLOR)_r_listview_getitemlparam (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lpnmlv->iItem);
if (!ptr_clr_crnt)
break;
@@ -1351,10 +1068,15 @@ INT_PTR CALLBACK SettingsProc (
_r_listview_redraw (hwnd, IDC_COLORS);
- tab_context = _app_listview_getcontext (_r_app_gethwnd (), INT_ERROR);
+ hmain = _r_app_gethwnd ();
- if (tab_context)
- _r_listview_redraw (_r_app_gethwnd (), tab_context->listview_id);
+ if (hmain)
+ {
+ tab_context = _app_listview_getcontext (hmain, INT_ERROR);
+
+ if (tab_context)
+ _r_listview_redraw (hmain, tab_context->listview_id);
+ }
}
break;
@@ -1363,9 +1085,7 @@ INT_PTR CALLBACK SettingsProc (
case NM_CLICK:
case NM_RETURN:
{
- PNMLINK pnmlink;
-
- pnmlink = (PNMLINK)lparam;
+ PNMLINK pnmlink = (PNMLINK)lparam;
if (!_r_str_isempty (pnmlink->item.szUrl))
_r_shell_opendefault (pnmlink->item.szUrl);
@@ -1386,12 +1106,17 @@ INT_PTR CALLBACK SettingsProc (
{
case IDC_ALWAYSONTOP_CHK:
{
+ HWND hmain;
BOOLEAN is_enabled;
is_enabled = _r_ctrl_isbuttonchecked (hwnd, ctrl_id);
_r_config_setboolean (L"AlwaysOnTop", is_enabled, NULL);
- _r_menu_checkitem (GetMenu (_r_app_gethwnd ()), IDM_ALWAYSONTOP_CHK, 0, MF_BYCOMMAND, is_enabled);
+
+ hmain = _r_app_gethwnd ();
+
+ if (hmain)
+ _r_menu_checkitem (GetMenu (hmain), IDM_ALWAYSONTOP_CHK, 0, MF_BYCOMMAND, is_enabled);
break;
}
@@ -1450,7 +1175,11 @@ INT_PTR CALLBACK SettingsProc (
case IDC_USEHASHES_CHK:
case IDC_USENETWORKRESOLUTION_CHK:
{
- _app_config_apply (_r_app_gethwnd (), hwnd, ctrl_id);
+ HWND hmain = _r_app_gethwnd ();
+
+ if (hmain)
+ _app_config_apply (hmain, hwnd, ctrl_id);
+
break;
}
@@ -1464,52 +1193,47 @@ INT_PTR CALLBACK SettingsProc (
case IDC_BLOCKLIST_EXTRA_ALLOW:
case IDC_BLOCKLIST_EXTRA_BLOCK:
{
- HMENU hmenu;
+ HMENU hmenu = NULL;
+ HWND hmain;
LONG new_state;
- hmenu = GetMenu (_r_app_gethwnd ());
+ hmain = _r_app_gethwnd ();
+
+ if (hmain)
+ hmenu = GetMenu (hmain);
if (ctrl_id >= IDC_BLOCKLIST_SPY_DISABLE && ctrl_id <= IDC_BLOCKLIST_SPY_BLOCK)
{
- new_state = _r_calc_clamp (
- _r_ctrl_isradiochecked (hwnd, IDC_BLOCKLIST_SPY_DISABLE, IDC_BLOCKLIST_SPY_BLOCK) - IDC_BLOCKLIST_SPY_DISABLE,
- 0,
- 2
- );
+ new_state = _r_calc_clamp (_r_ctrl_isradiochecked (hwnd, IDC_BLOCKLIST_SPY_DISABLE, IDC_BLOCKLIST_SPY_BLOCK) - IDC_BLOCKLIST_SPY_DISABLE, 0, 2);
- _r_menu_checkitem (hmenu, IDM_BLOCKLIST_SPY_DISABLE, IDM_BLOCKLIST_SPY_BLOCK, MF_BYCOMMAND, IDM_BLOCKLIST_SPY_DISABLE + new_state);
+ if (hmenu)
+ _r_menu_checkitem (hmenu, IDM_BLOCKLIST_SPY_DISABLE, IDM_BLOCKLIST_SPY_BLOCK, MF_BYCOMMAND, IDM_BLOCKLIST_SPY_DISABLE + new_state);
_r_config_setlong (L"BlocklistSpyState", new_state, NULL);
- _app_ruleblocklistset (_r_app_gethwnd (), new_state, INT_ERROR, INT_ERROR, TRUE);
+ _app_ruleblocklistset (hmain, new_state, INT_ERROR, INT_ERROR, TRUE);
}
else if (ctrl_id >= IDC_BLOCKLIST_UPDATE_DISABLE && ctrl_id <= IDC_BLOCKLIST_UPDATE_BLOCK)
{
- new_state = _r_calc_clamp (
- _r_ctrl_isradiochecked (hwnd, IDC_BLOCKLIST_UPDATE_DISABLE, IDC_BLOCKLIST_UPDATE_BLOCK) - IDC_BLOCKLIST_UPDATE_DISABLE,
- 0,
- 2
- );
+ new_state = _r_calc_clamp (_r_ctrl_isradiochecked (hwnd, IDC_BLOCKLIST_UPDATE_DISABLE, IDC_BLOCKLIST_UPDATE_BLOCK) - IDC_BLOCKLIST_UPDATE_DISABLE, 0, 2);
- _r_menu_checkitem (hmenu, IDM_BLOCKLIST_UPDATE_DISABLE, IDM_BLOCKLIST_UPDATE_BLOCK, MF_BYCOMMAND, IDM_BLOCKLIST_UPDATE_DISABLE + new_state);
+ if (hmenu)
+ _r_menu_checkitem (hmenu, IDM_BLOCKLIST_UPDATE_DISABLE, IDM_BLOCKLIST_UPDATE_BLOCK, MF_BYCOMMAND, IDM_BLOCKLIST_UPDATE_DISABLE + new_state);
_r_config_setlong (L"BlocklistUpdateState", new_state, NULL);
- _app_ruleblocklistset (_r_app_gethwnd (), INT_ERROR, new_state, INT_ERROR, TRUE);
+ _app_ruleblocklistset (hmain, INT_ERROR, new_state, INT_ERROR, TRUE);
}
else if (ctrl_id >= IDC_BLOCKLIST_EXTRA_DISABLE && ctrl_id <= IDC_BLOCKLIST_EXTRA_BLOCK)
{
- new_state = _r_calc_clamp (
- _r_ctrl_isradiochecked (hwnd, IDC_BLOCKLIST_EXTRA_DISABLE, IDC_BLOCKLIST_EXTRA_BLOCK) - IDC_BLOCKLIST_EXTRA_DISABLE,
- 0,
- 2
- );
+ new_state = _r_calc_clamp (_r_ctrl_isradiochecked (hwnd, IDC_BLOCKLIST_EXTRA_DISABLE, IDC_BLOCKLIST_EXTRA_BLOCK) - IDC_BLOCKLIST_EXTRA_DISABLE, 0, 2);
- _r_menu_checkitem (hmenu, IDM_BLOCKLIST_EXTRA_DISABLE, IDM_BLOCKLIST_EXTRA_BLOCK, MF_BYCOMMAND, IDM_BLOCKLIST_EXTRA_DISABLE + new_state);
+ if (hmenu)
+ _r_menu_checkitem (hmenu, IDM_BLOCKLIST_EXTRA_DISABLE, IDM_BLOCKLIST_EXTRA_BLOCK, MF_BYCOMMAND, IDM_BLOCKLIST_EXTRA_DISABLE + new_state);
_r_config_setlong (L"BlocklistExtraState", new_state, NULL);
- _app_ruleblocklistset (_r_app_gethwnd (), INT_ERROR, INT_ERROR, new_state, TRUE);
+ _app_ruleblocklistset (hmain, INT_ERROR, INT_ERROR, new_state, TRUE);
}
break;
@@ -1518,8 +1242,7 @@ INT_PTR CALLBACK SettingsProc (
case IDC_ENABLELOG_CHK:
{
HWND hctrl;
- BOOLEAN is_postmessage;
- BOOLEAN is_enabled;
+ BOOLEAN is_enabled, is_postmessage;
//BOOLEAN is_logging_enabled;
is_postmessage = (lparam == WM_APP);
@@ -1548,9 +1271,7 @@ INT_PTR CALLBACK SettingsProc (
case IDC_ENABLEUILOG_CHK:
{
- BOOLEAN is_enabled;
-
- is_enabled = _r_ctrl_isbuttonchecked (hwnd, ctrl_id);
+ BOOLEAN is_enabled = _r_ctrl_isbuttonchecked (hwnd, ctrl_id);
_r_config_setboolean (L"IsLogUiEnabled", is_enabled, NULL);
@@ -1583,11 +1304,7 @@ INT_PTR CALLBACK SettingsProc (
case IDC_LOGPATH_BTN:
{
- COMDLG_FILTERSPEC filters[] = {
- {L"Log files (*.log, *.csv)", L"*.log;*.csv"},
- {L"All files (*.*)", L"*.*"},
- };
-
+ COMDLG_FILTERSPEC filters[] = {{L"Log files (*.log, *.csv)", L"*.log;*.csv"}, {L"All files (*.*)", L"*.*"}};
R_FILE_DIALOG file_dialog;
PR_STRING path;
HRESULT status;
@@ -1651,11 +1368,7 @@ INT_PTR CALLBACK SettingsProc (
case IDC_LOGVIEWER_BTN:
{
- COMDLG_FILTERSPEC filters[] = {
- {L"Executable files (*.exe)", L"*.exe"},
- {L"All files (*.*)", L"*.*"},
- };
-
+ COMDLG_FILTERSPEC filters[] = {{L"Executable files (*.exe)", L"*.exe"}, {L"All files (*.*)", L"*.*"}};
R_FILE_DIALOG file_dialog;
PR_STRING path;
HRESULT status;
@@ -1698,14 +1411,10 @@ INT_PTR CALLBACK SettingsProc (
case IDC_LOGSIZELIMIT_CTRL:
{
- LONG value;
-
if (notify_code != EN_KILLFOCUS)
break;
- value = _r_updown_getvalue (hwnd, IDC_LOGSIZELIMIT);
-
- _r_config_setlong (L"LogSizeLimitKb", value, NULL);
+ _r_config_setlong (L"LogSizeLimitKb", _r_updown_getvalue (hwnd, IDC_LOGSIZELIMIT), NULL);
break;
}
@@ -1713,10 +1422,9 @@ INT_PTR CALLBACK SettingsProc (
case IDC_ENABLENOTIFICATIONS_CHK:
{
HWND hctrl;
- BOOLEAN is_postmessage;
- BOOLEAN is_enabled;
+ BOOLEAN is_enabled, is_postmessage;
- is_postmessage = ((INT)lparam == WM_APP);
+ is_postmessage = (lparam == WM_APP);
is_enabled = _r_ctrl_isbuttonchecked (hwnd, ctrl_id);
if (!is_postmessage)
@@ -1732,7 +1440,7 @@ INT_PTR CALLBACK SettingsProc (
if (hctrl)
_r_ctrl_enable (hctrl, 0, is_enabled);
- _r_ctrl_sendcommand (hwnd, IDC_NOTIFICATIONSOUND_CHK, WM_APP);
+ _r_wnd_sendcommand (hwnd, IDC_NOTIFICATIONSOUND_CHK, WM_APP);
if (is_postmessage)
break;
@@ -1747,10 +1455,9 @@ INT_PTR CALLBACK SettingsProc (
case IDC_NOTIFICATIONSOUND_CHK:
{
- BOOLEAN is_postmessage;
- BOOLEAN is_checked;
+ BOOLEAN is_checked, is_postmessage;
- is_postmessage = ((INT)lparam == WM_APP);
+ is_postmessage = (lparam == WM_APP);
is_checked = _r_ctrl_isbuttonchecked (hwnd, ctrl_id);
_r_ctrl_checkbutton (hwnd, IDC_NOTIFICATIONFULLSCREENSILENTMODE_CHK, _r_config_getboolean (L"IsNotificationsFullscreenSilentMode", TRUE, NULL));
@@ -1799,13 +1506,9 @@ INT_PTR CALLBACK SettingsProc (
case IDC_EXCLUDECLASSIFYALLOW_CHK:
{
- HANDLE hengine;
-
_r_config_setboolean (L"IsExcludeClassifyAllow", _r_ctrl_isbuttonchecked (hwnd, ctrl_id), NULL);
- hengine = _wfp_getenginehandle ();
-
- _wfp_logsetoption (hengine);
+ _wfp_logsetoption (_wfp_getenginehandle ());
break;
}
@@ -1837,74 +1540,74 @@ VOID _app_addwindowtabs (
PITEM_TAB_CONTEXT context;
// apps profile tab
- context = _r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
+ context = (PITEM_TAB_CONTEXT)_r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
context->listview_id = IDC_APPS_PROFILE;
context->locale_id = IDS_TAB_APPS;
- _r_tab_additem (hwnd, IDC_TAB, INT_MAX, L"", I_DEFAULT, (LPARAM)context);
+ _r_tab_additem (hwnd, IDC_TAB, INT_ERROR, L"", I_DEFAULT, (LPARAM)context);
// apps services tab
- context = _r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
+ context = (PITEM_TAB_CONTEXT)_r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
context->listview_id = IDC_APPS_SERVICE;
context->locale_id = IDS_TAB_SERVICES;
- _r_tab_additem (hwnd, IDC_TAB, INT_MAX, L"", I_DEFAULT, (LPARAM)context);
+ _r_tab_additem (hwnd, IDC_TAB, INT_ERROR, L"", I_DEFAULT, (LPARAM)context);
// uwp apps (win8+)
if (_r_sys_isosversiongreaterorequal (WINDOWS_8))
{
- context = _r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
+ context = (PITEM_TAB_CONTEXT)_r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
context->listview_id = IDC_APPS_UWP;
context->locale_id = IDS_TAB_PACKAGES;
- _r_tab_additem (hwnd, IDC_TAB, INT_MAX, L"", I_DEFAULT, (LPARAM)context);
+ _r_tab_additem (hwnd, IDC_TAB, INT_ERROR, L"", I_DEFAULT, (LPARAM)context);
}
if (!_r_config_getboolean (L"IsInternalRulesDisabled", FALSE, NULL))
{
// rules blocklist tab
- context = _r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
+ context = (PITEM_TAB_CONTEXT)_r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
context->listview_id = IDC_RULES_BLOCKLIST;
context->locale_id = IDS_TRAY_BLOCKLIST_RULES;
- _r_tab_additem (hwnd, IDC_TAB, INT_MAX, L"", I_DEFAULT, (LPARAM)context);
+ _r_tab_additem (hwnd, IDC_TAB, INT_ERROR, L"", I_DEFAULT, (LPARAM)context);
// rules system tab
- context = _r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
+ context = (PITEM_TAB_CONTEXT)_r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
context->listview_id = IDC_RULES_SYSTEM;
context->locale_id = IDS_TRAY_SYSTEM_RULES;
- _r_tab_additem (hwnd, IDC_TAB, INT_MAX, L"", I_DEFAULT, (LPARAM)context);
+ _r_tab_additem (hwnd, IDC_TAB, INT_ERROR, L"", I_DEFAULT, (LPARAM)context);
}
// rules user tab
- context = _r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
+ context = (PITEM_TAB_CONTEXT)_r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
context->listview_id = IDC_RULES_CUSTOM;
context->locale_id = IDS_TRAY_USER_RULES;
- _r_tab_additem (hwnd, IDC_TAB, INT_MAX, L"", I_DEFAULT, (LPARAM)context);
+ _r_tab_additem (hwnd, IDC_TAB, INT_ERROR, L"", I_DEFAULT, (LPARAM)context);
// network tab
- context = _r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
+ context = (PITEM_TAB_CONTEXT)_r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
context->listview_id = IDC_NETWORK;
context->locale_id = IDS_TAB_NETWORK;
- _r_tab_additem (hwnd, IDC_TAB, INT_MAX, L"", I_DEFAULT, (LPARAM)context);
+ _r_tab_additem (hwnd, IDC_TAB, INT_ERROR, L"", I_DEFAULT, (LPARAM)context);
// log tab
- context = _r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
+ context = (PITEM_TAB_CONTEXT)_r_mem_allocate (sizeof (ITEM_TAB_CONTEXT));
context->listview_id = IDC_LOG;
context->locale_id = IDS_TITLE_LOGGING;
- _r_tab_additem (hwnd, IDC_TAB, INT_MAX, L"", I_DEFAULT, (LPARAM)context);
+ _r_tab_additem (hwnd, IDC_TAB, INT_ERROR, L"", I_DEFAULT, (LPARAM)context);
}
VOID _app_tabs_init (
@@ -1914,36 +1617,18 @@ VOID _app_tabs_init (
{
PITEM_TAB_CONTEXT tab_context;
RECT rect = {0};
- LONG statusbar_height;
- LONG rebar_height;
- ULONG style;
+ LONG rebar_height, statusbar_height;
+ LONG_PTR style;
HWND hlistview;
statusbar_height = _r_status_getheight (hwnd, IDC_STATUSBAR);
rebar_height = _r_rebar_getheight (hwnd, IDC_REBAR);
- GetClientRect (hwnd, &rect);
+ if (!GetClientRect (hwnd, &rect))
+ return;
- SetWindowPos (
- config.hrebar,
- NULL,
- 0,
- 0,
- rect.right,
- rebar_height,
- SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER
- );
-
- SetWindowPos (
- GetDlgItem (hwnd, IDC_TAB),
- NULL
- ,
- 0,
- rebar_height,
- rect.right,
- rect.bottom - rebar_height - statusbar_height,
- SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER
- );
+ SetWindowPos (config.hrebar, NULL, 0, 0, rect.right, rebar_height, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
+ SetWindowPos (GetDlgItem (hwnd, IDC_TAB), NULL, 0, rebar_height, rect.right, rect.bottom - rebar_height - statusbar_height, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
_app_listview_loadfont (dpi_value, TRUE);
@@ -2009,7 +1694,7 @@ VOID _app_tabs_init (
{
_r_listview_setstyle (hwnd, tab_context->listview_id, style, TRUE);
- _r_listview_addcolumn (hwnd, tab_context->listview_id, 0, L"#", -10, LVCFMT_LEFT);
+ _r_listview_addcolumn (hwnd, tab_context->listview_id, 0, L"", -10, LVCFMT_LEFT);
_r_listview_addcolumn (hwnd, tab_context->listview_id, 1, L"", -10, LVCFMT_LEFT);
_r_listview_addcolumn (hwnd, tab_context->listview_id, 2, L"", -10, LVCFMT_LEFT);
_r_listview_addcolumn (hwnd, tab_context->listview_id, 3, L"", -10, LVCFMT_LEFT);
@@ -2020,13 +1705,12 @@ VOID _app_tabs_init (
_r_listview_addcolumn (hwnd, tab_context->listview_id, 8, L"", -10, LVCFMT_LEFT);
_r_listview_addcolumn (hwnd, tab_context->listview_id, 9, L"", -10, LVCFMT_RIGHT);
_r_listview_addcolumn (hwnd, tab_context->listview_id, 10, L"", -10, LVCFMT_LEFT);
- _r_listview_addcolumn (hwnd, tab_context->listview_id, 11, L"", -10, LVCFMT_LEFT);
_r_listview_addgroup (hwnd, tab_context->listview_id, 0, L"", 0, LVGS_COLLAPSIBLE | LVGS_NOHEADER, LVGS_COLLAPSIBLE | LVGS_NOHEADER);
}
// add filter group
- _r_listview_addgroup (hwnd, tab_context->listview_id, LV_HIDDEN_GROUP_ID, L"", 0, LVGS_HIDDEN | LVGS_NOHEADER | LVGS_COLLAPSED, LVGS_HIDDEN | LVGS_NOHEADER | LVGS_COLLAPSED);
+ _r_listview_addgroup (hwnd, tab_context->listview_id, LV_HIDDEN_GROUP_ID, L"", 0, LVGS_COLLAPSED | LVGS_HIDDEN | LVGS_NOHEADER, LVGS_COLLAPSED | LVGS_HIDDEN | LVGS_NOHEADER);
_app_listview_setfont (hwnd, tab_context->listview_id);
@@ -2052,7 +1736,7 @@ VOID _app_initialize (
R_ENVIRONMENT environment;
// set privileges
- _r_sys_setprocessprivilege (NtCurrentProcess (), privileges, RTL_NUMBER_OF (privileges), TRUE);
+ _r_sys_setprocessprivilege (hwnd, NtCurrentProcess (), privileges, RTL_NUMBER_OF (privileges), TRUE);
// set process priority
_r_sys_setenvironment (&environment, PROCESS_PRIORITY_CLASS_HIGH, IoPriorityHigh, MEMORY_PRIORITY_NORMAL);
@@ -2067,8 +1751,8 @@ VOID _app_initialize (
_r_sys_setenvironment (&environment, THREAD_PRIORITY_BELOW_NORMAL, IoPriorityLow, MEMORY_PRIORITY_NORMAL);
- _r_workqueue_initialize (&log_queue, 6, &environment, L"PacketsQueue");
_r_workqueue_initialize (&resolver_queue, 6, &environment, L"ResolverQueue");
+ _r_workqueue_initialize (&log_queue, 6, &environment, L"PacketsQueue");
_r_sys_setenvironment (&environment, THREAD_PRIORITY_HIGHEST, IoPriorityHigh, MEMORY_PRIORITY_NORMAL);
@@ -2083,43 +1767,42 @@ VOID _app_initialize (
config.svchost_path = _r_obj_concatstringrefs (
2,
- &_r_sys_getsystemdirectory ()->sr,
+ _r_sys_getsystemdirectory (),
&svchost_sr
);
config.wusvc_path = _r_obj_concatstringrefs (
2,
- &_r_sys_getsystemdirectory ()->sr,
+ _r_sys_getsystemdirectory (),
&wusvc_sr
);
config.system_path = _r_obj_createstring (PROC_SYSTEM_NAME);
-
config.ntoskrnl_path = _r_sys_getkernelfilename (TRUE);
if (!config.ntoskrnl_path)
- config.ntoskrnl_path = _r_obj_referenceemptystring ();
+ config.ntoskrnl_path = _r_obj_createstring (L"ntoskrnl.exe"); // search path
- config.my_hash = _r_str_gethash (&config.my_path->sr, TRUE);
config.ntoskrnl_hash = _r_str_gethash (&config.system_path->sr, TRUE);
config.svchost_hash = _r_str_gethash (&config.svchost_path->sr, TRUE);
config.wusvc_hash = _r_str_gethash (&config.wusvc_path->sr, TRUE);
+ config.my_hash = _r_str_gethash (&config.my_path->sr, TRUE);
// initialize free list
- _r_freelist_initialize (&context_free_list, sizeof (ITEM_CONTEXT), 0x20);
_r_freelist_initialize (&listview_free_list, sizeof (ITEM_LISTVIEW_CONTEXT), 0x800);
+ _r_freelist_initialize (&context_free_list, sizeof (ITEM_CONTEXT), 0x20);
// initialize colors array
colors_table = _r_obj_createhashtable (sizeof (ITEM_COLOR), 0x08, NULL);
// initialize colors
+ config.color_network = _app_addcolor (IDS_HIGHLIGHT_CONNECTION, L"IsHighlightConnection", L"ColorConnection", LV_COLOR_CONNECTION, TRUE);
+ config.color_nonremovable = _app_addcolor (IDS_DISABLEREMOVAL, L"IsHighlightUndelete", L"ColorUndelete", LV_COLOR_UNDELETE, TRUE);
config.color_invalid = _app_addcolor (IDS_HIGHLIGHT_INVALID, L"IsHighlightInvalid", L"ColorInvalid", LV_COLOR_INVALID, TRUE);
config.color_special = _app_addcolor (IDS_HIGHLIGHT_SPECIAL, L"IsHighlightSpecial", L"ColorSpecial", LV_COLOR_SPECIAL, TRUE);
config.color_signed = _app_addcolor (IDS_HIGHLIGHT_SIGNED, L"IsHighlightSigned", L"ColorSigned", LV_COLOR_SIGNED, TRUE);
- config.color_pico = _app_addcolor (IDS_HIGHLIGHT_PICO, L"IsHighlightPico", L"ColorPico", LV_COLOR_PICO, TRUE);
config.color_system = _app_addcolor (IDS_HIGHLIGHT_SYSTEM, L"IsHighlightSystem", L"ColorSystem", LV_COLOR_SYSTEM, TRUE);
- config.color_network = _app_addcolor (IDS_HIGHLIGHT_CONNECTION, L"IsHighlightConnection", L"ColorConnection", LV_COLOR_CONNECTION, TRUE);
- config.color_nonremovable = _app_addcolor (IDS_DISABLEREMOVAL, L"IsHighlightUndelete", L"ColorUndelete", LV_COLOR_UNDELETE, TRUE);
+ config.color_pico = _app_addcolor (IDS_HIGHLIGHT_PICO, L"IsHighlightPico", L"ColorPico", LV_COLOR_PICO, TRUE);
_app_generate_credentials ();
@@ -2127,23 +1810,22 @@ VOID _app_initialize (
_app_icons_getdefault ();
// initialize global filters array object
- filter_ids = _r_obj_createarray (sizeof (GUID), 0x0C, NULL);
+ filter_ids = _r_obj_createarray (sizeof (GUID), 0x10, NULL);
// initialize apps table
apps_table = _r_obj_createhashtablepointer (0x20);
// initialize rules array object
- rules_list = _r_obj_createlist (0x0C, &_r_obj_dereference);
+ rules_list = _r_obj_createlist (0x10, &_r_obj_dereference);
// initialize rules configuration table
- rules_config = _r_obj_createhashtable (sizeof (ITEM_RULE_CONFIG), 8, &_app_dereferenceruleconfig);
+ rules_config = _r_obj_createhashtable (sizeof (ITEM_RULE_CONFIG), 0x10, &_app_dereferenceruleconfig);
// initialize log hashtable object
log_table = _r_obj_createhashtablepointer (0x20);
// initialize cache table
cache_information = _r_obj_createhashtablepointer (0x20);
-
cache_resolution = _r_obj_createhashtablepointer (0x20);
NtCreateEvent (&config.hnotify_evt, EVENT_ALL_ACCESS, NULL, NotificationEvent, TRUE);
@@ -2180,7 +1862,7 @@ INT_PTR CALLBACK DlgProc (
{
case WM_INITDIALOG:
{
- WCHAR internal_profile_version[64];
+ WCHAR internal_profile_version[0x40];
ENUM_INSTALL_TYPE install_type;
LONG dpi_value;
@@ -2214,7 +1896,7 @@ INT_PTR CALLBACK DlgProc (
_app_profile_load (hwnd, NULL);
// install filters
- install_type = _wfp_isfiltersinstalled ();
+ install_type = _wfp_getinstalltype ();
if (install_type != INSTALL_DISABLED)
{
@@ -2280,14 +1962,10 @@ INT_PTR CALLBACK DlgProc (
case RM_TASKBARCREATED:
{
- ENUM_INSTALL_TYPE install_type;
-
- install_type = _wfp_getinstalltype ();
-
// refresh tray icon
_r_tray_create (hwnd, &GUID_TrayIcon, RM_TRAYICON, NULL, NULL, FALSE);
- _app_settrayicon (hwnd, install_type);
+ _app_settrayicon (hwnd, _wfp_getinstalltype ());
break;
}
@@ -2331,7 +2009,7 @@ INT_PTR CALLBACK DlgProc (
case WM_MBUTTONUP:
{
- _r_ctrl_sendcommand (hwnd, IDM_TRAY_LOGSHOW, 0);
+ _r_wnd_sendcommand (hwnd, IDM_TRAY_LOGSHOW, 0);
break;
}
@@ -2369,13 +2047,11 @@ INT_PTR CALLBACK DlgProc (
case WM_NOTIFICATION:
{
- PITEM_LOG ptr_log;
HWND hnotify;
if (_r_queuedlock_tryacquireexclusive (&lock_notify))
{
- ptr_log = _r_obj_reference ((PITEM_LOG)lparam);
- hnotify = _app_notify_getwindow (ptr_log);
+ hnotify = _app_notify_getwindow ((PITEM_LOG)_r_obj_reference ((PITEM_LOG)lparam));
_r_queuedlock_releaseexclusive (&lock_notify);
@@ -2420,8 +2096,6 @@ INT_PTR CALLBACK DlgProc (
case WM_DESTROY:
{
- HANDLE hengine;
-
_app_loginit (FALSE);
if (_r_queuedlock_islocked (&lock_apply))
@@ -2432,9 +2106,7 @@ INT_PTR CALLBACK DlgProc (
_r_tray_destroy (hwnd, &GUID_TrayIcon);
- hengine = _wfp_getenginehandle ();
-
- _wfp_uninitialize (hengine, FALSE);
+ _wfp_uninitialize (_wfp_getenginehandle (), FALSE);
_r_imagelist_destroy (config.himg_rules_small);
_r_imagelist_destroy (config.himg_rules_large);
@@ -2449,11 +2121,10 @@ INT_PTR CALLBACK DlgProc (
case WM_DROPFILES:
{
+ PITEM_APP ptr_app;
PR_STRING path;
HDROP hdrop;
- ULONG app_hash = 0;
- ULONG numfiles;
- ULONG length;
+ ULONG app_hash = 0, length, numfiles;
hdrop = (HDROP)wparam;
numfiles = DragQueryFileW (hdrop, UINT32_MAX, NULL, 0);
@@ -2467,7 +2138,14 @@ INT_PTR CALLBACK DlgProc (
{
_r_str_trimtonullterminator (&path->sr);
- app_hash = _app_addapplication (hwnd, DATA_UNKNOWN, path, NULL, NULL);
+ ptr_app = _app_addapplication (hwnd, DATA_UNKNOWN, path, NULL, NULL);
+
+ if (ptr_app)
+ {
+ app_hash = ptr_app->app_hash;
+
+ _r_obj_dereference (ptr_app);
+ }
}
_r_obj_dereference (path);
@@ -2558,7 +2236,6 @@ INT_PTR CALLBACK DlgProc (
case RBN_HEIGHTCHANGE:
{
_r_wnd_sendmessage (hwnd, 0, WM_SIZE, 0, 0);
-
break;
}
@@ -2592,19 +2269,19 @@ INT_PTR CALLBACK DlgProc (
if (!tab_context)
break;
- hlistview = GetDlgItem (hwnd, tab_context->listview_id);
-
- if (!hlistview)
- break;
-
_app_search_applyfilter (hwnd, tab_context->listview_id, config.search_string);
_app_listview_updateby_id (hwnd, tab_context->listview_id, PR_UPDATE_FORCE | PR_UPDATE_NORESIZE);
- ShowWindow (hlistview, SW_SHOWNA);
+ hlistview = GetDlgItem (hwnd, tab_context->listview_id);
- if (_r_wnd_isvisible (hwnd, TRUE)) // HACK!!!
- SetFocus (hlistview);
+ if (hlistview)
+ {
+ ShowWindow (hlistview, SW_SHOWNA);
+
+ if (_r_wnd_isvisible (hwnd, TRUE)) // HACK!!!
+ SetFocus (hlistview);
+ }
_app_listview_resize (hwnd, tab_context->listview_id, FALSE);
@@ -2651,14 +2328,10 @@ INT_PTR CALLBACK DlgProc (
case LVN_DELETEITEM:
{
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
PITEM_LISTVIEW_CONTEXT context;
- LPNMLISTVIEW lpnmlv;
- INT listview_id;
- lpnmlv = (LPNMLISTVIEW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- if (!(listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_LOG))
+ if (!(lpnmlv->hdr.idFrom >= IDC_APPS_PROFILE && lpnmlv->hdr.idFrom <= IDC_LOG))
break;
context = (PITEM_LISTVIEW_CONTEXT)lpnmlv->lParam;
@@ -2673,29 +2346,21 @@ INT_PTR CALLBACK DlgProc (
case LVN_COLUMNCLICK:
{
- LPNMLISTVIEW lpnmlv;
- INT ctrl_id;
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
- lpnmlv = (LPNMLISTVIEW)lparam;
- ctrl_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- _app_listview_sort (hwnd, ctrl_id, lpnmlv->iSubItem, TRUE);
+ _app_listview_sort (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lpnmlv->iSubItem, TRUE);
break;
}
case LVN_GETINFOTIP:
{
- LPNMLVGETINFOTIPW lpnmlv;
+ LPNMLVGETINFOTIPW lpnmlv = (LPNMLVGETINFOTIPW)lparam;
PR_STRING string;
- INT listview_id;
- lpnmlv = (LPNMLVGETINFOTIPW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
+ lparam = _app_listview_getitemcontext (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lpnmlv->iItem);
- lparam = _app_listview_getitemcontext (hwnd, listview_id, lpnmlv->iItem);
-
- string = _app_gettooltipbylparam (hwnd, listview_id, lparam);
+ string = _app_gettooltipbylparam (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lparam);
if (!string)
break;
@@ -2709,21 +2374,16 @@ INT_PTR CALLBACK DlgProc (
case LVN_ITEMCHANGING:
{
- LPNMLISTVIEW lpnmlv;
- INT listview_id;
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
ULONG_PTR app_hash;
- lpnmlv = (LPNMLISTVIEW)lparam;
-
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- if (_app_listview_islocked (hwnd, listview_id))
+ if (_app_listview_islocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom))
break;
if (!(lpnmlv->uChanged & LVIF_STATE) || !lpnmlv->lParam)
break;
- if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP))
+ if ((lpnmlv->hdr.idFrom >= IDC_APPS_PROFILE && lpnmlv->hdr.idFrom <= IDC_APPS_UWP))
{
app_hash = _app_listview_getcontextcode (lpnmlv->lParam);
@@ -2731,7 +2391,7 @@ INT_PTR CALLBACK DlgProc (
{
if (app_hash == config.my_hash)
{
- if (!_r_show_confirmmessage (hwnd, L"WARNING!", SZ_WARNING_ME, NULL, FALSE))
+ if (!_r_show_confirmmessage (hwnd, L"WARNING!", _r_locale_getstring (IDS_WARNING_ME), NULL, FALSE))
{
SetWindowLongPtrW (hwnd, DWLP_MSGRESULT, TRUE);
@@ -2741,9 +2401,9 @@ INT_PTR CALLBACK DlgProc (
}
else if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2))
{
- if (app_hash == config.svchost_hash)
+ if (app_hash == config.svchost_hash || app_hash == config.ntoskrnl_hash)
{
- if (!_r_show_confirmmessage (hwnd, L"WARNING!", SZ_WARNING_SVCHOST, NULL, FALSE))
+ if (!_r_show_confirmmessage (hwnd, L"WARNING!", _r_locale_getstring (IDS_WARNING_UNEXPECTED), NULL, FALSE))
{
SetWindowLongPtrW (hwnd, DWLP_MSGRESULT, TRUE);
@@ -2767,31 +2427,25 @@ INT_PTR CALLBACK DlgProc (
case LVN_ITEMCHANGED:
{
- LPNMLISTVIEW lpnmlv;
- HANDLE hengine;
- PR_LIST rules;
- PITEM_APP ptr_app;
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
PITEM_RULE ptr_rule;
+ PITEM_APP ptr_app;
+ PR_LIST rules;
ULONG_PTR rule_idx;
ULONG app_hash;
- INT listview_id;
- BOOLEAN is_changed = FALSE;
- BOOLEAN is_enabled;
-
- lpnmlv = (LPNMLISTVIEW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
+ BOOLEAN is_changed = FALSE, is_enabled;
if ((lpnmlv->uChanged & LVIF_STATE) == 0)
break;
if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (1) || ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2)))
{
- if (_app_listview_islocked (hwnd, listview_id))
+ if (_app_listview_islocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom))
break;
is_enabled = (lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2);
- if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP)
+ if (lpnmlv->hdr.idFrom >= IDC_APPS_PROFILE && lpnmlv->hdr.idFrom <= IDC_APPS_UWP)
{
app_hash = (ULONG)_app_listview_getcontextcode (lpnmlv->lParam);
ptr_app = _app_getappitem (app_hash);
@@ -2803,9 +2457,9 @@ INT_PTR CALLBACK DlgProc (
{
ptr_app->is_enabled = is_enabled;
- _app_listview_lock (hwnd, listview_id, TRUE);
- _app_setappiteminfo (hwnd, listview_id, lpnmlv->iItem, ptr_app);
- _app_listview_lock (hwnd, listview_id, FALSE);
+ _app_listview_lock (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom);
+ _app_setappiteminfo (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lpnmlv->iItem, ptr_app);
+ _app_listview_unlock (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom);
if (is_enabled)
_app_notify_freeobject (NULL, ptr_app);
@@ -2815,23 +2469,21 @@ INT_PTR CALLBACK DlgProc (
if (_wfp_isfiltersinstalled ())
{
- hengine = _wfp_getenginehandle ();
-
rules = _r_obj_createlist (1, NULL);
_r_obj_addlistitem (rules, ptr_app, NULL);
- _wfp_create3filters (hengine, rules, DBG_ARG, FALSE);
+ _wfp_createappfilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
_r_obj_dereference (rules);
- }
- is_changed = TRUE;
+ is_changed = TRUE;
+ }
}
_r_obj_dereference (ptr_app);
}
- else if (listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM)
+ else if (lpnmlv->hdr.idFrom >= IDC_RULES_BLOCKLIST && lpnmlv->hdr.idFrom <= IDC_RULES_CUSTOM)
{
rule_idx = _app_listview_getcontextcode (lpnmlv->lParam);
ptr_rule = _app_getrulebyid (rule_idx);
@@ -2841,27 +2493,25 @@ INT_PTR CALLBACK DlgProc (
if (ptr_rule->is_enabled != is_enabled)
{
- _app_listview_lock (hwnd, listview_id, TRUE);
+ _app_listview_lock (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom);
_app_ruleenable (ptr_rule, is_enabled, TRUE);
- _app_setruleiteminfo (hwnd, listview_id, lpnmlv->iItem, ptr_rule, TRUE);
+ _app_setruleiteminfo (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lpnmlv->iItem, ptr_rule, TRUE);
- _app_listview_lock (hwnd, listview_id, FALSE);
+ _app_listview_unlock (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom);
if (_wfp_isfiltersinstalled ())
{
- hengine = _wfp_getenginehandle ();
-
rules = _r_obj_createlist (1, NULL);
_r_obj_addlistitem (rules, ptr_rule, NULL);
- _wfp_create4filters (hengine, rules, DBG_ARG, FALSE);
+ _wfp_createrulefilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
_r_obj_dereference (rules);
- }
- is_changed = TRUE;
+ is_changed = TRUE;
+ }
}
_r_obj_dereference (ptr_rule);
@@ -2869,7 +2519,7 @@ INT_PTR CALLBACK DlgProc (
if (is_changed)
{
- _app_listview_updateby_id (hwnd, listview_id, 0);
+ _app_listview_updateby_id (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, 0);
_app_profile_save (hwnd);
}
@@ -2880,13 +2530,9 @@ INT_PTR CALLBACK DlgProc (
case LVN_GETDISPINFO:
{
- LPNMLVDISPINFOW lpnmlv;
- INT listview_id;
+ LPNMLVDISPINFOW lpnmlv = (LPNMLVDISPINFOW)lparam;
- lpnmlv = (LPNMLVDISPINFOW)lparam;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- _app_message_displayinfo (hwnd, listview_id, lpnmlv);
+ _app_message_displayinfo (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom, lpnmlv);
break;
}
@@ -2906,43 +2552,34 @@ INT_PTR CALLBACK DlgProc (
case NM_DBLCLK:
{
- LPNMITEMACTIVATE lpnmlv;
+ LPNMITEMACTIVATE lpnmlv = (LPNMITEMACTIVATE)lparam;
LPNMMOUSE lpmouse;
- INT command_id = 0;
- INT listview_id;
-
- lpnmlv = (LPNMITEMACTIVATE)lparam;
if (lpnmlv->iItem == INT_ERROR)
break;
- listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom;
-
- if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_LOG)
+ if (lpnmlv->hdr.idFrom >= IDC_APPS_PROFILE && lpnmlv->hdr.idFrom <= IDC_LOG)
{
- command_id = IDM_PROPERTIES;
+ _r_wnd_sendcommand (hwnd, IDM_PROPERTIES, 0);
}
- else if (listview_id == IDC_STATUSBAR)
+ else if (lpnmlv->hdr.idFrom == IDC_STATUSBAR)
{
lpmouse = (LPNMMOUSE)lparam;
if (lpmouse->dwItemSpec == 0)
{
- command_id = IDM_SELECT_ALL;
+ _r_wnd_sendcommand (hwnd, IDM_SELECT_ALL, 0);
}
else if (lpmouse->dwItemSpec == 1)
{
- command_id = IDM_PURGE_UNUSED;
+ _r_wnd_sendcommand (hwnd, IDM_PURGE_UNUSED, 0);
}
else if (lpmouse->dwItemSpec == 2)
{
- command_id = IDM_PURGE_TIMERS;
+ _r_wnd_sendcommand (hwnd, IDM_PURGE_TIMERS, 0);
}
}
- if (command_id)
- _r_ctrl_sendcommand (hwnd, command_id, 0);
-
break;
}
@@ -2977,16 +2614,10 @@ INT_PTR CALLBACK DlgProc (
{
case PBT_APMSUSPEND:
{
- HANDLE engine_handle;
-
_app_logclear_ui (hwnd);
if (config.is_neteventset)
- {
- engine_handle = _wfp_getenginehandle ();
-
- _wfp_logunsubscribe (engine_handle);
- }
+ _wfp_logunsubscribe (_wfp_getenginehandle ());
SetWindowLongPtrW (hwnd, DWLP_MSGRESULT, TRUE);
@@ -2996,14 +2627,8 @@ INT_PTR CALLBACK DlgProc (
case PBT_APMRESUMECRITICAL:
case PBT_APMRESUMESUSPEND:
{
- HANDLE engine_handle;
-
if (config.is_neteventset)
- {
- engine_handle = _wfp_getenginehandle ();
-
- _wfp_logsubscribe (hwnd, engine_handle);
- }
+ _wfp_logsubscribe (hwnd, _wfp_getenginehandle ());
SetWindowLongPtrW (hwnd, DWLP_MSGRESULT, TRUE);
@@ -3020,9 +2645,8 @@ INT_PTR CALLBACK DlgProc (
{
case DBT_DEVICEARRIVAL:
{
- PDEV_BROADCAST_HDR lbhdr;
PDEV_BROADCAST_VOLUME lpdbv;
- BOOLEAN is_appexist;
+ PDEV_BROADCAST_HDR lbhdr;
if (_wfp_isfiltersapplying () || !_wfp_isfiltersinstalled ())
break;
@@ -3033,9 +2657,7 @@ INT_PTR CALLBACK DlgProc (
{
lpdbv = (PDEV_BROADCAST_VOLUME)lparam;
- is_appexist = _app_isapphavedrive (FirstDriveFromMask (lpdbv->dbcv_unitmask));
-
- if (is_appexist)
+ if (_app_isapphavedrive (FirstDriveFromMask (lpdbv->dbcv_unitmask)))
_app_changefilters (hwnd, TRUE, FALSE);
}
@@ -3076,8 +2698,7 @@ INT_PTR CALLBACK DlgProc (
{
if (ctrl_id >= IDX_LANGUAGE && ctrl_id <= IDX_LANGUAGE + (INT)(INT_PTR)_r_locale_getcount () + 1)
{
- HMENU hsubmenu;
- HMENU hmenu;
+ HMENU hmenu, hsubmenu;
hmenu = GetMenu (hwnd);
@@ -3118,7 +2739,7 @@ INT_PTR CALLBACK DlgProc (
break;
}
- // fall through
+ FALLTHROUGH;
}
case IDM_TRAY_SHOW:
@@ -3169,11 +2790,7 @@ INT_PTR CALLBACK DlgProc (
case IDM_IMPORT:
{
- COMDLG_FILTERSPEC filters[] = {
- {L"Profile files (*.xml)", L"*.xml"},
- {L"All files (*.*)", L"*.*"},
- };
-
+ COMDLG_FILTERSPEC filters[] = {{L"Profile files (*.xml)", L"*.xml"}, {L"All files (*.*)", L"*.*"}};
R_FILE_DIALOG file_dialog;
R_STRINGREF sr;
PR_STRING path;
@@ -3217,11 +2834,7 @@ INT_PTR CALLBACK DlgProc (
case IDM_EXPORT:
{
- COMDLG_FILTERSPEC filters[] = {
- {L"Profile files (*.xml)", L"*.xml"},
- {L"All files (*.*)", L"*.*"},
- };
-
+ COMDLG_FILTERSPEC filters[] = {{L"Profile files (*.xml)", L"*.xml"}, {L"All files (*.*)", L"*.*"}};
R_FILE_DIALOG file_dialog;
R_STRINGREF sr;
PR_STRING path;
@@ -3244,13 +2857,13 @@ INT_PTR CALLBACK DlgProc (
if (SUCCEEDED (status))
{
- _app_profile_save (hwnd);
+ _app_profile_save (hwnd); // required!
- // added information for export profile failure (issue #707)
status = _r_fs_copyfile (&profile_info.profile_path->sr, &path->sr, FALSE);
+ // display message for export profile failure (issue #707)
if (!NT_SUCCESS (status))
- _r_show_errormessage (hwnd, NULL, status, path->buffer, ET_NATIVE);
+ _r_show_errormessage (hwnd, L"Could not create file copy!", status, path->buffer, ET_NATIVE);
_r_obj_dereference (path);
}
@@ -3264,12 +2877,9 @@ INT_PTR CALLBACK DlgProc (
case IDM_ALWAYSONTOP_CHK:
{
- BOOLEAN new_val;
-
- new_val = !_r_config_getboolean (L"AlwaysOnTop", FALSE, NULL);
+ BOOLEAN new_val = _r_config_invertboolean (L"AlwaysOnTop", FALSE, NULL);
_r_menu_checkitem (GetMenu (hwnd), ctrl_id, 0, MF_BYCOMMAND, new_val);
- _r_config_setboolean (L"AlwaysOnTop", new_val, NULL);
_r_wnd_top (hwnd, new_val);
@@ -3279,12 +2889,9 @@ INT_PTR CALLBACK DlgProc (
case IDM_AUTOSIZECOLUMNS_CHK:
{
PITEM_TAB_CONTEXT tab_context;
- BOOLEAN new_val;
-
- new_val = !_r_config_getboolean (L"AutoSizeColumns", TRUE, NULL);
+ BOOLEAN new_val = _r_config_invertboolean (L"AutoSizeColumns", TRUE, NULL);
_r_menu_checkitem (GetMenu (hwnd), ctrl_id, 0, MF_BYCOMMAND, new_val);
- _r_config_setboolean (L"AutoSizeColumns", new_val, NULL);
if (new_val)
{
@@ -3300,18 +2907,16 @@ INT_PTR CALLBACK DlgProc (
case IDM_SHOWFILENAMESONLY_CHK:
{
PITEM_TAB_CONTEXT tab_context;
- BOOLEAN new_val;
-
- new_val = !_r_config_getboolean (L"ShowFilenames", TRUE, NULL);
+ BOOLEAN new_val = _r_config_invertboolean (L"ShowFilenames", TRUE, NULL);
_r_menu_checkitem (GetMenu (hwnd), ctrl_id, 0, MF_BYCOMMAND, new_val);
- _r_config_setboolean (L"ShowFilenames", new_val, NULL);
tab_context = _app_listview_getcontext (hwnd, INT_ERROR);
if (tab_context)
{
_r_listview_redraw (hwnd, tab_context->listview_id);
+
_app_listview_sort (hwnd, tab_context->listview_id, INT_ERROR, FALSE);
}
@@ -3320,14 +2925,10 @@ INT_PTR CALLBACK DlgProc (
case IDM_SHOWSEARCHBAR_CHK:
{
- BOOLEAN new_val;
-
- new_val = !_r_config_getboolean (L"IsShowSearchBar", TRUE, NULL);
+ BOOLEAN new_val = _r_config_invertboolean (L"IsShowSearchBar", TRUE, NULL);
_r_menu_checkitem (GetMenu (hwnd), ctrl_id, 0, MF_BYCOMMAND, new_val);
- _r_config_setboolean (L"IsShowSearchBar", new_val, NULL);
-
if (config.hsearchbar)
_app_search_setvisible (hwnd, config.hsearchbar, _r_dc_getwindowdpi (hwnd));
@@ -3354,7 +2955,6 @@ INT_PTR CALLBACK DlgProc (
}
_r_menu_checkitem (GetMenu (hwnd), IDM_VIEW_DETAILS, IDM_VIEW_TILE, MF_BYCOMMAND, ctrl_id);
-
_r_config_setlong (L"ViewType", view_type, NULL);
_app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE);
@@ -3382,7 +2982,6 @@ INT_PTR CALLBACK DlgProc (
}
_r_menu_checkitem (GetMenu (hwnd), IDM_SIZE_SMALL, IDM_SIZE_EXTRALARGE, MF_BYCOMMAND, ctrl_id);
-
_r_config_setlong (L"IconSize", icon_size, NULL);
_app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE);
@@ -3394,13 +2993,9 @@ INT_PTR CALLBACK DlgProc (
{
PITEM_APP ptr_app = NULL;
ULONG_PTR enum_key = 0;
- INT listview_id;
- BOOLEAN new_val;
-
- new_val = !_r_config_getboolean (L"IsIconsHidden", FALSE, NULL);
+ BOOLEAN new_val = _r_config_invertboolean (L"IsIconsHidden", FALSE, NULL);
_r_menu_checkitem (GetMenu (hwnd), ctrl_id, 0, MF_BYCOMMAND, new_val);
- _r_config_setboolean (L"IsIconsHidden", new_val, NULL);
if (!new_val)
{
@@ -3408,12 +3003,7 @@ INT_PTR CALLBACK DlgProc (
while (_r_obj_enumhashtablepointer (apps_table, (PVOID_PTR)&ptr_app, NULL, &enum_key))
{
- if (!ptr_app->real_path)
- continue;
-
- listview_id = _app_listview_getbytype (ptr_app->type);
-
- _app_getfileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, listview_id);
+ _app_getfileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, _app_listview_getbytype (ptr_app->type));
}
_r_queuedlock_releaseshared (&lock_apps);
@@ -3528,13 +3118,9 @@ INT_PTR CALLBACK DlgProc (
case IDM_TRAY_ENABLELOG_CHK:
{
- BOOLEAN new_val;
+ BOOLEAN new_val = _r_config_invertboolean (L"IsLogEnabled", FALSE, NULL);
- new_val = !_r_config_getboolean (L"IsLogEnabled", FALSE, NULL);
-
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, ctrl_id, NULL, 0, new_val ? TBSTATE_PRESSED | TBSTATE_ENABLED : TBSTATE_ENABLED, I_IMAGENONE);
-
- _r_config_setboolean (L"IsLogEnabled", new_val, NULL);
+ _r_toolbar_pressbutton (config.hrebar, IDC_TOOLBAR, ctrl_id, new_val);
_app_loginit (new_val);
@@ -3543,13 +3129,9 @@ INT_PTR CALLBACK DlgProc (
case IDM_TRAY_ENABLEUILOG_CHK:
{
- BOOLEAN new_val;
+ BOOLEAN new_val = _r_config_invertboolean (L"IsLogUiEnabled", FALSE, NULL);
- new_val = !_r_config_getboolean (L"IsLogUiEnabled", FALSE, NULL);
-
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, ctrl_id, NULL, 0, new_val ? TBSTATE_PRESSED | TBSTATE_ENABLED : TBSTATE_ENABLED, I_IMAGENONE);
-
- _r_config_setboolean (L"IsLogUiEnabled", new_val, NULL);
+ _r_toolbar_pressbutton (config.hrebar, IDC_TOOLBAR, ctrl_id, new_val);
break;
}
@@ -3557,13 +3139,9 @@ INT_PTR CALLBACK DlgProc (
case IDM_TRAY_ENABLENOTIFICATIONS_CHK:
{
HWND hnotify;
- BOOLEAN new_val;
+ BOOLEAN new_val = _r_config_invertboolean (L"IsNotificationsEnabled", TRUE, NULL);
- new_val = !_r_config_getboolean (L"IsNotificationsEnabled", TRUE, NULL);
-
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, ctrl_id, NULL, 0, new_val ? TBSTATE_PRESSED | TBSTATE_ENABLED : TBSTATE_ENABLED, I_IMAGENONE);
-
- _r_config_setboolean (L"IsNotificationsEnabled", new_val, NULL);
+ _r_toolbar_pressbutton (config.hrebar, IDC_TOOLBAR, ctrl_id, new_val);
hnotify = _app_notify_getwindow (NULL);
@@ -3575,34 +3153,21 @@ INT_PTR CALLBACK DlgProc (
case IDM_TRAY_ENABLENOTIFICATIONSSOUND_CHK:
{
- BOOLEAN new_val;
-
- new_val = !_r_config_getboolean (L"IsNotificationsSound", TRUE, NULL);
-
- _r_config_setboolean (L"IsNotificationsSound", new_val, NULL);
-
+ _r_config_invertboolean (L"IsNotificationsSound", TRUE, NULL);
break;
}
case IDM_TRAY_NOTIFICATIONFULLSCREENSILENTMODE_CHK:
{
- BOOLEAN new_val;
-
- new_val = !_r_config_getboolean (L"IsNotificationsFullscreenSilentMode", TRUE, NULL);
-
- _r_config_setboolean (L"IsNotificationsFullscreenSilentMode", new_val, NULL);
-
+ _r_config_invertboolean (L"IsNotificationsFullscreenSilentMode", TRUE, NULL);
break;
}
case IDM_TRAY_NOTIFICATIONONTRAY_CHK:
{
HWND hnotify;
- BOOLEAN new_val;
- new_val = !_r_config_getboolean (L"IsNotificationsOnTray", FALSE, NULL);
-
- _r_config_setboolean (L"IsNotificationsOnTray", new_val, NULL);
+ _r_config_invertboolean (L"IsNotificationsOnTray", FALSE, NULL);
hnotify = _app_notify_getwindow (NULL);
@@ -3654,14 +3219,10 @@ INT_PTR CALLBACK DlgProc (
case IDM_ADD_FILE:
{
- COMDLG_FILTERSPEC filters[] = {
- {L"Executable files (*.exe)", L"*.exe"},
- {L"All files (*.*)", L"*.*"},
- };
-
+ COMDLG_FILTERSPEC filters[] = {{L"Executable files (*.exe)", L"*.exe"}, {L"All files (*.*)", L"*.*"}};
R_FILE_DIALOG file_dialog;
+ PITEM_APP ptr_app;
PR_STRING path;
- ULONG_PTR app_hash;
HRESULT status;
status = _r_filedialog_initialize (&file_dialog, PR_FILEDIALOG_OPENFILE);
@@ -3678,14 +3239,16 @@ INT_PTR CALLBACK DlgProc (
if (SUCCEEDED (status))
{
- app_hash = _app_addapplication (hwnd, DATA_UNKNOWN, path, NULL, NULL);
+ ptr_app = _app_addapplication (hwnd, DATA_UNKNOWN, path, NULL, NULL);
- if (app_hash)
+ if (ptr_app)
{
- _app_listview_updateby_param (hwnd, app_hash, PR_SETITEM_UPDATE, TRUE);
- _app_listview_showitemby_param (hwnd, app_hash, TRUE);
+ _app_listview_updateby_param (hwnd, ptr_app->app_hash, PR_SETITEM_UPDATE, TRUE);
+ _app_listview_showitemby_param (hwnd, ptr_app->app_hash, TRUE);
_app_profile_save (hwnd);
+
+ _r_obj_dereference (ptr_app);
}
_r_obj_dereference (path);
@@ -3744,7 +3307,7 @@ INT_PTR CALLBACK DlgProc (
status = _r_shell_showfile (&ptr_app->real_path->sr);
if (FAILED (status))
- _r_show_errormessage (hwnd, L"Cannot open file!", status, ptr_app->real_path->buffer, ET_WINDOWS);
+ _r_show_errormessage (hwnd, L"Cannot explore file!", status, ptr_app->real_path->buffer, ET_WINDOWS);
}
}
@@ -3768,7 +3331,7 @@ INT_PTR CALLBACK DlgProc (
status = _r_shell_showfile (&ptr_network->path->sr);
if (FAILED (status))
- _r_show_errormessage (hwnd, L"Cannot open file!", status, ptr_network->path->buffer, ET_WINDOWS);
+ _r_show_errormessage (hwnd, L"Cannot explore file!", status, ptr_network->path->buffer, ET_WINDOWS);
}
}
@@ -3792,7 +3355,7 @@ INT_PTR CALLBACK DlgProc (
status = _r_shell_showfile (&ptr_log->path->sr);
if (FAILED (status))
- _r_show_errormessage (hwnd, L"Cannot open file!", status, ptr_log->path->buffer, ET_WINDOWS);
+ _r_show_errormessage (hwnd, L"Cannot explore file!", status, ptr_log->path->buffer, ET_WINDOWS);
}
}
@@ -3865,8 +3428,7 @@ INT_PTR CALLBACK DlgProc (
case IDM_TAB_NEXT:
case IDM_TAB_PREV:
{
- INT tabs_count;
- INT item_id;
+ INT item_id, tabs_count;
tabs_count = _r_tab_getitemcount (hwnd, IDC_TAB);
@@ -3910,12 +3472,10 @@ BOOLEAN NTAPI _app_parseargs (
_In_ R_CMDLINE_INFO_CLASS info_class
)
{
- HANDLE hengine;
+ HANDLE hengine = _wfp_getenginehandle ();
_app_initialize (NULL);
- hengine = _wfp_getenginehandle ();
-
switch (info_class)
{
case CmdlineHelp:
@@ -3955,6 +3515,8 @@ BOOLEAN NTAPI _app_parseargs (
case CmdlineUninstall:
{
+ // -uninstall -silent never be implemented, only with confirmation, or every dumbass can disable filters!
+ // https://github.com/henrypp/simplewall/issues/1698#issuecomment-4532518363
if (_wfp_isfiltersinstalled () && _app_installmessage (NULL, FALSE))
{
_wfp_destroyfilters (hengine);
@@ -3979,7 +3541,6 @@ INT APIENTRY wWinMain (
)
{
HWND hwnd;
- ULONG result;
if (!_r_app_initialize (&_app_parseargs))
return ERROR_APP_INIT_FAILURE;
@@ -3989,7 +3550,5 @@ INT APIENTRY wWinMain (
if (!hwnd)
return ERROR_APP_INIT_FAILURE;
- result = _r_wnd_message_callback (hwnd, MAKEINTRESOURCE (IDA_MAIN));
-
- return result;
+ return _r_wnd_message_callback (hwnd, MAKEINTRESOURCE (IDA_MAIN));
}
diff --git a/src/main.h b/src/main.h
index dd77d661..3724c737 100644
--- a/src/main.h
+++ b/src/main.h
@@ -22,7 +22,7 @@
#pragma comment(lib, "wintrust.lib")
// log
-#define DBG_ARG TEXT (__FILE__), __LINE__
+#define DBG_ARG _r_path_getbasename2 (TEXT (__FILE__)), __LINE__
#define DBG_ARG_VAR file_name, line
// guids
@@ -75,12 +75,12 @@ typedef enum _ENUM_INFO_DATA
typedef enum _ENUM_INFO_DATA2
{
- INFO_ICON_ID,
+ INFO_ICON_ID = 0,
INFO_SIGNATURE_STRING, // dereference required
INFO_VERSION_STRING, // dereference required
} ENUM_INFO_DATA2;
-#define LOG_PATH_DEFAULT L"%USERPROFILE%\\" APP_NAME_SHORT L".log"
+#define LOG_PATH_DEFAULT L"%USERPROFILE%\\" APP_NAME_SHORT L".csv"
#define LOG_VIEWER_DEFAULT L"%SystemRoot%\\notepad.exe"
#define LOG_SIZE_LIMIT_DEFAULT _r_calc_kilobytes2bytes (1)
@@ -93,6 +93,7 @@ typedef enum _ENUM_INFO_DATA2
#define PATH_SVCHOST L"\\svchost.exe"
#define PATH_WUSVC L"\\wusvc.exe"
+#define WINDOWSSPYBLOCKER_TITLE L"Author: WindowsSpyBlocker - block spying and tracking on Windows systems."
#define WINDOWSSPYBLOCKER_URL L"https://github.com/crazy-max/WindowsSpyBlocker"
#define SZ_TAB L" "
@@ -114,10 +115,6 @@ typedef enum _ENUM_INFO_DATA2
#define SZ_LOG_BODY L"\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"," \
L"\"%s\",\"%s\",\"#%" TEXT (PRIu64) L"\",\"%s\",\"%s\"" SZ_CRLF
-#define SZ_WARNING_ME L"If you disallow this, you cannot use resolve network addresses option. Continue?"
-#define SZ_WARNING_SVCHOST L"Be careful, through service host (svchost.exe)" \
- L"internet traffic can let out through unexpected ways. Continue?"
-
#define SZ_HELP L"\"simplewall.exe -install\" - enable filtering." SZ_CRLF \
L"\"simplewall.exe -install -temp\" - enable filtering until reboot." SZ_CRLF \
L"\"simplewall.exe -install -silent\" - enable filtering without prompt." SZ_CRLF \
@@ -130,10 +127,10 @@ typedef enum _ENUM_INFO_DATA2
#define DIVIDER_RULE_RANGE L'-'
#define DIVIDER_TRIM SZ_CRLF L" "
-#define BACKUP_HOURS_PERIOD _r_calc_hours2seconds (4) // make backup every X hour(s) (default)
+#define BACKUP_HOURS_PERIOD _r_calc_hours2seconds (4) // made backup every X hour(s) (default)
-#define LEN_IP_MAX 68
-#define MAP_CACHE_MAX 900 // limit for caching hashtable
+#define LEN_IP_MAX 0x44
+#define MAP_CACHE_MAX 0x0384 // limit for caching hashtable
#define TRANSACTION_TIMEOUT 9000
@@ -153,20 +150,17 @@ typedef enum _ENUM_INFO_DATA2
// notifications
#define NOTIFY_TIMER_SAFETY_TIMEOUT 900
-#define NOTIFY_TIMER_SAFETY_ID 666
-
#define NOTIFY_TIMEOUT_DEFAULT 60 // sec.
-
#define NOTIFY_SOUND_NAME L"MailBeep"
// default colors
-#define LV_COLOR_INVALID RGB(255, 125, 148)
-#define LV_COLOR_SPECIAL RGB(255, 255, 170)
-#define LV_COLOR_SIGNED RGB(175, 228, 163)
-#define LV_COLOR_PICO RGB(51, 153, 255)
-#define LV_COLOR_SYSTEM RGB(151, 196, 251)
-#define LV_COLOR_CONNECTION RGB(255, 168, 242)
-#define LV_COLOR_UNDELETE RGB(211, 211, 211)
+#define LV_COLOR_INVALID RGB(0xFF, 0x7C, 0x94)
+#define LV_COLOR_SPECIAL RGB(0xFF, 0xFF, 0xAA)
+#define LV_COLOR_SIGNED RGB(0xAE, 0xE4, 0xA2)
+#define LV_COLOR_PICO RGB(0x32, 0x98, 0xFF)
+#define LV_COLOR_SYSTEM RGB(0x96, 0xC4, 0xFA)
+#define LV_COLOR_CONNECTION RGB(0xFF, 0xA8, 0xF2)
+#define LV_COLOR_UNDELETE RGB(0xD4, 0xD4, 0xD4)
// memory limitation for 1 rule
#define RULE_NAME_CCH_MAX 0x0040 // 64
@@ -174,18 +168,17 @@ typedef enum _ENUM_INFO_DATA2
typedef struct _STATIC_DATA
{
- WCHAR windows_dir_buffer[256];
R_STRINGREF windows_dir;
GUID session_key;
PR_STRING search_string;
- PR_STRING my_path;
PR_STRING ntoskrnl_path;
PR_STRING svchost_path;
- PR_STRING wusvc_path;
PR_STRING system_path;
+ PR_STRING wusvc_path;
+ PR_STRING my_path;
PR_BYTE service_wdiservicehost_sid;
PR_BYTE service_policyagent_sid;
@@ -251,6 +244,54 @@ typedef struct _PROFILE_DATA
LONG64 profile_internal_timestamp;
} PROFILE_DATA, *PPROFILE_DATA;
+typedef struct _ITEM_LOG
+{
+ union
+ {
+ IN6_ADDR remote_addr6;
+ IN_ADDR remote_addr;
+ } DUMMYUNIONNAME;
+
+ union
+ {
+ IN6_ADDR local_addr6;
+ IN_ADDR local_addr;
+ } DUMMYUNIONNAME2;
+
+ PR_STRING protocol_str;
+ PR_STRING filter_name;
+ PR_STRING layer_name;
+ PR_STRING username;
+ PR_STRING path;
+
+ volatile PR_STRING remote_addr_str;
+ volatile PR_STRING local_addr_str;
+ volatile PR_STRING remote_host_str;
+ volatile PR_STRING local_host_str;
+
+ LONG64 timestamp;
+
+ UINT64 filter_id;
+
+ ULONG app_hash;
+
+ volatile LONG log_id;
+
+ FWP_DIRECTION direction;
+ ADDRESS_FAMILY af;
+
+ UINT16 remote_port;
+ UINT16 local_port;
+ UINT8 protocol;
+
+ BOOLEAN is_myprovider;
+ BOOLEAN is_blocklist;
+ BOOLEAN is_loopback;
+ BOOLEAN is_custom;
+ BOOLEAN is_system;
+ BOOLEAN is_allow;
+} ITEM_LOG, *PITEM_LOG;
+
typedef struct _ITEM_APP
{
PR_ARRAY guids;
@@ -262,7 +303,7 @@ typedef struct _ITEM_APP
PR_STRING comment;
PR_STRING hash;
- PVOID notification; // PITEM_LOG
+ PITEM_LOG notification;
PR_BYTE bytes; // service - PSECURITY_DESCRIPTOR / uwp - PSID (win8+)
PTP_TIMER htimer;
@@ -291,15 +332,11 @@ typedef struct _ITEM_APP_INFO
{
PR_STRING signature_info;
PR_STRING version_info;
-
PR_STRING path;
ULONG app_hash;
-
LONG icon_id;
-
ENUM_TYPE_DATA type;
-
INT listview_id;
BOOLEAN is_loaded;
@@ -317,21 +354,11 @@ typedef struct _ITEM_RULE
PR_HASHTABLE apps;
PR_ARRAY guids;
- PR_STRING name;
- PR_STRING comment;
+ PR_STRING protocol_str;
PR_STRING rule_remote;
PR_STRING rule_local;
- PR_STRING protocol_str;
-
- struct
- {
- ULONG is_enabled_default : 1;
- ULONG is_forservices : 1;
- ULONG is_haveerrors : 1;
- ULONG is_readonly : 1;
- ULONG is_enabled : 1;
- ULONG spare_bits : 27;
- } DUMMYSTRUCTNAME;
+ PR_STRING comment;
+ PR_STRING name;
union
{
@@ -345,8 +372,19 @@ typedef struct _ITEM_RULE
} DUMMYSTRUCTNAME2;
} DUMMYUNIONNAME;
- ENUM_TYPE_DATA type;
+ struct
+ {
+ ULONG is_enabled_default : 1;
+ ULONG is_forservice : 1;
+ ULONG is_fordriver : 1;
+ ULONG is_haveerrors : 1;
+ ULONG is_readonly : 1;
+ ULONG is_enabled : 1;
+ ULONG spare_bits : 26;
+ } DUMMYSTRUCTNAME2;
+ ULONG rule_hash;
+ ENUM_TYPE_DATA type;
FWP_ACTION_TYPE action;
UINT8 profile; // reserved ffu!
@@ -375,15 +413,13 @@ typedef struct _ITEM_NETWORK
IN6_ADDR local_addr6;
} DUMMYUNIONNAME2;
- PR_STRING path;
-
volatile PR_STRING local_addr_str;
volatile PR_STRING remote_addr_str;
-
volatile PR_STRING local_host_str;
volatile PR_STRING remote_host_str;
PR_STRING protocol_str;
+ PR_STRING path;
ULONG app_hash;
ULONG state;
@@ -400,66 +436,15 @@ typedef struct _ITEM_NETWORK
BOOLEAN is_connection;
} ITEM_NETWORK, *PITEM_NETWORK;
-typedef struct _ITEM_LOG
-{
- union
- {
- IN_ADDR remote_addr;
- IN6_ADDR remote_addr6;
- } DUMMYUNIONNAME;
-
- union
- {
- IN_ADDR local_addr;
- IN6_ADDR local_addr6;
- } DUMMYUNIONNAME2;
-
- PR_STRING path;
- PR_STRING filter_name;
- PR_STRING layer_name;
- PR_STRING username;
- PR_STRING protocol_str;
-
- volatile PR_STRING local_addr_str;
- volatile PR_STRING remote_addr_str;
-
- volatile PR_STRING local_host_str;
- volatile PR_STRING remote_host_str;
-
- LONG64 timestamp;
-
- UINT64 filter_id;
-
- ULONG app_hash;
-
- volatile LONG log_id;
-
- FWP_DIRECTION direction;
-
- ADDRESS_FAMILY af;
-
- UINT16 remote_port;
- UINT16 local_port;
-
- UINT8 protocol;
-
- BOOLEAN is_allow;
- BOOLEAN is_loopback;
- BOOLEAN is_blocklist;
- BOOLEAN is_custom;
- BOOLEAN is_system;
- BOOLEAN is_myprovider;
-} ITEM_LOG, *PITEM_LOG;
-
typedef struct _ITEM_STATUS
{
- ULONG_PTR apps_count;
- ULONG_PTR apps_timer_count;
- ULONG_PTR apps_unused_count;
- ULONG_PTR rules_count;
- ULONG_PTR rules_global_count;
ULONG_PTR rules_predefined_count;
+ ULONG_PTR apps_unused_count;
+ ULONG_PTR apps_timer_count;
+ ULONG_PTR rules_global_count;
ULONG_PTR rules_user_count;
+ ULONG_PTR rules_count;
+ ULONG_PTR apps_count;
} ITEM_STATUS, *PITEM_STATUS;
typedef struct _ITEM_CONTEXT
@@ -481,8 +466,8 @@ typedef struct _ITEM_CONTEXT
typedef struct _ITEM_COLOR
{
- PR_STRING config_name;
PR_STRING config_value;
+ PR_STRING config_name;
COLORREF default_clr;
COLORREF new_clr;
ULONG locale_id;
@@ -501,17 +486,17 @@ typedef struct _ITEM_ADDRESS
struct
{
- FWP_RANGE range;
+ FWP_RANGE0 range;
- UINT8 addr6_low[FWP_V6_ADDR_SIZE];
UINT8 addr6_high[FWP_V6_ADDR_SIZE];
+ UINT8 addr6_low[FWP_V6_ADDR_SIZE];
} DUMMYSTRUCTNAME;
} DUMMYUNIONNAME;
- UINT16 port;
-
- ENUM_TYPE_DATA type;
NET_ADDRESS_FORMAT format;
+ ENUM_TYPE_DATA type;
+
+ UINT16 port;
BOOLEAN is_range;
} ITEM_ADDRESS, *PITEM_ADDRESS;
@@ -521,13 +506,13 @@ typedef struct _ITEM_LOG_CALLBACK
union
{
const FWP_BYTE_ARRAY16 *remote_addr6;
- ULONG_PTR remote_addr4;
+ ULONG remote_addr4;
} DUMMYUNIONNAME;
union
{
const FWP_BYTE_ARRAY16 *local_addr6;
- ULONG_PTR local_addr4;
+ ULONG local_addr4;
} DUMMYUNIONNAME2;
FILETIME timestamp;
@@ -539,16 +524,15 @@ typedef struct _ITEM_LOG_CALLBACK
FWP_IP_VERSION version;
- UINT32 flags;
UINT32 direction;
-
+ UINT32 flags;
UINT16 remote_port;
UINT16 local_port;
UINT16 layer_id;
UINT8 protocol;
- BOOLEAN is_allow;
BOOLEAN is_loopback;
+ BOOLEAN is_allow;
} ITEM_LOG_CALLBACK, *PITEM_LOG_CALLBACK;
typedef struct _ITEM_TAB_CONTEXT
diff --git a/src/messages.c b/src/messages.c
index 2bac3099..bc450dda 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -7,18 +7,14 @@ VOID _app_message_initialize (
_In_ HWND hwnd
)
{
- ENUM_INSTALL_TYPE install_type;
HMENU hmenu;
- LONG icon_size;
- LONG view_type;
- UINT menu_id;
+ LONG icon_size, view_type;
+ ULONG menu_id;
BOOLEAN is_enabled;
- install_type = _wfp_getinstalltype ();
-
_r_tray_create (hwnd, &GUID_TrayIcon, RM_TRAYICON, NULL, NULL, FALSE);
- _app_settrayicon (hwnd, install_type);
+ _app_settrayicon (hwnd, _wfp_getinstalltype ());
hmenu = GetMenu (hwnd);
@@ -77,7 +73,7 @@ VOID _app_message_initialize (
_r_menu_checkitem (hmenu, IDM_RULE_ALLOW6TO4, 0, MF_BYCOMMAND, _r_config_getboolean (L"AllowIPv6", TRUE, NULL));
_r_menu_checkitem (hmenu, IDM_RULE_ALLOWWINDOWSUPDATE, 0, MF_BYCOMMAND, _app_wufixenabled ());
- if (!_r_sys_isosversiongreaterorequal (WINDOWS_10))
+ if (_r_sys_isosversionlower (WINDOWS_10))
_r_menu_enableitem (hmenu, IDM_RULE_ALLOWWINDOWSUPDATE, FALSE, FALSE);
_r_menu_checkitem (hmenu, IDM_PROFILETYPE_PLAIN, IDM_PROFILETYPE_ENCRYPTED, MF_BYCOMMAND, IDM_PROFILETYPE_PLAIN + _r_calc_clamp (_r_config_getlong (L"ProfileType", 0, NULL), 0, 2));
@@ -87,65 +83,27 @@ VOID _app_message_initialize (
_r_menu_checkitem (hmenu, IDM_USECERTIFICATES_CHK, 0, MF_BYCOMMAND, _r_config_getboolean (L"IsCertificatesEnabled", TRUE, NULL));
_r_menu_checkitem (hmenu, IDM_KEEPUNUSED_CHK, 0, MF_BYCOMMAND, _r_config_getboolean (L"IsKeepUnusedApps", TRUE, NULL));
_r_menu_checkitem (hmenu, IDM_USEHASHES_CHK, 0, MF_BYCOMMAND, is_enabled);
- _r_menu_checkitem (hmenu, IDM_USENETWORKRESOLUTION_CHK, 0, MF_BYCOMMAND, _r_config_getboolean (L"IsNetworkResolutionsEnabled", FALSE, NULL));
+ _r_menu_checkitem (hmenu, IDM_USENETWORKRESOLUTION_CHK, 0, MF_BYCOMMAND, _r_config_getboolean (L"IsNetworkResolutionsEnabled", TRUE, NULL));
_r_menu_checkitem (hmenu, IDM_USEAPPMONITOR_CHK, 0, MF_BYCOMMAND, _r_config_getboolean (L"IsEnableAppMonitor", FALSE, NULL));
_r_menu_enableitem (hmenu, IDM_USEAPPMONITOR_CHK, FALSE, is_enabled);
- _r_menu_checkitem (
- hmenu,
- IDM_BLOCKLIST_SPY_DISABLE,
- IDM_BLOCKLIST_SPY_BLOCK,
- MF_BYCOMMAND,
- IDM_BLOCKLIST_SPY_DISABLE + _r_calc_clamp (_r_config_getlong (L"BlocklistSpyState", 2, NULL), 0, 2)
- );
+ menu_id = (IDM_BLOCKLIST_SPY_DISABLE + _r_calc_clamp (_r_config_getlong (L"BlocklistSpyState", 2, NULL), 0, 2));
- _r_menu_checkitem (
- hmenu,
- IDM_BLOCKLIST_UPDATE_DISABLE,
- IDM_BLOCKLIST_UPDATE_BLOCK,
- MF_BYCOMMAND,
- IDM_BLOCKLIST_UPDATE_DISABLE + _r_calc_clamp (_r_config_getlong (L"BlocklistUpdateState", 0, NULL), 0, 2)
- );
+ _r_menu_checkitem (hmenu, IDM_BLOCKLIST_SPY_DISABLE, IDM_BLOCKLIST_SPY_BLOCK, MF_BYCOMMAND, menu_id);
- _r_menu_checkitem (
- hmenu,
- IDM_BLOCKLIST_EXTRA_DISABLE,
- IDM_BLOCKLIST_EXTRA_BLOCK,
- MF_BYCOMMAND,
- IDM_BLOCKLIST_EXTRA_DISABLE + _r_calc_clamp (_r_config_getlong (L"BlocklistExtraState", 0, NULL), 0, 2)
- );
+ menu_id = (IDM_BLOCKLIST_UPDATE_DISABLE + _r_calc_clamp (_r_config_getlong (L"BlocklistUpdateState", 0, NULL), 0, 2));
+
+ _r_menu_checkitem (hmenu, IDM_BLOCKLIST_UPDATE_DISABLE, IDM_BLOCKLIST_UPDATE_BLOCK, MF_BYCOMMAND, menu_id);
+
+ menu_id = (IDM_BLOCKLIST_EXTRA_DISABLE + _r_calc_clamp (_r_config_getlong (L"BlocklistExtraState", 0, NULL), 0, 2));
+
+ _r_menu_checkitem (hmenu, IDM_BLOCKLIST_EXTRA_DISABLE, IDM_BLOCKLIST_EXTRA_BLOCK, MF_BYCOMMAND, menu_id);
}
- _r_toolbar_setbutton (
- config.hrebar,
- IDC_TOOLBAR,
- IDM_TRAY_ENABLENOTIFICATIONS_CHK,
- NULL,
- 0,
- _r_config_getboolean (L"IsNotificationsEnabled", TRUE, NULL) ? TBSTATE_PRESSED | TBSTATE_ENABLED : TBSTATE_ENABLED,
- I_IMAGENONE
- );
-
- _r_toolbar_setbutton (
- config.hrebar,
- IDC_TOOLBAR,
- IDM_TRAY_ENABLELOG_CHK,
- NULL,
- 0,
- _r_config_getboolean (L"IsLogEnabled", FALSE, NULL) ? TBSTATE_PRESSED | TBSTATE_ENABLED : TBSTATE_ENABLED,
- I_IMAGENONE
- );
-
- _r_toolbar_setbutton (
- config.hrebar,
- IDC_TOOLBAR,
- IDM_TRAY_ENABLEUILOG_CHK,
- NULL,
- 0,
- _r_config_getboolean (L"IsLogUiEnabled", FALSE, NULL) ? TBSTATE_PRESSED | TBSTATE_ENABLED : TBSTATE_ENABLED,
- I_IMAGENONE
- );
+ _r_toolbar_pressbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLENOTIFICATIONS_CHK, _r_config_getboolean (L"IsNotificationsEnabled", TRUE, NULL));
+ _r_toolbar_pressbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLELOG_CHK, _r_config_getboolean (L"IsLogEnabled", FALSE, NULL));
+ _r_toolbar_pressbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLEUILOG_CHK, _r_config_getboolean (L"IsLogUiEnabled", FALSE, NULL));
}
VOID _app_message_localize (
@@ -155,14 +113,11 @@ VOID _app_message_localize (
PITEM_TAB_CONTEXT tab_context;
PR_STRING localized_string = NULL;
LPCWSTR recommended_string;
- HMENU hmenu;
- HMENU hsubmenu;
+ HMENU hmenu, hsubmenu;
LONG dpi_value;
hmenu = GetMenu (hwnd);
- dpi_value = _r_dc_getwindowdpi (hwnd);
-
if (hmenu)
{
_r_menu_setitemtext (hmenu, 0, TRUE, _r_locale_getstring (IDS_FILE));
@@ -173,77 +128,17 @@ VOID _app_message_localize (
_r_menu_setitemtext (hmenu, 5, TRUE, _r_locale_getstring (IDS_HELP));
// file submenu
- _r_menu_setitemtextformat (
- hmenu,
- IDM_SETTINGS,
- FALSE,
- L"%s...\tF2",
- _r_locale_getstring (IDS_SETTINGS)
- );
-
- _r_menu_setitemtextformat (
- hmenu,
- IDM_ADD_FILE,
- FALSE,
- L"%s...",
- _r_locale_getstring (IDS_ADD_FILE)
- );
-
- _r_menu_setitemtextformat (
- hmenu,
- IDM_IMPORT,
- FALSE,
- L"%s...\tCtrl+O",
- _r_locale_getstring (IDS_IMPORT)
- );
-
- _r_menu_setitemtextformat (
- hmenu,
- IDM_EXPORT,
- FALSE,
- L"%s...\tCtrl+S",
- _r_locale_getstring (IDS_EXPORT)
- );
-
- _r_menu_setitemtextformat (
- hmenu,
- IDM_EXIT,
- FALSE,
- _r_locale_getstring (IDS_EXIT)
- );
+ _r_menu_setitemtextformat (hmenu, IDM_SETTINGS, FALSE, L"%s...\tF2", _r_locale_getstring (IDS_SETTINGS));
+ _r_menu_setitemtextformat (hmenu, IDM_ADD_FILE, FALSE, L"%s...", _r_locale_getstring (IDS_ADD_FILE));
+ _r_menu_setitemtextformat (hmenu, IDM_IMPORT, FALSE, L"%s...\tCtrl+O", _r_locale_getstring (IDS_IMPORT));
+ _r_menu_setitemtextformat (hmenu, IDM_EXPORT, FALSE, L"%s...\tCtrl+S", _r_locale_getstring (IDS_EXPORT));
+ _r_menu_setitemtextformat (hmenu, IDM_EXIT, FALSE, _r_locale_getstring (IDS_EXIT));
// edit submenu
- _r_menu_setitemtextformat (
- hmenu,
- IDM_PURGE_UNUSED,
- FALSE,
- L"%s\tCtrl+Shift+X",
- _r_locale_getstring (IDS_PURGE_UNUSED)
- );
-
- _r_menu_setitemtextformat (
- hmenu,
- IDM_PURGE_TIMERS,
- FALSE,
- L"%s\tCtrl+Shift+T",
- _r_locale_getstring (IDS_PURGE_TIMERS)
- );
-
- _r_menu_setitemtextformat (
- hmenu,
- IDM_LOGCLEAR,
- FALSE,
- L"%s\tCtrl+X",
- _r_locale_getstring (IDS_LOGCLEAR)
- );
-
- _r_menu_setitemtextformat (
- hmenu,
- IDM_REFRESH,
- FALSE,
- L"%s\tF5",
- _r_locale_getstring (IDS_REFRESH)
- );
+ _r_menu_setitemtextformat (hmenu, IDM_PURGE_UNUSED, FALSE, L"%s\tCtrl+Shift+X", _r_locale_getstring (IDS_PURGE_UNUSED));
+ _r_menu_setitemtextformat (hmenu, IDM_PURGE_TIMERS, FALSE, L"%s\tCtrl+Shift+T", _r_locale_getstring (IDS_PURGE_TIMERS));
+ _r_menu_setitemtextformat (hmenu, IDM_LOGCLEAR, FALSE, L"%s\tCtrl+X", _r_locale_getstring (IDS_LOGCLEAR));
+ _r_menu_setitemtextformat (hmenu, IDM_REFRESH, FALSE, L"%s\tF5", _r_locale_getstring (IDS_REFRESH));
// view submenu
_r_menu_setitemtext (hmenu, IDM_ALWAYSONTOP_CHK, FALSE, _r_locale_getstring (IDS_ALWAYSONTOP_CHK));
@@ -268,14 +163,7 @@ VOID _app_message_localize (
if (hsubmenu)
{
_r_menu_setitemtext (hsubmenu, ICONS_MENU, TRUE, _r_locale_getstring (IDS_ICONS));
-
- _r_menu_setitemtextformat (
- hsubmenu,
- LANG_MENU,
- TRUE,
- L"%s (Language)",
- _r_locale_getstring (IDS_LANGUAGE)
- );
+ _r_menu_setitemtextformat (hsubmenu, LANG_MENU, TRUE, L"%s (Language)", _r_locale_getstring (IDS_LANGUAGE));
_r_locale_enum (hsubmenu, LANG_MENU, IDX_LANGUAGE); // enum localizations
}
@@ -293,7 +181,7 @@ VOID _app_message_localize (
_r_menu_setitemtext (hmenu, IDM_RULE_ALLOWLOOPBACK, FALSE, _r_locale_getstring (IDS_RULE_ALLOWLOOPBACK));
_r_menu_setitemtext (hmenu, IDM_RULE_ALLOW6TO4, FALSE, _r_locale_getstring (IDS_RULE_ALLOW6TO4));
- _r_menu_setitemtext (hmenu, IDM_RULE_ALLOWWINDOWSUPDATE, FALSE, _r_locale_getstring (IDS_RULE_ALLOWWINDOWSUPDATE));
+ _r_menu_setitemtextformat (hmenu, IDM_RULE_ALLOWWINDOWSUPDATE, FALSE, L"%s (win10+)", _r_locale_getstring (IDS_RULE_ALLOWWINDOWSUPDATE));
_r_menu_setitemtext (hmenu, IDM_PROFILETYPE_PLAIN, FALSE, _r_locale_getstring (IDS_PROFILE_TYPE_PLAIN));
_r_menu_setitemtext (hmenu, IDM_PROFILETYPE_COMPRESSED, FALSE, _r_locale_getstring (IDS_PROFILE_TYPE_COMPRESSED));
@@ -344,27 +232,29 @@ VOID _app_message_localize (
}
// localize toolbar
+ dpi_value = _r_dc_getwindowdpi (hwnd);
+
_app_setinterfacestate (hwnd, dpi_value);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_REFRESH, _r_locale_getstring (IDS_REFRESH), BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT, 0, I_IMAGENONE);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_SETTINGS, _r_locale_getstring (IDS_SETTINGS), BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_REFRESH, _r_locale_getstring (IDS_REFRESH), BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT, 0, I_DEFAULT);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_SETTINGS, _r_locale_getstring (IDS_SETTINGS), BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT, 0, I_DEFAULT);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s...", _r_locale_getstring (IDS_OPENRULESEDITOR)));
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_OPENRULESEDITOR, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_OPENRULESEDITOR, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_DEFAULT);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLENOTIFICATIONS_CHK, _r_locale_getstring (IDS_ENABLENOTIFICATIONS_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_IMAGENONE);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLELOG_CHK, _r_locale_getstring (IDS_ENABLELOG_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLENOTIFICATIONS_CHK, _r_locale_getstring (IDS_ENABLENOTIFICATIONS_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_DEFAULT);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLELOG_CHK, _r_locale_getstring (IDS_ENABLELOG_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_DEFAULT);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_ENABLEUILOG_CHK), _r_locale_getstring (IDS_SESSION_ONLY)));
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLEUILOG_CHK, localized_string->buffer, BTNS_CHECK | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLEUILOG_CHK, localized_string->buffer, BTNS_CHECK | BTNS_AUTOSIZE, 0, I_DEFAULT);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (Ctrl+I)", _r_locale_getstring (IDS_LOGSHOW)));
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGSHOW, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGSHOW, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_DEFAULT);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (Ctrl+X)", _r_locale_getstring (IDS_LOGCLEAR)));
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGCLEAR, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGCLEAR, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_DEFAULT);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_DONATE, _r_locale_getstring (IDS_DONATE), BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_DONATE, _r_locale_getstring (IDS_DONATE), BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_DEFAULT);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s... (Ctrl+F)", _r_locale_getstring (IDS_FIND)));
_r_edit_setcuebanner (config.hrebar, IDC_SEARCH, localized_string->buffer);
@@ -435,30 +325,30 @@ VOID _app_message_localize (
case IDC_LOG:
{
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 1, _r_locale_getstring (IDS_NAME), 0);
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 2, _r_locale_getstring (IDS_DATE), 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 0, _r_locale_getstring (IDS_NAME), 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 1, _r_locale_getstring (IDS_DATE), 0);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_ADDRESS), _r_locale_getstring (IDS_DIRECTION_LOCAL)));
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 3, localized_string->buffer, 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 2, localized_string->buffer, 0);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_HOST), _r_locale_getstring (IDS_DIRECTION_LOCAL)));
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 4, localized_string->buffer, 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 3, localized_string->buffer, 0);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_PORT), _r_locale_getstring (IDS_DIRECTION_LOCAL)));
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 5, localized_string->buffer, 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 4, localized_string->buffer, 0);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_ADDRESS), _r_locale_getstring (IDS_DIRECTION_REMOTE)));
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 6, localized_string->buffer, 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 5, localized_string->buffer, 0);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_HOST), _r_locale_getstring (IDS_DIRECTION_REMOTE)));
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 7, localized_string->buffer, 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 6, localized_string->buffer, 0);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_PORT), _r_locale_getstring (IDS_DIRECTION_REMOTE)));
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 8, localized_string->buffer, 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 7, localized_string->buffer, 0);
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 9, _r_locale_getstring (IDS_PROTOCOL), 0);
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 10, _r_locale_getstring (IDS_DIRECTION), 0);
- _r_listview_setcolumn (hwnd, tab_context->listview_id, 11, _r_locale_getstring (IDS_FILTER), 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 8, _r_locale_getstring (IDS_PROTOCOL), 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 9, _r_locale_getstring (IDS_DIRECTION), 0);
+ _r_listview_setcolumn (hwnd, tab_context->listview_id, 10, _r_locale_getstring (IDS_FILTER), 0);
break;
}
@@ -471,13 +361,6 @@ VOID _app_message_localize (
_r_obj_dereference (localized_string);
}
-VOID _app_message_uninitialize (
- _In_ HWND hwnd
-)
-{
- _r_tray_destroy (hwnd, &GUID_TrayIcon);
-}
-
VOID _app_generate_appmenu (
_In_ HMENU hmenu,
_In_opt_ HMENU hsubmenu_rules,
@@ -490,7 +373,7 @@ VOID _app_generate_appmenu (
// show rules
if (hsubmenu_rules)
{
- _r_menu_addsubmenu (hmenu, INT_ERROR, hsubmenu_rules, _r_locale_getstring (IDS_TRAY_RULES));
+ _r_menu_addsubmenu (hmenu, MAXUINT, hsubmenu_rules, _r_locale_getstring (IDS_TRAY_RULES));
_r_menu_additem (hsubmenu_rules, IDM_DISABLENOTIFICATIONS, _r_locale_getstring (IDS_DISABLENOTIFICATIONS));
_r_menu_additem (hsubmenu_rules, IDM_DISABLEREMOVAL, _r_locale_getstring (IDS_DISABLEREMOVAL));
@@ -506,7 +389,7 @@ VOID _app_generate_appmenu (
// show timers
if (hsubmenu_timers)
{
- _r_menu_addsubmenu (hmenu, INT_ERROR, hsubmenu_timers, _r_locale_getstring (IDS_TIMER));
+ _r_menu_addsubmenu (hmenu, MAXUINT, hsubmenu_timers, _r_locale_getstring (IDS_TIMER));
_r_menu_additem (hsubmenu_timers, IDM_DISABLETIMER, _r_locale_getstring (IDS_DISABLETIMER));
_r_menu_addseparator (hsubmenu_timers);
@@ -517,23 +400,142 @@ VOID _app_generate_appmenu (
_r_menu_addseparator (hmenu);
}
+VOID _app_generate_rulescontrol (
+ _In_ HMENU hsubmenu,
+ _In_ ULONG app_hash,
+ _In_opt_ PITEM_LOG ptr_log
+)
+{
+ ITEM_STATUS info_status;
+ PITEM_RULE ptr_rule;
+ WCHAR buffer[0x80];
+ ULONG_PTR limit_count, i;
+ BOOLEAN is_enabled, is_global;
+
+ _app_getcount (&info_status);
+
+ if (info_status.rules_count == 0)
+ {
+ _r_menu_additem_ex (hsubmenu, IDX_RULES_SPECIAL, _r_locale_getstring (IDS_STATUS_EMPTY), MF_DISABLED);
+ }
+ else
+ {
+ for (ULONG_PTR type = 0; type < 2; type++)
+ {
+ if (type == 0)
+ {
+ if (info_status.rules_predefined_count == 0)
+ continue;
+ }
+ else
+ {
+ if (info_status.rules_user_count == 0)
+ continue;
+ }
+
+ for (ULONG_PTR loop = 0; loop < 2; loop++)
+ {
+ limit_count = 14; // limit rules for menu
+
+ _r_queuedlock_acquireshared (&lock_rules);
+
+ for (i = 0; i < _r_obj_getlistsize (rules_list) && limit_count; i++)
+ {
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
+
+ if (!ptr_rule || ptr_rule->type != DATA_RULE_USER)
+ continue;
+
+ is_global = (ptr_rule->is_enabled && _r_obj_isempty (ptr_rule->apps));
+ is_enabled = is_global || (ptr_rule->is_enabled && (_r_obj_findhashtable (ptr_rule->apps, app_hash)));
+
+ if ((type == 0 && (!ptr_rule->is_readonly || is_global)) || (type == 1 && (ptr_rule->is_readonly || is_global)))
+ continue;
+
+ if ((loop == 0 && !is_enabled) || (loop == 1 && is_enabled))
+ continue;
+
+ _r_str_printf (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_RULE_APPLY_2), _r_obj_getstring (ptr_rule->name));
+
+ if (ptr_rule->is_readonly)
+ _r_str_append (buffer, RTL_NUMBER_OF (buffer), SZ_RULE_INTERNAL_MENU);
+
+ _r_menu_additem_ex (hsubmenu, (ULONG)(IDX_RULES_SPECIAL + i), buffer, is_enabled ? MF_CHECKED : MF_UNCHECKED);
+
+ limit_count -= 1;
+ }
+
+ _r_queuedlock_releaseshared (&lock_rules);
+ }
+
+ if (type == 0)
+ _r_menu_addseparator (hsubmenu);
+ }
+
+ if (ptr_log)
+ {
+ _r_menu_addseparator (hsubmenu);
+
+ _r_str_printf (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_RULE_APPLY_2), _r_obj_getstring (ptr_log->remote_addr_str));
+
+ _r_menu_additem (hsubmenu, (ULONG)(IDX_RULES_SPECIAL + i) + 1, buffer);
+ }
+ }
+
+ _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"%s...", _r_locale_getstring (IDS_OPENRULESEDITOR));
+
+ _r_menu_additem (hsubmenu, IDM_OPENRULESEDITOR, buffer);
+}
+
+VOID _app_generate_timerscontrol (
+ _In_ HMENU hsubmenu,
+ _In_ ULONG app_hash
+)
+{
+ PR_STRING string;
+ LONG64 app_time = 0, current_time, timestamp;
+ ULONG index;
+ BOOLEAN is_checked = FALSE;
+
+ current_time = _r_unixtime_now ();
+
+ _app_getappinfobyhash (app_hash, INFO_TIMER, &app_time, sizeof (LONG64));
+
+ for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (timer_array); i++)
+ {
+ timestamp = timer_array[i];
+
+ string = _r_format_interval (timestamp);
+
+ index = (ULONG)(IDX_TIMER + i);
+
+ _r_menu_additem (hsubmenu, index, string->buffer);
+
+ if (!is_checked && (app_time > current_time) && (app_time <= (current_time + timestamp)))
+ {
+ _r_menu_checkitem (hsubmenu, IDX_TIMER, index, MF_BYCOMMAND, index);
+
+ is_checked = TRUE;
+ }
+
+ _r_obj_dereference (string);
+ }
+
+ if (!is_checked)
+ _r_menu_checkitem (hsubmenu, IDM_DISABLETIMER, IDM_DISABLETIMER, MF_BYCOMMAND, IDM_DISABLETIMER);
+}
+
VOID _app_message_contextmenu (
_In_ HWND hwnd,
_In_ LPNMITEMACTIVATE lpnmlv
)
{
- PR_STRING localized_string = NULL;
- PR_STRING column_text = NULL;
- HMENU hsubmenu_timers = NULL;
- HMENU hsubmenu_rules = NULL;
- HMENU hmenu;
+ HMENU hmenu, hsubmenu_rules = NULL, hsubmenu_timers = NULL;
+ PR_STRING column_text = NULL, localized_string = NULL;
PITEM_NETWORK ptr_network;
PITEM_APP ptr_app = NULL;
- ULONG hash_code;
- ULONG app_hash;
+ ULONG app_hash, hash_code;
INT listview_id;
- INT command_id;
- BOOLEAN is_readonly = FALSE;
BOOLEAN is_checked = FALSE;
if (lpnmlv->iItem == INT_ERROR)
@@ -599,20 +601,15 @@ VOID _app_message_contextmenu (
if (ptr_app)
{
- if (_app_getappinfo (ptr_app, INFO_IS_SILENT, &is_checked, sizeof (BOOLEAN)))
- {
- if (is_checked)
- _r_menu_checkitem (hmenu, IDM_DISABLENOTIFICATIONS, 0, MF_BYCOMMAND, is_checked);
- }
+ if (_app_getappinfo (ptr_app, INFO_IS_SILENT, &is_checked, sizeof (BOOLEAN)) && is_checked)
+ _r_menu_checkitem (hmenu, IDM_DISABLENOTIFICATIONS, 0, MF_BYCOMMAND, is_checked);
if (_app_getappinfo (ptr_app, INFO_IS_UNDELETABLE, &is_checked, sizeof (BOOLEAN)))
{
- if (is_checked)
- {
- _r_menu_checkitem (hmenu, IDM_DISABLEREMOVAL, 0, MF_BYCOMMAND, is_checked);
+ _r_menu_checkitem (hmenu, IDM_DISABLEREMOVAL, 0, MF_BYCOMMAND, is_checked);
+ if (is_checked)
_r_menu_enableitem (hmenu, IDM_DELETE, FALSE, FALSE);
- }
}
}
@@ -639,11 +636,8 @@ VOID _app_message_contextmenu (
hash_code = (ULONG)_app_listview_getitemcontext (hwnd, listview_id, lpnmlv->iItem);
- if (_app_getruleinfobyid (hash_code, INFO_IS_READONLY, &is_readonly, sizeof (BOOLEAN)))
- {
- if (is_readonly)
- _r_menu_enableitem (hmenu, IDM_DELETE, FALSE, FALSE);
- }
+ if (_app_getruleinfobyid (hash_code, INFO_IS_READONLY, &is_checked, sizeof (BOOLEAN)) && is_checked)
+ _r_menu_enableitem (hmenu, IDM_DELETE, FALSE, FALSE);
}
_r_menu_addseparator (hmenu);
@@ -665,7 +659,6 @@ VOID _app_message_contextmenu (
if (column_text)
{
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (4, _r_locale_getstring (IDS_COPY), L" \"", column_text->buffer, L"\""));
-
_r_menu_additem (hmenu, IDM_COPY_VALUE, localized_string->buffer);
_r_obj_dereference (column_text);
@@ -703,7 +696,6 @@ VOID _app_message_contextmenu (
if (column_text)
{
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (4, _r_locale_getstring (IDS_COPY), L" \"", column_text->buffer, L"\""));
-
_r_menu_additem (hmenu, IDM_COPY_VALUE, localized_string->buffer);
_r_obj_dereference (column_text);
@@ -768,26 +760,23 @@ VOID _app_message_contextmenu (
if (ptr_app)
{
if (_app_getappinfo (ptr_app, INFO_IS_SILENT, &is_checked, sizeof (BOOLEAN)))
- {
- if (is_checked)
- _r_menu_checkitem (hmenu, IDM_DISABLENOTIFICATIONS, 0, MF_BYCOMMAND, is_checked);
- }
+ _r_menu_checkitem (hmenu, IDM_DISABLENOTIFICATIONS, 0, MF_BYCOMMAND, is_checked);
if (_app_getappinfo (ptr_app, INFO_IS_UNDELETABLE, &is_checked, sizeof (BOOLEAN)))
- {
- if (is_checked)
- _r_menu_checkitem (hmenu, IDM_DISABLEREMOVAL, 0, MF_BYCOMMAND, is_checked);
- }
+ _r_menu_checkitem (hmenu, IDM_DISABLEREMOVAL, 0, MF_BYCOMMAND, is_checked);
}
break;
}
}
- command_id = _r_menu_popup (hmenu, hwnd, NULL, FALSE);
+ _r_menu_popup (hmenu, hwnd, NULL, (LPARAM)lpnmlv->iSubItem);
- if (command_id)
- _r_ctrl_sendcommand (hwnd, command_id, (LPARAM)lpnmlv->iSubItem);
+ if (localized_string)
+ _r_obj_dereference (localized_string);
+
+ if (ptr_app)
+ _r_obj_dereference (ptr_app);
if (hsubmenu_rules)
DestroyMenu (hsubmenu_rules);
@@ -796,12 +785,6 @@ VOID _app_message_contextmenu (
DestroyMenu (hsubmenu_timers);
DestroyMenu (hmenu);
-
- if (localized_string)
- _r_obj_dereference (localized_string);
-
- if (ptr_app)
- _r_obj_dereference (ptr_app);
}
VOID _app_message_contextmenu_columns (
@@ -836,7 +819,6 @@ VOID _app_message_contextmenu_columns (
if (column_text)
{
_r_menu_additem (hmenu, IDX_COLUMN + i, column_text->buffer);
-
_r_menu_checkitem (hmenu, IDX_COLUMN + i, 0, MF_BYCOMMAND, TRUE);
_r_obj_dereference (column_text);
@@ -844,7 +826,7 @@ VOID _app_message_contextmenu_columns (
}
- _r_menu_popup (hmenu, hwnd, NULL, TRUE);
+ _r_menu_popup (hmenu, hwnd, NULL, 0);
DestroyMenu (hmenu);
}
@@ -854,10 +836,9 @@ VOID _app_message_traycontextmenu (
)
{
ENUM_INSTALL_TYPE install_type;
- HMENU hsubmenu;
- HMENU hmenu;
+ HMENU hmenu, hsubmenu;
- hmenu = LoadMenuW (NULL, MAKEINTRESOURCE (IDM_TRAY));
+ hmenu = LoadMenuW (_r_sys_getimagebase (), MAKEINTRESOURCE (IDM_TRAY));
if (!hmenu)
return;
@@ -886,20 +867,19 @@ VOID _app_message_traycontextmenu (
_r_menu_setitemtext (hsubmenu, IDM_TRAY_NOTIFICATIONONTRAY_CHK, FALSE, _r_locale_getstring (IDS_NOTIFICATIONONTRAY_CHK));
_r_menu_setitemtext (hsubmenu, IDM_TRAY_ENABLELOG_CHK, FALSE, _r_locale_getstring (IDS_ENABLELOG_CHK));
_r_menu_setitemtextformat (hsubmenu, IDM_TRAY_ENABLEUILOG_CHK, FALSE, L"%s (%s)", _r_locale_getstring (IDS_ENABLEUILOG_CHK), _r_locale_getstring (IDS_SESSION_ONLY));
-
_r_menu_setitemtext (hsubmenu, IDM_TRAY_LOGSHOW, FALSE, _r_locale_getstring (IDS_LOGSHOW));
_r_menu_setitemtext (hsubmenu, IDM_TRAY_LOGCLEAR, FALSE, _r_locale_getstring (IDS_LOGCLEAR));
+ _r_menu_setitemtext (hsubmenu, ERRLOG_ID, TRUE, _r_locale_getstring (IDS_TRAY_LOGERR));
if (_r_fs_isexists (&_r_app_getlogpath ()->sr))
{
- _r_menu_setitemtext (hsubmenu, ERRLOG_ID, TRUE, _r_locale_getstring (IDS_TRAY_LOGERR));
-
_r_menu_setitemtext (hsubmenu, IDM_TRAY_LOGSHOW_ERR, FALSE, _r_locale_getstring (IDS_LOGSHOW));
_r_menu_setitemtext (hsubmenu, IDM_TRAY_LOGCLEAR_ERR, FALSE, _r_locale_getstring (IDS_LOGCLEAR));
}
else
{
DeleteMenu (hsubmenu, ERRLOG_ID, MF_BYPOSITION);
+ //_r_menu_enableitem (hsubmenu, ERRLOG_ID, TRUE, FALSE);
}
_r_menu_setitemtextformat (hsubmenu, IDM_TRAY_SETTINGS, FALSE, L"%s...", _r_locale_getstring (IDS_SETTINGS));
@@ -927,9 +907,9 @@ VOID _app_message_traycontextmenu (
if (_wfp_isfiltersapplying ())
_r_menu_enableitem (hsubmenu, IDM_TRAY_START, FALSE, FALSE);
- SetForegroundWindow (hwnd); // don't touch
+ SetForegroundWindow (hwnd); // don't fucking touch!
- _r_menu_popup (hsubmenu, hwnd, NULL, TRUE);
+ _r_menu_popup (hsubmenu, hwnd, NULL, 0);
DestroyMenu (hmenu);
}
@@ -948,23 +928,23 @@ VOID _app_message_dpichanged (
// reset toolbar information
_app_setinterfacestate (hwnd, dpi_value);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_REFRESH, _r_locale_getstring (IDS_REFRESH), BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT, 0, I_IMAGENONE);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_SETTINGS, _r_locale_getstring (IDS_SETTINGS), BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_REFRESH, _r_locale_getstring (IDS_REFRESH), BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT, 0, I_DEFAULT);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_SETTINGS, _r_locale_getstring (IDS_SETTINGS), BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT, 0, I_DEFAULT);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_OPENRULESEDITOR), L"..."));
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_OPENRULESEDITOR, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_OPENRULESEDITOR, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_DEFAULT);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLENOTIFICATIONS_CHK, _r_locale_getstring (IDS_ENABLENOTIFICATIONS_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_IMAGENONE);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLELOG_CHK, _r_locale_getstring (IDS_ENABLELOG_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_IMAGENONE);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLEUILOG_CHK, _r_locale_getstring (IDS_ENABLEUILOG_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLENOTIFICATIONS_CHK, _r_locale_getstring (IDS_ENABLENOTIFICATIONS_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_DEFAULT);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLELOG_CHK, _r_locale_getstring (IDS_ENABLELOG_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_DEFAULT);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLEUILOG_CHK, _r_locale_getstring (IDS_ENABLEUILOG_CHK), BTNS_CHECK | BTNS_AUTOSIZE, 0, I_DEFAULT);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_LOGSHOW), L" (Ctrl+I)"));
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGSHOW, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGSHOW, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_DEFAULT);
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_LOGCLEAR), L" (Ctrl+X)"));
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGCLEAR, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_TRAY_LOGCLEAR, localized_string->buffer, BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_DEFAULT);
- _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_DONATE, _r_locale_getstring (IDS_DONATE), BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_IMAGENONE);
+ _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_DONATE, _r_locale_getstring (IDS_DONATE), BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_DEFAULT);
_app_listview_loadfont (dpi_value, TRUE);
_app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE);
@@ -984,11 +964,9 @@ LONG_PTR _app_message_custdraw (
PITEM_COLOR ptr_clr;
PITEM_LOG ptr_log;
COLORREF new_clr = 0;
- ULONG app_hash = 0;
- ULONG index;
+ ULONG app_hash = 0, index;
INT listview_id;
- BOOLEAN is_validconnection = FALSE;
- BOOLEAN is_systemapp = FALSE;
+ BOOLEAN is_systemapp = FALSE, is_validconnection = FALSE;
switch (lpnmlv->nmcd.dwDrawStage)
{
@@ -1030,7 +1008,6 @@ LONG_PTR _app_message_custdraw (
app_hash = ptr_network->app_hash;
is_systemapp = _app_isappfromsystem (ptr_network->path, app_hash);
is_validconnection = ptr_network->is_connection;
- //is_validconnection = FALSE; // do not highlight connections
_r_obj_dereference (ptr_network);
}
@@ -1041,7 +1018,7 @@ LONG_PTR _app_message_custdraw (
if (ptr_log)
{
- app_hash = _app_getlogapp (index);
+ app_hash = ptr_log->app_hash;
is_systemapp = _app_isappfromsystem (ptr_log->path, app_hash);
_r_obj_dereference (ptr_log);
@@ -1071,10 +1048,7 @@ LONG_PTR _app_message_custdraw (
case IDC_RULES_CUSTOM:
case IDC_APP_RULES_ID:
{
- index = (ULONG)_app_listview_getcontextcode (lpnmlv->nmcd.lItemlParam);
-
- new_clr = _app_getrulecolor (listview_id, index);
-
+ new_clr = _app_getrulecolor (listview_id, _app_listview_getcontextcode (lpnmlv->nmcd.lItemlParam));
break;
}
@@ -1119,7 +1093,7 @@ VOID _app_displayinfoapp_callback (
LONG icon_id = 0;
// set text
- if (lpnmlv->item.mask & LVIF_TEXT)
+ if ((lpnmlv->item.mask & LVIF_TEXT) == LVIF_TEXT)
{
switch (lpnmlv->item.iSubItem)
{
@@ -1154,14 +1128,14 @@ VOID _app_displayinfoapp_callback (
}
// set image
- if (lpnmlv->item.mask & LVIF_IMAGE)
+ if ((lpnmlv->item.mask & LVIF_IMAGE) == LVIF_IMAGE)
{
- if (_app_getappinfoparam2 (ptr_app->app_hash, (INT)lpnmlv->hdr.idFrom, INFO_ICON_ID, &icon_id, sizeof (LONG)))
+ if (_app_getappinfoparam2 (ptr_app->app_hash, (INT)(INT_PTR)lpnmlv->hdr.idFrom, INFO_ICON_ID, &icon_id, sizeof (LONG)))
lpnmlv->item.iImage = icon_id;
}
// set group id
- if (lpnmlv->item.mask & LVIF_GROUPID)
+ if ((lpnmlv->item.mask & LVIF_GROUPID) == LVIF_GROUPID)
{
if (_app_listview_isitemhidden (lpnmlv->item.lParam))
{
@@ -1202,14 +1176,7 @@ VOID _app_displayinfoapp_callback (
else
{
// silent apps without rules and not enabled added into silent group
- if (ptr_app->is_silent)
- {
- lpnmlv->item.iGroupId = 4;
- }
- else
- {
- lpnmlv->item.iGroupId = 3;
- }
+ lpnmlv->item.iGroupId = ptr_app->is_silent ? 4 : 3;
}
}
}
@@ -1225,26 +1192,19 @@ VOID _app_displayinforule_callback (
PR_STRING string;
// set text
- if (lpnmlv->item.mask & LVIF_TEXT)
+ if ((lpnmlv->item.mask & LVIF_TEXT) == LVIF_TEXT)
{
switch (lpnmlv->item.iSubItem)
{
case 0:
{
- if (ptr_rule->name)
+ if (ptr_rule->is_readonly && ptr_rule->type == DATA_RULE_USER)
{
- if (ptr_rule->is_readonly && ptr_rule->type == DATA_RULE_USER)
- {
- _r_str_printf (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, L"%s" SZ_RULE_INTERNAL_MENU, ptr_rule->name->buffer);
- }
- else
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, ptr_rule->name->buffer);
- }
+ _r_str_printf (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, L"%s" SZ_RULE_INTERNAL_MENU, ptr_rule->name->buffer);
}
else
{
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_locale_getstring (IDS_STATUS_EMPTY));
+ _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, ptr_rule->name->buffer);
}
break;
@@ -1252,15 +1212,7 @@ VOID _app_displayinforule_callback (
case 1:
{
- if (ptr_rule->protocol_str)
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, ptr_rule->protocol_str->buffer);
- }
- else
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_locale_getstring (IDS_ANY));
- }
-
+ _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, ptr_rule->protocol_str ? ptr_rule->protocol_str->buffer : _r_locale_getstring (IDS_ANY));
break;
}
@@ -1281,11 +1233,11 @@ VOID _app_displayinforule_callback (
}
// set image
- if (lpnmlv->item.mask & LVIF_IMAGE)
+ if ((lpnmlv->item.mask & LVIF_IMAGE) == LVIF_IMAGE)
lpnmlv->item.iImage = (ptr_rule->action == FWP_ACTION_BLOCK) ? 1 : 0;
// set group id
- if (lpnmlv->item.mask & LVIF_GROUPID)
+ if ((lpnmlv->item.mask & LVIF_GROUPID) == LVIF_GROUPID)
{
if (_app_listview_isitemhidden (lpnmlv->item.lParam))
{
@@ -1301,14 +1253,7 @@ VOID _app_displayinforule_callback (
{
if (ptr_rule->is_enabled)
{
- if (ptr_rule->is_forservices || !_r_obj_isempty (ptr_rule->apps))
- {
- lpnmlv->item.iGroupId = 1;
- }
- else
- {
- lpnmlv->item.iGroupId = 0;
- }
+ lpnmlv->item.iGroupId = (ptr_rule->is_fordriver || ptr_rule->is_forservice || !_r_obj_isempty (ptr_rule->apps)) ? 1 : 0;
}
else
{
@@ -1330,7 +1275,7 @@ VOID _app_displayinfonetwork_callback (
LONG icon_id = 0;
// set text
- if (lpnmlv->item.mask & LVIF_TEXT)
+ if ((lpnmlv->item.mask & LVIF_TEXT) == LVIF_TEXT)
{
switch (lpnmlv->item.iSubItem)
{
@@ -1351,7 +1296,7 @@ VOID _app_displayinfonetwork_callback (
_r_obj_dereference (ptr_app);
}
- else if (ptr_network->path)
+ else if (!_r_obj_isstringempty (ptr_network->path))
{
_r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_path_getbasename (&ptr_network->path->sr));
}
@@ -1361,7 +1306,7 @@ VOID _app_displayinfonetwork_callback (
case 1:
{
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->local_addr_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->local_addr_str, NULL, NULL);
if (string)
_r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
@@ -1371,16 +1316,9 @@ VOID _app_displayinfonetwork_callback (
case 2:
{
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->local_host_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->local_host_str, NULL, NULL);
- if (string)
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
- }
- else
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_locale_getstring (IDS_LOADING));
- }
+ _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string ? string->buffer : _r_locale_getstring (IDS_LOADING));
break;
}
@@ -1404,7 +1342,7 @@ VOID _app_displayinfonetwork_callback (
case 4:
{
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->remote_addr_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->remote_addr_str, NULL, NULL);
if (string)
_r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
@@ -1414,16 +1352,9 @@ VOID _app_displayinfonetwork_callback (
case 5:
{
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->remote_host_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->remote_host_str, NULL, NULL);
- if (string)
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
- }
- else
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_locale_getstring (IDS_LOADING));
- }
+ _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string ? string->buffer : _r_locale_getstring (IDS_LOADING));
break;
}
@@ -1447,15 +1378,7 @@ VOID _app_displayinfonetwork_callback (
case 7:
{
- if (ptr_network->protocol_str)
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, ptr_network->protocol_str->buffer);
- }
- else
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_locale_getstring (IDS_ANY));
- }
-
+ _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, ptr_network->protocol_str ? ptr_network->protocol_str->buffer : _r_locale_getstring (IDS_ANY));
break;
}
@@ -1472,14 +1395,14 @@ VOID _app_displayinfonetwork_callback (
}
// set image
- if (lpnmlv->item.mask & LVIF_IMAGE)
+ if ((lpnmlv->item.mask & LVIF_IMAGE) == LVIF_IMAGE)
{
if (_app_getappinfoparam2 (ptr_network->app_hash, (INT)lpnmlv->hdr.idFrom, INFO_ICON_ID, &icon_id, sizeof (LONG)))
lpnmlv->item.iImage = icon_id;
}
// set group id
- if (lpnmlv->item.mask & LVIF_GROUPID)
+ if ((lpnmlv->item.mask & LVIF_GROUPID) == LVIF_GROUPID)
{
if (_app_listview_isitemhidden (lpnmlv->item.lParam))
{
@@ -1513,17 +1436,11 @@ VOID _app_displayinfolog_callback (
LONG icon_id = 0;
// set text
- if (lpnmlv->item.mask & LVIF_TEXT)
+ if ((lpnmlv->item.mask & LVIF_TEXT) == LVIF_TEXT)
{
switch (lpnmlv->item.iSubItem)
{
case 0:
- {
- _r_str_printf (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, L"%d", _InterlockedCompareExchange (&ptr_log->log_id, 0, 0));
- break;
- }
-
- case 1:
{
if (ptr_app)
{
@@ -1531,24 +1448,24 @@ VOID _app_displayinfolog_callback (
if (string)
{
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
+ _r_str_printf (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, L"%d. %s", _InterlockedCompareExchange (&ptr_log->log_id, 0, 0), string->buffer);
_r_obj_dereference (string);
}
}
- else if (ptr_log->path)
+ else if (!_r_obj_isstringempty (ptr_log->path))
{
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_path_getbasename (&ptr_log->path->sr));
+ _r_str_printf (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, L"%d. %s", _InterlockedCompareExchange (&ptr_log->log_id, 0, 0), _r_path_getbasename (&ptr_log->path->sr));
}
else
{
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_locale_getstring (IDS_STATUS_EMPTY));
+ _r_str_printf (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, L"%d. %s", _InterlockedCompareExchange (&ptr_log->log_id, 0, 0), _r_locale_getstring (IDS_STATUS_EMPTY));
}
break;
}
- case 2:
+ case 1:
{
string = _r_format_unixtime (ptr_log->timestamp, FDTF_SHORTDATE | FDTF_LONGTIME);
@@ -1562,9 +1479,9 @@ VOID _app_displayinfolog_callback (
break;
}
- case 3:
+ case 2:
{
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_addr_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_addr_str, NULL, NULL);
if (string)
_r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
@@ -1572,23 +1489,16 @@ VOID _app_displayinfolog_callback (
break;
}
+ case 3:
+ {
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_host_str, NULL, NULL);
+
+ _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string ? string->buffer : _r_locale_getstring (IDS_LOADING));
+
+ break;
+ }
+
case 4:
- {
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_host_str, NULL, NULL);
-
- if (string)
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
- }
- else
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_locale_getstring (IDS_LOADING));
- }
-
- break;
- }
-
- case 5:
{
if (ptr_log->local_port)
{
@@ -1605,9 +1515,9 @@ VOID _app_displayinfolog_callback (
break;
}
- case 6:
+ case 5:
{
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_addr_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_addr_str, NULL, NULL);
if (string)
_r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
@@ -1615,23 +1525,16 @@ VOID _app_displayinfolog_callback (
break;
}
+ case 6:
+ {
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_host_str, NULL, NULL);
+
+ _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string ? string->buffer : _r_locale_getstring (IDS_LOADING));
+
+ break;
+ }
+
case 7:
- {
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_host_str, NULL, NULL);
-
- if (string)
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
- }
- else
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_locale_getstring (IDS_LOADING));
- }
-
- break;
- }
-
- case 8:
{
if (ptr_log->remote_port)
{
@@ -1648,21 +1551,13 @@ VOID _app_displayinfolog_callback (
break;
}
- case 9:
+ case 8:
{
- if (ptr_log->protocol_str)
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, ptr_log->protocol_str->buffer);
- }
- else
- {
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, _r_locale_getstring (IDS_ANY));
- }
-
+ _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, ptr_log->protocol_str ? ptr_log->protocol_str->buffer : _r_locale_getstring (IDS_ANY));
break;
}
- case 10:
+ case 9:
{
string = _app_db_getdirectionname (ptr_log->direction, ptr_log->is_loopback, FALSE);
@@ -1676,42 +1571,24 @@ VOID _app_displayinfolog_callback (
break;
}
- case 11:
+ case 10:
{
- string = _r_obj_concatstrings (
- 2,
- ptr_log->is_allow ? L"[A] " : L"[B] ",
- _r_obj_getstringordefault (ptr_log->filter_name, _r_locale_getstring (IDS_STATUS_EMPTY))
- );
-
- _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, string->buffer);
-
- _r_obj_dereference (string);
-
+ _r_str_printf (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, L"%s %s", ptr_log->is_allow ? L"[A]" : L"[B]", _r_obj_getstringordefault (ptr_log->filter_name, _r_locale_getstring (IDS_STATUS_EMPTY)));
break;
}
}
}
// set image
- if (lpnmlv->item.mask & LVIF_IMAGE)
+ if ((lpnmlv->item.mask & LVIF_IMAGE) == LVIF_IMAGE)
{
if (_app_getappinfoparam2 (ptr_log->app_hash, (INT)lpnmlv->hdr.idFrom, INFO_ICON_ID, &icon_id, sizeof (LONG)))
lpnmlv->item.iImage = icon_id;
}
// set group id
- if (lpnmlv->item.mask & LVIF_GROUPID)
- {
- if (_app_listview_isitemhidden (lpnmlv->item.lParam))
- {
- lpnmlv->item.iGroupId = LV_HIDDEN_GROUP_ID;
- }
- else
- {
- lpnmlv->item.iGroupId = 0;
- }
- }
+ if ((lpnmlv->item.mask & LVIF_GROUPID) == LVIF_GROUPID)
+ lpnmlv->item.iGroupId = _app_listview_isitemhidden (lpnmlv->item.lParam) ? LV_HIDDEN_GROUP_ID : 0;
}
BOOLEAN _app_message_displayinfo (
@@ -1818,7 +1695,6 @@ VOID _app_command_idtorules (
PITEM_RULE ptr_rule;
PITEM_APP ptr_app;
PR_LIST rules;
- HANDLE hengine;
ULONG_PTR rule_idx;
ULONG app_hash;
INT item_id = INT_ERROR;
@@ -1829,7 +1705,7 @@ VOID _app_command_idtorules (
if (!tab_context || !_r_listview_getselectedcount (hwnd, tab_context->listview_id))
return;
- rule_idx = (ULONG_PTR)ctrl_id - IDX_RULES_SPECIAL;
+ rule_idx = (ULONG_PTR)(ctrl_id - IDX_RULES_SPECIAL);
ptr_rule = _app_getrulebyid (rule_idx);
if (!ptr_rule)
@@ -1839,7 +1715,7 @@ VOID _app_command_idtorules (
{
app_hash = _app_listview_getappcontext (hwnd, tab_context->listview_id, item_id);
- if (ptr_rule->is_forservices && _app_issystemhash (app_hash))
+ if ((ptr_rule->is_fordriver || ptr_rule->is_forservice) && _app_issystemhash (app_hash))
continue;
ptr_app = _app_getappitem (app_hash);
@@ -1859,13 +1735,11 @@ VOID _app_command_idtorules (
if (_wfp_isfiltersinstalled ())
{
- hengine = _wfp_getenginehandle ();
-
- rules = _r_obj_createlist (10, NULL);
+ rules = _r_obj_createlist (0x10, NULL);
_r_obj_addlistitem (rules, ptr_rule, NULL);
- _wfp_create4filters (hengine, rules, DBG_ARG, FALSE);
+ _wfp_createrulefilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
_r_obj_dereference (rules);
}
@@ -1886,10 +1760,9 @@ VOID _app_command_idtotimers (
PITEM_TAB_CONTEXT tab_context;
PITEM_APP ptr_app;
PR_LIST rules;
- HANDLE hengine;
ULONG_PTR timer_idx;
- ULONG app_hash;
LONG64 seconds;
+ ULONG app_hash;
INT item_id = INT_ERROR;
tab_context = _app_listview_getcontext (hwnd, INT_ERROR);
@@ -1897,14 +1770,12 @@ VOID _app_command_idtotimers (
if (!tab_context || !_r_listview_getselectedcount (hwnd, tab_context->listview_id))
return;
- timer_idx = (ULONG_PTR)ctrl_id - IDX_TIMER;
+ timer_idx = (ULONG_PTR)(ctrl_id - IDX_TIMER);
seconds = timer_array[timer_idx];
if (_wfp_isfiltersinstalled ())
{
- hengine = _wfp_getenginehandle ();
-
- rules = _r_obj_createlist (8, &_r_obj_dereference);
+ rules = _r_obj_createlist (0x10, &_r_obj_dereference);
while ((item_id = _r_listview_getnextselected (hwnd, tab_context->listview_id, item_id)) != INT_ERROR)
{
@@ -1919,7 +1790,8 @@ VOID _app_command_idtotimers (
}
}
- _wfp_create3filters (hengine, rules, TEXT (__FILE__), __LINE__, FALSE);
+ if (!_r_obj_isempty2 (rules))
+ _wfp_createappfilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
_r_obj_dereference (rules);
}
@@ -1933,10 +1805,8 @@ VOID _app_command_logshow (
_In_ HWND hwnd
)
{
+ PR_STRING cmdline, log_path, viewer_path;
HANDLE current_handle;
- PR_STRING viewer_path;
- PR_STRING log_path;
- PR_STRING cmdline;
INT item_count;
NTSTATUS status;
@@ -1944,33 +1814,32 @@ VOID _app_command_logshow (
{
item_count = _r_listview_getitemcount (hwnd, IDC_LOG);
- _r_wnd_toggle (hwnd, TRUE);
-
_app_settab_id (hwnd, IDC_LOG);
+ _r_wnd_toggle (hwnd, TRUE);
+
if (item_count)
_r_listview_ensurevisible (hwnd, IDC_LOG, item_count - 1);
}
else
{
- log_path = _r_config_getstringexpand (L"LogPath", LOG_PATH_DEFAULT, NULL);
-
+ log_path = _app_getlogpath ();
viewer_path = _app_getlogviewer ();
if (!log_path || !_r_fs_isexists (&log_path->sr) || !viewer_path || !_r_fs_isexists (&viewer_path->sr))
{
- if (log_path)
- _r_obj_dereference (log_path);
-
if (viewer_path)
_r_obj_dereference (viewer_path);
+ if (log_path)
+ _r_obj_dereference (log_path);
+
_r_wnd_toggle (hwnd, TRUE);
return;
}
- current_handle = _InterlockedCompareExchangePointer (&config.hlogfile, NULL, NULL);
+ current_handle = (HANDLE)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hlogfile, NULL, NULL);
if (current_handle)
_r_fs_flushfile (current_handle);
@@ -1987,7 +1856,7 @@ VOID _app_command_logshow (
status = _r_sys_createprocess (&viewer_path->sr, &cmdline->sr, NULL, FALSE);
if (status != STATUS_SUCCESS)
- _r_show_errormessage (hwnd, NULL, status, cmdline->buffer, ET_NATIVE);
+ _r_show_errormessage (hwnd, L"Could not create process!", status, cmdline->buffer, ET_NATIVE);
_r_obj_dereference (viewer_path);
_r_obj_dereference (log_path);
@@ -2004,7 +1873,7 @@ VOID _app_command_logclear (
LONG64 file_size;
BOOLEAN is_valid;
- log_path = _r_config_getstringexpand (L"LogPath", LOG_PATH_DEFAULT, NULL);
+ log_path = _app_getlogpath ();
current_handle = _InterlockedCompareExchangePointer (&config.hlogfile, NULL, NULL);
@@ -2025,7 +1894,6 @@ VOID _app_command_logclear (
if (_r_show_confirmmessage (hwnd, _r_locale_getstring (IDS_QUESTION), NULL, L"ConfirmLogClear", FALSE))
{
_app_logclear (current_handle);
-
_app_logclear_ui (hwnd);
}
}
@@ -2038,8 +1906,7 @@ VOID _app_command_logerrshow (
_In_opt_ HWND hwnd
)
{
- PR_STRING process_path;
- PR_STRING viewer_path;
+ PR_STRING process_path, viewer_path;
PR_STRING path;
NTSTATUS status;
@@ -2065,7 +1932,7 @@ VOID _app_command_logerrshow (
status = _r_sys_createprocess (&viewer_path->sr, &process_path->sr, NULL, FALSE);
if (status != STATUS_SUCCESS)
- _r_show_errormessage (hwnd, NULL, status, viewer_path->buffer, ET_NATIVE);
+ _r_show_errormessage (hwnd, L"Could not create process!", status, viewer_path->buffer, ET_NATIVE);
_r_obj_dereference (process_path);
_r_obj_dereference (viewer_path);
@@ -2076,16 +1943,17 @@ VOID _app_command_logerrclear (
)
{
PR_STRING path;
+ NTSTATUS status;
path = _r_app_getlogpath ();
- if (!_r_fs_isexists (&path->sr))
+ if (!_r_fs_isexists (&path->sr) || !_r_show_confirmmessage (hwnd, _r_locale_getstring (IDS_QUESTION), NULL, L"ConfirmLogClear", FALSE))
return;
- if (!_r_show_confirmmessage (hwnd, _r_locale_getstring (IDS_QUESTION), NULL, L"ConfirmLogClear", FALSE))
- return;
+ status = _r_fs_deletefile (&path->sr, NULL);
- _r_fs_deletefile (&path->sr, NULL);
+ if (!NT_SUCCESS (status))
+ _r_show_errormessage (hwnd, L"Could not delete file!", status, path->buffer, ET_NATIVE);
}
VOID _app_command_copy (
@@ -2098,8 +1966,7 @@ VOID _app_command_copy (
PITEM_TAB_CONTEXT tab_context;
R_STRINGBUILDER sb;
PR_STRING string;
- INT column_count;
- INT item_id = INT_ERROR;
+ INT column_count, item_id = INT_ERROR;
tab_context = _app_listview_getcontext (hwnd, INT_ERROR);
@@ -2108,7 +1975,7 @@ VOID _app_command_copy (
column_count = _r_listview_getcolumncount (hwnd, tab_context->listview_id);
- _r_obj_initializestringbuilder (&sb, 512);
+ _r_obj_initializestringbuilder (&sb, 0x200);
while ((item_id = _r_listview_getnextselected (hwnd, tab_context->listview_id, item_id)) != INT_ERROR)
{
@@ -2150,7 +2017,8 @@ VOID _app_command_copy (
_r_str_trimstring2 (&string->sr, DIVIDER_TRIM, 0);
- _r_clipboard_set (hwnd, &string->sr);
+ if (!_r_obj_isstringempty2 (string))
+ _r_clipboard_set (hwnd, &string->sr);
_r_obj_deletestringbuilder (&sb);
}
@@ -2161,21 +2029,19 @@ VOID _app_command_checkbox (
)
{
PITEM_TAB_CONTEXT tab_context;
- PITEM_APP ptr_app;
PITEM_RULE ptr_rule;
+ PITEM_APP ptr_app;
PR_LIST rules;
- HANDLE hengine;
ULONG hash_code;
INT item_id = INT_ERROR;
- BOOLEAN new_val = (ctrl_id == IDM_CHECK);
- BOOLEAN is_changed = FALSE;
+ BOOLEAN is_changed = FALSE, new_val = (ctrl_id == IDM_CHECK);
tab_context = _app_listview_getcontext (hwnd, INT_ERROR);
if (!tab_context)
return;
- rules = _r_obj_createlist (8, &_r_obj_dereference);
+ rules = _r_obj_createlist (0x10, &_r_obj_dereference);
if (tab_context->listview_id >= IDC_APPS_PROFILE && tab_context->listview_id <= IDC_APPS_UWP)
{
@@ -2200,9 +2066,9 @@ VOID _app_command_checkbox (
ptr_app->is_enabled = new_val;
- _app_listview_lock (hwnd, tab_context->listview_id, TRUE);
+ _app_listview_lock (hwnd, tab_context->listview_id);
_app_setappiteminfo (hwnd, tab_context->listview_id, item_id, ptr_app);
- _app_listview_lock (hwnd, tab_context->listview_id, FALSE);
+ _app_listview_unlock (hwnd, tab_context->listview_id);
_r_obj_addlistitem (rules, ptr_app, NULL);
@@ -2216,15 +2082,8 @@ VOID _app_command_checkbox (
}
}
- if (is_changed)
- {
- if (_wfp_isfiltersinstalled ())
- {
- hengine = _wfp_getenginehandle ();
-
- _wfp_create3filters (hengine, rules, DBG_ARG, FALSE);
- }
- }
+ if (is_changed && _wfp_isfiltersinstalled ())
+ _wfp_createappfilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
}
else if (tab_context->listview_id >= IDC_RULES_BLOCKLIST && tab_context->listview_id <= IDC_RULES_CUSTOM)
{
@@ -2240,9 +2099,9 @@ VOID _app_command_checkbox (
{
_app_ruleenable (ptr_rule, new_val, TRUE);
- _app_listview_lock (hwnd, tab_context->listview_id, TRUE);
+ _app_listview_lock (hwnd, tab_context->listview_id);
_app_setruleiteminfo (hwnd, tab_context->listview_id, item_id, ptr_rule, TRUE);
- _app_listview_lock (hwnd, tab_context->listview_id, FALSE);
+ _app_listview_unlock (hwnd, tab_context->listview_id);
_r_obj_addlistitem (rules, ptr_rule, NULL);
@@ -2256,25 +2115,18 @@ VOID _app_command_checkbox (
}
}
- if (is_changed)
- {
- if (_wfp_isfiltersinstalled ())
- {
- hengine = _wfp_getenginehandle ();
-
- _wfp_create4filters (hengine, rules, DBG_ARG, FALSE);
- }
- }
+ if (is_changed && _wfp_isfiltersinstalled ())
+ _wfp_createrulefilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
}
- _r_obj_dereference (rules);
-
if (is_changed)
{
_app_listview_updateby_id (hwnd, tab_context->listview_id, PR_UPDATE_FORCE);
_app_profile_save (hwnd);
}
+
+ _r_obj_dereference (rules);
}
VOID _app_command_delete (
@@ -2284,20 +2136,17 @@ VOID _app_command_delete (
R_STRINGREF crlf = PR_STRINGREF_INIT (SZ_CRLF);
PITEM_TAB_CONTEXT tab_context;
R_STRINGBUILDER sb;
- PR_ARRAY guids = NULL;
PITEM_NETWORK ptr_network;
PR_HASHTABLE apps_checker;
+ PR_ARRAY guids = NULL;
MIB_TCPROW tcprow;
PR_STRING string;
- HANDLE hengine;
PITEM_APP ptr_app;
PITEM_RULE ptr_rule;
- ULONG_PTR rule_idx;
- ULONG_PTR enum_key;
- ULONG hash_code;
- INT selected_count;
+ ULONG_PTR enum_key = 0, rule_idx;
LPARAM lparam;
- INT item_count;
+ ULONG hash_code;
+ INT item_count, selected_count;
tab_context = _app_listview_getcontext (hwnd, INT_ERROR);
@@ -2313,7 +2162,7 @@ VOID _app_command_delete (
if (tab_context->listview_id != IDC_NETWORK)
{
- _r_obj_initializestringbuilder (&sb, 256);
+ _r_obj_initializestringbuilder (&sb, 0);
string = _r_locale_getstring_ex (IDS_QUESTION_DELETE);
@@ -2345,9 +2194,9 @@ VOID _app_command_delete (
_r_obj_appendstringbuilder2 (&sb, &crlf);
_r_obj_dereference (string);
- }
- j += 1;
+ j += 1;
+ }
}
string = _r_obj_finalstringbuilder (&sb);
@@ -2357,15 +2206,14 @@ VOID _app_command_delete (
if (_r_show_message (hwnd, MB_YESNO | MB_ICONEXCLAMATION, NULL, string->buffer) != IDYES)
{
_r_obj_dereference (string);
-
return;
}
- guids = _r_obj_createarray (sizeof (GUID), 10, NULL);
-
- _r_obj_dereference (string);
+ _r_obj_deletestringbuilder (&sb);
}
+ guids = _r_obj_createarray (sizeof (GUID), 0x10, NULL);
+
for (INT i = item_count - 1; i != INT_ERROR; i--)
{
if (!_r_listview_isitemselected (hwnd, tab_context->listview_id, i))
@@ -2386,8 +2234,8 @@ VOID _app_command_delete (
_r_listview_deleteitem (hwnd, tab_context->listview_id, i);
- _app_timer_reset (hwnd, ptr_app);
_app_notify_freeobject (NULL, ptr_app);
+ _app_timer_reset (hwnd, ptr_app);
_r_queuedlock_acquireexclusive (&lock_apps);
_app_freeapplication (hwnd, hash_code);
@@ -2406,7 +2254,7 @@ VOID _app_command_delete (
if (!ptr_rule->is_readonly) // skip "read-only" rules
{
- apps_checker = _r_obj_createhashtable (sizeof (SHORT), 6, NULL);
+ apps_checker = _r_obj_createhashtable (sizeof (SHORT), 0x10, NULL);
if (!_r_obj_isempty (ptr_rule->guids))
_r_obj_addarrayitems (guids, ptr_rule->guids->items, ptr_rule->guids->count);
@@ -2432,6 +2280,8 @@ VOID _app_command_delete (
{
_app_listview_updateitemby_param (hwnd, hash_code, TRUE);
}
+
+ _r_obj_dereference (apps_checker);
}
_r_obj_dereference (ptr_rule);
@@ -2449,10 +2299,10 @@ VOID _app_command_delete (
RtlZeroMemory (&tcprow, sizeof (MIB_TCPROW));
tcprow.dwState = MIB_TCP_STATE_DELETE_TCB;
- tcprow.dwLocalAddr = ptr_network->local_addr.S_un.S_addr;
- tcprow.dwLocalPort = _r_byteswap_ushort ((USHORT)ptr_network->local_port);
tcprow.dwRemoteAddr = ptr_network->remote_addr.S_un.S_addr;
tcprow.dwRemotePort = _r_byteswap_ushort ((USHORT)ptr_network->remote_port);
+ tcprow.dwLocalAddr = ptr_network->local_addr.S_un.S_addr;
+ tcprow.dwLocalPort = _r_byteswap_ushort ((USHORT)ptr_network->local_port);
if (SetTcpEntry (&tcprow) == NO_ERROR)
{
@@ -2466,24 +2316,15 @@ VOID _app_command_delete (
}
}
- if (guids)
- {
- if (!_r_obj_isempty (guids))
- {
- if (_wfp_isfiltersinstalled ())
- {
- hengine = _wfp_getenginehandle ();
-
- _wfp_destroyfilters_array (hengine, guids, DBG_ARG);
- }
- }
-
- _r_obj_dereference (guids);
- }
+ if (!_r_obj_isempty (guids) && _wfp_isfiltersinstalled ())
+ _wfp_destroyfilters_array (_wfp_getenginehandle (), guids, DBG_ARG);
_app_listview_updateby_id (hwnd, tab_context->listview_id, 0);
_app_profile_save (hwnd);
+
+ if (guids)
+ _r_obj_dereference (guids);
}
VOID _app_command_disable (
@@ -2499,7 +2340,7 @@ VOID _app_command_disable (
tab_context = _app_listview_getcontext (hwnd, INT_ERROR);
- // note: these commands only for apps...
+ // note: these commands only for apps (and log)...
if (!tab_context || (!(tab_context->listview_id >= IDC_APPS_PROFILE && tab_context->listview_id <= IDC_APPS_UWP) && tab_context->listview_id != IDC_LOG))
return;
@@ -2553,20 +2394,20 @@ VOID _app_command_openeditor (
PEDITOR_CONTEXT context;
PITEM_RULE ptr_rule;
PITEM_LOG ptr_log;
- PR_STRING string;
+ PITEM_APP ptr_app;
ULONG_PTR id_code;
ULONG hash_code;
INT item_id = INT_ERROR;
- ptr_rule = _app_addrule (NULL, NULL, NULL, FWP_DIRECTION_OUTBOUND, FWP_ACTION_PERMIT, 0, 0);
-
- _app_ruleenable (ptr_rule, TRUE, FALSE);
-
tab_context = _app_listview_getcontext (hwnd, INT_ERROR);
if (!tab_context)
return;
+ ptr_rule = _app_addrule (NULL, NULL, NULL, FWP_DIRECTION_OUTBOUND, FWP_ACTION_PERMIT, 0, 0);
+
+ _app_ruleenable (ptr_rule, TRUE, FALSE);
+
switch (tab_context->listview_id)
{
case IDC_APPS_PROFILE:
@@ -2581,6 +2422,21 @@ VOID _app_command_openeditor (
_r_obj_addhashtableitem (ptr_rule->apps, hash_code, NULL);
}
+ item_id = _r_listview_getnextselected (hwnd, tab_context->listview_id, INT_ERROR);
+
+ if (item_id != INT_ERROR)
+ {
+ hash_code = (ULONG)_app_listview_getitemcontext (hwnd, tab_context->listview_id, item_id);
+ ptr_app = _app_getappitem (hash_code);
+
+ if (ptr_app)
+ {
+ _r_obj_movereference ((PVOID_PTR)&ptr_rule->name, _r_listview_getitemtext (hwnd, tab_context->listview_id, item_id, 0));
+
+ _r_obj_dereference (ptr_app);
+ }
+ }
+
break;
}
@@ -2597,19 +2453,22 @@ VOID _app_command_openeditor (
if (ptr_network)
{
- if (!ptr_rule->name)
- ptr_rule->name = _r_listview_getitemtext (hwnd, tab_context->listview_id, item_id, 0);
+ _r_obj_movereference ((PVOID_PTR)&ptr_rule->name, _r_listview_getitemtext (hwnd, tab_context->listview_id, item_id, 0));
if (ptr_network->app_hash && !_r_obj_isstringempty (ptr_network->path))
{
if (!_app_isappfound (ptr_network->app_hash))
{
- ptr_network->app_hash = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_network->path, NULL, NULL);
+ ptr_app = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_network->path, NULL, NULL);
- if (ptr_network->app_hash)
+ if (ptr_app)
{
+ ptr_network->app_hash = ptr_app->app_hash;
+
_app_listview_updateby_param (hwnd, ptr_network->app_hash, PR_SETITEM_UPDATE, TRUE);
+ _r_obj_dereference (ptr_app);
+
_app_profile_save (hwnd);
}
}
@@ -2619,11 +2478,11 @@ VOID _app_command_openeditor (
ptr_rule->protocol = ptr_network->protocol;
- string = _app_formataddress (ptr_network->af, 0, &ptr_network->remote_addr, ptr_network->remote_port, FMTADDR_AS_RULE);
- _r_obj_movereference ((PVOID_PTR)&ptr_rule->rule_remote, string);
+ if (_app_checkipisnotlocal (ptr_network->af, &ptr_network->remote_addr))
+ _r_obj_movereference ((PVOID_PTR)&ptr_rule->rule_remote, _app_formataddress (ptr_network->af, 0, &ptr_network->remote_addr, ptr_network->remote_port, FMTADDR_AS_RULE));
- string = _app_formataddress (ptr_network->af, 0, &ptr_network->local_addr, ptr_network->local_port, FMTADDR_AS_RULE);
- _r_obj_movereference ((PVOID_PTR)&ptr_rule->rule_local, string);
+ if (_app_checkipisnotlocal (ptr_network->af, &ptr_network->local_addr))
+ _r_obj_movereference ((PVOID_PTR)&ptr_rule->rule_local, _app_formataddress (ptr_network->af, 0, &ptr_network->local_addr, ptr_network->local_port, FMTADDR_AS_RULE));
_r_obj_dereference (ptr_network);
}
@@ -2643,19 +2502,22 @@ VOID _app_command_openeditor (
if (ptr_log)
{
- if (!ptr_rule->name)
- ptr_rule->name = _r_listview_getitemtext (hwnd, tab_context->listview_id, item_id, 0);
+ _r_obj_movereference ((PVOID_PTR)&ptr_rule->name, _r_listview_getitemtext (hwnd, tab_context->listview_id, item_id, 0));
if (ptr_log->app_hash && !_r_obj_isstringempty (ptr_log->path))
{
if (!_app_isappfound (ptr_log->app_hash))
{
- ptr_log->app_hash = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_log->path, NULL, NULL);
+ ptr_app = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_log->path, NULL, NULL);
- if (ptr_log->app_hash)
+ if (ptr_app)
{
+ ptr_log->app_hash = ptr_app->app_hash;
+
_app_listview_updateby_param (hwnd, ptr_log->app_hash, PR_SETITEM_UPDATE, TRUE);
+ _r_obj_dereference (ptr_app);
+
_app_profile_save (hwnd);
}
}
@@ -2663,14 +2525,14 @@ VOID _app_command_openeditor (
_r_obj_addhashtableitem (ptr_rule->apps, ptr_log->app_hash, NULL);
}
- ptr_rule->protocol = ptr_log->protocol;
ptr_rule->direction = ptr_log->direction;
+ ptr_rule->protocol = ptr_log->protocol;
- string = _app_formataddress (ptr_log->af, 0, &ptr_log->remote_addr, ptr_log->remote_port, FMTADDR_AS_RULE);
- _r_obj_movereference ((PVOID_PTR)&ptr_rule->rule_remote, string);
+ if (_app_checkipisnotlocal (ptr_log->af, &ptr_log->remote_addr))
+ _r_obj_movereference ((PVOID_PTR)&ptr_rule->rule_remote, _app_formataddress (ptr_log->af, 0, &ptr_log->remote_addr, ptr_log->remote_port, FMTADDR_AS_RULE));
- string = _app_formataddress (ptr_log->af, 0, &ptr_log->local_addr, ptr_log->local_port, FMTADDR_AS_RULE);
- _r_obj_movereference ((PVOID_PTR)&ptr_rule->rule_local, string);
+ if (_app_checkipisnotlocal (ptr_log->af, &ptr_log->local_addr))
+ _r_obj_movereference ((PVOID_PTR)&ptr_rule->rule_local, _app_formataddress (ptr_log->af, 0, &ptr_log->local_addr, ptr_log->local_port, FMTADDR_AS_RULE));
_r_obj_dereference (ptr_log);
}
@@ -2741,21 +2603,22 @@ VOID _app_command_properties (
if (context)
{
- _app_listview_lock (hwnd, tab_context->listview_id, TRUE);
+ _app_listview_lock (hwnd, tab_context->listview_id);
_app_setappiteminfo (hwnd, tab_context->listview_id, item_id, ptr_app);
- _app_listview_lock (hwnd, tab_context->listview_id, FALSE);
+ _app_listview_unlock (hwnd, tab_context->listview_id);
_app_listview_updateby_id (hwnd, tab_context->listview_id, 0);
- _app_profile_save (hwnd);
-
_app_editor_deletewindow (context);
+
+ _app_profile_save (hwnd);
}
_r_obj_dereference (ptr_app);
break;
}
+
case IDC_RULES_BLOCKLIST:
case IDC_RULES_SYSTEM:
case IDC_RULES_CUSTOM:
@@ -2770,15 +2633,15 @@ VOID _app_command_properties (
if (context)
{
- _app_listview_lock (hwnd, tab_context->listview_id, TRUE);
+ _app_listview_lock (hwnd, tab_context->listview_id);
_app_setruleiteminfo (hwnd, tab_context->listview_id, item_id, ptr_rule, TRUE);
- _app_listview_lock (hwnd, tab_context->listview_id, FALSE);
+ _app_listview_unlock (hwnd, tab_context->listview_id);
_app_listview_updateby_id (hwnd, tab_context->listview_id, 0);
- _app_profile_save (hwnd);
-
_app_editor_deletewindow (context);
+
+ _app_profile_save (hwnd);
}
_r_obj_dereference (ptr_rule);
@@ -2798,13 +2661,17 @@ VOID _app_command_properties (
{
if (!_app_isappfound (ptr_network->app_hash))
{
- ptr_network->app_hash = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_network->path, NULL, NULL);
+ ptr_app = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_network->path, NULL, NULL);
- if (ptr_network->app_hash)
+ if (ptr_app)
{
+ ptr_network->app_hash = ptr_app->app_hash;
+
_app_listview_updateby_param (hwnd, ptr_network->app_hash, PR_SETITEM_UPDATE, TRUE);
_app_profile_save (hwnd);
+
+ _r_obj_dereference (ptr_app);
}
}
@@ -2829,13 +2696,17 @@ VOID _app_command_properties (
{
if (!_app_isappfound (ptr_log->app_hash))
{
- ptr_log->app_hash = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_log->path, NULL, NULL);
+ ptr_app = _app_addapplication (hwnd, DATA_UNKNOWN, ptr_log->path, NULL, NULL);
- if (ptr_log->app_hash)
+ if (ptr_app)
{
+ ptr_log->app_hash = ptr_app->app_hash;
+
_app_listview_updateby_param (hwnd, ptr_log->app_hash, PR_SETITEM_UPDATE, TRUE);
_app_profile_save (hwnd);
+
+ _r_obj_dereference (ptr_app);
}
}
@@ -2857,16 +2728,16 @@ VOID _app_command_purgeunused (
R_STRINGBUILDER sb;
PITEM_APP ptr_app = NULL;
PR_STRING string = NULL;
- PR_HASHTABLE apps_list;
+ PR_LIST apps_list;
PR_ARRAY guids;
- HANDLE hengine;
ULONG_PTR enum_key = 0;
ULONG hash_code;
+ INT i = 1;
- apps_list = _r_obj_createhashtable (sizeof (ULONG_PTR), 8, NULL);
- guids = _r_obj_createarray (sizeof (GUID), 10, NULL);
+ apps_list = _r_obj_createlist (0x10, NULL);
+ guids = _r_obj_createarray (sizeof (GUID), 0x10, NULL);
- _r_obj_initializestringbuilder (&sb, 256);
+ _r_obj_initializestringbuilder (&sb, 0);
_r_queuedlock_acquireshared (&lock_apps);
@@ -2875,57 +2746,57 @@ VOID _app_command_purgeunused (
if (!_app_isappunused (ptr_app) || ptr_app->type == DATA_APP_SERVICE || ptr_app->type == DATA_APP_UWP)
continue;
- _app_deleteappitem (hwnd, ptr_app->type, hash_code);
-
- _app_timer_reset (NULL, ptr_app);
-
- _app_notify_freeobject (NULL, ptr_app);
-
if (!_r_obj_isempty (ptr_app->guids))
_r_obj_addarrayitems (guids, ptr_app->guids->items, ptr_app->guids->count);
- _r_obj_addhashtableitem (apps_list, hash_code, NULL);
+ _r_obj_addlistitem (apps_list, ptr_app, NULL);
- string = _app_getapppath (ptr_app, _r_config_getboolean (L"IsShortPath", TRUE, NULL));
+ string = _app_getapppath (ptr_app);
if (string)
{
- _r_obj_appendstringbuilder (&sb, L"- ");
-
+ _r_obj_appendstringbuilderformat (&sb, L"%d. ", i);
_r_obj_appendstringbuilder2 (&sb, &string->sr);
_r_obj_appendstringbuilder (&sb, SZ_CRLF);
_r_obj_dereference (string);
+
+ i += 1;
}
}
_r_queuedlock_releaseshared (&lock_apps);
- if (_r_obj_gethashtablesize (apps_list))
+ if (_r_obj_getlistsize (apps_list))
{
- enum_key = 0;
-
string = _r_obj_finalstringbuilder (&sb);
_r_str_trimstring2 (&string->sr, SZ_CRLF, PR_TRIM_END_ONLY);
if (_r_show_confirmmessage (hwnd, _r_locale_getstring (IDS_PURGE_UNUSED), string->buffer, L"ConfirmUnused", FALSE))
{
- _r_queuedlock_acquireexclusive (&lock_apps);
+ //_r_queuedlock_acquireexclusive (&lock_apps);
- while (_r_obj_enumhashtable (apps_list, NULL, &hash_code, &enum_key))
+ for (ULONG_PTR i = 0; i < _r_obj_getlistsize (apps_list); i++)
{
+ ptr_app = (PITEM_APP)_r_obj_getlistitem (apps_list, i);
+
+ if (!ptr_app)
+ continue;
+
+ hash_code = ptr_app->app_hash;
+
+ _app_deleteappitem (hwnd, ptr_app->type, hash_code);
+ _app_notify_freeobject (NULL, ptr_app);
+ _app_timer_reset (NULL, ptr_app);
+
_app_freeapplication (hwnd, hash_code);
}
- _r_queuedlock_releaseexclusive (&lock_apps);
+ //_r_queuedlock_releaseexclusive (&lock_apps);
if (!_r_obj_isempty2 (guids) && _wfp_isfiltersinstalled ())
- {
- hengine = _wfp_getenginehandle ();
-
- _wfp_destroyfilters_array (hengine, guids, DBG_ARG);
- }
+ _wfp_destroyfilters_array (_wfp_getenginehandle (), guids, DBG_ARG);
_app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE);
@@ -2945,18 +2816,17 @@ VOID _app_command_purgetimers (
{
PITEM_APP ptr_app = NULL;
R_STRINGBUILDER sb;
- PR_STRING string;
- PR_STRING path;
- HANDLE hengine;
- PR_LIST rules;
+ PR_LIST apps_list;
+ PR_STRING path, string;
ULONG_PTR enum_key = 0;
+ INT i = 1;
if (!_app_istimersactive ())
return;
- rules = _r_obj_createlist (10, NULL);
+ apps_list = _r_obj_createlist (0x10, NULL);
- _r_obj_initializestringbuilder (&sb, 0x100);
+ _r_obj_initializestringbuilder (&sb, 0);
_r_queuedlock_acquireshared (&lock_apps);
@@ -2964,13 +2834,13 @@ VOID _app_command_purgetimers (
{
if (_app_istimerset (ptr_app))
{
- _r_obj_addlistitem (rules, ptr_app, NULL);
+ _r_obj_addlistitem (apps_list, ptr_app, NULL);
- path = _app_getapppath (ptr_app, _r_config_getboolean (L"IsShortPath", TRUE, NULL));
+ path = _app_getapppath (ptr_app);
if (path)
{
- _r_obj_appendstringbuilder (&sb, L"- ");
+ _r_obj_appendstringbuilderformat (&sb, L"%d. ", i);
_r_obj_appendstringbuilder2 (&sb, &path->sr);
@@ -2988,13 +2858,15 @@ VOID _app_command_purgetimers (
_r_obj_appendstringbuilder (&sb, SZ_CRLF);
_r_obj_dereference (path);
+
+ i += 1;
}
}
}
_r_queuedlock_releaseshared (&lock_apps);
- if (!_r_obj_isempty2 (rules))
+ if (!_r_obj_isempty2 (apps_list))
{
string = _r_obj_finalstringbuilder (&sb);
@@ -3003,15 +2875,11 @@ VOID _app_command_purgetimers (
if (_r_show_confirmmessage (hwnd, _r_locale_getstring (IDS_QUESTION_TIMERS), string->buffer, L"ConfirmTimers", FALSE))
{
if (_wfp_isfiltersinstalled ())
- {
- hengine = _wfp_getenginehandle ();
+ _wfp_createappfilters (_wfp_getenginehandle (), apps_list, DBG_ARG, FALSE);
- _wfp_create3filters (hengine, rules, DBG_ARG, FALSE);
- }
-
- for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
+ for (ULONG_PTR i = 0; i < _r_obj_getlistsize (apps_list); i++)
{
- ptr_app = _r_obj_getlistitem (rules, i);
+ ptr_app = (PITEM_APP)_r_obj_getlistitem (apps_list, i);
if (ptr_app)
_app_timer_reset (hwnd, ptr_app);
@@ -3025,7 +2893,7 @@ VOID _app_command_purgetimers (
_r_obj_deletestringbuilder (&sb);
- _r_obj_dereference (rules);
+ _r_obj_dereference (apps_list);
}
VOID _app_command_selectfont (
@@ -3035,12 +2903,11 @@ VOID _app_command_selectfont (
CHOOSEFONT cf = {0};
LOGFONT lf = {0};
LONG dpi_value;
- UINT flags;
cf.lStructSize = sizeof (CHOOSEFONT);
cf.hwndOwner = hwnd;
cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_NOSCRIPTSEL | CF_LIMITSIZE | CF_NOVERTFONTS;
- cf.nSizeMax = 16;
+ cf.nSizeMax = 32;
cf.nSizeMin = 8;
cf.lpLogFont = &lf;
@@ -3056,7 +2923,5 @@ VOID _app_command_selectfont (
_app_listview_loadfont (dpi_value, TRUE);
_app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE);
- flags = RDW_NOFRAME | RDW_NOINTERNALPAINT | RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN;
-
- RedrawWindow (hwnd, NULL, NULL, flags);
+ RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_NOINTERNALPAINT | RDW_ALLCHILDREN | RDW_NOFRAME);
}
diff --git a/src/messages.h b/src/messages.h
index f3cb21ad..dca9be32 100644
--- a/src/messages.h
+++ b/src/messages.h
@@ -7,11 +7,14 @@ VOID _app_message_initialize (
_In_ HWND hwnd
);
-VOID _app_message_localize (
+FORCEINLINE VOID _app_message_uninitialize (
_In_ HWND hwnd
-);
+)
+{
+ _r_tray_destroy (hwnd, &GUID_TrayIcon);
+}
-VOID _app_message_uninitialize (
+VOID _app_message_localize (
_In_ HWND hwnd
);
@@ -22,6 +25,17 @@ VOID _app_generate_appmenu (
_In_ ULONG app_hash
);
+VOID _app_generate_rulescontrol (
+ _In_ HMENU hsubmenu,
+ _In_ ULONG app_hash,
+ _In_opt_ PITEM_LOG ptr_log
+);
+
+VOID _app_generate_timerscontrol (
+ _In_ HMENU hsubmenu,
+ _In_ ULONG app_hash
+);
+
VOID _app_message_contextmenu (
_In_ HWND hwnd,
_In_ LPNMITEMACTIVATE lpnmlv
diff --git a/src/network.c b/src/network.c
index 0f137b77..13e1eb5b 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2019-2025 Henry++
+// Copyright (c) 2019-2026 Henry++
#include "global.h"
@@ -11,10 +11,10 @@ PITEM_NETWORK_CONTEXT _app_network_getcontext ()
if (_r_initonce_begin (&init_once))
{
- network_context = _r_mem_allocate (sizeof (ITEM_NETWORK_CONTEXT));
+ network_context = (PITEM_NETWORK_CONTEXT)_r_mem_allocate (sizeof (ITEM_NETWORK_CONTEXT));
- network_context->network_ptr = _r_obj_createhashtablepointer (256);
- network_context->checker_ptr = _r_obj_createhashtablepointer (256);
+ network_context->network_ptr = _r_obj_createhashtablepointer (0x100);
+ network_context->checker_ptr = _r_obj_createhashtablepointer (0x100);
_r_initonce_end (&init_once);
}
@@ -28,11 +28,8 @@ VOID _app_network_initialize (
{
PITEM_NETWORK_CONTEXT network_context;
R_ENVIRONMENT environment;
- BOOLEAN is_enabled;
- is_enabled = _r_config_getboolean (L"IsNetworkMonitorEnabled", TRUE, NULL);
-
- if (!is_enabled)
+ if (!_r_config_getboolean (L"IsNetworkMonitorEnabled", TRUE, NULL))
return;
network_context = _app_network_getcontext ();
@@ -73,24 +70,21 @@ VOID _app_network_generatetable (
_Inout_ PITEM_NETWORK_CONTEXT network_context
)
{
- PMIB_TCPTABLE_OWNER_MODULE tcp4_table;
PMIB_TCP6TABLE_OWNER_MODULE tcp6_table;
- PMIB_UDPTABLE_OWNER_MODULE udp4_table;
PMIB_UDP6TABLE_OWNER_MODULE udp6_table;
+ PMIB_TCPTABLE_OWNER_MODULE tcp4_table;
+ PMIB_UDPTABLE_OWNER_MODULE udp4_table;
PITEM_NETWORK ptr_network;
- IN_ADDR remote_addr;
- IN_ADDR local_addr;
+ IN_ADDR local_addr, remote_addr;
PVOID buffer;
- ULONG network_hash;
- ULONG allocated_size;
- ULONG required_size;
+ ULONG allocated_size, network_hash, required_size = 0;
ULONG status;
_r_queuedlock_acquireexclusive (&network_context->lock_checker);
_r_obj_clearhashtable (network_context->checker_ptr);
_r_queuedlock_releaseexclusive (&network_context->lock_checker);
- required_size = 0;
+ // TCP IPv4
GetExtendedTcpTable (NULL, &required_size, FALSE, AF_INET, TCP_TABLE_OWNER_MODULE_ALL, 0);
allocated_size = required_size;
@@ -98,15 +92,15 @@ VOID _app_network_generatetable (
if (required_size)
{
- tcp4_table = buffer;
+ tcp4_table = (PMIB_TCPTABLE_OWNER_MODULE)buffer;
status = GetExtendedTcpTable (tcp4_table, &required_size, FALSE, AF_INET, TCP_TABLE_OWNER_MODULE_ALL, 0);
if (status == NO_ERROR)
{
for (ULONG i = 0; i < tcp4_table->dwNumEntries; i++)
{
- RtlZeroMemory (&remote_addr, sizeof (remote_addr));
- RtlZeroMemory (&local_addr, sizeof (local_addr));
+ RtlZeroMemory (&remote_addr, sizeof (IN_ADDR));
+ RtlZeroMemory (&local_addr, sizeof (IN_ADDR));
remote_addr.S_un.S_addr = tcp4_table->table[i].dwRemoteAddr;
local_addr.S_un.S_addr = tcp4_table->table[i].dwLocalAddr;
@@ -125,26 +119,23 @@ VOID _app_network_generatetable (
if (_app_network_isitemfound (network_hash))
{
_r_queuedlock_acquireexclusive (&network_context->lock_checker);
-
_r_obj_addhashtablepointer (network_context->checker_ptr, network_hash, NULL);
-
_r_queuedlock_releaseexclusive (&network_context->lock_checker);
continue;
}
- ptr_network = _r_obj_allocate (sizeof (ITEM_NETWORK), &_app_dereferencenetwork);
+ ptr_network = (PITEM_NETWORK)_r_obj_allocate (sizeof (ITEM_NETWORK), &_app_dereferencenetwork);
if (!_app_network_getpath (ptr_network, tcp4_table->table[i].dwOwningPid, tcp4_table->table[i].OwningModuleInfo))
{
_r_obj_dereference (ptr_network);
-
continue;
}
ptr_network->af = AF_INET;
ptr_network->protocol = IPPROTO_TCP;
- ptr_network->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_network->protocol, ptr_network->af));
+ ptr_network->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_network->protocol, ptr_network->af, L""));
ptr_network->remote_addr.S_un.S_addr = tcp4_table->table[i].dwRemoteAddr;
ptr_network->remote_port = _r_byteswap_ushort ((USHORT)tcp4_table->table[i].dwRemotePort);
@@ -171,6 +162,7 @@ VOID _app_network_generatetable (
}
}
+ // TCP IPv6
required_size = 0;
GetExtendedTcpTable (NULL, &required_size, FALSE, AF_INET6, TCP_TABLE_OWNER_MODULE_ALL, 0);
@@ -183,7 +175,7 @@ VOID _app_network_generatetable (
allocated_size = required_size;
}
- tcp6_table = buffer;
+ tcp6_table = (PMIB_TCP6TABLE_OWNER_MODULE)buffer;
status = GetExtendedTcpTable (tcp6_table, &required_size, FALSE, AF_INET6, TCP_TABLE_OWNER_MODULE_ALL, 0);
if (status == NO_ERROR)
@@ -210,18 +202,17 @@ VOID _app_network_generatetable (
continue;
}
- ptr_network = _r_obj_allocate (sizeof (ITEM_NETWORK), &_app_dereferencenetwork);
+ ptr_network = (PITEM_NETWORK)_r_obj_allocate (sizeof (ITEM_NETWORK), &_app_dereferencenetwork);
if (!_app_network_getpath (ptr_network, tcp6_table->table[i].dwOwningPid, tcp6_table->table[i].OwningModuleInfo))
{
_r_obj_dereference (ptr_network);
-
continue;
}
ptr_network->af = AF_INET6;
ptr_network->protocol = IPPROTO_TCP;
- ptr_network->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_network->protocol, ptr_network->af));
+ ptr_network->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_network->protocol, ptr_network->af, L""));
RtlCopyMemory (ptr_network->remote_addr6.u.Byte, tcp6_table->table[i].ucRemoteAddr, FWP_V6_ADDR_SIZE);
ptr_network->remote_port = _r_byteswap_ushort ((USHORT)tcp6_table->table[i].dwRemotePort);
@@ -248,6 +239,7 @@ VOID _app_network_generatetable (
}
}
+ // UDP IPv4
required_size = 0;
GetExtendedUdpTable (NULL, &required_size, FALSE, AF_INET, UDP_TABLE_OWNER_MODULE, 0);
@@ -259,27 +251,18 @@ VOID _app_network_generatetable (
allocated_size = required_size;
}
- udp4_table = buffer;
+ udp4_table = (PMIB_UDPTABLE_OWNER_MODULE)buffer;
status = GetExtendedUdpTable (udp4_table, &required_size, FALSE, AF_INET, UDP_TABLE_OWNER_MODULE, 0);
if (status == NO_ERROR)
{
for (ULONG i = 0; i < udp4_table->dwNumEntries; i++)
{
- RtlZeroMemory (&local_addr, sizeof (local_addr));
+ RtlZeroMemory (&local_addr, sizeof (IN_ADDR));
local_addr.S_un.S_addr = udp4_table->table[i].dwLocalAddr;
- network_hash = _app_network_gethash (
- AF_INET,
- udp4_table->table[i].dwOwningPid,
- NULL,
- 0,
- &local_addr,
- udp4_table->table[i].dwLocalPort,
- IPPROTO_UDP,
- 0
- );
+ network_hash = _app_network_gethash (AF_INET, udp4_table->table[i].dwOwningPid, NULL, 0, &local_addr, udp4_table->table[i].dwLocalPort, IPPROTO_UDP, 0);
if (_app_network_isitemfound (network_hash))
{
@@ -290,18 +273,17 @@ VOID _app_network_generatetable (
continue;
}
- ptr_network = _r_obj_allocate (sizeof (ITEM_NETWORK), &_app_dereferencenetwork);
+ ptr_network = (PITEM_NETWORK)_r_obj_allocate (sizeof (ITEM_NETWORK), &_app_dereferencenetwork);
if (!_app_network_getpath (ptr_network, udp4_table->table[i].dwOwningPid, udp4_table->table[i].OwningModuleInfo))
{
_r_obj_dereference (ptr_network);
-
continue;
}
ptr_network->af = AF_INET;
ptr_network->protocol = IPPROTO_UDP;
- ptr_network->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_network->protocol, ptr_network->af));
+ ptr_network->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_network->protocol, ptr_network->af, L""));
ptr_network->local_addr.S_un.S_addr = udp4_table->table[i].dwLocalAddr;
ptr_network->local_port = _r_byteswap_ushort ((USHORT)udp4_table->table[i].dwLocalPort);
@@ -320,6 +302,7 @@ VOID _app_network_generatetable (
}
}
+ // UDP IPv6
required_size = 0;
GetExtendedUdpTable (NULL, &required_size, FALSE, AF_INET6, UDP_TABLE_OWNER_MODULE, 0);
@@ -331,23 +314,14 @@ VOID _app_network_generatetable (
allocated_size = required_size;
}
- udp6_table = buffer;
+ udp6_table = (PMIB_UDP6TABLE_OWNER_MODULE)buffer;
status = GetExtendedUdpTable (udp6_table, &required_size, FALSE, AF_INET6, UDP_TABLE_OWNER_MODULE, 0);
if (status == NO_ERROR)
{
for (ULONG i = 0; i < udp6_table->dwNumEntries; i++)
{
- network_hash = _app_network_gethash (
- AF_INET6,
- udp6_table->table[i].dwOwningPid,
- NULL,
- 0,
- udp6_table->table[i].ucLocalAddr,
- udp6_table->table[i].dwLocalPort,
- IPPROTO_UDP,
- 0
- );
+ network_hash = _app_network_gethash (AF_INET6, udp6_table->table[i].dwOwningPid, NULL, 0, udp6_table->table[i].ucLocalAddr, udp6_table->table[i].dwLocalPort, IPPROTO_UDP, 0);
if (_app_network_isitemfound (network_hash))
{
@@ -358,18 +332,17 @@ VOID _app_network_generatetable (
continue;
}
- ptr_network = _r_obj_allocate (sizeof (ITEM_NETWORK), &_app_dereferencenetwork);
+ ptr_network = (PITEM_NETWORK)_r_obj_allocate (sizeof (ITEM_NETWORK), &_app_dereferencenetwork);
if (!_app_network_getpath (ptr_network, udp6_table->table[i].dwOwningPid, udp6_table->table[i].OwningModuleInfo))
{
_r_obj_dereference (ptr_network);
-
continue;
}
ptr_network->af = AF_INET6;
ptr_network->protocol = IPPROTO_UDP;
- ptr_network->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_network->protocol, ptr_network->af));
+ ptr_network->protocol_str = _r_obj_createstring (_app_db_getprotoname (ptr_network->protocol, ptr_network->af, L""));
RtlCopyMemory (ptr_network->local_addr6.u.Byte, udp6_table->table[i].ucLocalAddr, FWP_V6_ADDR_SIZE);
ptr_network->local_port = _r_byteswap_ushort ((USHORT)udp6_table->table[i].dwLocalPort);
@@ -406,7 +379,7 @@ PITEM_NETWORK _app_network_getitem (
return NULL;
_r_queuedlock_acquireshared (&network_context->lock_network);
- ptr_network = _r_obj_findhashtablepointer (network_context->network_ptr, network_hash);
+ ptr_network = (PITEM_NETWORK)_r_obj_findhashtablepointer (network_context->network_ptr, network_hash);
_r_queuedlock_releaseshared (&network_context->lock_network);
return ptr_network;
@@ -443,18 +416,17 @@ ULONG _app_network_gethash (
_In_opt_ ULONG state
)
{
- WCHAR remote_address[LEN_IP_MAX] = {0};
- WCHAR local_address[LEN_IP_MAX] = {0};
- PR_STRING network_string;
- ULONG network_hash;
+ WCHAR local_address[LEN_IP_MAX] = {0}, remote_address[LEN_IP_MAX] = {0}, network_string[0x100];
if (remote_addr)
- _app_formatip (af, remote_addr, remote_address, RTL_NUMBER_OF (remote_address), FALSE);
+ _app_formatip (remote_address, RTL_NUMBER_OF (remote_address), af, remote_addr, FALSE);
if (local_addr)
- _app_formatip (af, local_addr, local_address, RTL_NUMBER_OF (local_address), FALSE);
+ _app_formatip (local_address, RTL_NUMBER_OF (local_address), af, local_addr, FALSE);
- network_string = _r_format_string (
+ _r_str_printf (
+ network_string,
+ RTL_NUMBER_OF (network_string),
L"%" TEXT (PRIu8) L"_%" TEXT (PR_ULONG) L"_%s_%" TEXT (PR_ULONG) L"_%s_%" TEXT (PR_ULONG) L"_%" TEXT (PRIu8) L"_%" TEXT (PR_ULONG),
af,
pid,
@@ -466,11 +438,7 @@ ULONG _app_network_gethash (
state
);
- network_hash = _r_str_gethash (&network_string->sr, TRUE);
-
- _r_obj_dereference (network_string);
-
- return network_hash;
+ return _r_str_gethash2 (network_string, TRUE);
}
BOOLEAN _app_network_getpath (
@@ -481,8 +449,7 @@ BOOLEAN _app_network_getpath (
{
PTOKEN_APPCONTAINER_INFORMATION app_container = NULL;
PR_STRING process_name = NULL;
- HANDLE hprocess;
- HANDLE htoken;
+ HANDLE hprocess, htoken;
NTSTATUS status;
if (pid == PROC_WAITING_PID)
@@ -516,14 +483,7 @@ BOOLEAN _app_network_getpath (
if (NT_SUCCESS (status))
{
- if (_r_sys_isprocessimmersive (hprocess))
- {
- ptr_network->type = DATA_APP_UWP;
- }
- else
- {
- ptr_network->type = DATA_APP_REGULAR;
- }
+ ptr_network->type = _r_sys_isprocessimmersive (hprocess) ? DATA_APP_UWP : DATA_APP_REGULAR;
if (ptr_network->type == DATA_APP_UWP)
{
@@ -625,14 +585,14 @@ BOOLEAN _app_network_isvalidconnection (
_In_ LPCVOID address
)
{
- PIN_ADDR p4addr;
PIN6_ADDR p6addr;
+ PIN_ADDR p4addr;
switch (af)
{
case AF_INET:
{
- p4addr = (PIN_ADDR)address;
+ p4addr = (const PIN_ADDR)address;
return (!IN4_IS_ADDR_UNSPECIFIED (p4addr) &&
!IN4_IS_ADDR_LOOPBACK (p4addr) &&
@@ -644,18 +604,21 @@ BOOLEAN _app_network_isvalidconnection (
case AF_INET6:
{
- p6addr = (PIN6_ADDR)address;
+ p6addr = (const PIN6_ADDR)address;
return (!IN6_IS_ADDR_UNSPECIFIED (p6addr) &&
!IN6_IS_ADDR_LOOPBACK (p6addr) &&
+ !IN6_IS_ADDR_ANYCAST (p6addr) &&
!IN6_IS_ADDR_LINKLOCAL (p6addr) &&
!IN6_IS_ADDR_MULTICAST (p6addr) &&
- !IN6_IS_ADDR_SITELOCAL (p6addr) &&
- !IN6_IS_ADDR_ANYCAST (p6addr));
+ !IN6_IS_ADDR_SITELOCAL (p6addr));
+ }
+
+ default:
+ {
+ return FALSE; // unknown address family
}
}
-
- return FALSE;
}
VOID _app_network_printlistviewtable (
@@ -665,11 +628,9 @@ VOID _app_network_printlistviewtable (
PITEM_NETWORK ptr_network = NULL;
PR_STRING string;
ULONG_PTR enum_key = 0;
- ULONG_PTR app_hash;
- ULONG network_hash;
+ ULONG app_hash, network_hash;
INT item_count;
- BOOLEAN is_highlight = FALSE;
- BOOLEAN is_refresh = FALSE;
+ BOOLEAN is_highlight = FALSE, is_refresh = FALSE;
if (_r_config_getboolean (L"IsEnableHighlighting", TRUE, NULL) && _r_config_getboolean (L"IsHighlightConnection", TRUE, L"colors"))
is_highlight = TRUE;
@@ -679,7 +640,7 @@ VOID _app_network_printlistviewtable (
while (_r_obj_enumhashtablepointer (network_context->network_ptr, (PVOID_PTR)&ptr_network, &network_hash, &enum_key))
{
- string = _r_obj_findhashtablepointer (network_context->checker_ptr, network_hash);
+ string = (PR_STRING)_r_obj_findhashtablepointer (network_context->checker_ptr, network_hash);
if (!string)
continue;
@@ -722,11 +683,8 @@ VOID _app_network_printlistviewtable (
_app_network_removeitem (network_hash);
- // redraw listview item
- if (!is_highlight || !app_hash)
- continue;
-
- _app_listview_updateby_param (network_context->hwnd, app_hash, PR_SETITEM_REDRAW, TRUE);
+ if (app_hash && is_highlight)
+ _app_listview_updateby_param (network_context->hwnd, app_hash, PR_SETITEM_REDRAW, TRUE); // redraw listview item
}
}
@@ -760,7 +718,7 @@ VOID NTAPI _app_network_threadproc (
_app_network_generatetable (network_context);
_app_network_printlistviewtable (network_context);
- _r_sys_waitforsingleobject (NtCurrentThread (), 3000);
+ _r_sys_waitforsingleobject (NtCurrentThread (), 2000);
}
_app_network_uninitialize (network_context);
diff --git a/src/network.h b/src/network.h
index 1da78f7d..84f09a72 100644
--- a/src/network.h
+++ b/src/network.h
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2019-2025 Henry++
+// Copyright (c) 2019-2026 Henry++
#pragma once
diff --git a/src/notifications.c b/src/notifications.c
index c768d9ba..93436a82 100644
--- a/src/notifications.c
+++ b/src/notifications.c
@@ -8,9 +8,7 @@ HWND _app_notify_getwindow (
_In_opt_ PITEM_LOG ptr_log
)
{
- HWND hwnd;
-
- hwnd = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnotification, NULL, NULL);
+ HWND hwnd = (HWND)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnotification, NULL, NULL);
if (hwnd)
{
@@ -27,7 +25,7 @@ HWND _app_notify_getwindow (
_r_sys_waitforsingleobject (config.hnotify_evt, 2000);
- return _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnotification, NULL, NULL);
+ return (HWND)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnotification, NULL, NULL);
}
_Ret_maybenull_
@@ -35,23 +33,18 @@ PNOTIFY_CONTEXT _app_notify_getcontext (
_In_ HWND hwnd
)
{
- PNOTIFY_CONTEXT context;
-
- context = _r_wnd_getcontext (hwnd, SHORT_MAX);
-
- return context;
+ return (PNOTIFY_CONTEXT)_r_wnd_getcontext (hwnd, SHORT_MAX);
}
VOID _app_notify_setcontext (
_In_ HWND hwnd,
- _In_opt_ PNOTIFY_CONTEXT context
+ _Inout_opt_ PNOTIFY_CONTEXT context
)
{
if (context)
+ {
context->hwnd = hwnd;
- if (context)
- {
_r_wnd_setcontext (hwnd, SHORT_MAX, context);
}
else
@@ -68,7 +61,7 @@ BOOLEAN _app_notify_command (
{
PITEM_APP ptr_app;
PR_LIST rules;
- HANDLE hengine;
+ HWND hmain;
ULONG app_hash;
app_hash = _app_notify_getapp_id (hwnd);
@@ -77,48 +70,45 @@ BOOLEAN _app_notify_command (
if (!ptr_app)
return FALSE;
+ hmain = _r_app_gethwnd ();
+
_app_notify_freeobject (hwnd, ptr_app);
- rules = _r_obj_createlist (4, NULL);
+ rules = _r_obj_createlist (0x02, NULL);
if (button_id == IDC_ALLOW_BTN || button_id == IDC_BLOCK_BTN)
{
ptr_app->is_enabled = (button_id == IDC_ALLOW_BTN);
ptr_app->is_silent = (button_id == IDC_BLOCK_BTN);
- if (ptr_app->is_enabled && seconds)
+ if (ptr_app->is_enabled && seconds > 0)
{
- _app_timer_set (_r_app_gethwnd (), ptr_app, seconds);
+ _app_timer_set (hmain, ptr_app, seconds);
}
else
{
- _app_listview_updateitemby_param (_r_app_gethwnd (), app_hash, TRUE);
+ if (hmain)
+ _app_listview_updateitemby_param (hmain, app_hash, TRUE);
}
_r_obj_addlistitem (rules, ptr_app, NULL);
}
else if (button_id == IDC_NEXT_BTN)
{
- // NOTHING!
+ NOTHING;
}
else if (button_id == IDM_DISABLENOTIFICATIONS)
{
ptr_app->is_silent = TRUE;
}
- ptr_app->last_notify = _r_unixtime_now ();
+ ptr_app->last_notify = _r_unixtime_now (); // store last display time
- if (rules->count)
- {
- if (_wfp_isfiltersinstalled ())
- {
- hengine = _wfp_getenginehandle ();
+ if (!_r_obj_isempty2 (rules) && _wfp_isfiltersinstalled ())
+ _wfp_createappfilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
- _wfp_create3filters (hengine, rules, DBG_ARG, FALSE);
- }
- }
-
- _app_listview_updateby_id (_r_app_gethwnd (), ptr_app->type, PR_UPDATE_TYPE);
+ if (hmain)
+ _app_listview_updateby_id (hmain, ptr_app->type, PR_UPDATE_TYPE);
_r_obj_dereference (ptr_app);
_r_obj_dereference (rules);
@@ -134,27 +124,23 @@ BOOLEAN _app_notify_addobject (
_Inout_ PITEM_APP ptr_app
)
{
- LONG64 current_time;
- LONG64 notification_timeout;
+ LONG64 current_time, notification_timeout;
- current_time = _r_unixtime_now ();
notification_timeout = _r_config_getlong64 (L"NotificationsTimeout", NOTIFY_TIMEOUT_DEFAULT, NULL);
+ current_time = _r_unixtime_now ();
// check for last display time
- if (notification_timeout && ((current_time - ptr_app->last_notify) <= notification_timeout))
+ if (notification_timeout > 0 && ((current_time - ptr_app->last_notify) <= notification_timeout))
return FALSE;
ptr_app->last_notify = current_time;
- _r_obj_swapreference (&ptr_app->notification, ptr_log);
+ _r_obj_swapreference ((PVOID_PTR)&ptr_app->notification, ptr_log);
if (_r_wnd_sendmessage (hwnd, 0, WM_NOTIFICATION, 0, (LPARAM)ptr_app->notification))
{
- if (_r_config_getboolean (L"IsNotificationsSound", TRUE, NULL))
- {
- if (!_r_config_getboolean (L"IsNotificationsFullscreenSilentMode", TRUE, NULL) || !_r_wnd_isfullscreenmode ())
- _app_notify_playsound ();
- }
+ if (_r_config_getboolean (L"IsNotificationsSound", TRUE, NULL) && (!_r_config_getboolean (L"IsNotificationsFullscreenSilentMode", TRUE, NULL) || !_r_wnd_isfullscreenmode ()))
+ _app_notify_playsound ();
return TRUE;
}
@@ -167,26 +153,22 @@ VOID _app_notify_freeobject (
_Inout_ PITEM_APP ptr_app
)
{
- ULONG_PTR app_hash;
-
if (!hwnd)
hwnd = _app_notify_getwindow (NULL);
if (ptr_app->notification)
- _r_obj_clearreference (&ptr_app->notification);
+ _r_obj_clearreference ((PVOID_PTR)&ptr_app->notification);
- if (!hwnd)
- return;
-
- app_hash = _app_notify_getnextapp_id (hwnd);
-
- if (app_hash)
+ if (hwnd)
{
- _app_notify_refresh (hwnd);
- }
- else
- {
- DestroyWindow (hwnd);
+ if (_app_notify_getnextapp_id (hwnd) != 0)
+ {
+ _app_notify_refresh (hwnd);
+ }
+ else
+ {
+ DestroyWindow (hwnd);
+ }
}
}
@@ -203,7 +185,7 @@ PITEM_LOG _app_notify_getobject (
if (!ptr_app)
return NULL;
- ptr_log = _r_obj_referencesafe (ptr_app->notification);
+ ptr_log = (PITEM_LOG)_r_obj_referencesafe (ptr_app->notification);
_r_obj_dereference (ptr_app);
@@ -215,30 +197,22 @@ HICON _app_notify_getapp_icon (
_In_ HWND hwnd
)
{
- PNOTIFY_CONTEXT context;
+ PNOTIFY_CONTEXT context = _app_notify_getcontext (hwnd);
- context = _app_notify_getcontext (hwnd);
-
- if (!context)
- return NULL;
-
- return context->hicon;
+ return context ? context->hicon : NULL;
}
+_Success_ (return != 0)
ULONG _app_notify_getapp_id (
_In_ HWND hwnd
)
{
- PNOTIFY_CONTEXT context;
+ PNOTIFY_CONTEXT context = _app_notify_getcontext (hwnd);
- context = _app_notify_getcontext (hwnd);
-
- if (!context)
- return 0;
-
- return context->app_hash;
+ return context ? context->app_hash : 0;
}
+_Success_ (return != 0)
ULONG _app_notify_getnextapp_id (
_In_ HWND hwnd
)
@@ -265,6 +239,7 @@ ULONG _app_notify_getnextapp_id (
continue;
app_hash = ptr_app->app_hash;
+
break;
}
@@ -306,14 +281,10 @@ VOID _app_notify_setapp_id (
_In_opt_ ULONG app_hash
)
{
- PNOTIFY_CONTEXT context;
+ PNOTIFY_CONTEXT context = _app_notify_getcontext (hwnd);
- context = _app_notify_getcontext (hwnd);
-
- if (!context)
- return;
-
- context->app_hash = app_hash;
+ if (context)
+ context->app_hash = app_hash;
}
VOID _app_notify_show (
@@ -321,11 +292,8 @@ VOID _app_notify_show (
_In_ PITEM_LOG ptr_log
)
{
- PR_STRING localized_string = NULL;
- PR_STRING string = NULL;
- PR_STRING loading;
- PR_STRING empty;
- WCHAR window_title[128];
+ PR_STRING empty, loading, localized_string = NULL, string = NULL;
+ WCHAR window_title[0x80];
PITEM_APP ptr_app;
HDWP hdefer;
BOOLEAN is_fullscreenmode;
@@ -335,7 +303,6 @@ VOID _app_notify_show (
if (!ptr_app)
{
DestroyWindow (hwnd);
-
return;
}
@@ -355,17 +322,16 @@ VOID _app_notify_show (
if (_r_obj_isstringempty (empty))
_r_obj_movereference ((PVOID_PTR)&empty, _r_obj_createstring (L"Empty..."));
- // print name
- _r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_NAME), L":"));
- _r_obj_movereference ((PVOID_PTR)&string, _app_getappdisplayname (ptr_app, TRUE));
-
- _r_ctrl_settablestring (hwnd, &hdefer, IDC_FILE_ID, &localized_string->sr, IDC_FILE_TEXT, string ? &string->sr : &empty->sr);
-
loading = _r_locale_getstring_ex (IDS_LOADING);
if (_r_obj_isstringempty (loading))
_r_obj_movereference ((PVOID_PTR)&loading, _r_obj_createstring (L"Loading..."));
+ // print name
+ _r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_NAME), L":"));
+ _r_obj_movereference ((PVOID_PTR)&string, _app_getappdisplayname (ptr_app, TRUE));
+ _r_ctrl_settablestring (hwnd, &hdefer, IDC_FILE_ID, &localized_string->sr, IDC_FILE_TEXT, string ? &string->sr : &empty->sr);
+
// print signature
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_SIGNATURE), L":"));
_r_ctrl_settablestring (hwnd, &hdefer, IDC_SIGNATURE_ID, &localized_string->sr, IDC_SIGNATURE_TEXT, &loading->sr);
@@ -381,13 +347,11 @@ VOID _app_notify_show (
// print port
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_PORT), L":"));
_r_obj_movereference ((PVOID_PTR)&string, _app_formatport (ptr_log->remote_port, ptr_log->protocol));
-
_r_ctrl_settablestring (hwnd, &hdefer, IDC_PORT_ID, &localized_string->sr, IDC_PORT_TEXT, string ? &string->sr : &empty->sr);
// print direction
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_DIRECTION), L":"));
_r_obj_movereference ((PVOID_PTR)&string, _app_db_getdirectionname (ptr_log->direction, ptr_log->is_loopback, TRUE));
-
_r_ctrl_settablestring (hwnd, &hdefer, IDC_DIRECTION_ID, &localized_string->sr, IDC_DIRECTION_TEXT, string ? &string->sr : &empty->sr);
// print filter name
@@ -397,7 +361,6 @@ VOID _app_notify_show (
// print date
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_DATE), L":"));
_r_obj_movereference ((PVOID_PTR)&string, _r_format_unixtime (ptr_log->timestamp, FDTF_SHORTDATE | FDTF_LONGTIME));
-
_r_ctrl_settablestring (hwnd, &hdefer, IDC_DATE_ID, &localized_string->sr, IDC_DATE_TEXT, string ? &string->sr : &empty->sr);
if (hdefer)
@@ -419,7 +382,7 @@ VOID _app_notify_show (
// set correct position
_app_notify_setposition (hwnd, FALSE);
- ShowWindow (hwnd, SW_SHOWNOACTIVATE);
+ ShowWindow (hwnd, SW_SHOWNA);
InvalidateRect (hwnd, NULL, TRUE);
@@ -429,24 +392,22 @@ VOID _app_notify_show (
if (string)
_r_obj_dereference (string);
+ _r_obj_dereference (ptr_app);
_r_obj_dereference (loading);
_r_obj_dereference (empty);
-
- _r_obj_dereference (ptr_app);
}
-// Play notification sound even if system have "nosound" mode
+// play notification sound even when system have "nosound" mode
VOID _app_notify_playsound ()
{
static volatile PR_STRING cached_path = NULL;
- PR_STRING current_path;
- PR_STRING path;
+ PR_STRING current_path, path;
HANDLE hkey;
ULONG flags = SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_SENTRY;
NTSTATUS status;
- current_path = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&cached_path, NULL, NULL);
+ current_path = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&cached_path, NULL, NULL);
if (_r_obj_isstringempty (current_path) || !_r_fs_isexists (¤t_path->sr))
{
@@ -458,7 +419,7 @@ VOID _app_notify_playsound ()
if (NT_SUCCESS (status))
{
- current_path = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&cached_path, path, current_path);
+ current_path = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&cached_path, path, current_path);
if (current_path)
_r_obj_dereference (path);
@@ -479,7 +440,7 @@ VOID _app_notify_queueinfo (
{
PITEM_CONTEXT context;
- context = _r_freelist_allocateitem (&context_free_list);
+ context = (PITEM_CONTEXT)_r_freelist_allocateitem (&context_free_list);
context->hwnd = hwnd;
context->base_address = _r_obj_reference (ptr_log);
@@ -487,28 +448,26 @@ VOID _app_notify_queueinfo (
_r_workqueue_queueitem (&resolve_notify_queue, &_app_queue_notifyinformation, context);
}
-VOID _app_notify_killprocess (
+BOOLEAN _app_notify_killprocess (
_In_ HWND hwnd
)
{
- PSYSTEM_PROCESS_INFORMATION process;
- PSYSTEM_PROCESS_INFORMATION spi;
+ PSYSTEM_PROCESS_INFORMATION process, spi;
PNOTIFY_CONTEXT context;
- HANDLE hprocess;
PITEM_APP ptr_app;
- PR_STRING path;
- PR_STRING file_name;
+ PR_STRING file_name, path;
+ HANDLE hprocess;
NTSTATUS status;
context = _app_notify_getcontext (hwnd);
if (!context)
- return;
+ return FALSE;
ptr_app = _app_getappitem (context->app_hash);
if (!ptr_app)
- return;
+ return FALSE;
status = _r_sys_enumprocesses (&spi);
@@ -518,7 +477,7 @@ VOID _app_notify_killprocess (
_r_log (LOG_LEVEL_ERROR, NULL, L"_r_sys_enumprocesses", status, NULL);
- return;
+ return FALSE;
}
file_name = _r_path_getbasenamestring (&ptr_app->real_path->sr);
@@ -527,10 +486,10 @@ VOID _app_notify_killprocess (
do
{
- if (!process->ImageName.Buffer)
+ if (!process->ImageName.Buffer || process->ImageName.Length == 0)
continue;
- if (_r_str_compare (process->ImageName.Buffer, file_name->buffer, TRUE) == 0)
+ if (_r_str_isequal2 (&file_name->sr, process->ImageName.Buffer, TRUE))
{
status = _r_sys_getprocessimagepathbyid (&path, HandleToULong (process->UniqueProcessId), TRUE);
@@ -551,7 +510,7 @@ VOID _app_notify_killprocess (
}
else
{
- _r_show_errormessage (hwnd, L"Cannot open process!", status, file_name->buffer, ET_NATIVE);
+ _r_show_errormessage (hwnd, L"Cannot open process for termination!", status, file_name->buffer, ET_NATIVE);
}
}
@@ -568,6 +527,8 @@ VOID _app_notify_killprocess (
_r_obj_dereference (file_name);
_r_mem_free (spi);
+
+ return NT_SUCCESS (status);
}
VOID _app_notify_refresh (
@@ -575,29 +536,18 @@ VOID _app_notify_refresh (
)
{
PITEM_LOG ptr_log;
- ULONG app_hash;
- if (!_r_wnd_isvisible (hwnd, TRUE))
+ if (!_r_wnd_isvisible (hwnd, TRUE) || !_r_config_getboolean (L"IsNotificationsEnabled", TRUE, NULL))
{
DestroyWindow (hwnd);
-
return;
}
- if (!_r_config_getboolean (L"IsNotificationsEnabled", TRUE, NULL))
- {
- DestroyWindow (hwnd);
-
- return;
- }
-
- app_hash = _app_notify_getapp_id (hwnd);
- ptr_log = _app_notify_getobject (app_hash);
+ ptr_log = _app_notify_getobject (_app_notify_getapp_id (hwnd));
if (!ptr_log)
{
DestroyWindow (hwnd);
-
return;
}
@@ -616,11 +566,10 @@ VOID _app_notify_setposition (
R_RECTANGLE window_rect;
HMONITOR hmonitor;
PRECT rect;
- LONG dpi_value;
LONG border_x;
- BOOLEAN is_intray;
- _r_wnd_getposition (hwnd, &window_rect);
+ if (!_r_wnd_getposition (hwnd, &window_rect))
+ return;
if (!is_forced && _r_wnd_isvisible (hwnd, FALSE))
{
@@ -630,9 +579,7 @@ VOID _app_notify_setposition (
return;
}
- is_intray = _r_config_getboolean (L"IsNotificationsOnTray", FALSE, NULL);
-
- if (is_intray)
+ if (_r_config_getboolean (L"IsNotificationsOnTray", FALSE, NULL))
{
monitor_info.cbSize = sizeof (MONITORINFO);
@@ -644,9 +591,7 @@ VOID _app_notify_setposition (
if (SHAppBarMessage (ABM_GETTASKBARPOS, &taskbar_rect))
{
- dpi_value = _r_dc_getwindowdpi (hwnd);
-
- border_x = _r_dc_getsystemmetrics (SM_CXBORDER, dpi_value);
+ border_x = _r_dc_getsystemmetrics (SM_CXBORDER, _r_dc_getwindowdpi (hwnd));
rect = &monitor_info.rcWork;
if (taskbar_rect.uEdge == ABE_LEFT)
@@ -688,13 +633,13 @@ VOID _app_notify_settimeout (
_In_ HWND hwnd
)
{
- _r_ctrl_enable (hwnd, IDC_RULES_BTN, FALSE);
_r_ctrl_enable (hwnd, IDC_KILLPROCESS_BTN, FALSE);
+ _r_ctrl_enable (hwnd, IDC_RULES_BTN, FALSE);
_r_ctrl_enable (hwnd, IDC_ALLOW_BTN, FALSE);
_r_ctrl_enable (hwnd, IDC_BLOCK_BTN, FALSE);
_r_ctrl_enable (hwnd, IDC_NEXT_BTN, FALSE);
- SetTimer (hwnd, NOTIFY_TIMER_SAFETY_ID, NOTIFY_TIMER_SAFETY_TIMEOUT, NULL);
+ _r_sys_settimer (hwnd, GENERAL_ID, NOTIFY_TIMER_SAFETY_TIMEOUT, NULL);
}
VOID _app_notify_initialize (
@@ -703,19 +648,13 @@ VOID _app_notify_initialize (
)
{
NONCLIENTMETRICS ncm = {0};
- HBITMAP hbmp_allow;
- HBITMAP hbmp_block;
- HBITMAP hbmp_cross;
- HBITMAP hbmp_next;
- HBITMAP hbmp_rules;
- LONG icon_small;
- LONG icon_large;
+ HBITMAP hbmp_allow, hbmp_block, hbmp_cross, hbmp_next, hbmp_rules;
+ LONG icon_large, icon_small;
// destroy previous resources
SAFE_DELETE_OBJECT (context->hfont_title);
SAFE_DELETE_OBJECT (context->hfont_link);
SAFE_DELETE_OBJECT (context->hfont_text);
-
SAFE_DELETE_ICON (context->hico_allow);
SAFE_DELETE_ICON (context->hico_block);
SAFE_DELETE_ICON (context->hico_cross);
@@ -726,14 +665,10 @@ VOID _app_notify_initialize (
icon_large = _r_dc_getsystemmetrics (SM_CXICON, dpi_value);
// set window icon
- _r_wnd_seticon (
- context->hwnd,
- _r_sys_loadsharedicon (NULL, MAKEINTRESOURCE (SIH_EXCLAMATION), icon_small),
- _r_sys_loadsharedicon (NULL, MAKEINTRESOURCE (SIH_EXCLAMATION), icon_large)
- );
+ _r_wnd_seticon (context->hwnd, _r_sys_loadsharedicon (NULL, MAKEINTRESOURCE (SIH_EXCLAMATION), icon_small), _r_sys_loadsharedicon (NULL, MAKEINTRESOURCE (SIH_EXCLAMATION), icon_large));
// set window font
- ncm.cbSize = sizeof (ncm);
+ ncm.cbSize = sizeof (NONCLIENTMETRICS);
if (_r_dc_getsystemparametersinfo (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, dpi_value))
{
@@ -815,25 +750,26 @@ VOID _app_notify_destroy (
{
PNOTIFY_CONTEXT context;
+ _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnotification, NULL, config.hnotification);
+
context = _app_notify_getcontext (hwnd);
if (!context)
return;
+ // remove context
_app_notify_setcontext (hwnd, NULL);
- SAFE_DELETE_ICON (context->hicon);
-
SAFE_DELETE_OBJECT (context->hfont_title);
SAFE_DELETE_OBJECT (context->hfont_link);
SAFE_DELETE_OBJECT (context->hfont_text);
-
SAFE_DELETE_ICON (context->hico_allow);
SAFE_DELETE_ICON (context->hico_block);
SAFE_DELETE_ICON (context->hico_cross);
SAFE_DELETE_ICON (context->hico_rules);
+ SAFE_DELETE_ICON (context->hicon);
- _r_mem_free (context);
+ _r_mem_free (context); // cleanup!
}
VOID _app_notify_drawgradient (
@@ -841,17 +777,14 @@ VOID _app_notify_drawgradient (
_In_ LPCRECT rect
)
{
- COLORREF gradient_arr[] = {
- RGB (0, 68, 112),
- RGB (7, 111, 95),
- };
+ COLORREF gradient_arr[] = {RGB (0, 68, 112), RGB (7, 111, 95)};
GRADIENT_RECT gradient_rect = {0};
TRIVERTEX trivertx[2] = {0};
static_assert (RTL_NUMBER_OF (gradient_arr) == RTL_NUMBER_OF (trivertx), "Invalid array size!");
gradient_rect.LowerRight = 1;
- //gradient_rect.UpperLeft = 0;
+ gradient_rect.UpperLeft = 0;
for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (trivertx); i++)
{
@@ -887,26 +820,22 @@ INT_PTR CALLBACK NotificationProc (
{
PNOTIFY_CONTEXT context;
PITEM_LOG ptr_log;
- HWND current_hwnd;
- HWND htip;
- LONG dpi_value;
+ HWND current_hwnd, htip;
- current_hwnd = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnotification, hwnd, config.hnotification);
+ current_hwnd = (HWND)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnotification, hwnd, config.hnotification);
if (current_hwnd)
DestroyWindow (current_hwnd);
// initialize window context
- context = _r_mem_allocate (sizeof (NOTIFY_CONTEXT));
+ context = (PNOTIFY_CONTEXT)_r_mem_allocate (sizeof (NOTIFY_CONTEXT));
_app_notify_setcontext (hwnd, context);
// set correct position
_app_notify_setposition (hwnd, FALSE);
- dpi_value = _r_dc_getwindowdpi (hwnd);
-
- _app_notify_initialize (context, dpi_value);
+ _app_notify_initialize (context, _r_dc_getwindowdpi (hwnd));
// initialize tips
htip = _r_ctrl_createtip (hwnd);
@@ -918,7 +847,7 @@ INT_PTR CALLBACK NotificationProc (
_r_ctrl_settiptext (htip, hwnd, IDC_KILLPROCESS_BTN, LPSTR_TEXTCALLBACK);
_r_ctrl_settiptext (htip, hwnd, IDC_ALLOW_BTN, LPSTR_TEXTCALLBACK);
_r_ctrl_settiptext (htip, hwnd, IDC_BLOCK_BTN, LPSTR_TEXTCALLBACK);
- _r_ctrl_settiptext (htip, hwnd, IDC_NEXT_BTN, L"NEXT!");
+ _r_ctrl_settiptext (htip, hwnd, IDC_NEXT_BTN, LPSTR_TEXTCALLBACK);
}
// display log information
@@ -949,10 +878,7 @@ INT_PTR CALLBACK NotificationProc (
case WM_NCDESTROY:
{
- _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&config.hnotification, NULL, config.hnotification);
-
_app_notify_destroy (hwnd);
-
break;
}
@@ -960,7 +886,7 @@ INT_PTR CALLBACK NotificationProc (
{
KillTimer (hwnd, wparam);
- if (wparam != NOTIFY_TIMER_SAFETY_ID)
+ if (wparam != GENERAL_ID)
break;
_r_ctrl_enable (hwnd, IDC_RULES_BTN, TRUE);
@@ -974,9 +900,7 @@ INT_PTR CALLBACK NotificationProc (
case WM_DPICHANGED:
{
- PNOTIFY_CONTEXT context;
-
- context = _app_notify_getcontext (hwnd);
+ PNOTIFY_CONTEXT context = _app_notify_getcontext (hwnd);
_r_wnd_message_dpichanged (hwnd, wparam, lparam);
@@ -1014,19 +938,8 @@ INT_PTR CALLBACK NotificationProc (
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
{
- HDC hdc;
- INT text_clr;
-
- hdc = (HDC)wparam;
-
- if (msg == WM_CTLCOLORSTATIC && (GetDlgCtrlID ((HWND)lparam) == IDC_FILE_TEXT))
- {
- text_clr = COLOR_HIGHLIGHT;
- }
- else
- {
- text_clr = COLOR_WINDOWTEXT;
- }
+ HDC hdc = (HDC)wparam;
+ INT text_clr = (msg == WM_CTLCOLORSTATIC && GetDlgCtrlID ((HWND)lparam) == IDC_FILE_TEXT) ? COLOR_HIGHLIGHT : COLOR_WINDOWTEXT;
SetBkMode (hdc, TRANSPARENT); // HACK!!!
@@ -1038,15 +951,11 @@ INT_PTR CALLBACK NotificationProc (
case WM_DRAWITEM:
{
- LPDRAWITEMSTRUCT draw_info;
- RECT rect;
- LONG dpi_value;
- LONG icon_size_x;
- LONG wnd_spacing;
+ LPDRAWITEMSTRUCT draw_info = (LPDRAWITEMSTRUCT)lparam;
PR_STRING string;
HICON hicon;
-
- draw_info = (LPDRAWITEMSTRUCT)lparam;
+ RECT rect;
+ LONG dpi_value, icon_size_x, wnd_spacing;
if (draw_info->CtlID != IDC_HEADER_ID)
break;
@@ -1067,14 +976,7 @@ INT_PTR CALLBACK NotificationProc (
if (string)
{
SetTextColor (draw_info->hDC, RGB (255, 255, 255));
-
- SetRect (
- &rect,
- wnd_spacing,
- 0,
- _r_calc_rectwidth (&draw_info->rcItem) - (wnd_spacing * 3) - icon_size_x,
- _r_calc_rectheight (&draw_info->rcItem)
- );
+ SetRect (&rect, wnd_spacing, 0, _r_calc_rectwidth (&draw_info->rcItem) - (wnd_spacing * 3) - icon_size_x, _r_calc_rectheight (&draw_info->rcItem));
_r_dc_drawtext (NULL, draw_info->hDC, &string->sr, &rect, 0, 0, DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOCLIP | DT_NOPREFIX, 0);
@@ -1086,25 +988,9 @@ INT_PTR CALLBACK NotificationProc (
if (hicon)
{
- SetRect (
- &rect,
- _r_calc_rectwidth (&draw_info->rcItem) - icon_size_x - wnd_spacing,
- (_r_calc_rectheight (&draw_info->rcItem) / 2) - (icon_size_x / 2),
- icon_size_x,
- icon_size_x
- );
+ SetRect (&rect, _r_calc_rectwidth (&draw_info->rcItem) - icon_size_x - wnd_spacing, (_r_calc_rectheight (&draw_info->rcItem) / 2) - (icon_size_x / 2), icon_size_x, icon_size_x);
- DrawIconEx (
- draw_info->hDC,
- rect.left,
- rect.top,
- hicon,
- rect.right,
- rect.bottom,
- 0,
- NULL,
- DI_IMAGE | DI_MASK
- );
+ DrawIconEx (draw_info->hDC, rect.left, rect.top, hicon, rect.right, rect.bottom, 0, NULL, DI_IMAGE | DI_MASK);
}
SetWindowLongPtrW (hwnd, DWLP_MSGRESULT, TRUE);
@@ -1114,11 +1000,7 @@ INT_PTR CALLBACK NotificationProc (
case WM_SETCURSOR:
{
- INT ctrl_id;
-
- ctrl_id = GetDlgCtrlID ((HWND)wparam);
-
- if (ctrl_id == IDC_FILE_TEXT)
+ if (GetDlgCtrlID ((HWND)wparam) == IDC_FILE_TEXT)
{
SetCursor (LoadCursorW (NULL, IDC_HAND));
@@ -1140,50 +1022,37 @@ INT_PTR CALLBACK NotificationProc (
case WM_EXITSIZEMOVE:
case WM_CAPTURECHANGED:
{
- HCURSOR hcursor;
- LONG_PTR ex_style;
-
- ex_style = _r_wnd_getstyle (hwnd, GWL_EXSTYLE);
+ LONG_PTR ex_style = _r_wnd_getstyle (hwnd, GWL_EXSTYLE);
if (!(ex_style & WS_EX_LAYERED))
_r_wnd_setstyle (hwnd, WS_EX_LAYERED, WS_EX_LAYERED, GWL_EXSTYLE);
- hcursor = LoadCursorW (NULL, (msg == WM_ENTERSIZEMOVE) ? IDC_SIZEALL : IDC_ARROW);
-
SetLayeredWindowAttributes (hwnd, 0, (msg == WM_ENTERSIZEMOVE) ? 150 : 255, LWA_ALPHA);
- SetCursor (hcursor);
+ SetCursor (LoadCursorW (NULL, (msg == WM_ENTERSIZEMOVE) ? IDC_SIZEALL : IDC_ARROW));
break;
}
case WM_NOTIFY:
{
- LPNMHDR nmlp;
-
- nmlp = (LPNMHDR)lparam;
+ LPNMHDR nmlp = (LPNMHDR)lparam;
switch (nmlp->code)
{
case BCN_DROPDOWN:
{
PNOTIFY_CONTEXT context;
- PITEM_LOG ptr_log;
R_RECTANGLE rectangle;
+ PITEM_LOG ptr_log;
RECT rect;
HMENU hsubmenu;
- INT ctrl_id;
-
- ctrl_id = (INT)(INT_PTR)nmlp->idFrom;
-
- if (!_r_ctrl_isenabled (hwnd, ctrl_id))
- break;
-
- if (ctrl_id != IDC_ALLOW_BTN && ctrl_id != IDC_RULES_BTN)
- break;
context = _app_notify_getcontext (hwnd);
- if (!context)
+ if (!context || !_r_ctrl_isenabled (hwnd, (INT)(INT_PTR)nmlp->idFrom))
+ break;
+
+ if (nmlp->idFrom != IDC_ALLOW_BTN && nmlp->idFrom != IDC_RULES_BTN)
break;
ptr_log = _app_notify_getobject (context->app_hash);
@@ -1193,11 +1062,11 @@ INT_PTR CALLBACK NotificationProc (
if (!hsubmenu)
break;
- if (ctrl_id == IDC_RULES_BTN)
+ if (nmlp->idFrom == IDC_RULES_BTN)
{
_app_generate_rulescontrol (hsubmenu, context->app_hash, ptr_log);
}
- else if (ctrl_id == IDC_ALLOW_BTN)
+ else if (nmlp->idFrom == IDC_ALLOW_BTN)
{
_app_generate_timerscontrol (hsubmenu, context->app_hash);
}
@@ -1210,7 +1079,7 @@ INT_PTR CALLBACK NotificationProc (
_r_wnd_adjustrectangletoworkingarea (&rectangle, nmlp->hwndFrom);
_r_wnd_rectangletorect (&rect, &rectangle);
- _r_menu_popup (hsubmenu, hwnd, (PPOINT)&rect, TRUE);
+ _r_menu_popup (hsubmenu, hwnd, (PPOINT)&rect, 0);
}
DestroyMenu (hsubmenu);
@@ -1220,14 +1089,12 @@ INT_PTR CALLBACK NotificationProc (
case TTN_GETDISPINFO:
{
- LPNMTTDISPINFOW lpnmdi;
- WCHAR buffer[1024] = {0};
+ LPNMTTDISPINFOW lpnmdi = (LPNMTTDISPINFOW)lparam;
+ WCHAR buffer[0x200] = {0};
PR_STRING string;
+ HWND hmain;
ULONG app_hash;
- INT ctrl_id;
- INT listview_id = 0;
-
- lpnmdi = (LPNMTTDISPINFOW)lparam;
+ INT ctrl_id, listview_id = 0;
if ((lpnmdi->uFlags & TTF_IDISHWND) == 0)
break;
@@ -1238,15 +1105,20 @@ INT_PTR CALLBACK NotificationProc (
{
app_hash = _app_notify_getapp_id (hwnd);
- if (_app_getappinfobyhash (app_hash, INFO_LISTVIEW_ID, &listview_id, sizeof (INT)))
+ hmain = _r_app_gethwnd ();
+
+ if (hmain)
{
- string = _app_gettooltipbylparam (_r_app_gethwnd (), listview_id, app_hash);
-
- if (string)
+ if (_app_getappinfobyhash (app_hash, INFO_LISTVIEW_ID, &listview_id, sizeof (INT)))
{
- _r_str_copy (buffer, RTL_NUMBER_OF (buffer), string->buffer);
+ string = _app_gettooltipbylparam (hmain, listview_id, app_hash);
- _r_obj_dereference (string);
+ if (string)
+ {
+ _r_str_copy (buffer, RTL_NUMBER_OF (buffer), string->buffer);
+
+ _r_obj_dereference (string);
+ }
}
}
}
@@ -1266,6 +1138,10 @@ INT_PTR CALLBACK NotificationProc (
{
_r_str_copy (buffer, RTL_NUMBER_OF (buffer), _r_locale_getstring (IDS_ACTION_TERMINATE_HINT));
}
+ else if (ctrl_id == IDC_NEXT_BTN)
+ {
+ _r_str_copy (buffer, RTL_NUMBER_OF (buffer), L"NEXT!");
+ }
else
{
string = _r_ctrl_getstring (hwnd, ctrl_id);
@@ -1290,18 +1166,16 @@ INT_PTR CALLBACK NotificationProc (
case WM_COMMAND:
{
- INT ctrl_id;
-
- ctrl_id = LOWORD (wparam);
+ INT ctrl_id = LOWORD (wparam);
if (ctrl_id >= IDX_RULES_SPECIAL && ctrl_id <= IDX_RULES_SPECIAL + (INT)(INT_PTR)_r_obj_getlistsize (rules_list) + 1)
{
- HANDLE hengine;
- PR_LIST rules;
PITEM_RULE ptr_rule;
PITEM_APP ptr_app;
PITEM_LOG ptr_log;
PR_STRING rule;
+ PR_LIST rules;
+ HWND hmain;
ULONG_PTR rule_idx;
ULONG app_hash;
BOOLEAN is_remove;
@@ -1312,9 +1186,11 @@ INT_PTR CALLBACK NotificationProc (
if (!ptr_app)
return FALSE;
- rule_idx = (ULONG_PTR)ctrl_id - IDX_RULES_SPECIAL;
+ rule_idx = (ULONG_PTR)(ctrl_id - IDX_RULES_SPECIAL);
ptr_rule = _app_getrulebyid (rule_idx);
+ hmain = _r_app_gethwnd ();
+
if (!ptr_rule)
{
ptr_log = _app_notify_getobject (app_hash);
@@ -1325,26 +1201,26 @@ INT_PTR CALLBACK NotificationProc (
ptr_rule = _app_addrule (NULL, NULL, NULL, FWP_DIRECTION_OUTBOUND, FWP_ACTION_PERMIT, ptr_log->protocol, ptr_log->af);
- ptr_rule->name = _r_obj_createstring2 (&rule->sr);
- ptr_rule->rule_remote = _r_obj_createstring2 (&rule->sr);
+ _r_obj_movereference ((PVOID_PTR)&ptr_rule->name, _r_obj_createstring2 (&rule->sr));
+ _r_obj_movereference ((PVOID_PTR)&ptr_rule->rule_remote, _r_obj_createstring2 (&rule->sr));
_app_ruleenable (ptr_rule, TRUE, FALSE);
_r_obj_addhashtableitem (ptr_rule->apps, app_hash, NULL);
- _r_obj_dereference (rule);
-
_r_queuedlock_acquireexclusive (&lock_rules);
_r_obj_addlistitem (rules_list, ptr_rule, &rule_idx);
_r_queuedlock_releaseexclusive (&lock_rules);
- if (rule_idx != SIZE_MAX)
+ if (hmain)
{
- _app_listview_addruleitem (_r_app_gethwnd (), ptr_rule, (ULONG)rule_idx, TRUE);
- _app_listview_updateby_id (_r_app_gethwnd (), DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE);
-
- _app_profile_save (hwnd);
+ _app_listview_addruleitem (hmain, ptr_rule, rule_idx, TRUE);
+ _app_listview_updateby_id (hmain, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE);
}
+
+ _app_profile_save (hwnd);
+
+ _r_obj_dereference (rule);
}
_app_notify_freeobject (hwnd, ptr_app);
@@ -1354,7 +1230,7 @@ INT_PTR CALLBACK NotificationProc (
_app_notify_freeobject (hwnd, ptr_app);
- if (!(ptr_rule->is_forservices && _app_issystemhash (app_hash)))
+ if (!((ptr_rule->is_fordriver || ptr_rule->is_forservice) && _app_issystemhash (app_hash)))
{
is_remove = ptr_rule->is_enabled && _r_obj_findhashtable (ptr_rule->apps, app_hash);
@@ -1372,23 +1248,25 @@ INT_PTR CALLBACK NotificationProc (
_app_ruleenable (ptr_rule, TRUE, TRUE);
}
- _app_listview_updateitemby_param (_r_app_gethwnd (), app_hash, TRUE);
- _app_listview_updateitemby_param (_r_app_gethwnd (), rule_idx, FALSE);
+ if (hmain)
+ {
+ _app_listview_updateitemby_param (hmain, app_hash, TRUE);
+ _app_listview_updateitemby_param (hmain, rule_idx, FALSE);
+ }
if (_wfp_isfiltersinstalled ())
{
- hengine = _wfp_getenginehandle ();
-
- rules = _r_obj_createlist (1, NULL);
+ rules = _r_obj_createlist (0x02, NULL);
_r_obj_addlistitem (rules, ptr_rule, NULL);
- _wfp_create4filters (hengine, rules, DBG_ARG, FALSE);
+ _wfp_createrulefilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
_r_obj_dereference (rules);
}
- _app_listview_updateby_id (_r_app_gethwnd (), DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE);
+ if (hmain)
+ _app_listview_updateby_id (hmain, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE);
_r_obj_dereference (ptr_rule);
_r_obj_dereference (ptr_app);
@@ -1401,15 +1279,13 @@ INT_PTR CALLBACK NotificationProc (
else if (ctrl_id >= IDX_TIMER && ctrl_id <= (IDX_TIMER + (RTL_NUMBER_OF (timer_array) - 1)))
{
ULONG_PTR timer_idx;
- LONG64 seconds;
if (!_r_ctrl_isenabled (hwnd, IDC_ALLOW_BTN))
return FALSE;
- timer_idx = (ULONG_PTR)ctrl_id - IDX_TIMER;
- seconds = timer_array[timer_idx];
+ timer_idx = (ULONG_PTR)(ctrl_id - IDX_TIMER);
- _app_notify_command (hwnd, IDC_ALLOW_BTN, seconds);
+ _app_notify_command (hwnd, IDC_ALLOW_BTN, timer_array[timer_idx]);
return FALSE;
}
@@ -1426,6 +1302,9 @@ INT_PTR CALLBACK NotificationProc (
{
ULONG app_hash;
+ if (!_r_app_gethwnd ())
+ break;
+
app_hash = _app_notify_getapp_id (hwnd);
if (app_hash)
@@ -1438,10 +1317,8 @@ INT_PTR CALLBACK NotificationProc (
{
PEDITOR_CONTEXT context;
PITEM_APP ptr_app;
- ULONG app_hash;
- app_hash = _app_notify_getapp_id (hwnd);
- ptr_app = _app_getappitem (app_hash);
+ ptr_app = _app_getappitem (_app_notify_getapp_id (hwnd));
if (!ptr_app)
break;
@@ -1470,50 +1347,42 @@ INT_PTR CALLBACK NotificationProc (
case IDC_KILLPROCESS_BTN:
{
- _app_notify_killprocess (hwnd);
-
- _r_ctrl_enable (hwnd, ctrl_id, FALSE);
+ if (_app_notify_killprocess (hwnd))
+ _r_ctrl_enable (hwnd, ctrl_id, FALSE);
break;
}
case IDM_OPENRULESEDITOR:
{
+ PR_STRING app_name, rule_name, rule_string;
PEDITOR_CONTEXT context;
- PITEM_APP ptr_app;
PITEM_RULE ptr_rule;
+ PITEM_APP ptr_app;
PITEM_LOG ptr_log;
- PR_STRING app_name;
- PR_STRING rule_name;
- PR_STRING rule_string;
+ HWND hmain;
ULONG_PTR rule_idx;
- ULONG app_hash;
- app_hash = _app_notify_getapp_id (hwnd);
- ptr_log = _app_notify_getobject (app_hash);
+ ptr_log = _app_notify_getobject (_app_notify_getapp_id (hwnd));
if (!ptr_log)
break;
- app_hash = ptr_log->app_hash;
- ptr_app = _app_getappitem (app_hash);
+ ptr_app = _app_getappitem (ptr_log->app_hash);
if (!ptr_app)
{
_r_obj_dereference (ptr_log);
-
break;
}
app_name = _app_getappdisplayname (ptr_app, TRUE);
-
rule_string = _app_formataddress (ptr_log->af, 0, &ptr_log->remote_addr, ptr_log->remote_port, FMTADDR_AS_RULE);
-
rule_name = _r_format_string (L"%s - %s", _r_obj_getstring (app_name), _r_obj_getstring (rule_string));
ptr_rule = _app_addrule (rule_name, rule_string, NULL, ptr_log->direction, FWP_ACTION_PERMIT, ptr_log->protocol, ptr_log->af);
- _r_obj_addhashtableitem (ptr_rule->apps, app_hash, NULL);
+ _r_obj_addhashtableitem (ptr_rule->apps, ptr_log->app_hash, NULL);
_app_ruleenable (ptr_rule, TRUE, TRUE);
@@ -1525,13 +1394,18 @@ INT_PTR CALLBACK NotificationProc (
_r_obj_addlistitem (rules_list, _r_obj_reference (ptr_rule), &rule_idx);
_r_queuedlock_releaseexclusive (&lock_rules);
+ hmain = _r_app_gethwnd ();
+
// set rule information
- _app_listview_addruleitem (_r_app_gethwnd (), ptr_rule, rule_idx, TRUE);
+ if (hmain)
+ {
+ _app_listview_addruleitem (hmain, ptr_rule, rule_idx, TRUE);
- // update app information
- _app_listview_updateitemby_param (_r_app_gethwnd (), app_hash, TRUE);
+ // update app information
+ _app_listview_updateitemby_param (hmain, ptr_log->app_hash, TRUE);
- _app_listview_updateby_id (_r_app_gethwnd (), DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE);
+ _app_listview_updateby_id (hmain, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE);
+ }
_app_profile_save (hwnd);
@@ -1540,12 +1414,12 @@ INT_PTR CALLBACK NotificationProc (
_app_notify_freeobject (hwnd, ptr_app);
- if (app_name)
- _r_obj_dereference (app_name);
-
if (rule_string)
_r_obj_dereference (rule_string);
+ if (app_name)
+ _r_obj_dereference (app_name);
+
_r_obj_dereference (rule_name);
_r_obj_dereference (ptr_rule);
_r_obj_dereference (ptr_log);
@@ -1557,8 +1431,7 @@ INT_PTR CALLBACK NotificationProc (
case IDM_COPY: // ctrl+c
case IDM_SELECT_ALL: // ctrl+a
{
- static R_STRINGREF sr = PR_STRINGREF_INIT (WC_EDITW);
-
+ R_STRINGREF sr = PR_STRINGREF_INIT (WC_EDIT);
PR_STRING class_name;
HWND hedit;
diff --git a/src/notifications.h b/src/notifications.h
index 354a3d6f..7d6e7ebe 100644
--- a/src/notifications.h
+++ b/src/notifications.h
@@ -34,7 +34,7 @@ PNOTIFY_CONTEXT _app_notify_getcontext (
VOID _app_notify_setcontext (
_In_ HWND hwnd,
- _In_opt_ PNOTIFY_CONTEXT context
+ _Inout_opt_ PNOTIFY_CONTEXT context
);
BOOLEAN _app_notify_command (
@@ -64,10 +64,12 @@ PITEM_LOG _app_notify_getobject (
_In_ ULONG app_hash
);
+_Success_ (return != 0)
ULONG _app_notify_getapp_id (
_In_ HWND hwnd
);
+_Success_ (return != 0)
ULONG _app_notify_getnextapp_id (
_In_ HWND hwnd
);
diff --git a/src/packages.c b/src/packages.c
index 4893de73..5c544aa5 100644
--- a/src/packages.c
+++ b/src/packages.c
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2016-2025 Henry++
+// Copyright (c) 2016-2026 Henry++
#include "global.h"
@@ -31,12 +31,10 @@ VOID _app_package_parsepath (
R_STRINGREF separator_sr = PR_STRINGREF_INIT (L"\\");
R_XML_LIBRARY xml_library = {0};
- PR_STRING manifest_path = NULL;
- PR_STRING result_path = NULL;
- PR_STRING path_string;
+ PR_STRING manifest_path = NULL, path_string, result_path = NULL;
R_STRINGREF executable_sr;
- HRESULT status;
BOOLEAN is_success = FALSE;
+ HRESULT status;
path_string = *package_root_folder;
@@ -47,7 +45,6 @@ VOID _app_package_parsepath (
if (_r_fs_isexists (&manifest_path->sr))
{
is_success = TRUE;
-
break;
}
}
@@ -77,7 +74,6 @@ VOID _app_package_parsepath (
if (_r_fs_isexists (&result_path->sr))
{
_r_obj_swapreference ((PVOID_PTR)package_root_folder, result_path);
-
break;
}
}
@@ -85,12 +81,12 @@ VOID _app_package_parsepath (
CleanupExit:
- if (result_path)
- _r_obj_dereference (result_path);
-
if (manifest_path)
_r_obj_dereference (manifest_path);
+ if (result_path)
+ _r_obj_dereference (result_path);
+
_r_xml_destroylibrary (&xml_library);
}
@@ -100,12 +96,10 @@ VOID _app_package_getpackagebyname (
_In_ PR_STRING key_name
)
{
- WCHAR buffer[256];
- PR_STRING package_sid_string = NULL;
- PR_STRING display_name = NULL;
- PR_STRING real_path = NULL;
+ PR_STRING display_name = NULL, package_sid_string = NULL, real_path = NULL;
PR_BYTE package_sid = NULL;
PITEM_APP ptr_app;
+ WCHAR buffer[0x100];
HANDLE hsubkey;
LONG64 timestamp;
ULONG app_hash;
@@ -116,14 +110,18 @@ VOID _app_package_getpackagebyname (
status = _r_reg_openkey (&hsubkey, hroot, buffer, 0, KEY_READ);
if (!NT_SUCCESS (status))
+ {
+ _r_log (LOG_LEVEL_ERROR, NULL, TEXT (__FUNCTION__), status, buffer);
+
goto CleanupExit;
+ }
status = _r_reg_querybinary (hsubkey, L"PackageSid", &package_sid);
if (!NT_SUCCESS (status))
goto CleanupExit;
- status = _r_str_fromsid (&package_sid_string, package_sid->buffer);
+ status = _r_str_fromsid (&package_sid_string, (PSID)(package_sid->buffer));
if (!NT_SUCCESS (status))
goto CleanupExit;
@@ -142,37 +140,32 @@ VOID _app_package_getpackagebyname (
_app_package_parsepath (&real_path);
//_r_queuedlock_acquireexclusive (&lock_apps);
- app_hash = _app_addapplication (NULL, DATA_APP_UWP, package_sid_string, display_name, real_path);
+ ptr_app = _app_addapplication (NULL, DATA_APP_UWP, package_sid_string, display_name, real_path);
//_r_queuedlock_releaseexclusive (&lock_apps);
- if (app_hash)
+ if (ptr_app)
{
- ptr_app = _app_getappitem (app_hash);
+ status = _r_reg_queryinfo (hsubkey, NULL, ×tamp);
- if (ptr_app)
- {
- status = _r_reg_queryinfo (hsubkey, NULL, ×tamp);
+ if (NT_SUCCESS (status))
+ _app_setappinfo (ptr_app, INFO_TIMESTAMP, ×tamp);
- if (NT_SUCCESS (status))
- _app_setappinfo (ptr_app, INFO_TIMESTAMP, ×tamp);
+ _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_reference (package_sid));
- _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_reference (package_sid));
-
- _r_obj_dereference (ptr_app);
- }
+ _r_obj_dereference (ptr_app);
}
CleanupExit:
+ if (package_sid_string)
+ _r_obj_dereference (package_sid_string);
+
if (display_name)
_r_obj_dereference (display_name);
if (package_sid)
_r_obj_dereference (package_sid);
- if (package_sid_string)
- _r_obj_dereference (package_sid_string);
-
if (real_path)
_r_obj_dereference (real_path);
@@ -186,12 +179,10 @@ VOID _app_package_getpackagebysid (
_In_ PR_STRING key_name
)
{
- WCHAR buffer[256];
- PR_STRING display_name = NULL;
- PR_STRING real_path = NULL;
+ PR_STRING display_name = NULL, moniker = NULL, real_path = NULL;
PR_BYTE package_sid = NULL;
- PR_STRING moniker = NULL;
PITEM_APP ptr_app;
+ WCHAR buffer[0x100];
HANDLE hsubkey;
LONG64 timestamp = 0;
ULONG app_hash;
@@ -208,7 +199,11 @@ VOID _app_package_getpackagebysid (
status = _r_reg_openkey (&hsubkey, hroot, buffer, 0, KEY_READ);
if (!NT_SUCCESS (status))
+ {
+ _r_log (LOG_LEVEL_ERROR, NULL, TEXT (__FUNCTION__), status, buffer);
+
goto CleanupExit;
+ }
package_sid = _r_str_tosid (key_name);
@@ -229,39 +224,34 @@ VOID _app_package_getpackagebysid (
_app_package_parsepath (&real_path);
//_r_queuedlock_acquireexclusive (&lock_apps);
- app_hash = _app_addapplication (NULL, DATA_APP_UWP, key_name, display_name, NULL);
+ ptr_app = _app_addapplication (NULL, DATA_APP_UWP, key_name, display_name, NULL);
//_r_queuedlock_releaseexclusive (&lock_apps);
- if (app_hash)
+ if (ptr_app)
{
- ptr_app = _app_getappitem (app_hash);
+ status = _r_reg_queryinfo (hsubkey, NULL, ×tamp);
- if (ptr_app)
- {
- status = _r_reg_queryinfo (hsubkey, NULL, ×tamp);
+ if (NT_SUCCESS (status))
+ _app_setappinfo (ptr_app, INFO_TIMESTAMP, ×tamp);
- if (NT_SUCCESS (status))
- _app_setappinfo (ptr_app, INFO_TIMESTAMP, ×tamp);
+ _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_reference (package_sid));
- _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_reference (package_sid));
-
- _r_obj_dereference (ptr_app);
- }
+ _r_obj_dereference (ptr_app);
}
CleanupExit:
- if (moniker)
- _r_obj_dereference (moniker);
-
if (display_name)
_r_obj_dereference (display_name);
+ if (package_sid)
+ _r_obj_dereference (package_sid);
+
if (real_path)
_r_obj_dereference (real_path);
- if (package_sid)
- _r_obj_dereference (package_sid);
+ if (moniker)
+ _r_obj_dereference (moniker);
if (hsubkey)
NtClose (hsubkey);
@@ -271,27 +261,22 @@ VOID NTAPI _app_package_threadproc (
_In_ PVOID arglist
)
{
- IO_STATUS_BLOCK isb;
- HANDLE hservices_key = NULL;
- HANDLE hpackages_key = NULL;
- HANDLE event_handle1 = NULL;
- HANDLE event_handle2 = NULL;
- HANDLE hevents[2] = {0};
+ HANDLE hpackages_key = NULL, hservices_key = NULL, event_handle1 = NULL, event_handle2 = NULL, hevents[2] = {0};
PITEM_APP ptr_app = NULL;
+ IO_STATUS_BLOCK isb;
HWND hwnd;
LONG64 current_time;
ULONG_PTR enum_key = 0;
ULONG flags = REG_NOTIFY_CHANGE_NAME;
NTSTATUS status;
- hwnd = arglist;
+ hwnd = (HWND)arglist;
status = NtCreateEvent (&event_handle1, EVENT_ALL_ACCESS, NULL, NotificationEvent, FALSE);
if (!NT_SUCCESS (status))
{
_r_show_errormessage (hwnd, NULL, status, L"NtCreateEvent", ET_NATIVE);
-
return;
}
@@ -301,6 +286,8 @@ VOID NTAPI _app_package_threadproc (
{
_r_show_errormessage (hwnd, NULL, status, L"NtCreateEvent", ET_NATIVE);
+ NtClose (event_handle1); // do not left handle opened!
+
return;
}
@@ -311,9 +298,9 @@ VOID NTAPI _app_package_threadproc (
if (_r_sys_isosversiongreaterorequal (WINDOWS_8))
{
- flags |= REG_NOTIFY_THREAD_AGNOSTIC;
-
_r_reg_openkey (&hpackages_key, HKEY_CURRENT_USER, L"Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppModel\\Repository\\Packages", 0, KEY_NOTIFY);
+
+ flags |= REG_NOTIFY_THREAD_AGNOSTIC;
}
if (NT_SUCCESS (status))
@@ -404,11 +391,11 @@ VOID NTAPI _app_package_threadproc (
}
VOID _app_package_getpackageslist (
- _In_ HWND hwnd
+ _In_opt_ HWND hwnd
)
{
- LPWSTR reg_byname = L"Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppModel\\Repository\\Packages";
- LPWSTR reg_bysid = L"Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\Mappings";
+ LPCWSTR reg_byname = L"Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppModel\\Repository\\Packages";
+ LPCWSTR reg_bysid = L"Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\Mappings";
PR_STRING name;
HANDLE hkey;
ULONG index = 0;
@@ -419,8 +406,8 @@ VOID _app_package_getpackageslist (
if (!NT_SUCCESS (status))
{
- if (status != STATUS_OBJECT_NAME_NOT_FOUND)
- _r_show_errormessage (hwnd, NULL, status, reg_byname, ET_NATIVE);
+ if (hwnd && status != STATUS_OBJECT_NAME_NOT_FOUND)
+ _r_show_errormessage (hwnd, L"Could not query packages by name!", status, reg_byname, ET_NATIVE);
}
else
{
@@ -446,8 +433,8 @@ VOID _app_package_getpackageslist (
if (!NT_SUCCESS (status))
{
- if (status != STATUS_OBJECT_NAME_NOT_FOUND)
- _r_show_errormessage (hwnd, NULL, status, reg_bysid, ET_NATIVE);
+ if (hwnd && status != STATUS_OBJECT_NAME_NOT_FOUND)
+ _r_show_errormessage (hwnd, L"Could not query packages by sid!", status, reg_bysid, ET_NATIVE);
}
else
{
@@ -472,69 +459,59 @@ VOID _app_package_getpackageslist (
}
VOID _app_package_getserviceslist (
- _In_ HWND hwnd
+ _In_opt_ HWND hwnd
)
{
- WCHAR general_key[256];
- LPENUM_SERVICE_STATUS_PROCESS services;
- LPENUM_SERVICE_STATUS_PROCESS service;
- EXPLICIT_ACCESS ea;
+ PR_STRING converted_path, name_string, service_name, service_path;
+ LPENUM_SERVICE_STATUS_PROCESS service, services;
+ PVOID buffer, service_sd = NULL;
R_STRINGREF dummy_filename;
- PR_STRING converted_path;
- PR_STRING name_string;
- PR_STRING service_name;
- PR_STRING service_path;
+ WCHAR general_key[0x100];
PR_BYTE service_sid;
- SC_HANDLE hsvcmgr;
+ EXPLICIT_ACCESS ea;
PITEM_APP ptr_app;
- PVOID service_sd;
- PVOID buffer;
+ SC_HANDLE hsvcmgr;
HANDLE hkey;
LONG64 service_timestamp;
- ULONG service_type = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS;
- ULONG service_state = SERVICE_STATE_ALL;
- ULONG services_returned;
- ULONG return_length;
- ULONG buffer_size;
- ULONG sd_length;
- ULONG app_hash;
+ ULONG buffer_size, return_length, services_returned, service_type = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS, sd_length;
NTSTATUS status;
hsvcmgr = OpenSCManagerW (NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE);
if (!hsvcmgr)
{
- _r_show_errormessage (hwnd, NULL, NtLastError (), L"OpenSCManagerW", ET_WINDOWS);
+ if (hwnd)
+ _r_show_errormessage (hwnd, NULL, NtLastError (), L"OpenSCManagerW", ET_WINDOWS);
return;
}
// win10+
if (_r_sys_isosversiongreaterorequal (WINDOWS_10))
- service_type |= SERVICE_INTERACTIVE_PROCESS | SERVICE_USER_SERVICE;
+ service_type |= SERVICE_INTERACTIVE_PROCESS | SERVICE_USER_SERVICE | SERVICE_USERSERVICE_INSTANCE;
buffer_size = PR_SIZE_BUFFER;
buffer = _r_mem_allocate (buffer_size);
- if (!EnumServicesStatusExW (hsvcmgr, SC_ENUM_PROCESS_INFO, service_type, service_state, buffer, buffer_size, &return_length, &services_returned, NULL, NULL))
+ if (!EnumServicesStatusExW (hsvcmgr, SC_ENUM_PROCESS_INFO, service_type, SERVICE_STATE_ALL, (PBYTE)buffer, buffer_size, &return_length, &services_returned, NULL, NULL))
{
if (NtLastError () == ERROR_MORE_DATA)
{
- // set the buffer
+ // reallocate new buffer
buffer_size += return_length;
buffer = _r_mem_reallocate (buffer, buffer_size);
// now query again for services
- if (!EnumServicesStatusExW (hsvcmgr, SC_ENUM_PROCESS_INFO, service_type, service_state, buffer, buffer_size, &return_length, &services_returned, NULL, NULL))
+ if (!EnumServicesStatusExW (hsvcmgr, SC_ENUM_PROCESS_INFO, service_type, SERVICE_STATE_ALL, (PBYTE)buffer, buffer_size, &return_length, &services_returned, NULL, NULL))
{
- _r_mem_free (buffer);
+ _r_mem_free (buffer); // cleanup!
buffer = NULL;
}
}
else
{
- _r_mem_free (buffer);
+ _r_mem_free (buffer); // cleanup!
buffer = NULL;
}
@@ -554,38 +531,15 @@ VOID _app_package_getserviceslist (
{
service = &services[i];
- app_hash = _r_str_gethash2 (service->lpServiceName, TRUE);
-
- if (_app_isappfound (app_hash))
+ if (_app_isappfound (_r_str_gethash2 (service->lpServiceName, TRUE)))
continue;
- _r_str_printf (general_key, RTL_NUMBER_OF (general_key), L"System\\CurrentControlSet\\Services\\%s", service->lpServiceName);
-
- service_name = _r_obj_createstring (service->lpServiceName);
+ _r_str_printf (general_key, RTL_NUMBER_OF (general_key), L"SYSTEM\\CurrentControlSet\\Services\\%s", service->lpServiceName);
status = _r_reg_openkey (&hkey, HKEY_LOCAL_MACHINE, general_key, 0, KEY_READ);
if (!NT_SUCCESS (status))
- {
- _r_obj_dereference (service_name);
-
continue;
- }
-
- // skip userservice instances service types (win10+)
- if (_r_sys_isosversiongreaterorequal (WINDOWS_10))
- {
- status = _r_reg_queryulong (hkey, L"Type", &service_type);
-
- if (!NT_SUCCESS (status) || (service_type & SERVICE_USERSERVICE_INSTANCE) != 0)
- {
- _r_obj_dereference (service_name);
-
- NtClose (hkey);
-
- continue;
- }
- }
// query service path
status = _r_reg_querystring (hkey, L"ImagePath", &service_path, NULL);
@@ -600,10 +554,7 @@ VOID _app_package_getserviceslist (
}
else
{
- converted_path = _r_path_dospathfromnt (&service_path->sr);
-
- if (converted_path)
- _r_obj_movereference ((PVOID_PTR)&service_path, converted_path);
+ _r_obj_movereference ((PVOID_PTR)&service_path, _r_path_dospathfromnt (&service_path->sr));
}
// query service sid
@@ -611,49 +562,40 @@ VOID _app_package_getserviceslist (
if (NT_SUCCESS (status))
{
- // When evaluating SECURITY_DESCRIPTOR conditions, the filter engine
- // checks for FWP_ACTRL_MATCH_FILTER access. If the DACL grants access,
- // it does not mean that the traffic is allowed; it just means that the
- // condition evaluates to true. Likewise if it denies access, the
- // condition evaluates to false.
-
- _app_setexplicitaccess (&ea, GRANT_ACCESS, FWP_ACTRL_MATCH_FILTER, NO_INHERITANCE, service_sid->buffer);
-
- // Security descriptors must be in self-relative form (i.e., contiguous).
- // The security descriptor returned by BuildSecurityDescriptorW is
- // already self-relative, but if you're using another mechanism to build
- // the descriptor, you may have to convert it. See MakeSelfRelativeSD for
- // details.
+ // when evaluating SECURITY_DESCRIPTOR conditions, the filter engine checks for FWP_ACTRL_MATCH_FILTER access.
+ // if the DACL grants access, it does not mean that the traffic is allowed; it just means that the condition
+ // evaluates to true. likewise if it denies access, the condition evaluates to FALSE.
+ _app_setexplicitaccess (&ea, NO_INHERITANCE, GRANT_ACCESS, FWP_ACTRL_MATCH_FILTER, (PSID)(service_sid->buffer));
+ // security descriptors must be in self-relative form (i.e., contiguous). the security descriptor returned
+ // by BuildSecurityDescriptorW is already self-relative, but if you're using another mechanism to build
+ // the descriptor, you may have to convert it. see MakeSelfRelativeSD for details.
status = BuildSecurityDescriptorW (NULL, NULL, 1, &ea, 0, NULL, NULL, &sd_length, &service_sd);
if (status == ERROR_SUCCESS && service_sd)
{
+ service_name = _r_obj_createstring (service->lpServiceName);
name_string = _r_obj_createstring (service->lpDisplayName);
- app_hash = _app_addapplication (NULL, DATA_APP_SERVICE, service_name, name_string, service_path);
+ ptr_app = _app_addapplication (NULL, DATA_APP_SERVICE, service_name, name_string, service_path);
- if (app_hash)
+ if (ptr_app)
{
- ptr_app = _app_getappitem (app_hash);
+ // query service timestamp
+ status = _r_reg_queryinfo (hkey, NULL, &service_timestamp);
- if (ptr_app)
- {
- // query service timestamp
- status = _r_reg_queryinfo (hkey, NULL, &service_timestamp);
+ if (NT_SUCCESS (status))
+ _app_setappinfo (ptr_app, INFO_TIMESTAMP, &service_timestamp);
- if (NT_SUCCESS (status))
- _app_setappinfo (ptr_app, INFO_TIMESTAMP, &service_timestamp);
+ _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_createbyte_ex ((LPCSTR)service_sd, sd_length));
- _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_createbyte_ex (service_sd, sd_length));
-
- _r_obj_dereference (ptr_app);
- }
+ _r_obj_dereference (ptr_app);
}
- LocalFree (service_sd);
-
+ _r_obj_dereference (service_name);
_r_obj_dereference (name_string);
+
+ LocalFree (service_sd);
}
_r_obj_dereference (service_sid);
@@ -662,12 +604,10 @@ VOID _app_package_getserviceslist (
_r_obj_dereference (service_path);
}
- _r_obj_dereference (service_name);
-
NtClose (hkey);
}
- _r_mem_free (buffer);
-
CloseServiceHandle (hsvcmgr);
+
+ _r_mem_free (buffer);
}
diff --git a/src/packages.h b/src/packages.h
index 5bc7eeba..6221c6b5 100644
--- a/src/packages.h
+++ b/src/packages.h
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2016-2025 Henry++
+// Copyright (c) 2016-2026 Henry++
#pragma once
@@ -28,9 +28,9 @@ VOID NTAPI _app_package_threadproc (
);
VOID _app_package_getpackageslist (
- _In_ HWND hwnd
+ _In_opt_ HWND hwnd
);
VOID _app_package_getserviceslist (
- _In_ HWND hwnd
+ _In_opt_ HWND hwnd
);
diff --git a/src/profile.c b/src/profile.c
index a785842e..e8553953 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -19,7 +19,7 @@ BOOLEAN _app_getappinfo (
{
PVOID ptr;
- if (length != sizeof (PVOID))
+ if (length != sizeof (PR_STRING))
return FALSE;
if (ptr_app->real_path)
@@ -38,7 +38,7 @@ BOOLEAN _app_getappinfo (
{
PVOID ptr;
- if (length != sizeof (PVOID))
+ if (length != sizeof (PR_STRING))
return FALSE;
if (ptr_app->display_name)
@@ -65,7 +65,7 @@ BOOLEAN _app_getappinfo (
{
PVOID ptr;
- if (length != sizeof (PVOID))
+ if (length != sizeof (PR_STRING))
return FALSE;
if (ptr_app->hash)
@@ -109,6 +109,9 @@ BOOLEAN _app_getappinfo (
listview_id = _app_listview_getbytype (ptr_app->type);
+ if (listview_id == 0)
+ return FALSE;
+
RtlCopyMemory (buffer, &listview_id, length);
return TRUE;
@@ -190,7 +193,8 @@ BOOLEAN _app_getappinfobyhash (
return is_success;
}
-VOID _app_setappinfo (
+_Success_ (return)
+BOOLEAN _app_setappinfo (
_In_ PITEM_APP ptr_app,
_In_ ENUM_INFO_DATA info_data,
_In_opt_ PVOID value
@@ -201,49 +205,47 @@ VOID _app_setappinfo (
case INFO_BYTES_DATA:
{
_r_obj_movereference ((PVOID_PTR)&ptr_app->bytes, value);
- break;
+
+ return TRUE;
}
case INFO_COMMENT:
{
_r_obj_movereference ((PVOID_PTR)&ptr_app->comment, value);
- break;
+
+ return TRUE;
}
case INFO_HASH:
{
_r_obj_movereference ((PVOID_PTR)&ptr_app->hash, value);
- break;
+
+ return TRUE;
}
case INFO_TIMESTAMP:
{
if (!value)
- break;
+ return FALSE;
ptr_app->timestamp = *((PLONG64)value);
- break;
+ return TRUE;
}
case INFO_TIMER:
{
- HANDLE engine_handle;
LONG64 timestamp;
if (!value)
- break;
+ return FALSE;
timestamp = *((PLONG64)value);
// check timer expiration
if (timestamp <= _r_unixtime_now ())
{
- engine_handle = _wfp_getenginehandle ();
-
- _wfp_destroyfilters_array (engine_handle, ptr_app->guids, DBG_ARG);
-
- _r_obj_cleararray (ptr_app->guids);
+ _wfp_destroyfilters_array (_wfp_getenginehandle (), ptr_app->guids, DBG_ARG);
ptr_app->timer = 0;
ptr_app->is_enabled = FALSE;
@@ -256,24 +258,18 @@ VOID _app_setappinfo (
_app_listview_updateitemby_param (_r_app_gethwnd (), ptr_app->app_hash, TRUE);
- break;
+ return TRUE;
}
case INFO_DISABLE:
{
- HANDLE engine_handle;
-
ptr_app->is_enabled = FALSE;
- engine_handle = _wfp_getenginehandle ();
-
- _wfp_destroyfilters_array (engine_handle, ptr_app->guids, DBG_ARG);
-
- _r_obj_cleararray (ptr_app->guids);
+ _wfp_destroyfilters_array (_wfp_getenginehandle (), ptr_app->guids, DBG_ARG);
_app_listview_updateitemby_param (_r_app_gethwnd (), ptr_app->app_hash, TRUE);
- break;
+ return TRUE;
}
case INFO_IS_ENABLED:
@@ -282,7 +278,7 @@ VOID _app_setappinfo (
_app_listview_updateitemby_param (_r_app_gethwnd (), ptr_app->app_hash, TRUE);
- break;
+ return TRUE;
}
case INFO_IS_SILENT:
@@ -292,13 +288,14 @@ VOID _app_setappinfo (
if (ptr_app->is_silent)
_app_notify_freeobject (NULL, ptr_app);
- break;
+ return TRUE;
}
case INFO_IS_UNDELETABLE:
{
ptr_app->is_undeletable = (PtrToLong (value) ? TRUE : FALSE);
- break;
+
+ return TRUE;
}
default:
@@ -306,24 +303,30 @@ VOID _app_setappinfo (
break;
}
}
+
+ return FALSE;
}
-VOID _app_setappinfobyhash (
+_Success_ (return)
+BOOLEAN _app_setappinfobyhash (
_In_ ULONG app_hash,
_In_ ENUM_INFO_DATA info_data,
_In_opt_ PVOID value
)
{
PITEM_APP ptr_app;
+ BOOLEAN is_success;
ptr_app = _app_getappitem (app_hash);
if (!ptr_app)
- return;
+ return FALSE;
- _app_setappinfo (ptr_app, info_data, value);
+ is_success = _app_setappinfo (ptr_app, info_data, value);
_r_obj_dereference (ptr_app);
+
+ return is_success;
}
_Success_ (return)
@@ -347,6 +350,9 @@ BOOLEAN _app_getruleinfo (
listview_id = _app_listview_getbytype (ptr_rule->type);
+ if (listview_id == 0)
+ return FALSE;
+
RtlCopyMemory (buffer, &listview_id, length);
return TRUE;
@@ -354,9 +360,9 @@ BOOLEAN _app_getruleinfo (
case INFO_IS_READONLY:
{
- INT is_readonly;
+ BOOLEAN is_readonly;
- if (length != sizeof (INT))
+ if (length != sizeof (BOOLEAN))
return FALSE;
is_readonly = !!ptr_rule->is_readonly;
@@ -396,8 +402,8 @@ BOOLEAN _app_getruleinfobyid (
return is_success;
}
-_Success_ (return != 0)
-ULONG _app_addapplication (
+_Ret_maybenull_
+PITEM_APP _app_addapplication (
_In_opt_ HWND hwnd,
_In_ ENUM_TYPE_DATA type,
_In_ PR_STRING path,
@@ -411,11 +417,8 @@ ULONG _app_addapplication (
ULONG app_hash;
BOOLEAN is_ntoskrnl;
- if (_r_obj_isstringempty2 (path))
- return 0;
-
- if (_app_isappvalidpath (path) && _r_fs_isdirectory (&path->sr))
- return 0;
+ if (_r_obj_isstringempty2 (path) || (_app_isappvalidpath (path) && _r_fs_isdirectory (&path->sr)))
+ return NULL;
_r_obj_initializestringref2 (&path_sr, &path->sr);
@@ -429,9 +432,9 @@ ULONG _app_addapplication (
app_hash = _r_str_gethash (&path_sr, TRUE);
if (_app_isappfound (app_hash))
- return app_hash; // already exists
+ return _app_getappitem (app_hash); // already exists
- ptr_app = _r_obj_allocate (sizeof (ITEM_APP), &_app_dereferenceapp);
+ ptr_app = (PITEM_APP)_r_obj_allocate (sizeof (ITEM_APP), &_app_dereferenceapp);
is_ntoskrnl = (app_hash == config.ntoskrnl_hash);
ptr_app->app_hash = app_hash;
@@ -447,10 +450,10 @@ ULONG _app_addapplication (
ptr_app->type = type;
if (display_name)
- ptr_app->display_name = _r_obj_reference (display_name);
+ ptr_app->display_name = _r_obj_createstring2 (&display_name->sr);
if (real_path)
- ptr_app->real_path = _r_obj_reference (real_path);
+ ptr_app->real_path = _r_obj_createstring2 (&real_path->sr);
}
else if (_r_str_isstartswith2 (&path_sr, L"\\device\\", TRUE)) // device path
{
@@ -465,17 +468,10 @@ ULONG _app_addapplication (
}
else
{
- ptr_app->type = PathIsNetworkPathW (path_sr.buffer) ? DATA_APP_NETWORK : DATA_APP_REGULAR;
+ ptr_app->type = _r_path_isnetwork (&path_sr) ? DATA_APP_NETWORK : DATA_APP_REGULAR;
}
- if (is_ntoskrnl)
- {
- ptr_app->real_path = _r_obj_createstring2 (&config.ntoskrnl_path->sr);
- }
- else
- {
- ptr_app->real_path = _r_obj_createstring2 (&path_sr);
- }
+ ptr_app->real_path = _r_obj_createstring2 (is_ntoskrnl ? &config.ntoskrnl_path->sr : &path_sr);
}
ptr_app->original_path = _r_obj_createstring2 (&path_sr);
@@ -493,11 +489,10 @@ ULONG _app_addapplication (
ptr_app->short_name = _r_path_getbasenamestring (&path_sr);
}
- ptr_app->guids = _r_obj_createarray (sizeof (GUID), 0x04, NULL); // initialize guids array
+ ptr_app->guids = _r_obj_createarray (sizeof (GUID), 0x02, NULL); // initialize guids array
ptr_app->timestamp = _r_unixtime_now ();
// insert object into the table
- //
//_r_queuedlock_acquireexclusive (&lock_apps);
_r_obj_addhashtablepointer (apps_table, app_hash, ptr_app);
//_r_queuedlock_releaseexclusive (&lock_apps);
@@ -507,10 +502,10 @@ ULONG _app_addapplication (
_app_listview_addappitem (hwnd, ptr_app);
// queue file information
- if (!_r_obj_isstringempty (ptr_app->real_path))
+ if (!_r_obj_isstringempty (ptr_app->real_path) && _app_isappvalidbinary (ptr_app->real_path))
_app_getfileinformation (ptr_app->real_path, app_hash, ptr_app->type, _app_listview_getbytype (ptr_app->type));
- return app_hash;
+ return (PITEM_APP)_r_obj_reference (ptr_app);
}
PITEM_RULE _app_addrule (
@@ -524,27 +519,27 @@ PITEM_RULE _app_addrule (
)
{
PITEM_RULE ptr_rule;
+ LPCWSTR proto;
- ptr_rule = _r_obj_allocate (sizeof (ITEM_RULE), &_app_dereferencerule);
+ ptr_rule = (PITEM_RULE)_r_obj_allocate (sizeof (ITEM_RULE), &_app_dereferencerule);
- ptr_rule->apps = _r_obj_createhashtable (sizeof (SHORT), 4, NULL); // initialize hashtable
- ptr_rule->guids = _r_obj_createarray (sizeof (GUID), 4, NULL); // initialize array
+ ptr_rule->apps = _r_obj_createhashtable (sizeof (SHORT), 0x02, NULL); // initialize apps hashtable
+ ptr_rule->guids = _r_obj_createarray (sizeof (GUID), 0x02, NULL); // initialize filters array
ptr_rule->type = DATA_RULE_USER;
// set rule name
- if (name)
- {
- ptr_rule->name = _r_obj_reference (name);
+ ptr_rule->name = !_r_obj_isstringempty (name) ? _r_obj_createstring2 (&name->sr) : _r_obj_createstring (L"");
- if (_r_str_getlength2 (&ptr_rule->name->sr) > RULE_NAME_CCH_MAX)
- _r_str_setlength (&ptr_rule->name->sr, RULE_NAME_CCH_MAX * sizeof (WCHAR));
- }
+ if (_r_str_getlength2 (&ptr_rule->name->sr) > RULE_NAME_CCH_MAX)
+ _r_str_setlength (&ptr_rule->name->sr, RULE_NAME_CCH_MAX * sizeof (WCHAR));
+
+ ptr_rule->rule_hash = _r_str_gethash (&ptr_rule->name->sr, TRUE);
// set rule destination
if (rule_remote)
{
- ptr_rule->rule_remote = _r_obj_reference (rule_remote);
+ ptr_rule->rule_remote = _r_obj_createstring2 (&rule_remote->sr);
if (_r_str_getlength2 (&ptr_rule->rule_remote->sr) > RULE_RULE_CCH_MAX)
_r_str_setlength (&ptr_rule->rule_remote->sr, RULE_RULE_CCH_MAX * sizeof (WCHAR));
@@ -553,7 +548,7 @@ PITEM_RULE _app_addrule (
// set rule source
if (rule_local)
{
- ptr_rule->rule_local = _r_obj_reference (rule_local);
+ ptr_rule->rule_local = _r_obj_createstring2 (&rule_local->sr);
if (_r_str_getlength2 (&ptr_rule->rule_local->sr) > RULE_RULE_CCH_MAX)
_r_str_setlength (&ptr_rule->rule_local->sr, RULE_RULE_CCH_MAX * sizeof (WCHAR));
@@ -565,7 +560,9 @@ PITEM_RULE _app_addrule (
ptr_rule->protocol = protocol;
ptr_rule->af = af;
- ptr_rule->protocol_str = _r_obj_createstring (_app_db_getprotoname (protocol, af));
+ proto = _app_db_getprotoname (protocol, af, NULL);
+
+ ptr_rule->protocol_str = proto ? _r_obj_createstring (proto) : NULL;
return ptr_rule;
}
@@ -583,7 +580,7 @@ PITEM_RULE_CONFIG _app_addruleconfigtable (
entry.name = _r_obj_reference (rule_name);
entry.is_enabled = is_enabled;
- return _r_obj_addhashtableitem (hashtable, rule_hash, &entry);
+ return (PITEM_RULE_CONFIG)_r_obj_addhashtableitem (hashtable, rule_hash, &entry);
}
_Ret_maybenull_
@@ -593,8 +590,11 @@ PITEM_APP _app_getappitem (
{
PITEM_APP ptr_app;
+ if (!app_hash)
+ return NULL;
+
_r_queuedlock_acquireshared (&lock_apps);
- ptr_app = _r_obj_findhashtablepointer (apps_table, app_hash);
+ ptr_app = (PITEM_APP)_r_obj_findhashtablepointer (apps_table, app_hash);
_r_queuedlock_releaseshared (&lock_apps);
return ptr_app;
@@ -608,27 +608,15 @@ PITEM_RULE _app_getrulebyid (
PITEM_RULE ptr_rule;
_r_queuedlock_acquireshared (&lock_rules);
-
- if (index < _r_obj_getlistsize (rules_list))
- {
- ptr_rule = _r_obj_getlistitem (rules_list, index);
- }
- else
- {
- ptr_rule = NULL;
- }
-
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, index);
_r_queuedlock_releaseshared (&lock_rules);
- if (ptr_rule)
- return _r_obj_reference (ptr_rule);
-
- return NULL;
+ return (PITEM_RULE)_r_obj_referencesafe (ptr_rule);
}
_Ret_maybenull_
PITEM_RULE _app_getrulebyhash (
- _In_ ULONG_PTR rule_hash
+ _In_ ULONG rule_hash
)
{
PITEM_RULE ptr_rule;
@@ -640,19 +628,13 @@ PITEM_RULE _app_getrulebyhash (
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
- if (ptr_rule)
+ if (ptr_rule && ptr_rule->is_readonly && ptr_rule->rule_hash == rule_hash)
{
- if (ptr_rule->is_readonly)
- {
- if (_r_str_gethash (&ptr_rule->name->sr, TRUE) == rule_hash)
- {
- _r_queuedlock_releaseshared (&lock_rules);
+ _r_queuedlock_releaseshared (&lock_rules);
- return _r_obj_reference (ptr_rule);
- }
- }
+ return (PITEM_RULE)_r_obj_reference (ptr_rule);
}
}
@@ -669,7 +651,7 @@ PITEM_RULE_CONFIG _app_getruleconfigitem (
PITEM_RULE_CONFIG ptr_rule_config;
_r_queuedlock_acquireshared (&lock_rules_config);
- ptr_rule_config = _r_obj_findhashtable (rules_config, rule_hash);
+ ptr_rule_config = (PITEM_RULE_CONFIG)_r_obj_findhashtable (rules_config, rule_hash);
_r_queuedlock_releaseshared (&lock_rules_config);
return ptr_rule_config;
@@ -683,7 +665,7 @@ PITEM_LOG _app_getlogitem (
PITEM_LOG ptr_log;
_r_queuedlock_acquireshared (&lock_loglist);
- ptr_log = _r_obj_findhashtablepointer (log_table, log_hash);
+ ptr_log = (PITEM_LOG)_r_obj_findhashtablepointer (log_table, log_hash);
_r_queuedlock_releaseshared (&lock_loglist);
return ptr_log;
@@ -695,7 +677,7 @@ ULONG _app_getlogapp (
)
{
PITEM_LOG ptr_log;
- ULONG app_hash;
+ ULONG app_hash = 0;
ptr_log = _app_getlogitem (index);
@@ -704,13 +686,12 @@ ULONG _app_getlogapp (
app_hash = ptr_log->app_hash;
_r_obj_dereference (ptr_log);
-
- return app_hash;
}
- return 0;
+ return app_hash;
}
+_Success_ (return != 0)
COLORREF _app_getappcolor (
_In_ INT listview_id,
_In_ ULONG app_hash,
@@ -720,8 +701,7 @@ COLORREF _app_getappcolor (
{
PITEM_APP ptr_app;
ULONG color_hash = 0;
- BOOLEAN is_profilelist;
- BOOLEAN is_networklist;
+ BOOLEAN is_networklist, is_profilelist;
ptr_app = _app_getappitem (app_hash);
@@ -788,10 +768,7 @@ CleanupExit:
if (ptr_app)
_r_obj_dereference (ptr_app);
- if (color_hash)
- return _app_getcolorvalue (color_hash);
-
- return 0;
+ return color_hash ? _app_getcolorvalue (color_hash) : 0;
}
VOID _app_deleteappitem (
@@ -800,8 +777,7 @@ VOID _app_deleteappitem (
_In_ ULONG_PTR id_code
)
{
- INT listview_id;
- INT item_id;
+ INT item_id, listview_id;
listview_id = _app_listview_getbytype (type);
@@ -825,12 +801,9 @@ VOID _app_freeapplication (
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
- if (!ptr_rule)
- continue;
-
- if (ptr_rule->type != DATA_RULE_USER)
+ if (!ptr_rule || ptr_rule->type != DATA_RULE_USER)
continue;
if (hwnd)
@@ -875,7 +848,7 @@ VOID _app_getcount (
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
if (!ptr_rule)
continue;
@@ -901,6 +874,7 @@ VOID _app_getcount (
_r_queuedlock_releaseshared (&lock_rules);
}
+_Success_ (return != 0)
COLORREF _app_getrulecolor (
_In_ INT listview_id,
_In_ ULONG_PTR rule_idx
@@ -918,17 +892,14 @@ COLORREF _app_getrulecolor (
{
color_hash = config.color_invalid;
}
- else if (_r_config_getboolean (L"IsHighlightSpecial", TRUE, L"colors") && (ptr_rule->is_forservices || !_r_obj_isempty (ptr_rule->apps)))
+ else if (_r_config_getboolean (L"IsHighlightSpecial", TRUE, L"colors") && (ptr_rule->is_fordriver || ptr_rule->is_forservice || !_r_obj_isempty (ptr_rule->apps)))
{
color_hash = config.color_special;
}
_r_obj_dereference (ptr_rule);
- if (color_hash)
- return _app_getcolorvalue (color_hash);
-
- return 0;
+ return color_hash ? _app_getcolorvalue (color_hash) : 0;
}
VOID _app_setappiteminfo (
@@ -963,7 +934,8 @@ VOID _app_setruleiteminfo (
while (_r_obj_enumhashtable (ptr_rule->apps, NULL, &hash_code, &enum_key))
{
- _app_listview_updateitemby_param (hwnd, hash_code, TRUE);
+ if (hash_code != 0)
+ _app_listview_updateitemby_param (hwnd, hash_code, TRUE);
}
}
@@ -974,19 +946,13 @@ VOID _app_ruleenable (
)
{
PITEM_RULE_CONFIG ptr_config;
- ULONG rule_hash;
ptr_rule->is_enabled = is_enable;
- if (!ptr_rule->is_readonly || !ptr_rule->name)
+ if (!ptr_rule->is_readonly)
return;
- rule_hash = _r_str_gethash (&ptr_rule->name->sr, TRUE);
-
- if (!rule_hash)
- return;
-
- ptr_config = _app_getruleconfigitem (rule_hash);
+ ptr_config = _app_getruleconfigitem (ptr_rule->rule_hash);
if (ptr_config)
{
@@ -997,7 +963,7 @@ VOID _app_ruleenable (
if (is_createconfig)
{
_r_queuedlock_acquireexclusive (&lock_rules_config);
- ptr_config = _app_addruleconfigtable (rules_config, rule_hash, ptr_rule->name, is_enable);
+ ptr_config = _app_addruleconfigtable (rules_config, ptr_rule->rule_hash, ptr_rule->name, is_enable);
_r_queuedlock_releaseexclusive (&lock_rules_config);
if (ptr_config)
@@ -1013,10 +979,7 @@ VOID _app_ruleremoveapp (
_In_ ULONG app_hash
)
{
- if (!ptr_rule->apps)
- return;
-
- if (!_r_obj_removehashtableitem (ptr_rule->apps, app_hash))
+ if (!ptr_rule->apps || !_r_obj_removehashtableitem (ptr_rule->apps, app_hash))
return;
if (ptr_rule->is_enabled && _r_obj_isempty (ptr_rule->apps))
@@ -1024,11 +987,8 @@ VOID _app_ruleremoveapp (
ptr_rule->is_enabled = FALSE;
ptr_rule->is_haveerrors = FALSE;
- if (hwnd)
- {
- if (item_id != SIZE_MAX)
- _app_listview_updateitemby_param (hwnd, item_id, FALSE);
- }
+ if (hwnd && item_id != SIZE_MAX)
+ _app_listview_updateitemby_param (hwnd, item_id, FALSE);
}
}
@@ -1068,7 +1028,7 @@ BOOLEAN _app_ruleblocklistsetstate (
_In_ LONG extra_state
)
{
- if (ptr_rule->type != DATA_RULE_BLOCKLIST || _r_obj_isstringempty (ptr_rule->name))
+ if (ptr_rule->type != DATA_RULE_BLOCKLIST)
return FALSE;
if (_r_str_isstartswith2 (&ptr_rule->name->sr, L"spy_", TRUE))
@@ -1096,23 +1056,19 @@ VOID _app_ruleblocklistset (
_In_ BOOLEAN is_instantapply
)
{
- PR_LIST rules;
PITEM_RULE ptr_rule;
- HANDLE hengine;
+ PR_LIST rules;
ULONG_PTR changes_count = 0;
- rules = _r_obj_createlist (6, &_r_obj_dereference);
+ rules = _r_obj_createlist (0x10, &_r_obj_dereference);
_r_queuedlock_acquireshared (&lock_rules);
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
- if (!ptr_rule)
- continue;
-
- if (ptr_rule->type != DATA_RULE_BLOCKLIST)
+ if (!ptr_rule || ptr_rule->type != DATA_RULE_BLOCKLIST)
continue;
if (!_app_ruleblocklistsetstate (ptr_rule, spy_state, update_state, extra_state))
@@ -1138,15 +1094,8 @@ VOID _app_ruleblocklistset (
if (is_instantapply)
{
- if (rules->count)
- {
- if (_wfp_isfiltersinstalled ())
- {
- hengine = _wfp_getenginehandle ();
-
- _wfp_create4filters (hengine, rules, DBG_ARG, FALSE);
- }
- }
+ if (!_r_obj_isempty2 (rules) && _wfp_isfiltersinstalled ())
+ _wfp_createrulefilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
}
_app_profile_save (hwnd); // required!
@@ -1158,15 +1107,15 @@ VOID _app_ruleblocklistset (
_Ret_maybenull_
PR_STRING _app_appexpandrules (
_In_ ULONG app_hash,
- _In_ LPWSTR delimeter
+ _In_ LPCWSTR delimeter
)
{
- R_STRINGBUILDER buffer;
R_STRINGREF delimeter_sr;
- PR_STRING string;
PITEM_RULE ptr_rule;
+ R_STRINGBUILDER sb;
+ PR_STRING string;
- _r_obj_initializestringbuilder (&buffer, 256);
+ _r_obj_initializestringbuilder (&sb, 0);
_r_obj_initializestringref (&delimeter_sr, delimeter);
@@ -1174,68 +1123,78 @@ PR_STRING _app_appexpandrules (
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
- if (!ptr_rule)
- continue;
-
- if (ptr_rule->is_enabled && ptr_rule->type == DATA_RULE_USER && !_r_obj_isstringempty (ptr_rule->name) && _r_obj_findhashtable (ptr_rule->apps, app_hash))
+ if (ptr_rule && ptr_rule->is_enabled && ptr_rule->type == DATA_RULE_USER && _r_obj_findhashtable (ptr_rule->apps, app_hash))
{
- _r_obj_appendstringbuilder2 (&buffer, &ptr_rule->name->sr);
+ _r_obj_appendstringbuilder2 (&sb, &ptr_rule->name->sr);
if (ptr_rule->is_readonly)
- _r_obj_appendstringbuilder (&buffer, SZ_RULE_INTERNAL_MENU);
+ _r_obj_appendstringbuilder (&sb, SZ_RULE_INTERNAL_MENU);
- _r_obj_appendstringbuilder2 (&buffer, &delimeter_sr);
+ _r_obj_appendstringbuilder2 (&sb, &delimeter_sr);
}
}
_r_queuedlock_releaseshared (&lock_rules);
- string = _r_obj_finalstringbuilder (&buffer);
+ string = _r_obj_finalstringbuilder (&sb);
_r_str_trimstring (&string->sr, &delimeter_sr, 0);
if (!_r_obj_isstringempty2 (string))
return string;
- _r_obj_deletestringbuilder (&buffer);
+ _r_obj_deletestringbuilder (&sb);
return NULL;
-
}
_Ret_maybenull_
PR_STRING _app_rulesexpandapps (
_In_ PITEM_RULE ptr_rule,
_In_ BOOLEAN is_fordisplay,
- _In_ LPWSTR delimeter
+ _In_ LPCWSTR delimeter
)
{
R_STRINGREF delimeter_sr;
- R_STRINGBUILDER sr;
+ R_STRINGBUILDER sb;
PITEM_APP ptr_app;
PR_STRING string;
ULONG_PTR enum_key = 0;
ULONG hash_code;
- _r_obj_initializestringbuilder (&sr, 256);
+ _r_obj_initializestringbuilder (&sb, 0);
_r_obj_initializestringref (&delimeter_sr, delimeter);
- if (is_fordisplay && ptr_rule->is_forservices)
+ if (is_fordisplay)
{
- string = _r_obj_concatstrings (
- 4,
- PROC_SYSTEM_NAME,
- delimeter,
- _r_obj_getstring (config.svchost_path),
- delimeter
- );
+ if (ptr_rule->is_fordriver)
+ {
+ string = _r_obj_concatstrings (
+ 2,
+ PROC_SYSTEM_NAME,
+ delimeter
+ );
- _r_obj_appendstringbuilder2 (&sr, &string->sr);
+ _r_obj_appendstringbuilder2 (&sb, &string->sr);
- _r_obj_dereference (string);
+ _r_obj_dereference (string);
+ }
+
+ if (ptr_rule->is_forservice)
+ {
+ string = _r_obj_concatstrings (
+ 2,
+ _r_obj_getstring (config.svchost_path),
+ delimeter
+ );
+
+ _r_obj_appendstringbuilder2 (&sb, &string->sr);
+
+ _r_obj_dereference (string);
+ }
}
while (_r_obj_enumhashtable (ptr_rule->apps, NULL, &hash_code, &enum_key))
@@ -1247,31 +1206,19 @@ PR_STRING _app_rulesexpandapps (
string = NULL;
- if (is_fordisplay)
- {
- if (ptr_app->type == DATA_APP_UWP)
- {
- if (ptr_app->display_name)
- string = _r_path_compact (&ptr_app->display_name->sr, 64);
- }
- }
+ if (is_fordisplay && ptr_app->type == DATA_APP_UWP && ptr_app->display_name)
+ string = _r_path_compact (&ptr_app->display_name->sr, 0x40);
+
+ if (!string && is_fordisplay && ptr_app->original_path)
+ string = _r_path_compact (&ptr_app->original_path->sr, 0x40);
if (!string)
- {
- if (is_fordisplay)
- {
- if (ptr_app->original_path)
- string = _r_path_compact (&ptr_app->original_path->sr, 64);
- }
- }
-
- if (!string)
- string = _r_obj_referencesafe (ptr_app->original_path);
+ string = (PR_STRING)_r_obj_referencesafe (ptr_app->original_path);
if (string)
{
- _r_obj_appendstringbuilder2 (&sr, &string->sr);
- _r_obj_appendstringbuilder2 (&sr, &delimeter_sr);
+ _r_obj_appendstringbuilder2 (&sb, &string->sr);
+ _r_obj_appendstringbuilder2 (&sb, &delimeter_sr);
_r_obj_dereference (string);
}
@@ -1279,37 +1226,33 @@ PR_STRING _app_rulesexpandapps (
_r_obj_dereference (ptr_app);
}
- string = _r_obj_finalstringbuilder (&sr);
+ string = _r_obj_finalstringbuilder (&sb);
_r_str_trimstring (&string->sr, &delimeter_sr, PR_TRIM_END_ONLY);
if (!_r_obj_isstringempty2 (string))
return string;
- _r_obj_deletestringbuilder (&sr);
+ _r_obj_deletestringbuilder (&sb);
return NULL;
}
_Ret_maybenull_
PR_STRING _app_rulesexpandrules (
- _In_opt_ PR_STRING rule,
- _In_ LPWSTR delimeter
+ _In_opt_ PR_STRING rule
)
{
+ R_STRINGREF delimeter_sr, first_part, remaining_part;
R_STRINGBUILDER sb;
- R_STRINGREF delimeter_sr;
- R_STRINGREF remaining_part;
- R_STRINGREF first_part;
PR_STRING string;
if (_r_obj_isstringempty (rule))
return NULL;
- _r_obj_initializestringbuilder (&sb, 256);
-
- _r_obj_initializestringref (&delimeter_sr, delimeter);
+ _r_obj_initializestringbuilder (&sb, 0);
+ _r_obj_initializestringref (&delimeter_sr, SZ_CRLF SZ_TAB);
_r_obj_initializestringref2 (&remaining_part, &rule->sr);
while (remaining_part.length != 0)
@@ -1340,11 +1283,8 @@ BOOLEAN _app_isappfromsystem (
if (_app_issystemhash (app_hash))
return TRUE;
- if (path)
- {
- if (_r_str_isstartswith (&path->sr, &config.windows_dir, TRUE))
- return TRUE;
- }
+ if (path && _r_str_isstartswith (&path->sr, &config.windows_dir, TRUE))
+ return TRUE;
return FALSE;
}
@@ -1356,6 +1296,7 @@ BOOLEAN _app_isapphavedrive (
PITEM_APP ptr_app = NULL;
ULONG_PTR enum_key = 0;
INT drive_id;
+ BOOLEAN is_havedrive = FALSE;
_r_queuedlock_acquireshared (&lock_apps);
@@ -1364,29 +1305,21 @@ BOOLEAN _app_isapphavedrive (
if (_r_obj_isstringempty (ptr_app->original_path))
continue;
- if (ptr_app->type == DATA_APP_REGULAR)
- {
- drive_id = PathGetDriveNumberW (ptr_app->original_path->buffer);
- }
- else
- {
- drive_id = INT_ERROR;
- }
+ drive_id = (ptr_app->type == DATA_APP_REGULAR) ? _r_path_getdrivenumber (&ptr_app->original_path->sr) : INT_ERROR;
if (ptr_app->type == DATA_APP_DEVICE || (drive_id != INT_ERROR && drive_id == letter))
{
if (ptr_app->is_enabled || _app_isapphaverule (ptr_app->app_hash, FALSE))
{
- _r_queuedlock_releaseshared (&lock_apps);
-
- return TRUE;
+ is_havedrive = TRUE;
+ break;
}
}
}
_r_queuedlock_releaseshared (&lock_apps);
- return FALSE;
+ return is_havedrive;
}
BOOLEAN _app_isapphaverule (
@@ -1395,30 +1328,27 @@ BOOLEAN _app_isapphaverule (
)
{
PITEM_RULE ptr_rule;
+ BOOLEAN is_haverule = FALSE;
_r_queuedlock_acquireshared (&lock_rules);
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
- if (ptr_rule)
+ if (ptr_rule && ptr_rule->type == DATA_RULE_USER && (is_countdisabled || ptr_rule->is_enabled))
{
- if (ptr_rule->type == DATA_RULE_USER && (is_countdisabled || ptr_rule->is_enabled))
+ if (_r_obj_findhashtable (ptr_rule->apps, app_hash))
{
- if (_r_obj_findhashtable (ptr_rule->apps, app_hash))
- {
- _r_queuedlock_releaseshared (&lock_rules);
-
- return TRUE;
- }
+ is_haverule = TRUE;
+ break;
}
}
}
_r_queuedlock_releaseshared (&lock_rules);
- return FALSE;
+ return is_haverule;
}
BOOLEAN _app_isappexists (
@@ -1447,12 +1377,12 @@ BOOLEAN _app_isappexists (
case DATA_APP_UWP:
case DATA_APP_PICO:
{
- return TRUE; // service and UWP is already undeletable
+ return TRUE; // services and UWP apps are already undeletable!
}
default:
{
- return FALSE;
+ return FALSE; // unknown app!
}
}
}
@@ -1490,13 +1420,7 @@ BOOLEAN _app_isappused (
_In_ PITEM_APP ptr_app
)
{
- if (ptr_app->is_enabled || ptr_app->is_silent || ptr_app->is_undeletable)
- return TRUE;
-
- if (_app_isapphaverule (ptr_app->app_hash, TRUE))
- return TRUE;
-
- return FALSE;
+ return (ptr_app->is_enabled || ptr_app->is_silent || ptr_app->is_undeletable || _app_isapphaverule (ptr_app->app_hash, TRUE)) ? TRUE : FALSE;
}
BOOLEAN _app_issystemhash (
@@ -1507,21 +1431,20 @@ BOOLEAN _app_issystemhash (
}
BOOLEAN _app_isrulesupportedbyos (
- _In_ PR_STRINGREF os_version
+ _In_ PCR_STRINGREF os_version
)
{
static PR_STRING version_string = NULL;
- PR_STRING current_version;
- PR_STRING new_version;
+ PR_STRING current_version, new_version;
- current_version = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&version_string, NULL, NULL);
+ current_version = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&version_string, NULL, NULL);
if (!current_version)
{
new_version = _r_format_string (L"%d.%d", NtCurrentPeb ()->OSMajorVersion, NtCurrentPeb ()->OSMinorVersion);
- current_version = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&version_string, new_version, NULL);
+ current_version = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&version_string, new_version, NULL);
if (!current_version)
{
@@ -1538,38 +1461,33 @@ BOOLEAN _app_isrulesupportedbyos (
VOID _app_profile_initialize ()
{
- R_STRINGREF profile_internal_sr = PR_STRINGREF_INIT (XML_PROFILE_INTERNAL);
- R_STRINGREF profile_bak_sr = PR_STRINGREF_INIT (XML_PROFILE_FILE L".bak");
- R_STRINGREF profile_sr = PR_STRINGREF_INIT (XML_PROFILE_FILE);
- R_STRINGREF separator_sr = PR_STRINGREF_INIT (L"\\");
+ R_STRINGREF profile_internal_sr = PR_STRINGREF_INIT (XML_PROFILE_INTERNAL), profile_bak_sr = PR_STRINGREF_INIT (XML_PROFILE_FILE L".bak");
+ R_STRINGREF profile_sr = PR_STRINGREF_INIT (XML_PROFILE_FILE), separator_sr = PR_STRINGREF_INIT (L"\\");
PR_STRING path;
path = _r_app_getprofiledirectory ();
- _r_obj_movereference ((PVOID_PTR)&profile_info.profile_path, _r_obj_concatstringrefs (3, &path->sr, &separator_sr, &profile_sr));
- _r_obj_movereference ((PVOID_PTR)&profile_info.profile_path_backup, _r_obj_concatstringrefs (3, &path->sr, &separator_sr, &profile_bak_sr));
- _r_obj_movereference ((PVOID_PTR)&profile_info.profile_path_internal, _r_obj_concatstringrefs (3, &path->sr, &separator_sr, &profile_internal_sr));
+ _r_obj_movereference ((PVOID_PTR)&profile_info.profile_path_internal, _r_obj_concatstringrefs (3, path, &separator_sr, &profile_internal_sr));
+ _r_obj_movereference ((PVOID_PTR)&profile_info.profile_path_backup, _r_obj_concatstringrefs (3, path, &separator_sr, &profile_bak_sr));
+ _r_obj_movereference ((PVOID_PTR)&profile_info.profile_path, _r_obj_concatstringrefs (3, path, &separator_sr, &profile_sr));
}
NTSTATUS _app_profile_load_fromresource (
- _Out_ PDB_INFORMATION out_buffer,
+ _Out_ PDB_INFORMATION db_info,
_In_ LPCWSTR resource_name
)
{
- PDB_INFORMATION db_info;
- R_STORAGE buffer;
+ R_STORAGE storage;
NTSTATUS status;
- db_info = out_buffer;
-
status = _app_db_initialize (db_info, TRUE);
if (NT_SUCCESS (status))
{
- status = _r_res_loadresource (&buffer, _r_sys_getimagebase (), RT_RCDATA, resource_name, 0);
+ status = _r_res_loadresource (&storage, _r_sys_getimagebase (), RT_RCDATA, resource_name, 0);
if (NT_SUCCESS (status))
- status = _app_db_openfrombuffer (db_info, &buffer, XML_VERSION_MAXIMUM, XML_TYPE_PROFILE_INTERNAL);
+ status = _app_db_openfrombuffer (db_info, &storage, XML_TYPE_PROFILE_INTERNAL);
}
return status;
@@ -1577,30 +1495,43 @@ NTSTATUS _app_profile_load_fromresource (
VOID _app_profile_load_fallback ()
{
- ULONG app_hash;
+ PITEM_APP ptr_app;
if (!_app_isappfound (config.my_hash))
{
- app_hash = _app_addapplication (NULL, DATA_UNKNOWN, config.my_path, NULL, NULL);
+ ptr_app = _app_addapplication (NULL, DATA_UNKNOWN, config.my_path, NULL, NULL);
- if (app_hash)
- _app_setappinfobyhash (app_hash, INFO_IS_ENABLED, LongToPtr (TRUE));
+ if (ptr_app)
+ {
+ _app_setappinfo (ptr_app, INFO_IS_ENABLED, LongToPtr (TRUE));
+
+ _r_obj_dereference (ptr_app);
+ }
}
- _app_setappinfobyhash (config.my_hash, INFO_IS_UNDELETABLE, LongToPtr (TRUE));
-
// disable deletion for this shit ;)
if (!_r_config_getboolean (L"IsInternalRulesDisabled", FALSE, NULL))
{
if (!_app_isappfound (config.ntoskrnl_hash) && !_r_obj_isstringempty (config.system_path))
- _app_addapplication (NULL, DATA_UNKNOWN, config.system_path, NULL, NULL);
+ {
+ ptr_app = _app_addapplication (NULL, DATA_UNKNOWN, config.system_path, NULL, NULL);
+
+ if (ptr_app)
+ _r_obj_dereference (ptr_app);
+ }
if (!_app_isappfound (config.svchost_hash) && !_r_obj_isstringempty (config.svchost_path))
- _app_addapplication (NULL, DATA_UNKNOWN, config.svchost_path, NULL, NULL);
+ {
+ ptr_app = _app_addapplication (NULL, DATA_UNKNOWN, config.svchost_path, NULL, NULL);
- _app_setappinfobyhash (config.ntoskrnl_hash, INFO_IS_UNDELETABLE, LongToPtr (TRUE));
- _app_setappinfobyhash (config.svchost_hash, INFO_IS_UNDELETABLE, LongToPtr (TRUE));
+ if (ptr_app)
+ _r_obj_dereference (ptr_app);
+ }
}
+
+ _app_setappinfobyhash (config.ntoskrnl_hash, INFO_IS_UNDELETABLE, LongToPtr (TRUE));
+ _app_setappinfobyhash (config.svchost_hash, INFO_IS_UNDELETABLE, LongToPtr (TRUE));
+ _app_setappinfobyhash (config.my_hash, INFO_IS_UNDELETABLE, LongToPtr (TRUE));
}
VOID _app_profile_load_internal (
@@ -1610,21 +1541,16 @@ VOID _app_profile_load_internal (
_Out_ PLONG64 out_timestamp
)
{
- DB_INFORMATION db_info_buffer;
- DB_INFORMATION db_info_file;
- PDB_INFORMATION db_info;
- BOOLEAN is_loadfromresource;
+ DB_INFORMATION *db_info, db_info_buffer, db_info_file = {0};
LONG64 timestamp = 0;
- NTSTATUS status_file;
- NTSTATUS status_res;
- NTSTATUS status;
+ BOOLEAN is_loadfromresource;
+ NTSTATUS status, status_file, status_res;
status_file = _app_db_initialize (&db_info_file, TRUE);
if (_r_fs_isexists (&path->sr))
{
- if (NT_SUCCESS (status_file))
- status_file = _app_db_openfromfile (&db_info_file, path, XML_VERSION_MAXIMUM, XML_TYPE_PROFILE_INTERNAL);
+ status_file = SUCCEEDED (status_file) ? _app_db_openfromfile (&db_info_file, path, XML_TYPE_PROFILE_INTERNAL) : STATUS_INVALID_PARAMETER;
}
else
{
@@ -1634,14 +1560,7 @@ VOID _app_profile_load_internal (
status_res = _app_profile_load_fromresource (&db_info_buffer, resource_name);
// NOTE: prefer new profile version for 3.4+
- if (!NT_SUCCESS (status_file))
- {
- is_loadfromresource = TRUE;
- }
- else
- {
- is_loadfromresource = (db_info_file.version < db_info_buffer.version) || (db_info_file.timestamp < db_info_buffer.timestamp);
- }
+ is_loadfromresource = (!NT_SUCCESS (status_file)) ? TRUE : (db_info_file.version < db_info_buffer.version) || (db_info_file.timestamp < db_info_buffer.timestamp);
db_info = is_loadfromresource ? &db_info_buffer : &db_info_file;
@@ -1657,9 +1576,13 @@ VOID _app_profile_load_internal (
if (status != STATUS_OBJECT_NAME_NOT_FOUND && status != STATUS_OBJECT_PATH_NOT_FOUND)
{
if (hwnd)
+ {
_r_show_errormessage (hwnd, L"Could not load internal profile!", status, NULL, ET_NATIVE);
-
- _r_log (LOG_LEVEL_ERROR, NULL, L"_app_profile_load_internal", status, NULL);
+ }
+ else
+ {
+ _r_log (LOG_LEVEL_ERROR, NULL, L"_app_profile_load_internal", status, NULL);
+ }
}
}
@@ -1710,28 +1633,32 @@ NTSTATUS _app_profile_load (
status = _app_db_initialize (&db_info, TRUE);
- if (!NT_SUCCESS (status))
+ if (FAILED (status))
{
if (hwnd)
- _r_show_errormessage (hwnd, L"Could not intitialize profile!", status, NULL, ET_WINDOWS);
-
- _r_log (LOG_LEVEL_ERROR, NULL, L"_app_db_initialize", status, NULL);
+ {
+ _r_show_errormessage (hwnd, L"Could not intitialize XML library!", status, NULL, ET_WINDOWS);
+ }
+ else
+ {
+ _r_log (LOG_LEVEL_ERROR, NULL, L"_app_db_initialize", status, NULL);
+ }
goto CleanupExit;
}
- if (path_custom)
+ if (path_custom && _r_fs_isexists (&path_custom->sr))
{
- status = _app_db_openfromfile (&db_info, path_custom, XML_VERSION_MINIMAL, XML_TYPE_PROFILE);
+ status = _app_db_openfromfile (&db_info, path_custom, XML_TYPE_PROFILE);
}
else
{
_r_queuedlock_acquireshared (&lock_profile);
- status = _app_db_openfromfile (&db_info, profile_info.profile_path, XML_VERSION_MINIMAL, XML_TYPE_PROFILE);
+ status = _app_db_openfromfile (&db_info, profile_info.profile_path, XML_TYPE_PROFILE);
if (!NT_SUCCESS (status))
- status = _app_db_openfromfile (&db_info, profile_info.profile_path_backup, XML_VERSION_MINIMAL, XML_TYPE_PROFILE);
+ status = _app_db_openfromfile (&db_info, profile_info.profile_path_backup, XML_TYPE_PROFILE);
_r_queuedlock_releaseshared (&lock_profile);
}
@@ -1757,15 +1684,19 @@ CleanupExit:
if (status != STATUS_OBJECT_NAME_NOT_FOUND && status != STATUS_OBJECT_PATH_NOT_FOUND)
{
if (hwnd)
+ {
_r_show_errormessage (hwnd, L"Could not load profile!", status, NULL, ET_NATIVE);
-
- _r_log (LOG_LEVEL_ERROR, NULL, L"_app_profile_load", status, NULL);
+ }
+ else
+ {
+ _r_log (LOG_LEVEL_ERROR, NULL, TEXT (__FUNCTION__), status, NULL);
+ }
}
}
if (is_update)
{
- // load internal rules (new!)
+ // load internal rules!
if (!_r_config_getboolean (L"IsInternalRulesDisabled", FALSE, NULL))
_app_profile_load_internal (hwnd, profile_info.profile_path_internal, MAKEINTRESOURCE (IDR_PROFILE_INTERNAL), &profile_info.profile_internal_timestamp);
@@ -1791,12 +1722,16 @@ NTSTATUS _app_profile_save (
status = _app_db_initialize (&db_info, FALSE);
- if (!NT_SUCCESS (status))
+ if (FAILED (status))
{
if (hwnd)
- _r_show_errormessage (hwnd, L"Could not intitialize profile!", status, NULL, ET_WINDOWS);
-
- _r_log (LOG_LEVEL_ERROR, NULL, L"_app_db_initialize", status, NULL);
+ {
+ _r_show_errormessage (hwnd, L"Could not intitialize XML library!", status, NULL, ET_WINDOWS);
+ }
+ else
+ {
+ _r_log (LOG_LEVEL_ERROR, NULL, L"_app_db_initialize", status, NULL);
+ }
return status;
}
@@ -1808,25 +1743,24 @@ NTSTATUS _app_profile_save (
if (!_r_fs_isexists (&profile_info.profile_path_backup->sr))
is_backuprequired = TRUE;
- if (!is_backuprequired)
- {
- if (timestamp - _r_config_getlong64 (L"BackupTimestamp", 0, NULL) >= _r_config_getlong64 (L"BackupPeriod", BACKUP_HOURS_PERIOD, NULL))
- is_backuprequired = TRUE;
- }
+ if (!is_backuprequired && (timestamp - _r_config_getlong64 (L"BackupTimestamp", 0, NULL) >= _r_config_getlong64 (L"BackupPeriod", BACKUP_HOURS_PERIOD, NULL)))
+ is_backuprequired = TRUE;
}
_r_queuedlock_acquireexclusive (&lock_profile);
-
status = _app_db_savetofile (&db_info, profile_info.profile_path, XML_VERSION_MAXIMUM, XML_TYPE_PROFILE, timestamp);
-
_r_queuedlock_releaseexclusive (&lock_profile);
if (!NT_SUCCESS (status))
{
if (hwnd)
- _r_show_errormessage (hwnd, L"Could not save profile!", status, NULL, ET_NATIVE);
-
- _r_log (LOG_LEVEL_ERROR, NULL, L"_app_db_savetofile", status, profile_info.profile_path->buffer);
+ {
+ _r_show_errormessage (hwnd, L"Could not save profile!", status, profile_info.profile_path->buffer, ET_NATIVE);
+ }
+ else
+ {
+ _r_log (LOG_LEVEL_ERROR, NULL, L"_app_db_savetofile", status, profile_info.profile_path->buffer);
+ }
}
_app_db_destroy (&db_info);
diff --git a/src/profile.h b/src/profile.h
index ac2dae80..9fd9e196 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -29,13 +29,15 @@ BOOLEAN _app_getappinfobyhash (
_In_ ULONG_PTR length
);
-VOID _app_setappinfo (
+_Success_ (return)
+BOOLEAN _app_setappinfo (
_In_ PITEM_APP ptr_app,
_In_ ENUM_INFO_DATA info_data,
_In_opt_ PVOID value
);
-VOID _app_setappinfobyhash (
+_Success_ (return)
+BOOLEAN _app_setappinfobyhash (
_In_ ULONG app_hash,
_In_ ENUM_INFO_DATA info_data,
_In_opt_ PVOID value
@@ -57,8 +59,8 @@ BOOLEAN _app_getruleinfobyid (
_In_ ULONG_PTR length
);
-_Success_ (return != 0)
-ULONG _app_addapplication (
+_Ret_maybenull_
+PITEM_APP _app_addapplication (
_In_opt_ HWND hwnd,
_In_ ENUM_TYPE_DATA type,
_In_ PR_STRING path,
@@ -96,7 +98,7 @@ PITEM_RULE _app_getrulebyid (
_Ret_maybenull_
PITEM_RULE _app_getrulebyhash (
- _In_ ULONG_PTR rule_hash
+ _In_ ULONG rule_hash
);
_Ret_maybenull_
@@ -114,6 +116,7 @@ ULONG _app_getlogapp (
_In_ ULONG index
);
+_Success_ (return != 0)
COLORREF _app_getappcolor (
_In_ INT listview_id,
_In_ ULONG app_hash,
@@ -170,6 +173,7 @@ VOID _app_getcount (
_Out_ PITEM_STATUS status
);
+_Success_ (return != 0)
COLORREF _app_getrulecolor (
_In_ INT listview_id,
_In_ ULONG_PTR rule_idx
@@ -196,13 +200,6 @@ VOID _app_ruleenable (
_In_ BOOLEAN is_createconfig
);
-//VOID _app_rulecleanapp (
-// _In_opt_ HWND hwnd,
-// _In_ ULONG_PTR item_id,
-// _In_ PITEM_RULE ptr_rule,
-// _In_opt_ ULONG_PTR app_hash
-//);
-
VOID _app_ruleremoveapp (
_In_opt_ HWND hwnd,
_In_ ULONG_PTR item_id,
@@ -233,30 +230,29 @@ VOID _app_ruleblocklistset (
_Ret_maybenull_
PR_STRING _app_appexpandrules (
_In_ ULONG app_hash,
- _In_ LPWSTR delimeter
+ _In_ LPCWSTR delimeter
);
_Ret_maybenull_
PR_STRING _app_rulesexpandapps (
_In_ PITEM_RULE ptr_rule,
_In_ BOOLEAN is_fordisplay,
- _In_ LPWSTR delimeter
+ _In_ LPCWSTR delimeter
);
_Ret_maybenull_
PR_STRING _app_rulesexpandrules (
- _In_opt_ PR_STRING rule,
- _In_ LPWSTR delimeter
+ _In_opt_ PR_STRING rule
);
BOOLEAN _app_isrulesupportedbyos (
- _In_ PR_STRINGREF os_version
+ _In_ PCR_STRINGREF os_version
);
VOID _app_profile_initialize ();
NTSTATUS _app_profile_load_fromresource (
- _Out_ PDB_INFORMATION out_buffer,
+ _Out_ PDB_INFORMATION db_info,
_In_ LPCWSTR resource_name
);
diff --git a/src/search.c b/src/search.c
index 50cbe49e..8dc716e7 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1,6 +1,6 @@
// simplewall
-// Copyright (c) 2012-2021 dmex
-// Copyright (c) 2021-2025 Henry++
+// Copyright (c) 2012-2026 dmex
+// Copyright (c) 2021-2026 Henry++
#include "global.h"
@@ -13,14 +13,15 @@ VOID _app_search_initialize (
LONG cx_border;
HRESULT status;
- GetWindowRect (context->hwnd, &rect);
+ if (!GetWindowRect (context->hwnd, &rect))
+ return;
cx_border = _r_dc_getsystemmetrics (SM_CXBORDER, context->dpi_value);
// initialize borders
context->cx_width = _r_dc_getdpi (20, context->dpi_value);
context->cx_border = cx_border;
- context->dc_brush = GetStockObject (DC_BRUSH);
+ context->dc_brush = (HBRUSH)GetStockObject (DC_BRUSH);
if (IsThemeActive ())
{
@@ -43,9 +44,11 @@ VOID _app_search_create (
)
{
PSEARCH_CONTEXT context;
- WCHAR buffer[128];
+ WCHAR buffer[0x80];
- context = _r_mem_allocate (sizeof (SEARCH_CONTEXT));
+ context = (PSEARCH_CONTEXT)_r_mem_allocate (sizeof (SEARCH_CONTEXT));
+
+ BringWindowToTop (hwnd); // HACK!!!
context->hwnd = hwnd;
context->dpi_value = _r_dc_getwindowdpi (hwnd);
@@ -54,16 +57,17 @@ VOID _app_search_create (
_r_wnd_setcontext (context->hwnd, SHORT_MAX, context);
- // Subclass the Edit control window procedure.
+ // subclass the edit control window procedure
context->wnd_proc = (WNDPROC)GetWindowLongPtrW (context->hwnd, GWLP_WNDPROC);
SetWindowLongPtrW (context->hwnd, GWLP_WNDPROC, (LONG_PTR)&_app_search_subclass_proc);
+ // set cue banner
_r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"%s...", _r_locale_getstring (IDS_FIND));
_r_edit_setcuebanner (context->hwnd, 0, buffer);
- // Initialize the theme parameters.
- _app_search_themechanged (hwnd, context);
+ // initialize the theme parameters
+ _app_search_themechanged (context->hwnd, context);
}
VOID _app_search_initializeimages (
@@ -116,13 +120,13 @@ VOID _app_search_themechanged (
_app_search_initialize (context);
_app_search_initializeimages (context, hwnd);
- // Reset the client area margins.
- _r_ctrl_settextmargin (hwnd, 0, 0, 0);
+ // reset the client area margins
+ CallWindowProcW (context->wnd_proc, hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELPARAM (0, 0));
- // Refresh the non-client area.
+ // refresh the non-client area
SetWindowPos (hwnd, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
- // Force the edit control to update its non-client area.
+ // force the edit control to update its non-client area
RedrawWindow (hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
}
@@ -132,11 +136,7 @@ VOID _app_search_setvisible (
_In_ LONG dpi_value
)
{
- BOOLEAN is_visible;
-
- is_visible = _r_config_getboolean (L"IsShowSearchBar", TRUE, NULL);
-
- if (is_visible)
+ if (_r_config_getboolean (L"IsShowSearchBar", TRUE, NULL))
{
if (!_r_rebar_isbandexists (hwnd, IDC_REBAR, REBAR_SEARCH_ID))
_r_rebar_insertband (hwnd, IDC_REBAR, REBAR_SEARCH_ID, config.hsearchbar, RBBS_VARIABLEHEIGHT | RBBS_NOGRIPPER | RBBS_USECHEVRON, _r_dc_getdpi (180, dpi_value), 20);
@@ -176,6 +176,11 @@ VOID _app_search_drawwindow (
PatBlt (context->hdc, wnd_rect->left, wnd_rect->top, wnd_rect->right - wnd_rect->left, 1, PATCOPY);
PatBlt (context->hdc, wnd_rect->left, wnd_rect->bottom - 1, wnd_rect->right - wnd_rect->left, 1, PATCOPY);
+ PatBlt (context->hdc, wnd_rect->left, wnd_rect->top, 1, wnd_rect->bottom - wnd_rect->top, PATCOPY);
+ PatBlt (context->hdc, wnd_rect->right - 1, wnd_rect->top, 1, wnd_rect->bottom - wnd_rect->top, PATCOPY);
+ PatBlt (context->hdc, wnd_rect->left, wnd_rect->top, wnd_rect->right - wnd_rect->left, 1, PATCOPY);
+ PatBlt (context->hdc, wnd_rect->left, wnd_rect->bottom - 1, wnd_rect->right - wnd_rect->left, 1, PATCOPY);
+
SetDCBrushColor (context->hdc, RGB (60, 60, 60));
SelectObject (context->hdc, context->dc_brush);
@@ -193,6 +198,7 @@ VOID _app_search_drawbutton (
)
{
RECT btn_rect;
+ HICON hicon;
_app_search_getbuttonrect (context, wnd_rect, &btn_rect);
@@ -209,17 +215,9 @@ VOID _app_search_drawbutton (
_r_dc_fillrect (context->hdc, &btn_rect, _r_theme_isenabled () ? RGB (60, 60, 60) : GetSysColor (COLOR_WINDOW));
}
- DrawIconEx (
- context->hdc,
- btn_rect.left + 1,
- btn_rect.top,
- _r_theme_isenabled () ? context->hicon_light : context->hicon_dark,
- context->image_width,
- context->image_height,
- 0,
- NULL,
- DI_NORMAL
- );
+ hicon = _r_theme_isenabled () ? context->hicon_light : context->hicon_dark;
+
+ DrawIconEx (context->hdc, btn_rect.left + 1, btn_rect.top, hicon, context->image_width, context->image_height, 0, NULL, DI_NORMAL);
}
VOID _app_search_getbuttonrect (
@@ -228,12 +226,16 @@ VOID _app_search_getbuttonrect (
_Out_ PRECT btn_rect
)
{
- *btn_rect = *wnd_rect;
+ CopyRect (btn_rect, wnd_rect);
btn_rect->left = ((btn_rect->right - context->cx_width) - context->cx_border - 1);
btn_rect->top += context->cx_border;
btn_rect->right -= context->cx_border;
btn_rect->bottom -= context->cx_border;
+
+ // shift the button rect to the left based on the button index
+ //btn_rect->left -= (context->cx_width + context->cx_border - 1);
+ //btn_rect->right -= (context->cx_width + context->cx_border - 1);
}
BOOLEAN _app_search_isstringfound (
@@ -243,7 +245,7 @@ BOOLEAN _app_search_isstringfound (
_Inout_ PBOOLEAN is_changed
)
{
- if (!string)
+ if (_r_obj_isstringempty (string))
{
if (context->is_hidden)
{
@@ -319,9 +321,9 @@ BOOLEAN _app_search_applyfilteritem (
_In_opt_ PR_STRING search_string
)
{
- PITEM_APP ptr_app = NULL;
- PITEM_RULE ptr_rule = NULL;
PITEM_NETWORK ptr_network = NULL;
+ PITEM_RULE ptr_rule = NULL;
+ PITEM_APP ptr_app = NULL;
PITEM_LOG ptr_log = NULL;
PR_STRING string;
BOOLEAN is_changed = FALSE;
@@ -334,7 +336,7 @@ BOOLEAN _app_search_applyfilteritem (
is_changed = TRUE;
}
- if (!search_string)
+ if (_r_obj_isstringempty (search_string))
goto CleanupExit;
switch (listview_id)
@@ -350,18 +352,12 @@ BOOLEAN _app_search_applyfilteritem (
goto CleanupExit;
// path
- if (ptr_app->real_path)
- {
- if (_app_search_isstringfound (&ptr_app->real_path->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_app->real_path && _app_search_isstringfound (&ptr_app->real_path->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
// comment
- if (!_r_obj_isstringempty (ptr_app->comment))
- {
- if (_app_search_isstringfound (&ptr_app->comment->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (!_r_obj_isstringempty (ptr_app->comment) && _app_search_isstringfound (&ptr_app->comment->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
break;
}
@@ -376,36 +372,21 @@ BOOLEAN _app_search_applyfilteritem (
if (!ptr_rule)
goto CleanupExit;
- if (ptr_rule->name)
- {
- if (_app_search_isstringfound (&ptr_rule->name->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_rule->name && _app_search_isstringfound (&ptr_rule->name->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
- if (ptr_rule->rule_remote)
- {
- if (_app_search_isstringfound (&ptr_rule->rule_remote->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_rule->rule_remote && _app_search_isstringfound (&ptr_rule->rule_remote->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
- if (ptr_rule->rule_local)
- {
- if (_app_search_isstringfound (&ptr_rule->rule_local->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_rule->rule_local && _app_search_isstringfound (&ptr_rule->rule_local->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
- if (ptr_rule->protocol_str)
- {
- if (_app_search_isstringfound (&ptr_rule->protocol_str->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_rule->protocol_str && _app_search_isstringfound (&ptr_rule->protocol_str->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
// comment
- if (!_r_obj_isstringempty (ptr_rule->comment))
- {
- if (_app_search_isstringfound (&ptr_rule->comment->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (!_r_obj_isstringempty (ptr_rule->comment) && _app_search_isstringfound (&ptr_rule->comment->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
break;
}
@@ -418,14 +399,11 @@ BOOLEAN _app_search_applyfilteritem (
goto CleanupExit;
// path
- if (ptr_network->path)
- {
- if (_app_search_isstringfound (&ptr_network->path->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_network->path && _app_search_isstringfound (&ptr_network->path->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
// local address
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->local_addr_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->local_addr_str, NULL, NULL);
if (string)
{
@@ -434,7 +412,7 @@ BOOLEAN _app_search_applyfilteritem (
}
// local host
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->local_host_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->local_host_str, NULL, NULL);
if (string)
{
@@ -443,7 +421,7 @@ BOOLEAN _app_search_applyfilteritem (
}
// remote address
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->remote_addr_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->remote_addr_str, NULL, NULL);
if (string)
{
@@ -452,7 +430,7 @@ BOOLEAN _app_search_applyfilteritem (
}
// remote host
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->remote_host_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_network->remote_host_str, NULL, NULL);
if (string)
{
@@ -461,11 +439,8 @@ BOOLEAN _app_search_applyfilteritem (
}
// protocol
- if (ptr_network->protocol_str)
- {
- if (_app_search_isstringfound (&ptr_network->protocol_str->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_network->protocol_str && _app_search_isstringfound (&ptr_network->protocol_str->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
break;
}
@@ -478,35 +453,23 @@ BOOLEAN _app_search_applyfilteritem (
goto CleanupExit;
// path
- if (ptr_log->path)
- {
- if (_app_search_isstringfound (&ptr_log->path->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_log->path && _app_search_isstringfound (&ptr_log->path->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
// filter name
- if (ptr_log->filter_name)
- {
- if (_app_search_isstringfound (&ptr_log->filter_name->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_log->filter_name && _app_search_isstringfound (&ptr_log->filter_name->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
// layer name
- if (ptr_log->layer_name)
- {
- if (_app_search_isstringfound (&ptr_log->layer_name->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_log->layer_name && _app_search_isstringfound (&ptr_log->layer_name->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
// user name
- if (ptr_log->username)
- {
- if (_app_search_isstringfound (&ptr_log->username->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_log->username && _app_search_isstringfound (&ptr_log->username->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
// local address
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_addr_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_addr_str, NULL, NULL);
if (string)
{
@@ -515,7 +478,7 @@ BOOLEAN _app_search_applyfilteritem (
}
// local host
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_host_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_host_str, NULL, NULL);
if (string)
{
@@ -524,7 +487,7 @@ BOOLEAN _app_search_applyfilteritem (
}
// remote address
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_addr_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_addr_str, NULL, NULL);
if (string)
{
@@ -533,7 +496,7 @@ BOOLEAN _app_search_applyfilteritem (
}
// remote host
- string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_host_str, NULL, NULL);
+ string = (PR_STRING)_InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_host_str, NULL, NULL);
if (string)
{
@@ -542,11 +505,8 @@ BOOLEAN _app_search_applyfilteritem (
}
// protocol
- if (ptr_log->protocol_str)
- {
- if (_app_search_isstringfound (&ptr_log->protocol_str->sr, &search_string->sr, context, &is_changed))
- goto CleanupExit;
- }
+ if (ptr_log->protocol_str && _app_search_isstringfound (&ptr_log->protocol_str->sr, &search_string->sr, context, &is_changed))
+ goto CleanupExit;
break;
}
@@ -554,21 +514,21 @@ BOOLEAN _app_search_applyfilteritem (
CleanupExit:
- if (ptr_app)
- _r_obj_dereference (ptr_app);
-
- if (ptr_rule)
- _r_obj_dereference (ptr_rule);
+ if (is_changed)
+ _r_listview_setitem (hwnd, listview_id, item_id, 0, NULL, I_IMAGECALLBACK, I_GROUPIDCALLBACK, I_DEFAULT);
if (ptr_network)
_r_obj_dereference (ptr_network);
+ if (ptr_rule)
+ _r_obj_dereference (ptr_rule);
+
+ if (ptr_app)
+ _r_obj_dereference (ptr_app);
+
if (ptr_log)
_r_obj_dereference (ptr_log);
- if (is_changed)
- _r_listview_setitem (hwnd, listview_id, item_id, 0, NULL, I_IMAGECALLBACK, I_GROUPIDCALLBACK, I_DEFAULT);
-
return is_changed;
}
@@ -599,7 +559,7 @@ VOID _app_search_createbufferedcontext (
context->hbitmap = CreateCompatibleBitmap (hdc, context->rect.right, context->rect.bottom);
- context->old_bitmap = SelectObject (context->hdc, context->hbitmap);
+ context->old_bitmap = (HBITMAP)SelectObject (context->hdc, context->hbitmap);
}
VOID _app_search_destroybufferedcontext (
@@ -624,10 +584,10 @@ LRESULT CALLBACK _app_search_subclass_proc (
PSEARCH_CONTEXT context;
WNDPROC wnd_proc;
- context = _r_wnd_getcontext (hwnd, SHORT_MAX);
+ context = (PSEARCH_CONTEXT)_r_wnd_getcontext (hwnd, SHORT_MAX);
if (!context)
- return 0;
+ return DefWindowProcW (hwnd, msg, wparam, lparam);
wnd_proc = context->wnd_proc;
@@ -660,10 +620,10 @@ LRESULT CALLBACK _app_search_subclass_proc (
calc_size = (LPNCCALCSIZE_PARAMS)lparam;
- // Let Windows handle the non-client defaults.
+ // let Windows handle the non-client defaults
CallWindowProcW (wnd_proc, hwnd, msg, wparam, lparam);
- // Deflate the client area to accommodate the custom button.
+ // deflate the client area to accommodate the custom button
calc_size->rgrc[0].right -= context->cx_width;
return 0;
@@ -671,11 +631,21 @@ LRESULT CALLBACK _app_search_subclass_proc (
case WM_NCPAINT:
{
- RECT wnd_rect;
- RECT buf_rect;
+ RECT buf_rect, wnd_rect;
HRGN hrgn;
HDC hdc;
- ULONG flags = DCX_WINDOW | DCX_LOCKWINDOWUPDATE | DCX_USESTYLE;
+ ULONG flags = DCX_WINDOW | DCX_CACHE | DCX_USESTYLE;
+ LONG height, width;
+
+ // get the screen coordinates of the window
+ if (!GetWindowRect (hwnd, &wnd_rect))
+ break;
+
+ width = _r_calc_rectwidth (&wnd_rect);
+ height = _r_calc_rectheight (&wnd_rect);
+
+ if (height <= 0 || width <= 0)
+ break;
hrgn = (HRGN)wparam;
@@ -689,22 +659,10 @@ LRESULT CALLBACK _app_search_subclass_proc (
if (hdc)
{
- // Get the screen coordinates of the window.
- GetWindowRect (hwnd, &wnd_rect);
-
- // Adjust the coordinates (start from 0,0).
+ // normalize window coordinates (start from 0,0)
OffsetRect (&wnd_rect, -wnd_rect.left, -wnd_rect.top);
- // Exclude client area.
- ExcludeClipRect (
- hdc,
- wnd_rect.left + context->cx_border + 1,
- wnd_rect.top + context->cx_border + 1,
- wnd_rect.right - context->cx_width - (context->cx_border + 1),
- wnd_rect.bottom - (context->cx_border + 1)
- );
-
- SetRect (&buf_rect, 0, 0, _r_calc_rectwidth (&wnd_rect), _r_calc_rectheight (&wnd_rect));
+ SetRect (&buf_rect, 0, 0, width, height);
if (context->hdc && (context->rect.right < buf_rect.right || context->rect.bottom < buf_rect.bottom))
_app_search_destroybufferedcontext (context);
@@ -719,6 +677,16 @@ LRESULT CALLBACK _app_search_subclass_proc (
break;
}
+ // exclude client area from NC drawing
+ ExcludeClipRect (
+ hdc,
+ wnd_rect.left + context->cx_border + 1,
+ wnd_rect.top + context->cx_border + 1,
+ wnd_rect.right - context->cx_width - (context->cx_border + 1),
+ wnd_rect.bottom - (context->cx_border + 1)
+ );
+
+ // NC frame
if ((context->is_mouseactive && context->is_hot) || GetFocus () == hwnd)
{
_r_dc_framerect (context->hdc, &wnd_rect, _r_theme_isenabled () ? WND_HOT_CLR : GetSysColor (COLOR_HOTLIGHT));
@@ -739,7 +707,8 @@ LRESULT CALLBACK _app_search_subclass_proc (
_app_search_drawwindow (context, &wnd_rect);
_app_search_drawbutton (context, hwnd, &wnd_rect);
- BitBlt (hdc, buf_rect.left, buf_rect.top, buf_rect.right, buf_rect.bottom, context->hdc, 0, 0, SRCCOPY);
+ // commit to the target DC
+ BitBlt (hdc, 0, 0, buf_rect.right, buf_rect.bottom, context->hdc, 0, 0, SRCCOPY);
ReleaseDC (hwnd, hdc);
}
@@ -749,22 +718,21 @@ LRESULT CALLBACK _app_search_subclass_proc (
case WM_NCHITTEST:
{
- RECT wnd_rect;
- RECT btn_rect;
- POINT point;
+ RECT btn_rect, wnd_rect;
+ POINT point = {0};
- // Get the screen coordinates of the mouse.
- if (!GetCursorPos (&point))
- break;
+ // get the screen coordinates of the mouse
+ point.x = GET_X_LPARAM (lparam);
+ point.y = GET_Y_LPARAM (lparam);
- // Get the screen coordinates of the window.
+ // get the screen coordinates of the window
if (!GetWindowRect (hwnd, &wnd_rect))
break;
- // Get the position of the inserted button.
+ // get the position of the inserted button
_app_search_getbuttonrect (context, &wnd_rect, &btn_rect);
- // Check that the mouse is within the inserted button.
+ // check that the mouse is within the inserted button
if (PtInRect (&btn_rect, point))
return HTBORDER;
@@ -773,19 +741,18 @@ LRESULT CALLBACK _app_search_subclass_proc (
case WM_NCLBUTTONDOWN:
{
- RECT wnd_rect;
- RECT btn_rect;
- POINT point;
+ RECT btn_rect, wnd_rect;
+ POINT point = {0};
- // Get the screen coordinates of the mouse.
- if (!GetCursorPos (&point))
- break;
+ // get the screen coordinates of the mouse
+ point.x = GET_X_LPARAM (lparam);
+ point.y = GET_Y_LPARAM (lparam);
- // Get the screen coordinates of the window.
+ // get the screen coordinates of the window
if (!GetWindowRect (hwnd, &wnd_rect))
break;
- // Get the position of the inserted button.
+ // get the position of the inserted button
_app_search_getbuttonrect (context, &wnd_rect, &btn_rect);
context->is_pushed = PtInRect (&btn_rect, point);
@@ -799,22 +766,24 @@ LRESULT CALLBACK _app_search_subclass_proc (
case WM_LBUTTONUP:
{
- RECT wnd_rect;
- RECT btn_rect;
- POINT point;
+ RECT btn_rect, wnd_rect;
+ POINT point = {0};
+ ULONG position;
- // Get the screen coordinates of the mouse.
- if (!GetCursorPos (&point))
- break;
+ // get the screen coordinates of the mouse
+ position = GetMessagePos ();
- // Get the screen coordinates of the window.
+ point.x = GET_X_LPARAM (position);
+ point.y = GET_Y_LPARAM (position);
+
+ // get the screen coordinates of the window
if (!GetWindowRect (hwnd, &wnd_rect))
break;
- // Get the position of the inserted button.
+ // get the position of the inserted button
_app_search_getbuttonrect (context, &wnd_rect, &btn_rect);
- // Check that the mouse is within the inserted button.
+ // check that the mouse is within the inserted button
if (PtInRect (&btn_rect, point))
{
SetFocus (hwnd);
@@ -840,10 +809,12 @@ LRESULT CALLBACK _app_search_subclass_proc (
case WM_UNDO:
case WM_KEYUP:
case WM_SETTEXT:
- case WM_KILLFOCUS:
{
+ LRESULT result = CallWindowProcW (wnd_proc, hwnd, msg, wparam, lparam);
+
RedrawWindow (hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
- break;
+
+ return result;
}
case WM_SETTINGCHANGE:
@@ -863,28 +834,30 @@ LRESULT CALLBACK _app_search_subclass_proc (
case WM_NCMOUSEMOVE:
{
TRACKMOUSEEVENT tme = {0};
- RECT wnd_rect;
- RECT btn_rect;
- POINT pt;
+ RECT btn_rect, wnd_rect;
+ POINT point = {0};
+ ULONG position;
- // Get the screen coordinates of the mouse.
- if (!GetCursorPos (&pt))
- break;
+ // get the screen coordinates of the mouse
+ position = GetMessagePos ();
- // Get the screen coordinates of the window.
+ point.x = GET_X_LPARAM (position);
+ point.y = GET_Y_LPARAM (position);
+
+ // get the screen coordinates of the window
if (!GetWindowRect (hwnd, &wnd_rect))
break;
- context->is_hot = PtInRect (&wnd_rect, pt);
+ context->is_hot = PtInRect (&wnd_rect, point);
- // Get the position of the inserted button.
+ // get the position of the inserted button
_app_search_getbuttonrect (context, &wnd_rect, &btn_rect);
- // Check that the mouse is within the inserted button.
+ // check that the mouse is within the inserted button
if (!context->is_mouseactive)
{
tme.cbSize = sizeof (TRACKMOUSEEVENT);
- tme.dwFlags = TME_LEAVE;
+ tme.dwFlags = TME_LEAVE | TME_NONCLIENT;
tme.hwndTrack = hwnd;
tme.dwHoverTime = 0;
@@ -902,27 +875,16 @@ LRESULT CALLBACK _app_search_subclass_proc (
case WM_NCMOUSELEAVE:
{
TRACKMOUSEEVENT tme = {0};
- RECT wnd_rect;
- RECT btn_rect;
+ RECT btn_rect, wnd_rect;
POINT point;
- if (context->is_mouseactive)
- {
- tme.cbSize = sizeof (TRACKMOUSEEVENT);
- tme.dwFlags = TME_LEAVE | TME_CANCEL;
- tme.hwndTrack = hwnd;
- tme.dwHoverTime = 0;
+ context->is_mouseactive = FALSE;
- TrackMouseEvent (&tme);
-
- context->is_mouseactive = FALSE;
- }
-
- // Get the screen coordinates of the mouse.
+ // get the screen coordinates of the mouse
if (!GetCursorPos (&point))
break;
- // Get the screen coordinates of the window.
+ // get the screen coordinates of the window
if (!GetWindowRect (hwnd, &wnd_rect))
break;
@@ -934,6 +896,24 @@ LRESULT CALLBACK _app_search_subclass_proc (
break;
}
+
+ case WM_CHAR:
+ {
+ // delete previous word for ctrl+backspace (dmex)
+ if (wparam == VK_F16 && GetAsyncKeyState (VK_CONTROL) < 0)
+ return 1;
+
+ break;
+ }
+
+ case WM_GETDLGCODE:
+ {
+ // intercept esc key (otherwise it would get sent to parent window)
+ if (wparam == VK_ESCAPE && ((MSG*)lparam)->message == WM_KEYDOWN)
+ return DLGC_WANTMESSAGE;
+
+ break;
+ }
}
return CallWindowProcW (wnd_proc, hwnd, msg, wparam, lparam);
diff --git a/src/search.h b/src/search.h
index fe4520b2..d8aa9c48 100644
--- a/src/search.h
+++ b/src/search.h
@@ -1,6 +1,6 @@
// simplewall
-// Copyright (c) 2012-2021 dmex
-// Copyright (c) 2021-2025 Henry++
+// Copyright (c) 2012-2026 dmex
+// Copyright (c) 2021-2026 Henry++
#pragma once
diff --git a/src/security.c b/src/security.c
index 6c05d39e..1e91cd37 100644
--- a/src/security.c
+++ b/src/security.c
@@ -9,19 +9,17 @@ PSID _app_quyerybuiltinsid (
)
{
PSID sid;
- ULONG sid_length;
+ ULONG sid_length = SECURITY_MAX_SID_SIZE;
- sid_length = SECURITY_MAX_SID_SIZE;
- sid = _r_mem_allocate (sid_length);
+ sid = (PSID)_r_mem_allocate (sid_length);
if (!CreateWellKnownSid (sid_type, NULL, sid, &sid_length))
{
_r_log_v (LOG_LEVEL_ERROR, NULL, L"CreateWellKnownSid", NtLastError (), L"%d", sid_type);
- _r_mem_free (sid);
+ _r_mem_free (sid); // cleanup!
return NULL;
-
}
return sid;
@@ -29,20 +27,20 @@ PSID _app_quyerybuiltinsid (
VOID _app_generate_credentials ()
{
- // For revoke current user (v3.0.5 Beta and lower)
- config.builtin_current_sid = _r_sys_getcurrenttoken ()->token_sid;
+ // S-1-5-32-556 (BUILTIN\Network Configuration Operators)
+ config.builtin_netops_sid = _app_quyerybuiltinsid (WinBuiltinNetworkConfigurationOperatorsSid);
// S-1-5-32-544 (BUILTIN\Administrators)
config.builtin_admins_sid = _app_quyerybuiltinsid (WinBuiltinAdministratorsSid);
- // S-1-5-32-556 (BUILTIN\Network Configuration Operators)
- config.builtin_netops_sid = _app_quyerybuiltinsid (WinBuiltinNetworkConfigurationOperatorsSid);
+ // for revoke current user (v3.0.5 Beta and lower)
+ config.builtin_current_sid = _r_sys_getcurrenttoken ()->token_sid;
+ _r_sys_getservicesid (&config.service_wdiservicehost_sid, L"WdiServiceHost");
+ _r_sys_getservicesid (&config.service_policyagent_sid, L"PolicyAgent");
_r_sys_getservicesid (&config.service_mpssvc_sid, L"mpssvc");
_r_sys_getservicesid (&config.service_nlasvc_sid, L"NlaSvc");
- _r_sys_getservicesid (&config.service_policyagent_sid, L"PolicyAgent");
_r_sys_getservicesid (&config.service_rpcss_sid, L"RpcSs");
- _r_sys_getservicesid (&config.service_wdiservicehost_sid, L"WdiServiceHost");
}
_Ret_maybenull_
@@ -55,9 +53,7 @@ PACL _app_createaccesscontrollist (
EXPLICIT_ACCESS ea[3] = {0};
PACL new_dacl = NULL;
ULONG count = 0;
- BOOLEAN is_currentuserhaverights = FALSE;
- BOOLEAN is_openforeveryone = FALSE;
- BOOLEAN is_secured = FALSE;
+ BOOLEAN is_currentuserhaverights = FALSE, is_openforeveryone = FALSE, is_secured = FALSE;
NTSTATUS status;
for (WORD ace_index = 0; ace_index < acl->AceCount; ace_index++)
@@ -110,18 +106,18 @@ PACL _app_createaccesscontrollist (
{
// revoke current user access rights
if (is_currentuserhaverights)
- _app_setexplicitaccess (&ea[count++], REVOKE_ACCESS, 0, NO_INHERITANCE, config.builtin_current_sid);
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, REVOKE_ACCESS, 0, config.builtin_current_sid);
// revoke everyone access rights
if (is_openforeveryone)
- _app_setexplicitaccess (&ea[count++], REVOKE_ACCESS, 0, NO_INHERITANCE, &SeEveryoneSid);
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, REVOKE_ACCESS, 0, &SeEveryoneSid);
// secure filter from deletion
_app_setexplicitaccess (
&ea[count++],
+ is_secure ? CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE : NO_INHERITANCE,
is_secure ? DENY_ACCESS : GRANT_ACCESS,
FWPM_ACTRL_WRITE | DELETE | WRITE_DAC | WRITE_OWNER,
- is_secure ? CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE : NO_INHERITANCE,
&SeEveryoneSid
);
@@ -138,17 +134,17 @@ PACL _app_createaccesscontrollist (
VOID _app_setexplicitaccess (
_Out_ PEXPLICIT_ACCESS ea,
+ _In_ ULONG inheritance,
_In_ ACCESS_MODE mode,
_In_ ULONG rights,
- _In_ ULONG inheritance,
_In_opt_ PSID sid
)
{
RtlSecureZeroMemory (ea, sizeof (EXPLICIT_ACCESS));
- ea->grfAccessMode = mode;
ea->grfAccessPermissions = rights;
ea->grfInheritance = inheritance;
+ ea->grfAccessMode = mode;
BuildTrusteeWithSidW (&(ea->Trustee), sid);
}
@@ -159,15 +155,11 @@ VOID _app_setenginesecurity (
{
PSECURITY_DESCRIPTOR security_descriptor = NULL;
PACCESS_ALLOWED_ACE ace = NULL;
- EXPLICIT_ACCESS ea[18] = {0};
- PSID sid_owner = NULL;
- PSID sid_group = NULL;
- PACL new_dacl = NULL;
- PACL dacl = NULL;
- PACL sacl = NULL;
+ EXPLICIT_ACCESS ea[0x12] = {0};
+ PACL dacl = NULL, sacl = NULL, new_dacl = NULL;
+ PSID sid_group = NULL, sid_owner = NULL;
ULONG count = 0;
- BOOLEAN is_currentuserhaverights = FALSE;
- BOOLEAN is_openforeveryone = FALSE;
+ BOOLEAN is_currentuserhaverights = FALSE, is_openforeveryone = FALSE;
LONG status;
status = FwpmEngineGetSecurityInfo0 (hengine, DACL_SECURITY_INFORMATION, &sid_owner, &sid_group, &dacl, &sacl, &security_descriptor);
@@ -175,7 +167,6 @@ VOID _app_setenginesecurity (
if (status != ERROR_SUCCESS)
{
_r_log (LOG_LEVEL_ERROR, NULL, L"FwpmEngineGetSecurityInfo0", status, NULL);
-
return;
}
@@ -188,7 +179,6 @@ VOID _app_setenginesecurity (
if (!NT_SUCCESS (status))
{
_r_log_v (LOG_LEVEL_ERROR, NULL, L"RtlGetAce", status, L"%d", ace_index);
-
continue;
}
@@ -222,158 +212,58 @@ VOID _app_setenginesecurity (
if (is_currentuserhaverights || is_openforeveryone)
{
FwpmEngineSetSecurityInfo0 (hengine, OWNER_SECURITY_INFORMATION, &SeLocalServiceSid, NULL, NULL, NULL);
-
FwpmNetEventsSetSecurityInfo0 (hengine, OWNER_SECURITY_INFORMATION, &SeLocalServiceSid, NULL, NULL, NULL);
// revoke current user access rights
- if (is_currentuserhaverights)
- {
- if (config.builtin_current_sid)
- _app_setexplicitaccess (&ea[count++], REVOKE_ACCESS, 0, NO_INHERITANCE, config.builtin_current_sid);
- }
+ if (is_currentuserhaverights && config.builtin_current_sid)
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, REVOKE_ACCESS, 0, config.builtin_current_sid);
// reset default engine rights
if (is_openforeveryone)
{
if (config.builtin_admins_sid)
{
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- FWPM_GENERIC_ALL | DELETE | WRITE_DAC | WRITE_OWNER, NO_INHERITANCE,
- config.builtin_admins_sid
- );
-
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- 0x10000000,
- OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE,
- config.builtin_admins_sid
- );
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE | WRITE_DAC | WRITE_OWNER, config.builtin_admins_sid);
+ _app_setexplicitaccess (&ea[count++], OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, GRANT_ACCESS, 0x10000000, config.builtin_admins_sid);
}
if (config.builtin_netops_sid)
{
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- FWPM_GENERIC_ALL | DELETE,
- NO_INHERITANCE,
- config.builtin_netops_sid
- );
-
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- 0xE0000000,
- OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE,
- config.builtin_netops_sid
- );
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, config.builtin_netops_sid);
+ _app_setexplicitaccess (&ea[count++], OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, GRANT_ACCESS, 0xE0000000, config.builtin_netops_sid);
}
if (config.service_mpssvc_sid)
{
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- FWPM_GENERIC_ALL | DELETE,
- NO_INHERITANCE,
- config.service_mpssvc_sid->buffer
- );
-
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- 0xE0000000,
- OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE,
- config.service_mpssvc_sid->buffer
- );
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, (PSID)config.service_mpssvc_sid->buffer);
+ _app_setexplicitaccess (&ea[count++], OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, GRANT_ACCESS, 0xE0000000, (PSID)config.service_mpssvc_sid->buffer);
}
if (config.service_nlasvc_sid)
{
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- FWPM_GENERIC_READ | FWPM_GENERIC_EXECUTE,
- NO_INHERITANCE,
- config.service_nlasvc_sid->buffer
- );
-
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- 0xA0000000,
- OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE,
- config.service_nlasvc_sid->buffer
- );
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, GRANT_ACCESS, FWPM_GENERIC_READ | FWPM_GENERIC_EXECUTE, (PSID)config.service_nlasvc_sid->buffer);
+ _app_setexplicitaccess (&ea[count++], OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, GRANT_ACCESS, 0xA0000000, (PSID)config.service_nlasvc_sid->buffer);
}
if (config.service_policyagent_sid)
{
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- FWPM_GENERIC_ALL | DELETE,
- NO_INHERITANCE,
- config.service_policyagent_sid->buffer
- );
-
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- 0xE0000000,
- OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE,
- config.service_policyagent_sid->buffer
- );
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, (PSID)config.service_policyagent_sid->buffer);
+ _app_setexplicitaccess (&ea[count++], OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, GRANT_ACCESS, 0xE0000000, (PSID)config.service_policyagent_sid->buffer);
}
if (config.service_rpcss_sid)
{
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- FWPM_GENERIC_ALL | DELETE,
- NO_INHERITANCE,
- config.service_rpcss_sid->buffer
- );
-
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- 0xE0000000,
- OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE,
- config.service_rpcss_sid->buffer
- );
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, (PSID)config.service_rpcss_sid->buffer);
+ _app_setexplicitaccess (&ea[count++], OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, GRANT_ACCESS, 0xE0000000, (PSID)config.service_rpcss_sid->buffer);
}
if (config.service_wdiservicehost_sid)
{
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- FWPM_GENERIC_READ | FWPM_GENERIC_EXECUTE,
- NO_INHERITANCE,
- config.service_wdiservicehost_sid->buffer
- );
-
- _app_setexplicitaccess (
- &ea[count++],
- GRANT_ACCESS,
- 0xA0000000,
- OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE,
- config.service_wdiservicehost_sid->buffer
- );
+ _app_setexplicitaccess (&ea[count++], NO_INHERITANCE, GRANT_ACCESS, FWPM_GENERIC_READ | FWPM_GENERIC_EXECUTE, (PSID)config.service_wdiservicehost_sid->buffer);
+ _app_setexplicitaccess (&ea[count++], OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, GRANT_ACCESS, 0xA0000000, (PSID)config.service_wdiservicehost_sid->buffer);
}
- _app_setexplicitaccess (
- &ea[count++],
- SET_ACCESS,
- FWPM_ACTRL_CLASSIFY | FWPM_ACTRL_OPEN,
- OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE,
- &SeEveryoneSid
- );
+ _app_setexplicitaccess (&ea[count++], OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE, SET_ACCESS, FWPM_ACTRL_BEGIN_READ_TXN | FWPM_ACTRL_CLASSIFY | FWPM_ACTRL_OPEN | FWPM_ACTRL_SUBSCRIBE, &SeEveryoneSid);
}
status = SetEntriesInAclW (count, ea, dacl, &new_dacl);
@@ -410,53 +300,34 @@ VOID _app_setprovidersecurity (
)
{
PSECURITY_DESCRIPTOR security_descriptor;
- PSID sid_owner;
- PSID sid_group;
- PACL dacl;
- PACL sacl;
- PACL new_dacl;
+ PSID sid_group, sid_owner;
+ PACL dacl, sacl, new_dacl;
ULONG status;
- status = FwpmProviderGetSecurityInfoByKey0 (
- hengine,
- provider_guid,
- DACL_SECURITY_INFORMATION,
- &sid_owner,
- &sid_group,
- &dacl,
- &sacl,
- &security_descriptor
- );
+ status = FwpmProviderGetSecurityInfoByKey0 (hengine, provider_guid, DACL_SECURITY_INFORMATION, &sid_owner, &sid_group, &dacl, &sacl, &security_descriptor);
- if (status != ERROR_SUCCESS)
+ if (status == ERROR_SUCCESS)
{
- _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmProviderGetSecurityInfoByKey0", status, NULL);
-
- return;
- }
-
- if (dacl)
- {
- new_dacl = _app_createaccesscontrollist (dacl, is_secure);
-
- if (new_dacl)
+ if (dacl)
{
- status = FwpmProviderSetSecurityInfoByKey0 (
- hengine,
- provider_guid,
- OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
- (PCSID)config.builtin_admins_sid,
- NULL,
- new_dacl,
- NULL
- );
+ new_dacl = _app_createaccesscontrollist (dacl, is_secure);
- if (status != ERROR_SUCCESS)
- _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmProviderSetSecurityInfoByKey0", status, NULL);
+ if (new_dacl)
+ {
+ status = FwpmProviderSetSecurityInfoByKey0 (hengine, provider_guid, OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, (PCSID)config.builtin_admins_sid, NULL, new_dacl, NULL);
- LocalFree (new_dacl);
+ if (status != ERROR_SUCCESS)
+ _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmProviderSetSecurityInfoByKey0", status, NULL);
+
+ LocalFree (new_dacl);
+ }
}
}
+ else
+ {
+ //if (status != FWP_E_PROVIDER_NOT_FOUND)
+ _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmProviderGetSecurityInfoByKey0", status, NULL);
+ }
if (security_descriptor)
FwpmFreeMemory0 ((PVOID_PTR)&security_descriptor);
@@ -469,53 +340,34 @@ VOID _app_setsublayersecurity (
)
{
PSECURITY_DESCRIPTOR security_descriptor;
- PSID sid_owner;
- PSID sid_group;
- PACL dacl;
- PACL sacl;
- PACL new_dacl;
+ PSID sid_group, sid_owner;
+ PACL dacl, sacl, new_dacl;
ULONG status;
- status = FwpmSubLayerGetSecurityInfoByKey0 (
- hengine,
- sublayer_guid,
- DACL_SECURITY_INFORMATION,
- &sid_owner,
- &sid_group,
- &dacl,
- &sacl,
- &security_descriptor
- );
+ status = FwpmSubLayerGetSecurityInfoByKey0 (hengine, sublayer_guid, DACL_SECURITY_INFORMATION, &sid_owner, &sid_group, &dacl, &sacl, &security_descriptor);
- if (status != ERROR_SUCCESS)
+ if (status == ERROR_SUCCESS)
{
- _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmSubLayerGetSecurityInfoByKey0", status, NULL);
-
- return;
- }
-
- if (dacl)
- {
- new_dacl = _app_createaccesscontrollist (dacl, is_secure);
-
- if (new_dacl)
+ if (dacl)
{
- status = FwpmSubLayerSetSecurityInfoByKey0 (
- hengine,
- sublayer_guid,
- OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
- (PCSID)config.builtin_admins_sid,
- NULL,
- new_dacl,
- NULL
- );
+ new_dacl = _app_createaccesscontrollist (dacl, is_secure);
- if (status != ERROR_SUCCESS)
- _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmSubLayerSetSecurityInfoByKey0", status, NULL);
+ if (new_dacl)
+ {
+ status = FwpmSubLayerSetSecurityInfoByKey0 (hengine, sublayer_guid, OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, (PCSID)config.builtin_admins_sid, NULL, new_dacl, NULL);
- LocalFree (new_dacl);
+ if (status != ERROR_SUCCESS)
+ _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmSubLayerSetSecurityInfoByKey0", status, NULL);
+
+ LocalFree (new_dacl);
+ }
}
}
+ else
+ {
+ //if (status != FWP_E_SUBLAYER_NOT_FOUND)
+ _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmSubLayerGetSecurityInfoByKey0", status, NULL);
+ }
if (security_descriptor)
FwpmFreeMemory0 ((PVOID_PTR)&security_descriptor);
@@ -528,54 +380,34 @@ VOID _app_setcalloutsecurity (
)
{
PSECURITY_DESCRIPTOR security_descriptor;
- PSID sid_owner;
- PSID sid_group;
- PACL dacl;
- PACL sacl;
- PACL new_dacl;
+ PSID sid_group, sid_owner;
+ PACL dacl, sacl, new_dacl;
ULONG status;
- status = FwpmCalloutGetSecurityInfoByKey0 (
- hengine,
- callout_guid,
- DACL_SECURITY_INFORMATION,
- &sid_owner,
- &sid_group,
- &dacl,
- &sacl,
- &security_descriptor
- );
+ status = FwpmCalloutGetSecurityInfoByKey0 (hengine, callout_guid, DACL_SECURITY_INFORMATION, &sid_owner, &sid_group, &dacl, &sacl, &security_descriptor);
- if (status != ERROR_SUCCESS)
+ if (status == ERROR_SUCCESS)
{
- if (status != FWP_E_CALLOUT_NOT_FOUND)
- _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmCalloutGetSecurityInfoByKey0", status, NULL);
-
- return;
- }
-
- if (dacl)
- {
- new_dacl = _app_createaccesscontrollist (dacl, is_secure);
-
- if (new_dacl)
+ if (dacl)
{
- status = FwpmCalloutSetSecurityInfoByKey0 (
- hengine,
- callout_guid,
- OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
- (PCSID)config.builtin_admins_sid,
- NULL,
- new_dacl,
- NULL
- );
+ new_dacl = _app_createaccesscontrollist (dacl, is_secure);
- if (status != ERROR_SUCCESS)
- _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmCalloutSetSecurityInfoByKey0", status, NULL);
+ if (new_dacl)
+ {
+ status = FwpmCalloutSetSecurityInfoByKey0 (hengine, callout_guid, OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, (PCSID)config.builtin_admins_sid, NULL, new_dacl, NULL);
- LocalFree (new_dacl);
+ if (status != ERROR_SUCCESS)
+ _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmCalloutSetSecurityInfoByKey0", status, NULL);
+
+ LocalFree (new_dacl);
+ }
}
}
+ else
+ {
+ //if (status != FWP_E_CALLOUT_NOT_FOUND)
+ _r_log (LOG_LEVEL_ERROR, NULL, L"FwpmCalloutGetSecurityInfoByKey0", status, NULL);
+ }
if (security_descriptor)
FwpmFreeMemory0 ((PVOID_PTR)&security_descriptor);
@@ -590,11 +422,8 @@ VOID _app_setfiltersecurity (
)
{
PSECURITY_DESCRIPTOR security_descriptor;
- PSID sid_owner;
- PSID sid_group;
- PACL dacl;
- PACL sacl;
- PACL new_dacl;
+ PSID sid_group, sid_owner;
+ PACL dacl, sacl, new_dacl;
ULONG status;
status = FwpmFilterGetSecurityInfoByKey0 (hengine, filter_guid, DACL_SECURITY_INFORMATION, &sid_owner, &sid_group, &dacl, &sacl, &security_descriptor);
diff --git a/src/security.h b/src/security.h
index 7bde2859..8fd9c548 100644
--- a/src/security.h
+++ b/src/security.h
@@ -18,9 +18,9 @@ PACL _app_createaccesscontrollist (
VOID _app_setexplicitaccess (
_Out_ PEXPLICIT_ACCESS ea,
+ _In_ ULONG inheritance,
_In_ ACCESS_MODE mode,
_In_ ULONG rights,
- _In_ ULONG inheritance,
_In_opt_ PSID sid
);
diff --git a/src/timer.c b/src/timer.c
index b88a11d3..245c9176 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2016-2024 Henry++
+// Copyright (c) 2016-2026 Henry++
#include "global.h"
@@ -41,9 +41,9 @@ VOID _app_timer_set (
_In_ LONG64 seconds
)
{
- PTP_TIMER htimer;
- FILETIME file_time;
LARGE_INTEGER timestamp;
+ FILETIME file_time;
+ PTP_TIMER htimer;
LONG64 current_time;
BOOLEAN is_created = FALSE;
NTSTATUS status;
@@ -78,12 +78,23 @@ VOID _app_timer_set (
is_created = TRUE;
}
+ else
+ {
+ if (hwnd)
+ {
+ _r_show_errormessage (hwnd, L"Could not allocate timer!", status, NULL, ET_NATIVE);
+ }
+ else
+ {
+ _r_log (LOG_LEVEL_ERROR, NULL, L"TpAllocTimer", status, NULL);
+ }
+ }
}
if (is_created)
{
ptr_app->is_enabled = TRUE;
- ptr_app->timer = current_time + seconds;
+ ptr_app->timer = (current_time + seconds);
}
else
{
@@ -126,19 +137,18 @@ VOID _app_timer_remove (
TpReleaseTimer (current_timer);
}
-VOID CALLBACK _app_timer_callback (
+VOID NTAPI _app_timer_callback (
_Inout_ PTP_CALLBACK_INSTANCE instance,
_Inout_opt_ PVOID context,
_Inout_ PTP_TIMER timer
)
{
- HANDLE hengine;
- HWND hwnd;
+ WCHAR buffer[0x100];
+ PR_STRING display_name;
PITEM_APP ptr_app;
PR_LIST rules;
- PR_STRING string;
- WCHAR buffer[256];
- ULONG icon_id;
+ HWND hwnd;
+ ULONG icon_id = NIIF_INFO;
HRESULT status;
ptr_app = _app_getappitem (PtrToUlong (context));
@@ -152,44 +162,35 @@ VOID CALLBACK _app_timer_callback (
_app_timer_reset (hwnd, ptr_app);
- hengine = _wfp_getenginehandle ();
-
- rules = _r_obj_createlist (2, NULL);
+ rules = _r_obj_createlist (0x01, NULL);
_r_obj_addlistitem (rules, ptr_app, NULL);
- _wfp_create3filters (hengine, rules, DBG_ARG, FALSE);
+ _wfp_createappfilters (_wfp_getenginehandle (), rules, DBG_ARG, FALSE);
- _app_listview_updateby_id (hwnd, ptr_app->type, PR_UPDATE_TYPE | PR_UPDATE_FORCE);
-
- _r_obj_dereference (ptr_app);
- _r_obj_dereference (rules);
+ if (hwnd)
+ _app_listview_updateby_id (hwnd, ptr_app->type, PR_UPDATE_TYPE | PR_UPDATE_FORCE);
_app_profile_save (hwnd);
if (_r_config_getboolean (L"IsNotificationsTimer", TRUE, NULL))
{
- icon_id = NIIF_INFO;
-
if (!_r_config_getboolean (L"IsNotificationsSound", TRUE, NULL))
icon_id |= NIIF_NOSOUND;
- string = _app_getappdisplayname (ptr_app, TRUE);
+ display_name = _app_getappdisplayname (ptr_app, TRUE);
- _r_str_printf (
- buffer,
- RTL_NUMBER_OF (buffer),
- L"%s - %s",
- _r_app_getname (),
- _r_obj_getstringorempty (string)
- );
+ _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"%s - %s", _r_app_getname (), _r_obj_getstringordefault (display_name, L""));
_r_tray_popup (hwnd, &GUID_TrayIcon, icon_id, buffer, _r_locale_getstring (IDS_STATUS_TIMER_DONE));
- if (string)
- _r_obj_dereference (string);
+ if (display_name)
+ _r_obj_dereference (display_name);
}
if (status == S_OK || status == S_FALSE)
CoUninitialize ();
+
+ _r_obj_dereference (ptr_app);
+ _r_obj_dereference (rules);
}
diff --git a/src/timer.h b/src/timer.h
index b3143fae..379595a9 100644
--- a/src/timer.h
+++ b/src/timer.h
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2016-2024 Henry++
+// Copyright (c) 2016-2026 Henry++
#pragma once
@@ -24,7 +24,7 @@ VOID _app_timer_remove (
_Inout_ PITEM_APP ptr_app
);
-VOID CALLBACK _app_timer_callback (
+VOID NTAPI _app_timer_callback (
_Inout_ PTP_CALLBACK_INSTANCE instance,
_Inout_opt_ PVOID context,
_Inout_ PTP_TIMER timer
diff --git a/src/uwp.cpp b/src/uwp.cpp
index e0baff2b..f67a9342 100644
--- a/src/uwp.cpp
+++ b/src/uwp.cpp
@@ -1,5 +1,5 @@
// simplewall
-// Copyright (c) 2022-2024 Henry++
+// Copyright (c) 2022-2026 Henry++
#include "routine.h"
@@ -15,14 +15,13 @@
_Success_ (return)
BOOLEAN _app_uwp_loadpackageinfo (
_In_ PR_STRING package_name,
- _Inout_ PR_STRING_PTR name_ptr,
- _Inout_ PR_STRING_PTR path_ptr
+ _Inout_ PR_STRING_PTR out_name,
+ _Inout_ PR_STRING_PTR out_path
)
{
+ winrt::Windows::ApplicationModel::PackageStatus package_status = 0;
winrt::Windows::ApplicationModel::Package package = NULL;
- winrt::Windows::ApplicationModel::PackageStatus status = 0;
- winrt::hstring display_name;
- winrt::hstring path;
+ winrt::hstring display_name, path;
package = winrt::Windows::Management::Deployment::PackageManager{}.FindPackage (package_name->buffer);
@@ -31,9 +30,9 @@ BOOLEAN _app_uwp_loadpackageinfo (
if (_r_sys_isosversiongreaterorequal (WINDOWS_10))
{
- status = package.Status ();
+ package_status = package.Status ();
- if (status.Disabled () || status.NotAvailable ())
+ if (package_status.Disabled () || package_status.NotAvailable ())
return FALSE;
}
@@ -45,18 +44,18 @@ BOOLEAN _app_uwp_loadpackageinfo (
if (display_name.empty ())
{
- *name_ptr = _r_obj_createstring2 (&package_name->sr);
+ *out_name = _r_obj_createstring2 (&package_name->sr);
}
else
{
- if (display_name == L"1527c705-839a-4832-9118-54d4Bd6a0c89")
+ if (_r_str_compare (display_name.c_str (), L"1527C705-839A-4832-9118-54D4BD6A0C89", TRUE) == 0)
display_name = L"File Picker"; // HACK!!!
- *name_ptr = _r_obj_createstring_ex (display_name.c_str (), display_name.size () * sizeof (WCHAR));
+ *out_name = _r_obj_createstring_ex (display_name.c_str (), display_name.size () * sizeof (WCHAR));
}
if (!path.empty ())
- *path_ptr = _r_obj_createstring_ex (path.c_str (), path.size () * sizeof (WCHAR));
+ *out_path = _r_obj_createstring_ex (path.c_str (), path.size () * sizeof (WCHAR));
return TRUE;
}
@@ -64,25 +63,21 @@ BOOLEAN _app_uwp_loadpackageinfo (
_Success_ (return)
BOOLEAN _app_uwp_getpackageinfo (
_In_ PR_STRING package_name,
- _Out_ PR_STRING_PTR name_ptr,
- _Out_ PR_STRING_PTR path_ptr
+ _Out_ PR_STRING_PTR out_name,
+ _Out_ PR_STRING_PTR out_path
)
{
- BOOLEAN status = FALSE;
-
- *name_ptr = NULL;
- *path_ptr = NULL;
+ *out_name = NULL;
+ *out_path = NULL;
__try
{
- status = _app_uwp_loadpackageinfo (package_name, name_ptr, path_ptr);
+ return _app_uwp_loadpackageinfo (package_name, out_name, out_path);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
- *name_ptr = _r_obj_createstring2 (&package_name->sr);
+ *out_name = _r_obj_createstring2 (&package_name->sr);
return TRUE;
}
-
- return status;
}
diff --git a/src/uwp.h b/src/uwp.h
index c9f17e0e..86d190f5 100644
--- a/src/uwp.h
+++ b/src/uwp.h
@@ -1,27 +1,22 @@
// simplewall
-// Copyright (c) 2022-2024 Henry++
+// Copyright (c) 2022-2026 Henry++
#pragma once
-#ifdef __cplusplus
-extern "C"
-{
-#endif
+EXTERN_C_START
_Success_ (return)
BOOLEAN _app_uwp_loadpackageinfo (
_In_ PR_STRING package_name,
- _Inout_ PR_STRING_PTR name_ptr,
- _Inout_ PR_STRING_PTR path_ptr
+ _Inout_ PR_STRING_PTR out_name,
+ _Inout_ PR_STRING_PTR out_path
);
_Success_ (return)
BOOLEAN _app_uwp_getpackageinfo (
_In_ PR_STRING package_name,
- _Out_ PR_STRING_PTR name_ptr,
- _Out_ PR_STRING_PTR path_ptr
+ _Out_ PR_STRING_PTR out_name,
+ _Out_ PR_STRING_PTR out_path
);
-#ifdef __cplusplus
-}
-#endif
+EXTERN_C_END
diff --git a/src/wfp.c b/src/wfp.c
index ab8df229..aeb134a7 100644
--- a/src/wfp.c
+++ b/src/wfp.c
@@ -3,6 +3,68 @@
#include "global.h"
+// there is russian documentation on how WFP works:
+// https://www.cyberforum.ru/drivers-programming/thread1298567.html
+HANDLE _wfp_getenginehandle ()
+{
+ static R_INITONCE init_once = PR_INITONCE_INIT;
+ static HANDLE hengine = NULL;
+
+ FWPM_SESSION0 session;
+ ULONG attempts = 6;
+ ULONG status;
+
+ if (_r_initonce_begin (&init_once))
+ {
+ _r_math_generateguid (&config.session_key);
+
+ do
+ {
+ RtlZeroMemory (&session, sizeof (FWPM_SESSION0));
+
+ session.displayData.name = _r_app_getname ();
+ session.displayData.description = _r_app_getname ();
+ session.sessionKey = config.session_key;
+ session.txnWaitTimeoutInMSec = TRANSACTION_TIMEOUT;
+
+ status = FwpmEngineOpen0 (NULL, RPC_C_AUTHN_DEFAULT, NULL, &session, &hengine);
+
+ if (status == ERROR_SUCCESS)
+ {
+ break;
+ }
+ else
+ {
+ // this error says that BFE service is not in the running state, so we wait! (issue #1043)
+ if (status == EPT_S_NOT_REGISTERED)
+ {
+ if (attempts != 0)
+ {
+ _r_sys_sleep (500);
+
+ attempts -= 1;
+
+ continue;
+ }
+ }
+
+ _r_show_errormessage (_r_app_gethwnd (), L"WFP engine initialization failed! Try again later.", status, NULL, ET_WINDOWS);
+
+ _r_log (LOG_LEVEL_CRITICAL, NULL, L"FwpmEngineOpen0", status, NULL);
+
+ NtTerminateProcess (NtCurrentProcess (), status);
+
+ break;
+ }
+ }
+ while (--attempts);
+
+ _r_initonce_end (&init_once);
+ }
+
+ return hengine;
+}
+
BOOLEAN _wfp_isfiltersapplying ()
{
return _r_queuedlock_islocked (&lock_apply) || _r_queuedlock_islocked (&lock_transaction);
@@ -68,73 +130,7 @@ ENUM_INSTALL_TYPE _wfp_issublayerinstalled (
BOOLEAN _wfp_isfiltersinstalled ()
{
- ENUM_INSTALL_TYPE install_type;
-
- install_type = _wfp_getinstalltype ();
-
- return (install_type != INSTALL_DISABLED);
-}
-
-HANDLE _wfp_getenginehandle ()
-{
- static R_INITONCE init_once = PR_INITONCE_INIT;
- static HANDLE engine_handle = NULL;
-
- FWPM_SESSION0 session;
- ULONG attempts = 6;
- ULONG status;
-
- if (_r_initonce_begin (&init_once))
- {
- _r_math_generateguid (&config.session_key);
-
- do
- {
- RtlZeroMemory (&session, sizeof (FWPM_SESSION0));
-
- session.displayData.name = _r_app_getname ();
- session.displayData.description = _r_app_getname ();
-
- session.sessionKey = config.session_key;
-
- session.txnWaitTimeoutInMSec = TRANSACTION_TIMEOUT;
-
- status = FwpmEngineOpen0 (NULL, RPC_C_AUTHN_WINNT, NULL, &session, &engine_handle);
-
- if (status == ERROR_SUCCESS)
- {
- break;
- }
- else
- {
- if (status == EPT_S_NOT_REGISTERED)
- {
- // The error say that BFE service is not in the running state, so we wait.
- if (attempts)
- {
- _r_sys_sleep (500);
-
- attempts -= 1;
-
- continue;
- }
- }
-
- _r_show_errormessage (_r_app_gethwnd (), L"WFP engine initialization failed! Try again later.", status, NULL, ET_WINDOWS);
-
- _r_log (LOG_LEVEL_CRITICAL, NULL, L"FwpmEngineOpen0", status, NULL);
-
- NtTerminateProcess (NtCurrentProcess (), status);
-
- break;
- }
- }
- while (--attempts);
-
- _r_initonce_end (&init_once);
- }
-
- return engine_handle;
+ return (_wfp_getinstalltype () != INSTALL_DISABLED);
}
ENUM_INSTALL_TYPE _wfp_getinstalltype ()
@@ -142,8 +138,9 @@ ENUM_INSTALL_TYPE _wfp_getinstalltype ()
return _wfp_isproviderinstalled (_wfp_getenginehandle ());
}
+_Ret_maybenull_
PR_STRING _wfp_getlayername (
- _In_ LPGUID layer_guid
+ _In_ LPCGUID layer_guid
)
{
LPCGUID layer_guids[] = {
@@ -192,10 +189,10 @@ PR_STRING _wfp_getlayername (
PR_STRINGREF_INIT (L"FWPM_LAYER_OUTBOUND_ICMP_ERROR_V6"),
};
- C_ASSERT (RTL_NUMBER_OF (layer_guids) == RTL_NUMBER_OF (layer_names));
-
PR_STRING string;
+ C_ASSERT (RTL_NUMBER_OF (layer_guids) == RTL_NUMBER_OF (layer_names));
+
for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (layer_guids); i++)
{
if (IsEqualGUID (layer_guid, layer_guids[i]))
@@ -214,13 +211,10 @@ BOOLEAN _wfp_initialize (
{
FWPM_PROVIDER0 provider;
FWPM_SUBLAYER0 sublayer;
- FWP_VALUE0* fwp_query = NULL;
- FWP_VALUE0 val;
+ FWP_VALUE0 *fwp_query = NULL, val;
+ BOOLEAN is_intransact, is_providerexist, is_sublayerexist;
BOOLEAN is_success = TRUE; // already initialized
- BOOLEAN is_providerexist;
- BOOLEAN is_sublayerexist;
- BOOLEAN is_intransact;
- LONG status;
+ ULONG status;
_r_queuedlock_acquireshared (&lock_transaction);
@@ -241,7 +235,6 @@ BOOLEAN _wfp_initialize (
provider.displayData.name = _r_app_getname ();
provider.displayData.description = _r_app_getname ();
-
provider.providerKey = GUID_WfpProvider;
if (!config.is_filterstemporary)
@@ -277,12 +270,9 @@ BOOLEAN _wfp_initialize (
sublayer.displayData.name = _r_app_getname ();
sublayer.displayData.description = _r_app_getname ();
-
sublayer.providerKey = (LPGUID)&GUID_WfpProvider;
sublayer.subLayerKey = GUID_WfpSublayer;
-
- // highest weight for UINT16
- sublayer.weight = (UINT16)_r_config_getlong (L"SublayerWeight", FW_SUBLAYER_WEIGHT, NULL);
+ sublayer.weight = (UINT16)_r_config_getlong (L"SublayerWeight", FWW_SUBLAYER, NULL);
if (!config.is_filterstemporary)
sublayer.flags = FWPM_SUBLAYER_FLAG_PERSISTENT;
@@ -317,11 +307,8 @@ BOOLEAN _wfp_initialize (
}
}
- // set provider security information
- _app_setprovidersecurity (engine_handle, &GUID_WfpProvider, TRUE);
-
- // set sublayer security information
- _app_setsublayersecurity (engine_handle, &GUID_WfpSublayer, TRUE);
+ _app_setprovidersecurity (engine_handle, &GUID_WfpProvider, TRUE); // set provider security information
+ _app_setsublayersecurity (engine_handle, &GUID_WfpSublayer, TRUE); // set sublayer security information
// dropped packets logging (win7+)
if (!config.is_neteventset)
@@ -365,30 +352,22 @@ BOOLEAN _wfp_initialize (
if (config.is_neteventset)
{
_wfp_logsetoption (engine_handle);
-
_wfp_logsubscribe (hwnd, engine_handle);
}
}
- // packet queuing (win8+)
- if (_r_sys_isosversiongreaterorequal (WINDOWS_8))
+ // enables inbound or forward packet queuing independently. when enabled, the system is able to evenly distribute cpu load to multiple cpus for site-to-site ipsec tunnel scenarios. (win8+)
+ if (_r_sys_isosversiongreaterorequal (WINDOWS_8) && _r_config_getboolean (L"IsPacketQueuingEnabled", TRUE, NULL))
{
- if (_r_config_getboolean (L"IsPacketQueuingEnabled", TRUE, NULL))
- {
- // Enables inbound or forward packet queuing independently.
- // when enabled, the system is able to evenly distribute cpu load
- // to multiple cpus for site-to-site ipsec tunnel scenarios.
+ RtlZeroMemory (&val, sizeof (FWP_VALUE0));
- RtlZeroMemory (&val, sizeof (FWP_VALUE0));
+ val.type = FWP_UINT32;
+ val.uint32 = FWPM_ENGINE_OPTION_PACKET_QUEUE_INBOUND | FWPM_ENGINE_OPTION_PACKET_QUEUE_FORWARD;
- val.type = FWP_UINT32;
- val.uint32 = FWPM_ENGINE_OPTION_PACKET_QUEUE_INBOUND | FWPM_ENGINE_OPTION_PACKET_QUEUE_FORWARD;
+ status = FwpmEngineSetOption0 (engine_handle, FWPM_ENGINE_PACKET_QUEUING, &val);
- status = FwpmEngineSetOption0 (engine_handle, FWPM_ENGINE_PACKET_QUEUING, &val);
-
- if (status != ERROR_SUCCESS)
- _r_log (LOG_LEVEL_WARNING, NULL, L"FwpmEngineSetOption0", status, L"FWPM_ENGINE_PACKET_QUEUING");
- }
+ if (status != ERROR_SUCCESS)
+ _r_log (LOG_LEVEL_WARNING, NULL, L"FwpmEngineSetOption0", status, L"FWPM_ENGINE_PACKET_QUEUING");
}
CleanupExit:
@@ -405,8 +384,8 @@ VOID _wfp_uninitialize (
{
PR_ARRAY callouts;
PR_STRING string;
- LPCGUID guid;
FWP_VALUE0 val;
+ LPCGUID guid;
BOOLEAN is_intransact;
ULONG status;
@@ -436,7 +415,7 @@ VOID _wfp_uninitialize (
status = _wfp_dumpcallouts (engine_handle, &GUID_WfpProvider, &callouts);
- if (status == ERROR_SUCCESS && callouts)
+ if (status == ERROR_SUCCESS)
{
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (callouts); i++)
{
@@ -461,11 +440,11 @@ VOID _wfp_uninitialize (
status = FwpmCalloutDeleteByKey0 (engine_handle, guid);
- if (status != ERROR_SUCCESS)
+ if (status != ERROR_SUCCESS && status != FWP_E_CALLOUT_NOT_FOUND)
{
_r_str_fromguid (&string, guid, TRUE);
- _r_log (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmCalloutDeleteByKey0", status, _r_obj_getstring (string));
+ _r_log (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmCalloutDeleteByKey0", status, _r_obj_getstringordefault (string, L""));
if (string)
_r_obj_dereference (string);
@@ -499,12 +478,11 @@ VOID _wfp_installfilters (
_In_ HANDLE engine_handle
)
{
- // dump all filters into array
- PR_ARRAY guids;
- PR_LIST rules;
- LPGUID guid;
PITEM_APP ptr_app = NULL;
PITEM_RULE ptr_rule;
+ PR_ARRAY guids;
+ PR_LIST rules;
+ LPCGUID guid;
ULONG_PTR enum_key = 0;
BOOLEAN is_intransact;
ULONG status;
@@ -524,7 +502,7 @@ VOID _wfp_installfilters (
{
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
{
- guid = (LPGUID)_r_obj_getarrayitem (guids, i);
+ guid = (LPCGUID)_r_obj_getarrayitem (guids, i);
if (guid)
_app_setfiltersecurity (engine_handle, guid, FALSE, DBG_ARG);
@@ -538,16 +516,16 @@ VOID _wfp_installfilters (
{
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
{
- guid = (LPGUID)_r_obj_getarrayitem (guids, i);
+ guid = (LPCGUID)_r_obj_getarrayitem (guids, i);
if (guid)
- _wfp_deletefilter (engine_handle, guid);
+ _wfp_deletefilter (engine_handle, guid, DBG_ARG);
}
_r_obj_dereference (guids);
}
- rules = _r_obj_createlist (10, &_r_obj_dereference);
+ rules = _r_obj_createlist (0x10, &_r_obj_dereference);
// apply apps rules
_r_queuedlock_acquireshared (&lock_apps);
@@ -562,7 +540,7 @@ VOID _wfp_installfilters (
if (!_r_obj_isempty2 (rules))
{
- _wfp_create3filters (engine_handle, rules, DBG_ARG, is_intransact);
+ _wfp_createappfilters (engine_handle, rules, DBG_ARG, is_intransact);
_r_obj_clearlist (rules);
}
@@ -572,26 +550,23 @@ VOID _wfp_installfilters (
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
- if (ptr_rule)
- {
- if (ptr_rule->is_enabled)
- _r_obj_addlistitem (rules, _r_obj_reference (ptr_rule), NULL);
- }
+ if (ptr_rule && ptr_rule->is_enabled)
+ _r_obj_addlistitem (rules, _r_obj_reference (ptr_rule), NULL);
}
_r_queuedlock_releaseshared (&lock_rules);
if (!_r_obj_isempty2 (rules))
{
- _wfp_create4filters (engine_handle, rules, DBG_ARG, is_intransact);
+ _wfp_createrulefilters (engine_handle, rules, DBG_ARG, is_intransact);
_r_obj_clearlist (rules);
}
// apply internal rules
- _wfp_create2filters (engine_handle, DBG_ARG, is_intransact);
+ _wfp_createglobalfilters (engine_handle, DBG_ARG, is_intransact);
if (is_intransact)
_wfp_transact_commit (engine_handle, DBG_ARG);
@@ -603,7 +578,7 @@ VOID _wfp_installfilters (
{
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
{
- guid = (LPGUID)_r_obj_getarrayitem (guids, i);
+ guid = (LPCGUID)_r_obj_getarrayitem (guids, i);
if (guid)
_app_setfiltersecurity (engine_handle, guid, TRUE, DBG_ARG);
@@ -667,7 +642,9 @@ BOOLEAN _wfp_transact_commit (
BOOLEAN _wfp_deletefilter (
_In_ HANDLE engine_handle,
- _In_ LPCGUID filter_id
+ _In_ LPCGUID filter_id,
+ _In_ LPCWSTR file_name,
+ _In_ ULONG line
)
{
PR_STRING string;
@@ -679,7 +656,7 @@ BOOLEAN _wfp_deletefilter (
{
_r_str_fromguid (&string, filter_id, TRUE);
- _r_log (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmFilterDeleteByKey0", status, _r_obj_getstringordefault (string, L""));
+ _r_log_v (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmFilterDeleteByKey0", status, L"%s:%d (%s)", DBG_ARG_VAR, _r_obj_getstringordefault (string, L""));
if (string)
_r_obj_dereference (string);
@@ -690,6 +667,7 @@ BOOLEAN _wfp_deletefilter (
return TRUE;
}
+_Ret_maybenull_
FORCEINLINE static LPCWSTR _wfp_filtertypetostring (
_In_ ENUM_TYPE_DATA filter_type
)
@@ -734,39 +712,11 @@ FORCEINLINE static LPCWSTR _wfp_filtertypetostring (
}
}
-ULONG _wfp_createcallout (
- _In_ HANDLE engine_handle,
- _In_ LPCGUID layer_key,
- _In_ LPCGUID callout_key
-)
-{
- FWPM_CALLOUT0 callout = {0};
- ULONG status;
-
- callout.displayData.name = _r_app_getname ();
- callout.displayData.description = _r_app_getname ();
-
- if (!config.is_filterstemporary)
- callout.flags = FWPM_CALLOUT_FLAG_PERSISTENT;
-
- callout.providerKey = (LPGUID)&GUID_WfpProvider;
-
- RtlCopyMemory (&callout.calloutKey, callout_key, sizeof (GUID));
- RtlCopyMemory (&callout.applicableLayer, layer_key, sizeof (GUID));
-
- status = FwpmCalloutAdd0 (engine_handle, &callout, NULL, NULL);
-
- if (status != ERROR_SUCCESS && status != FWP_E_ALREADY_EXISTS)
- _r_log (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmCalloutAdd0", status, NULL);
-
- return status;
-}
-
ULONG _wfp_createfilter (
_In_ HANDLE engine_handle,
_In_ ENUM_TYPE_DATA type,
_In_opt_ LPCWSTR filter_name,
- _In_reads_ (count) FWPM_FILTER_CONDITION0 *lpcond,
+ _In_reads_opt_ (count) FWPM_FILTER_CONDITION0 *lpcond,
_In_ UINT32 count,
_In_ LPCGUID layer_id,
_In_opt_ LPCGUID callout_id,
@@ -777,13 +727,13 @@ ULONG _wfp_createfilter (
)
{
FWPM_FILTER0 filter = {0};
- WCHAR filter_description[128];
+ WCHAR filter_description[0x80];
PR_STRING layer_name;
LPCWSTR filter_type;
UINT64 filter_id;
ULONG status;
- // create filter guid
+ // generate filter guid
_r_math_generateguid (&filter.filterKey);
filter_type = _wfp_filtertypetostring (type);
@@ -798,12 +748,12 @@ ULONG _wfp_createfilter (
}
else
{
- _r_str_copy (filter_description, RTL_NUMBER_OF (filter_description), _r_locale_getstring (IDS_STATUS_EMPTY));
+ _r_str_copy (filter_description, RTL_NUMBER_OF (filter_description), L"");
}
- // reset action rights
- if (weight == FW_WEIGHT_HIGHEST_IMPORTANT || action == FWP_ACTION_BLOCK || action == FWP_ACTION_CALLOUT_TERMINATING)
- filter.flags = FWPM_FILTER_FLAG_CLEAR_ACTION_RIGHT;
+ // clear filter action right
+ if ((weight == FWW_IMPORTANT) || (action == FWP_ACTION_BLOCK) || (action == FWP_ACTION_CALLOUT_TERMINATING))
+ filter.flags |= FWPM_FILTER_FLAG_CLEAR_ACTION_RIGHT;
// set filter flags
if ((flags & FWPM_FILTER_FLAG_BOOTTIME) == 0)
@@ -848,9 +798,9 @@ ULONG _wfp_createfilter (
}
else
{
- layer_name = _wfp_getlayername ((LPGUID)layer_id);
+ layer_name = _wfp_getlayername (layer_id);
- _r_log_v (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmFilterAdd0", status, L"%s\\%s", _r_obj_getstring (layer_name), filter.displayData.description);
+ _r_log_v (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmFilterAdd0", status, L"%s\\%s", _r_obj_getstringordefault (layer_name, L""), filter.displayData.description);
if (layer_name)
_r_obj_dereference (layer_name);
@@ -875,8 +825,7 @@ VOID _wfp_clearfilter_ids ()
{
ptr_app->is_haveerrors = FALSE;
- if (ptr_app->guids)
- _r_obj_cleararray (ptr_app->guids);
+ _r_obj_cleararray (ptr_app->guids);
}
_r_queuedlock_releaseshared (&lock_apps);
@@ -886,7 +835,7 @@ VOID _wfp_clearfilter_ids ()
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules_list); i++)
{
- ptr_rule = _r_obj_getlistitem (rules_list, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules_list, i);
if (!ptr_rule)
continue;
@@ -910,9 +859,7 @@ VOID _wfp_destroyfilters (
// destroy all filters
_r_queuedlock_acquireshared (&lock_transaction);
-
status = _wfp_dumpfilters (engine_handle, &GUID_WfpProvider, &guids);
-
_r_queuedlock_releaseshared (&lock_transaction);
if (status != ERROR_SUCCESS)
@@ -925,14 +872,16 @@ VOID _wfp_destroyfilters (
VOID _wfp_destroyfilters_array (
_In_ HANDLE engine_handle,
- _In_ PR_ARRAY guids,
+ _Inout_ PR_ARRAY guids,
_In_ LPCWSTR file_name,
_In_ ULONG line
)
{
- LPGUID guid;
- BOOLEAN is_enabled;
- BOOLEAN is_intransact;
+ LPCGUID guid;
+ BOOLEAN is_enabled, is_intransact;
+
+ if (_r_obj_isempty2 (guids))
+ return;
is_enabled = _app_initinterfacestate (_r_app_gethwnd (), FALSE);
@@ -940,7 +889,7 @@ VOID _wfp_destroyfilters_array (
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
{
- guid = (LPGUID)_r_obj_getarrayitem (guids, i);
+ guid = (LPCGUID)_r_obj_getarrayitem (guids, i);
if (guid)
_app_setfiltersecurity (engine_handle, guid, FALSE, DBG_ARG_VAR);
@@ -950,10 +899,10 @@ VOID _wfp_destroyfilters_array (
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
{
- guid = (LPGUID)_r_obj_getarrayitem (guids, i);
+ guid = (LPCGUID)_r_obj_getarrayitem (guids, i);
if (guid)
- _wfp_deletefilter (engine_handle, guid);
+ _wfp_deletefilter (engine_handle, guid, DBG_ARG_VAR);
}
if (is_intransact)
@@ -962,6 +911,8 @@ VOID _wfp_destroyfilters_array (
_r_queuedlock_releaseshared (&lock_transaction);
_app_restoreinterfacestate (_r_app_gethwnd (), is_enabled);
+
+ _r_obj_cleararray (guids);
}
BOOLEAN _wfp_createrulefilter (
@@ -970,34 +921,26 @@ BOOLEAN _wfp_createrulefilter (
_In_opt_ LPCWSTR filter_name,
_In_opt_ ULONG app_hash,
_In_opt_ PITEM_FILTER_CONFIG filter_config,
- _In_opt_ PR_STRINGREF rule_remote,
- _In_opt_ PR_STRINGREF rule_local,
+ _In_opt_ PCR_STRINGREF rule_remote,
+ _In_opt_ PCR_STRINGREF rule_local,
_In_ UINT8 weight,
_In_ FWP_ACTION_TYPE action,
_In_ UINT32 flags,
_Inout_opt_ PR_ARRAY guids
)
{
- FWPM_FILTER_CONDITION0 fwfc[8] = {0};
- UINT32 count = 0;
- ITEM_ADDRESS address;
- FWP_V4_ADDR_AND_MASK fwp_addr4_and_mask1;
- FWP_V4_ADDR_AND_MASK fwp_addr4_and_mask2;
- FWP_V6_ADDR_AND_MASK fwp_addr6_and_mask1;
- FWP_V6_ADDR_AND_MASK fwp_addr6_and_mask2;
- FWP_RANGE0 fwp_range1;
- FWP_RANGE0 fwp_range2;
+ FWP_V4_ADDR_AND_MASK fwp_addr4_and_mask1, fwp_addr4_and_mask2;
+ FWP_V6_ADDR_AND_MASK fwp_addr6_and_mask1, fwp_addr6_and_mask2;
+ PCR_STRINGREF rules[] = {rule_remote, rule_local};
+ FWPM_FILTER_CONDITION0 fwfc[0x08] = {0};
+ FWP_RANGE0 fwp_range1, fwp_range2;
FWP_BYTE_BLOB *byte_blob = NULL;
PITEM_APP ptr_app = NULL;
FWP_DIRECTION direction;
- UINT8 protocol;
+ ITEM_ADDRESS address;
ADDRESS_FAMILY af;
- PR_STRINGREF rules[] = {
- rule_remote,
- rule_local
- };
- //BOOLEAN is_remoteaddr_set = FALSE;
- //BOOLEAN is_remoteport_set = FALSE;
+ UINT32 count = 0;
+ UINT8 protocol;
BOOLEAN is_success = FALSE;
NTSTATUS status;
@@ -1021,7 +964,7 @@ BOOLEAN _wfp_createrulefilter (
if (!ptr_app)
{
- _r_log_v (LOG_LEVEL_WARNING, NULL, TEXT (__FUNCTION__), STATUS_OBJECT_PATH_NOT_FOUND, L"App \"%" TEXT (PR_ULONG) L"\" was not found!", app_hash);
+ _r_log_v (LOG_LEVEL_WARNING, NULL, TEXT (__FUNCTION__), STATUS_NOT_FOUND, L"App \"%" TEXT (PR_ULONG) L"\" was not found!", app_hash);
goto CleanupExit;
}
@@ -1041,7 +984,7 @@ BOOLEAN _wfp_createrulefilter (
}
else
{
- _r_log (LOG_LEVEL_ERROR, NULL, TEXT (__FUNCTION__), STATUS_OBJECT_PATH_NOT_FOUND, _r_obj_getstring (ptr_app->original_path));
+ _r_log (LOG_LEVEL_ERROR, NULL, TEXT (__FUNCTION__), STATUS_NOT_FOUND, _r_obj_getstring (ptr_app->original_path));
goto CleanupExit;
}
@@ -1050,16 +993,18 @@ BOOLEAN _wfp_createrulefilter (
{
if (ptr_app->bytes)
{
+ //ByteBlobAlloc ((PVOID_PTR)&byte_blob, ptr_app->bytes->buffer, ptr_app->bytes->length);
+
fwfc[count].fieldKey = FWPM_CONDITION_ALE_PACKAGE_ID;
fwfc[count].matchType = FWP_MATCH_EQUAL;
fwfc[count].conditionValue.type = FWP_SID;
- fwfc[count].conditionValue.sid = (PSID)ptr_app->bytes->buffer;
+ fwfc[count].conditionValue.sid = (SID*)ptr_app->bytes->buffer;
count += 1;
}
else
{
- _r_log (LOG_LEVEL_ERROR, NULL, TEXT (__FUNCTION__), STATUS_OBJECT_PATH_NOT_FOUND, _r_obj_getstring (ptr_app->original_path));
+ _r_log (LOG_LEVEL_ERROR, NULL, TEXT (__FUNCTION__), STATUS_NOT_FOUND, _r_obj_getstring (ptr_app->original_path));
goto CleanupExit;
}
@@ -1097,18 +1042,6 @@ BOOLEAN _wfp_createrulefilter (
if (!_app_parserulestring (rules[i], &address))
goto CleanupExit;
- if (i == 0)
- {
- if (address.type == DATA_TYPE_PORT)
- {
- //is_remoteport_set = TRUE;
- }
- else if (address.type == DATA_TYPE_IP)
- {
- //is_remoteaddr_set = TRUE;
- }
- }
-
if (address.is_range)
{
if (address.type == DATA_TYPE_IP)
@@ -1123,31 +1056,17 @@ BOOLEAN _wfp_createrulefilter (
}
else
{
- goto CleanupExit;
+ goto CleanupExit; // unknown address family
}
}
if (address.type == DATA_TYPE_PORT)
{
- if (i == 0)
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_REMOTE_PORT;
- }
- else
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_LOCAL_PORT;
- }
+ fwfc[count].fieldKey = (i == 0) ? FWPM_CONDITION_IP_REMOTE_PORT : FWPM_CONDITION_IP_LOCAL_PORT;
}
else
{
- if (i == 0)
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_REMOTE_ADDRESS;
- }
- else
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_LOCAL_ADDRESS;
- }
+ fwfc[count].fieldKey = (i == 0) ? FWPM_CONDITION_IP_REMOTE_ADDRESS : FWPM_CONDITION_IP_LOCAL_ADDRESS;
}
fwfc[count].matchType = FWP_MATCH_RANGE;
@@ -1156,11 +1075,13 @@ BOOLEAN _wfp_createrulefilter (
if (i == 0)
{
fwp_range1 = address.range;
+
fwfc[count].conditionValue.rangeValue = &fwp_range1;
}
else
{
fwp_range2 = address.range;
+
fwfc[count].conditionValue.rangeValue = &fwp_range2;
}
@@ -1170,15 +1091,7 @@ BOOLEAN _wfp_createrulefilter (
{
if (address.type == DATA_TYPE_PORT)
{
- if (i == 0)
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_REMOTE_PORT;
- }
- else
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_LOCAL_PORT;
- }
-
+ fwfc[count].fieldKey = (i == 0) ? FWPM_CONDITION_IP_REMOTE_PORT : FWPM_CONDITION_IP_LOCAL_PORT;
fwfc[count].matchType = FWP_MATCH_EQUAL;
fwfc[count].conditionValue.type = FWP_UINT16;
fwfc[count].conditionValue.uint16 = address.port;
@@ -1187,15 +1100,7 @@ BOOLEAN _wfp_createrulefilter (
}
else if (address.type == DATA_TYPE_IP)
{
- if (i == 0)
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_REMOTE_ADDRESS;
- }
- else
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_LOCAL_ADDRESS;
- }
-
+ fwfc[count].fieldKey = (i == 0) ? FWPM_CONDITION_IP_REMOTE_ADDRESS : FWPM_CONDITION_IP_LOCAL_ADDRESS;
fwfc[count].matchType = FWP_MATCH_EQUAL;
if (address.format == NET_ADDRESS_IPV4)
@@ -1208,11 +1113,13 @@ BOOLEAN _wfp_createrulefilter (
if (i == 0)
{
fwp_addr4_and_mask1 = address.addr4;
+
fwfc[count].conditionValue.v4AddrMask = &fwp_addr4_and_mask1;
}
else
{
fwp_addr4_and_mask2 = address.addr4;
+
fwfc[count].conditionValue.v4AddrMask = &fwp_addr4_and_mask2;
}
@@ -1228,11 +1135,13 @@ BOOLEAN _wfp_createrulefilter (
if (i == 0)
{
fwp_addr6_and_mask1 = address.addr6;
+
fwfc[count].conditionValue.v6AddrMask = &fwp_addr6_and_mask1;
}
else
{
fwp_addr6_and_mask2 = address.addr6;
+
fwfc[count].conditionValue.v6AddrMask = &fwp_addr6_and_mask2;
}
@@ -1240,7 +1149,7 @@ BOOLEAN _wfp_createrulefilter (
}
else
{
- goto CleanupExit;
+ goto CleanupExit; // unknown address family
}
}
else
@@ -1254,15 +1163,7 @@ BOOLEAN _wfp_createrulefilter (
{
if (address.port)
{
- if (i == 0)
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_REMOTE_PORT;
- }
- else
- {
- fwfc[count].fieldKey = FWPM_CONDITION_IP_LOCAL_PORT;
- }
-
+ fwfc[count].fieldKey = (i == 0) ? FWPM_CONDITION_IP_REMOTE_PORT : FWPM_CONDITION_IP_LOCAL_PORT;
fwfc[count].matchType = FWP_MATCH_EQUAL;
fwfc[count].conditionValue.type = FWP_UINT16;
fwfc[count].conditionValue.uint16 = address.port;
@@ -1287,92 +1188,36 @@ BOOLEAN _wfp_createrulefilter (
if (direction == FWP_DIRECTION_OUTBOUND || direction == FWP_DIRECTION_MAX)
{
if (af == AF_INET || af == AF_UNSPEC)
- {
- _wfp_createfilter (
- engine_handle,
- filter_type,
- filter_name,
- fwfc,
- count,
- &FWPM_LAYER_ALE_AUTH_CONNECT_V4,
- NULL,
- weight,
- action,
- flags,
- guids
- );
- }
+ _wfp_createfilter (engine_handle, filter_type, filter_name, fwfc, count, &FWPM_LAYER_ALE_AUTH_CONNECT_V4, NULL, weight, action, flags, guids);
if (af == AF_INET6 || af == AF_UNSPEC)
- {
- _wfp_createfilter (
- engine_handle,
- filter_type,
- filter_name,
- fwfc,
- count,
- &FWPM_LAYER_ALE_AUTH_CONNECT_V6,
- NULL,
- weight,
- action,
- flags,
- guids
- );
- }
+ _wfp_createfilter (engine_handle, filter_type, filter_name, fwfc, count, &FWPM_LAYER_ALE_AUTH_CONNECT_V6, NULL, weight, action, flags, guids);
}
// create inbound layer filter
if (direction == FWP_DIRECTION_INBOUND || direction == FWP_DIRECTION_MAX)
{
if (af == AF_INET || af == AF_UNSPEC)
- {
- _wfp_createfilter (
- engine_handle,
- filter_type,
- filter_name,
- fwfc,
- count,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4,
- NULL,
- weight,
- action,
- flags,
- guids
- );
- }
+ _wfp_createfilter (engine_handle, filter_type, filter_name, fwfc, count, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4, NULL, weight, action, flags, guids);
if (af == AF_INET6 || af == AF_UNSPEC)
- {
- _wfp_createfilter (
- engine_handle,
- filter_type,
- filter_name,
- fwfc,
- count,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- weight,
- action,
- flags,
- guids
- );
- }
+ _wfp_createfilter (engine_handle, filter_type, filter_name, fwfc, count, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, weight, action, flags, guids);
}
is_success = TRUE;
CleanupExit:
- if (ptr_app)
- _r_obj_dereference (ptr_app);
-
if (byte_blob)
ByteBlobFree ((PVOID_PTR)&byte_blob);
+ if (ptr_app)
+ _r_obj_dereference (ptr_app);
+
return is_success;
}
-BOOLEAN _wfp_create4filters (
+BOOLEAN _wfp_createrulefilters (
_In_ HANDLE engine_handle,
_In_ PR_LIST rules,
_In_ LPCWSTR file_name,
@@ -1380,10 +1225,7 @@ BOOLEAN _wfp_create4filters (
_In_ BOOLEAN is_intransact
)
{
- R_STRINGREF remote_remaining_part;
- R_STRINGREF local_remaining_part;
- R_STRINGREF rule_remote_part;
- R_STRINGREF rule_local_part;
+ R_STRINGREF local_remaining_part, remote_remaining_part, rule_local_part, rule_remote_part;
PITEM_RULE ptr_rule;
LPCWSTR rule_name;
PR_ARRAY guids;
@@ -1406,12 +1248,12 @@ BOOLEAN _wfp_create4filters (
{
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
{
- ptr_rule = _r_obj_getlistitem (rules, i);
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules, i);
if (!ptr_rule)
continue;
- if (!_r_obj_isempty (ptr_rule->guids))
+ if (!_r_obj_isempty2 (ptr_rule->guids))
{
_r_obj_addarrayitems (guids, ptr_rule->guids->items, ptr_rule->guids->count);
@@ -1419,6 +1261,183 @@ BOOLEAN _wfp_create4filters (
}
}
+ if (!_r_obj_isempty2 (guids))
+ {
+ for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
+ {
+ guid = (LPCGUID)_r_obj_getarrayitem (guids, i);
+
+ if (guid)
+ _app_setfiltersecurity (engine_handle, guid, FALSE, DBG_ARG_VAR);
+ }
+ }
+
+ _r_queuedlock_acquireshared (&lock_transaction);
+
+ is_intransact = !_wfp_transact_start (engine_handle, DBG_ARG_VAR);
+ }
+
+ if (!_r_obj_isempty2 (guids))
+ {
+ for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
+ {
+ guid = (LPCGUID)_r_obj_getarrayitem (guids, i);
+
+ if (guid)
+ _wfp_deletefilter (engine_handle, guid, DBG_ARG_VAR);
+ }
+ }
+
+ for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
+ {
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules, i);
+
+ if (!ptr_rule)
+ continue;
+
+ ptr_rule->is_haveerrors = FALSE;
+
+ _r_obj_cleararray (ptr_rule->guids);
+
+ if (!ptr_rule->is_enabled)
+ continue;
+
+ rule_name = _r_obj_getstring (ptr_rule->name);
+
+ if (!_r_obj_isstringempty (ptr_rule->rule_remote))
+ {
+ _r_str_splitatchar (&ptr_rule->rule_remote->sr, DIVIDER_RULE[0], &rule_remote_part, &remote_remaining_part);
+ }
+ else
+ {
+ _r_obj_initializestringrefempty (&remote_remaining_part);
+ _r_obj_initializestringrefempty (&rule_remote_part);
+ }
+
+ if (!_r_obj_isstringempty (ptr_rule->rule_local))
+ {
+ _r_str_splitatchar (&ptr_rule->rule_local->sr, DIVIDER_RULE[0], &rule_local_part, &local_remaining_part);
+ }
+ else
+ {
+ _r_obj_initializestringrefempty (&local_remaining_part);
+ _r_obj_initializestringrefempty (&rule_local_part);
+ }
+
+ while (TRUE)
+ {
+ // apply rules for kernel drivers (System)
+ if (ptr_rule->is_fordriver)
+ {
+ if (!_wfp_createrulefilter (engine_handle, ptr_rule->type, rule_name, config.ntoskrnl_hash, &ptr_rule->config, &rule_remote_part, &rule_local_part, ptr_rule->weight, ptr_rule->action, 0, ptr_rule->guids))
+ ptr_rule->is_haveerrors = TRUE;
+ }
+
+ // apply rules for service host (svchost)
+ if (ptr_rule->is_forservice)
+ {
+ if (!_wfp_createrulefilter (engine_handle, ptr_rule->type, rule_name, config.svchost_hash, &ptr_rule->config, &rule_remote_part, &rule_local_part, ptr_rule->weight, ptr_rule->action, 0, ptr_rule->guids))
+ ptr_rule->is_haveerrors = TRUE;
+ }
+
+ if (!_r_obj_isempty (ptr_rule->apps))
+ {
+ enum_key = 0;
+
+ while (_r_obj_enumhashtable (ptr_rule->apps, NULL, &hash_code, &enum_key))
+ {
+ if ((ptr_rule->is_fordriver || ptr_rule->is_forservice) && _app_issystemhash (hash_code))
+ continue;
+
+ if (!_wfp_createrulefilter (engine_handle, ptr_rule->type, rule_name, hash_code, &ptr_rule->config, &rule_remote_part, &rule_local_part, ptr_rule->weight, ptr_rule->action, 0, ptr_rule->guids))
+ ptr_rule->is_haveerrors = TRUE;
+ }
+ }
+ else
+ {
+ if (!_wfp_createrulefilter (engine_handle, ptr_rule->type, rule_name, 0, &ptr_rule->config, &rule_remote_part, &rule_local_part, ptr_rule->weight, ptr_rule->action, 0, ptr_rule->guids))
+ ptr_rule->is_haveerrors = TRUE;
+ }
+
+ if (remote_remaining_part.length == 0 && local_remaining_part.length == 0)
+ break;
+
+ if (remote_remaining_part.length != 0)
+ _r_str_splitatchar (&remote_remaining_part, DIVIDER_RULE[0], &rule_remote_part, &remote_remaining_part);
+
+ if (local_remaining_part.length != 0)
+ _r_str_splitatchar (&local_remaining_part, DIVIDER_RULE[0], &rule_local_part, &local_remaining_part);
+ }
+ }
+
+ if (!is_intransact)
+ {
+ _wfp_transact_commit (engine_handle, DBG_ARG_VAR);
+
+ for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
+ {
+ ptr_rule = (PITEM_RULE)_r_obj_getlistitem (rules, i);
+
+ if (ptr_rule && ptr_rule->is_enabled)
+ {
+ for (ULONG_PTR j = 0; j < _r_obj_getarraysize (ptr_rule->guids); j++)
+ {
+ guid = (LPCGUID)_r_obj_getarrayitem (ptr_rule->guids, j);
+
+ if (guid)
+ _app_setfiltersecurity (engine_handle, guid, TRUE, DBG_ARG_VAR);
+ }
+ }
+ }
+
+ _r_queuedlock_releaseshared (&lock_transaction);
+ }
+
+ _app_restoreinterfacestate (_r_app_gethwnd (), is_enabled);
+
+ _r_obj_dereference (guids);
+
+ return TRUE;
+}
+
+BOOLEAN _wfp_createappfilters (
+ _In_ HANDLE engine_handle,
+ _In_ PR_LIST rules,
+ _In_ LPCWSTR file_name,
+ _In_ ULONG line,
+ _In_ BOOLEAN is_intransact
+)
+{
+ PITEM_APP ptr_app;
+ PR_STRING string;
+ PR_ARRAY guids;
+ LPCGUID guid;
+ BOOLEAN is_enabled;
+
+ if (_r_obj_isempty2 (rules))
+ return FALSE;
+
+ if (!is_intransact && _wfp_isfiltersapplying ())
+ is_intransact = TRUE;
+
+ guids = _r_obj_createarray (sizeof (GUID), 0x10, NULL);
+
+ is_enabled = _app_initinterfacestate (_r_app_gethwnd (), FALSE);
+
+ if (!is_intransact)
+ {
+ for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
+ {
+ ptr_app = (PITEM_APP)_r_obj_getlistitem (rules, i);
+
+ if (ptr_app && !_r_obj_isempty (ptr_app->guids))
+ {
+ _r_obj_addarrayitems (guids, ptr_app->guids->items, ptr_app->guids->count);
+
+ _r_obj_cleararray (ptr_app->guids);
+ }
+ }
+
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
{
guid = (LPCGUID)_r_obj_getarrayitem (guids, i);
@@ -1437,252 +1456,19 @@ BOOLEAN _wfp_create4filters (
guid = (LPCGUID)_r_obj_getarrayitem (guids, i);
if (guid)
- _wfp_deletefilter (engine_handle, guid);
+ _wfp_deletefilter (engine_handle, guid, DBG_ARG_VAR);
}
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
{
- ptr_rule = _r_obj_getlistitem (rules, i);
-
- if (!ptr_rule)
- continue;
-
- ptr_rule->is_haveerrors = FALSE;
-
- _r_obj_cleararray (ptr_rule->guids);
-
- if (!ptr_rule->is_enabled)
- continue;
-
- rule_name = _r_obj_getstring (ptr_rule->name);
-
- if (!_r_obj_isstringempty (ptr_rule->rule_remote))
- {
- _r_str_splitatchar (&ptr_rule->rule_remote->sr, DIVIDER_RULE[0], &rule_remote_part, &remote_remaining_part);
- }
- else
- {
- _r_obj_initializestringrefempty (&rule_remote_part);
- _r_obj_initializestringrefempty (&remote_remaining_part);
- }
-
- if (!_r_obj_isstringempty (ptr_rule->rule_local))
- {
- _r_str_splitatchar (&ptr_rule->rule_local->sr, DIVIDER_RULE[0], &rule_local_part, &local_remaining_part);
- }
- else
- {
- _r_obj_initializestringrefempty (&rule_local_part);
- _r_obj_initializestringrefempty (&local_remaining_part);
- }
-
- while (TRUE)
- {
- // apply rules for services hosts
- if (ptr_rule->is_forservices)
- {
- if (!_wfp_createrulefilter (
- engine_handle,
- ptr_rule->type,
- rule_name,
- config.ntoskrnl_hash,
- &ptr_rule->config,
- &rule_remote_part,
- &rule_local_part,
- ptr_rule->weight,
- ptr_rule->action,
- 0,
- ptr_rule->guids))
- {
- ptr_rule->is_haveerrors = TRUE;
- }
-
- if (!_wfp_createrulefilter (
- engine_handle,
- ptr_rule->type,
- rule_name,
- config.svchost_hash,
- &ptr_rule->config,
- &rule_remote_part,
- &rule_local_part,
- ptr_rule->weight,
- ptr_rule->action,
- 0,
- ptr_rule->guids))
- {
- ptr_rule->is_haveerrors = TRUE;
- }
- }
-
- if (!_r_obj_isempty (ptr_rule->apps))
- {
- enum_key = 0;
-
- while (_r_obj_enumhashtable (ptr_rule->apps, NULL, &hash_code, &enum_key))
- {
- if (ptr_rule->is_forservices && _app_issystemhash (hash_code))
- continue;
-
- if (!_wfp_createrulefilter (
- engine_handle,
- ptr_rule->type,
- rule_name,
- hash_code,
- &ptr_rule->config,
- &rule_remote_part,
- &rule_local_part,
- ptr_rule->weight,
- ptr_rule->action,
- 0,
- ptr_rule->guids))
- {
- ptr_rule->is_haveerrors = TRUE;
- }
- }
- }
- else
- {
- if (!_wfp_createrulefilter (
- engine_handle,
- ptr_rule->type,
- rule_name,
- 0,
- &ptr_rule->config,
- &rule_remote_part,
- &rule_local_part,
- ptr_rule->weight,
- ptr_rule->action,
- 0,
- ptr_rule->guids))
- {
- ptr_rule->is_haveerrors = TRUE;
- }
- }
-
- if (remote_remaining_part.length == 0 && local_remaining_part.length == 0)
- break;
-
- if (remote_remaining_part.length != 0)
- _r_str_splitatchar (&remote_remaining_part, DIVIDER_RULE[0], &rule_remote_part, &remote_remaining_part);
-
- if (local_remaining_part.length != 0)
- _r_str_splitatchar (&local_remaining_part, DIVIDER_RULE[0], &rule_local_part, &local_remaining_part);
- }
- }
-
- if (!is_intransact)
- {
- _wfp_transact_commit (engine_handle, DBG_ARG_VAR);
-
- for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
- {
- ptr_rule = _r_obj_getlistitem (rules, i);
-
- if (ptr_rule && ptr_rule->is_enabled)
- {
- for (ULONG_PTR j = 0; j < _r_obj_getarraysize (ptr_rule->guids); j++)
- {
- guid = (LPGUID)_r_obj_getarrayitem (ptr_rule->guids, j);
-
- if (guid)
- _app_setfiltersecurity (engine_handle, guid, TRUE, DBG_ARG_VAR);
- }
- }
- }
-
- _r_queuedlock_releaseshared (&lock_transaction);
- }
-
- _app_restoreinterfacestate (_r_app_gethwnd (), is_enabled);
-
- _r_obj_dereference (guids);
-
- return TRUE;
-}
-
-BOOLEAN _wfp_create3filters (
- _In_ HANDLE engine_handle,
- _In_ PR_LIST rules,
- _In_ LPCWSTR file_name,
- _In_ ULONG line,
- _In_ BOOLEAN is_intransact
-)
-{
-
- PR_ARRAY guids;
- LPGUID guid;
- PITEM_APP ptr_app;
- PR_STRING string;
- BOOLEAN is_enabled;
-
- if (_r_obj_isempty (rules))
- return FALSE;
-
- if (!is_intransact && _wfp_isfiltersapplying ())
- is_intransact = TRUE;
-
- guids = _r_obj_createarray (sizeof (GUID), 10, NULL);
-
- is_enabled = _app_initinterfacestate (_r_app_gethwnd (), FALSE);
-
- if (!is_intransact)
- {
- for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
- {
- ptr_app = _r_obj_getlistitem (rules, i);
-
- if (ptr_app && !_r_obj_isempty (ptr_app->guids))
- {
- _r_obj_addarrayitems (guids, ptr_app->guids->items, ptr_app->guids->count);
-
- _r_obj_cleararray (ptr_app->guids);
- }
- }
-
- for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
- {
- guid = (LPGUID)_r_obj_getarrayitem (guids, i);
-
- if (guid)
- _app_setfiltersecurity (engine_handle, guid, FALSE, DBG_ARG_VAR);
- }
-
- _r_queuedlock_acquireshared (&lock_transaction);
-
- is_intransact = !_wfp_transact_start (engine_handle, DBG_ARG_VAR);
- }
-
- for (ULONG_PTR i = 0; i < _r_obj_getarraysize (guids); i++)
- {
- guid = (LPGUID)_r_obj_getarrayitem (guids, i);
-
- if (guid)
- _wfp_deletefilter (engine_handle, guid);
- }
-
- for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
- {
- ptr_app = _r_obj_getlistitem (rules, i);
+ ptr_app = (PITEM_APP)_r_obj_getlistitem (rules, i);
if (ptr_app && ptr_app->is_enabled)
{
string = _app_getappdisplayname (ptr_app, TRUE);
- if (!_wfp_createrulefilter (
- engine_handle,
- ptr_app->type,
- _r_obj_getstring (string),
- ptr_app->app_hash,
- NULL,
- NULL,
- NULL,
- FW_WEIGHT_APP,
- FWP_ACTION_PERMIT,
- 0,
- ptr_app->guids))
- {
+ if (!_wfp_createrulefilter (engine_handle, ptr_app->type, _r_obj_getstringordefault (string, L""), ptr_app->app_hash, NULL, NULL, NULL, FWW_APP, FWP_ACTION_PERMIT, 0, ptr_app->guids))
ptr_app->is_haveerrors = TRUE;
- }
if (string)
_r_obj_dereference (string);
@@ -1695,13 +1481,13 @@ BOOLEAN _wfp_create3filters (
for (ULONG_PTR i = 0; i < _r_obj_getlistsize (rules); i++)
{
- ptr_app = _r_obj_getlistitem (rules, i);
+ ptr_app = (PITEM_APP)_r_obj_getlistitem (rules, i);
if (ptr_app)
{
for (ULONG_PTR j = 0; j < _r_obj_getarraysize (ptr_app->guids); j++)
{
- guid = (LPGUID)_r_obj_getarrayitem (ptr_app->guids, j);
+ guid = (LPCGUID)_r_obj_getarrayitem (ptr_app->guids, j);
if (guid)
_app_setfiltersecurity (engine_handle, guid, TRUE, DBG_ARG_VAR);
@@ -1719,7 +1505,7 @@ BOOLEAN _wfp_create3filters (
return TRUE;
}
-BOOLEAN _wfp_create2filters (
+BOOLEAN _wfp_createglobalfilters (
_In_ HANDLE engine_handle,
_In_ LPCWSTR file_name,
_In_ ULONG line,
@@ -1747,22 +1533,22 @@ BOOLEAN _wfp_create2filters (
PR_STRINGREF_INIT (L"[::]/0"),
PR_STRINGREF_INIT (L"[::]/128"),
PR_STRINGREF_INIT (L"[::1]/128"),
- PR_STRINGREF_INIT (L"[::ffff:0:0]/96"),
- PR_STRINGREF_INIT (L"[::ffff:0:0:0]/96"),
- PR_STRINGREF_INIT (L"[64:ff9b::]/96"),
+ PR_STRINGREF_INIT (L"[::FFFF:0:0]/96"),
+ PR_STRINGREF_INIT (L"[::FFFF:0:0:0]/96"),
+ PR_STRINGREF_INIT (L"[64:FF9B::]/96"),
PR_STRINGREF_INIT (L"[100::]/64"),
PR_STRINGREF_INIT (L"[2001::]/32"),
PR_STRINGREF_INIT (L"[2001:20::]/28"),
- PR_STRINGREF_INIT (L"[2001:db8::]/32"),
+ PR_STRINGREF_INIT (L"[2001:DB8::]/32"),
PR_STRINGREF_INIT (L"[2002::]/16"),
- PR_STRINGREF_INIT (L"[fc00::]/7"),
- PR_STRINGREF_INIT (L"[fe80::]/10"),
- PR_STRINGREF_INIT (L"[ff00::]/8")
+ PR_STRINGREF_INIT (L"[FC00::]/7"),
+ PR_STRINGREF_INIT (L"[FE80::]/10"),
+ PR_STRINGREF_INIT (L"[FF00::]/8")
};
- FWPM_FILTER_CONDITION0 fwfc[4] = {0};
+ FWPM_FILTER_CONDITION0 fwfc[0x04] = {0};
ITEM_ADDRESS address;
- LPGUID guid;
+ LPCGUID guid;
FWP_ACTION_TYPE action;
BOOLEAN is_enabled;
@@ -1777,7 +1563,7 @@ BOOLEAN _wfp_create2filters (
{
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (filter_ids); i++)
{
- guid = (LPGUID)_r_obj_getarrayitem (filter_ids, i);
+ guid = (LPCGUID)_r_obj_getarrayitem (filter_ids, i);
if (guid)
_app_setfiltersecurity (engine_handle, guid, FALSE, DBG_ARG_VAR);
@@ -1793,10 +1579,10 @@ BOOLEAN _wfp_create2filters (
{
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (filter_ids); i++)
{
- guid = (LPGUID)_r_obj_getarrayitem (filter_ids, i);
+ guid = (LPCGUID)_r_obj_getarrayitem (filter_ids, i);
if (guid)
- _wfp_deletefilter (engine_handle, guid);
+ _wfp_deletefilter (engine_handle, guid, DBG_ARG_VAR);
}
_r_obj_cleararray (filter_ids);
@@ -1805,9 +1591,7 @@ BOOLEAN _wfp_create2filters (
// add loopback connections permission
if (_r_config_getboolean (L"AllowLoopbackConnections", TRUE, NULL))
{
- // match all loopback (localhost) data
- // tests if the network traffic is (non-)app container loopback traffic (win8+)
-
+ // match all loopback (localhost) traffic
fwfc[0].fieldKey = FWPM_CONDITION_FLAGS;
fwfc[0].matchType = FWP_MATCH_FLAGS_ALL_SET;
fwfc[0].conditionValue.type = FWP_UINT32;
@@ -1817,64 +1601,13 @@ BOOLEAN _wfp_create2filters (
if (_r_sys_isosversiongreaterorequal (WINDOWS_8))
{
fwfc[0].matchType = FWP_MATCH_FLAGS_ANY_SET;
- fwfc[0].conditionValue.uint32 |= FWP_CONDITION_FLAG_IS_APPCONTAINER_LOOPBACK;
+ fwfc[0].conditionValue.uint32 |= FWP_CONDITION_FLAG_IS_APPCONTAINER_LOOPBACK | FWP_CONDITION_FLAG_IS_NON_APPCONTAINER_LOOPBACK;
}
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_LOOPBACK,
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_CONNECT_V4,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_LOOPBACK,
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_CONNECT_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_LOOPBACK,
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_LOOPBACK,
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_LOOPBACK, fwfc, 1, &FWPM_LAYER_ALE_AUTH_CONNECT_V4, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_LOOPBACK, fwfc, 1, &FWPM_LAYER_ALE_AUTH_CONNECT_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_LOOPBACK, fwfc, 1, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_LOOPBACK, fwfc, 1, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (loopback_list); i++)
{
@@ -1890,35 +1623,11 @@ BOOLEAN _wfp_create2filters (
fwfc[1].fieldKey = FWPM_CONDITION_IP_REMOTE_ADDRESS;
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_LOOPBACK,
- fwfc,
- 2,
- &FWPM_LAYER_ALE_AUTH_CONNECT_V4,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_LOOPBACK, fwfc, 2, &FWPM_LAYER_ALE_AUTH_CONNECT_V4, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
fwfc[1].fieldKey = FWPM_CONDITION_IP_LOCAL_ADDRESS;
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_LOOPBACK,
- fwfc,
- 2,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_LOOPBACK, fwfc, 2, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
}
else if (address.format == NET_ADDRESS_IPV6)
{
@@ -1927,41 +1636,22 @@ BOOLEAN _wfp_create2filters (
fwfc[1].fieldKey = FWPM_CONDITION_IP_REMOTE_ADDRESS;
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_LOOPBACK,
- fwfc,
- 2,
- &FWPM_LAYER_ALE_AUTH_CONNECT_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_LOOPBACK, fwfc, 2, &FWPM_LAYER_ALE_AUTH_CONNECT_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
fwfc[1].fieldKey = FWPM_CONDITION_IP_LOCAL_ADDRESS;
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_LOOPBACK,
- fwfc,
- 2,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_LOOPBACK, fwfc, 2, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
+ }
+ else
+ {
+ // unknown address family
}
}
}
// firewall service rules
- // https://msdn.microsoft.com/en-us/library/gg462153.aspx
+ // https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml
+ // https://learn.microsoft.com/ru-ru/previous-versions/windows/embedded/gg462153(v=winembedded.80)
if (_r_config_getboolean (L"AllowIPv6", TRUE, NULL))
{
// allows 6to4 tunneling, which enables ipv6 to run over an ipv4 network
@@ -1970,99 +1660,34 @@ BOOLEAN _wfp_create2filters (
fwfc[0].conditionValue.type = FWP_UINT8;
fwfc[0].conditionValue.uint8 = IPPROTO_IPV6; // ipv6 header
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- L"Allow6to4",
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, L"Allow6to4", fwfc, 1, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
- // allows icmpv6 router solicitation messages, which are
- // required for the ipv6 stack to work properly
+ // allows icmpv6 router solicitation messages, which are required for the ipv6 stack to work properly
fwfc[0].fieldKey = FWPM_CONDITION_ICMP_TYPE;
fwfc[0].matchType = FWP_MATCH_EQUAL;
fwfc[0].conditionValue.type = FWP_UINT16;
+ fwfc[0].conditionValue.uint16 = 0x85; // router solicitation
- fwfc[0].conditionValue.uint16 = 0x85;
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, L"AllowIcmpV6Type133", fwfc, 1, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- L"AllowIcmpV6Type133",
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ // allows icmpv6 router advertise messages, which are required for the ipv6 stack to work properly
+ fwfc[0].conditionValue.uint16 = 0x86; // router advertisement
- // allows icmpv6 router advertise messages, which are required
- // for the ipv6 stack to work properly
- fwfc[0].conditionValue.uint16 = 0x86;
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, L"AllowIcmpV6Type134", fwfc, 1, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- L"AllowIcmpV6Type134",
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ // allows icmpv6 neighbor solicitation messages, which are required for the ipv6 stack to work properly
+ fwfc[0].conditionValue.uint16 = 0x87; // neighbor solicitation
- // allows icmpv6 neighbor solicitation messages, which
- // are required for the ipv6 stack to work properly
- fwfc[0].conditionValue.uint16 = 0x87;
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, L"AllowIcmpV6Type135", fwfc, 1, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- L"AllowIcmpV6Type135",
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ // allows icmpv6 neighbor advertise messages, which are required for the ipv6 stack to work properly
+ fwfc[0].conditionValue.uint16 = 0x88; // neighbor advertisement
- // allows icmpv6 neighbor advertise messages, which are
- // required for the ipv6 stack to work properly
- fwfc[0].conditionValue.uint16 = 0x88;
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- L"AllowIcmpV6Type136",
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, L"AllowIcmpV6Type136", fwfc, 1, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, 0, filter_ids);
}
// prevent port scanning using stealth discards and silent drops
- // https://docs.microsoft.com/ru-ru/windows/desktop/FWP/preventing-port-scanning
+ // https://learn.microsoft.com/ru-ru/windows/win32/fwp/preventing-port-scanning
if (_r_config_getboolean (L"UseStealthMode", TRUE, NULL))
{
// blocks udp port scanners
@@ -2073,40 +1698,15 @@ BOOLEAN _wfp_create2filters (
// tests if the network traffic is (non-)app container loopback traffic (win8+)
if (_r_sys_isosversiongreaterorequal (WINDOWS_8))
- fwfc[0].conditionValue.uint32 |= FWP_CONDITION_FLAG_IS_APPCONTAINER_LOOPBACK;
+ fwfc[0].conditionValue.uint32 |= FWP_CONDITION_FLAG_IS_APPCONTAINER_LOOPBACK | FWP_CONDITION_FLAG_IS_NON_APPCONTAINER_LOOPBACK;
fwfc[1].fieldKey = FWPM_CONDITION_ICMP_TYPE;
fwfc[1].matchType = FWP_MATCH_EQUAL;
fwfc[1].conditionValue.type = FWP_UINT16;
fwfc[1].conditionValue.uint16 = 0x03; // destination unreachable
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_ICMP_ERROR,
- fwfc,
- 2,
- &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V4,
- NULL,
- FW_WEIGHT_HIGHEST,
- FWP_ACTION_BLOCK,
- 0,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_ICMP_ERROR,
- fwfc,
- 2,
- &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V6,
- NULL,
- FW_WEIGHT_HIGHEST,
- FWP_ACTION_BLOCK,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_ICMP_ERROR, fwfc, 2, &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V4, NULL, FWW_HIGHEST, FWP_ACTION_BLOCK, 0, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_ICMP_ERROR, fwfc, 2, &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V6, NULL, FWW_HIGHEST, FWP_ACTION_BLOCK, 0, filter_ids);
// blocks tcp port scanners (exclude loopback)
fwfc[0].conditionValue.uint32 |= FWP_CONDITION_FLAG_IS_IPSEC_SECURED;
@@ -2114,12 +1714,12 @@ BOOLEAN _wfp_create2filters (
_wfp_createfilter (
engine_handle,
DATA_FILTER_GENERAL,
- FW_NAME_TCP_RST_ONCLOSE,
+ FWN_TCP_RST_ONCLOSE,
fwfc,
1,
&FWPM_LAYER_INBOUND_TRANSPORT_V4_DISCARD,
&FWPM_CALLOUT_WFP_TRANSPORT_LAYER_V4_SILENT_DROP,
- FW_WEIGHT_HIGHEST,
+ FWW_HIGHEST,
FWP_ACTION_CALLOUT_TERMINATING,
0,
filter_ids
@@ -2128,20 +1728,19 @@ BOOLEAN _wfp_create2filters (
_wfp_createfilter (
engine_handle,
DATA_FILTER_GENERAL,
- FW_NAME_TCP_RST_ONCLOSE,
+ FWN_TCP_RST_ONCLOSE,
fwfc,
1,
&FWPM_LAYER_INBOUND_TRANSPORT_V6_DISCARD,
&FWPM_CALLOUT_WFP_TRANSPORT_LAYER_V6_SILENT_DROP,
- FW_WEIGHT_HIGHEST,
+ FWW_HIGHEST,
FWP_ACTION_CALLOUT_TERMINATING,
0,
filter_ids
);
}
- // install boot-time filters (enforced at boot-time,
- // even before "base filtering engine" service starts)
+ // install boot-time filters (enforced at boot-time, even before BFE service starts)
if (_r_config_getboolean (L"InstallBoottimeFilters", TRUE, NULL) && !config.is_filterstemporary)
{
fwfc[0].fieldKey = FWPM_CONDITION_FLAGS;
@@ -2153,204 +1752,24 @@ BOOLEAN _wfp_create2filters (
if (_r_sys_isosversiongreaterorequal (WINDOWS_8))
{
fwfc[0].matchType = FWP_MATCH_FLAGS_ANY_SET;
- fwfc[0].conditionValue.uint32 |= FWP_CONDITION_FLAG_IS_APPCONTAINER_LOOPBACK;
+ fwfc[0].conditionValue.uint32 |= FWP_CONDITION_FLAG_IS_APPCONTAINER_LOOPBACK | FWP_CONDITION_FLAG_IS_NON_APPCONTAINER_LOOPBACK;
}
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_IPFORWARD_V4,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_IPFORWARD_V4, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_IPFORWARD_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_INBOUND_ICMP_ERROR_V4, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_INBOUND_ICMP_ERROR_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V4, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V6, NULL, FWW_IMPORTANT, FWP_ACTION_PERMIT, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_IPFORWARD_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_INBOUND_ICMP_ERROR_V4,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_INBOUND_ICMP_ERROR_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V4,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V6,
- NULL,
- FW_WEIGHT_HIGHEST_IMPORTANT,
- FWP_ACTION_PERMIT,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- NULL,
- 0,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4,
- NULL,
- FW_WEIGHT_LOWEST,
- FWP_ACTION_BLOCK,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- NULL,
- 0,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- FW_WEIGHT_LOWEST,
- FWP_ACTION_BLOCK,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- NULL,
- 0,
- &FWPM_LAYER_INBOUND_ICMP_ERROR_V4,
- NULL,
- FW_WEIGHT_LOWEST,
- FWP_ACTION_BLOCK,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- NULL,
- 0,
- &FWPM_LAYER_INBOUND_ICMP_ERROR_V6,
- NULL,
- FW_WEIGHT_LOWEST,
- FWP_ACTION_BLOCK,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- NULL,
- 0,
- &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V4,
- NULL,
- FW_WEIGHT_LOWEST,
- FWP_ACTION_BLOCK,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- NULL,
- 0,
- &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V6,
- NULL,
- FW_WEIGHT_LOWEST,
- FWP_ACTION_BLOCK,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, NULL, 0, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4, NULL, FWW_LOWEST, FWP_ACTION_BLOCK, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, NULL, 0, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, FWW_LOWEST, FWP_ACTION_BLOCK, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, NULL, 0, &FWPM_LAYER_INBOUND_ICMP_ERROR_V4, NULL, FWW_LOWEST, FWP_ACTION_BLOCK, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, NULL, 0, &FWPM_LAYER_INBOUND_ICMP_ERROR_V6, NULL, FWW_LOWEST, FWP_ACTION_BLOCK, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, NULL, 0, &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V4, NULL, FWW_LOWEST, FWP_ACTION_BLOCK, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, NULL, 0, &FWPM_LAYER_OUTBOUND_ICMP_ERROR_V6, NULL, FWW_LOWEST, FWP_ACTION_BLOCK, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
// win7+ boot-time features
fwfc[0].fieldKey = FWPM_CONDITION_FLAGS;
@@ -2358,33 +1777,8 @@ BOOLEAN _wfp_create2filters (
fwfc[0].conditionValue.type = FWP_UINT32;
fwfc[0].conditionValue.uint32 = FWP_CONDITION_FLAG_IS_OUTBOUND_PASS_THRU | FWP_CONDITION_FLAG_IS_INBOUND_PASS_THRU;
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_IPFORWARD_V4,
- NULL,
- FW_WEIGHT_APP,
- FWP_ACTION_BLOCK,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BOOTTIME,
- fwfc,
- 1,
- &FWPM_LAYER_IPFORWARD_V6,
- NULL,
- FW_WEIGHT_APP,
- FWP_ACTION_BLOCK,
- FWPM_FILTER_FLAG_BOOTTIME,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_IPFORWARD_V4, NULL, FWW_APP, FWP_ACTION_BLOCK, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BOOTTIME, fwfc, 1, &FWPM_LAYER_IPFORWARD_V6, NULL, FWW_APP, FWP_ACTION_BLOCK, FWPM_FILTER_FLAG_BOOTTIME, filter_ids);
}
action = _r_config_getboolean (L"BlockOutboundConnections", TRUE, NULL) ? FWP_ACTION_BLOCK : FWP_ACTION_PERMIT;
@@ -2398,12 +1792,12 @@ BOOLEAN _wfp_create2filters (
_wfp_createfilter (
engine_handle,
DATA_FILTER_GENERAL,
- FW_NAME_BLOCK_CONNECTION,
+ FWN_BLOCK_CONNECTION,
NULL,
0,
&FWPM_LAYER_ALE_AUTH_CONNECT_V4,
&FWPM_CALLOUT_TCP_TEMPLATES_CONNECT_LAYER_V4,
- FW_WEIGHT_LOWEST,
+ FWW_LOWEST,
FWP_ACTION_CALLOUT_TERMINATING,
0,
filter_ids
@@ -2412,12 +1806,12 @@ BOOLEAN _wfp_create2filters (
_wfp_createfilter (
engine_handle,
DATA_FILTER_GENERAL,
- FW_NAME_BLOCK_CONNECTION,
+ FWN_BLOCK_CONNECTION,
NULL,
0,
&FWPM_LAYER_ALE_AUTH_CONNECT_V6,
&FWPM_CALLOUT_TCP_TEMPLATES_CONNECT_LAYER_V6,
- FW_WEIGHT_LOWEST,
+ FWW_LOWEST,
FWP_ACTION_CALLOUT_TERMINATING,
0,
filter_ids
@@ -2426,71 +1820,14 @@ BOOLEAN _wfp_create2filters (
}
// fallback
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BLOCK_CONNECTION,
- NULL,
- 0,
- &FWPM_LAYER_ALE_AUTH_CONNECT_V4,
- NULL,
- FW_WEIGHT_LOWEST,
- action,
- 0,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BLOCK_CONNECTION,
- NULL,
- 0,
- &FWPM_LAYER_ALE_AUTH_CONNECT_V6,
- NULL,
- FW_WEIGHT_LOWEST,
- action,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BLOCK_CONNECTION, NULL, 0, &FWPM_LAYER_ALE_AUTH_CONNECT_V4, NULL, FWW_LOWEST, action, 0, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BLOCK_CONNECTION, NULL, 0, &FWPM_LAYER_ALE_AUTH_CONNECT_V6, NULL, FWW_LOWEST, action, 0, filter_ids);
// block inbound connections
- if (_r_config_getboolean (L"UseStealthMode", TRUE, NULL) || _r_config_getboolean (L"BlockInboundConnections", TRUE, NULL))
- {
- action = FWP_ACTION_BLOCK;
- }
- else
- {
- action = FWP_ACTION_PERMIT;
- }
+ action = (_r_config_getboolean (L"UseStealthMode", TRUE, NULL) || _r_config_getboolean (L"BlockInboundConnections", TRUE, NULL)) ? FWP_ACTION_BLOCK : FWP_ACTION_PERMIT;
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BLOCK_RECVACCEPT,
- NULL,
- 0,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4,
- NULL,
- FW_WEIGHT_LOWEST,
- action,
- 0,
- filter_ids
- );
-
- _wfp_createfilter (
- engine_handle,
- DATA_FILTER_GENERAL,
- FW_NAME_BLOCK_RECVACCEPT,
- NULL,
- 0,
- &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6,
- NULL,
- FW_WEIGHT_LOWEST,
- action,
- 0,
- filter_ids
- );
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BLOCK_RECVACCEPT, NULL, 0, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4, NULL, FWW_LOWEST, action, 0, filter_ids);
+ _wfp_createfilter (engine_handle, DATA_FILTER_GENERAL, FWN_BLOCK_RECVACCEPT, NULL, 0, &FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6, NULL, FWW_LOWEST, action, 0, filter_ids);
if (!is_intransact)
{
@@ -2498,7 +1835,7 @@ BOOLEAN _wfp_create2filters (
for (ULONG_PTR i = 0; i < _r_obj_getarraysize (filter_ids); i++)
{
- guid = (LPGUID)_r_obj_getarrayitem (filter_ids, i);
+ guid = (LPCGUID)_r_obj_getarrayitem (filter_ids, i);
if (guid)
_app_setfiltersecurity (engine_handle, guid, TRUE, DBG_ARG_VAR);
@@ -2519,10 +1856,9 @@ ULONG _wfp_dumpcallouts (
_Outptr_ PR_ARRAY_PTR out_buffer
)
{
- FWPM_CALLOUT0 **callouts_enum = NULL;
- FWPM_CALLOUT0 *callout;
- PR_ARRAY guids = NULL;
+ FWPM_CALLOUT0 **callouts_enum = NULL, *callout;
HANDLE enum_handle = NULL;
+ PR_ARRAY guids = NULL;
UINT32 return_count;
ULONG status;
@@ -2533,12 +1869,15 @@ ULONG _wfp_dumpcallouts (
if (status != ERROR_SUCCESS)
return status;
+ if (!enum_handle)
+ return ERROR_NOT_FOUND;
+
status = FwpmCalloutEnum0 (engine_handle, enum_handle, UINT32_MAX, &callouts_enum, &return_count);
if (status != ERROR_SUCCESS)
goto CleanupExit;
- if (!callouts_enum)
+ if (!callouts_enum || !return_count)
{
status = ERROR_NOT_FOUND;
@@ -2570,7 +1909,9 @@ CleanupExit:
else
{
if (guids)
- _r_obj_dereference (guids);
+ _r_obj_dereference (guids); // cleanup!
+
+ *out_buffer = NULL;
}
if (enum_handle)
@@ -2596,19 +1937,27 @@ ULONG _wfp_dumpfilters (
UINT32 return_count;
ULONG status;
- *out_buffer = NULL;
-
status = FwpmFilterCreateEnumHandle0 (engine_handle, NULL, &enum_handle);
if (status != ERROR_SUCCESS)
+ {
+ _r_log (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmFilterCreateEnumHandle0", status, NULL);
+
+ *out_buffer = NULL;
+
return status;
+ }
status = FwpmFilterEnum0 (engine_handle, enum_handle, UINT32_MAX, &filters_enum, &return_count);
if (status != ERROR_SUCCESS)
- goto CleanupExit;
+ {
+ _r_log (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmFilterEnum0", status, NULL);
- if (!filters_enum)
+ goto CleanupExit;
+ }
+
+ if (!filters_enum || !return_count)
{
status = ERROR_NOT_FOUND;
@@ -2629,16 +1978,21 @@ ULONG _wfp_dumpfilters (
}
if (_r_obj_isempty2 (guids))
- {
status = ERROR_NOT_FOUND;
- _r_obj_dereference (guids);
- }
-
CleanupExit:
if (status == ERROR_SUCCESS)
+ {
*out_buffer = guids;
+ }
+ else
+ {
+ if (guids)
+ _r_obj_dereference (guids); // cleanup!
+
+ *out_buffer = NULL;
+ }
if (enum_handle)
FwpmFilterDestroyEnumHandle0 (engine_handle, enum_handle);
@@ -2655,7 +2009,6 @@ VOID NTAPI _wfp_applythread (
{
PITEM_CONTEXT context;
HANDLE engine_handle;
- LONG dpi_value;
_r_queuedlock_acquireshared (&lock_apply);
@@ -2687,10 +2040,8 @@ VOID NTAPI _wfp_applythread (
if (_r_sys_isosversiongreaterorequal (WINDOWS_10))
_app_wufixenable (context->hwnd, _r_config_getboolean (L"IsWUFixEnabled", FALSE, NULL));
- dpi_value = _r_dc_getwindowdpi (context->hwnd);
-
_app_restoreinterfacestate (context->hwnd, TRUE);
- _app_setinterfacestate (context->hwnd, dpi_value);
+ _app_setinterfacestate (context->hwnd, _r_dc_getwindowdpi (context->hwnd));
_r_freelist_deleteitem (&context_free_list, context);
@@ -2703,19 +2054,18 @@ VOID _wfp_firewallenable (
_In_ BOOLEAN is_enable
)
{
- NET_FW_PROFILE_TYPE2 profile_types[] = {
- NET_FW_PROFILE2_DOMAIN,
- NET_FW_PROFILE2_PRIVATE,
- NET_FW_PROFILE2_PUBLIC
- };
-
+ NET_FW_PROFILE_TYPE2 profile_types[] = {NET_FW_PROFILE2_DOMAIN, NET_FW_PROFILE2_PRIVATE, NET_FW_PROFILE2_PUBLIC};
INetFwPolicy2 *INetFwPolicy = NULL;
HRESULT status;
status = CoCreateInstance (&CLSID_NetFwPolicy2, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwPolicy2, (PVOID_PTR)&INetFwPolicy);
if (FAILED (status))
+ {
+ _r_log (LOG_LEVEL_INFO, NULL, L"CoCreateInstance", status, L"IID_INetFwPolicy2");
+
return;
+ }
for (ULONG_PTR i = 0; i < RTL_NUMBER_OF (profile_types); i++)
{
@@ -2730,12 +2080,7 @@ VOID _wfp_firewallenable (
BOOLEAN _wfp_firewallisenabled ()
{
- NET_FW_PROFILE_TYPE2 profile_types[] = {
- NET_FW_PROFILE2_DOMAIN,
- NET_FW_PROFILE2_PRIVATE,
- NET_FW_PROFILE2_PUBLIC
- };
-
+ NET_FW_PROFILE_TYPE2 profile_types[] = {NET_FW_PROFILE2_DOMAIN, NET_FW_PROFILE2_PRIVATE, NET_FW_PROFILE2_PUBLIC};
INetFwPolicy2 *INetFwPolicy = NULL;
VARIANT_BOOL result = VARIANT_FALSE;
HRESULT status;
@@ -2792,8 +2137,7 @@ NTSTATUS _FwpmGetAppIdFromFileName1 (
if (!NT_SUCCESS (status))
{
- // file is inaccessible or not found, maybe low-level
- // driver preventing file access? try another way!
+ // file is inaccessible or not found, maybe low-level driver preventing file access? try another way!
if (status == STATUS_OBJECT_NAME_NOT_FOUND || status == STATUS_FILE_IS_A_DIRECTORY || status == STATUS_ACCESS_DENIED)
{
if (!_app_isappvalidpath (path))
@@ -2841,7 +2185,7 @@ NTSTATUS _FwpmGetAppIdFromFileName1 (
return STATUS_SUCCESS;
}
}
- else if (type == DATA_APP_PICO || type == DATA_APP_DEVICE)
+ else if (type == DATA_APP_DEVICE || type == DATA_APP_PICO)
{
original_path = _r_obj_createstring2 (&path->sr);
@@ -2866,7 +2210,7 @@ VOID ByteBlobAlloc (
{
FWP_BYTE_BLOB *blob;
- blob = _r_mem_allocate (sizeof (FWP_BYTE_BLOB) + bytes_count);
+ blob = (FWP_BYTE_BLOB*)_r_mem_allocate (sizeof (FWP_BYTE_BLOB) + bytes_count);
blob->size = (UINT32)(UINT_PTR)bytes_count;
blob->data = PTR_ADD_OFFSET (blob, sizeof (FWP_BYTE_BLOB));
@@ -2882,7 +2226,7 @@ VOID ByteBlobFree (
{
FWP_BYTE_BLOB *original_blob;
- original_blob = *byte_blob;
+ original_blob = (FWP_BYTE_BLOB*)*byte_blob;
*byte_blob = NULL;
if (original_blob)
diff --git a/src/wfp.h b/src/wfp.h
index 0e7e73c0..8acd97a8 100644
--- a/src/wfp.h
+++ b/src/wfp.h
@@ -8,25 +8,29 @@ DEFINE_GUID (GUID_WfpProvider, 0xB0D553E2, 0xC6A0, 0x4A9A, 0xAE, 0xB8, 0xC7, 0x5
DEFINE_GUID (GUID_WfpSublayer, 0x9FEE6F59, 0xB951, 0x4F9A, 0xB5, 0x2F, 0x13, 0x3D, 0xCF, 0x7A, 0x42, 0x79);
// filter names
-#define FW_NAME_BLOCK_CONNECTION L"BlockConnection"
-#define FW_NAME_BLOCK_RECVACCEPT L"BlockRecvAccept"
-#define FW_NAME_ICMP_ERROR L"BlockIcmpError"
-#define FW_NAME_TCP_RST_ONCLOSE L"BlockTcpRstOnClose"
-#define FW_NAME_BOOTTIME L"BlockBoottime"
-#define FW_NAME_LOOPBACK L"AllowLoopback"
+#define FWN_BLOCK_CONNECTION L"BlockConnection"
+#define FWN_BLOCK_RECVACCEPT L"BlockRecvAccept"
+#define FWN_ICMP_ERROR L"BlockIcmpError"
+#define FWN_TCP_RST_ONCLOSE L"BlockTcpRstOnClose"
+#define FWN_BOOTTIME L"BlockBoottime"
+#define FWN_LOOPBACK L"AllowLoopback"
// sublayer weight
-#define FW_SUBLAYER_WEIGHT 0xFFFF
+#define FWW_SUBLAYER 0xFFFF // highest weight for UINT16
// filter weights
-#define FW_WEIGHT_HIGHEST_IMPORTANT 0x0F
-#define FW_WEIGHT_HIGHEST 0x0E
-#define FW_WEIGHT_RULE_BLOCKLIST 0x0D
-#define FW_WEIGHT_RULE_USER_BLOCK 0x0C
-#define FW_WEIGHT_RULE_USER 0x0B
-#define FW_WEIGHT_RULE_SYSTEM 0x0A
-#define FW_WEIGHT_APP 0x09
-#define FW_WEIGHT_LOWEST 0x08
+#define FWW_IMPORTANT 0x0F
+#define FWW_HIGHEST 0x0E
+#define FWW_RULE_BLOCKLIST 0x0D
+#define FWW_RULE_USER_BLOCK 0x0C
+#define FWW_RULE_USER 0x0B
+#define FWW_RULE_SYSTEM 0x0A
+#define FWW_APP 0x09
+#define FWW_LOWEST 0x08
+
+HANDLE _wfp_getenginehandle ();
+
+BOOLEAN _wfp_isfiltersapplying ();
ENUM_INSTALL_TYPE _wfp_isproviderinstalled (
_In_ HANDLE engine_handle
@@ -36,16 +40,13 @@ ENUM_INSTALL_TYPE _wfp_issublayerinstalled (
_In_ HANDLE engine_handle
);
-BOOLEAN _wfp_isfiltersapplying ();
-
BOOLEAN _wfp_isfiltersinstalled ();
-HANDLE _wfp_getenginehandle ();
-
ENUM_INSTALL_TYPE _wfp_getinstalltype ();
+_Ret_maybenull_
PR_STRING _wfp_getlayername (
- _In_ LPGUID layer_guid
+ _In_ LPCGUID layer_guid
);
BOOLEAN _wfp_initialize (
@@ -74,22 +75,18 @@ BOOLEAN _wfp_transact_commit (
_In_ ULONG line
);
-ULONG _wfp_createcallout (
- _In_ HANDLE engine_handle,
- _In_ LPCGUID layer_key,
- _In_ LPCGUID callout_key
-);
-
BOOLEAN _wfp_deletefilter (
_In_ HANDLE engine_handle,
- _In_ LPCGUID filter_id
+ _In_ LPCGUID filter_id,
+ _In_ LPCWSTR file_name,
+ _In_ ULONG line
);
ULONG _wfp_createfilter (
_In_ HANDLE engine_handle,
_In_ ENUM_TYPE_DATA type,
_In_opt_ LPCWSTR filter_name,
- _In_reads_ (count) FWPM_FILTER_CONDITION0 *lpcond,
+ _In_reads_opt_ (count) FWPM_FILTER_CONDITION0 *lpcond,
_In_ UINT32 count,
_In_ LPCGUID layer_id,
_In_opt_ LPCGUID callout_id,
@@ -107,7 +104,7 @@ VOID _wfp_destroyfilters (
VOID _wfp_destroyfilters_array (
_In_ HANDLE engine_handle,
- _In_ PR_ARRAY guids,
+ _Inout_ PR_ARRAY guids,
_In_ LPCWSTR file_name,
_In_ ULONG line
);
@@ -118,15 +115,15 @@ BOOLEAN _wfp_createrulefilter (
_In_opt_ LPCWSTR filter_name,
_In_opt_ ULONG app_hash,
_In_opt_ PITEM_FILTER_CONFIG filter_config,
- _In_opt_ PR_STRINGREF rule_remote,
- _In_opt_ PR_STRINGREF rule_local,
+ _In_opt_ PCR_STRINGREF rule_remote,
+ _In_opt_ PCR_STRINGREF rule_local,
_In_ UINT8 weight,
_In_ FWP_ACTION_TYPE action,
_In_ UINT32 flags,
_Inout_opt_ PR_ARRAY guids
);
-BOOLEAN _wfp_create4filters (
+BOOLEAN _wfp_createrulefilters (
_In_ HANDLE engine_handle,
_In_ PR_LIST rules,
_In_ LPCWSTR file_name,
@@ -134,7 +131,7 @@ BOOLEAN _wfp_create4filters (
_In_ BOOLEAN is_intransact
);
-BOOLEAN _wfp_create3filters (
+BOOLEAN _wfp_createappfilters (
_In_ HANDLE engine_handle,
_In_ PR_LIST rules,
_In_ LPCWSTR file_name,
@@ -142,7 +139,7 @@ BOOLEAN _wfp_create3filters (
_In_ BOOLEAN is_intransact
);
-BOOLEAN _wfp_create2filters (
+BOOLEAN _wfp_createglobalfilters (
_In_ HANDLE engine_handle,
_In_ LPCWSTR file_name,
_In_ ULONG line,