DocumentTreeNodeData[] GetChildren(DocumentTreeNodeData node) { var n = node; return((DocumentTreeNodeData[])execInThread(() => { n.TreeNode.EnsureChildrenLoaded(); return n.TreeNode.DataChildren.OfType <DocumentTreeNodeData>().ToArray(); })); }
CreateTypeDefCommand(IList<TypeDef> ownerList, DocumentTreeNodeData ownerNode, TypeDefOptions options) { this.ownerList = ownerList; var modNode = ownerNode.GetModuleNode(); Debug.Assert(modNode != null); if (modNode == null) throw new InvalidOperationException(); nsNodeCreator = new NamespaceNodeCreator(options.Namespace, modNode); typeNode = modNode.Context.DocumentTreeView.Create(options.CreateTypeDef(modNode.Document.ModuleDef)); }
public DerivedTypesFinder(DocumentTreeNodeData targetNode, TypeDef type) : base(targetNode) { msgNodeGroup = targetNode.Context.DocumentTreeView.DocumentTreeNodeGroups.GetGroup(DocumentTreeNodeGroupType.MessageTreeNodeGroupDerivedTypes); derivedTypesGroup = targetNode.Context.DocumentTreeView.DocumentTreeNodeGroups.GetGroup(DocumentTreeNodeGroupType.DerivedTypeTreeNodeGroupDerivedTypes); weakModules = targetNode.Context.DocumentTreeView.DocumentService.GetDocuments().Where(a => !(a.ModuleDef is null)).SelectMany(a => !(a.AssemblyDef is null) ? (IEnumerable <ModuleDef>)a.AssemblyDef.Modules : new[] { a.ModuleDef }).Select(a => new WeakReference(a)).ToArray(); this.type = type; Start(); }
DocumentTabReferenceResult Create(DocumentTreeNodeData node) { var content = documentTabContentFactoryService.CreateTabContent(new[] { node }); if (content == null) { return(null); } return(new DocumentTabReferenceResult(content)); }
public override DocumentTreeNodeFilterResult GetResultOther(DocumentTreeNodeData node) { bool isMatch = (flags & VisibleMembersFlags.Other) != 0; if (!isMatch) { return(new DocumentTreeNodeFilterResult(FilterType.Hide, isMatch)); } return(new DocumentTreeNodeFilterResult(FilterType.Visible, isMatch)); }
void DecompileNode(IDecompileNodeContext context, DocumentTreeNodeData node) { foreach (var d in decompileNodes) { if (d.Decompile(context, node)) { return; } } Debug.Fail("Missing decompiler"); }
void DecompileUnknown(DocumentTreeNodeData node) { if (node is IDecompileSelf decompileSelf && !(decompileNodeContext is null)) { if (decompileSelf.Decompile(decompileNodeContext)) { return; } } decompiler.WriteCommentLine(output, NameUtilities.CleanName(node.ToString(decompiler))); }
static ModuleDocumentNode GetModuleNode(DocumentTreeNodeData node) { if (node is AssemblyDocumentNode asmNode) { asmNode.TreeNode.EnsureChildrenLoaded(); return(asmNode.TreeNode.DataChildren.FirstOrDefault() as ModuleDocumentNode); } else { return(node.GetModuleNode()); } }
/// <summary> /// Gets the resource element or null /// </summary> /// <param name="node">Node</param> /// <returns></returns> public static ResourceElement?GetResourceElement(DocumentTreeNodeData node) { if (node is ResourceElementNode resourceElementNode) { return(resourceElementNode.ResourceElement); } if (node.TryGetData(out Data? data)) { return(data.ResourceElement); } return(null); }
void DecompileUnknown(DocumentTreeNodeData node) { var decompileSelf = node as IDecompileSelf; if (decompileSelf != null && decompileNodeContext != null) { if (decompileSelf.Decompile(decompileNodeContext)) { return; } } decompiler.WriteCommentLine(output, NameUtilities.CleanName(node.ToString(decompiler))); }
internal static ModuleDefMD?GetModuleOffset(DocumentTreeNodeData node, ResourceElement resourceElement, out FileOffset fileOffset) { fileOffset = 0; var module = node.GetModule() as ModuleDefMD; //TODO: Support CorModuleDef if (module is null) { return(null); } fileOffset = resourceElement.ResourceData.StartOffset; return(module); }
public static SerializedPath Create(DocumentTreeNodeData node) { var path = new SerializedPath(); while (node != null && node.TreeNode.Parent != null) { path.Names.Add(node.NodePathName); var parent = node.TreeNode.Parent; node = parent.Data as DocumentTreeNodeData; } path.Names.Reverse(); return(path); }
public bool Decompile(IDecompileNodeContext context, DocumentTreeNodeData node) { var msgNode = node as SomeMessageNode; if (msgNode == null) { return(false); } context.Decompiler.WriteCommentLine(context.Output, "The secret message has been decrypted."); context.Decompiler.WriteCommentLine(context.Output, string.Format("The message is: {0}", msgNode.Message)); context.ContentTypeString = ContentTypes.PlainText; return(true); }
public bool RaiseNodeActivated(DocumentTreeNodeData node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (NodeActivated == null) { return(false); } var e = new DocumentTreeNodeActivatedEventArgs(node); NodeActivated(this, e); return(e.Handled); }
PropertyDefSettingsCommand(PropertyNode propNode, PropertyDefOptions options) { this.propNode = propNode; this.newOptions = options; this.origOptions = new PropertyDefOptions(propNode.PropertyDef); this.origParentNode = (DocumentTreeNodeData)propNode.TreeNode.Parent.Data; this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(propNode.TreeNode); Debug.Assert(this.origParentChildIndex >= 0); if (this.origParentChildIndex < 0) { throw new InvalidOperationException(); } this.nameChanged = origOptions.Name != newOptions.Name; }
EventDefSettingsCommand(EventNode eventNode, EventDefOptions options) { this.eventNode = eventNode; newOptions = options; origOptions = new EventDefOptions(eventNode.EventDef); origParentNode = (DocumentTreeNodeData)eventNode.TreeNode.Parent.Data; origParentChildIndex = origParentNode.TreeNode.Children.IndexOf(eventNode.TreeNode); Debug.Assert(origParentChildIndex >= 0); if (origParentChildIndex < 0) { throw new InvalidOperationException(); } nameChanged = origOptions.Name != newOptions.Name; }
/// <summary> /// Gets a <see cref="IResourceDataProvider"/> if <paramref name="node"/> is a resource node, else returns null /// </summary> /// <param name="node">Node</param> /// <returns></returns> public static IResourceDataProvider?GetResourceDataProvider(DocumentTreeNodeData node) { if (node is IResourceDataProvider provider) { return(provider); } if (ResourceNode.GetResource(node) is Resource resource) { return(new ResourceNode_ResourceDataProvider(node, resource)); } if (ResourceElementNode.GetResourceElement(node) is ResourceElement resourceElement) { return(new ResourceElementNode_ResourceDataProvider(node, resourceElement)); } return(null); }
static NodeType GetNodeType(DocumentTreeNodeData node) { NodeType nodeType; var type = node.GetType(); lock (lockObj) { if (toNodeType.TryGetValue(type, out nodeType)) { return(nodeType); } nodeType = GetNodeTypeSlow(node); toNodeType.Add(type, nodeType); } return(nodeType); }
/// <summary> /// Adds the resource element to a resource element node /// </summary> /// <param name="node">Node</param> /// <param name="resourceElement">Resource element</param> public static void AddResourceElement(DocumentTreeNodeData node, ResourceElement resourceElement) { if (node is ResourceElementNode resourceElementNode) { if (resourceElementNode.ResourceElement != resourceElement) { throw new InvalidOperationException(); } } else { if (node.TryGetData <Data>(out _)) { throw new InvalidOperationException(); } node.AddData(new Data(resourceElement)); } }
MethodDefSettingsCommand(MethodNode methodNode, MethodDefOptions options) { this.methodNode = methodNode; newOptions = options; origOptions = new MethodDefOptions(methodNode.MethodDef); origParentNode = (DocumentTreeNodeData)methodNode.TreeNode.Parent.Data; origParentChildIndex = origParentNode.TreeNode.Children.IndexOf(methodNode.TreeNode); Debug.Assert(origParentChildIndex >= 0); if (origParentChildIndex < 0) { throw new InvalidOperationException(); } nameChanged = origOptions.Name != newOptions.Name; if (nameChanged) { memberRefInfos = RefFinder.FindMemberRefsToThisModule(methodNode.GetModule()).Where(a => RefFinder.MethodEqualityComparerInstance.Equals(a, methodNode.MethodDef)).Select(a => new Field.MemberRefInfo(a)).ToArray(); } }
FieldDefSettingsCommand(FieldNode fieldNode, FieldDefOptions options) { this.fieldNode = fieldNode; this.newOptions = options; this.origOptions = new FieldDefOptions(fieldNode.FieldDef); this.origParentNode = (DocumentTreeNodeData)fieldNode.TreeNode.Parent.Data; this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(fieldNode.TreeNode); Debug.Assert(this.origParentChildIndex >= 0); if (this.origParentChildIndex < 0) { throw new InvalidOperationException(); } this.nameChanged = origOptions.Name != newOptions.Name; if (this.nameChanged) { this.memberRefInfos = RefFinder.FindMemberRefsToThisModule(fieldNode.GetModule()).Where(a => RefFinder.FieldEqualityComparerInstance.Equals(a, fieldNode.FieldDef)).Select(a => new MemberRefInfo(a)).ToArray(); } }
internal static ModuleDefMD?GetModuleOffset(DocumentTreeNodeData node, Resource resource, out FileOffset fileOffset) { fileOffset = 0; var er = resource as EmbeddedResource; if (er is null) { return(null); } var module = node.GetModule() as ModuleDefMD; //TODO: Support CorModuleDef if (module is null) { return(null); } fileOffset = (FileOffset)er.CreateReader().StartOffset; return(module); }
TypeDefSettingsCommand(ModuleDef module, TypeNode typeNode, TypeDefOptions options) { this.module = module; this.typeNode = typeNode; newOptions = options; origOptions = new TypeDefOptions(typeNode.TypeDef); origParentNode = (DocumentTreeNodeData)typeNode.TreeNode.Parent.Data; origParentChildIndex = origParentNode.TreeNode.Children.IndexOf(typeNode.TreeNode); Debug.Assert(origParentChildIndex >= 0); if (origParentChildIndex < 0) throw new InvalidOperationException(); nameChanged = origOptions.Name != newOptions.Name; if (origParentNode is NamespaceNode) { var modNode = (ModuleDocumentNode)origParentNode.TreeNode.Parent.Data; if (newOptions.Namespace != origOptions.Namespace) nsNodeCreator = new NamespaceNodeCreator(newOptions.Namespace, modNode); } if (nameChanged || origOptions.Namespace != newOptions.Namespace) typeRefInfos = RefFinder.FindTypeRefsToThisModule(module).Where(a => RefFinder.TypeEqualityComparerInstance.Equals(a, typeNode.TypeDef)).Select(a => new TypeRefInfo(a)).ToArray(); }
public bool Decompile(IDecompileNodeContext context, DocumentTreeNodeData node) { new NodeDecompiler(a => context.UIThread(() => a()), context.Output, context.Decompiler, context.DecompilationContext, context).Decompile(node); return(true); }
public virtual DocumentTreeNodeFilterResult GetResultOther(DocumentTreeNodeData node) => new DocumentTreeNodeFilterResult();
public virtual DocumentTreeNodeFilterResult GetResultOther(DocumentTreeNodeData node) => filter.GetResultOther(node);
public NodeAndResourceElement(DocumentTreeNodeData node) { Debug2.Assert(ResourceElementNode.GetResourceElement(node) is not null); this.node = node; }
public void Decompile(DocumentTreeNodeData node) { var nodeType = GetNodeType(node); switch (nodeType) { case NodeType.Unknown: DecompileUnknown(node); break; case NodeType.Assembly: decompiler.Decompile(((AssemblyDocumentNode)node).Document.AssemblyDef !, output, decompilationContext); break; case NodeType.Module: decompiler.Decompile(((ModuleDocumentNode)node).Document.ModuleDef !, output, decompilationContext); break; case NodeType.Type: decompiler.Decompile(((TypeNode)node).TypeDef, output, decompilationContext); break; case NodeType.Method: decompiler.Decompile(((MethodNode)node).MethodDef, output, decompilationContext); break; case NodeType.Field: decompiler.Decompile(((FieldNode)node).FieldDef, output, decompilationContext); break; case NodeType.Property: decompiler.Decompile(((PropertyNode)node).PropertyDef, output, decompilationContext); break; case NodeType.Event: decompiler.Decompile(((EventNode)node).EventDef, output, decompilationContext); break; case NodeType.AssemblyRef: Decompile((AssemblyReferenceNode)node); break; case NodeType.BaseTypeFolder: Decompile((BaseTypeFolderNode)node); break; case NodeType.BaseType: Decompile((BaseTypeNode)node); break; case NodeType.DerivedType: Decompile((DerivedTypeNode)node); break; case NodeType.DerivedTypesFolder: Decompile((DerivedTypesFolderNode)node); break; case NodeType.ModuleRef: Decompile((ModuleReferenceNode)node); break; case NodeType.Namespace: Decompile((NamespaceNode)node); break; case NodeType.PEFile: Decompile((PEDocumentNode)node); break; case NodeType.ReferencesFolder: Decompile((ReferencesFolderNode)node); break; case NodeType.ResourcesFolder: Decompile((ResourcesFolderNode)node); break; case NodeType.Resource: Decompile((ResourceNode)node); break; case NodeType.ResourceElement: Decompile((ResourceElementNode)node); break; case NodeType.ResourceElementSet: Decompile((ResourceElementSetNode)node); break; case NodeType.UnknownFile: Decompile((UnknownDocumentNode)node); break; case NodeType.Message: Decompile((MessageNode)node); break; default: Debug.Fail($"Unknown NodeType: {nodeType}"); goto case NodeType.Unknown; } }
static NodeType GetNodeTypeSlow(DocumentTreeNodeData node) { if (node is AssemblyDocumentNode) { return(NodeType.Assembly); } if (node is ModuleDocumentNode) { return(NodeType.Module); } if (node is TypeNode) { return(NodeType.Type); } if (node is MethodNode) { return(NodeType.Method); } if (node is FieldNode) { return(NodeType.Field); } if (node is PropertyNode) { return(NodeType.Property); } if (node is EventNode) { return(NodeType.Event); } if (node is AssemblyReferenceNode) { return(NodeType.AssemblyRef); } if (node is BaseTypeFolderNode) { return(NodeType.BaseTypeFolder); } if (node is BaseTypeNode) { return(NodeType.BaseType); } if (node is DerivedTypeNode) { return(NodeType.DerivedType); } if (node is DerivedTypesFolderNode) { return(NodeType.DerivedTypesFolder); } if (node is ModuleReferenceNode) { return(NodeType.ModuleRef); } if (node is NamespaceNode) { return(NodeType.Namespace); } if (node is PEDocumentNode) { return(NodeType.PEFile); } if (node is ReferencesFolderNode) { return(NodeType.ReferencesFolder); } if (node is ResourcesFolderNode) { return(NodeType.ResourcesFolder); } if (node is ResourceNode) { return(NodeType.Resource); } if (node is ResourceElementNode) { return(NodeType.ResourceElement); } if (node is ResourceElementSetNode) { return(NodeType.ResourceElementSet); } if (node is UnknownDocumentNode) { return(NodeType.UnknownFile); } if (node is MessageNode) { return(NodeType.Message); } return(NodeType.Unknown); }
public NodeAndResource(DocumentTreeNodeData node) { Debug2.Assert(!(ResourceNode.GetResource(node) is null)); this.node = node; }