Exemple #1
0
 private void OnCalcClick(object sender, EventArgs e)
 {
     OnModuleChanged?.Invoke(this);
 }
Exemple #2
0
 private void OnConvertClicked(object sender, EventArgs e)
 {
     OnModuleChanged?.Invoke(this);
 }
Exemple #3
0
        /// <summary>Creates an ILNode-Tree representing the structure of the given Assembly
        /// and stores it in the ModuleList Dictionary with the AssemblyDefinition name as key.</summary>
        /// <param name="assDef">The AssemblyDefinition which should be loaded into the searchlist</param>
        /// <param name="subResolveDepth">When the given AssemblyDefinition uses references to other Assemblys
        /// the method will add them recursivly to the given depth</param>
        public void LoadAssembly(AssemblyDefinition assDef, int subResolveDepth = 0)
        {
            if (assDef == null)
            {
                throw new ArgumentNullException(nameof(assDef));
            }
            if (subResolveDepth < 0)
            {
                throw new ArgumentException(nameof(subResolveDepth) + " must be non-negative.");
            }
            if (IsModuleLoaded(assDef.Name.Name))
            {
                return;
            }

            ILNode ilParent = new ILNode(assDef.Name.Name, assDef.FullName, assDef, StructureView.Structure);             // StructureView.Module

            AddModule(assDef.Name.Name, ilParent);

            foreach (ModuleDefinition ModDef in assDef.Modules)
            {
                ILNode tnModDef             = ilParent.Add(ModDef.Name, ModDef.Name, ModDef, StructureView.Structure);
                DefaultAssemblyResolver dar = (DefaultAssemblyResolver)ModDef.AssemblyResolver;
                Array.ForEach(dar.GetSearchDirectories(), dar.RemoveSearchDirectory);
                dar.AddSearchDirectory(Path.GetDirectoryName(dataStruct.AssemblyLocation));

                // Subresolving references
                foreach (AssemblyNameReference anr in ModDef.AssemblyReferences)
                {
                    try
                    {
                        AssemblyDefinition AssSubRef = ModDef.AssemblyResolver.Resolve(anr);
                        tnModDef.Add(anr.Name, AssSubRef.FullName, AssSubRef, StructureView.Structure);
                        if (subResolveDepth > 0)
                        {
                            LoadAssembly(AssSubRef, subResolveDepth - 1);
                        }
                    }
                    catch { Log.Write(Log.Level.Warning, $"AssemblyReference \"{anr.Name}\" couldn't be found for \"{ ModDef.Name}\""); }
                }

                Dictionary <string, ILNode> nsDict = new Dictionary <string, ILNode>();
                foreach (TypeDefinition TypDef in ModDef.Types)
                {
                    string nsstr = TypDef.Namespace;
                    ILNode tnAssemblyContainer;
                    if (!nsDict.ContainsKey(nsstr))
                    {
                        string displaystr = string.IsNullOrEmpty(nsstr) ? "<Default Namespace>" : nsstr;
                        tnAssemblyContainer = ilParent.Add(displaystr, displaystr, new NamespaceHolder(displaystr), StructureView.Namesp);
                        nsDict.Add(nsstr, tnAssemblyContainer);
                    }
                    else
                    {
                        tnAssemblyContainer = nsDict[nsstr];
                    }

                    ILNode tnTypDef = tnAssemblyContainer.Add(TypDef.Name, TypDef.FullName, TypDef, StructureView.Classes);
                    LoadSubItemsRecursive(tnTypDef, TypDef);
                }
            }
            ilParent.Sort();

            if (subResolveDepth == 0)             // If this is the last LoadAssembly recursion call then invoke the callback
            {
                OnModuleChanged?.Invoke(this);
            }
        }