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); }
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)); }