private static bool AllowPath(string path) { string sha256 = ""; string signId = ""; if (Platform.Instance.FileExists(path) == false) { return(false); } List <string> trustedPaths = Platform.Instance.GetTrustedPaths(); foreach (string trustedPath in trustedPaths) { if (path.StartsWith(trustedPath, StringComparison.InvariantCulture)) { return(true); } } // Avoid if possible any shell before the storage init. if (Engine.Instance.Storage == null) { return(false); } Json rulesCustom = Engine.Instance.Storage.GetJson("external.rules"); for (int r = 0; r < 2; r++) { Json rules = null; if (r == 0) { if (Engine.Instance.Storage.GetBool("external.rules.recommended")) { rules = Engine.Instance.Manifest["external-rules-recommended"].Value as Json; } else { continue; } } else if (r == 1) { rules = rulesCustom; } foreach (Json rule in rules.GetArray()) { string type = rule["type"].Value as string; if (type == "all") { return(true); } if (type == "sign") { if (signId == "") { signId = Platform.Instance.FileGetSignedId(path); } if (rule["id"].Value as string == signId) { return(true); } } if (type == "sha256") { if (sha256 == "") { sha256 = UtilsCore.HashSHA256File(path); } if (rule["hash"].Value as string == sha256) { return(true); } } if (type == "path") { if (rule["path"].Value as string == path) { return(true); } } } } // Ensure compute, Report and result if (signId == "") { signId = Platform.Instance.FileGetSignedId(path); } if (sha256 == "") { sha256 = UtilsCore.HashSHA256File(path); } Json askToUi = new Json(); askToUi["sha256"].Value = sha256; askToUi["sign-id"].Value = signId; askToUi["path"].Value = path; // Propose to add rule to UI Json replyUi = Engine.Instance.OnAskShellExternalPermission(askToUi); if (replyUi.HasKey("allow")) { if (Convert.ToBoolean(replyUi["allow"].Value) == false) { return(false); } } if (replyUi.HasKey("type")) { replyUi.RemoveKey("allow"); rulesCustom.Append(replyUi); Engine.Instance.Storage.SetJson("external.rules", rulesCustom); return(AllowPath(path)); } if (replyUi.HasKey("allow")) { if (Convert.ToBoolean(replyUi["allow"].Value) == true) { return(true); } } //Engine.Instance.Storage.SetJson("external.rules", rules); return(false); }