private static void appendAttributes(StringBuilder sb, StixDataEntityBase entity, bool showDescription) { var hasAttributes = entity.GetType() == typeof(AttackPattern) || entity.GetType() == typeof(CourseOfAction); if (!hasAttributes) { return; } if (showDescription) { sb.AppendLine("<i><size=140%>Attributes</size></i>"); sb.AppendLine(); } if (entity.GetType() == typeof(AttackPattern)) { appendAttackPatternAttributes(sb, (AttackPattern)entity); } else if (entity.GetType() == typeof(CourseOfAction)) { appendCourseOfActionAttributes(sb, (CourseOfAction)entity); } sb.AppendLine("<indent=0>"); }
private static void appendRelationships(StringBuilder sb, StixDataEntityBase entity) { sb.AppendLine("<i><size=140%>Relationships</size></i>"); sb.AppendLine(); if (entity.GetType() == typeof(Asset)) { var asset = (Asset)entity; // Is targeted by attack patterns var targetedBy = State.I.GameEntities.SDOs.attack_patterns.Where( (aP) => aP.custom.activation_zone.categories.Any( (c) => c == asset.custom.category)); var targetedByStrings = targetedBy.Select((aP) => aP.name); sb.AppendLine(buildAttributeText("Targeted by", targetedByStrings.Join("; "))); } else if (entity.GetType() == typeof(AttackPattern)) { var attackPattern = (AttackPattern)entity; // Targets assets var targets = attackPattern.custom.activation_zone.categories.Select(EnumHelper.GetEnumMemberAttributeValue); sb.AppendLine(buildAttributeText("Targets", targets.Join("; "))); // Mitigated by course of actions var mitigatedBy = State.I.GameEntities.SDOs.course_of_actions.Where( (c) => attackPattern.MitigatedByCategories.Contains(c.custom.category)); var mitigatedByStrings = mitigatedBy.Select((c) => c.custom.mitigation); sb.AppendLine(buildAttributeText("Mitigated by", mitigatedByStrings.Join("; "))); } else if (entity.GetType() == typeof(CourseOfAction)) { var courseOfAction = (CourseOfAction)entity; // Mitigates attack patterns var mitigates = State.I.GameEntities.SDOs.attack_patterns.Where( (aP) => aP.MitigatedByCategories.Contains(courseOfAction.custom.category)); var mitigatesStrings = mitigates.Select((c) => c.name); sb.AppendLine(buildAttributeText("Mitigates", mitigatesStrings.Join("; "))); } sb.AppendLine("<indent=0>"); }