From 4f20fedfee8e514e82548bf89c246481c2f53119 Mon Sep 17 00:00:00 2001 From: henrypp Date: Wed, 1 Dec 2021 22:33:31 +0600 Subject: [PATCH] refactor helper.c --- simplewall.vcxproj | 8 +- simplewall.vcxproj.filters | 16 +- src/controls.c | 2 + src/editor.c | 22 +- src/global.h | 6 +- src/helper.c | 1494 +----------------------------------- src/helper.h | 25 - src/icons.c | 183 +++++ src/icons.h | 19 + src/log.c | 16 +- src/main.c | 16 +- src/messages.c | 6 +- src/notifications.c | 6 +- src/packages.c | 409 ++++++++++ src/packages.h | 9 + 15 files changed, 713 insertions(+), 1524 deletions(-) create mode 100644 src/icons.c create mode 100644 src/icons.h create mode 100644 src/packages.c create mode 100644 src/packages.h diff --git a/simplewall.vcxproj b/simplewall.vcxproj index b5957244..2873dea5 100644 --- a/simplewall.vcxproj +++ b/simplewall.vcxproj @@ -353,14 +353,16 @@ + + + - @@ -375,15 +377,17 @@ + + + - diff --git a/simplewall.vcxproj.filters b/simplewall.vcxproj.filters index f4011b18..be55c0e9 100644 --- a/simplewall.vcxproj.filters +++ b/simplewall.vcxproj.filters @@ -60,7 +60,13 @@ Source Files - + + Source Files + + + Source Files + + Source Files @@ -128,7 +134,13 @@ Header Files - + + Header Files + + + Header Files + + Header Files diff --git a/src/controls.c b/src/controls.c index e2830831..2da2b1ee 100644 --- a/src/controls.c +++ b/src/controls.c @@ -559,6 +559,8 @@ PR_STRING _app_gettooltipbylparam (_In_ HWND hwnd, _In_ INT listview_id, _In_ UL PR_STRING string; PR_STRING string_tmp; + UNREFERENCED_PARAMETER (hwnd); + _r_obj_initializestringbuilder (&sr); if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) || listview_id == IDC_RULE_APPS_ID) diff --git a/src/editor.c b/src/editor.c index 4e86ef70..f4f867b6 100644 --- a/src/editor.c +++ b/src/editor.c @@ -237,7 +237,7 @@ INT_PTR CALLBACK EditorRuleProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpar if (hdc) { - _r_dc_drawwindowdefault (hdc, hwnd, TRUE); + _r_dc_drawwindow (hdc, hwnd, TRUE); EndPaint (hwnd, &ps); } @@ -459,7 +459,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa { index += 1; - string = _app_getprotoname (protos[i], AF_UNSPEC, TRUE); + string = _app_db_getprotoname (protos[i], AF_UNSPEC, TRUE); _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"%s (%" TEXT (PRIu8) L")", string->buffer, protos[i]); @@ -475,7 +475,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa // unknown protocol if (_r_combobox_getcurrentitem (hwnd, IDC_RULE_PROTOCOL_ID) == CB_ERR) { - string = _app_getprotoname (context->ptr_rule->protocol, AF_UNSPEC, TRUE); + string = _app_db_getprotoname (context->ptr_rule->protocol, AF_UNSPEC, TRUE); _r_str_printf (buffer, RTL_NUMBER_OF (buffer), L"%s (%" TEXT (PR_ULONG) L")", string->buffer, context->ptr_rule->protocol); @@ -643,7 +643,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa // app icon if (GetDlgItem (hwnd, IDC_APP_ICON_ID)) { - context->hicon = _app_getfileiconsafe (context->ptr_app->app_hash); + context->hicon = _app_icons_getsafeapp_hicon (context->ptr_app->app_hash); SendDlgItemMessage (hwnd, IDC_APP_ICON_ID, STM_SETICON, (WPARAM)context->hicon, 0); } @@ -659,8 +659,6 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa // app signature if (GetDlgItem (hwnd, IDC_APP_SIGNATURE_ID)) { - PR_STRING string; - string = _app_getappinfoparam2 (context->ptr_app->app_hash, INFO_SIGNATURE_STRING); _r_ctrl_setstringformat (hwnd, IDC_APP_SIGNATURE_ID, L"%s: %s", _r_locale_getstring (IDS_SIGNATURE), _r_obj_getstringordefault (string, _r_locale_getstring (IDS_SIGN_UNSIGNED))); @@ -956,7 +954,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa case LVN_DELETEITEM: { - PITEM_LISTVIEW_CONTEXT context; + PITEM_LISTVIEW_CONTEXT listview_context; LPNMLISTVIEW lpnmlv; INT listview_id; @@ -966,12 +964,12 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa if (!(listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID)) break; - context = (PITEM_LISTVIEW_CONTEXT)lpnmlv->lParam; + listview_context = (PITEM_LISTVIEW_CONTEXT)lpnmlv->lParam; - if (!context) + if (!listview_context) break; - _app_destroylistviewcontext (context); + _app_destroylistviewcontext (listview_context); break; } @@ -1482,7 +1480,7 @@ INT_PTR CALLBACK EditorProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, if (hdc) { - _r_dc_drawwindowdefault (hdc, hwnd, FALSE); + _r_dc_drawwindow (hdc, hwnd, FALSE); EndPaint (hwnd, &ps); } @@ -1645,7 +1643,7 @@ INT_PTR CALLBACK EditorProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, context->ptr_rule->protocol = (UINT8)_r_combobox_getitemparam (hpage_general, IDC_RULE_PROTOCOL_ID, _r_combobox_getcurrentitem (hpage_general, IDC_RULE_PROTOCOL_ID)); context->ptr_rule->af = (ADDRESS_FAMILY)_r_combobox_getitemparam (hpage_general, IDC_RULE_VERSION_ID, _r_combobox_getcurrentitem (hpage_general, IDC_RULE_VERSION_ID)); - string = _app_getprotoname (context->ptr_rule->protocol, context->ptr_rule->af, FALSE); + string = _app_db_getprotoname (context->ptr_rule->protocol, context->ptr_rule->af, FALSE); _r_obj_movereference (&context->ptr_rule->protocol_str, string); context->ptr_rule->direction = (FWP_DIRECTION)_r_calc_clamp (_r_ctrl_isradiobuttonchecked (hpage_general, IDC_RULE_DIRECTION_OUTBOUND, IDC_RULE_DIRECTION_ANY) - IDC_RULE_DIRECTION_OUTBOUND, FWP_DIRECTION_OUTBOUND, FWP_DIRECTION_MAX); diff --git a/src/global.h b/src/global.h index 7d1b444d..a926c567 100644 --- a/src/global.h +++ b/src/global.h @@ -34,7 +34,6 @@ DECLSPEC_SELECTANY PROFILE_DATA profile_info = {0}; DECLSPEC_SELECTANY PR_HASHTABLE apps_table = NULL; DECLSPEC_SELECTANY PR_LIST rules_list = NULL; DECLSPEC_SELECTANY PR_HASHTABLE rules_config = NULL; -DECLSPEC_SELECTANY PR_HASHTABLE network_table = NULL; DECLSPEC_SELECTANY PR_HASHTABLE log_table = NULL; DECLSPEC_SELECTANY PR_HASHTABLE cache_information = NULL; @@ -49,7 +48,6 @@ DECLSPEC_SELECTANY R_QUEUED_LOCK lock_apply = PR_QUEUED_LOCK_INIT; DECLSPEC_SELECTANY R_QUEUED_LOCK lock_rules = PR_QUEUED_LOCK_INIT; DECLSPEC_SELECTANY R_QUEUED_LOCK lock_rules_config = PR_QUEUED_LOCK_INIT; DECLSPEC_SELECTANY R_QUEUED_LOCK lock_loglist = PR_QUEUED_LOCK_INIT; -DECLSPEC_SELECTANY R_QUEUED_LOCK lock_network = PR_QUEUED_LOCK_INIT; DECLSPEC_SELECTANY R_QUEUED_LOCK lock_profile = PR_QUEUED_LOCK_INIT; DECLSPEC_SELECTANY R_QUEUED_LOCK lock_transaction = PR_QUEUED_LOCK_INIT; @@ -88,13 +86,15 @@ DECLSPEC_SELECTANY const LONG64 timer_array[] = #endif #include "controls.h" +#include "db.h" #include "editor.h" #include "helper.h" +#include "icons.h" #include "log.h" #include "messages.h" #include "network.h" #include "notifications.h" -#include "profile2.h" +#include "packages.h" #include "profile.h" #include "search.h" #include "security.h" diff --git a/src/helper.c b/src/helper.c index d7021518..8674214e 100644 --- a/src/helper.c +++ b/src/helper.c @@ -225,7 +225,7 @@ PR_STRING _app_formataddress (_In_ ADDRESS_FAMILY af, _In_ UINT8 proto, _In_ LPC if ((flags & FMTADDR_USE_PROTOCOL)) { - string = _app_getprotoname (proto, af, FALSE); + string = _app_db_getprotoname (proto, af, FALSE); if (string) { @@ -330,12 +330,10 @@ PR_STRING _app_formatport (_In_ UINT16 port, _In_ UINT8 proto) { LPCWSTR service_string; - service_string = _app_getservicename (port, proto, NULL); + service_string = _app_db_getservicename (port, proto, NULL); if (service_string) - { return _r_format_string (L"%" TEXT (PRIu16) L" (%s)", port, service_string); - } return _r_format_string (L"%" TEXT (PRIu16), port); } @@ -369,7 +367,7 @@ PVOID _app_getappinfoparam2 (_In_ ULONG_PTR app_hash, _In_ ENUM_INFO_DATA2 info) { case INFO_ICON_ID: { - return LongToPtr (_app_getdefaultappicon_id ()); + return LongToPtr (_app_icons_getdefaultapp_id ()); } } } @@ -391,11 +389,11 @@ PVOID _app_getappinfoparam2 (_In_ ULONG_PTR app_hash, _In_ ENUM_INFO_DATA2 info) { if (ptr_app_info->type == DATA_APP_UWP) { - icon_id = _app_getdefaultuwpicon_id (); + icon_id = _app_icons_getdefaultuwp_id (); } else { - icon_id = _app_getdefaultappicon_id (); + icon_id = _app_icons_getdefaultapp_id (); } result = LongToPtr (icon_id); @@ -499,184 +497,6 @@ BOOLEAN _app_isappvalidpath (_In_ PR_STRINGREF path) return TRUE; } -PICON_INFORMATION _app_getdefaulticons () -{ - static R_INITONCE init_once = PR_INITONCE_INIT; - static ICON_INFORMATION icon_info = {0}; - - if (_r_initonce_begin (&init_once)) - { - PR_STRING path; - - // load default icons - path = _r_obj_concatstrings (2, _r_sys_getsystemdirectory ()->buffer, L"\\svchost.exe"); - - _app_loadfileicon (path, &icon_info.app_icon_id, &icon_info.app_hicon, FALSE); - - // load uwp icons - if (_r_sys_isosversiongreaterorequal (WINDOWS_8)) - { - _r_obj_movereference (&path, _r_obj_concatstrings (2, _r_sys_getsystemdirectory ()->buffer, L"\\wsreset.exe")); - - _app_loadfileicon (path, &icon_info.uwp_icon_id, &icon_info.uwp_hicon, FALSE); - } - - _r_obj_dereference (path); - - _r_initonce_end (&init_once); - } - - return &icon_info; -} - -_Ret_maybenull_ -HICON _app_getdefaultapphicon () -{ - PICON_INFORMATION icon_info; - - icon_info = _app_getdefaulticons (); - - if (icon_info->app_hicon) - return CopyIcon (icon_info->app_hicon); - - return NULL; -} - -LONG _app_getdefaultappicon_id () -{ - PICON_INFORMATION icon_info; - - icon_info = _app_getdefaulticons (); - - return icon_info->app_icon_id; -} - -LONG _app_getdefaultuwpicon_id () -{ - PICON_INFORMATION icon_info; - - icon_info = _app_getdefaulticons (); - - return icon_info->uwp_icon_id; -} - -VOID _app_loadfileicon (_In_ PR_STRING path, _Out_opt_ PLONG icon_id, _Out_opt_ HICON_PTR hicon, _In_ BOOLEAN is_loaddefaults) -{ - SHFILEINFO shfi = {0}; - PICON_INFORMATION icon_info; - UINT flags; - - flags = SHGFI_LARGEICON; - - if (icon_id) - flags |= SHGFI_SYSICONINDEX; - - if (hicon) - flags |= SHGFI_ICON; - - if (SHGetFileInfo (path->buffer, 0, &shfi, sizeof (shfi), flags)) - { - if (icon_id) - *icon_id = shfi.iIcon; - - if (hicon) - *hicon = shfi.hIcon; - - return; - } - - if (!icon_id && !hicon) - return; - - if (is_loaddefaults) - { - icon_info = _app_getdefaulticons (); - - if (icon_id) - *icon_id = icon_info->app_icon_id; - - if (hicon) - { - if (icon_info->app_hicon) - { - *hicon = CopyIcon (icon_info->app_hicon); - } - else - { - *hicon = NULL; - } - } - - return; - } - - // set to null - if (icon_id) - *icon_id = 0; - - if (hicon) - *hicon = NULL; -} - -HICON _app_setdefaulticons (_In_ ENUM_TYPE_DATA type, _In_ PICON_INFORMATION icon_info) -{ - if (type == DATA_APP_UWP) - { - if (icon_info->uwp_hicon) - return CopyIcon (icon_info->uwp_hicon); - } - - if (icon_info->app_hicon) - return CopyIcon (icon_info->app_hicon); - - return NULL; -} - -HICON _app_getfileiconsafe (_In_ ULONG_PTR app_hash) -{ - PICON_INFORMATION icon_info; - PITEM_APP ptr_app; - HICON hicon; - LONG icon_id; - BOOLEAN is_iconshidded; - - icon_info = _app_getdefaulticons (); - ptr_app = _app_getappitem (app_hash); - - if (!ptr_app) - { - if (icon_info->app_hicon) - return CopyIcon (icon_info->app_hicon); - - return NULL; - } - - is_iconshidded = _r_config_getboolean (L"IsIconsHidden", FALSE); - - if (!ptr_app->real_path || is_iconshidded || !_app_isappvalidbinary (ptr_app->type, ptr_app->real_path)) - { - hicon = _app_setdefaulticons (ptr_app->type, icon_info); - - _r_obj_dereference (ptr_app); - - return hicon; - } - - _app_loadfileicon (ptr_app->real_path, &icon_id, &hicon, TRUE); - - if (!icon_id || (ptr_app->type == DATA_APP_UWP && icon_id == icon_info->app_icon_id)) - { - if (hicon) - DestroyIcon (hicon); - - hicon = _app_setdefaulticons (ptr_app->type, icon_info); - } - - _r_obj_dereference (ptr_app); - - return hicon; -} - LPCWSTR _app_getappdisplayname (_In_ PITEM_APP ptr_app, _In_ BOOLEAN is_shortened) { if (ptr_app->app_hash == config.ntoskrnl_hash) @@ -739,17 +559,17 @@ VOID _app_getfileicon (_Inout_ PITEM_APP_INFO ptr_app_info) icon_id = 0; - default_icon_id = _app_getdefaultappicon_id (); + default_icon_id = _app_icons_getdefaultapp_id (); is_iconshidded = _r_config_getboolean (L"IsIconsHidden", FALSE); if (!is_iconshidded && _app_isappvalidbinary (ptr_app_info->type, ptr_app_info->path)) - _app_loadfileicon (ptr_app_info->path, &icon_id, NULL, TRUE); + _app_icons_loadfromfile (ptr_app_info->path, &icon_id, NULL, TRUE); if (!icon_id || (ptr_app_info->type == DATA_APP_UWP && icon_id == default_icon_id)) { if (ptr_app_info->type == DATA_APP_UWP) { - icon_id = _app_getdefaultuwpicon_id (); + icon_id = _app_icons_getdefaultuwp_id (); } else { @@ -1152,1296 +972,38 @@ VOID _app_getfileversioninfo (_Inout_ PITEM_APP_INFO ptr_app_info) FreeLibrary (hlib); } -_Ret_maybenull_ -LPCWSTR _app_getservicename (_In_ UINT16 port, _In_ UINT8 proto, _In_opt_ LPCWSTR default_value) +ULONG_PTR _app_addcolor (_In_ UINT locale_id, _In_ LPCWSTR config_name, _In_ BOOLEAN is_enabled, _In_ LPCWSTR config_value, _In_ COLORREF default_clr) { - switch (port) - { - case 1: - return L"tcpmux"; - - case 7: - return L"echo"; - - case 9: - return L"discard"; - - case 11: - return L"systat"; - - case 13: - return L"daytime"; - - case 20: - return L"ftp-data"; - - case 21: - return L"ftp"; - - case 22: - return L"ssh"; - - case 23: - return L"telnet"; - - case 25: - return L"smtp"; - - case 26: - return L"rsftp"; - - case 37: - return L"time"; - - case 39: - return L"rlp"; - - case 42: - return L"nameserver"; - - case 43: - return L"nicname"; - - case 48: - return L"auditd"; - - case 53: - return L"domain"; - - case 63: - return L"whois++"; - - case 67: - case 68: - return L"dhcp"; - - case 69: - return L"tftp"; - - case 78: - return L"vettcp"; - - case 79: - case 2003: - return L"finger"; - - case 80: - return L"http"; - - case 81: - return L"hosts2-ns"; - - case 84: - return L"ctf"; - - case 88: - return L"kerberos-sec"; - - case 90: - return L"dnsix"; - - case 92: - return L"npp"; - - case 93: - return L"dcp"; - - case 94: - return L"objcall"; - - case 95: - return L"supdup"; - - case 101: - return L"hostname"; - - case 105: - return L"cso"; - - case 106: - return L"pop3pw"; - - case 107: - return L"rtelnet"; - - case 109: - return L"pop2"; - - case 110: - return L"pop3"; - - case 111: - return L"rpcbind"; - - case 112: - return L"mcidas"; - - case 113: - return L"auth"; - - case 115: - return L"sftp"; - - case 118: - return L"sqlserv"; - - case 119: - return L"nntp"; - - case 123: - return L"ntp"; - - case 126: - return L"nxedit"; - - case 129: - return L"pwdgen"; - - case 135: - return L"msrpc"; - - case 136: - return L"profile"; - - case 137: - return L"netbios-ns"; - - case 138: - return L"netbios-dgm"; - - case 139: - return L"netbios-ssn"; - - case 143: - return L"imap"; - - case 144: - return L"news"; - - case 145: - return L"uaac"; - - case 150: - return L"sql-net"; - - case 152: - return L"bftp"; - - case 156: - return L"sqlsrv"; - - case 159: - return L"nss-routing"; - - case 160: - return L"sgmp-traps"; - - case 161: - return L"snmp"; - - case 162: - return L"snmptrap"; - - case 169: - return L"send"; - - case 174: - return L"mailq"; - - case 175: - return L"vmnet"; - - case 179: - return L"bgp"; - - case 182: - return L"audit"; - - case 185: - return L"remote-kis"; - - case 186: - return L"kis"; - - case 194: - case 529: - return L"irc"; - - case 195: - return L"dn6-nlm-aud"; - - case 196: - return L"dn6-smm-red"; - - case 197: - return L"dls"; - - case 199: - return L"smux"; - - case 209: - return L"qmtp"; - - case 245: - return L"link"; - - case 280: - return L"http-mgmt"; - - case 322: - return L"rtsps"; - - case 349: - return L"mftp"; - - case 389: - return L"ldap"; - - case 427: - return L"svrloc"; - - case 443: - { - if (proto == IPPROTO_UDP) - return L"quic"; - - return L"https"; - } - - case 444: - return L"snpp"; - - case 445: - return L"microsoft-ds"; - - case 464: - return L"kerberos"; - - case 465: - return L"smtps"; - - case 500: - return L"isakmp"; - - case 513: - return L"login"; - - case 514: - return L"shell"; - - case 515: - return L"printer"; - - case 524: - return L"ncp"; - - case 530: - return L"rpc"; - - case 543: - return L"klogin"; - - case 544: - return L"kshell"; - - case 546: - return L"dhcpv6-client"; - - case 547: - return L"dhcpv6-server"; - - case 548: - return L"afp"; - - case 554: - return L"rtsp"; - - case 565: - return L"whoami"; - - case 558: - return L"sdnskmp"; - - case 585: - return L"imap4-ssl"; - - case 587: - return L"submission"; - - case 631: - return L"ipp"; - - case 636: - return L"ldaps"; - - case 646: - return L"ldp"; - - case 647: - return L"dhcp-failover"; - - case 666: - return L"doom"; // khe-khe-khe! - - case 847: - return L"dhcp-failover2"; - - case 861: - return L"owamp-control"; - - case 862: - return L"twamp-control"; - - case 873: - return L"rsync"; - - case 853: - return L"domain-s"; - - case 989: - return L"ftps-data"; - - case 990: - return L"ftps"; - - case 992: - return L"telnets"; - - case 993: - return L"imaps"; - - case 994: - return L"ircs"; - - case 995: - return L"pop3s"; - - case 1025: - return L"NFS-or-IIS"; - - case 1027: - return L"IIS"; - - case 1029: - return L"ms-lsa"; - - case 1110: - return L"nfsd"; - - case 1111: - return L"lmsocialserver"; - - case 1112: - case 1114: - case 4333: - return L"mini-sql"; - - case 1119: - return L"bnetgame"; - - case 1120: - return L"bnetfile"; - - case 1123: - return L"murray"; - - case 1194: - return L"openvpn"; - - case 1337: - return L"menandmice-dns"; - - case 1433: - return L"ms-sql-s"; - - case 1688: - return L"nsjtp-data"; + ITEM_COLOR ptr_clr = {0}; + ULONG hash_code; - case 1701: - return L"l2tp"; + ptr_clr.config_name = _r_obj_createstring (config_name); + ptr_clr.config_value = _r_obj_createstring (config_value); + ptr_clr.new_clr = _r_config_getulong_ex (config_value, default_clr, L"colors"); - case 1720: - return L"h323q931"; + ptr_clr.default_clr = default_clr; + ptr_clr.locale_id = locale_id; + ptr_clr.is_enabled = is_enabled; - case 1723: - return L"pptp"; + hash_code = _r_str_gethash2 (ptr_clr.config_value, TRUE); - case 1863: - return L"msnp"; + _r_obj_addhashtableitem (colors_table, hash_code, &ptr_clr); - case 1900: - case 5000: - return L"upnp"; + return hash_code; +} - case 2000: - return L"cisco-sccp"; +COLORREF _app_getcolorvalue (_In_ ULONG_PTR color_hash) +{ + PITEM_COLOR ptr_clr; - case 2054: - return L"weblogin"; + ptr_clr = _r_obj_findhashtable (colors_table, color_hash); - case 2086: - return L"gnunet"; - - case 2001: - return L"dc"; - - case 2121: - return L"ccproxy-ftp"; - - case 2164: - return L"ddns-v3"; - - case 2167: - return L"raw-serial"; - - case 2171: - return L"msfw-storage"; - - case 2172: - return L"msfw-s-storage"; - - case 2173: - return L"msfw-replica"; - - case 2174: - return L"msfw-array"; - - case 2371: - return L"worldwire"; - - case 2717: - return L"pn-requester"; - - case 2869: - return L"icslap"; - - case 3000: - return L"ppp"; - - case 3074: - return L"xbox"; - - case 3128: - return L"squid-http"; - - case 3306: - return L"mysql"; - - case 3389: - return L"ms-wbt-server"; - - case 3407: - return L"ldap-admin"; - - case 3540: - return L"pnrp-port"; - - case 3558: - return L"mcp-port"; - - case 3587: - return L"p2pgroup"; - - case 3702: - return L"ws-discovery"; - - case 3713: - return L"tftps"; - - case 3724: - return L"blizwow"; - - case 4500: - return L"ipsec-nat-t"; - - case 4554: - return L"msfrs"; - - case 4687: - return L"nst"; - - case 4876: - return L"tritium-can"; - - case 4899: - return L"radmin"; - - case 5004: - return L"rtp-data"; - - case 5005: - return L"rtp"; - - case 5009: - return L"airport-admin"; - - case 5051: - return L"ida-agent"; - - case 5060: - return L"sip"; - - case 5101: - return L"admdog"; - - case 5190: - return L"aol"; - - case 5350: - return L"nat-pmp-status"; - - case 5351: - return L"nat-pmp"; - - case 5352: - return L"dns-llq"; - - case 5353: - return L"mdns"; - - case 5354: - return L"mdnsresponder"; - - case 5355: - return L"llmnr"; - - case 5357: - return L"wsdapi"; - - case 5358: - return L"wsdapi-s"; - - case 5362: - return L"serverwsd2"; - - case 5432: - return L"postgresql"; - - case 5631: - return L"pcanywheredata"; - - case 5666: - return L"nrpe"; - - case 5687: - return L"gog-multiplayer"; - - case 5800: - return L"vnc-http"; - - case 5900: - return L"vnc"; - - case 5938: - return L"teamviewer"; - - case 6000: - case 6001: - case 6002: - case 6003: - return L"x11"; - - case 6222: - case 6662: // deprecated! - return L"radmind"; - - case 6346: - return L"gnutella"; - - case 6347: - return L"gnutella2"; - - case 6622: - return L"mcftp"; - - case 6665: - case 6666: - case 6667: - case 6668: - case 6669: - return L"ircu"; - - case 6881: - return L"bittorrent-tracker"; - - case 7070: - return L"realserver"; - - case 7235: - return L"aspcoordination"; - - case 8443: - return L"https-alt"; - - case 8021: - return L"ftp-proxy"; - - case 8333: - case 18333: - return L"bitcoin"; - - case 591: - case 8000: - case 8008: - case 8080: - case 8444: - return L"http-alt"; - - case 8999: - return L"bctp"; - - case 9418: - return L"git"; - - case 9800: - return L"webdav"; - - case 10107: - return L"bctp-server"; - - case 11371: - { - if (proto == IPPROTO_UDP) - return L"hkp"; - - return L"pksd"; - } - - case 25565: - return L"minecraft"; - - case 26000: - return L"quake"; - - case 27015: - return L"halflife"; - - case 27017: - case 27018: - case 27019: - case 28017: - return L"mongod"; - - case 27500: - return L"quakeworld"; - - case 27910: - return L"quake2"; - - case 27960: - return L"quake3"; - - case 28240: - return L"siemensgsm"; - - case 33434: - return L"traceroute"; - } - - return default_value; -} - -PR_STRING _app_getprotoname (_In_ ULONG proto, _In_ ADDRESS_FAMILY af, _In_ BOOLEAN is_notnull) -{ - static R_STRINGREF unknown_sr = PR_STRINGREF_INIT (SZ_UNKNOWN); - - switch (proto) - { - // NOTE: this is used for "any" protocol - case IPPROTO_HOPOPTS: - //return L"hopopt"; - break; - - case IPPROTO_ICMP: - return _r_obj_createstring (L"icmp"); - - case IPPROTO_IGMP: - return _r_obj_createstring (L"igmp"); - - case IPPROTO_GGP: - return _r_obj_createstring (L"ggp"); - - case IPPROTO_IPV4: - return _r_obj_createstring (L"ipv4"); - - case IPPROTO_ST: - return _r_obj_createstring (L"st"); - - case IPPROTO_TCP: - return _r_obj_createstring (((af == AF_INET6) ? L"tcp6" : L"tcp")); - - case IPPROTO_CBT: - return _r_obj_createstring (L"cbt"); - - case IPPROTO_EGP: - return _r_obj_createstring (L"egp"); - - case IPPROTO_IGP: - return _r_obj_createstring (L"igp"); - - case IPPROTO_PUP: - return _r_obj_createstring (L"pup"); - - case IPPROTO_UDP: - return _r_obj_createstring (((af == AF_INET6) ? L"udp6" : L"udp")); - - case IPPROTO_IDP: - return _r_obj_createstring (L"xns-idp"); - - case IPPROTO_RDP: - return _r_obj_createstring (L"rdp"); - - case IPPROTO_IPV6: - return _r_obj_createstring (L"ipv6"); - - case IPPROTO_ROUTING: - return _r_obj_createstring (L"ipv6-route"); - - case IPPROTO_FRAGMENT: - return _r_obj_createstring (L"ipv6-frag"); - - case IPPROTO_ESP: - return _r_obj_createstring (L"esp"); - - case IPPROTO_AH: - return _r_obj_createstring (L"ah"); - - case IPPROTO_ICMPV6: - return _r_obj_createstring (L"ipv6-icmp"); - - case IPPROTO_DSTOPTS: - return _r_obj_createstring (L"ipv6-opts"); - - case IPPROTO_L2TP: - return _r_obj_createstring (L"l2tp"); - - case IPPROTO_SCTP: - return _r_obj_createstring (L"sctp"); - } - - if (is_notnull) - return _r_obj_createstring3 (&unknown_sr); - - return NULL; -} - -_Ret_maybenull_ -LPCWSTR _app_getconnectionstatusname (_In_ ULONG state) -{ - switch (state) - { - case MIB_TCP_STATE_CLOSED: - return L"Closed"; - - case MIB_TCP_STATE_LISTEN: - return L"Listen"; - - case MIB_TCP_STATE_SYN_SENT: - return L"SYN sent"; - - case MIB_TCP_STATE_SYN_RCVD: - return L"SYN received"; - - case MIB_TCP_STATE_ESTAB: - return L"Established"; - - case MIB_TCP_STATE_FIN_WAIT1: - return L"FIN wait 1"; - - case MIB_TCP_STATE_FIN_WAIT2: - return L"FIN wait 2"; - - case MIB_TCP_STATE_CLOSE_WAIT: - return L"Close wait"; - - case MIB_TCP_STATE_CLOSING: - return L"Closing"; - - case MIB_TCP_STATE_LAST_ACK: - return L"Last ACK"; - - case MIB_TCP_STATE_TIME_WAIT: - return L"Time wait"; - - case MIB_TCP_STATE_DELETE_TCB: - return L"Delete TCB"; - } - - return NULL; -} - -_Ret_maybenull_ -PR_STRING _app_getdirectionname (_In_ FWP_DIRECTION direction, _In_ BOOLEAN is_loopback, _In_ BOOLEAN is_localized) -{ - LPCWSTR text = NULL; - - if (is_localized) - { - if (direction == FWP_DIRECTION_OUTBOUND) - { - text = _r_locale_getstring (IDS_DIRECTION_1); - } - else if (direction == FWP_DIRECTION_INBOUND) - { - text = _r_locale_getstring (IDS_DIRECTION_2); - } - else if (direction == FWP_DIRECTION_MAX) - { - text = _r_locale_getstring (IDS_ANY); - } - } - else - { - if (direction == FWP_DIRECTION_OUTBOUND) - { - text = SZ_DIRECTION_OUT; - } - else if (direction == FWP_DIRECTION_INBOUND) - { - text = SZ_DIRECTION_IN; - } - else if (direction == FWP_DIRECTION_MAX) - { - text = SZ_DIRECTION_ANY; - } - } - - if (!text) - return NULL; - - if (is_loopback) - return _r_obj_concatstrings (2, text, L" (" SZ_DIRECTION_LOOPBACK L")"); - - return _r_obj_createstring (text); -} - -ULONG_PTR _app_addcolor (_In_ UINT locale_id, _In_ LPCWSTR config_name, _In_ BOOLEAN is_enabled, _In_ LPCWSTR config_value, _In_ COLORREF default_clr) -{ - ITEM_COLOR ptr_clr = {0}; - ULONG hash_code; - - ptr_clr.config_name = _r_obj_createstring (config_name); - ptr_clr.config_value = _r_obj_createstring (config_value); - ptr_clr.new_clr = _r_config_getulong_ex (config_value, default_clr, L"colors"); - - ptr_clr.default_clr = default_clr; - ptr_clr.locale_id = locale_id; - ptr_clr.is_enabled = is_enabled; - - hash_code = _r_str_gethash2 (ptr_clr.config_value, TRUE); - - _r_obj_addhashtableitem (colors_table, hash_code, &ptr_clr); - - return hash_code; -} - -COLORREF _app_getcolorvalue (_In_ ULONG_PTR color_hash) -{ - PITEM_COLOR ptr_clr; - - ptr_clr = _r_obj_findhashtable (colors_table, color_hash); - - if (ptr_clr) - return ptr_clr->new_clr ? ptr_clr->new_clr : ptr_clr->default_clr; + if (ptr_clr) + return ptr_clr->new_clr ? ptr_clr->new_clr : ptr_clr->default_clr; return 0; } -VOID _app_load_appxmanifest (_Inout_ PR_STRING_PTR package_root_folder) -{ - static R_STRINGREF appx_names[] = { - PR_STRINGREF_INIT (L"AppxManifest.xml"), - PR_STRINGREF_INIT (L"VSAppxManifest.xml"), - }; - - static R_STRINGREF separator_sr = PR_STRINGREF_INIT (L"\\"); - - R_XML_LIBRARY xml_library = {0}; - PR_STRING manifest_path; - PR_STRING result_path; - PR_STRING path_string; - R_STRINGREF executable_sr; - HRESULT hr; - BOOLEAN is_success; - - path_string = *package_root_folder; - - manifest_path = NULL; - result_path = NULL; - - is_success = FALSE; - - for (SIZE_T i = 0; i < RTL_NUMBER_OF (appx_names); i++) - { - _r_obj_movereference (&manifest_path, _r_obj_concatstringrefs (3, &path_string->sr, &separator_sr, &appx_names[i])); - - if (_r_fs_exists (manifest_path->buffer)) - { - is_success = TRUE; - break; - } - } - - if (!is_success) - goto CleanupExit; - - hr = _r_xml_initializelibrary (&xml_library, TRUE, NULL); - - if (hr != S_OK) - goto CleanupExit; - - hr = _r_xml_parsefile (&xml_library, manifest_path->buffer); - - if (hr != S_OK) - goto CleanupExit; - - if (!_r_xml_findchildbytagname (&xml_library, L"Applications")) - goto CleanupExit; - - while (_r_xml_enumchilditemsbytagname (&xml_library, L"Application")) - { - if (!_r_xml_getattribute (&xml_library, L"Executable", &executable_sr)) - continue; - - _r_obj_movereference (&result_path, _r_obj_concatstringrefs (3, &path_string->sr, &separator_sr, &executable_sr)); - - if (_r_fs_exists (result_path->buffer)) - { - _r_obj_swapreference (package_root_folder, result_path); - break; - } - } - -CleanupExit: - - if (result_path) - _r_obj_dereference (result_path); - - if (manifest_path) - _r_obj_dereference (manifest_path); - - _r_xml_destroylibrary (&xml_library); -} - -VOID _app_generate_packages () -{ - PR_BYTE package_sid; - PR_STRING package_sid_string; - PR_STRING key_name; - PR_STRING display_name; - PR_STRING real_path; - ULONG_PTR app_hash; - HKEY hkey; - HKEY hsubkey; - ULONG key_index; - ULONG max_length; - ULONG size; - LSTATUS code; - - code = RegOpenKeyEx (HKEY_CURRENT_USER, L"Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppModel\\Repository\\Packages", 0, KEY_READ, &hkey); - - if (code != ERROR_SUCCESS) - return; - - max_length = _r_reg_querysubkeylength (hkey); - - if (max_length) - { - key_name = _r_obj_createstring_ex (NULL, max_length * sizeof (WCHAR)); - key_index = 0; - - while (TRUE) - { - size = max_length + 1; - - if (RegEnumKeyEx (hkey, key_index++, key_name->buffer, &size, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) - break; - - _r_obj_trimstringtonullterminator (key_name); - - code = RegOpenKeyEx (hkey, key_name->buffer, 0, KEY_READ, &hsubkey); - - if (code == ERROR_SUCCESS) - { - package_sid = _r_reg_querybinary (hsubkey, NULL, L"PackageSid"); - - if (package_sid) - { - if (RtlValidSid (package_sid->buffer)) - { - package_sid_string = _r_str_fromsid (package_sid->buffer); - - if (package_sid_string) - { - if (!_app_isappfound (_r_str_gethash2 (package_sid_string, TRUE))) - { - display_name = _r_reg_querystring (hsubkey, NULL, L"DisplayName"); - - if (display_name) - { - if (!_r_obj_isstringempty (display_name)) - { - if (display_name->buffer[0] == L'@') - { - PR_STRING localized_name; - UINT localized_length; - - localized_length = 512; - localized_name = _r_obj_createstring_ex (NULL, localized_length * sizeof (WCHAR)); - - if (SUCCEEDED (SHLoadIndirectString (display_name->buffer, localized_name->buffer, localized_length, NULL))) - { - _r_obj_trimstringtonullterminator (localized_name); - - _r_obj_movereference (&display_name, localized_name); - } - else - { - _r_obj_dereference (localized_name); - } - } - } - - // use registry key name as fallback package name - if (_r_obj_isstringempty (display_name)) - _r_obj_swapreference (&display_name, key_name); - - real_path = _r_reg_querystring (hsubkey, NULL, L"PackageRootFolder"); - - // load additional info from appx manifest - _app_load_appxmanifest (&real_path); - - app_hash = _app_addapplication (NULL, DATA_APP_UWP, &package_sid_string->sr, display_name, real_path); - - if (app_hash) - { - PITEM_APP ptr_app; - - ptr_app = _app_getappitem (app_hash); - - if (ptr_app) - { - LONG64 timestamp = _r_reg_querytimestamp (hsubkey); - - _app_setappinfo (ptr_app, INFO_TIMESTAMP_PTR, ×tamp); - _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_reference (package_sid)); - - _r_obj_dereference (ptr_app); - } - } - - if (real_path) - _r_obj_dereference (real_path); - - _r_obj_dereference (display_name); - } - } - - _r_obj_dereference (package_sid_string); - } - } - - _r_obj_dereference (package_sid); - } - - RegCloseKey (hsubkey); - } - } - - _r_obj_dereference (key_name); - } - - RegCloseKey (hkey); -} - -VOID _app_generate_services () -{ - SC_HANDLE hsvcmgr; - - hsvcmgr = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE); - - if (!hsvcmgr) - return; - - static ULONG initial_buffer_size = 0x8000; - - ULONG return_length; - ULONG services_returned; - ULONG service_type = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS; - ULONG service_state = SERVICE_STATE_ALL; - - // win10+ - if (_r_sys_isosversiongreaterorequal (WINDOWS_10)) - service_type |= SERVICE_INTERACTIVE_PROCESS | SERVICE_USER_SERVICE; - - ULONG buffer_size = initial_buffer_size; - PVOID buffer = _r_mem_allocatezero (buffer_size); - - if (!EnumServicesStatusEx (hsvcmgr, SC_ENUM_PROCESS_INFO, service_type, service_state, buffer, buffer_size, &return_length, &services_returned, NULL, NULL)) - { - if (GetLastError () == ERROR_MORE_DATA) - { - // Set the buffer - buffer_size += return_length; - buffer = _r_mem_reallocatezero (buffer, buffer_size); - - // Now query again for services - if (!EnumServicesStatusEx (hsvcmgr, SC_ENUM_PROCESS_INFO, service_type, service_state, buffer, buffer_size, &return_length, &services_returned, NULL, NULL)) - { - _r_mem_free (buffer); - buffer = NULL; - } - } - else - { - _r_mem_free (buffer); - buffer = NULL; - } - } - - // now traverse each service to get information - if (buffer) - { - WCHAR general_key[256]; - EXPLICIT_ACCESS ea; - R_STRINGREF service_name; - LPENUM_SERVICE_STATUS_PROCESS service; - LPENUM_SERVICE_STATUS_PROCESS services; - PSID service_sid; - PVOID service_sd; - PR_STRING service_path; - LONG64 service_timestamp; - ULONG_PTR app_hash; - ULONG service_type; - ULONG sd_length; - - HKEY hkey; - - services = (LPENUM_SERVICE_STATUS_PROCESS)buffer; - - for (ULONG i = 0; i < services_returned; i++) - { - service = &services[i]; - - _r_obj_initializestringref (&service_name, service->lpServiceName); - - app_hash = _r_str_gethash3 (&service_name, TRUE); - - if (_app_isappfound (app_hash)) - continue; - - _r_str_printf (general_key, RTL_NUMBER_OF (general_key), L"System\\CurrentControlSet\\Services\\%s", service->lpServiceName); - - if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, general_key, 0, KEY_READ, &hkey) != ERROR_SUCCESS) - continue; - - // skip userservice instances service types (win10+) - if (_r_sys_isosversiongreaterorequal (WINDOWS_10)) - { - service_type = _r_reg_queryulong (hkey, NULL, L"Type"); - - if (!service_type || (service_type & SERVICE_USERSERVICE_INSTANCE) != 0) - { - RegCloseKey (hkey); - continue; - } - } - - // query service path - service_path = _r_reg_querystring (hkey, L"Parameters", L"ServiceDLL"); - - if (!service_path) - { - // Windows 8 places the ServiceDll for some services in the root key. (dmex) - if (_r_sys_isosversionequal (WINDOWS_8) || _r_sys_isosversionequal (WINDOWS_8_1)) - service_path = _r_reg_querystring (hkey, NULL, L"ServiceDLL"); - - if (!service_path) - service_path = _r_reg_querystring (hkey, NULL, L"ImagePath"); - } - - if (service_path) - { - R_STRINGREF dummy_filename; - R_STRINGREF dummy_argument; - PR_STRING converted_path; - - _r_path_parsecommandlinefuzzy (&service_path->sr, &dummy_filename, &dummy_argument, &converted_path); - - if (converted_path) - { - _r_obj_movereference (&service_path, converted_path); - } - else - { - converted_path = _r_path_dospathfromnt (service_path); - - if (converted_path) - _r_obj_movereference (&service_path, converted_path); - } - - // query service timestamp - service_timestamp = _r_reg_querytimestamp (hkey); - - // query service sid - service_sid = _r_sys_getservicesid (&service_name); - - if (service_sid) - { - // 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); - - // 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. - if (BuildSecurityDescriptor (NULL, NULL, 1, &ea, 0, NULL, NULL, &sd_length, &service_sd) == ERROR_SUCCESS && service_sd) - { - PR_STRING name_string; - PITEM_APP ptr_app; - - name_string = _r_obj_createstring (service->lpDisplayName); - - app_hash = _app_addapplication (NULL, DATA_APP_SERVICE, &service_name, name_string, service_path); - - if (app_hash) - { - ptr_app = _app_getappitem (app_hash); - - if (ptr_app) - { - _app_setappinfo (ptr_app, INFO_TIMESTAMP_PTR, &service_timestamp); - _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_createbyte_ex (service_sd, sd_length)); - - _r_obj_dereference (ptr_app); - } - } - - LocalFree (service_sd); - - _r_obj_dereference (name_string); - } - - _r_mem_free (service_sid); - } - - _r_obj_dereference (service_path); - } - - RegCloseKey (hkey); - } - - _r_mem_free (buffer); - } - - CloseServiceHandle (hsvcmgr); -} - VOID _app_generate_rulescontrol (_In_ HMENU hsubmenu, _In_opt_ ULONG_PTR app_hash) { ITEM_STATUS status; @@ -3106,7 +1668,7 @@ VOID NTAPI _app_queuenotifyinformation (_In_ PVOID arglist, _In_ ULONG busy_coun } // query file icon - hicon = _app_getfileiconsafe (context->ptr_log->app_hash); + hicon = _app_icons_getsafeapp_hicon (context->ptr_log->app_hash); if (_r_wnd_isvisible (context->hwnd)) { diff --git a/src/helper.h b/src/helper.h index c2da2ed7..7a909f19 100644 --- a/src/helper.h +++ b/src/helper.h @@ -67,17 +67,6 @@ BOOLEAN _app_isappsigned (_In_ ULONG_PTR app_hash); BOOLEAN _app_isappvalidbinary (_In_ ENUM_TYPE_DATA type, _In_ PR_STRING path); BOOLEAN _app_isappvalidpath (_In_ PR_STRINGREF path); -PICON_INFORMATION _app_getdefaulticons (); - -_Ret_maybenull_ -HICON _app_getdefaultapphicon (); - -LONG _app_getdefaultappicon_id (); -LONG _app_getdefaultuwpicon_id (); - -VOID _app_loadfileicon (_In_ PR_STRING path, _Out_opt_ PLONG icon_id, _Out_opt_ HICON_PTR hicon, _In_ BOOLEAN is_loaddefaults); -HICON _app_getfileiconsafe (_In_ ULONG_PTR app_hash); - LPCWSTR _app_getappdisplayname (_In_ PITEM_APP ptr_app, _In_ BOOLEAN is_shortened); PR_STRING _app_getappname (_In_ PITEM_APP ptr_app); @@ -85,23 +74,9 @@ VOID _app_getfileicon (_Inout_ PITEM_APP_INFO ptr_app_info); VOID _app_getfilesignatureinfo (_Inout_ PITEM_APP_INFO ptr_app_info); VOID _app_getfileversioninfo (_Inout_ PITEM_APP_INFO ptr_app_info); -_Ret_maybenull_ -LPCWSTR _app_getservicename (_In_ UINT16 port, _In_ UINT8 proto, _In_opt_ LPCWSTR default_value); - -PR_STRING _app_getprotoname (_In_ ULONG proto, _In_ ADDRESS_FAMILY af, _In_ BOOLEAN is_notnull); - -_Ret_maybenull_ -LPCWSTR _app_getconnectionstatusname (_In_ ULONG state); - -_Ret_maybenull_ -PR_STRING _app_getdirectionname (_In_ FWP_DIRECTION direction, _In_ BOOLEAN is_loopback, _In_ BOOLEAN is_localized); - ULONG_PTR _app_addcolor (_In_ UINT locale_id, _In_ LPCWSTR config_name, _In_ BOOLEAN is_enabled, _In_ LPCWSTR config_value, _In_ COLORREF default_clr); COLORREF _app_getcolorvalue (_In_ ULONG_PTR color_hash); -VOID _app_generate_packages (); -VOID _app_generate_services (); - VOID _app_generate_rulescontrol (_In_ HMENU hsubmenu, _In_opt_ ULONG_PTR app_hash); VOID _app_generate_timerscontrol (_In_ HMENU hsubmenu, _In_opt_ PITEM_APP ptr_app); diff --git a/src/icons.c b/src/icons.c new file mode 100644 index 00000000..69d9ab64 --- /dev/null +++ b/src/icons.c @@ -0,0 +1,183 @@ +// simplewall +// Copyright (c) 2016-2021 Henry++ + +#include "global.h" + +PICON_INFORMATION _app_icons_getdefault () +{ + static R_INITONCE init_once = PR_INITONCE_INIT; + static ICON_INFORMATION icon_info = {0}; + + if (_r_initonce_begin (&init_once)) + { + PR_STRING path; + + // load default icons + path = _r_obj_concatstrings (2, _r_sys_getsystemdirectory ()->buffer, L"\\svchost.exe"); + + _app_icons_loadfromfile (path, &icon_info.app_icon_id, &icon_info.app_hicon, FALSE); + + // load uwp icons + if (_r_sys_isosversiongreaterorequal (WINDOWS_8)) + { + _r_obj_movereference (&path, _r_obj_concatstrings (2, _r_sys_getsystemdirectory ()->buffer, L"\\wsreset.exe")); + + _app_icons_loadfromfile (path, &icon_info.uwp_icon_id, &icon_info.uwp_hicon, FALSE); + } + + _r_obj_dereference (path); + + _r_initonce_end (&init_once); + } + + return &icon_info; +} + +_Ret_maybenull_ +HICON _app_icons_getdefaultapp_hicon () +{ + PICON_INFORMATION icon_info; + + icon_info = _app_icons_getdefault (); + + if (icon_info->app_hicon) + return CopyIcon (icon_info->app_hicon); + + return NULL; +} + +_Ret_maybenull_ +HICON _app_icons_getdefaulttype_hicon (_In_ ENUM_TYPE_DATA type, _In_ PICON_INFORMATION icon_info) +{ + if (type == DATA_APP_UWP) + { + if (icon_info->uwp_hicon) + return CopyIcon (icon_info->uwp_hicon); + } + + if (icon_info->app_hicon) + return CopyIcon (icon_info->app_hicon); + + return NULL; +} + +LONG _app_icons_getdefaultapp_id () +{ + PICON_INFORMATION icon_info; + + icon_info = _app_icons_getdefault (); + + return icon_info->app_icon_id; +} + +LONG _app_icons_getdefaultuwp_id () +{ + PICON_INFORMATION icon_info; + + icon_info = _app_icons_getdefault (); + + return icon_info->uwp_icon_id; +} + +HICON _app_icons_getsafeapp_hicon (_In_ ULONG_PTR app_hash) +{ + PICON_INFORMATION icon_info; + 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 NULL; + } + + is_iconshidded = _r_config_getboolean (L"IsIconsHidden", FALSE); + + if (!ptr_app->real_path || is_iconshidded || !_app_isappvalidbinary (ptr_app->type, ptr_app->real_path)) + { + hicon = _app_icons_getdefaulttype_hicon (ptr_app->type, icon_info); + + _r_obj_dereference (ptr_app); + + return hicon; + } + + _app_icons_loadfromfile (ptr_app->real_path, &icon_id, &hicon, TRUE); + + if (!icon_id || (ptr_app->type == DATA_APP_UWP && icon_id == icon_info->app_icon_id)) + { + if (hicon) + DestroyIcon (hicon); + + hicon = _app_icons_getdefaulttype_hicon (ptr_app->type, icon_info); + } + + _r_obj_dereference (ptr_app); + + return hicon; +} + +VOID _app_icons_loadfromfile (_In_ PR_STRING path, _Out_opt_ PLONG icon_id, _Out_opt_ HICON_PTR hicon, _In_ BOOLEAN is_loaddefaults) +{ + SHFILEINFO shfi = {0}; + PICON_INFORMATION icon_info; + UINT flags; + + flags = SHGFI_LARGEICON; + + if (icon_id) + flags |= SHGFI_SYSICONINDEX; + + if (hicon) + flags |= SHGFI_ICON; + + if (SHGetFileInfo (path->buffer, 0, &shfi, sizeof (shfi), flags)) + { + if (icon_id) + *icon_id = shfi.iIcon; + + if (hicon) + *hicon = shfi.hIcon; + + return; + } + + if (!icon_id && !hicon) + return; + + if (is_loaddefaults) + { + icon_info = _app_icons_getdefault (); + + if (icon_id) + *icon_id = icon_info->app_icon_id; + + if (hicon) + { + if (icon_info->app_hicon) + { + *hicon = CopyIcon (icon_info->app_hicon); + } + else + { + *hicon = NULL; + } + } + + return; + } + + // set to null + if (icon_id) + *icon_id = 0; + + if (hicon) + *hicon = NULL; +} diff --git a/src/icons.h b/src/icons.h new file mode 100644 index 00000000..62681ebc --- /dev/null +++ b/src/icons.h @@ -0,0 +1,19 @@ +// simplewall +// Copyright (c) 2016-2021 Henry++ + +#pragma once + +PICON_INFORMATION _app_icons_getdefault (); + +_Ret_maybenull_ +HICON _app_icons_getdefaultapp_hicon (); + +_Ret_maybenull_ +HICON _app_icons_getdefaulttype_hicon (_In_ ENUM_TYPE_DATA type, _In_ PICON_INFORMATION icon_info); + +LONG _app_icons_getdefaultapp_id (); +LONG _app_icons_getdefaultuwp_id (); + +HICON _app_icons_getsafeapp_hicon (_In_ ULONG_PTR app_hash); + +VOID _app_icons_loadfromfile (_In_ PR_STRING path, _Out_opt_ PLONG icon_id, _Out_opt_ HICON_PTR hicon, _In_ BOOLEAN is_loaddefaults); diff --git a/src/log.c b/src/log.c index 0061e0cf..7dc37aff 100644 --- a/src/log.c +++ b/src/log.c @@ -53,6 +53,8 @@ ULONG_PTR _app_getloghash (_In_ HWND hwnd, _In_ PITEM_LOG ptr_log) PR_STRING log_string; ULONG_PTR log_hash; + UNREFERENCED_PARAMETER (hwnd); + log_string = _r_format_string ( L"log-hash:%" TEXT (PRIu8) L"-%" TEXT (PR_ULONG_PTR) L"-%" TEXT (PRIu8) L"-%" TEXT (PRIu8) L"-%" TEXT (PRIu16) L"-%" TEXT (PRIu16) L"-%s-%s", ptr_log->af, @@ -173,7 +175,7 @@ VOID _app_logwrite (_In_ PITEM_LOG ptr_log) 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_getdirectionname (ptr_log->direction, ptr_log->is_loopback, FALSE); + direction_string = _app_db_getdirectionname (ptr_log->direction, ptr_log->is_loopback, FALSE); buffer = _r_format_string ( SZ_LOG_BODY, @@ -604,7 +606,7 @@ VOID CALLBACK _wfp_logcallback (_In_ PITEM_LOG_CALLBACK log) if ((log->flags & FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET)) { ptr_log->protocol = log->protocol; - ptr_log->protocol_str = _app_getprotoname (ptr_log->protocol, ptr_log->af, FALSE); + ptr_log->protocol_str = _app_db_getprotoname (ptr_log->protocol, ptr_log->af, FALSE); } // indicates FWPM_NET_EVENT_TYPE_CLASSIFY_ALLOW state @@ -1166,6 +1168,8 @@ VOID CALLBACK _wfp_logcallback0 (_In_opt_ PVOID context, _In_ const FWPM_NET_EVE { ITEM_LOG_CALLBACK log; + UNREFERENCED_PARAMETER (context); + if (log_struct_to_f (&log, (PVOID)event, WINDOWS_7)) _wfp_logcallback (&log); } @@ -1175,6 +1179,8 @@ VOID CALLBACK _wfp_logcallback1 (_In_opt_ PVOID context, _In_ const FWPM_NET_EVE { ITEM_LOG_CALLBACK log; + UNREFERENCED_PARAMETER (context); + if (log_struct_to_f (&log, (PVOID)event, WINDOWS_8)) _wfp_logcallback (&log); } @@ -1184,6 +1190,8 @@ VOID CALLBACK _wfp_logcallback2 (_In_opt_ PVOID context, _In_ const FWPM_NET_EVE { ITEM_LOG_CALLBACK log; + UNREFERENCED_PARAMETER (context); + if (log_struct_to_f (&log, (PVOID)event, WINDOWS_10_1607)) _wfp_logcallback (&log); } @@ -1193,6 +1201,8 @@ VOID CALLBACK _wfp_logcallback3 (_In_opt_ PVOID context, _In_ const FWPM_NET_EVE { ITEM_LOG_CALLBACK log; + UNREFERENCED_PARAMETER (context); + if (log_struct_to_f (&log, (PVOID)event, WINDOWS_10_1803)) _wfp_logcallback (&log); } @@ -1202,6 +1212,8 @@ VOID CALLBACK _wfp_logcallback4 (_In_opt_ PVOID context, _In_ const FWPM_NET_EVE { ITEM_LOG_CALLBACK log; + UNREFERENCED_PARAMETER (context); + if (log_struct_to_f (&log, (PVOID)event, WINDOWS_10_1809)) _wfp_logcallback (&log); } diff --git a/src/main.c b/src/main.c index fb42046f..dcd0a78b 100644 --- a/src/main.c +++ b/src/main.c @@ -558,7 +558,7 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam LONG icon_id; INT item_id; - icon_id = _app_getdefaultappicon_id (); + icon_id = _app_icons_getdefaultapp_id (); _app_setcheckboxlock (hwnd, IDC_COLORS, TRUE); @@ -1635,7 +1635,7 @@ VOID _app_initialize () _app_generate_credentials (); // load default icons - _app_getdefaulticons (); + _app_icons_getdefault (); // initialize global filters array object if (!filter_ids) @@ -1657,10 +1657,6 @@ VOID _app_initialize () if (!log_table) log_table = _r_obj_createhashtablepointer (32); - // initialize network table - if (!network_table) - network_table = _r_obj_createhashtablepointer (32); - // initialize cache table if (!cache_information) cache_information = _r_obj_createhashtablepointer (32); @@ -1917,6 +1913,8 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In _r_config_setlong (L"CurrentTab", _app_getcurrentlistview_id (hwnd)); + _app_network_uninitialize (); + _r_tray_destroy (hwnd, &GUID_TrayIcon); _app_loginit (FALSE); @@ -2461,7 +2459,10 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In hengine = _wfp_getenginehandle (); if (hengine) + { + _app_network_unsubscribe (hengine); _wfp_logunsubscribe (hengine); + } } SetWindowLongPtr (hwnd, DWLP_MSGRESULT, TRUE); @@ -2478,7 +2479,10 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In hengine = _wfp_getenginehandle (); if (hengine) + { + _app_network_subscribe (hengine); _wfp_logsubscribe (hengine); + } } SetWindowLongPtr (hwnd, DWLP_MSGRESULT, TRUE); diff --git a/src/messages.c b/src/messages.c index 8b340fd8..e492436c 100644 --- a/src/messages.c +++ b/src/messages.c @@ -777,7 +777,7 @@ VOID _app_displayinforule_callback (_In_ INT listview_id, _In_ PITEM_RULE ptr_ru case 2: { - string = _app_getdirectionname (ptr_rule->direction, FALSE, TRUE); + string = _app_db_getdirectionname (ptr_rule->direction, FALSE, TRUE); if (string) { @@ -934,7 +934,7 @@ VOID _app_displayinfonetwork_callback (_In_ PITEM_NETWORK ptr_network, _Inout_ L case 8: { - name = _app_getconnectionstatusname (ptr_network->state); + name = _app_db_getconnectionstatename (ptr_network->state); if (name) _r_str_copy (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, name); @@ -1104,7 +1104,7 @@ VOID _app_displayinfolog_callback (_Inout_ LPNMLVDISPINFOW lpnmlv, _In_opt_ PITE case 8: { - string = _app_getdirectionname (ptr_log->direction, ptr_log->is_loopback, FALSE); + string = _app_db_getdirectionname (ptr_log->direction, ptr_log->is_loopback, FALSE); if (string) { diff --git a/src/notifications.c b/src/notifications.c index 0b978ad5..0fe1679b 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -293,7 +293,7 @@ VOID _app_notify_setapp_icon (_In_ HWND hwnd, _In_opt_ HICON hicon, _In_ BOOLEAN return; if (!hicon) - hicon = _app_getdefaultapphicon (); + hicon = _app_icons_getdefaultapp_hicon (); hicon_prev = context->hicon; context->hicon = hicon; @@ -374,7 +374,7 @@ VOID _app_notify_show (_In_ HWND hwnd, _In_ PITEM_LOG ptr_log, _In_ BOOLEAN is_f // print direction _r_obj_movereference (&localized_string, _r_obj_concatstrings (2, _r_locale_getstring (IDS_DIRECTION), L":")); - _r_obj_movereference (&string, _app_getdirectionname (ptr_log->direction, ptr_log->is_loopback, TRUE)); + _r_obj_movereference (&string, _app_db_getdirectionname (ptr_log->direction, ptr_log->is_loopback, TRUE)); _r_ctrl_settablestring (hwnd, IDC_DIRECTION_ID, &localized_string->sr, IDC_DIRECTION_TEXT, string ? &string->sr : &empty_sr); @@ -830,7 +830,7 @@ INT_PTR CALLBACK NotificationProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wp if (hdc) { - _r_dc_drawwindowdefault (hdc, hwnd, TRUE); + _r_dc_drawwindow (hdc, hwnd, TRUE); EndPaint (hwnd, &ps); } diff --git a/src/packages.c b/src/packages.c new file mode 100644 index 00000000..5d135048 --- /dev/null +++ b/src/packages.c @@ -0,0 +1,409 @@ +// simplewall +// Copyright (c) 2016-2021 Henry++ + +#include "global.h" + +VOID _app_package_getpackageinfo (_Inout_ PR_STRING_PTR package_root_folder) +{ + static R_STRINGREF appx_names[] = { + PR_STRINGREF_INIT (L"AppxManifest.xml"), + PR_STRINGREF_INIT (L"VSAppxManifest.xml"), + }; + + static R_STRINGREF separator_sr = PR_STRINGREF_INIT (L"\\"); + + R_XML_LIBRARY xml_library = {0}; + PR_STRING manifest_path; + PR_STRING result_path; + PR_STRING path_string; + R_STRINGREF executable_sr; + HRESULT hr; + BOOLEAN is_success; + + path_string = *package_root_folder; + + manifest_path = NULL; + result_path = NULL; + + is_success = FALSE; + + for (SIZE_T i = 0; i < RTL_NUMBER_OF (appx_names); i++) + { + _r_obj_movereference (&manifest_path, _r_obj_concatstringrefs (3, &path_string->sr, &separator_sr, &appx_names[i])); + + if (_r_fs_exists (manifest_path->buffer)) + { + is_success = TRUE; + break; + } + } + + if (!is_success) + goto CleanupExit; + + hr = _r_xml_initializelibrary (&xml_library, TRUE, NULL); + + if (hr != S_OK) + goto CleanupExit; + + hr = _r_xml_parsefile (&xml_library, manifest_path->buffer); + + if (hr != S_OK) + goto CleanupExit; + + if (!_r_xml_findchildbytagname (&xml_library, L"Applications")) + goto CleanupExit; + + while (_r_xml_enumchilditemsbytagname (&xml_library, L"Application")) + { + if (!_r_xml_getattribute (&xml_library, L"Executable", &executable_sr)) + continue; + + _r_obj_movereference (&result_path, _r_obj_concatstringrefs (3, &path_string->sr, &separator_sr, &executable_sr)); + + if (_r_fs_exists (result_path->buffer)) + { + _r_obj_swapreference (package_root_folder, result_path); + break; + } + } + +CleanupExit: + + if (result_path) + _r_obj_dereference (result_path); + + if (manifest_path) + _r_obj_dereference (manifest_path); + + _r_xml_destroylibrary (&xml_library); +} + +VOID _app_package_getpackageslist () +{ + PR_BYTE package_sid; + PR_STRING package_sid_string; + PR_STRING key_name; + PR_STRING display_name; + PR_STRING localized_name; + PR_STRING real_path; + PITEM_APP ptr_app; + LONG64 timestamp; + ULONG_PTR app_hash; + UINT localized_length; + HKEY hkey; + HKEY hsubkey; + ULONG key_index; + ULONG max_length; + ULONG size; + LSTATUS code; + + code = RegOpenKeyEx ( + HKEY_CURRENT_USER, + L"Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppModel\\Repository\\Packages", + 0, + KEY_READ, + &hkey + ); + + if (code != ERROR_SUCCESS) + return; + + max_length = _r_reg_querysubkeylength (hkey); + + if (max_length) + { + key_index = 0; + key_name = _r_obj_createstring_ex (NULL, max_length * sizeof (WCHAR)); + + while (TRUE) + { + size = max_length + 1; + + if (RegEnumKeyEx (hkey, key_index++, key_name->buffer, &size, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) + break; + + _r_obj_trimstringtonullterminator (key_name); + + code = RegOpenKeyEx (hkey, key_name->buffer, 0, KEY_READ, &hsubkey); + + if (code == ERROR_SUCCESS) + { + package_sid = _r_reg_querybinary (hsubkey, NULL, L"PackageSid"); + + if (package_sid) + { + if (RtlValidSid (package_sid->buffer)) + { + package_sid_string = _r_str_fromsid (package_sid->buffer); + + if (package_sid_string) + { + if (!_app_isappfound (_r_str_gethash2 (package_sid_string, TRUE))) + { + display_name = _r_reg_querystring (hsubkey, NULL, L"DisplayName"); + + if (display_name) + { + if (!_r_obj_isstringempty2 (display_name)) + { + if (display_name->buffer[0] == L'@') + { + localized_length = 512; + localized_name = _r_obj_createstring_ex (NULL, localized_length * sizeof (WCHAR)); + + if (SUCCEEDED (SHLoadIndirectString (display_name->buffer, localized_name->buffer, localized_length, NULL))) + { + _r_obj_trimstringtonullterminator (localized_name); + + _r_obj_movereference (&display_name, localized_name); + } + else + { + _r_obj_dereference (localized_name); + } + } + } + + // use registry key name as fallback package name + if (_r_obj_isstringempty (display_name)) + _r_obj_swapreference (&display_name, key_name); + + real_path = _r_reg_querystring (hsubkey, NULL, L"PackageRootFolder"); + + // load additional info from appx manifest + _app_package_getpackageinfo (&real_path); + + app_hash = _app_addapplication (NULL, DATA_APP_UWP, &package_sid_string->sr, display_name, real_path); + + if (app_hash) + { + ptr_app = _app_getappitem (app_hash); + + if (ptr_app) + { + timestamp = _r_reg_querytimestamp (hsubkey); + + _app_setappinfo (ptr_app, INFO_TIMESTAMP_PTR, ×tamp); + _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_reference (package_sid)); + + _r_obj_dereference (ptr_app); + } + } + + if (real_path) + _r_obj_dereference (real_path); + + _r_obj_dereference (display_name); + } + } + + _r_obj_dereference (package_sid_string); + } + } + + _r_obj_dereference (package_sid); + } + + RegCloseKey (hsubkey); + } + } + + _r_obj_dereference (key_name); + } + + RegCloseKey (hkey); +} + +VOID _app_package_getserviceslist () +{ + static ULONG initial_buffer_size = 0x8000; + + SC_HANDLE hsvcmgr; + + WCHAR general_key[256]; + EXPLICIT_ACCESS ea; + R_STRINGREF service_name; + LPENUM_SERVICE_STATUS_PROCESS service; + LPENUM_SERVICE_STATUS_PROCESS services; + PSID service_sid; + PVOID service_sd; + PR_STRING service_path; + LONG64 service_timestamp; + ULONG_PTR app_hash; + ULONG service_type; + ULONG service_state; + ULONG sd_length; + + PR_STRING name_string; + PITEM_APP ptr_app; + + R_STRINGREF dummy_filename; + R_STRINGREF dummy_argument; + PR_STRING converted_path; + + PVOID buffer; + ULONG buffer_size; + + ULONG return_length; + ULONG services_returned; + + HKEY hkey; + + hsvcmgr = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE); + + if (!hsvcmgr) + return; + + service_type = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS; + service_state = SERVICE_STATE_ALL; + + // win10+ + if (_r_sys_isosversiongreaterorequal (WINDOWS_10)) + service_type |= SERVICE_INTERACTIVE_PROCESS | SERVICE_USER_SERVICE; + + buffer_size = initial_buffer_size; + buffer = _r_mem_allocatezero (buffer_size); + + if (!EnumServicesStatusEx (hsvcmgr, SC_ENUM_PROCESS_INFO, service_type, service_state, buffer, buffer_size, &return_length, &services_returned, NULL, NULL)) + { + if (GetLastError () == ERROR_MORE_DATA) + { + // Set the buffer + buffer_size += return_length; + buffer = _r_mem_reallocatezero (buffer, buffer_size); + + // Now query again for services + if (!EnumServicesStatusEx (hsvcmgr, SC_ENUM_PROCESS_INFO, service_type, service_state, buffer, buffer_size, &return_length, &services_returned, NULL, NULL)) + { + _r_mem_free (buffer); + buffer = NULL; + } + } + else + { + _r_mem_free (buffer); + buffer = NULL; + } + } + + // now traverse each service to get information + if (buffer) + { + services = (LPENUM_SERVICE_STATUS_PROCESS)buffer; + + for (ULONG i = 0; i < services_returned; i++) + { + service = &services[i]; + + _r_obj_initializestringref (&service_name, service->lpServiceName); + + app_hash = _r_str_gethash3 (&service_name, TRUE); + + if (_app_isappfound (app_hash)) + continue; + + _r_str_printf (general_key, RTL_NUMBER_OF (general_key), L"System\\CurrentControlSet\\Services\\%s", service->lpServiceName); + + if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, general_key, 0, KEY_READ, &hkey) != ERROR_SUCCESS) + continue; + + // skip userservice instances service types (win10+) + if (_r_sys_isosversiongreaterorequal (WINDOWS_10)) + { + service_type = _r_reg_queryulong (hkey, NULL, L"Type"); + + if (!service_type || (service_type & SERVICE_USERSERVICE_INSTANCE) != 0) + { + RegCloseKey (hkey); + continue; + } + } + + // query service path + service_path = _r_reg_querystring (hkey, L"Parameters", L"ServiceDLL"); + + if (!service_path) + { + // Windows 8 places the ServiceDll for some services in the root key. (dmex) + if (_r_sys_isosversionequal (WINDOWS_8) || _r_sys_isosversionequal (WINDOWS_8_1)) + service_path = _r_reg_querystring (hkey, NULL, L"ServiceDLL"); + + if (!service_path) + service_path = _r_reg_querystring (hkey, NULL, L"ImagePath"); + } + + if (service_path) + { + _r_path_parsecommandlinefuzzy (&service_path->sr, &dummy_filename, &dummy_argument, &converted_path); + + if (converted_path) + { + _r_obj_movereference (&service_path, converted_path); + } + else + { + converted_path = _r_path_dospathfromnt (service_path); + + if (converted_path) + _r_obj_movereference (&service_path, converted_path); + } + + // query service timestamp + service_timestamp = _r_reg_querytimestamp (hkey); + + // query service sid + service_sid = _r_sys_getservicesid (&service_name); + + if (service_sid) + { + // 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); + + // 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. + if (BuildSecurityDescriptor (NULL, NULL, 1, &ea, 0, NULL, NULL, &sd_length, &service_sd) == ERROR_SUCCESS && service_sd) + { + name_string = _r_obj_createstring (service->lpDisplayName); + + app_hash = _app_addapplication (NULL, DATA_APP_SERVICE, &service_name, name_string, service_path); + + if (app_hash) + { + ptr_app = _app_getappitem (app_hash); + + if (ptr_app) + { + _app_setappinfo (ptr_app, INFO_TIMESTAMP_PTR, &service_timestamp); + _app_setappinfo (ptr_app, INFO_BYTES_DATA, _r_obj_createbyte_ex (service_sd, sd_length)); + + _r_obj_dereference (ptr_app); + } + } + + LocalFree (service_sd); + + _r_obj_dereference (name_string); + } + + _r_mem_free (service_sid); + } + + _r_obj_dereference (service_path); + } + + RegCloseKey (hkey); + } + + _r_mem_free (buffer); + } + + CloseServiceHandle (hsvcmgr); +} diff --git a/src/packages.h b/src/packages.h new file mode 100644 index 00000000..38c3b907 --- /dev/null +++ b/src/packages.h @@ -0,0 +1,9 @@ +// simplewall +// Copyright (c) 2016-2021 Henry++ + +#pragma once + +VOID _app_package_getpackageinfo (_Inout_ PR_STRING_PTR package_root_folder); + +VOID _app_package_getpackageslist (); +VOID _app_package_getserviceslist ();