Пример #1
0
        private static string[] ForgeClousotCommandLineFromOutputFile(string outputDir)
        {
            try
            {
                var lines            = File.ReadAllLines(Path.Combine(outputDir, CloudotInstructionsFileName));
                var result           = new List <string>();
                var optionsWithPaths = GeneralOptions.GetClousotOptionsWithPaths().ToArray();
                var optionsBounds    = FindOptions(lines);
                for (var i = optionsBounds.Item1; i < optionsBounds.Item2; i++)
                {
                    var line = lines[i];
                    if (line.Length > 0)
                    {
                        var subLine = line.Substring(1);
                        if (optionsWithPaths.Any(optionName => subLine.StartsWith(optionName)))
                        {
                            line = ReplaceVolumesWithLocalRootPath(outputDir, line);
                        }
                        else if (IsPath(line))
                        {
                            line = ReplaceVolumesWithLocalRootPath(outputDir, line);
                        }
                    }
                    result.Add(line);
                }

                return(result.ToArray());
            }
            catch (Exception)
            {
                CloudotLogging.WriteLine("Something went wrong while getting the cmd line from dir {0}", outputDir);
                return(null);
            }
        }
Пример #2
0
        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);
        }