Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public IDnSpyFilenameKey CreateKey(IFileManager fileManager, DnSpyFileInfo fileInfo)
 {
     var filename = GetFilename(fileInfo);
     if (filename != null)
         return new FilenameKey(filename);
     return null;
 }
Exemplo n.º 3
0
		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;
		}
Exemplo n.º 4
0
 /// <inheritdoc/>
 protected override void OnPropertyChanged(string propName)
 {
     base.OnPropertyChanged(propName);
     if (propName == nameof(Filename))
     {
         fileInfo = DnSpyFileInfo.CreateFile(Filename);
     }
 }
Exemplo n.º 5
0
		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;
		}
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
        /// <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));
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
0
 internal static IDnSpyFile CreateDnSpyFileFromFile(DnSpyFileInfo fileInfo, string filename, bool useMemoryMappedIO, bool loadPDBFiles, IAssemblyResolver asmResolver)
 {
     return DnSpyFile.CreateDnSpyFileFromFile(fileInfo, filename, useMemoryMappedIO, loadPDBFiles, asmResolver, false);
 }
Exemplo n.º 10
0
 /// <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);
Exemplo n.º 11
0
 /// <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);
Exemplo n.º 12
0
 public IDnSpyFile TryGetOrCreate(DnSpyFileInfo info, bool isAutoLoaded)
 {
     return TryGetOrCreateInternal(info, isAutoLoaded, false);
 }
Exemplo n.º 13
0
 public void Add(DnSpyFileInfo file)
 {
     files.Add(file);
 }
Exemplo n.º 14
0
 public FileToLoad(DnSpyFileInfo info, bool isAutoLoaded = false)
 {
     this.Info = info;
     this.IsAutoLoaded = isAutoLoaded;
 }
Exemplo n.º 15
0
        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;
        }
Exemplo n.º 16
0
 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;
 }
Exemplo n.º 17
0
        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;
        }
Exemplo n.º 18
0
 /// <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;
 }
Exemplo n.º 19
0
        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;
        }
Exemplo n.º 20
0
 public IDnSpyFile TryCreateOnly(DnSpyFileInfo info)
 {
     return TryCreateDnSpyFile(info);
 }
Exemplo n.º 21
0
 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);
 }