private void Init(int id, int step, PhysicalLocation physicalLocation, string fullyQualifiedLogicalName, string logicalLocationKey, string module, int threadId, string message, AnnotatedCodeLocationKind kind, TaintKind taintKind, string target, IEnumerable <string> values, object state, string targetKey, bool essential, AnnotatedCodeLocationImportance importance, string snippet, IEnumerable <Annotation> annotations, IDictionary <string, SerializedPropertyInfo> properties) { Id = id; Step = step; if (physicalLocation != null) { PhysicalLocation = new PhysicalLocation(physicalLocation); } FullyQualifiedLogicalName = fullyQualifiedLogicalName; LogicalLocationKey = logicalLocationKey; Module = module; ThreadId = threadId; Message = message; Kind = kind; TaintKind = taintKind; Target = target; if (values != null) { var destination_0 = new List <string>(); foreach (var value_0 in values) { destination_0.Add(value_0); } Values = destination_0; } State = state; TargetKey = targetKey; Essential = essential; Importance = importance; Snippet = snippet; if (annotations != null) { var destination_1 = new List <Annotation>(); foreach (var value_1 in annotations) { if (value_1 == null) { destination_1.Add(null); } else { destination_1.Add(new Annotation(value_1)); } } Annotations = destination_1; } if (properties != null) { Properties = new Dictionary <string, SerializedPropertyInfo>(properties); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { AnnotatedCodeLocationKind kind = (AnnotatedCodeLocationKind)value; switch (kind) { case AnnotatedCodeLocationKind.Unknown: { return("Unknown"); } case AnnotatedCodeLocationKind.Stack: { return("Stack(s)"); } case AnnotatedCodeLocationKind.CodeFlow: { return("Code Flow(s)"); } } throw new InvalidOperationException("Unexpected annotated location kind:" + kind.ToString()); }
private static void CreateAnnotatedCodeLocationCollections( IEnumerable <IEnumerable <AnnotatedCodeLocation> > codeLocationCollections, AnnotatedCodeLocationKind annotatedCodeLocationKind, SarifError sarifError) { if (codeLocationCollections == null) { return; } foreach (IEnumerable <AnnotatedCodeLocation> codeLocations in codeLocationCollections) { CaptureAnnotatedCodeLocations(codeLocations, annotatedCodeLocationKind, sarifError); } }
private void PopulateControl(ObservableCollection <AnnotatedCodeLocationModel> items, IList <IList <AnnotatedCodeLocation> > annotatedCodeLocationSets, AnnotatedCodeLocationKind kind) { int index = 0; NewLineIndex newLineIndex = null; Dictionary <string, NewLineIndex> fileToNewLineIndexMap = new Dictionary <string, NewLineIndex>(); foreach (IList <AnnotatedCodeLocation> annotatedCodeLocations in annotatedCodeLocationSets) { index++; // Labels are 1-indexed in UI foreach (AnnotatedCodeLocation codeLocation in annotatedCodeLocations) { PhysicalLocationComponent plc = codeLocation.PhysicalLocation[0]; string fileName = plc.Uri.LocalPath; Region region = plc.Region; if (!File.Exists(fileName)) { fileName = RebaselineFileName(fileName, _remappedPathPrefixes); if (fileName == null) { // User cancelled items.Clear(); return; } } if (!fileToNewLineIndexMap.TryGetValue(fileName, out newLineIndex)) { fileToNewLineIndexMap[fileName] = newLineIndex = new NewLineIndex(File.ReadAllText(fileName)); } region.Populate(newLineIndex); items.Add(new AnnotatedCodeLocationModel() { Index = index, Kind = kind, Message = codeLocation.Message, Region = region, FilePath = fileName, }); } } }
private static void CaptureAnnotatedCodeLocations(IEnumerable <AnnotatedCodeLocation> codeLocations, AnnotatedCodeLocationKind annotatedCodeLocationKind, SarifError sarifError) { if (codeLocations == null) { return; } int annotationCollectionCount = 0; foreach (AnnotatedCodeLocation codeLocation in codeLocations) { PhysicalLocation plc = codeLocation.PhysicalLocation; sarifError.Annotations.Add(new AnnotatedCodeLocationModel() { Index = annotationCollectionCount, Kind = annotatedCodeLocationKind, Region = plc.Region, FilePath = plc.Uri.LocalPath, Message = codeLocation.Message }); annotationCollectionCount++; } }
/// <summary> /// Initializes a new instance of the <see cref="AnnotatedCodeLocation" /> class from the supplied values. /// </summary> /// <param name="id"> /// An initialization value for the <see cref="P: Id" /> property. /// </param> /// <param name="step"> /// An initialization value for the <see cref="P: Step" /> property. /// </param> /// <param name="physicalLocation"> /// An initialization value for the <see cref="P: PhysicalLocation" /> property. /// </param> /// <param name="fullyQualifiedLogicalName"> /// An initialization value for the <see cref="P: FullyQualifiedLogicalName" /> property. /// </param> /// <param name="logicalLocationKey"> /// An initialization value for the <see cref="P: LogicalLocationKey" /> property. /// </param> /// <param name="module"> /// An initialization value for the <see cref="P: Module" /> property. /// </param> /// <param name="threadId"> /// An initialization value for the <see cref="P: ThreadId" /> property. /// </param> /// <param name="message"> /// An initialization value for the <see cref="P: Message" /> property. /// </param> /// <param name="kind"> /// An initialization value for the <see cref="P: Kind" /> property. /// </param> /// <param name="taintKind"> /// An initialization value for the <see cref="P: TaintKind" /> property. /// </param> /// <param name="target"> /// An initialization value for the <see cref="P: Target" /> property. /// </param> /// <param name="values"> /// An initialization value for the <see cref="P: Values" /> property. /// </param> /// <param name="state"> /// An initialization value for the <see cref="P: State" /> property. /// </param> /// <param name="targetKey"> /// An initialization value for the <see cref="P: TargetKey" /> property. /// </param> /// <param name="essential"> /// An initialization value for the <see cref="P: Essential" /> property. /// </param> /// <param name="importance"> /// An initialization value for the <see cref="P: Importance" /> property. /// </param> /// <param name="snippet"> /// An initialization value for the <see cref="P: Snippet" /> property. /// </param> /// <param name="annotations"> /// An initialization value for the <see cref="P: Annotations" /> property. /// </param> /// <param name="properties"> /// An initialization value for the <see cref="P: Properties" /> property. /// </param> public AnnotatedCodeLocation(int id, int step, PhysicalLocation physicalLocation, string fullyQualifiedLogicalName, string logicalLocationKey, string module, int threadId, string message, AnnotatedCodeLocationKind kind, TaintKind taintKind, string target, IEnumerable <string> values, object state, string targetKey, bool essential, AnnotatedCodeLocationImportance importance, string snippet, IEnumerable <Annotation> annotations, IDictionary <string, SerializedPropertyInfo> properties) { Init(id, step, physicalLocation, fullyQualifiedLogicalName, logicalLocationKey, module, threadId, message, kind, taintKind, target, values, state, targetKey, essential, importance, snippet, annotations, properties); }
private void ProcessLine(string logFileLine, Result result) { var codeFlow = result.CodeFlows[0]; const int STEP = 0; const int URI = 1; const int LINE = 2; // const int IMPORTANCE = 3; This value not persisted to SARIF const int STATE = 4; const int KIND1 = 5; // When KIND1 == "Atomic" the 6th slot is the // the remainder of the kind id, e.g., Atomic Assigment const int KIND2 = 6; // When KIND1 == "Call" the 6th and 7th slots are: const int CALLER = 6; const int CALLEE = 7; int step; string[] tokens = logFileLine.Split(' '); if (int.TryParse(tokens[STEP], out step)) { // If we find a numeric value as the first token, // this is a general step. Uri uri = null; string uriText = tokens[URI].Trim('"'); if (!uriText.Equals("?", StringComparison.Ordinal)) { if (File.Exists(uriText)) { uriText = Path.GetFullPath(uriText); } uri = new Uri(uriText, UriKind.RelativeOrAbsolute); } // We assume a valid line here. This code will throw if not. int line = int.Parse(tokens[LINE]); string sdvKind = tokens[KIND1]; if (sdvKind.Equals("Atomic", StringComparison.Ordinal)) { // For multipart SDV kinds 'Atomic XXX', we // map using the second value only, e.g, // 'Assignment' or 'Conditional' sdvKind = tokens[KIND2]; } AnnotatedCodeLocationKind kind = ConvertToAnnotatedCodeLocationKind(sdvKind.Trim()); var annotatedCodeLocation = new AnnotatedCodeLocation { Kind = kind, Step = step, Importance = AnnotatedCodeLocationImportance.Unimportant, PhysicalLocation = (uri != null) ? new PhysicalLocation { Uri = uri, Region = new Region { StartLine = line } } : null, }; if (kind == AnnotatedCodeLocationKind.Call) { string extraMsg = tokens[KIND1] + " " + tokens[CALLER] + " " + tokens[CALLEE]; string caller, callee; if (ExtractCallerAndCallee(extraMsg.Trim(), out caller, out callee)) { annotatedCodeLocation.FullyQualifiedLogicalName = caller; annotatedCodeLocation.Target = callee; _callers.Push(caller); } else { Debug.Assert(false); } if (uri == null) { annotatedCodeLocation.Importance = AnnotatedCodeLocationImportance.Unimportant; } else if (IsHarnessOrRulesFiles(uriText)) { annotatedCodeLocation.Importance = AnnotatedCodeLocationImportance.Important; } else { annotatedCodeLocation.Importance = AnnotatedCodeLocationImportance.Essential; } } if (kind == AnnotatedCodeLocationKind.CallReturn) { Debug.Assert(_callers.Count > 0); annotatedCodeLocation.FullyQualifiedLogicalName = _callers.Pop(); } string separatorText = "^====Auto====="; string state = tokens[STATE]; string[] stateTokens = state.Split(new string[] { separatorText }, StringSplitOptions.RemoveEmptyEntries); if (stateTokens.Length > 0) { if (stateTokens.Length == 2) { annotatedCodeLocation.SetProperty("currentDataValues", stateTokens[0]); annotatedCodeLocation.SetProperty("permanentDataValues", stateTokens[1]); } else { Debug.Assert(stateTokens.Length == 1); if (stateTokens[0].StartsWith(separatorText)) { annotatedCodeLocation.SetProperty("permanentDataValues", stateTokens[0]); } else { annotatedCodeLocation.SetProperty("currentDataValues", stateTokens[0]); } } } codeFlow.Locations.Add(annotatedCodeLocation); } else { // This is the defect message. const int LEVEL = 0; string levelText = tokens[LEVEL]; result.Level = ConvertToResultLevel(levelText); // Everything on the line following defect level comprises the message result.Message = logFileLine.Substring(levelText.Length).Trim(); // SDV currently produces 'pass' notifications when // the final line is prefixed with 'Error'. We'll examine // the message text to detect this condition if (result.Message.Contains("is satisfied")) { result.Level = ResultLevel.Pass; } // Finally, populate this result location with the // last observed location in the code flow. IList <AnnotatedCodeLocation> locations = result.CodeFlows[0].Locations; for (int i = locations.Count - 1; i >= 0; --i) { if (locations[i].PhysicalLocation != null) { result.Locations.Add(new Location { ResultFile = locations[i].PhysicalLocation }); break; } } } }
private void Init(int id, int step, PhysicalLocation physicalLocation, string fullyQualifiedLogicalName, string logicalLocationKey, string module, int threadId, string message, AnnotatedCodeLocationKind kind, TaintKind taintKind, string target, IEnumerable<string> values, object state, string targetKey, bool essential, AnnotatedCodeLocationImportance importance, string snippet, IEnumerable<Annotation> annotations, IDictionary<string, SerializedPropertyInfo> properties) { Id = id; Step = step; if (physicalLocation != null) { PhysicalLocation = new PhysicalLocation(physicalLocation); } FullyQualifiedLogicalName = fullyQualifiedLogicalName; LogicalLocationKey = logicalLocationKey; Module = module; ThreadId = threadId; Message = message; Kind = kind; TaintKind = taintKind; Target = target; if (values != null) { var destination_0 = new List<string>(); foreach (var value_0 in values) { destination_0.Add(value_0); } Values = destination_0; } State = state; TargetKey = targetKey; Essential = essential; Importance = importance; Snippet = snippet; if (annotations != null) { var destination_1 = new List<Annotation>(); foreach (var value_1 in annotations) { if (value_1 == null) { destination_1.Add(null); } else { destination_1.Add(new Annotation(value_1)); } } Annotations = destination_1; } if (properties != null) { Properties = new Dictionary<string, SerializedPropertyInfo>(properties); } }
/// <summary> /// Initializes a new instance of the <see cref="AnnotatedCodeLocation" /> class from the supplied values. /// </summary> /// <param name="id"> /// An initialization value for the <see cref="P: Id" /> property. /// </param> /// <param name="step"> /// An initialization value for the <see cref="P: Step" /> property. /// </param> /// <param name="physicalLocation"> /// An initialization value for the <see cref="P: PhysicalLocation" /> property. /// </param> /// <param name="fullyQualifiedLogicalName"> /// An initialization value for the <see cref="P: FullyQualifiedLogicalName" /> property. /// </param> /// <param name="logicalLocationKey"> /// An initialization value for the <see cref="P: LogicalLocationKey" /> property. /// </param> /// <param name="module"> /// An initialization value for the <see cref="P: Module" /> property. /// </param> /// <param name="threadId"> /// An initialization value for the <see cref="P: ThreadId" /> property. /// </param> /// <param name="message"> /// An initialization value for the <see cref="P: Message" /> property. /// </param> /// <param name="kind"> /// An initialization value for the <see cref="P: Kind" /> property. /// </param> /// <param name="taintKind"> /// An initialization value for the <see cref="P: TaintKind" /> property. /// </param> /// <param name="target"> /// An initialization value for the <see cref="P: Target" /> property. /// </param> /// <param name="values"> /// An initialization value for the <see cref="P: Values" /> property. /// </param> /// <param name="state"> /// An initialization value for the <see cref="P: State" /> property. /// </param> /// <param name="targetKey"> /// An initialization value for the <see cref="P: TargetKey" /> property. /// </param> /// <param name="essential"> /// An initialization value for the <see cref="P: Essential" /> property. /// </param> /// <param name="importance"> /// An initialization value for the <see cref="P: Importance" /> property. /// </param> /// <param name="snippet"> /// An initialization value for the <see cref="P: Snippet" /> property. /// </param> /// <param name="annotations"> /// An initialization value for the <see cref="P: Annotations" /> property. /// </param> /// <param name="properties"> /// An initialization value for the <see cref="P: Properties" /> property. /// </param> public AnnotatedCodeLocation(int id, int step, PhysicalLocation physicalLocation, string fullyQualifiedLogicalName, string logicalLocationKey, string module, int threadId, string message, AnnotatedCodeLocationKind kind, TaintKind taintKind, string target, IEnumerable<string> values, object state, string targetKey, bool essential, AnnotatedCodeLocationImportance importance, string snippet, IEnumerable<Annotation> annotations, IDictionary<string, SerializedPropertyInfo> properties) { Init(id, step, physicalLocation, fullyQualifiedLogicalName, logicalLocationKey, module, threadId, message, kind, taintKind, target, values, state, targetKey, essential, importance, snippet, annotations, properties); }