diff --git a/src/profile.cpp b/src/profile.cpp index 191d712c..45fda0fb 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -44,7 +44,7 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti { ptr_app->type = DataAppUWP; - _app_item_get (DataAppUWP, app_hash, nullptr, &real_path, &ptr_app->psid, nullptr, nullptr); + _app_item_get (DataAppUWP, app_hash, nullptr, &real_path, &ptr_app->pdata, nullptr); } else if (PathIsNetworkPath (path)) // network path { @@ -58,7 +58,7 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti if (!is_ntoskrnl && real_path.Find (OBJ_NAME_PATH_SEPARATOR) == rstring::npos) { - if (_app_item_get (DataAppService, app_hash, nullptr, &real_path, nullptr, &ptr_app->psd, nullptr)) + if (_app_item_get (DataAppService, app_hash, nullptr, &real_path, &ptr_app->pdata, nullptr)) ptr_app->type = DataAppService; else @@ -188,8 +188,7 @@ bool _app_freeapplication (size_t hash) SAFE_DELETE_ARRAY (ptr_app->description); SAFE_DELETE_ARRAY (ptr_app->signer); - SAFE_DELETE_ARRAY (ptr_app->psid); - SAFE_DELETE_ARRAY (ptr_app->psd); + SAFE_DELETE_ARRAY (ptr_app->pdata); } if (hash) @@ -277,7 +276,7 @@ void _app_getcount (PITEM_STATUS ptr_status) for (auto const &p : apps) { - const ITEM_APP *ptr_app = &p.second; + const ITEM_APP* ptr_app = &p.second; const bool is_used = _app_isappused (ptr_app, p.first); if (_app_istimeractive (ptr_app)) @@ -394,14 +393,14 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) { rstring display_name; - if (_app_item_get (ptr_app->type, idx, &display_name, nullptr, nullptr, nullptr, nullptr)) + if (_app_item_get (ptr_app->type, idx, &display_name, nullptr, nullptr, nullptr)) result.AppendFormat (L"\r\n%s:\r\n" SZ_TAB L"%s\r\n" SZ_TAB L"%s" SZ_TAB, app.LocaleString (IDS_FILE, nullptr).GetString (), ptr_app->original_path, display_name.GetString ()); } else if (ptr_app->type == DataAppUWP) { rstring display_name; - if (_app_item_get (ptr_app->type, idx, &display_name, nullptr, nullptr, nullptr, nullptr)) + if (_app_item_get (ptr_app->type, idx, &display_name, nullptr, nullptr, nullptr)) result.AppendFormat (L"\r\n%s:\r\n" SZ_TAB L"%s" SZ_TAB, app.LocaleString (IDS_FILE, nullptr).GetString (), display_name.GetString ()); } @@ -528,24 +527,58 @@ void _app_ruleenable (PITEM_RULE ptr_rule, bool is_enable) if (ptr_rule->is_readonly && ptr_rule->pname) { - const size_t hash = _r_str_hash (ptr_rule->pname); + const size_t rule_hash = _r_str_hash (ptr_rule->pname); - if (rules_config.find (hash) != rules_config.end ()) + if (rule_hash) { - PITEM_RULE_CONFIG* ptr_config = &rules_config[hash]; + if (rules_config.find (rule_hash) != rules_config.end ()) + { + PITEM_RULE_CONFIG* ptr_config = &rules_config[rule_hash]; - if (!*ptr_config) - *ptr_config = new ITEM_RULE_CONFIG; + if (!*ptr_config) + * ptr_config = new ITEM_RULE_CONFIG; - (*ptr_config)->is_enabled = is_enable; + (*ptr_config)->is_enabled = is_enable; + } + else + { + PITEM_RULE_CONFIG ptr_config = new ITEM_RULE_CONFIG; + + ptr_config->is_enabled = is_enable; + + rules_config[rule_hash] = ptr_config; + } } - else + } +} + +void _app_ruleblocklistset () +{ + const bool is_blockspy = app.ConfigGet (L"BlocklistBlockSpy", true).AsBool (); + const bool is_allowupdate = app.ConfigGet (L"BlocklistAllowUpdate", false).AsBool (); + const bool is_allowextra = app.ConfigGet (L"BlocklistAllowExtra", false).AsBool (); + + for (size_t i = 0; i < rules_arr.size (); i++) + { + PITEM_RULE ptr_rule = rules_arr.at (i); + + if (!ptr_rule || ptr_rule->type != DataRuleBlocklist || !ptr_rule->pname || !ptr_rule->pname[0]) + continue; + + if (_wcsnicmp (ptr_rule->pname, L"spy_", 4) == 0) { - PITEM_RULE_CONFIG ptr_config = new ITEM_RULE_CONFIG; - - ptr_config->is_enabled = is_enable; - - rules_config[hash] = ptr_config; + ptr_rule->is_block = true; + ptr_rule->is_enabled = is_blockspy; + } + else if (_wcsnicmp (ptr_rule->pname, L"update_", 7) == 0) + { + ptr_rule->is_block = !is_allowupdate; + ptr_rule->is_enabled = true; + } + else if (_wcsnicmp (ptr_rule->pname, L"extra_", 6) == 0) + { + ptr_rule->is_block = !is_allowextra; + ptr_rule->is_enabled = true; } } } @@ -569,7 +602,7 @@ rstring _app_rulesexpand (PITEM_RULE const ptr_rule, bool is_forservices, LPCWST for (auto const &p : ptr_rule->apps) { - ITEM_APP const *ptr_app = _app_getapplication (p.first); + ITEM_APP const* ptr_app = _app_getapplication (p.first); if (ptr_app) { @@ -594,47 +627,50 @@ rstring _app_rulesexpand (PITEM_RULE const ptr_rule, bool is_forservices, LPCWST return result; } -bool _app_isapphaveconnection (size_t hash) +bool _app_isapphaveconnection (size_t app_hash) { - if (!hash) + if (!app_hash) return false; for (size_t i = 0; i < network_arr.size (); i++) { - PITEM_NETWORK const ptr_network = network_arr.at (i); + const PITEM_NETWORK ptr_network = network_arr.at (i); - if (ptr_network && ptr_network->hash == hash && (ptr_network->state == MIB_TCP_STATE_ESTAB)) - return true; + if (ptr_network && ptr_network->hash == app_hash) + { + if ((ptr_network->protocol == IPPROTO_TCP && (ptr_network->state == MIB_TCP_STATE_ESTAB || ptr_network->state == MIB_TCP_STATE_LISTEN)) || (ptr_network->protocol == IPPROTO_UDP && !ptr_network->state)) + return true; + } } return false; } -bool _app_isapphaverule (size_t hash) +bool _app_isapphaverule (size_t app_hash) { - if (!hash) + if (!app_hash) return false; for (size_t i = 0; i < rules_arr.size (); i++) { PITEM_RULE const ptr_rule = rules_arr.at (i); - if (ptr_rule && ptr_rule->is_enabled && ptr_rule->apps.find (hash) != ptr_rule->apps.end ()) + if (ptr_rule && ptr_rule->is_enabled && ptr_rule->type == DataRuleCustom && ptr_rule->apps.find (app_hash) != ptr_rule->apps.end ()) return true; } return false; } -bool _app_isappused (ITEM_APP const *ptr_app, size_t hash) +bool _app_isappused (ITEM_APP const* ptr_app, size_t app_hash) { - if (ptr_app && (ptr_app->is_enabled || ptr_app->is_silent) || _app_isapphaverule (hash)) + if (ptr_app && (ptr_app->is_enabled || ptr_app->is_silent) || _app_isapphaverule (app_hash)) return true; return false; } -bool _app_isappexists (ITEM_APP const *ptr_app) +bool _app_isappexists (ITEM_APP const* ptr_app) { if (!ptr_app) return false; @@ -652,11 +688,26 @@ bool _app_isappexists (ITEM_APP const *ptr_app) return ptr_app->real_path && ptr_app->real_path[0] && _r_fs_exists (ptr_app->real_path); else if (ptr_app->type == DataAppService || ptr_app->type == DataAppUWP) - return _app_item_get (ptr_app->type, _r_str_hash (ptr_app->original_path), nullptr, nullptr, nullptr, nullptr, nullptr); + return _app_item_get (ptr_app->type, _r_str_hash (ptr_app->original_path), nullptr, nullptr, nullptr, nullptr); return true; } +bool _app_ruleisblocklist (LPCWSTR name) +{ + if (!name || !name[0]) + return false; + + if ( + _wcsnicmp (name, L"extra_", 6) == 0 || + _wcsnicmp (name, L"spy_", 4) == 0 || + _wcsnicmp (name, L"update_", 7) == 0 + ) + return true; + + return false; +} + bool _app_isrulehost (LPCWSTR rule) { if (!rule || !rule[0]) @@ -707,302 +758,352 @@ bool _app_isruleport (LPCWSTR rule) return true; } -bool _app_isrulepresent (size_t hash) +//bool _app_isrulepresent (size_t hash) +//{ +// if (!hash) +// return false; +// +// for (size_t i = 0; i < rules_arr.size (); i++) +// { +// PITEM_RULE ptr_rule = rules_arr.at (i); +// +// if (ptr_rule && (ptr_rule->type == DataRuleSystem || (ptr_rule->type == DataRuleCustom && ptr_rule->is_readonly)) && ptr_rule->pname && _r_str_hash (ptr_rule->pname) == hash) +// return true; +// } +// +// return false; +//} + +bool _app_profile_load_check_node (pugi::xml_node & root, EnumXmlType type, bool is_strict) { - if (!hash) - return false; - - for (size_t i = 0; i < rules_arr.size (); i++) + if (root) { - PITEM_RULE ptr_rule = rules_arr.at (i); + if (is_strict) + return (root.attribute (L"type").as_int () == type); - if (ptr_rule && ptr_rule->is_readonly && ptr_rule->pname && _r_str_hash (ptr_rule->pname) == hash) - return true; + return (root.attribute (L"type").empty () || (root.attribute (L"type").as_int () == type)); } return false; } -void _app_profile_loadrules (std::vector * ptr_rules, LPCWSTR path, LPCWSTR path_backup, bool is_internal, EnumDataType type, UINT8 weight, time_t * ptimestamp) +bool _app_profile_load_check (LPCWSTR path, EnumXmlType type, bool is_strict) { - if (!ptr_rules) - return; + pugi::xml_document doc; + pugi::xml_parse_result result = doc.load_file (path, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); - pugi::xml_document doc_original; - pugi::xml_document doc_backup; - - pugi::xml_node root; - pugi::xml_parse_result result_original = doc_original.load_file (path, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); - - // if file not found or parsing error, load from backup - if (path_backup) + if (result) { - if (is_internal) - { - DWORD size = 0; - const LPVOID buffer = _app_loadresource (app.GetHINSTANCE (), path_backup, RT_RCDATA, &size); + pugi::xml_node root = doc.child (L"root"); - pugi::xml_parse_result result_backup; - - if (buffer) - result_backup = doc_backup.load_buffer (buffer, size, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); - - if (result_backup && (!result_original || doc_backup.child (L"root").attribute (L"timestamp").as_llong () > doc_original.child (L"root").attribute (L"timestamp").as_llong ())) - { - root = doc_backup.child (L"root"); - result_original = result_backup; - } - } - else - { - if (!result_original && _r_fs_exists (path_backup)) - result_original = doc_original.load_file (path_backup, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); - } + _app_profile_load_check_node (root, type, is_strict); } - // show only syntax, memory and i/o errors... - if (!result_original && result_original.status != pugi::status_file_not_found) - _app_logerror (L"pugi::load_file", 0, _r_fmt (L"status: %d,offset: %d,text: %s,file: %s", result_original.status, result_original.offset, rstring (result_original.description ()).GetString (), path), false); + return false; +} - if (result_original) +void _app_profile_load_fallback () +{ + if (!_app_getapplication (config.myhash)) + _app_addapplication (nullptr, app.GetBinaryPath (), 0, 0, 0, false, true, true); + + // disable deletion for this shit ;) + if (!_app_getapplication (config.ntoskrnl_hash)) + _app_addapplication (nullptr, PROC_SYSTEM_NAME, 0, 0, 0, false, false, true); + + if (!_app_getapplication (config.svchost_hash)) + _app_addapplication (nullptr, _r_path_expand (PATH_SVCHOST), 0, 0, 0, false, false, true); + + apps[config.myhash].is_undeletable = true; + apps[config.ntoskrnl_hash].is_undeletable = true; + apps[config.svchost_hash].is_undeletable = true; +} + +void _app_profile_load_helper (pugi::xml_node & root, EnumDataType type) +{ + for (pugi::xml_node item = root.child (L"item"); item; item = item.next_sibling (L"item")) { - if (!root) - root = doc_original.child (L"root"); - - if (root) + if (type == DataAppRegular) { - if (root.attribute (L"type").empty () || root.attribute (L"type").as_uint () == XmlRules) + _r_fastlock_acquireexclusive (&lock_access); + _app_addapplication (nullptr, item.attribute (L"path").as_string (), item.attribute (L"timestamp").as_llong (), item.attribute (L"timer").as_llong (), item.attribute (L"last_notify").as_llong (), item.attribute (L"is_silent").as_bool (), item.attribute (L"is_enabled").as_bool (), true); + _r_fastlock_releaseexclusive (&lock_access); + } + else if (type == DataRuleBlocklist || type == DataRuleSystem || type == DataRuleCustom) + { + const bool is_internal = (type == DataRuleSystem); + + PITEM_RULE ptr_rule = new ITEM_RULE; + + const size_t rule_hash = _r_str_hash (item.attribute (L"name").as_string ()); + PITEM_RULE_CONFIG ptr_config = nullptr; + + // allocate required memory { - if (ptimestamp) - *ptimestamp = root.attribute (L"timestamp").as_llong (); + const rstring attr_name = item.attribute (L"name").as_string (); + const rstring attr_rule_remote = item.attribute (L"rule").as_string (); + const rstring attr_rule_local = item.attribute (L"rule_local").as_string (); - for (pugi::xml_node item = root.child (L"item"); item; item = item.next_sibling (L"item")) + const size_t name_length = min (attr_name.GetLength (), RULE_NAME_CCH_MAX); + const size_t rule_remote_length = min (attr_rule_remote.GetLength (), RULE_RULE_CCH_MAX); + const size_t rule_local_length = min (attr_rule_local.GetLength (), RULE_RULE_CCH_MAX); + + _r_str_alloc (&ptr_rule->pname, name_length, attr_name); + _r_str_alloc (&ptr_rule->prule_remote, rule_remote_length, attr_rule_remote); + _r_str_alloc (&ptr_rule->prule_local, rule_local_length, attr_rule_local); + } + + ptr_rule->dir = (FWP_DIRECTION)item.attribute (L"dir").as_uint (); + ptr_rule->protocol = (UINT8)item.attribute (L"protocol").as_uint (); + ptr_rule->af = (ADDRESS_FAMILY)item.attribute (L"version").as_uint (); + + ptr_rule->type = ((is_internal && item.attribute (L"is_custom").as_bool ()) ? DataRuleCustom : type); + ptr_rule->is_block = item.attribute (L"is_block").as_bool (); + ptr_rule->is_forservices = item.attribute (L"is_services").as_bool (); + ptr_rule->is_readonly = (type != DataRuleCustom); + + // calculate rule weight + if (type == DataRuleBlocklist) + ptr_rule->weight = FILTER_WEIGHT_BLOCKLIST; + + else if (type == DataRuleSystem) + ptr_rule->weight = FILTER_WEIGHT_SYSTEM; + + else if (type == DataRuleCustom) + ptr_rule->weight = ptr_rule->is_block ? FILTER_WEIGHT_CUSTOM_BLOCK : FILTER_WEIGHT_CUSTOM; + + ptr_rule->is_enabled = item.attribute (L"is_enabled").as_bool (); + + if (is_internal) + { + // internal rules + if (rules_config.find (rule_hash) != rules_config.end ()) { - PITEM_RULE ptr_rule = new ITEM_RULE; + ptr_config = rules_config[rule_hash]; - if (ptr_rule) + if (ptr_config) + ptr_rule->is_enabled = ptr_config->is_enabled; + } + else + { + ptr_config = new ITEM_RULE_CONFIG; + + ptr_config->is_enabled = ptr_rule->is_enabled; + + _r_str_alloc (&ptr_config->pname, _r_str_length (ptr_rule->pname), ptr_rule->pname); + + _r_fastlock_acquireexclusive (&lock_access); + rules_config[rule_hash] = ptr_config; + _r_fastlock_releaseexclusive (&lock_access); + } + } + + // load apps + { + rstring apps_rule = item.attribute (L"apps").as_string (); + + if (is_internal && ptr_config && ptr_config->papps && ptr_config->papps[0]) + { + if (apps_rule.IsEmpty ()) + apps_rule = ptr_config->papps; + + else + apps_rule.AppendFormat (L"%s%s", RULE_DELIMETER, ptr_config->papps); + } + + if (!apps_rule.IsEmpty ()) + { + rstring::rvector arr = apps_rule.AsVector (RULE_DELIMETER); + + for (size_t i = 0; i < arr.size (); i++) { - const size_t hash = _r_str_hash (item.attribute (L"name").as_string ()); - PITEM_RULE_CONFIG ptr_config = nullptr; + const rstring app_path = _r_path_expand (arr.at (i).Trim (L"\r\n ")); + size_t app_hash = app_path.Hash (); - // allocate required memory + if (app_hash) { - const rstring attr_name = item.attribute (L"name").as_string (); - const rstring attr_rule_remote = item.attribute (L"rule").as_string (); - const rstring attr_rule_local = item.attribute (L"rule_local").as_string (); + if (item.attribute (L"is_services").as_bool () && (app_hash == config.ntoskrnl_hash || app_hash == config.svchost_hash)) + continue; - const size_t name_length = min (attr_name.GetLength (), RULE_NAME_CCH_MAX); - const size_t rule_remote_length = min (attr_rule_remote.GetLength (), RULE_RULE_CCH_MAX); - const size_t rule_local_length = min (attr_rule_local.GetLength (), RULE_RULE_CCH_MAX); + if (!_app_getapplication (app_hash)) + { + _r_fastlock_acquireexclusive (&lock_access); + app_hash = _app_addapplication (nullptr, app_path, 0, 0, 0, false, false, true); + _r_fastlock_releaseexclusive (&lock_access); + } - _r_str_alloc (&ptr_rule->pname, name_length, attr_name); - _r_str_alloc (&ptr_rule->prule_remote, rule_remote_length, attr_rule_remote); - _r_str_alloc (&ptr_rule->prule_local, rule_local_length, attr_rule_local); + if (ptr_rule->type == DataRuleSystem) + apps[app_hash].is_undeletable = true; + + ptr_rule->apps[app_hash] = true; } - - ptr_rule->dir = (FWP_DIRECTION)item.attribute (L"dir").as_uint (); - ptr_rule->protocol = (UINT8)item.attribute (L"protocol").as_uint (); - ptr_rule->af = (ADDRESS_FAMILY)item.attribute (L"version").as_uint (); - - ptr_rule->type = item.attribute (L"is_custom").as_bool () ? DataRuleCustom : type; - ptr_rule->is_block = item.attribute (L"is_block").as_bool (); - ptr_rule->is_forservices = item.attribute (L"is_services").as_bool (); - ptr_rule->is_readonly = (type != DataRuleCustom); - ptr_rule->weight = (type == DataRuleCustom && ptr_rule->is_block) ? FILTER_WEIGHT_CUSTOM_BLOCK : weight; // calculate rule weight - - ptr_rule->is_enabled = item.attribute (L"is_enabled").as_bool (); - - if (is_internal) - { - // internal rules - if (rules_config.find (hash) != rules_config.end ()) - { - ptr_config = rules_config[hash]; - - if (ptr_config) - ptr_rule->is_enabled = ptr_config->is_enabled; - } - else - { - ptr_config = new ITEM_RULE_CONFIG; - - if (ptr_config) - { - ptr_config->is_enabled = ptr_rule->is_enabled; - - _r_str_alloc (&ptr_config->pname, _r_str_length (ptr_rule->pname), ptr_rule->pname); - - rules_config[hash] = ptr_config; - } - } - } - - // load apps - { - rstring apps_rule = item.attribute (L"apps").as_string (); - - if (is_internal && ptr_config && ptr_config->papps) - { - if (apps_rule.IsEmpty ()) - apps_rule = ptr_config->papps; - - else - apps_rule.AppendFormat (L"%s%s", RULE_DELIMETER, ptr_config->papps); - } - - if (!apps_rule.IsEmpty ()) - { - rstring::rvector arr = apps_rule.AsVector (RULE_DELIMETER); - - for (size_t i = 0; i < arr.size (); i++) - { - const rstring app_path = _r_path_expand (arr.at (i).Trim (L"\r\n ")); - size_t app_hash = app_path.Hash (); - - if (app_hash) - { - if (item.attribute (L"is_services").as_bool ()) - { - if (app_hash == config.ntoskrnl_hash || app_hash == config.svchost_hash) - continue; - } - - if (!_app_getapplication (app_hash)) - app_hash = _app_addapplication (nullptr, app_path, 0, 0, 0, false, false, true); - - if (ptr_rule->type == DataRuleBlocklist || ptr_rule->type == DataRuleSystem) - apps[app_hash].is_undeletable = true; - - ptr_rule->apps[app_hash] = true; - } - } - } - } - - ptr_rules->push_back (ptr_rule); } } } + + _r_fastlock_acquireexclusive (&lock_access); + rules_arr.push_back (ptr_rule); + _r_fastlock_releaseexclusive (&lock_access); + } + else if (type == DataRulesConfig) + { + if (item.attribute (L"name").empty ()) + continue; + + const rstring rule_name = item.attribute (L"name").as_string (); + + // do not load blocklist config (old versions hack)! + if (_app_ruleisblocklist (rule_name)) + continue; + + const size_t rule_hash = rule_name.Hash (); + + if (rules_config.find (rule_hash) == rules_config.end ()) + { + PITEM_RULE_CONFIG ptr_config = new ITEM_RULE_CONFIG; + + ptr_config->is_enabled = item.attribute (L"is_enabled").as_bool (); + + const rstring attr_name = item.attribute (L"name").as_string (); + const rstring attr_apps = item.attribute (L"apps").as_string (); + + _r_str_alloc (&ptr_config->pname, attr_name.GetLength (), attr_name); + _r_str_alloc (&ptr_config->papps, attr_apps.GetLength (), attr_apps); + + _r_fastlock_acquireexclusive (&lock_access); + rules_config[rule_hash] = ptr_config; + _r_fastlock_releaseexclusive (&lock_access); + } } } } -void _app_profile_load (HWND hwnd, LPCWSTR path_apps, LPCWSTR path_rules) +void _app_profile_load_internal (LPCWSTR path, LPCWSTR path_backup, time_t * ptimestamp) +{ + pugi::xml_document doc_original; + pugi::xml_document doc_backup; + + pugi::xml_parse_result load_original = doc_original.load_file (path, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); + pugi::xml_parse_result load_backup; + + pugi::xml_node root; + + // if file not found or parsing error, load from backup + if (path_backup) + { + DWORD size = 0; + const LPVOID buffer = _app_loadresource (app.GetHINSTANCE (), path_backup, RT_RCDATA, &size); + + if (buffer) + load_backup = doc_backup.load_buffer (buffer, size, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); + + if (load_backup) + { + if (!load_original || doc_backup.child (L"root").attribute (L"timestamp").as_llong () > doc_original.child (L"root").attribute (L"timestamp").as_llong ()) + { + root = doc_backup.child (L"root"); + load_original = load_backup; + } + else + { + root = doc_original.child (L"root"); + } + } + } + + // show only syntax, memory and i/o errors... + if (!load_original && load_original.status != pugi::status_file_not_found && load_original.status != pugi::status_no_document_element) + _app_logerror (L"pugi::load_file", 0, _r_fmt (L"status: %d,offset: %d,text: %s,file: %s", load_original.status, load_original.offset, rstring (load_original.description ()).GetString (), path), false); + + if (load_original && root) + { + if (_app_profile_load_check_node (root, XmlProfileInternalV3, true)) + { + if (ptimestamp) + *ptimestamp = root.attribute (L"timestamp").as_llong (); + + pugi::xml_node root_rules_blocklist = root.child (L"rules_blocklist"); + + if (root_rules_blocklist) + _app_profile_load_helper (root_rules_blocklist, DataRuleBlocklist); + + pugi::xml_node root_rules_system = root.child (L"rules_system"); + + if (root_rules_system) + _app_profile_load_helper (root_rules_system, DataRuleSystem); + } + } +} + +void _app_profile_load (HWND hwnd) { const UINT current_listview_id = _app_gettab_id (hwnd); const size_t selected_item = (size_t)SendDlgItemMessage (hwnd, current_listview_id, LVM_GETNEXTITEM, (WPARAM)-1, LVNI_SELECTED); const INT scroll_pos = GetScrollPos (GetDlgItem (hwnd, current_listview_id), SB_VERT); - // load applications + // clean listview + if (hwnd) { - bool is_meadded = false; - - _r_fastlock_acquireexclusive (&lock_access); - - _app_freearray (&items); - - // generate package list (win8+) - if (_r_sys_validversion (6, 2)) - _app_generate_packages (); - - // generate services list - _app_generate_services (); - - // clean listview - if (hwnd) - { - _r_listview_deleteallitems (hwnd, IDC_APPS_PROFILE); - _r_listview_deleteallitems (hwnd, IDC_APPS_SERVICE); - _r_listview_deleteallitems (hwnd, IDC_APPS_UWP); - _r_listview_deleteallitems (hwnd, IDC_RULES_BLOCKLIST); - _r_listview_deleteallitems (hwnd, IDC_RULES_SYSTEM); - _r_listview_deleteallitems (hwnd, IDC_RULES_CUSTOM); - } - - // load apps list - { - apps.clear (); - - pugi::xml_document doc; - pugi::xml_parse_result result = doc.load_file (path_apps ? path_apps : config.apps_path, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); - - // load backup - if (!result) - { - if (_r_fs_exists (config.apps_path_backup)) - result = doc.load_file (config.apps_path_backup, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); - } - - if (!result) - { - // show only syntax, memory and i/o errors... - if (result.status != pugi::status_file_not_found) - _app_logerror (L"pugi::load_file", 0, _r_fmt (L"status: %d,offset: %d,text: %s,file: %s", result.status, result.offset, rstring (result.description ()).GetString (), path_apps ? path_apps : config.apps_path), false); - } - else - { - pugi::xml_node root = doc.child (L"root"); - - if (root) - { - if (root.attribute (L"type").empty () || root.attribute (L"type").as_uint () == XmlApps) - { - for (pugi::xml_node item = root.child (L"item"); item; item = item.next_sibling (L"item")) - { - const size_t hash = _r_str_hash (item.attribute (L"path").as_string ()); - - if (hash == config.myhash) - is_meadded = true; - - _app_addapplication (nullptr, item.attribute (L"path").as_string (), item.attribute (L"timestamp").as_llong (), item.attribute (L"timer").as_llong (), item.attribute (L"last_notify").as_llong (), item.attribute (L"is_silent").as_bool (), item.attribute (L"is_enabled").as_bool (), true); - } - } - } - } - } - - if (!is_meadded) - _app_addapplication (nullptr, app.GetBinaryPath (), 0, 0, 0, false, true, true); - - // disable deletion for this shit ;) - if (!_app_getapplication (config.ntoskrnl_hash)) - _app_addapplication (nullptr, PROC_SYSTEM_NAME, 0, 0, 0, false, false, true); - - if (!_app_getapplication (config.svchost_hash)) - _app_addapplication (nullptr, _r_path_expand (PATH_SVCHOST), 0, 0, 0, false, false, true); - - apps[config.myhash].is_undeletable = true; - apps[config.ntoskrnl_hash].is_undeletable = true; - apps[config.svchost_hash].is_undeletable = true; - - // add services and store apps - for (size_t i = 0; i < items.size (); i++) - { - const PITEM_ADD ptr_item = items.at (i); - - if (ptr_item) - _app_addapplication (nullptr, ptr_item->type == DataAppService ? ptr_item->service_name : ptr_item->sid, ptr_item->timestamp, 0, 0, false, false, true); - } + _r_listview_deleteallitems (hwnd, IDC_APPS_PROFILE); + _r_listview_deleteallitems (hwnd, IDC_APPS_SERVICE); + _r_listview_deleteallitems (hwnd, IDC_APPS_UWP); + _r_listview_deleteallitems (hwnd, IDC_RULES_BLOCKLIST); + _r_listview_deleteallitems (hwnd, IDC_RULES_SYSTEM); + _r_listview_deleteallitems (hwnd, IDC_RULES_CUSTOM); } - // load rules config + _r_fastlock_acquireexclusive (&lock_access); + + // clear services/uwp apps + _app_freearray (&items); + + // clear apps + apps.clear (); + + // clear rules + { + for (auto &p : rules_arr) + SAFE_DELETE (p); + + rules_arr.clear (); + } + + // clear rules config { for (auto &p : rules_config) SAFE_DELETE (p.second); rules_config.clear (); + } + // generate package list (win8+) + if (_r_sys_validversion (6, 2)) + _app_generate_packages (); + + // generate services list + _app_generate_services (); + + _r_fastlock_releaseexclusive (&lock_access); + + // load profile + if (_r_fs_exists (config.profile_path) || _r_fs_exists (config.profile_path_backup)) + { pugi::xml_document doc; - pugi::xml_parse_result result = doc.load_file (config.rules_config_path, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); + pugi::xml_parse_result result = doc.load_file (config.profile_path, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); - if (!result && _r_fs_exists (config.rules_config_path_backup)) - result = doc.load_file (config.rules_config_path_backup, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); + // load backup + if (!result) + result = doc.load_file (config.profile_path_backup, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); if (!result) { // show only syntax, memory and i/o errors... - if (result.status != pugi::status_file_not_found) - _app_logerror (L"pugi::load_file", 0, _r_fmt (L"status: %d,offset: %d,text: %s,file: %s", result.status, result.offset, rstring (result.description ()).GetString (), config.rules_config_path), false); + if (result.status != pugi::status_file_not_found && result.status != pugi::status_no_document_element) + _app_logerror (L"pugi::load_file", 0, _r_fmt (L"status: %d,offset: %d,text: %s,file: %s", result.status, result.offset, rstring (result.description ()).GetString (), config.profile_path), false); + + _r_fastlock_acquireexclusive (&lock_access); + _app_profile_load_fallback (); + _r_fastlock_releaseexclusive (&lock_access); } else { @@ -1010,52 +1111,128 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_apps, LPCWSTR path_rules) if (root) { - if (root.attribute (L"type").empty () || root.attribute (L"type").as_uint () == XmlRulesConfig) + if (_app_profile_load_check_node (root, XmlProfileV3, true)) { - for (pugi::xml_node item = root.child (L"item"); item; item = item.next_sibling (L"item")) - { - if (!item.attribute (L"name").empty ()) - { - const size_t hash = _r_str_hash (item.attribute (L"name").as_string ()); + // load apps (new!) + pugi::xml_node root_apps = root.child (L"apps"); - if (rules_config.find (hash) == rules_config.end ()) - { - PITEM_RULE_CONFIG ptr_config = new ITEM_RULE_CONFIG; + if (root_apps) + _app_profile_load_helper (root_apps, DataAppRegular); - ptr_config->is_enabled = item.attribute (L"is_enabled").as_bool (); + _r_fastlock_acquireexclusive (&lock_access); + _app_profile_load_fallback (); + _r_fastlock_releaseexclusive (&lock_access); - const rstring attr_name = item.attribute (L"name").as_string (); - const rstring attr_apps = item.attribute (L"apps").as_string (); + // load rules config (new!) + pugi::xml_node root_rules_config = root.child (L"rules_config"); - _r_str_alloc (&ptr_config->pname, attr_name.GetLength (), attr_name); - _r_str_alloc (&ptr_config->papps, attr_apps.GetLength (), attr_apps); + if (root_rules_config) + _app_profile_load_helper (root_rules_config, DataRulesConfig); - rules_config[hash] = ptr_config; - } - } - } + // load user rules (new!) + pugi::xml_node root_rules_custom = root.child (L"rules_custom"); + + if (root_rules_custom) + _app_profile_load_helper (root_rules_custom, DataRuleCustom); + + // load internal rules (new!) + _app_profile_load_internal (config.profile_internal_path, MAKEINTRESOURCE (IDR_PROFILE_INTERNAL), &config.profile_internal_timestamp); } } } } - - // clear rules + else { - for (size_t i = 0; i < rules_arr.size (); i++) - _app_freerule (&rules_arr.at (i)); + // load apps (old!) + { + pugi::xml_document doc_apps; + pugi::xml_parse_result result_apps = doc_apps.load_file (config.apps_path, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); - rules_arr.clear (); + // load backup + if (!result_apps) + result_apps = doc_apps.load_file (config.apps_path_backup, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); + + if (result_apps) + { + pugi::xml_node root = doc_apps.child (L"root"); + + if (root) + { + if (_app_profile_load_check_node (root, XmlApps, false)) + _app_profile_load_helper (root, DataAppRegular); + } + + // made old config backup! + if (_r_fs_exists (config.apps_path)) + _r_fs_move (config.apps_path, config.apps_path_backup, MOVEFILE_REPLACE_EXISTING); + } + + _r_fastlock_acquireexclusive (&lock_access); + _app_profile_load_fallback (); + _r_fastlock_releaseexclusive (&lock_access); + } + + // load rules config (old!) + { + pugi::xml_document doc_rules_config; + pugi::xml_parse_result result_rules_config = doc_rules_config.load_file (config.rules_config_path, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); + + // load backup + if (!result_rules_config) + result_rules_config = doc_rules_config.load_file (config.rules_config_path_backup, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); + + if (result_rules_config) + { + pugi::xml_node root = doc_rules_config.child (L"root"); + + if (root) + { + if (_app_profile_load_check_node (root, XmlRulesConfig, false)) + _app_profile_load_helper (root, DataRulesConfig); + } + + // made old config backup! + if (_r_fs_exists (config.rules_config_path)) + _r_fs_move (config.rules_config_path, config.rules_config_path_backup, MOVEFILE_REPLACE_EXISTING); + } + } + + // load internal rules (new!) + _app_profile_load_internal (config.profile_internal_path, MAKEINTRESOURCE (IDR_PROFILE_INTERNAL), &config.profile_internal_timestamp); + + // load rules custom (old!) + { + pugi::xml_document doc_rules_custom; + pugi::xml_parse_result result_rules_custom = doc_rules_custom.load_file (config.rules_custom_path, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); + + // load backup + if (!result_rules_custom) + { + if (_r_fs_exists (config.rules_custom_path_backup)) + result_rules_custom = doc_rules_custom.load_file (config.rules_custom_path_backup, PUGIXML_LOAD_FLAGS, PUGIXML_LOAD_ENCODING); + } + + if (result_rules_custom) + { + pugi::xml_node root = doc_rules_custom.child (L"root"); + + if (root) + { + if (_app_profile_load_check_node (root, XmlRules, false)) + _app_profile_load_helper (root, DataRuleCustom); + } + + // made old config backup! + if (_r_fs_exists (config.rules_custom_path)) + _r_fs_move (config.rules_custom_path, config.rules_custom_path_backup, MOVEFILE_REPLACE_EXISTING); + } + } + + _app_profile_save (); // required! } - // load blocklist rules (internal) - _app_profile_loadrules (&rules_arr, config.rules_blocklist_path, MAKEINTRESOURCE (IDR_RULES_BLOCKLIST), true, DataRuleBlocklist, FILTER_WEIGHT_BLOCKLIST, &config.blocklist_timestamp); - - // load system rules (internal) - _app_profile_loadrules (&rules_arr, config.rules_system_path, MAKEINTRESOURCE (IDR_RULES_SYSTEM), true, DataRuleSystem, FILTER_WEIGHT_SYSTEM, &config.rule_system_timestamp); - - // load user rules - _app_profile_loadrules (&rules_arr, path_rules ? path_rules : config.rules_custom_path, config.rules_custom_path_backup, false, DataRuleCustom, FILTER_WEIGHT_CUSTOM, nullptr); - + _r_fastlock_acquireexclusive (&lock_access); + _app_ruleblocklistset (); _r_fastlock_releaseexclusive (&lock_access); if (hwnd) @@ -1083,6 +1260,15 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_apps, LPCWSTR path_rules) _r_fastlock_releaseshared (&lock_checkbox); } + // add services and store apps + for (size_t i = 0; i < items.size (); i++) + { + const PITEM_ADD ptr_item = items.at (i); + + if (ptr_item) + _app_addapplication (hwnd, ptr_item->type == DataAppService ? ptr_item->service_name : ptr_item->sid, ptr_item->timestamp, 0, 0, false, false, true); + } + // add rules for (size_t i = 0; i < rules_arr.size (); i++) { @@ -1109,74 +1295,42 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_apps, LPCWSTR path_rules) _r_fastlock_releaseshared (&lock_access); } - _r_fastlock_acquireexclusive (&lock_network); - - if (hwnd) - _r_listview_deleteallitems (hwnd, IDC_NETWORK); - - for (size_t i = 0; i < network_arr.size (); i++) - SAFE_DELETE (network_arr[i]); - - network_arr.clear (); - - _app_generate_connections (); - - if (hwnd) + if (hwnd && current_listview_id) { - for (size_t i = 0; i < network_arr.size (); i++) - { - const PITEM_NETWORK ptr_network = network_arr.at (i); + const UINT new_listview_id = _app_gettab_id (hwnd); - if (!ptr_network) - continue; + _app_listviewsort (hwnd, new_listview_id); - //if (ptr_network->hash && !_app_getapplication (ptr_network->hash)) - // _app_addapplication (hwnd, ptr_network->path, 0, 0, 0, false, false, true); - - // TODO: add network resolver!!! - _app_formataddress (ptr_network->af, &ptr_network->local_addr, ptr_network->local_port, &ptr_network->local_fmt, false); - _app_formataddress (ptr_network->af, &ptr_network->remote_addr, ptr_network->remote_port, &ptr_network->remote_fmt, false); - - _r_listview_additem (hwnd, IDC_NETWORK, i, 0, _r_path_extractfile (ptr_network->path), ptr_network->icon_id, LAST_VALUE, i); - - _r_listview_setitem (hwnd, IDC_NETWORK, i, 1, ptr_network->local_fmt); - _r_listview_setitem (hwnd, IDC_NETWORK, i, 2, ptr_network->remote_fmt); - _r_listview_setitem (hwnd, IDC_NETWORK, i, 3, _app_getprotoname (ptr_network->protocol)); - _r_listview_setitem (hwnd, IDC_NETWORK, i, 4, _app_getstatename (ptr_network->state)); - } - } - - _r_fastlock_releaseexclusive (&lock_network); - - if (hwnd) - { - _app_listviewsort (hwnd, current_listview_id); - _app_showitem (hwnd, current_listview_id, selected_item, scroll_pos); + if (current_listview_id == new_listview_id) + _app_showitem (hwnd, current_listview_id, selected_item, scroll_pos); } } -void _app_profile_save (LPCWSTR path_apps, LPCWSTR path_rules) +void _app_profile_save () { const time_t current_time = _r_unixtime_now (); - const bool is_backuprequired = app.ConfigGet (L"IsBackupProfile", true).AsBool () && (((current_time - app.ConfigGet (L"BackupTimestamp", 0).AsLonglong ()) >= app.ConfigGet (L"BackupPeriod", _R_SECONDSCLOCK_HOUR (BACKUP_HOURS_PERIOD)).AsLonglong ()) || !_r_fs_exists (config.apps_path_backup) || !_r_fs_exists (config.rules_custom_path_backup) || !_r_fs_exists (config.rules_config_path_backup)); + const bool is_backuprequired = app.ConfigGet (L"IsBackupProfile", true).AsBool () && (((current_time - app.ConfigGet (L"BackupTimestamp", 0).AsLonglong ()) >= app.ConfigGet (L"BackupPeriod", _R_SECONDSCLOCK_HOUR (BACKUP_HOURS_PERIOD)).AsLonglong ()) || !_r_fs_exists (config.profile_path_backup)); - bool is_backupcreated = false; + pugi::xml_document doc; + pugi::xml_node root = doc.append_child (L"root"); - // save apps + if (root) { - pugi::xml_document doc; - pugi::xml_node root = doc.append_child (L"root"); + root.append_attribute (L"timestamp").set_value (current_time); + root.append_attribute (L"type").set_value (XmlProfileV3); - if (root) + pugi::xml_node root_apps = root.append_child (L"apps"); + pugi::xml_node root_rules_custom = root.append_child (L"rules_custom"); + pugi::xml_node root_rule_config = root.append_child (L"rules_config"); + + _r_fastlock_acquireshared (&lock_access); + + // save apps + if (root_apps) { - root.append_attribute (L"timestamp").set_value (current_time); - root.append_attribute (L"type").set_value (XmlApps); - - _r_fastlock_acquireshared (&lock_access); - for (auto &p : apps) { - PITEM_APP const ptr_app = &p.second; + const PITEM_APP ptr_app = &p.second; if (!ptr_app->original_path) continue; @@ -1186,7 +1340,7 @@ void _app_profile_save (LPCWSTR path_apps, LPCWSTR path_rules) if (!is_used && (ptr_app->type == DataAppService || ptr_app->type == DataAppUWP)) continue; - pugi::xml_node item = root.append_child (L"item"); + pugi::xml_node item = root_apps.append_child (L"item"); if (item) { @@ -1210,93 +1364,11 @@ void _app_profile_save (LPCWSTR path_apps, LPCWSTR path_rules) item.append_attribute (L"is_enabled").set_value (ptr_app->is_enabled); } } - - _r_fastlock_releaseshared (&lock_access); - - doc.save_file (path_apps ? path_apps : config.apps_path, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); - - // make backup - if (!path_apps && !apps.empty () && is_backuprequired) - { - doc.save_file (config.apps_path_backup, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); - is_backupcreated = true; - } } - } - // save internal rules config - { - pugi::xml_document doc; - pugi::xml_node root = doc.append_child (L"root"); - - if (root) + // save user rules + if (root_rules_custom) { - root.append_attribute (L"timestamp").set_value (current_time); - root.append_attribute (L"type").set_value (XmlRulesConfig); - - _r_fastlock_acquireshared (&lock_access); - - for (auto const &p : rules_config) - { - const PITEM_RULE_CONFIG ptr_config = p.second; - - if (!ptr_config || !ptr_config->pname) - continue; - - const size_t hash = _r_str_hash (ptr_config->pname); - - if (!_app_isrulepresent (hash)) - continue; - - pugi::xml_node item = root.append_child (L"item"); - - if (item) - { - item.append_attribute (L"name").set_value (p.second->pname); - - // save apps - const PITEM_RULE ptr_rule = _app_getrule (hash, DataRuleCustom, true); - - if (ptr_rule && !ptr_rule->apps.empty ()) - { - const rstring rule_apps = _app_rulesexpand (ptr_rule, false, L";"); - - if (!rule_apps.IsEmpty ()) - item.append_attribute (L"apps").set_value (rule_apps); - } - - if (p.second->is_enabled) - item.append_attribute (L"is_enabled").set_value (p.second->is_enabled); - } - } - - _r_fastlock_releaseshared (&lock_access); - - doc.save_file (config.rules_config_path, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); - - // make backup - if (!rules_config.empty () && is_backuprequired) - { - doc.save_file (config.rules_config_path_backup, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); - is_backupcreated = true; - } - } - } - - // save custom rules - { - pugi::xml_document doc; - pugi::xml_node root = doc.append_child (L"root"); - - if (root) - { - root.append_attribute (L"timestamp").set_value (current_time); - root.append_attribute (L"type").set_value (XmlRules); - - size_t rules_count = 0; - - _r_fastlock_acquireshared (&lock_access); - for (size_t i = 0; i < rules_arr.size (); i++) { const PITEM_RULE ptr_rule = rules_arr.at (i); @@ -1304,7 +1376,7 @@ void _app_profile_save (LPCWSTR path_apps, LPCWSTR path_rules) if (!ptr_rule || ptr_rule->is_readonly || !ptr_rule->pname) continue; - pugi::xml_node item = root.append_child (L"item"); + pugi::xml_node item = root_rules_custom.append_child (L"item"); if (item) { @@ -1326,26 +1398,13 @@ void _app_profile_save (LPCWSTR path_apps, LPCWSTR path_rules) item.append_attribute (L"version").set_value (ptr_rule->af); // add apps attribute + if (!ptr_rule->apps.empty ()) { - rstring arr; - bool is_haveapps = false; + const rstring rule_apps = _app_rulesexpand (ptr_rule, false, RULE_DELIMETER); - for (auto const &p : ptr_rule->apps) - { - PITEM_APP const ptr_app = _app_getapplication (p.first); - - if (ptr_app) - { - arr.Append (_r_path_unexpand (ptr_app->original_path)); - arr.Append (RULE_DELIMETER); - - is_haveapps = true; - } - } - - if (is_haveapps) - item.append_attribute (L"apps").set_value (arr.Trim (RULE_DELIMETER)); + if (!rule_apps.IsEmpty ()) + item.append_attribute (L"apps").set_value (rule_apps); } if (ptr_rule->is_block) @@ -1353,24 +1412,53 @@ void _app_profile_save (LPCWSTR path_apps, LPCWSTR path_rules) if (ptr_rule->is_enabled) item.append_attribute (L"is_enabled").set_value (ptr_rule->is_enabled); - - rules_count += 1; } } + } - _r_fastlock_releaseshared (&lock_access); - - doc.save_file (path_rules ? path_rules : config.rules_custom_path, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); - - // make backup - if (is_backupcreated || (!path_rules && rules_count && is_backuprequired)) + // save rules config + if (root_rule_config) + { + for (auto const &p : rules_config) { - doc.save_file (config.rules_custom_path_backup, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); - is_backupcreated = true; + const PITEM_RULE_CONFIG ptr_config = p.second; + + if (!ptr_config || !ptr_config->pname || !ptr_config->pname[0]) + continue; + + pugi::xml_node item = root_rule_config.append_child (L"item"); + + if (item) + { + item.append_attribute (L"name").set_value (p.second->pname); + + // save apps + const size_t rule_hash = _r_str_hash (ptr_config->pname); + const PITEM_RULE ptr_rule = _app_getrule (rule_hash, DataRuleCustom, true); + + if (ptr_rule && !ptr_rule->apps.empty ()) + { + const rstring rule_apps = _app_rulesexpand (ptr_rule, false, RULE_DELIMETER); + + if (!rule_apps.IsEmpty ()) + item.append_attribute (L"apps").set_value (rule_apps); + } + + if (p.second->is_enabled) + item.append_attribute (L"is_enabled").set_value (p.second->is_enabled); + } } } - } - if (is_backupcreated) - app.ConfigSet (L"BackupTimestamp", current_time); + doc.save_file (config.profile_path, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); + + _r_fastlock_releaseshared (&lock_access); + + // make backup + if (is_backuprequired) + { + doc.save_file (config.profile_path_backup, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); + app.ConfigSet (L"BackupTimestamp", current_time); + } + } } diff --git a/src/profile.hpp b/src/profile.hpp index 553a9336..20a65cc6 100644 --- a/src/profile.hpp +++ b/src/profile.hpp @@ -23,20 +23,24 @@ void _app_setappiteminfo (HWND hwnd, UINT listview_id, size_t item, size_t app_h void _app_setruleiteminfo (HWND hwnd, UINT listview_id, size_t item, PITEM_RULE ptr_rule, bool include_apps); void _app_ruleenable (PITEM_RULE ptr_rule, bool is_enable); +void _app_ruleblocklistset (); + rstring _app_rulesexpand (PITEM_RULE const ptr_rule, bool is_forservices, LPCWSTR delimeter); -bool _app_isapphaveconnection (size_t hash); -bool _app_isapphaverule (size_t hash); -bool _app_isappused (ITEM_APP const *ptr_app, size_t hash); +bool _app_isapphaveconnection (size_t app_hash); +bool _app_isapphaverule (size_t app_hash); +bool _app_isappused (ITEM_APP const *ptr_app, size_t app_hash); bool _app_isappexists (ITEM_APP const *ptr_app); + +bool _app_isruleblocklist (LPCWSTR name); bool _app_isrulehost (LPCWSTR rule); bool _app_isruleip (LPCWSTR rule); bool _app_isruleport (LPCWSTR rule); -bool _app_isrulepresent (size_t hash); +//bool _app_isrulepresent (size_t hash); -void _app_profile_loadrules (std::vector *ptr_rules, LPCWSTR path, LPCWSTR path_backup, bool is_internal, EnumDataType type, UINT8 weight, time_t *ptimestamp); - -void _app_profile_load (HWND hwnd, LPCWSTR path_apps = nullptr, LPCWSTR path_rules = nullptr); -void _app_profile_save (LPCWSTR path_apps = nullptr, LPCWSTR path_rules = nullptr); +bool _app_profile_load_check (LPCWSTR path, EnumXmlType type, bool is_strict); +void _app_profile_load_internal (LPCWSTR path, LPCWSTR path_backup, time_t* ptimestamp); +void _app_profile_load (HWND hwnd); +void _app_profile_save ();