public IDnSpyFile Create(IFileManager fileManager, DnSpyFileInfo fileInfo) { var filename = GetFilename(fileInfo); if (filename != null) return FileManager.CreateDnSpyFileFromFile(fileInfo, filename, fileManager.Settings.UseMemoryMappedIO, fileManager.Settings.LoadPDBFiles, fileManager.AssemblyResolver); return null; }
public IDnSpyFilenameKey CreateKey(IFileManager fileManager, DnSpyFileInfo fileInfo) { var filename = GetFilename(fileInfo); if (filename != null) return new FilenameKey(filename); return null; }
public IDnSpyFilenameKey CreateKey(IFileManager fileManager, DnSpyFileInfo fileInfo) { if (fileInfo.Type == MyDnSpyFile.THE_GUID) return new FilenameKey(fileInfo.Name); // Must match the key in MyDnSpyFile.Key // Also check for normal files if (fileInfo.Type == FileConstants.FILETYPE_FILE && IsSupportedFile(fileInfo.Name)) return new FilenameKey(fileInfo.Name); // Must match the key in MyDnSpyFile.Key return null; }
/// <inheritdoc/> protected override void OnPropertyChanged(string propName) { base.OnPropertyChanged(propName); if (propName == nameof(Filename)) { fileInfo = DnSpyFileInfo.CreateFile(Filename); } }
public IDnSpyFile Create(IFileManager fileManager, DnSpyFileInfo fileInfo) { if (fileInfo.Type == MyDnSpyFile.THE_GUID) return MyDnSpyFile.TryCreate(fileInfo.Name); // Also check for normal files if (fileInfo.Type == FileConstants.FILETYPE_FILE && IsSupportedFile(fileInfo.Name)) return MyDnSpyFile.TryCreate(fileInfo.Name); return null; }
static string GetFilename(DnSpyFileInfo fileInfo) { if (fileInfo.Type == FileConstants.FILETYPE_FILE) return fileInfo.Name; if (fileInfo.Type == FileConstants.FILETYPE_GAC) return GetGacFilename(fileInfo.Name); if (fileInfo.Type == FileConstants.FILETYPE_REFASM) return GetRefFileFilename(fileInfo.Name); return null; }
/// <summary> /// Creates a <see cref="IDnSpyFile"/> /// </summary> /// <param name="fileInfo">File info</param> /// <param name="filename">Filename</param> /// <param name="useMemoryMappedIO">true to use memory mapped I/O</param> /// <param name="loadPDBFile">true to load the PDB file if available</param> /// <param name="asmResolver">Assembly resolver</param> /// <param name="isModule">true if it's a module, false if it's an assembly</param> /// <returns></returns> public static IDnSpyFile CreateDnSpyFileFromFile(DnSpyFileInfo fileInfo, string filename, bool useMemoryMappedIO, bool loadPDBFile, IAssemblyResolver asmResolver, bool isModule) { try { // Quick check to prevent exceptions from being thrown if (!File.Exists(filename)) { return(new DnSpyUnknownFile(filename)); } IPEImage peImage; if (useMemoryMappedIO) { peImage = new PEImage(filename); } else { peImage = new PEImage(File.ReadAllBytes(filename), filename); } var dotNetDir = peImage.ImageNTHeaders.OptionalHeader.DataDirectories[14]; bool isDotNet = dotNetDir.VirtualAddress != 0 && dotNetDir.Size >= 0x48; if (isDotNet) { try { var options = new ModuleCreationOptions(DnSpyDotNetFileBase.CreateModuleContext(asmResolver)); if (isModule) { return(DnSpyDotNetFile.CreateModule(fileInfo, ModuleDefMD.Load(peImage, options), loadPDBFile)); } return(DnSpyDotNetFile.CreateAssembly(fileInfo, ModuleDefMD.Load(peImage, options), loadPDBFile)); } catch { } } return(new DnSpyPEFile(peImage)); } catch { } return(new DnSpyUnknownFile(filename)); }
/// <inheritdoc/> protected override List <IDnSpyFile> CreateChildren() { var asm = AssemblyDef; var list = new List <IDnSpyFile>(asm == null ? 1 : asm.Modules.Count); if (isAsmNode && asm != null) { bool foundThis = false; foreach (var module in asm.Modules) { if (this.ModuleDef == module) { Debug.Assert(!foundThis); foundThis = true; } list.Add(new DnSpyDotNetFile(DnSpyFileInfo.CreateFile(module.Location), module, loadedSymbols, false)); } Debug.Assert(foundThis); } return(list); }
internal static IDnSpyFile CreateDnSpyFileFromFile(DnSpyFileInfo fileInfo, string filename, bool useMemoryMappedIO, bool loadPDBFiles, IAssemblyResolver asmResolver) { return DnSpyFile.CreateDnSpyFileFromFile(fileInfo, filename, useMemoryMappedIO, loadPDBFiles, asmResolver, false); }
/// <summary> /// Creates an assembly /// </summary> /// <param name="fileInfo">File info</param> /// <param name="module">Module</param> /// <param name="loadSyms">true to load symbols</param> /// <returns></returns> public static DnSpyDotNetFile CreateAssembly(DnSpyFileInfo fileInfo, ModuleDef module, bool loadSyms) => new DnSpyDotNetFile(fileInfo, module, loadSyms, true);
/// <summary> /// Creates a module /// </summary> /// <param name="fileInfo">File info</param> /// <param name="module">Module</param> /// <param name="loadSyms">true to load symbols</param> /// <returns></returns> public static DnSpyDotNetFile CreateModule(DnSpyFileInfo fileInfo, ModuleDef module, bool loadSyms) => new DnSpyDotNetFile(fileInfo, module, loadSyms, false);
public IDnSpyFile TryGetOrCreate(DnSpyFileInfo info, bool isAutoLoaded) { return TryGetOrCreateInternal(info, isAutoLoaded, false); }
public void Add(DnSpyFileInfo file) { files.Add(file); }
public FileToLoad(DnSpyFileInfo info, bool isAutoLoaded = false) { this.Info = info; this.IsAutoLoaded = isAutoLoaded; }
IDnSpyFilenameKey TryCreateKey(DnSpyFileInfo info) { foreach (var creator in dnSpyFileCreators) { try { var key = creator.CreateKey(this, info); if (key != null) return key; } catch (Exception ex) { Debug.WriteLine(string.Format("IDnSpyFileCreator ({0}) failed with an exception: {1}", creator.GetType(), ex.Message)); } } return null; }
string GetDescription(DnSpyFileInfo info) { if (info.Type == FileConstants.FILETYPE_REFASM) { int index = info.Name.LastIndexOf(FileConstants.REFERENCE_ASSEMBLY_SEPARATOR); if (index >= 0) return info.Name.Substring(0, index); } return info.Name; }
internal IDnSpyFile TryCreateDnSpyFile(DnSpyFileInfo info) { foreach (var creator in dnSpyFileCreators) { try { var file = creator.Create(this, info); if (file != null) return file; } catch (Exception ex) { Debug.WriteLine(string.Format("IDnSpyFileCreator ({0}) failed with an exception: {1}", creator.GetType(), ex.Message)); } } return null; }
/// <summary> /// Constructor /// </summary> /// <param name="fileInfo">File info</param> /// <param name="module">Module</param> /// <param name="loadSyms">true to load symbols</param> /// <param name="isAsmNode">true if it's an assembly node, false if it's a module node</param> protected DnSpyDotNetFile(DnSpyFileInfo fileInfo, ModuleDef module, bool loadSyms, bool isAsmNode) : base(module, loadSyms) { this.fileInfo = fileInfo; this.isAsmNode = isAsmNode; }
public IDnSpyFile TryGetOrCreate(DnSpyFileInfo info, bool isAutoLoaded) { var key = TryCreateKey(info); if (key == null) return null; var existing = Find(key); if (existing != null) return existing; var newFile = TryCreateDnSpyFile(info); if (newFile == null) return null; newFile.IsAutoLoaded = isAutoLoaded; if (!AssemblyLoadEnabled) return AddTempCachedFile(newFile); var result = GetOrAdd(newFile); if (result != newFile) Dispose(newFile); return result; }
public IDnSpyFile TryCreateOnly(DnSpyFileInfo info) { return TryCreateDnSpyFile(info); }
public static void Save(ISettingsSection section, DnSpyFileInfo info) { section.Attribute(FILEINFO_NAME_ATTR, info.Name); if (info.Type != FileConstants.FILETYPE_FILE) section.Attribute(FILEINFO_TYPE_ATTR, info.Type); }