示例#1
0
        public override SelectionRuleNode VisitBooleanExpression(TmtParser.BooleanExpressionContext context)
        {
            SelectionRuleNode result;

            NaryRuleNode rule = null;

            switch (context.op?.GetText())
            {
            case "and":
                rule = new AndRuleNode()
                {
                    Name = "AND"
                };
                break;

            case "or":
                rule = new OrRuleNode()
                {
                    Name = "OR"
                };
                break;
            }

            if (Rule == null)
            {
                Rule = rule;
            }

            var left  = Visit(context.left);
            var right = Visit(context.right);

            if (left != null)
            {
                if (right != null)
                {
                    rule?.Children.Add(left);
                    rule?.Children.Add(right);

                    result = rule;
                }
                else
                {
                    result = left;
                    Rule   = left;
                }
            }
            else
            {
                result = right;
                Rule   = right;
            }

            return(result);
        }
示例#2
0
        private void CreateGenerationRule([NotNull] ThreatModel model,
                                          [NotNull] ThreatType source, [NotNull] IThreatType target)
        {
            SelectionRuleNode include = AnalyzeGenerationRule(model, target.Model, source.IncludeFilter);
            SelectionRuleNode exclude = AnalyzeGenerationRule(model, target.Model, source.ExcludeFilter);
            SelectionRule     rule    = null;

            var andNode = new AndRuleNode()
            {
                Name = "AND"
            };

            if (include != null)
            {
                andNode.Children.Add(include);
            }

            if (exclude != null)
            {
                andNode.Children.Add(new NotRuleNode()
                {
                    Name  = "NOT",
                    Child = exclude
                });
            }

            if (andNode.Children.Any())
            {
                andNode.Children.Add(new BooleanRuleNode("Out of Scope", Resources.DefaultNamespace, Resources.TmtFlowPropertySchema, false)
                {
                    Scope = AutoThreatGeneration.Engine.Scope.Object
                });

                rule = new SelectionRule()
                {
                    Root = andNode
                };

                var schemaManager = new AutoThreatGenPropertySchemaManager(target.Model);
                var propertyType  = schemaManager.GetPropertyType();
                var property      = target.GetProperty(propertyType) ?? target.AddProperty(propertyType, null);
                if (property is IPropertyJsonSerializableObject jsonSerializableObject)
                {
                    jsonSerializableObject.Value = rule;
                }
            }
        }