Exemplo n.º 1
0
        /// <summary>Initializes a new instance of the <see cref="Main"/> class.</summary>
        public Main()
        {
            InitializeComponent();

            // Initialize variables
            UpdateStatus(Resources.Analyzer_Preparing);

            // Initialize the Assembly Analyzer background worker
            assemblyWorker = new BackgroundWorker
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = true
            };

            assemblyWorker.DoWork             += AssemblyWorker_DoWork;
            assemblyWorker.ProgressChanged    += AssemblyWorker_ProgressChanged;
            assemblyWorker.RunWorkerCompleted += AssemblyWorker_WorkerCompleted;

            // Initialize variables.
            duration = new Stopwatch();

            // Configure decompiler
            assemblyAnalyzer = new AssemblyAnalyzer();

            // Report settings
            assemblyDashboard.ReloadDashboardPropertyGrids(assemblyAnalyzer.AssemblyPropertiesInfo, assemblyAnalyzer.Settings);

            // Assembly tree view information explorer
            assemblyExplorer.ResetAssemblyExplorerPropertyGrid();

            // Loads settings
            Cb_BrowseAfterBuild.Checked = Settings.Default.OpenBuildDirectoryOnOutput;
        }
Exemplo n.º 2
0
        public void Reports_test_assembly_as_csharp()
        {
            var analyzer = new AssemblyAnalyzer(typeof(Sanity_tests).GetTypeInfo().Assembly);

            var result = analyzer.DetectedLanguage;
            result.Should().Be(Language.CSharp);
        }
 /// <summary>
 /// Cria uma instancia já definindo o Worker background.
 /// </summary>
 /// <param name="assembliesDirectory"></param>
 /// <param name="observer"></param>
 public AssemblyInfoRepository(string assembliesDirectory, IAssemblyInfoRepositoryObserver observer)
 {
     assembliesDirectory.Require("assembliesDirectory").NotNull().NotEmpty();
     _assembliesDirectory = assembliesDirectory;
     _assemblyAnalyzer    = new AssemblyAnalyzer();
     _observer            = observer;
 }
Exemplo n.º 4
0
 public void OnInit()
 {
     AssemblyAnalyzer.AnalyzeAssemblies(new ActionReturnTypeAggregatorFinder()
     {
         schema = this
     });
 }
Exemplo n.º 5
0
        private string VerifyValidAssemblies()
        {
            List <ListViewItem> invalid_assemblies = new List <ListViewItem> ();

            foreach (ListViewItem lvi in AssemblyListView.Items)
            {
                if (!AssemblyAnalyzer.IsValidAssembly((string)lvi.Tag))
                {
                    invalid_assemblies.Add(lvi);
                }
            }

            string msg = "The following are not valid .Net assemblies and will not be scanned:\n";

            foreach (ListViewItem lvi in invalid_assemblies)
            {
                msg += string.Format("{0}\n", lvi.Text);
                AssemblyListView.Items.Remove(lvi);
            }

            if (invalid_assemblies.Count == 0)
            {
                return(string.Empty);
            }

            return(msg);
        }
Exemplo n.º 6
0
 public void OnInit()
 {
     AssemblyAnalyzer.AnalyzeAssemblies(new ActionArgumentComponentFinder()
     {
         schema = this
     });
 }
Exemplo n.º 7
0
 public void OnInit()
 {
     AssemblyAnalyzer.AnalyzeAssemblies(new NodeLayoutHandlerFinder()
     {
         schema = this
     });
 }
Exemplo n.º 8
0
 public void OnInit()
 {
     AssemblyAnalyzer.AnalyzeAssemblies(new SerializableMemberFinder()
     {
         cache = this
     });
 }
Exemplo n.º 9
0
        public static void ProcessAssemblies(ScannerConfiguration configuration)
        {
            foreach (var instrumentationSet in configuration.InstrumentationSets)
            {
                // load the instrumentation.xml and create InstrumentationModel
                var instrumentationModel = ReadInstrumentationFile(instrumentationSet);

                // nuget assemblies
                var downloadedNugetInfoList = GetNugetAssemblies(instrumentationSet, instrumentationModel.UniqueAssemblies);

                foreach (var downloadedNugetInfo in downloadedNugetInfoList)
                {
                    foreach (var intrumentedDllFileLocation in downloadedNugetInfo.InstrumentedDllFileLocations)
                    {
                        // Builds a model from the files
                        Console.WriteLine($"Starting scan of '{intrumentedDllFileLocation}'");
                        var assemblyAnalyzer = new AssemblyAnalyzer();
                        var assemblyAnalysis = assemblyAnalyzer.RunAssemblyAnalysis(intrumentedDllFileLocation);

                        var instrumentationValidator = new InstrumentationValidator(assemblyAnalysis);

                        // just some debugging writes
                        Console.WriteLine($"Found {assemblyAnalysis.ClassesCount} classes");
                        Console.WriteLine("Scan complete");

                        var targetFramework = Path.GetFileName(Path.GetDirectoryName(intrumentedDllFileLocation));

                        // run the validation
                        var report = instrumentationValidator.CheckInstrumentation(instrumentationModel, instrumentationSet.Name, targetFramework, downloadedNugetInfo.PackageVersion, downloadedNugetInfo.PackageName);
                        _instrumentationReports.Add(report);
                    }
                }
            }
        }
Exemplo n.º 10
0
 static void Main(string[] args)
 {
     AssemblyAnalyzer asmAnalyzer = new AssemblyAnalyzer();
     var codeApproved = asmAnalyzer.AnalyzeAssembly(Assembly.GetExecutingAssembly())
         ? "All the code was approved"
         : "Not all the code was approved";
     Console.WriteLine(codeApproved);
 }
Exemplo n.º 11
0
        public MainView()
        {
            InitializeComponent();

            context          = new AssemblyAnalyzer();
            this.DataContext = context;
            fileNames        = new List <string>();
        }
Exemplo n.º 12
0
        public void Reports_library_assembly_as_csharp()
        {
            var analyzer = new AssemblyAnalyzer(typeof(AssemblyAnalyzer).GetTypeInfo().Assembly);

            var result = analyzer.DetectedLanguage;

            result.Should().Be(Language.CSharp);
        }
Exemplo n.º 13
0
        public void When_analyzing(string fileName, string assemblyName, Language? expected)
        {
            var context = new SingleTestLoadContext(fileName);
            var assembly = context.LoadFromAssemblyName(new AssemblyName(assemblyName));

            var analyzer = new AssemblyAnalyzer(assembly);

            analyzer.DetectedLanguage.Should().Be(expected);
        }
Exemplo n.º 14
0
        public void When_analyzing(string fileName, string assemblyName, Language?expected)
        {
            var context  = new SingleTestLoadContext(fileName);
            var assembly = context.LoadFromAssemblyName(new AssemblyName(assemblyName));

            var analyzer = new AssemblyAnalyzer(assembly);

            analyzer.DetectedLanguage.Should().Be(expected);
        }
Exemplo n.º 15
0
        public void When_analyzing(string fileName, string assemblyName, Language?expected)
        {
#if NET451
            var assembly = Assembly.LoadFrom($"..\\..\\..\\SampleTestAssemblies{Path.DirectorySeparatorChar}{fileName}");
#else
            var assembly = CustomAssemblyLoader.Load(fileName, assemblyName);
#endif

            var analyzer = new AssemblyAnalyzer(assembly, failSilently: false);

            analyzer.DetectedLanguage.Should().Be(expected);
        }
Exemplo n.º 16
0
        public void When_analyzing(string fileName, string assemblyName, Language? expected)
        {
            #if NET451
            var assembly = Assembly.LoadFrom($"..\\..\\..\\SampleTestAssemblies{Path.DirectorySeparatorChar}{fileName}");
            #else
            var assembly = CustomAssemblyLoader.Load(fileName, assemblyName);
            #endif

            var analyzer = new AssemblyAnalyzer(assembly, failSilently: false);

            analyzer.DetectedLanguage.Should().Be(expected);
        }
Exemplo n.º 17
0
        public MainForm()
        {
            InitializeComponent ();

            image_directory = Path.Combine (Path.GetDirectoryName (Application.ExecutablePath), "Resources");
            LoadImages ();

            ResetForm ();
            SetupForm (WizardStep.Introduction);
            SetupMonoVersion ();

            aa = new AssemblyAnalyzer ();
        }
Exemplo n.º 18
0
        public MainForm()
        {
            InitializeComponent();

            image_directory = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Resources");
            LoadImages();

            ResetForm();
            SetupForm(WizardStep.Introduction);
            SetupMonoVersion();

            aa = new AssemblyAnalyzer();
        }
Exemplo n.º 19
0
        public AutoApplicationBundler(ApplicationSettings settings)
            : base(settings)
        {
            _razorEngine = new RazorEngine();
            _razorEngine.AddProjectDirectory(Settings.ProjectName, Settings.ProjectDirectory);

            _fileManager = new ApplicationFileManager()
            {
                TempStylesFilePath = Path.GetTempFileName()
            };

            _projAnalyzer = new ProjectAnalyzer();
            _asmAnalyzer  = new AssemblyAnalyzer();
        }
Exemplo n.º 20
0
 /// <summary>
 /// Initialyze the StubGenerator
 /// </summary>
 private void Init()
 {
     _outputOptions   = Configuration.OutputOptions;
     _inputAssemblies = GetAssemblies(Configuration.assembliesToAnalyzePath, true).ToArray <string>();
     _referencedAssembliesFolderPath = Configuration.ReferencedAssembliesFolderPath;
     _referencedAssembliesToLookInto = GetAssemblies(_referencedAssembliesFolderPath);
     GetModules();
     AnalysisUtils.SetModules(_modules);
     GetUnsupportedMethods();
     AddUndetectedMethodToUnsupportedMethods(Configuration.MethodsToAddManuallyBecauseTheyAreUndetected);
     _assemblyAnalyzer = new AssemblyAnalyzer(
         Configuration.SLMigrationCoreAssemblyFolderPath,
         _unsupportedMethodsInfo,
         _modules,
         _outputOptions);
 }
Exemplo n.º 21
0
        public AssemblyLoader InitializeWith(string path)
        {
            var appDomainSetup = new AppDomainSetup
            {
                ApplicationBase = Path.GetDirectoryName(path),
                ConfigurationFile = path + ".config",
            };
            var appDomain = AppDomain.CreateDomain("SubjectUnderTest", null, appDomainSetup);
            analyzer = ((AssemblyAnalyzer)
                appDomain.CreateInstanceAndUnwrap(
                    Assembly.GetExecutingAssembly().FullName,
                    typeof (AssemblyAnalyzer).FullName));
            analyzer.Load(path);

            return this;
        }
Exemplo n.º 22
0
        public static void Main(string[] args)
        {
            if (args.Length != 1 || string.IsNullOrWhiteSpace(args[0]))
            {
                Console.WriteLine("ERROR Missing arguement: Must supply path to configuration file.");
                return;
            }

            var filePath = args[0];

            if (!File.Exists(filePath))
            {
                Console.WriteLine("ERROR File not found: Provide path was incorrect or file missing.");
                return;
            }

            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(HyphenatedNamingConvention.Instance)
                               .Build();

            var configuration = deserializer.Deserialize <ScannerConfiguration>(File.ReadAllText(filePath));

            // now that we have a config, we need to handle checking more than one xml or dll

            // temp to allow other testing
            var fileNames = configuration.InstrumentationSets[0].LocalAssemblies.ToArray();

            // Builds a model from the files
            Console.WriteLine($"Starting scan of '{string.Join(',', fileNames)}'");
            var assemblyAnalyzer = new AssemblyAnalyzer();
            var assemblyAnalysis = assemblyAnalyzer.RunAssemblyAnalysis(fileNames);

            // just some debugging writes
            Console.WriteLine($"Found {assemblyAnalysis.ClassesCount} classes");
            Console.WriteLine("Scan complete");


            // build a searcher to check the inst file.
            var instrumentationValidator = new InstrumentationValidator(assemblyAnalysis);
            //var report = instrumentationValidator.CheckInstrumentation()

            //PrintReport();
        }
Exemplo n.º 23
0
        public static void ProcessAssemblies(ScannerConfiguration configuration)
        {
            foreach (var instrumentationSet in configuration.InstrumentationSets)
            {
                // TODO: deal with duplicate assembly names

                // load the instrumentation.xml and create InstrumentationModel
                var instrumentationModel = ReadInstrumentationFile(instrumentationSet);

                List <string> dllFileLocations = new List <string>();

                // nuget assemblies
                var nugetDllFileLocations = GetNugetAssemblies(instrumentationSet, instrumentationModel.UniqueAssemblies);
                if (nugetDllFileLocations != null)
                {
                    dllFileLocations.AddRange(nugetDllFileLocations);
                }

                // local assemblies
                var localDllFileLocations = GetLocalAssemblies(instrumentationSet);
                if (localDllFileLocations != null)
                {
                    dllFileLocations.AddRange(localDllFileLocations);
                }
                var dllFileNames = dllFileLocations.ToArray();

                // Builds a model from the files
                Console.WriteLine($"Starting scan of '{string.Join(',', dllFileNames)}'");
                var assemblyAnalyzer = new AssemblyAnalyzer();
                var assemblyAnalysis = assemblyAnalyzer.RunAssemblyAnalysis(dllFileNames);

                var instrumentationValidator = new InstrumentationValidator(assemblyAnalysis);

                // just some debugging writes
                Console.WriteLine($"Found {assemblyAnalysis.ClassesCount} classes");
                Console.WriteLine("Scan complete");

                // run the validation
                var report = instrumentationValidator.CheckInstrumentation(instrumentationModel, instrumentationSet.Name);
                _instrumentationReports.Add(report);
            }
        }
Exemplo n.º 24
0
        internal static void Start(object sender, EventArgs e)
        {
            //Debugger.Break();
            Stopwatch sw = Stopwatch.StartNew();

            ObjectManager = new ObjectManager();
            AssemblyAnalyzer.RegisterTarget(ObjectManager);

            ESExecute = new EndSceneExecute();
            AssemblyAnalyzer.RegisterTarget(ESExecute);

            DBC = new WoWDB();

            Movement = new Movement();
            AssemblyAnalyzer.RegisterTarget(Movement);

            LuaInterface.Initialize();

            Events = new Events();
            AssemblyAnalyzer.RegisterTarget(Events);

            Helper.Initialize();

            Spellbook = new SpellCollection();
            AssemblyAnalyzer.RegisterTarget(Spellbook);

            ScriptManager.Initialize();

            Camera = new Camera();

            //Initialize Chat Logger // qk
            Client.Chat.ChatThread.Start();

            AssemblyAnalyzer.Analyze(Assembly.GetExecutingAssembly());

            sw.Stop();
            Log.WriteLine("Initialization took {0} ms", sw.ElapsedMilliseconds);
        }
Exemplo n.º 25
0
        public void BasicConsoleResultTest()
        {
            var            x              = TestResources.GetTestProjectAssembly("BasicConsole");
            var            result         = new AssemblyAnalyzer(x);
            AssemblyResult assemblyResult = result.Analyse();

            Assert.Equal(2, assemblyResult.Types.Count);
            Assert.Equal("<Module>", assemblyResult.Types[0].ClassType);
            Assert.Equal("BasicConsole.Program", assemblyResult.Types[1].ClassType);

            //Focus on 2nd classtype
            var ct = assemblyResult.Types[1];

            Assert.Equal(2, ct.Methods.Count());

            //Focus on 2d method
            var mt = ct.Methods[1];

            Assert.Equal("Main", mt.Name);
            Assert.Equal("args", mt.Parameters);

            Assert.Equal(7, mt.Invocations.Count);
        }
Exemplo n.º 26
0
        /// <summary>Assembly worker do work.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param>
        /// <exception cref="NotImplementedException"></exception>
        private void AssemblyWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            assemblyWorker.ReportProgress(1);

            // Clear tree view
            assemblyExplorer.Tv_Assembly.InvokeIfRequired(() => assemblyExplorer.Tv_Assembly.Nodes.Clear());

            assemblyWorker.ReportProgress(10);

            // Reset the assembly editor property grid item values.
            assemblyExplorer.ResetAssemblyExplorerPropertyGrid();

            assemblyWorker.ReportProgress(20);

            // Get the assembly location from the parameter.
            string assemblyPath = e.Argument.ToString();

            assemblyWorker.ReportProgress(30);

            UpdateStatus(Resources.Analyzer_Build_ReflectionHierarchy);

            // Prepare to decompile the architecture
            assemblyAnalyzer = new AssemblyAnalyzer(assemblyPath);

            assemblyWorker.ReportProgress(40);

            assemblyAnalyzer.Analyze(assemblyPath);

            // Set assembly icon.
            if (assemblyAnalyzer.Icon != null)
            {
                Pb_Icon.Image = assemblyAnalyzer.Icon;
            }

            assemblyWorker.ReportProgress(50);

            assemblyExplorer.Analyze(Tb_Location.Text);

            assemblyWorker.ReportProgress(60);

            UpdateStatus(string.Format(Resources.Analyzer_Build_Preview, Path.GetFileNameWithoutExtension(Tb_Location.Text)));

            // Construct the assembly architecture to a tree view
            TreeNode treeNode = TypesUtil.GenerateTreeView(Tb_Location.Text);

            assemblyWorker.ReportProgress(70);

            // Expand from the root node.
            treeNode.ExpandAll();

            assemblyWorker.ReportProgress(80);

            UpdateStatus(string.Format(Resources.Analyzer_Generate_Documentation, Path.GetFileNameWithoutExtension(Tb_Location.Text)));

            // Add root node to tree view.
            assemblyExplorer.Tv_Assembly.InvokeIfRequired(() => assemblyExplorer.Tv_Assembly.Nodes.Add(treeNode));

            assemblyWorker.ReportProgress(90);

            // Refresh markdown preview contents.
            markdownPreview.Rtb_Preview.InvokeIfRequired(() => markdownPreview.Rtb_Preview.Text = assemblyAnalyzer.AssemblyReport.Contents);

            assemblyWorker.ReportProgress(100);
        }
Exemplo n.º 27
0
        private AssemblyPackageContainer GetAssemblyPackageFromLocal(IEnumerable <AssemblyPart> assemblyParts)
        {
            var           assemblyNames = new List <string>();
            List <string> files         = new List <string>();

            foreach (var dir in _assemblyFilesDirectories)
            {
                try
                {
                    foreach (var file in System.IO.Directory.GetFiles(dir).Select(f => System.IO.Path.GetFileName(f)).OrderBy(f => f))
                    {
                        var index = files.BinarySearch(file, StringComparer.OrdinalIgnoreCase);
                        if (index < 0)
                        {
                            files.Insert(~index, file);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new DetailsException(ResourceMessageFormatter.Create(() => Properties.Resources.AssemblyRepository_GetFilesFromRepositoryDirectoryError, dir), ex);
                }
            }
            var parts2 = assemblyParts.ToArray();
            IComparer <string> comparer = StringComparer.Create(System.Globalization.CultureInfo.InvariantCulture, true);

            foreach (var part in parts2)
            {
                var index = files.BinarySearch(part.Source, comparer);
                if (index >= 0)
                {
                    assemblyNames.Add(files[index]);
                }
            }
            var analyzer      = new AssemblyAnalyzer();
            var assemblyPaths = new List <string>();
            var names         = new List <string>();

            if (_assemblyInfoRepository != null)
            {
                AssemblyInfo info      = null;
                Exception    exception = null;
                var          infos     = new Queue <AssemblyInfo>();
                var          pending   = new Queue <string>(assemblyNames);
                while (pending.Count > 0)
                {
                    var assemblyName = pending.Dequeue();
                    if (names.FindIndex(f => StringComparer.InvariantCultureIgnoreCase.Equals(f, assemblyName)) < 0)
                    {
                        if (!_assemblyInfoRepository.TryGet(System.IO.Path.GetFileNameWithoutExtension(assemblyName), out info, out exception))
                        {
                            continue;
                        }
                        foreach (var i in info.References)
                        {
                            pending.Enqueue(i + ".dll");
                        }
                        names.Add(assemblyName);
                        foreach (var dir in _assemblyFilesDirectories)
                        {
                            if (System.IO.File.Exists(System.IO.Path.Combine(dir, assemblyName)))
                            {
                                assemblyPaths.Add(System.IO.Path.Combine(dir, assemblyName));
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (var assemblyName in assemblyNames)
                {
                    string assemblyPath = null;
                    foreach (var dir in _assemblyFilesDirectories)
                    {
                        assemblyPath = System.IO.Path.Combine(dir, assemblyName);
                        if (System.IO.File.Exists(assemblyPath))
                        {
                            break;
                        }
                    }
                    AsmData data = null;
                    try
                    {
                        data = analyzer.AnalyzeRootAssembly(assemblyPath);
                    }
                    catch (Exception ex)
                    {
                        throw new DetailsException(ResourceMessageFormatter.Create(() => Properties.Resources.AssemblyRepository_AnalyzeAssemblyError, assemblyName), ex);
                    }
                    var queue = new Queue <AsmData>();
                    queue.Enqueue(data);
                    while (queue.Count > 0)
                    {
                        data = queue.Dequeue();
                        if (string.IsNullOrEmpty(data.Path))
                        {
                            continue;
                        }
                        var fileName = System.IO.Path.GetFileName(data.Path);
                        var index    = names.FindIndex(f => StringComparer.InvariantCultureIgnoreCase.Equals(f, fileName));
                        if (index < 0)
                        {
                            names.Add(fileName);
                            assemblyPaths.Add(data.Path);
                        }
                        foreach (var i in data.References)
                        {
                            if (!string.IsNullOrEmpty(i.Path) && names.FindIndex(f => f == System.IO.Path.GetFileName(i.Path)) < 0)
                            {
                                queue.Enqueue(i);
                            }
                        }
                    }
                }
            }
            names.Reverse();
            var languages = new IO.Xap.LanguageInfo[] {
                new IO.Xap.LanguageInfo(new string[] {
                    ".dll"
                }, names.ToArray(), "")
            };
            var configuration = new IO.Xap.XapConfiguration(new IO.Xap.AppManifestTemplate(), languages, null);

            if (assemblyPaths.Count > 0 && UseDirectoryAssemblyPackages)
            {
                return(new AssemblyPackageContainer(new DirectoryAssemblyPackage(_assemblyResolverManager, assemblyPaths)));
            }
            else if (assemblyPaths.Count > 0)
            {
                assemblyPaths.Reverse();
                var entries = assemblyPaths.Select(f => {
                    var fileInfo = new System.IO.FileInfo(f);
                    return(new IO.Xap.XapBuilder.XapEntry(fileInfo.Name, new Lazy <System.IO.Stream>(() => fileInfo.OpenRead()), fileInfo.LastWriteTime));
                }).ToArray();
                var pkgUid = Guid.NewGuid();
                try
                {
                    var fileName = GetAssemblyPackageLocalFileName(pkgUid);
                    if (System.IO.File.Exists(fileName))
                    {
                        System.IO.File.Delete(fileName);
                    }
                    IO.Xap.XapBuilder.XapToDisk(configuration, entries, fileName);
                    var pkg = new AssemblyPackageResult(_assemblyResolverManager, pkgUid, fileName).CreatePackage();
                    lock (_objLock)
                        _packages.Add(new AssemblyPackageCacheEntry(pkg, null, fileName));
                    return(new AssemblyPackageContainer(pkg));
                }
                finally
                {
                    foreach (var i in entries)
                    {
                        i.Dispose();
                    }
                }
            }
            else
            {
                lock (_objLock)
                    _packages.Add(new AssemblyPackageCacheEntry(null, parts2, null));
                return(null);
            }
        }
Exemplo n.º 28
0
 public void SetUp()
 {
     _analyzer = new AssemblyAnalyzer();
 }