static void DumpNetModule(ProjectInfo info, List <ProjectInfo> projectFiles) { var fileName = info.AssemblyFileName; if (string.IsNullOrEmpty(fileName)) { throw new Exception(".NET module filename is empty or null"); } var listOpts = new DnSpyFileListOptionsImpl(); listOpts.UseGAC = !noGac; listOpts.UseDebugSymbols = true; listOpts.UseMemoryMappedIO = true; var fileList = new DnSpyFileList(listOpts, string.Empty); fileList.AssemblyResolver.AddSearchPath(Path.GetDirectoryName(fileName)); foreach (var path in asmPaths) { fileList.AssemblyResolver.AddSearchPath(path); } var file = fileList.OpenFile(fileName); var opts = new DecompilationOptions { FullDecompilation = true, CancellationToken = new CancellationToken(), }; TextWriter writer = null; try { var lang = GetLanguage(); if (useStdout) { writer = System.Console.Out; } else { var baseDir = GetProjectDir(lang, fileName); Directory.CreateDirectory(baseDir); writer = new StreamWriter(info.ProjectFileName, false, Encoding.UTF8); opts.SaveAsProjectDirectory = baseDir; opts.DontReferenceStdLib = noCorlibRef; opts.ProjectFiles = projectFiles; opts.ProjectGuid = info.ProjectGuid; opts.DontShowCreateMethodBodyExceptions = dontMaskErr; Console.WriteLine("Saving {0} to {1}", fileName, baseDir); } lang.DecompileAssembly(fileList, file, new PlainTextOutput(writer), opts); } finally { if (!useStdout && writer != null) { writer.Dispose(); } } }
private void AddToList(DnSpyFileList list, string FullName) { AssemblyNameInfo reference = new AssemblyNameInfo(FullName); string file = GacInterop.FindAssemblyInNetGac(reference); if (file != null) { list.OpenFile(file); } }
DnSpyFileList Create(XElement listElement) { var name = SessionSettings.Unescape((string)listElement.Attribute("name")); var list = new DnSpyFileList(options, name); var elems = listElement.Elements(FILE_SECTION_NAME).ToList(); elems.AddRange(listElement.Elements(FILE_SECTION_NAME_OLD)); foreach (var asm in elems) { try { list.OpenFile(SessionSettings.Unescape((string)asm)); } catch { } } list.IsDirty = false; return(list); }
public override void Drop(DragEventArgs e, int index) { Debug.Assert(!DisableDrop); if (DisableDrop) { return; } string[] filenames = null; int[] fileIndexes = e.Data.GetData(AssemblyTreeNode.DataFormat) as int[]; if (fileIndexes == null) { filenames = e.Data.GetData(DataFormats.FileDrop) as string[]; } if ((filenames != null && filenames.Length > 0) || (fileIndexes != null && fileIndexes.Length > 0)) { DnSpyFile newSelectedFile = null; bool newSelectedAsmExisted = false; var oldIgnoreSelChg = MainWindow.Instance.TreeView_SelectionChanged_ignore; try { lock (dnspyFileList.GetLockObj()) { int numFiles = dnspyFileList.Count_NoLock; var old = dnspyFileList.IsReArranging; try { MainWindow.Instance.TreeView_SelectionChanged_ignore = true; List <DnSpyFile> files; if (fileIndexes != null) { files = fileIndexes.Where(i => 0 <= i && i < Children.Count).Select(i => ((AssemblyTreeNode)Children[i]).DnSpyFile).Distinct().ToList(); } else { files = (from filename in filenames where filename != null select dnspyFileList.OpenFile(filename) into node where node != null select node).Distinct().ToList(); } var oldFiles = new Dictionary <DnSpyFile, bool>(files.Count); foreach (var file in files) { int nodeIndex = dnspyFileList.IndexOf_NoLock(file); oldFiles[file] = nodeIndex < numFiles; if (newSelectedFile == null) { newSelectedFile = file; newSelectedAsmExisted = oldFiles[file]; } if (nodeIndex < index) { index--; } numFiles--; dnspyFileList.IsReArranging = oldFiles[file]; dnspyFileList.RemoveAt_NoLock(nodeIndex); dnspyFileList.IsReArranging = old; } files.Reverse(); foreach (var asm in files) { dnspyFileList.IsReArranging = oldFiles[asm]; dnspyFileList.Insert_NoLock(index, asm); dnspyFileList.IsReArranging = old; } } finally { dnspyFileList.IsReArranging = old; } } if (newSelectedFile != null) { if (!newSelectedAsmExisted) { MainWindow.Instance.TreeView_SelectionChanged_ignore = oldIgnoreSelChg; } var node = MainWindow.Instance.FindTreeNode(newSelectedFile.AssemblyDef) ?? MainWindow.Instance.FindTreeNode(newSelectedFile.ModuleDef); if (node != null) { MainWindow.Instance.treeView.FocusNode(node); MainWindow.Instance.treeView.SelectedItem = node; } } } finally { MainWindow.Instance.TreeView_SelectionChanged_ignore = oldIgnoreSelChg; } } }