public static bool TryProcessPathsAndCreateAnalysisPackage(string outputDir, string[] originalClousotOptions, bool createThePackage, out AnalysisPackageInfo clousotOptions) { Contract.Requires(outputDir != null); Contract.Requires(originalClousotOptions != null); Contract.Ensures(!createThePackage || !Contract.Result <bool>() || Contract.ValueAtReturn(out clousotOptions).PackageFileName != null); clousotOptions = new AnalysisPackageInfo(); clousotOptions.ClousotOptions = originalClousotOptions; try { // Step 0: make sure the output dir exists DirectoryInfo outputDirInfo; if (Directory.Exists(outputDir)) { outputDirInfo = new DirectoryInfo(outputDir); } else { outputDirInfo = Directory.CreateDirectory(outputDir); } // Step 1: Expand the response file, set the field if (!FlattenClousotOptions(originalClousotOptions, out clousotOptions.ExpandedClousotOptions)) { return(false); } Contract.Assert(clousotOptions.ExpandedClousotOptions != null); var pathsInTheExpandedCommandLine = ExtractPathsAndUpdateThePackageInfo(ref clousotOptions); if (createThePackage) { // Step 2: Create the analysis package --- Go over all the directories and files, compress them, and save it in outputDirInfo clousotOptions.PackageFileName = CreateAnalysisPackage(outputDirInfo, pathsInTheExpandedCommandLine, clousotOptions.ExpandedClousotOptions); return(clousotOptions.PackageFileName != null); } else { return(true); } } catch (Exception) { // Something went wrong, we just abort return(false); } }
public static bool TryProcessPathsAndCreateAnalysisPackage(string outputDir, string[] originalClousotOptions, bool createThePackage, out AnalysisPackageInfo clousotOptions) { Contract.Requires(outputDir != null); Contract.Requires(originalClousotOptions != null); Contract.Ensures(!createThePackage || !Contract.Result<bool>() || Contract.ValueAtReturn(out clousotOptions).PackageFileName != null); clousotOptions = new AnalysisPackageInfo(); clousotOptions.ClousotOptions = originalClousotOptions; try { // Step 0: make sure the output dir exists DirectoryInfo outputDirInfo; if (Directory.Exists(outputDir)) { outputDirInfo = new DirectoryInfo(outputDir); } else { outputDirInfo = Directory.CreateDirectory(outputDir); } // Step 1: Expand the response file, set the field if (!FlattenClousotOptions(originalClousotOptions, out clousotOptions.ExpandedClousotOptions)) { return false; } Contract.Assert(clousotOptions.ExpandedClousotOptions != null); var pathsInTheExpandedCommandLine = ExtractPathsAndUpdateThePackageInfo(ref clousotOptions); if (createThePackage) { // Step 2: Create the analysis package --- Go over all the directories and files, compress them, and save it in outputDirInfo clousotOptions.PackageFileName = CreateAnalysisPackage(outputDirInfo, pathsInTheExpandedCommandLine, clousotOptions.ExpandedClousotOptions); return (clousotOptions.PackageFileName != null); } else { return true; } } catch (Exception) { // Something went wrong, we just abort return false; } }
private static List <Tuple <int, string> > ExtractPathsAndUpdateThePackageInfo(ref AnalysisPackageInfo packageInfo) { Contract.Requires(packageInfo.ExpandedClousotOptions != null); Contract.Ensures(packageInfo.AssembliesToAnalyze != null); Contract.Ensures(packageInfo.ExpandedClousotOptions == Contract.OldValue(packageInfo.ExpandedClousotOptions)); var result = new List <Tuple <int, string> >(); var assembliesToAnalyse = new List <string>(); var expandedClousotOptions = packageInfo.ExpandedClousotOptions; // Very stuping parsing algorithm, to be improved? // Step 0: get the clousot options that contain paths var clousotOptionsForPaths = GeneralOptions.GetClousotOptionsWithPaths().ToArray(); // Use ToArray to speed up the look ups // Step 1: go all over the clousot options to find those fields, or the dirs we are interested in for (var i = 0; i < expandedClousotOptions.Length; i++) { var option = expandedClousotOptions[i]; var pathsInTheOptions = GetPaths(option); // Step 1a : Is the current option a path? if (pathsInTheOptions.Count == 1) { // PrintPaths(pathsInTheOptions, "Found an assembly to analyze:"); AddIntoResult(result, i, pathsInTheOptions); // Executed only once because of the test above foreach (var match in pathsInTheOptions) { assembliesToAnalyse.Add(match.ToString()); } } // Step 1b : search inside the option else { option = option.Substring(1); // Remove the first char var tryFind = clousotOptionsForPaths.Where(t => option.StartsWith(t)); // Found a match if (tryFind.Any()) { foreach (var candidatePath in option.Split(';')) { var matches = GetPaths(candidatePath); // PrintPaths(matches, "Found path(s) for option in position " + i); AddIntoResult(result, i, matches); } } } } // Step 2: create the normalized command line var clonedCommandLine = packageInfo.ExpandedClousotOptions.Clone() as string[]; Contract.Assume(clonedCommandLine != null); foreach (var pair in result) { string unc; if (FileSystemAbstractions.TryGetUniversalName(Path.GetFullPath(pair.Item2), out unc)) { clonedCommandLine[pair.Item1] = clonedCommandLine[pair.Item1].Replace(pair.Item2, unc); } else { clonedCommandLine = null; break; } } packageInfo.AssembliesToAnalyze = assembliesToAnalyse.ToArray(); packageInfo.ExpandedClousotOptionsNormalized = clonedCommandLine; return(result); }
private static List<Tuple<int, string>> ExtractPathsAndUpdateThePackageInfo(ref AnalysisPackageInfo packageInfo) { Contract.Requires(packageInfo.ExpandedClousotOptions != null); Contract.Ensures(packageInfo.AssembliesToAnalyze != null); Contract.Ensures(packageInfo.ExpandedClousotOptions == Contract.OldValue(packageInfo.ExpandedClousotOptions)); var result = new List<Tuple<int, string>>(); var assembliesToAnalyse = new List<string>(); var expandedClousotOptions = packageInfo.ExpandedClousotOptions; // Very stuping parsing algorithm, to be improved? // Step 0: get the clousot options that contain paths var clousotOptionsForPaths = GeneralOptions.GetClousotOptionsWithPaths().ToArray(); // Use ToArray to speed up the look ups // Step 1: go all over the clousot options to find those fields, or the dirs we are interested in for (var i = 0; i < expandedClousotOptions.Length; i++) { var option = expandedClousotOptions[i]; var pathsInTheOptions = GetPaths(option); // Step 1a : Is the current option a path? if(pathsInTheOptions.Count == 1) { // PrintPaths(pathsInTheOptions, "Found an assembly to analyze:"); AddIntoResult(result, i, pathsInTheOptions); // Executed only once because of the test above foreach (var match in pathsInTheOptions) { assembliesToAnalyse.Add(match.ToString()); } } // Step 1b : search inside the option else { option = option.Substring(1); // Remove the first char var tryFind = clousotOptionsForPaths.Where(t => option.StartsWith(t)); // Found a match if(tryFind.Any()) { foreach (var candidatePath in option.Split(';')) { var matches = GetPaths(candidatePath); // PrintPaths(matches, "Found path(s) for option in position " + i); AddIntoResult(result, i, matches); } } } } // Step 2: create the normalized command line var clonedCommandLine = packageInfo.ExpandedClousotOptions.Clone() as string[]; Contract.Assume(clonedCommandLine != null); foreach(var pair in result) { string unc; if(FileSystemAbstractions.TryGetUniversalName(Path.GetFullPath(pair.Item2), out unc)) { clonedCommandLine[pair.Item1] = clonedCommandLine[pair.Item1].Replace(pair.Item2, unc); } else { clonedCommandLine = null; break; } } packageInfo.AssembliesToAnalyze = assembliesToAnalyse.ToArray(); packageInfo.ExpandedClousotOptionsNormalized = clonedCommandLine; return result; }