-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added feature to open and convert non-sarif static analysis file to sarif for analysis (#79) * New command to activate the converter is "Sarif: Convert and open a non-sarif file" * Supported analysis tool files are: * AndroidStudio, ClangAnalyzer, CppCheck, Fortify, FortifyFpr, FxCop, PREfast, Pylint, SemmleQL, StaticDriverVerifier, TSLint * Added support for showing QuickFix light bulb and context menu in the Problems panel when a Sarif result can be remapped (#98) * Fixed bug where the UI dialog for remapping allowed a non valid path to be entered (#92) * Fixed bug where the Sarif Explorer showed empty when a sarif result was missing data such as rule id, rule name or location (#94)
- Loading branch information
Showing
127 changed files
with
582 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+14 KB
resources/sarif.multitool/System.Diagnostics.TextWriterTraceListener.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+14.5 KB
resources/sarif.multitool/System.Runtime.CompilerServices.VisualC.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+21 KB
resources/sarif.multitool/System.Runtime.InteropServices.RuntimeInformation.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+19.5 KB
resources/sarif.multitool/System.Runtime.Serialization.Primitives.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+14.5 KB
resources/sarif.multitool/System.Security.Cryptography.Primitives.dll
Binary file not shown.
Binary file added
BIN
+15.5 KB
resources/sarif.multitool/System.Security.Cryptography.X509Certificates.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// /******************************************************** | ||
// * * | ||
// * Copyright (C) Microsoft. All rights reserved. * | ||
// * * | ||
// ********************************************************/ | ||
import { | ||
commands, extensions, MessageOptions, OpenDialogOptions, TextDocumentShowOptions, Uri, ViewColumn, window, | ||
} from "vscode"; | ||
import { Utilities } from "./Utilities"; | ||
|
||
/** | ||
* Handles converting a non sarif static analysis file to a sarif file via the sarif-sdk multitool | ||
*/ | ||
export class FileConverter { | ||
public static ConvertCommand = "extension.sarif.Convert"; | ||
|
||
/** | ||
* Opens a quick pick list to select a tool, then opens a file picker to select the file and converts selected file | ||
*/ | ||
public static selectConverter() { | ||
let tool: string; | ||
window.showQuickPick(Array.from(FileConverter.Tools.keys())).then((value: string) => { | ||
if (value === undefined) { | ||
return; | ||
} | ||
|
||
tool = value; | ||
const dialogOptions = { canSelectFiles: true, canSelectMany: false, filters: {} } as OpenDialogOptions; | ||
const toolExt = FileConverter.Tools.get(tool); | ||
dialogOptions.filters[`${tool} log files`] = toolExt; | ||
|
||
return window.showOpenDialog(dialogOptions); | ||
}).then((uris: Uri[]) => { | ||
if (uris !== undefined && uris.length > 0) { | ||
FileConverter.convert(uris[0], tool); | ||
} | ||
}); | ||
} | ||
|
||
private static childProcess; | ||
private static multiTool: string; | ||
private static tools: Map<string, string[]>; | ||
|
||
private static get ChildProcess() { | ||
if (FileConverter.childProcess === undefined) { | ||
FileConverter.childProcess = require("child_process"); | ||
} | ||
|
||
return FileConverter.childProcess; | ||
} | ||
|
||
private static get MultiTool(): string { | ||
if (FileConverter.multiTool === undefined) { | ||
FileConverter.multiTool = extensions.getExtension("MS-SarifVSCode.sarif-viewer").extensionPath + | ||
"/resources/sarif.multitool/Sarif.Multitool.exe"; | ||
} | ||
|
||
return FileConverter.multiTool; | ||
} | ||
|
||
private static get Tools(): Map<string, string[]> { | ||
if (FileConverter.tools === undefined) { | ||
FileConverter.tools = new Map<string, string[]>(); | ||
FileConverter.tools.set("AndroidStudio", ["xml"]); | ||
FileConverter.tools.set("ClangAnalyzer", ["xml"]); | ||
FileConverter.tools.set("CppCheck", ["xml"]); | ||
FileConverter.tools.set("Fortify", ["xml"]); | ||
FileConverter.tools.set("FortifyFpr", ["fpr"]); | ||
FileConverter.tools.set("FxCop", ["fxcop", "xml"]); | ||
FileConverter.tools.set("PREfast", ["xml"]); | ||
FileConverter.tools.set("Pylint", ["json"]); | ||
FileConverter.tools.set("SemmleQL", ["csv"]); | ||
FileConverter.tools.set("StaticDriverVerifier", ["tt"]); | ||
FileConverter.tools.set("TSLint", ["json"]); | ||
} | ||
|
||
return FileConverter.tools; | ||
} | ||
|
||
/** | ||
* Converts a file generated by a tool to a sarif file format using the sarif sdk multitool | ||
* @param uri path to the file to convert | ||
* @param tool tool that generated the file to convert | ||
*/ | ||
private static convert(uri: Uri, tool: string) { | ||
const output = Utilities.generateTempPath(uri.fsPath) + ".sarif"; | ||
const proc = FileConverter.ChildProcess.spawn(FileConverter.MultiTool, | ||
["convert", "-t", tool, "-o", output, "-p", "-f", uri.fsPath], | ||
); | ||
|
||
proc.on("close", (code) => { | ||
if (code === 0) { | ||
commands.executeCommand("vscode.open", Uri.file(output), | ||
{ preserveFocus: false, preview: false, viewColumn: ViewColumn.One } as TextDocumentShowOptions); | ||
} else { | ||
window.showErrorMessage(`Sarif converter failed with error code: ${code}`, | ||
{ modal: false } as MessageOptions); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.