static void Execute(ILSpyTreeNode[] nodes) { if (!CanExecute(nodes)) { return; } var nsNode = ILSpyTreeNode.GetNode <NamespaceTreeNode>(nodes[0]); string ns = nsNode == null ? string.Empty : nsNode.Name; var module = ILSpyTreeNode.GetModule(nodes[0]); Debug.Assert(module != null); if (module == null) { throw new InvalidOperationException(); } var options = TypeDefOptions.Create(ns, TypeConstants.DEFAULT_TYPE_NAME, module.CorLibTypes.Object.TypeDefOrRef, false); var data = new TypeOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, null); var win = new TypeOptionsDlg(); win.Title = CMD_NAME; win.DataContext = data; win.Owner = MainWindow.Instance; if (win.ShowDialog() != true) { return; } var cmd = new CreateTypeDefCommand(module.Types, nodes[0], data.CreateTypeDefOptions()); UndoCommandManager.Instance.Add(cmd); MainWindow.Instance.JumpToReference(cmd.typeNode); }
static IUndoObject GetUndoObject(object obj) { var node = obj as ILSpyTreeNode; if (node != null) { var asmNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node); Debug.Assert(asmNode != null); if (asmNode != null) { return(asmNode.LoadedAssembly); } return(null); } var doc = obj as AsmEdHexDocument; if (doc != null) { return(doc); } Debug.Fail(string.Format("Unknown modified object: {0}: {1}", obj == null ? null : obj.GetType(), obj)); return(null); }
LoadedAssembly GetAssembly(ContextMenuEntryContext context) { if (DebuggerService.CurrentDebugger == null || DebuggerService.CurrentDebugger.IsDebugging) { return(null); } SharpTreeNode node; if (context.Element is DecompilerTextView) { var tabState = MainWindow.Instance.GetActiveDecompileTabState(); if (tabState == null) { return(null); } if (tabState.DecompiledNodes.Length == 0) { return(null); } node = tabState.DecompiledNodes[0]; } else if (context.SelectedTreeNodes != null) { if (context.SelectedTreeNodes.Length == 0) { return(null); } node = context.SelectedTreeNodes[0]; } else { return(null); } var asmNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node); if (asmNode == null) { return(null); } var loadedAsm = asmNode.LoadedAssembly; var mod = loadedAsm.ModuleDefinition; if (mod == null) { return(null); } if (mod.Assembly == null || mod.Assembly.ManifestModule != mod) { return(null); } if (mod.ManagedEntryPoint == null && mod.NativeEntryPoint == 0) { return(null); } return(loadedAsm); }
static ModuleDef GetModule(ContextMenuEntryContext context, out DecompileTabState tabState) { tabState = null; if (context == null) { return(null); } var textView = context.Element as DecompilerTextView; if (textView != null) { tabState = DecompileTabState.GetDecompileTabState(textView); if (tabState != null && tabState.DecompiledNodes != null && tabState.DecompiledNodes.Length > 0) { return(GetModule(ILSpyTreeNode.GetNode <AssemblyTreeNode>(tabState.DecompiledNodes[0]))); } } if (context.SelectedTreeNodes != null && context.SelectedTreeNodes.Length == 1) { return(GetModule(ILSpyTreeNode.GetNode <AssemblyTreeNode>(context.SelectedTreeNodes[0]))); } return(null); }
HashSet <IUndoObject> GetAssemblyNodes(ILSpyTreeNode[] nodes) { var hash = new HashSet <IUndoObject>(); if (nodes.Length == 0) { var hex = MainWindow.Instance.ActiveTabState as HexTabState; if (hex != null) { var doc = hex.HexBox.Document as AsmEdHexDocument; if (doc != null) { hash.Add(UndoCommandManager.Instance.GetUndoObject(doc)); } } } foreach (var node in nodes) { var asmNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node); if (asmNode == null) { continue; } bool added = false; if (asmNode.DnSpyFile.ModuleDef != null) { var uo = UndoCommandManager.Instance.GetUndoObject(asmNode.DnSpyFile); if (UndoCommandManager.Instance.IsModified(uo)) { hash.Add(uo); added = true; } } var doc = HexDocumentManager.Instance.TryGet(asmNode.DnSpyFile.Filename); if (doc != null) { var uo = UndoCommandManager.Instance.GetUndoObject(doc); if (UndoCommandManager.Instance.IsModified(uo)) { hash.Add(uo); added = true; } } // If nothing was modified, just include the selected module if (!added && asmNode.DnSpyFile.ModuleDef != null) { hash.Add(UndoCommandManager.Instance.GetUndoObject(asmNode.DnSpyFile)); } } return(hash); }
CreateNestedTypeDefCommand(TypeTreeNode ownerType, TypeDefOptions options) { this.ownerType = ownerType; var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerType); Debug.Assert(modNode != null); if (modNode == null) throw new InvalidOperationException(); this.nestedType = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode); }
CreateTypeDefCommand(IList<TypeDef> ownerList, ILSpyTreeNode ownerNode, TypeDefOptions options) { this.ownerList = ownerList; var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerNode); Debug.Assert(modNode != null); if (modNode == null) throw new InvalidOperationException(); this.nsNodeCreator = new NamespaceTreeNodeCreator(options.Namespace, modNode); this.typeNode = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode); }
static AssemblyTreeNode GetActiveAssemblyTreeNode() { var tabState = MainWindow.Instance.GetActiveDecompileTabState(); if (tabState == null || tabState.DecompiledNodes.Length == 0) { return(null); } return(ILSpyTreeNode.GetNode <AssemblyTreeNode>(tabState.DecompiledNodes[0])); }
static IEnumerable <LoadedAssembly> GetLoadedAssemblies(IUndoCommand command) { foreach (var node in command.TreeNodes) { var asmNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node); Debug.Assert(asmNode != null); if (asmNode != null) { yield return(asmNode.LoadedAssembly); } } }
internal static bool IsInModifiedModule(HashSet <DnSpyFile> mods, ILSpyTreeNode[] nodes) { foreach (var node in nodes) { var modNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node); if (modNode == null || mods.Contains(modNode.DnSpyFile)) { return(true); } } return(false); }
HashSet <LoadedAssembly> GetAssemblyNodes(ILSpyTreeNode[] nodes) { var hash = new HashSet <LoadedAssembly>(); foreach (var node in nodes) { var asmNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node); if (asmNode != null && asmNode.LoadedAssembly.ModuleDefinition != null) { hash.Add(asmNode.LoadedAssembly); } } return(hash); }
static MemoryModuleDefFile GetFile(ContextMenuEntryContext context) { var modNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(GetTreeNode(context)); var mfile = modNode == null ? null : modNode.DnSpyFile as MemoryModuleDefFile; if (mfile == null) { return(null); } if (mfile.Process.HasExited || mfile.Process.Debugger.ProcessState == DebuggerProcessState.Terminated) { return(null); } return(mfile); }
static LoadedAssembly GetLoadedAssembly(SharpTreeNode node) { var asmNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node); if (asmNode == null) { return(null); } var module = asmNode.LoadedAssembly.ModuleDefinition as ModuleDefMD; if (module == null) { return(null); } return(asmNode.LoadedAssembly); }
static LoadedAssembly GetLoadedAssembly(SharpTreeNode node) { var asmNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node); if (asmNode == null) { return(null); } var module = asmNode.LoadedAssembly.ModuleDefinition as ModuleDefMD; if (module == null) { return(null); } if (!module.MetaData.PEImage.IsMemoryMappedIO) { return(null); } return(asmNode.LoadedAssembly); }
internal static string GetFilename(ILSpyTreeNode node) { var asmNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node); if (asmNode == null) { return(null); } var mod = asmNode.DnSpyFile.ModuleDef; if (mod != null && File.Exists(mod.Location)) { return(mod.Location); } var peImage = asmNode.DnSpyFile.PEImage; if (peImage != null && File.Exists(peImage.FileName)) { return(peImage.FileName); } return(null); }