コード例 #1
0
        public async Task DebugPatternFinderTest()
        {
            // Arrange
            var solutionPath          = Path.GetFullPath(@"..\Solution.sln");
            var configurationItemPath = Path.GetFullPath(@"..\ConfigurationItem.xml");

            var patternFinder = new PatternFinder();
            await patternFinder.Initialize(new List <string> {
                configurationItemPath
            }, new List <string>() { solutionPath }, true);

            // Act
            var results = patternFinder.FindPatterns();

            // Assert
            Assert.IsNotNull(results);
        }
コード例 #2
0
        public static async Task Main(string[] args)
        {
            var solutionPath            = string.Empty;
            var configurationFolderPath = string.Empty;

            if (args.Length == 0)
            {
                Console.WriteLine("Please provide the following parameters:");
                Console.WriteLine("/solutionPath=");
                Console.WriteLine("/configurationFolderPath=");
                return;
            }

            foreach (var arg in args)
            {
                var name  = arg;
                var value = string.Empty;

                if (arg.Contains('='))
                {
                    name  = arg.Substring(0, arg.IndexOf('='));
                    value = arg.Substring(arg.IndexOf('=') + 1);

                    switch (name.ToLower())
                    {
                    case "/solutionpath":
                        solutionPath = value;
                        break;

                    case "/configurationfolderpath":
                        if (value.EndsWith("\\"))
                        {
                            value = value.Substring(0, value.Length - 1);
                        }
                        configurationFolderPath = value;
                        break;

                    default:
                        break;
                    }
                }
            }

            if (string.IsNullOrEmpty(solutionPath) || !File.Exists(solutionPath))
            {
                Console.WriteLine("Invalid solution path provided.");
                return;
            }

            if (string.IsNullOrEmpty(configurationFolderPath) || !Directory.Exists(configurationFolderPath))
            {
                Console.WriteLine("Invalid configuration folder path provided.");
                return;
            }

            Helpers.SetMSBuildVersion(null);

            var configurationFiles = Helpers.GetConfigurationFiles(configurationFolderPath);

            var finder = new PatternFinder();

            Console.WriteLine("Initializing configuration and loading solution.");
            await finder.Initialize(configurationFiles, new List <string> {
                solutionPath
            }, true);

            Console.WriteLine("Scanning solution.");
            var results = finder.FindPatterns();

            ResultFormatter.PrintResults(results);

            Console.ReadKey();
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: Tilps/Stash
        private void button4_Click(object sender, EventArgs e)
        {
            #if DEBUG
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "CSV|*.csv";
            if (dialog.ShowDialog() == DialogResult.OK)
            {

                Dictionary<string, DatFile2> files = new Dictionary<string, DatFile2>();
                try
                {
                    Dictionary<string, List<int>> ids = new Dictionary<string, List<int>>();
                    List<string> fullPattern = new List<string>();
                    using (CSV csv = new CSV(dialog.FileName))
                    {
                        csv.GetRow();
                        while (true)
                        {
                            string[] row = csv.GetRow();
                            if (row == null)
                                break;
                            string path = row[5];
                            string fileName = Path.GetFileName(path);
                            if (!fileName.StartsWith("client_") || (!fileName.EndsWith(".dat") && !fileName.EndsWith(".datx")))
                                continue;
                            DatFile2 file;
                            if (!files.TryGetValue(path, out file))
                            {
                                try
                                {
                                    file = new DatFile2(path);
                                    files.Add(path, file);
                                    file.CheckJumpTables();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(string.Format("Error processing {0}, Exception: {1}", path, ex.ToString()));
                                    return;
                                }
                                ids[fileName] = new List<int>();
                            }
                            string result = row[7];
                            long offset;
                            long length;
                            bool hitDisk;
                            if (ParseResult(result, out offset, out length, out hitDisk))
                            {
                                if (!hitDisk)
                                {
                                    int id;
                                    if (file.TryMapToId(offset, out id))
                                    {
                                        string check = fileName + ":" + id.ToString();
                                        ids[fileName].Add(id);
                                        fullPattern.Add(check);
                                    }
                                }
                            }
                        }
                    }
                    PatternFinder<string> patterns = new PatternFinder<string>(fullPattern, EqualityComparer<string>.Default);
                    PatternFinder<string>.PatternTree tree = patterns.FindPatterns();
                }
                finally
                {
                    foreach (DatFile2 file in files.Values)
                    {
                        file.Dispose();
                    }
                }
            }
            Viewer view = new Viewer();
            view.Show(this);
            #endif
        }