Tree node representing an assembly. This class is responsible for loading both namespace and type nodes.
Inheritance: ILSpyTreeNode
 public ReferenceFolderTreeNode(ModuleDefMD module, AssemblyTreeNode parentAssembly, AssemblyListTreeNode assemblyListTreeNode)
 {
     this.module = module;
     this.parentAssembly = parentAssembly;
     this.assemblyListTreeNode = assemblyListTreeNode;
     this.LazyLoading = true;
 }
Exemple #2
0
 public ReferenceFolderTreeNode(ModuleDef module, AssemblyTreeNode parentAssembly, DnSpyFileListTreeNode dnSpyFileListTreeNode)
 {
     this.module                = module;
     this.parentAssembly        = parentAssembly;
     this.dnSpyFileListTreeNode = dnSpyFileListTreeNode;
     this.LazyLoading           = true;
 }
 public ReferenceFolderTreeNode(ModuleDefMD module, AssemblyTreeNode parentAssembly, AssemblyListTreeNode assemblyListTreeNode)
 {
     this.module               = module;
     this.parentAssembly       = parentAssembly;
     this.assemblyListTreeNode = assemblyListTreeNode;
     this.LazyLoading          = true;
 }
 /// <summary>
 /// Looks up the type node corresponding to the type definition.
 /// Returns null if no matching node is found.
 /// </summary>
 public TypeTreeNode FindTypeNode(TypeDef def)
 {
     if (def == null)
     {
         return(null);
     }
     if (def.DeclaringType != null)
     {
         TypeTreeNode decl = FindTypeNode(def.DeclaringType);
         if (decl != null)
         {
             decl.EnsureChildrenFiltered();
             return(decl.Children.OfType <TypeTreeNode>().FirstOrDefault(t => t.TypeDef == def));
         }
     }
     else
     {
         AssemblyTreeNode asm = FindModuleNode(def.Module);
         if (asm != null)
         {
             return(asm.FindNonNestedTypeNode(def));
         }
     }
     return(null);
 }
 /// <summary>
 /// Looks up the type node corresponding to the type definition.
 /// Returns null if no matching node is found.
 /// </summary>
 public TypeTreeNode FindTypeNode(TypeDef def)
 {
     if (def == null)
     {
         return(null);
     }
     if (def.DeclaringType != null)
     {
         TypeTreeNode decl = FindTypeNode(def.DeclaringType);
         if (decl != null)
         {
             decl.EnsureLazyChildren();
             return(decl.Children.OfType <TypeTreeNode>().FirstOrDefault(t => t.TypeDefinition == def && !t.IsHidden));
         }
     }
     else
     {
         AssemblyTreeNode asm = FindAssemblyNode(def.Module.Assembly);
         if (asm != null)
         {
             return(asm.FindTypeNode(def));
         }
     }
     return(null);
 }
        /// <summary>
        /// Looks up the type node corresponding to the type definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public TypeTreeNode FindTypeNode(ITypeDefinition def)
        {
            if (def == null)
            {
                return(null);
            }
            var declaringType = def.DeclaringTypeDefinition;

            if (declaringType != null)
            {
                TypeTreeNode decl = FindTypeNode(declaringType);
                if (decl != null)
                {
                    decl.EnsureLazyChildren();
                    return(decl.Children.OfType <TypeTreeNode>().FirstOrDefault(t => t.TypeDefinition.MetadataToken == def.MetadataToken && !t.IsHidden));
                }
            }
            else
            {
                AssemblyTreeNode asm = FindAssemblyNode(def.ParentModule);
                if (asm != null)
                {
                    return(asm.FindTypeNode(def));
                }
            }
            return(null);
        }
Exemple #7
0
		public TypeTreeNode(TypeDef type, AssemblyTreeNode parentAssemblyNode) {
			if (parentAssemblyNode == null)
				throw new ArgumentNullException("parentAssemblyNode");
			if (type == null)
				throw new ArgumentNullException("type");
			this.type = type;
			this.parentAssemblyNode = parentAssemblyNode;
			this.LazyLoading = true;
		}
Exemple #8
0
        public ModuleTreeNode(ModuleDefinition moduleDefinition, AssemblyTreeNode parentAssemblyNode)
        {
            if (moduleDefinition == null)
                throw new ArgumentNullException("moduleDefiniton");
            module = moduleDefinition;
            assemblyNode = parentAssemblyNode;

            this.LazyLoading = true;
        }
Exemple #9
0
		public TreeViewUpdater(CorModuleDefFile cmdf, AssemblyTreeNode node, HashSet<uint> modifiedTypes, HashSet<uint> loadedClassTokens) {
			Debug.Assert(node.DnSpyFile == cmdf);
			this.CorModuleDefFile = cmdf;
			this.ModuleNode = node;
			this.modifiedTypes = new HashSet<uint>(modifiedTypes);
			this.loadedClassTokens = loadedClassTokens;
			this.checkedTypes = new HashSet<TypeDef>();
			this.modNode = node;
		}
Exemple #10
0
        AssemblySettingsCommand(AssemblyTreeNode asmNode, AssemblyOptions newOptions)
        {
            this.asmNode = asmNode;
            this.newOptions = newOptions;
            this.origOptions = new AssemblyOptions(asmNode.LoadedAssembly.AssemblyDefinition);

            if (newOptions.Name != origOptions.Name)
                this.assemblyRefInfos = RefFinder.FindAssemblyRefsToThisModule(asmNode.LoadedAssembly.ModuleDefinition).Where(a => AssemblyNameComparer.NameAndPublicKeyTokenOnly.Equals(a, asmNode.LoadedAssembly.AssemblyDefinition)).Select(a => new AssemblyRefInfo(a)).ToArray();
        }
		public AssemblyReferenceTreeNode(AssemblyNameReference r, AssemblyTreeNode parentAssembly)
		{
			if (parentAssembly == null)
				throw new ArgumentNullException("parentAssembly");
			if (r == null)
				throw new ArgumentNullException("r");
			this.r = r;
			this.parentAssembly = parentAssembly;
			this.LazyLoading = true;
		}
        public ModuleTreeNode(ModuleDefinition moduleDefinition, AssemblyTreeNode parentAssemblyNode)
        {
            if (moduleDefinition == null)
            {
                throw new ArgumentNullException("moduleDefiniton");
            }
            module       = moduleDefinition;
            assemblyNode = parentAssemblyNode;

            this.LazyLoading = true;
        }
Exemple #13
0
		public TypeTreeNode(TypeDefinition type, AssemblyTreeNode parentAssemblyNode)
		{
			if (parentAssemblyNode == null)
				throw new ArgumentNullException("parentAssemblyNode");
			if (type == null)
				throw new ArgumentNullException("type");
			this.type = type;
			this.parentAssemblyNode = parentAssemblyNode;
			this.LazyLoading = true;
            this.Foreground = IsPublicAPI ? NodeBrushes.Normal : NodeBrushes.Private;
		}
		internal AssemblyReferenceTreeNode(AssemblyRef r, AssemblyTreeNode parentAssembly, DnSpyFileListTreeNode dnSpyFileListTreeNode) {
			if (parentAssembly == null)
				throw new ArgumentNullException("parentAssembly");
			if (dnSpyFileListTreeNode == null)
				throw new ArgumentNullException("dnSpyFileListTreeNode");
			if (r == null)
				throw new ArgumentNullException("r");
			this.r = r;
			this.dnSpyFileListTreeNode = dnSpyFileListTreeNode;
			this.parentAssembly = parentAssembly;
			this.LazyLoading = true;
		}
		public NamespaceTreeNodeCreator(string ns, AssemblyTreeNode asmNode) {
			Debug.Assert(asmNode.IsModule);
			if (!asmNode.IsModule)
				throw new InvalidOperationException();

			this.asmNode = asmNode;
			this.nsNode = asmNode.FindNamespaceNode(ns);
			if (this.nsNode == null) {
				this.nsNode = new NamespaceTreeNode(ns);
				this.nsNodeCreated = true;
			}
		}
Exemple #16
0
 public TypeTreeNode(TypeDefinition type, AssemblyTreeNode parentAssemblyNode)
 {
     if (parentAssemblyNode == null)
     {
         throw new ArgumentNullException(nameof(parentAssemblyNode));
     }
     if (type == null)
     {
         throw new ArgumentNullException(nameof(type));
     }
     this.TypeDefinition     = type;
     this.ParentAssemblyNode = parentAssemblyNode;
     this.LazyLoading        = true;
 }
Exemple #17
0
 public TypeTreeNode(TypeDef type, AssemblyTreeNode parentAssemblyNode)
 {
     if (parentAssemblyNode == null)
     {
         throw new ArgumentNullException("parentAssemblyNode");
     }
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     this.type = type;
     this.parentAssemblyNode = parentAssemblyNode;
     this.LazyLoading        = true;
 }
Exemple #18
0
 public AssemblyReferenceTreeNode(AssemblyNameReference r, AssemblyTreeNode parentAssembly)
 {
     if (parentAssembly == null)
     {
         throw new ArgumentNullException("parentAssembly");
     }
     if (r == null)
     {
         throw new ArgumentNullException("r");
     }
     this.r = r;
     this.parentAssembly = parentAssembly;
     this.LazyLoading    = true;
 }
 public TypeTreeNode(TypeDefinition type, AssemblyTreeNode parentAssemblyNode)
 {
     if (parentAssemblyNode == null)
     {
         throw new ArgumentNullException("parentAssemblyNode");
     }
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     this.type = type;
     this.parentAssemblyNode = parentAssemblyNode;
     this.LazyLoading        = true;
     this.Foreground         = IsPublicAPI ? NodeBrushes.Normal : NodeBrushes.Private;
 }
Exemple #20
0
        static IEnumerable <AssemblyTreeNode> GetAllRelatedNodes(AssemblyTreeNode node)
        {
            if (node.Parent is AssemblyTreeNode)
            {
                node = (AssemblyTreeNode)node.Parent;
            }
            yield return(node);

            foreach (var child in node.Children)
            {
                var asmChild = child as AssemblyTreeNode;
                if (asmChild != null)
                {
                    yield return(asmChild);
                }
            }
        }
Exemple #21
0
        public void RegisterCached(LoadedAssembly asm, AssemblyTreeNode asmNode)
        {
            CachedAssemblyTreeNode cachedInfo;

            if (!cachedAsmTreeNodes.TryGetValue(asm, out cachedInfo))
            {
                cachedAsmTreeNodes.Add(asm, cachedInfo = new CachedAssemblyTreeNode(asmNode));
            }
            else
            {
                Debug.Assert(cachedInfo.AssemblyTreeNode == asmNode);
                if (cachedInfo.AssemblyTreeNode != asmNode)
                {
                    throw new InvalidOperationException();
                }
            }
            cachedInfo.Counter++;
        }
Exemple #22
0
        /// <summary>
        /// Looks up the event node corresponding to the namespace definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public NamespaceTreeNode FindNamespaceNode(INamespace def)
        {
            var module = def.ContributingModules.FirstOrDefault();

            if (module == null)
            {
                return(null);
            }

            AssemblyTreeNode assemblyNode = FindAssemblyNode(module);

            if (assemblyNode == null)
            {
                return(null);
            }

            assemblyNode.EnsureLazyChildren();
            return(assemblyNode.Children.OfType <NamespaceTreeNode>().FirstOrDefault(n => def.FullName.Length == 0 || def.FullName.Equals(n.Text)));
        }
 /// <summary>
 /// Looks up the type node corresponding to the type definition.
 /// Returns null if no matching node is found.
 /// </summary>
 public TypeTreeNode FindTypeNode(TypeDefinition def)
 {
     if (def == null)
     {
         return(null);
     }
     if (def.DeclaringType != null)
     {
         TypeTreeNode decl = FindTypeNode(def.DeclaringType);
         if (decl != null)
         {
             decl.EnsureLazyChildren();
             return(decl.Children.OfType <TypeTreeNode>().FirstOrDefault(t => t.TypeDefinition == def && !t.IsHidden));
         }
     }
     else
     {
         if (def.Module.Assembly == null) //def.Module.Assembly is null in secodary modules ...
         {
             foreach (AssemblyTreeNode node in this.Children)
             {
                 if (node.LoadedAssembly.IsLoaded)
                 {
                     var t = node.FindTypeNode(def);
                     if (t != null)
                     {
                         return(t);
                     }
                 }
             }
             return(null);
         }
         else
         {
             AssemblyTreeNode asm = FindAssemblyNode(def.Module.Assembly);
             if (asm != null)
             {
                 return(asm.FindTypeNode(def));
             }
         }
     }
     return(null);
 }
Exemple #24
0
 internal AssemblyReferenceTreeNode(AssemblyRef r, AssemblyTreeNode parentAssembly, AssemblyListTreeNode assemblyListTreeNode)
 {
     if (parentAssembly == null)
     {
         throw new ArgumentNullException("parentAssembly");
     }
     if (assemblyListTreeNode == null)
     {
         throw new ArgumentNullException("assemblyListTreeNode");
     }
     if (r == null)
     {
         throw new ArgumentNullException("r");
     }
     this.r = r;
     this.assemblyListTreeNode = assemblyListTreeNode;
     this.parentAssembly       = parentAssembly;
     this.LazyLoading          = true;
 }
Exemple #25
0
        /// <summary>
        /// Called when it's been converted to an assembly
        /// </summary>
        /// <param name="modNode">Old child as returned by <see cref="OnConvertedToNetModule()"/></param>
        internal void OnConvertedToAssembly(AssemblyTreeNode modNode = null)
        {
            Debug.Assert(Children.Count == 0 || !(Children[0] is AssemblyTreeNode));
            Debug.Assert(!(Parent is AssemblyTreeNode));

            SharpTreeNode[] oldChildren = null;
            if (!LazyLoading)
            {
                // Children already loaded
                oldChildren = Children.ToArray();
                Children.Clear();
            }
            Debug.Assert(Children.Count == 0);
            if (Children.Count != 0)
            {
                throw new InvalidOperationException();
            }

            var newChild = modNode ?? new AssemblyTreeNode(assembly);

            Debug.Assert(newChild.Parent == null);
            if (newChild.Parent != null)
            {
                throw new InvalidOperationException();
            }
            Children.Add(newChild);
            newChild.LazyLoading = LazyLoading;
            LazyLoading          = false;

            if (oldChildren != null)
            {
                newChild.Children.AddRange(oldChildren);
                newChild.typeDict.AddRange(typeDict);
                typeDict.Clear();
                newChild.namespaces.AddRange(namespaces);
                namespaces.Clear();
            }
            Debug.Assert(typeDict.Count == 0);
            Debug.Assert(namespaces.Count == 0);
            RaiseUIPropsChanged();
        }
Exemple #26
0
        public ModuleReferenceTreeNode(AssemblyTreeNode parentAssembly, ModuleReferenceHandle r, MetadataReader module)
        {
            this.parentAssembly = parentAssembly ?? throw new ArgumentNullException(nameof(parentAssembly));
            if (r.IsNil)
            {
                throw new ArgumentNullException(nameof(r));
            }
            this.metadata   = module;
            this.handle     = r;
            this.reference  = module.GetModuleReference(r);
            this.moduleName = metadata.GetString(reference.Name);

            foreach (var h in module.AssemblyFiles)
            {
                var file = module.GetAssemblyFile(h);
                if (module.StringComparer.Equals(file.Name, moduleName))
                {
                    this.file             = file;
                    this.fileHandle       = h;
                    this.containsMetadata = file.ContainsMetadata;
                    break;
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// Called when it's been converted to an assembly
        /// </summary>
        /// <param name="modNode">Old child as returned by <see cref="OnConvertedToNetModule()"/></param>
        internal void OnConvertedToAssembly(AssemblyTreeNode modNode = null)
        {
            Debug.Assert(Children.Count == 0 || !(Children[0] is AssemblyTreeNode));
            Debug.Assert(!(Parent is AssemblyTreeNode));

            SharpTreeNode[] oldChildren = null;
            if (!LazyLoading) {
                // Children already loaded
                oldChildren = Children.ToArray();
                Children.Clear();
            }
            Debug.Assert(Children.Count == 0);
            if (Children.Count != 0)
                throw new InvalidOperationException();

            var newChild = modNode ?? new AssemblyTreeNode(assembly);
            Debug.Assert(newChild.Parent == null);
            if (newChild.Parent != null)
                throw new InvalidOperationException();
            Children.Add(newChild);
            newChild.LazyLoading = LazyLoading;
            LazyLoading = false;

            if (oldChildren != null) {
                newChild.Children.AddRange(oldChildren);
                newChild.typeDict.AddRange(typeDict);
                typeDict.Clear();
                newChild.namespaces.AddRange(namespaces);
                namespaces.Clear();
            }
            Debug.Assert(typeDict.Count == 0);
            Debug.Assert(namespaces.Count == 0);
            RaiseUIPropsChanged();
        }
Exemple #28
0
 public bool IsModified(AssemblyTreeNode asmNode)
 {
     return IsModified(asmNode.LoadedAssembly);
 }
Exemple #29
0
 RemoveNetModuleFromAssemblyCommand(AssemblyTreeNode modNode)
 {
     this.asmNode = (AssemblyTreeNode)modNode.Parent;
     Debug.Assert(this.asmNode != null);
     this.modNode = modNode;
     this.removeIndex = asmNode.Children.IndexOf(modNode);
     Debug.Assert(this.removeIndex > 0);
     Debug.Assert(asmNode.LoadedAssembly.AssemblyDefinition != null &&
         asmNode.LoadedAssembly.AssemblyDefinition.Modules.IndexOf(modNode.LoadedAssembly.ModuleDefinition) == this.removeIndex);
 }
Exemple #30
0
 public TypeTreeNode(ITypeDefinition typeDefinition, AssemblyTreeNode parentAssemblyNode)
 {
     this.ParentAssemblyNode = parentAssemblyNode ?? throw new ArgumentNullException(nameof(parentAssemblyNode));
     this.TypeDefinition     = typeDefinition ?? throw new ArgumentNullException(nameof(typeDefinition));
     this.LazyLoading        = true;
 }
Exemple #31
0
			public ModuleState(CorModuleDefFile corModuleDefFile, AssemblyTreeNode moduleNode, HashSet<uint> modifiedTypes, HashSet<uint> loadClassHash) {
				this.CorModuleDefFile = corModuleDefFile;
				this.ModuleNode = moduleNode;
				this.ModifiedTypes = modifiedTypes;
				this.LoadClassHash = loadClassHash;
			}
		static ModuleDef GetModule(AssemblyTreeNode node) {
			return GoToMDTableRowHexEditorCommand.HasPENode(node) ? node.DnSpyFile.ModuleDef : null;
		}
Exemple #33
0
 static void OnFileNameChangedInternal(AssemblyTreeNode node)
 {
     node.RaisePropertyChanged("Text");
     node.RaisePropertyChanged("ToolTip");
 }
 public AssemblyReferenceTreeNode(AssemblyReference r, AssemblyTreeNode parentAssembly)
 {
     this.r = r ?? throw new ArgumentNullException(nameof(r));
     this.parentAssembly = parentAssembly ?? throw new ArgumentNullException(nameof(parentAssembly));
     this.LazyLoading    = true;
 }
Exemple #35
0
 public ReferenceFolderTreeNode(ModuleDefinition module, AssemblyTreeNode parentAssembly)
 {
     this.module         = module;
     this.parentAssembly = parentAssembly;
     this.LazyLoading    = true;
 }
 public ReferenceFolderTreeNode(ModuleDefinition module, AssemblyTreeNode parentAssembly)
 {
     this.module = module;
     this.parentAssembly = parentAssembly;
     this.LazyLoading = true;
 }
Exemple #37
0
 static void OnFileNameChangedInternal(AssemblyTreeNode node)
 {
     node.RaisePropertyChanged("Text");
     node.RaisePropertyChanged("ToolTip");
 }
Exemple #38
0
 static IEnumerable<AssemblyTreeNode> GetAllRelatedNodes(AssemblyTreeNode node)
 {
     if (node.Parent is AssemblyTreeNode)
         node = (AssemblyTreeNode)node.Parent;
     yield return node;
     foreach (var child in node.Children) {
         var asmChild = child as AssemblyTreeNode;
         if (asmChild != null)
             yield return asmChild;
     }
 }
 public void RegisterCached(LoadedAssembly asm, AssemblyTreeNode asmNode)
 {
     CachedAssemblyTreeNode cachedInfo;
     if (!cachedAsmTreeNodes.TryGetValue(asm, out cachedInfo))
         cachedAsmTreeNodes.Add(asm, cachedInfo = new CachedAssemblyTreeNode(asmNode));
     else {
         Debug.Assert(cachedInfo.AssemblyTreeNode == asmNode);
         if (cachedInfo.AssemblyTreeNode != asmNode)
             throw new InvalidOperationException();
     }
     cachedInfo.Counter++;
 }
 public UndoRedoInfo(AssemblyTreeNode node, bool isInUndo, bool isInRedo)
 {
     this.IsInUndo = isInUndo;
     this.IsInRedo = isInRedo;
     this.Node = node;
 }
		internal static bool HasPENode(AssemblyTreeNode node) {
			if (node == null)
				return false;
			// Currently only nodes loaded from files on disk have a PE node
			return node.DnSpyFile.PEImage != null && node.DnSpyFile.LoadedFromFile;
		}
 public CachedAssemblyTreeNode(AssemblyTreeNode asmNode)
 {
     this.AssemblyTreeNode = asmNode;
 }
 public AssemblyTreeNodeCreator(AssemblyTreeNode asmNode)
     : this(asmNode.LoadedAssembly, asmNode, true)
 {
 }
Exemple #44
0
 public CachedAssemblyTreeNode(AssemblyTreeNode asmNode)
 {
     this.AssemblyTreeNode = asmNode;
 }
 public void Dispose()
 {
     if (asmNode != null)
         MainWindow.Instance.AssemblyListTreeNode.UnregisterCached(asmNode.LoadedAssembly);
     asmNode = null;
 }
Exemple #46
0
 AddExistingNetModuleToAssemblyCommand(AssemblyTreeNode asmNode, LoadedAssembly asm)
     : base(asmNode, new AssemblyTreeNode(asm), false)
 {
 }
Exemple #47
0
		AssemblySettingsCommand(AssemblyTreeNode asmNode, AssemblyOptions newOptions)
		{
			this.asmNode = asmNode;
			this.newOptions = newOptions;
			this.origOptions = new AssemblyOptions(asmNode.LoadedAssembly.AssemblyDefinition);
		}
Exemple #48
0
 public static bool AskUserToSaveIfModified(AssemblyTreeNode asmNode)
 {
     return AskUserToSaveIfModified(new[] { asmNode.LoadedAssembly });
 }
Exemple #49
0
 ModuleSettingsCommand(AssemblyTreeNode modNode, ModuleOptions newOptions)
 {
     this.modNode = modNode;
     this.newOptions = newOptions;
     this.origOptions = new ModuleOptions(modNode.LoadedAssembly.ModuleDefinition);
 }
 AssemblyTreeNodeCreator(LoadedAssembly asm, AssemblyTreeNode asmNode, bool restoreIndex)
 {
     this.asmNode = asmNode ?? new AssemblyTreeNode(asm);
     this.restoreIndex = restoreIndex;
     MainWindow.Instance.AssemblyListTreeNode.RegisterCached(asm, this.asmNode);
 }
Exemple #51
0
		RemoveAssemblyCommand(AssemblyTreeNode[] asmNodes)
		{
			this.savedStates = new AssemblyTreeNodeCreator[asmNodes.Length];
			try {
				for (int i = 0; i < this.savedStates.Length; i++)
					this.savedStates[i] = new AssemblyTreeNodeCreator(asmNodes[i]);
			}
			catch {
				Dispose();
				throw;
			}
		}
Exemple #52
0
		static IEnumerable<AssemblyTreeNode> GetAssemblyNodes(AssemblyTreeNode node) {
			if (!node.IsAssembly || node.Children.Count == 0)
				yield return node;
			else {
				foreach (AssemblyTreeNode child in node.Children)
					yield return child;
			}
		}
Exemple #53
0
 public ReferenceFolderTreeNode(PEFile module, AssemblyTreeNode parentAssembly)
 {
     this.module         = module;
     this.parentAssembly = parentAssembly;
     this.LazyLoading    = true;
 }