TypeDefSettingsCommand(ModuleDef module, ITypeNode typeNode, TypeDefOptions options) { this.module = module; this.typeNode = typeNode; this.newOptions = options; this.origOptions = new TypeDefOptions(typeNode.TypeDef); this.origParentNode = (IDocumentTreeNodeData)typeNode.TreeNode.Parent.Data; this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(typeNode.TreeNode); Debug.Assert(this.origParentChildIndex >= 0); if (this.origParentChildIndex < 0) { throw new InvalidOperationException(); } this.nameChanged = origOptions.Name != newOptions.Name; if (this.origParentNode is INamespaceNode) { var modNode = (IModuleDocumentNode)this.origParentNode.TreeNode.Parent.Data; if (newOptions.Namespace != origOptions.Namespace) { this.nsNodeCreator = new NamespaceNodeCreator(newOptions.Namespace, modNode); } } if (this.nameChanged || origOptions.Namespace != newOptions.Namespace) { this.typeRefInfos = RefFinder.FindTypeRefsToThisModule(module).Where(a => RefFinder.TypeEqualityComparerInstance.Equals(a, typeNode.TypeDef)).Select(a => new TypeRefInfo(a)).ToArray(); } }
RenameNamespaceCommand(string newName, INamespaceNode nsNode) { this.newName = newName; this.origName = nsNode.Name; this.nsNode = nsNode; this.existingNsNode = (INamespaceNode)nsNode.TreeNode.Parent.DataChildren.FirstOrDefault(a => a is INamespaceNode && newName == ((INamespaceNode)a).Name); var module = nsNode.GetModule(); Debug.Assert(module != null); if (module == null) { throw new InvalidOperationException(); } this.origParentNode = (IDocumentTreeNodeData)nsNode.TreeNode.Parent.Data; this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(nsNode.TreeNode); Debug.Assert(this.origParentChildIndex >= 0); if (this.origParentChildIndex < 0) { throw new InvalidOperationException(); } // Make sure the exact same namespace names are restored if we undo. The names are UTF8 // strings, but not necessarily canonicalized if it's an obfuscated assembly. nsNode.TreeNode.EnsureChildrenLoaded(); this.origChildren = nsNode.TreeNode.DataChildren.Cast <ITypeNode>().ToArray(); this.typeNamespaces = new UTF8String[nsNode.TreeNode.Children.Count]; for (int i = 0; i < this.typeNamespaces.Length; i++) { this.typeNamespaces[i] = origChildren[i].TypeDef.Namespace; } this.typeRefInfos = GetTypeRefInfos(module, new[] { nsNode }); }
/// <summary> /// Constructor /// </summary> /// <param name="node">Node</param> public DocumentTreeNodeActivatedEventArgs(IDocumentTreeNodeData node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } this.Node = node; }
IDocumentTreeNodeData[] GetChildren(IDocumentTreeNodeData node) { var n = node; return((IDocumentTreeNodeData[])execInThread(() => { n.TreeNode.EnsureChildrenLoaded(); return n.TreeNode.DataChildren.OfType <IDocumentTreeNodeData>().ToArray(); })); }
public override DocumentTreeNodeFilterResult GetResult(IDocumentTreeNodeData node) { bool isMatch = (flags & VisibleMembersFlags.Other) != 0; if (!isMatch) { return(new DocumentTreeNodeFilterResult(FilterType.Hide, isMatch)); } return(new DocumentTreeNodeFilterResult(FilterType.Visible, isMatch)); }
DocumentTabReferenceResult Create(IDocumentTreeNodeData node) { var content = documentTabContentFactoryService.CreateTabContent(new IDocumentTreeNodeData[] { node }); if (content == null) { return(null); } return(new DocumentTabReferenceResult(content)); }
void DecompileNode(IDecompileNodeContext context, IDocumentTreeNodeData node) { foreach (var d in decompileNodes) { if (d.Decompile(context, node)) { return; } } Debug.Fail("Missing decompiler"); }
CreateTypeDefCommand(IList <TypeDef> ownerList, IDocumentTreeNodeData ownerNode, TypeDefOptions options) { this.ownerList = ownerList; var modNode = ownerNode.GetModuleNode(); Debug.Assert(modNode != null); if (modNode == null) { throw new InvalidOperationException(); } this.nsNodeCreator = new NamespaceNodeCreator(options.Namespace, modNode); this.typeNode = modNode.Context.DocumentTreeView.Create(options.CreateTypeDef(modNode.Document.ModuleDef)); }
PropertyDefSettingsCommand(IPropertyNode propNode, PropertyDefOptions options) { this.propNode = propNode; this.newOptions = options; this.origOptions = new PropertyDefOptions(propNode.PropertyDef); this.origParentNode = (IDocumentTreeNodeData)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; }
void DecompileUnknown(IDocumentTreeNodeData node) { var decompileSelf = node as IDecompileSelf; if (decompileSelf != null && decompileNodeContext != null) { if (decompileSelf.Decompile(decompileNodeContext)) { return; } } decompiler.WriteCommentLine(output, NameUtilities.CleanName(node.ToString(decompiler))); }
public static SerializedPath Create(IDocumentTreeNodeData 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 IDocumentTreeNodeData; } path.Names.Reverse(); return(path); }
public bool Decompile(IDecompileNodeContext context, IDocumentTreeNodeData 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(IDocumentTreeNodeData 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); }
static NodeType GetNodeType(IDocumentTreeNodeData 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); }
EventDefSettingsCommand(IEventNode eventNode, EventDefOptions options) { this.eventNode = eventNode; this.newOptions = options; this.origOptions = new EventDefOptions(eventNode.EventDef); this.origParentNode = (IDocumentTreeNodeData)eventNode.TreeNode.Parent.Data; this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(eventNode.TreeNode); Debug.Assert(this.origParentChildIndex >= 0); if (this.origParentChildIndex < 0) { throw new InvalidOperationException(); } this.nameChanged = origOptions.Name != newOptions.Name; }
MethodDefSettingsCommand(IMethodNode methodNode, MethodDefOptions options) { this.methodNode = methodNode; this.newOptions = options; this.origOptions = new MethodDefOptions(methodNode.MethodDef); this.origParentNode = (IDocumentTreeNodeData)methodNode.TreeNode.Parent.Data; this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(methodNode.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(methodNode.GetModule()).Where(a => RefFinder.MethodEqualityComparerInstance.Equals(a, methodNode.MethodDef)).Select(a => new Field.MemberRefInfo(a)).ToArray(); } }
static void Filter(IDocumentTreeNodeData node) { if (node == null) { return; } var res = node.GetFilterType(node.Context.Filter); switch (res) { case FilterType.Default: case FilterType.Visible: node.FilterVersion = node.Context.FilterVersion; node.TreeNode.IsHidden = false; var fnode = node as DocumentTreeNodeData; if (fnode != null && fnode.refilter && node.TreeNode.Children.Count > 0) { node.OnEnsureChildrenLoaded(); } break; case FilterType.Hide: node.TreeNode.IsHidden = true; break; case FilterType.CheckChildren: node.FilterVersion = node.Context.FilterVersion; node.TreeNode.EnsureChildrenLoaded(); node.TreeNode.IsHidden = node.TreeNode.Children.All(a => a.IsHidden); break; default: Debug.Fail($"Invalid type: {res}"); goto case FilterType.Default; } }
public virtual DocumentTreeNodeFilterResult GetResult(IDocumentTreeNodeData node) => new DocumentTreeNodeFilterResult(FilterType.Hide, false);
public virtual DocumentTreeNodeFilterResult GetResult(IDocumentTreeNodeData node) => new DocumentTreeNodeFilterResult();
static NodeType GetNodeTypeSlow(IDocumentTreeNodeData node) { if (node is IAssemblyDocumentNode) { return(NodeType.Assembly); } if (node is IModuleDocumentNode) { return(NodeType.Module); } if (node is ITypeNode) { return(NodeType.Type); } if (node is IMethodNode) { return(NodeType.Method); } if (node is IFieldNode) { return(NodeType.Field); } if (node is IPropertyNode) { return(NodeType.Property); } if (node is IEventNode) { return(NodeType.Event); } if (node is IAssemblyReferenceNode) { return(NodeType.AssemblyRef); } if (node is IBaseTypeFolderNode) { return(NodeType.BaseTypeFolder); } if (node is IBaseTypeNode) { return(NodeType.BaseType); } if (node is IDerivedTypeNode) { return(NodeType.DerivedType); } if (node is IDerivedTypesFolderNode) { return(NodeType.DerivedTypesFolder); } if (node is IModuleReferenceNode) { return(NodeType.ModuleRef); } if (node is INamespaceNode) { return(NodeType.Namespace); } if (node is IPEDocumentNode) { return(NodeType.PEFile); } if (node is IReferencesFolderNode) { return(NodeType.ReferencesFolder); } if (node is IResourcesFolderNode) { return(NodeType.ResourcesFolder); } if (node is IResourceNode) { return(NodeType.Resource); } if (node is IResourceElementNode) { return(NodeType.ResourceElement); } if (node is IResourceElementSetNode) { return(NodeType.ResourceElementSet); } if (node is IUnknownDocumentNode) { return(NodeType.UnknownFile); } if (node is IMessageNode) { return(NodeType.Message); } return(NodeType.Unknown); }
public void Decompile(IDocumentTreeNodeData node) { var nodeType = GetNodeType(node); switch (nodeType) { case NodeType.Unknown: DecompileUnknown(node); break; case NodeType.Assembly: decompiler.Decompile(((IAssemblyDocumentNode)node).Document.AssemblyDef, output, decompilationContext); break; case NodeType.Module: decompiler.Decompile(((IModuleDocumentNode)node).Document.ModuleDef, output, decompilationContext); break; case NodeType.Type: decompiler.Decompile(((ITypeNode)node).TypeDef, output, decompilationContext); break; case NodeType.Method: decompiler.Decompile(((IMethodNode)node).MethodDef, output, decompilationContext); break; case NodeType.Field: decompiler.Decompile(((IFieldNode)node).FieldDef, output, decompilationContext); break; case NodeType.Property: decompiler.Decompile(((IPropertyNode)node).PropertyDef, output, decompilationContext); break; case NodeType.Event: decompiler.Decompile(((IEventNode)node).EventDef, output, decompilationContext); break; case NodeType.AssemblyRef: Decompile((IAssemblyReferenceNode)node); break; case NodeType.BaseTypeFolder: Decompile((IBaseTypeFolderNode)node); break; case NodeType.BaseType: Decompile((IBaseTypeNode)node); break; case NodeType.DerivedType: Decompile((IDerivedTypeNode)node); break; case NodeType.DerivedTypesFolder: Decompile((IDerivedTypesFolderNode)node); break; case NodeType.ModuleRef: Decompile((IModuleReferenceNode)node); break; case NodeType.Namespace: Decompile((INamespaceNode)node); break; case NodeType.PEFile: Decompile((IPEDocumentNode)node); break; case NodeType.ReferencesFolder: Decompile((IReferencesFolderNode)node); break; case NodeType.ResourcesFolder: Decompile((IResourcesFolderNode)node); break; case NodeType.Resource: Decompile((IResourceNode)node); break; case NodeType.ResourceElement: Decompile((IResourceElementNode)node); break; case NodeType.ResourceElementSet: Decompile((IResourceElementSetNode)node); break; case NodeType.UnknownFile: Decompile((IUnknownDocumentNode)node); break; case NodeType.Message: Decompile((IMessageNode)node); break; default: Debug.Fail(string.Format("Unknown NodeType: {0}", nodeType)); goto case NodeType.Unknown; } }
public virtual DocumentTreeNodeFilterResult GetResult(IDocumentTreeNodeData node) => this.filter.GetResult(node);
public bool Decompile(IDecompileNodeContext context, IDocumentTreeNodeData node) { new NodeDecompiler(a => context.UIThread(() => a()), context.Output, context.Decompiler, context.DecompilationContext, context).Decompile(node); return(true); }