コード例 #1
0
        private void analysis_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter      = "SpreadSheets (*.xlsx) | *.xlsx";
            dialog.Multiselect = false;

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(dialog.FileName, false);
                    workbookPart = spreadsheetDocument.WorkbookPart;
                }
                catch
                {
                    System.Windows.MessageBox.Show("The specification file is open in a other process");
                }

                SheetData sheetData = null;

                try
                {
                    Sheet sheet = workbookPart.Workbook.Sheets.ChildElements.Cast <Sheet>().First(x => x.Name == "Assembly Specification");
                    int   index = workbookPart.WorksheetParts.ToList().IndexOf(workbookPart.WorksheetParts.Last()) - workbookPart.Workbook.Sheets.ToList().IndexOf(sheet);
                    sheetData = workbookPart.WorksheetParts.ElementAt(index).Worksheet.Elements <SheetData>().First();
                }
                catch
                {
                    System.Windows.MessageBox.Show("Invalid specification file :\nCouldn't find the 'Assembly Specification' worksheet");
                }

                List <Row>  rows      = sheetData.Elements <Row>().ToList();
                List <Cell> headerRow = rows.First().Elements <Cell>().ToList();
                rows.RemoveAll(x => !x.Elements <Cell>().Any(y => !string.IsNullOrEmpty(TextInCell(y))));

                string assemblyName;

                if (headerRow.Any(x => TextInCell(x) == "Signed"))
                {
                    List <SignatureSpecification> sigspecs = new List <SignatureSpecification>();
                    int sigIndex = headerRow.IndexOf(headerRow.First(x => TextInCell(x) == "Signed"));

                    foreach (Row r in rows)
                    {
                        List <Cell> row = r.Elements <Cell>().ToList();
                        assemblyName = TextInCell(row.ElementAt(0));
                        sigspecs.Add(new SignatureSpecification(assemblyName, TextInCell(row.ElementAt(sigIndex)) == "x"));
                    }

                    SignatureAnalyzer sigAnalyzer = new SignatureAnalyzer();
                    sigAnalyzer.Analyze(Model, sigspecs);
                }

                if (headerRow.Any(x => TextInCell(x) == "Obfuscated"))
                {
                    List <ObfuscationSpecification> obfuscationspecs = new List <ObfuscationSpecification>();
                    int obIndex = headerRow.IndexOf(headerRow.First(x => TextInCell(x) == "Obfuscated"));

                    foreach (Row r in rows)
                    {
                        List <Cell> row = r.Elements <Cell>().ToList();
                        assemblyName = TextInCell(row.ElementAt(0));
                        obfuscationspecs.Add(new ObfuscationSpecification(assemblyName, TextInCell(row.ElementAt(obIndex)) == "x"));
                    }

                    ObfuscationAnalyzer obfuscationAnalyzer = new ObfuscationAnalyzer();
                    obfuscationAnalyzer.Analyze(Model, obfuscationspecs);
                }

                Model.SoftwareComponents.Where(x => x.Name != "System Assemblies").ToList().ForEach(x => ModelCommonDataOrganizer.UpdateGroups(Model, x));
                UpdateTreeView();
                UpdateErrorNodes(GraphViewer.Graph);
                analysis.Visibility = Visibility.Hidden;
            }
        }
コード例 #2
0
        private bool BuildAndDisplay(DirectoryInfo directory)
        {
            Topmost = true;
            Topmost = false;

            //// Step 1 : Model creation
            Model = new Model();

            if (SpecWindow.ExcludeDefaultCSGraphicLibAssemblies)
            {
                ExcludeDotNETFrameworkAssemblies();
                Model.AddRegex("PresentationCore");
                Model.AddRegex("PresentationFramework");
                Model.AddRegex("WindowsBase");
                Model.AddRegex("System.Deployment");
                Model.AddRegex("System.Drawing");
                Model.AddRegex("System.Windows.Forms");
            }
            else if (SpecWindow.ExcludeDefaultCSLibAssemblies)
            {
                ExcludeDotNETFrameworkAssemblies();
            }

            try
            {
                Model.Build(directory);
                ModelCommonDataOrganizer.Organize(Model);
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show("Grapher can analyze only DLLs built with .NET assemblies: " + e.Message);
            }

            //// Step 2 : Specifications adding

            if (!string.IsNullOrEmpty(SpecWindow.SpecFilePath))
            {
                try
                {
                    ComponentsBuilder builder = new ComponentsBuilder(SpecWindow.SpecFilePath);
                    builder.Build(Model);
                    Model
                    .SoftwareComponents
                    .Where(x => x.Name != "System Assemblies")
                    .ToList()
                    .ForEach(x => ModelCommonDataOrganizer.UpdateGroups(Model, x));
                }
                catch
                {
                    return(false); // an exception is raised in JSONParser or in a SoftwareComponent constructor
                }
            }

            //// Step 3 : Model representation
            ResetViews();
            DrawGraph();
            UpdateTreeView();
            analysis.Visibility   = Visibility.Visible;
            hideErrors.Visibility = Visibility.Visible;
            startLabel.Visibility = Visibility.Hidden;

            return(true);
        }