Пример #1
0
        public override ModuleDef?TryGetMetadata(ModuleId moduleId, DbgLoadModuleOptions options)
        {
            var mod = LoadNonDiskFile(moduleId, options) ?? LoadExisting(moduleId);

            if (!(mod is null))
            {
                return(mod);
            }

            if (moduleId.IsDynamic || moduleId.IsInMemory)
            {
                return(null);
            }

            string moduleFilename = moduleId.ModuleName;

            if (!File.Exists(moduleFilename))
            {
                return(null);
            }
            var asmFilename = GetAssemblyFilename(moduleFilename, moduleId.AssemblyFullName, moduleId.ModuleNameOnly);

            bool isAutoLoaded = (options & DbgLoadModuleOptions.AutoLoaded) != 0;

            if (!string.IsNullOrEmpty(asmFilename))
            {
                var document = documentService.TryGetOrCreate(DsDocumentInfo.CreateDocument(asmFilename), isAutoLoaded);
                if (document is null)
                {
                    document = documentService.Resolve(new AssemblyNameInfo(moduleId.AssemblyFullName), null);
                }
                if (!(document is null))
                {
                    // Common case is a single-file assembly or first module of a multifile assembly
                    if (asmFilename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
                    {
                        return(document.ModuleDef);
                    }

                    foreach (var child in document.Children)
                    {
                        if (child.Filename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
                        {
                            return(child.ModuleDef);
                        }
                    }
                }
            }

            return(documentService.TryGetOrCreate(DsDocumentInfo.CreateDocument(moduleFilename), isAutoLoaded)?.ModuleDef);
        }
Пример #2
0
        IDsDocument[] Open(bool many)
        {
            var dialog = new OpenFileDialog()
            {
                Filter           = PickFilenameConstants.DotNetAssemblyOrModuleFilter,
                RestoreDirectory = true,
                Multiselect      = many,
            };

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return(Array.Empty <IDsDocument>());
            }

            var list = new List <IDsDocument>(dialog.FileNames.Length);

            foreach (var filename in dialog.FileNames)
            {
                var info = DsDocumentInfo.CreateDocument(filename);
                var file = documentService.TryGetOrCreate(info);
                if (file != null)
                {
                    list.Add(file);
                }
            }
            return(list.ToArray());
        }
Пример #3
0
		void Load(DocumentToLoad f) {
			if (f.Info.Type == DocumentConstants.DOCUMENTTYPE_FILE && string.IsNullOrEmpty(f.Info.Name))
				return;
			var document = documentService.TryGetOrCreate(f.Info, f.IsAutoLoaded);
			if (document != null && !hash.Contains(document)) {
				loadedDocuments.Add(document);
				hash.Add(document);
			}
		}
Пример #4
0
        void Load(DocumentToLoad f)
        {
            if (f.Info.Type == DocumentConstants.DOCUMENTTYPE_FILE && string.IsNullOrEmpty(f.Info.Name))
            {
                return;
            }
            var document = documentService.TryGetOrCreate(f.Info, f.IsAutoLoaded);

            if (!(document is null) && !hash.Contains(document))
            {
                loadedDocuments.Add(document);
                hash.Add(document);
                if (!f.IsAutoLoaded)
                {
                    document.IsAutoLoaded = f.IsAutoLoaded;
                    mruList?.Add(document.Filename);
                }
            }
        }
Пример #5
0
        public IDsDocument[] Load(IEnumerable <DocumentToLoad> documents)
        {
            var loadedDocuments = new List <IDsDocument>();
            var hash            = new HashSet <IDsDocument>();

            foreach (var doc in documents)
            {
                if (doc.Info.Type == DocumentConstants.DOCUMENTTYPE_FILE && string.IsNullOrEmpty(doc.Info.Name))
                {
                    continue;
                }
                var document = documentService.TryGetOrCreate(doc.Info, doc.IsAutoLoaded);
                if (document != null && !hash.Contains(document))
                {
                    hash.Add(document);
                    loadedDocuments.Add(document);
                }
            }
            return(loadedDocuments.ToArray());
        }
Пример #6
0
        public IDsDocument LoadModule(ModuleId moduleId, bool canLoadDynFile, bool diskFileOk, bool isAutoLoaded)
        {
            IDsDocument document;

            if (diskFileOk)
            {
                document = LoadExisting(moduleId) ?? LoadNonDiskFile(moduleId, canLoadDynFile);
                if (document != null)
                {
                    return(document);
                }
            }
            else
            {
                document = LoadNonDiskFile(moduleId, canLoadDynFile) ?? LoadExisting(moduleId);
                if (document != null)
                {
                    return(document);
                }
            }

            if (moduleId.IsDynamic || moduleId.IsInMemory)
            {
                return(null);
            }

            string moduleFilename = moduleId.ModuleName;

            if (!File.Exists(moduleFilename))
            {
                return(null);
            }
            string asmFilename = GetAssemblyFilename(moduleFilename, moduleId.AssemblyFullName, moduleId.ModuleNameOnly);

            if (!string.IsNullOrEmpty(asmFilename))
            {
                document = documentService.TryGetOrCreate(DsDocumentInfo.CreateDocument(asmFilename), isAutoLoaded);
                if (document == null)
                {
                    document = documentService.Resolve(new AssemblyNameInfo(moduleId.AssemblyFullName), null);
                }
                if (document != null)
                {
                    // Common case is a one-file assembly or first module of a multifile assembly
                    if (asmFilename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
                    {
                        return(document);
                    }

                    foreach (var child in document.Children)
                    {
                        if (child.Filename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
                        {
                            return(child);
                        }
                    }
                }
            }

            return(documentService.TryGetOrCreate(DsDocumentInfo.CreateDocument(moduleFilename), isAutoLoaded));
        }