diff --git a/src/helper.hpp b/src/helper.hpp index c6439db2..143a57ec 100644 --- a/src/helper.hpp +++ b/src/helper.hpp @@ -12,14 +12,14 @@ void _app_setinterfacestate (HWND hwnd); void _app_applycasestyle (LPWSTR buffer, size_t length); -bool _app_formataddress (ADDRESS_FAMILY af, PVOID const ptr_addr, UINT16 port, LPWSTR *ptr_dest, bool is_appenddns); +bool _app_formataddress (ADDRESS_FAMILY af, PVOID const ptr_addr, UINT16 port, LPWSTR* ptr_dest, bool is_appenddns, bool is_appendarpa = false); void _app_freearray (std::vector* ptr); void _app_freecache (MCACHE_MAP* ptr_map); void _app_freethreadpool (MTHREADPOOL* ptr_pool); void _app_freelogstack (); -void _app_getappicon (ITEM_APP const *ptr_app, bool is_small, size_t* picon_id, HICON* picon); -void _app_getdisplayname (size_t hash, ITEM_APP const *ptr_app, LPWSTR* extracted_name); +void _app_getappicon (ITEM_APP const* ptr_app, bool is_small, size_t* picon_id, HICON* picon); +void _app_getdisplayname (size_t hash, ITEM_APP const* ptr_app, LPWSTR* extracted_name); bool _app_getfileicon (LPCWSTR path, bool is_small, size_t* picon_id, HICON* picon); rstring _app_getshortcutpath (HWND hwnd, LPCWSTR path); bool _app_getsignatureinfo (size_t hash, LPCWSTR path, LPWSTR* psigner); @@ -28,13 +28,13 @@ size_t _app_getposition (HWND hwnd, UINT listview_id, size_t idx); rstring _app_getprotoname (UINT8 proto); rstring _app_getstatename (DWORD state); -void _app_generate_connections (); +void _app_generate_connections (std::vector& ptr_arr); void _app_generate_packages (); void _app_generate_services (); void _app_generate_rulesmenu (HMENU hsubmenu, size_t app_hash); -bool _app_item_get (EnumDataType type, size_t hash, rstring* display_name, rstring* real_path, PSID* lpsid, PSECURITY_DESCRIPTOR* lpsd, rstring* /*description*/); +bool _app_item_get (EnumDataType type, size_t hash, rstring* display_name, rstring* real_path, PBYTE* lpdata, rstring* /*description*/); INT CALLBACK _app_listviewcompare_callback (LPARAM lp1, LPARAM lp2, LPARAM lparam); void _app_listviewsort (HWND hwnd, UINT listview_id, INT subitem = -1, bool is_notifycode = false); @@ -47,7 +47,7 @@ rstring _app_parsehostaddress_wsa (LPCWSTR hostname, USHORT port); bool _app_parsenetworkstring (LPCWSTR network_string, NET_ADDRESS_FORMAT* format_ptr, USHORT* port_ptr, FWP_V4_ADDR_AND_MASK* paddr4, FWP_V6_ADDR_AND_MASK* paddr6, LPWSTR paddr_dns, size_t dns_length); bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr); -bool _app_resolveaddress (ADDRESS_FAMILY af, LPVOID paddr, LPWSTR buffer, DWORD length); +bool _app_resolveaddress (ADDRESS_FAMILY af, LPVOID paddr, LPWSTR* pbuffer); void _app_resolvefilename (rstring& path); UINT _app_getlistview_id (EnumDataType type); diff --git a/src/log.cpp b/src/log.cpp index 1bf797a9..1cf03f3a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -387,7 +387,7 @@ void CALLBACK _wfp_logcallback (UINT32 flags, FILETIME const *pft, UINT8 const * { sidstring = _r_str_fromsid (package_id); - if (sidstring.IsEmpty () || !_app_item_get (DataAppUWP, sidstring.Hash (), nullptr, nullptr, nullptr, nullptr, nullptr)) + if (sidstring.IsEmpty () || !_app_item_get (DataAppUWP, sidstring.Hash (), nullptr, nullptr, nullptr, nullptr)) sidstring.Clear (); } diff --git a/src/main.hpp b/src/main.hpp index 50330695..f15f7026 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -22,7 +22,7 @@ #pragma comment(lib, "wintrust.lib") #pragma comment(lib, "windowscodecs.lib") -// guid +// guids extern "C" { static const GUID GUID_WfpProvider = {0xb0d553e2, 0xc6a0, 0x4a9a, {0xae, 0xb8, 0xc7, 0x52, 0x48, 0x3e, 0xd6, 0x2f}}; @@ -65,7 +65,8 @@ enum EnumDataType DataRuleCustom, DataTypePort, DataTypeIp, - DataTypeHost + DataTypeHost, + DataRulesConfig }; enum EnumXmlType @@ -73,6 +74,8 @@ enum EnumXmlType XmlApps = 0, XmlRules = 1, XmlRulesConfig = 2, + XmlProfileV3 = 3, + XmlProfileInternalV3 = 4, }; INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); @@ -83,11 +86,12 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam #define LANG_MENU 6 #define UID 1984 // if you want to keep a secret, you must also hide it from yourself. +#define XML_PROFILE L"profile.xml" +#define XML_PROFILE_INTERNAL L"profile_internal.xml" + #define XML_APPS L"apps.xml" -#define XML_BLOCKLIST L"blocklist.xml" #define XML_RULES_CONFIG L"rules_config.xml" #define XML_RULES_CUSTOM L"rules_custom.xml" -#define XML_RULES_SYSTEM L"rules_system.xml" #define LOG_DIV L',' #define LOG_PATH_EXT L"log" @@ -201,9 +205,11 @@ typedef std::vector MARRAY; struct STATIC_DATA { + WCHAR profile_path[MAX_PATH] = {0}; + WCHAR profile_path_backup[MAX_PATH] = {0}; + WCHAR profile_internal_path[MAX_PATH] = {0}; + WCHAR apps_path[MAX_PATH] = {0}; - WCHAR rules_blocklist_path[MAX_PATH] = {0}; - WCHAR rules_system_path[MAX_PATH] = {0}; WCHAR rules_custom_path[MAX_PATH] = {0}; WCHAR rules_config_path[MAX_PATH] = {0}; @@ -224,6 +230,8 @@ struct STATIC_DATA LPGUID psession = nullptr; HIMAGELIST himg = nullptr; + HIMAGELIST himg2 = nullptr; + HANDLE hengine = nullptr; HANDLE hlogfile = nullptr; HANDLE hnetevent = nullptr; @@ -237,8 +245,7 @@ struct STATIC_DATA HWND hrebar = nullptr; HWND hfind = nullptr; - time_t blocklist_timestamp = 0; - time_t rule_system_timestamp = 0; + time_t profile_internal_timestamp = 0; size_t ntoskrnl_hash = 0; size_t svchost_hash = 0; @@ -279,11 +286,7 @@ typedef struct tagITEM_APP LPWSTR description = nullptr; LPWSTR signer = nullptr; - union - { - PSECURITY_DESCRIPTOR psd = nullptr; // service app - PSID psid; // store app (win8+) - }; + PBYTE pdata = nullptr; // service - PSECURITY_DESCRIPTOR / uwp - PSID (win8+) HANDLE htimer = nullptr; @@ -488,7 +491,7 @@ typedef struct tagITEM_ADD service_name = nullptr; real_path = nullptr; - psid = nullptr; + pdata = nullptr; } ~tagITEM_ADD () @@ -509,11 +512,7 @@ typedef struct tagITEM_ADD LPWSTR sid = nullptr; LPWSTR service_name = nullptr; - union - { - PSID psid = nullptr; - PSECURITY_DESCRIPTOR psd; - }; + PVOID pdata = nullptr; // service - PSECURITY_DESCRIPTOR / uwp - PSID (win8+) } ITEM_ADD, *PITEM_ADD; typedef struct tagITEM_COLOR diff --git a/src/wfp.cpp b/src/wfp.cpp index 016e2bf9..b4ef9d25 100644 --- a/src/wfp.cpp +++ b/src/wfp.cpp @@ -40,11 +40,8 @@ bool _wfp_initialize (bool is_full) { config.psession = new GUID; - if (config.psession) - { - if (CoCreateGuid (config.psession) != S_OK) - SAFE_DELETE (config.psession); - } + if (CoCreateGuid (config.psession) != S_OK) + SAFE_DELETE (config.psession); } SecureZeroMemory (&session, sizeof (session)); @@ -726,12 +723,12 @@ bool _wfp_createrulefilter (LPCWSTR name, size_t app_hash, LPCWSTR rule_remote, if (ptr_app->type == DataAppUWP) // windows store app (win8+) { - if (ptr_app->psid) + if (ptr_app->pdata) { fwfc[count].fieldKey = FWPM_CONDITION_ALE_PACKAGE_ID; fwfc[count].matchType = FWP_MATCH_EQUAL; fwfc[count].conditionValue.type = FWP_SID; - fwfc[count].conditionValue.sid = (SID*)ptr_app->psid; + fwfc[count].conditionValue.sid = (SID*)ptr_app->pdata; count += 1; } @@ -756,7 +753,7 @@ bool _wfp_createrulefilter (LPCWSTR name, size_t app_hash, LPCWSTR rule_remote, count += 1; } - if (ptr_app->psd && ByteBlobAlloc (ptr_app->psd, GetSecurityDescriptorLength (ptr_app->psd), &bSid)) + if (ptr_app->pdata && ByteBlobAlloc (ptr_app->pdata, GetSecurityDescriptorLength (ptr_app->pdata), &bSid)) { fwfc[count].fieldKey = FWPM_CONDITION_ALE_USER_ID; fwfc[count].matchType = FWP_MATCH_EQUAL; @@ -1871,21 +1868,12 @@ bool ByteBlobAlloc (PVOID data, size_t length, FWP_BYTE_BLOB * *lpblob) { const PUINT8 tmp_ptr = new UINT8[length]; - if (!tmp_ptr) - { - SAFE_DELETE (*lpblob); + (*lpblob)->data = tmp_ptr; + (*lpblob)->size = (UINT32)length; - return false; - } - else - { - (*lpblob)->data = tmp_ptr; - (*lpblob)->size = (UINT32)length; + CopyMemory ((*lpblob)->data, data, length); - CopyMemory ((*lpblob)->data, data, length); - - return true; - } + return true; } return false;