/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="pdbImpl">PDB implementation to use</param> /// <param name="mdStream">.NET metadata stream which is now owned by us. Only need to be /// non-null if MS COM API should be used</param> /// <param name="pdbStream">PDB file stream which is now owned by us</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if it's not possible /// to create a <see cref="ISymbolReader"/>.</returns> public static ISymbolReader Create(PdbImplType pdbImpl, IImageStream mdStream, IImageStream pdbStream) { switch (pdbImpl) { case PdbImplType.MicrosoftCOM: return(Dss.SymbolReaderCreator.Create(mdStream, pdbStream)); case PdbImplType.Managed: if (mdStream != null) { mdStream.Dispose(); } return(Managed.SymbolReaderCreator.Create(pdbStream)); default: if (mdStream != null) { mdStream.Dispose(); } if (pdbStream != null) { pdbStream.Dispose(); } throw new InvalidOperationException(); } }
void ResetReader() { if (imageStream != null) { imageStream.Dispose(); imageStream = null; } imageStream = imageStreamCreator.CreateFull(); }
/// <inheritdoc/> public void Dispose() { if (ownReader && reader != null) { reader.Dispose(); } }
public void Dispose() { if (stream != null) { stream.Dispose(); } }
/// <inheritdoc/> protected override void Dispose(bool disposing) { if (!disposing) { return; } #if THREAD_SAFE theLock.EnterWriteLock(); try { #endif if (dataReader != null) { dataReader.Dispose(); } if (rsrcReader != null) { rsrcReader.Dispose(); } dataReader = null; rsrcReader = null; #if THREAD_SAFE } finally { theLock.ExitWriteLock(); } #endif base.Dispose(disposing); }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="pdbStream">PDB file stream which is now owned by this method</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c>.</returns> public static ISymbolReader Create(IImageStream pdbStream) { if (pdbStream == null) { return(null); } try { var pdbReader = new PdbReader(); pdbReader.Read(pdbStream); return(pdbReader); } catch (IOException) { } catch (UnauthorizedAccessException) { } catch (SecurityException) { } finally { if (pdbStream != null) { pdbStream.Dispose(); } } return(null); }
/// <inheritdoc/> public void Dispose() { if (reader != null) { reader.Dispose(); } }
/// <summary> /// Dispose method /// </summary> /// <param name="disposing"><c>true</c> if called by <see cref="Dispose()"/></param> protected virtual void Dispose(bool disposing) { if (disposing) { if (reader != null) { reader.Dispose(); } } }
/// <inheritdoc/> public void Dispose() { stream.Dispose(); var id = UserData as IDisposable; if (id != null) { id.Dispose(); } }
/// <inheritdoc/> public void Dispose() { if (imageStream != null) { imageStream.Dispose(); } numRows = 0; tableInfo = null; imageStream = null; }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="mdStream">.NET metadata stream which is now owned by this method</param> /// <param name="pdbData">PDB file data</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if any of the COM /// methods fail.</returns> public static ISymbolReader Create(IImageStream mdStream, byte[] pdbData) { if (pdbData == null) { if (mdStream != null) { mdStream.Dispose(); } return(null); } try { return(Create(mdStream, MemoryImageStream.Create(pdbData))); } catch { if (mdStream != null) { mdStream.Dispose(); } throw; } }
/// <summary> /// Dispose method /// </summary> /// <param name="disposing"><c>true</c> if called by <see cref="Dispose()"/></param> protected virtual void Dispose(bool disposing) { if (disposing) { if (imageStream != null) { imageStream.Dispose(); } imageStream = null; streamHeader = null; } }
/// <inheritdoc/> protected override void Dispose(bool disposing) { if (!disposing) { return; } if (dataStream != null) { dataStream.Dispose(); } dataStream = null; base.Dispose(disposing); }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="metaData">.NET metadata</param> /// <param name="pdbStream">PDB file stream which is now owned by this method</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if any of the COM /// methods fail.</returns> public static ISymbolReader Create(IMetaData metaData, IImageStream pdbStream) { try { return(Create(CreateMetaDataStream(metaData), pdbStream)); } catch { if (pdbStream != null) { pdbStream.Dispose(); } throw; } }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="mdStream">.NET metadata stream which is now owned by this method</param> /// <param name="pdbFileName">Path to PDB file</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if there's no PDB /// file on disk or if any of the COM methods fail.</returns> public static ISymbolReader Create(IImageStream mdStream, string pdbFileName) { try { return(Create(mdStream, OpenImageStream(pdbFileName))); } catch { if (mdStream != null) { mdStream.Dispose(); } throw; } }
static uint GetEntryPointToken(string filename, out string otherModuleName) { otherModuleName = null; IImageStream cor20HeaderStream = null; try { using (var peImage = new PEImage(filename)) { var dotNetDir = peImage.ImageNTHeaders.OptionalHeader.DataDirectories[14]; if (dotNetDir.VirtualAddress == 0) { return(0); } if (dotNetDir.Size < 0x48) { return(0); } var cor20Header = new ImageCor20Header(cor20HeaderStream = peImage.CreateStream(dotNetDir.VirtualAddress, 0x48), true); if ((cor20Header.Flags & ComImageFlags.NativeEntryPoint) != 0) { return(0); } uint token = cor20Header.EntryPointToken_or_RVA; if ((Table)(token >> 24) != Table.File) { return(token); } using (var mod = ModuleDefMD.Load(peImage)) { var file = mod.ResolveFile(token & 0x00FFFFFF); if (file == null || !file.ContainsMetaData) { return(0); } otherModuleName = file.Name; return(token); } } } catch { } finally { if (cor20HeaderStream != null) { cor20HeaderStream.Dispose(); } } return(0); }
public static SymbolReader Create(IMetaData metaData, IImageStream pdbStream) { try { // Embedded pdbs have priority var res = Create(metaData); if (res != null) { if (pdbStream != null) { pdbStream.Dispose(); } return(res); } return(CreateCore(pdbStream)); } catch { if (pdbStream != null) { pdbStream.Dispose(); } throw; } }
void Dispose(bool disposing) { if (gcHandle.IsAllocated) { try { gcHandle.Free(); } catch (InvalidOperationException) { } } if (disposing) { stream.Dispose(); } }
/// <inheritdoc/> protected override HotTableStream CreateHotTableStreamImpl() { IImageStream stream = null; try { stream = fullStream.Clone(); return(new HotTableStreamCLR40(stream, GetHotTableBaseOffset())); } catch { if (stream != null) { stream.Dispose(); } throw; } }
private ThreadSafe.IList <HotHeapStream> CreateHotHeapStreams2() { var list = ThreadSafeListCreator.Create <HotHeapStream>(); try { var dirBaseOffs = GetHotHeapDirectoryBaseOffset(); for (var offs = dirBaseOffs; offs + 8 <= endOffset - 8; offs += 8) { fullStream.Position = offs; HeapType heapType; long hotHeapOffset; ReadHotHeapDirectory(fullStream, dirBaseOffs, out heapType, out hotHeapOffset); IImageStream dataStream = null; HotHeapStream hotHeapStream = null; try { dataStream = fullStream.Clone(); list.Add(hotHeapStream = CreateHotHeapStream(heapType, dataStream, hotHeapOffset)); dataStream = null; hotHeapStream = null; } catch { if (hotHeapStream != null) { hotHeapStream.Dispose(); } if (dataStream != null) { dataStream.Dispose(); } throw; } } } catch { foreach (var h in list) { h.Dispose(); } throw; } return(list); }
/// <inheritdoc/> protected override void Dispose(bool disposing) { if (!disposing) { return; } if (dataReader != null) { dataReader.Dispose(); } if (rsrcReader != null) { rsrcReader.Dispose(); } dataReader = null; rsrcReader = null; base.Dispose(disposing); }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="pdbStream">PDB file stream which is now owned by this method</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c>.</returns> public static ISymbolReader Create(IImageStream pdbStream) { if (pdbStream == null) return null; try { var pdbReader = new PdbReader(); pdbReader.Read(pdbStream); return pdbReader; } catch (IOException) { } catch (UnauthorizedAccessException) { } catch (SecurityException) { } finally { if (pdbStream != null) pdbStream.Dispose(); } return null; }
public static SymbolReader TryCreate(IImageStream pdbStream, bool isEmbeddedPortablePdb) { try { if (pdbStream != null) { pdbStream.Position = 0; if (pdbStream.ReadUInt32() == 0x424A5342) { pdbStream.Position = 0; return(new PortablePdbReader(pdbStream, isEmbeddedPortablePdb ? PdbFileKind.EmbeddedPortablePDB : PdbFileKind.PortablePDB)); } } } catch (IOException) { } if (pdbStream != null) { pdbStream.Dispose(); } return(null); }
public void Dispose() { if (ownPeImage) { if (metaData != null) { metaData.Dispose(); } if (peImage != null) { peImage.Dispose(); } } if (peStream != null) { peStream.Dispose(); } metaData = null; peImage = null; peStream = null; }
public void Dispose() { if (ownPeImage) { if (dnFile != null) { dnFile.Dispose(); } if (peImage != null) { peImage.Dispose(); } } if (peStream != null) { peStream.Dispose(); } dnFile = null; peImage = null; peStream = null; }
/// <summary> /// Creates a new <see cref="SymbolReader"/> instance /// </summary> /// <param name="pdbStream">PDB file stream which is now owned by this method</param> /// <returns>A new <see cref="SymbolReader"/> instance or <c>null</c>.</returns> public static SymbolReader Create(IImageStream pdbStream) { if (pdbStream == null) { return(null); } try { var pdbReader = new PdbReader(); pdbReader.Read(pdbStream); return(pdbReader); } catch (PdbException) { } catch (IOException) { } finally { if (pdbStream != null) { pdbStream.Dispose(); } } return(null); }
static SymbolReader CreateCore(IImageStream pdbStream) { if (pdbStream == null) { return(null); } try { uint sig = pdbStream.ReadUInt32(); pdbStream.Position = 0; if (sig == 0x424A5342) { return(Portable.SymbolReaderCreator.TryCreate(pdbStream, false)); } return(Managed.SymbolReaderCreator.Create(pdbStream)); } catch (IOException) { } if (pdbStream != null) { pdbStream.Dispose(); } return(null); }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="metaData">.NET metadata</param> /// <param name="pdbStream">PDB file stream which is now owned by this method</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if any of the COM /// methods fail.</returns> public static ISymbolReader Create(IMetaData metaData, IImageStream pdbStream) { try { return Create(CreateMetaDataStream(metaData), pdbStream); } catch { if (pdbStream != null) pdbStream.Dispose(); throw; } }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="mdStream">.NET metadata stream which is now owned by this method</param> /// <param name="pdbStream">PDB file stream which is now owned by this method</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if any of the COM /// methods fail.</returns> public static ISymbolReader Create(IImageStream mdStream, IImageStream pdbStream) { ImageStreamIStream stream = null; PinnedMetaData pinnedMd = null; bool error = true; try { if (pdbStream == null || mdStream == null) { return(null); } object mdDispObj; Guid CLSID_CorMetaDataDispenser = new Guid(0xE5CB7A31, 0x7512, 0x11D2, 0x89, 0xCE, 0x0, 0x80, 0xC7, 0x92, 0xE5, 0xD8); Guid IID_IMetaDataDispenser = new Guid(0x809C652E, 0x7396, 0x11D2, 0x97, 0x71, 0x00, 0xA0, 0xC9, 0xB4, 0xD5, 0x0C); int hr = CoCreateInstance(ref CLSID_CorMetaDataDispenser, IntPtr.Zero, 1, ref IID_IMetaDataDispenser, out mdDispObj); if (hr < 0) { return(null); } object mdImportObj; var mdDisp = (IMetaDataDispenser)mdDispObj; Guid IID_IMetaDataImport = new Guid(0x7DAC8207, 0xD3AE, 0x4C75, 0x9B, 0x67, 0x92, 0x80, 0x1A, 0x49, 0x7D, 0x44); pinnedMd = new PinnedMetaData(mdStream); mdDisp.OpenScopeOnMemory(pinnedMd.Address, (uint)pinnedMd.Size, 0x10, ref IID_IMetaDataImport, out mdImportObj); Marshal.FinalReleaseComObject(mdDispObj); ISymUnmanagedReader symReader; var binder = (ISymUnmanagedBinder)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CorSymBinder_SxS)); stream = new ImageStreamIStream(pdbStream, null) { UserData = pinnedMd }; hr = binder.GetReaderFromStream((IMetaDataImport)mdImportObj, stream, out symReader); Marshal.FinalReleaseComObject(mdImportObj); Marshal.FinalReleaseComObject(binder); if (hr >= 0) { error = false; return(new SymbolReader(symReader)); } stream.Dispose(); } catch (IOException) { } catch (InvalidCastException) { } catch (COMException) { } finally { if (error) { if (stream != null) { stream.Dispose(); } if (pinnedMd != null) { pinnedMd.Dispose(); } if (mdStream != null) { mdStream.Dispose(); } if (pdbStream != null) { pdbStream.Dispose(); } } } return(null); }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="pdbImpl">PDB implementation to use</param> /// <param name="metaData">.NET metadata. Only need to be non-null if MS COM API should be used</param> /// <param name="pdbStream">PDB file stream which is now owned by us</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if it's not possible /// to create a <see cref="ISymbolReader"/>.</returns> public static ISymbolReader Create(PdbImplType pdbImpl, IMetaData metaData, IImageStream pdbStream) { switch (pdbImpl) { case PdbImplType.MicrosoftCOM: return Dss.SymbolReaderCreator.Create(metaData, pdbStream); case PdbImplType.Managed: return Managed.SymbolReaderCreator.Create(pdbStream); default: if (pdbStream != null) pdbStream.Dispose(); throw new InvalidOperationException(); } }
/// <inheritdoc/> protected override void InitializeInternal() { var hotHeapVersion = GetHotHeapVersion(peImage.FileName, mdHeader.VersionString); IImageStream imageStream = null, fullStream = null; DotNetStream dns = null; List <HotStream> hotStreams = null; HotStream hotStream = null; var newAllStreams = new List <DotNetStream>(allStreams); try { var mdRva = cor20Header.MetaData.VirtualAddress; for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--) { var sh = mdHeader.StreamHeaders[i]; var rva = mdRva + sh.Offset; var fileOffset = peImage.ToFileOffset(rva); imageStream = peImage.CreateStream(fileOffset, sh.StreamSize); switch (sh.Name) { case "#Strings": if (stringsStream == null) { stringsStream = new StringsStream(imageStream, sh); imageStream = null; newAllStreams.Add(stringsStream); continue; } break; case "#US": if (usStream == null) { usStream = new USStream(imageStream, sh); imageStream = null; newAllStreams.Add(usStream); continue; } break; case "#Blob": if (blobStream == null) { blobStream = new BlobStream(imageStream, sh); imageStream = null; newAllStreams.Add(blobStream); continue; } break; case "#GUID": if (guidStream == null) { guidStream = new GuidStream(imageStream, sh); imageStream = null; newAllStreams.Add(guidStream); continue; } break; case "#~": if (tablesStream == null) { tablesStream = new TablesStream(imageStream, sh); imageStream = null; newAllStreams.Add(tablesStream); continue; } break; case "#!": if (hotStreams == null) { hotStreams = new List <HotStream>(); } fullStream = peImage.CreateFullStream(); hotStream = HotStream.Create(hotHeapVersion, imageStream, sh, fullStream, fileOffset); fullStream = null; hotStreams.Add(hotStream); newAllStreams.Add(hotStream); hotStream = null; imageStream = null; continue; } dns = new DotNetStream(imageStream, sh); imageStream = null; newAllStreams.Add(dns); dns = null; } } finally { if (imageStream != null) { imageStream.Dispose(); } if (fullStream != null) { fullStream.Dispose(); } if (dns != null) { dns.Dispose(); } if (hotStream != null) { hotStream.Dispose(); } newAllStreams.Reverse(); allStreams = ThreadSafeListCreator.MakeThreadSafe(newAllStreams); } if (tablesStream == null) { throw new BadImageFormatException("Missing MD stream"); } if (hotStreams != null) { hotStreams.Reverse(); InitializeHotStreams(hotStreams); } tablesStream.Initialize(peImage); }
/// <inheritdoc/> protected override void Initialize2() { IImageStream imageStream = null; DotNetStream dns = null; try { var mdRva = cor20Header.MetaData.VirtualAddress; foreach (var sh in mdHeader.StreamHeaders) { var rva = mdRva + sh.Offset; imageStream = peImage.CreateStream(rva, sh.StreamSize); switch (sh.Name.ToUpperInvariant()) { case "#STRINGS": if (stringsStream == null) { stringsStream = new StringsStream(imageStream, sh); imageStream = null; allStreams.Add(stringsStream); continue; } break; case "#US": if (usStream == null) { usStream = new USStream(imageStream, sh); imageStream = null; allStreams.Add(usStream); continue; } break; case "#BLOB": if (blobStream == null) { blobStream = new BlobStream(imageStream, sh); imageStream = null; allStreams.Add(blobStream); continue; } break; case "#GUID": if (guidStream == null) { guidStream = new GuidStream(imageStream, sh); imageStream = null; allStreams.Add(guidStream); continue; } break; case "#-": if (tablesStream == null) { tablesStream = new TablesStream(imageStream, sh); imageStream = null; allStreams.Add(tablesStream); continue; } break; } dns = new DotNetStream(imageStream, sh); imageStream = null; allStreams.Add(dns); dns = null; } } finally { if (imageStream != null) { imageStream.Dispose(); } if (dns != null) { dns.Dispose(); } } if (tablesStream == null) { throw new BadImageFormatException("Missing MD stream"); } tablesStream.Initialize(peImage); // The pointer tables are used iff row count != 0 hasFieldPtr = !tablesStream.FieldPtrTable.IsEmpty; hasMethodPtr = !tablesStream.MethodPtrTable.IsEmpty; hasParamPtr = !tablesStream.ParamPtrTable.IsEmpty; hasEventPtr = !tablesStream.EventPtrTable.IsEmpty; hasPropertyPtr = !tablesStream.PropertyPtrTable.IsEmpty; hasDeletedRows = tablesStream.HasDelete; }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="mdStream">.NET metadata stream which is now owned by this method</param> /// <param name="pdbStream">PDB file stream which is now owned by this method</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if any of the COM /// methods fail.</returns> public static ISymbolReader Create(IImageStream mdStream, IImageStream pdbStream) { ImageStreamIStream stream = null; PinnedMetaData pinnedMd = null; bool error = true; try { if (pdbStream == null || mdStream == null) return null; object mdDispObj; Guid CLSID_CorMetaDataDispenser = new Guid(0xE5CB7A31, 0x7512, 0x11D2, 0x89, 0xCE, 0x0, 0x80, 0xC7, 0x92, 0xE5, 0xD8); Guid IID_IMetaDataDispenser = new Guid(0x809C652E, 0x7396, 0x11D2, 0x97, 0x71, 0x00, 0xA0, 0xC9, 0xB4, 0xD5, 0x0C); int hr = CoCreateInstance(ref CLSID_CorMetaDataDispenser, IntPtr.Zero, 1, ref IID_IMetaDataDispenser, out mdDispObj); if (hr < 0) return null; object mdImportObj; var mdDisp = (IMetaDataDispenser)mdDispObj; Guid IID_IMetaDataImport = new Guid(0x7DAC8207, 0xD3AE, 0x4C75, 0x9B, 0x67, 0x92, 0x80, 0x1A, 0x49, 0x7D, 0x44); pinnedMd = new PinnedMetaData(mdStream); mdDisp.OpenScopeOnMemory(pinnedMd.Address, (uint)pinnedMd.Size, 0x10, ref IID_IMetaDataImport, out mdImportObj); Marshal.FinalReleaseComObject(mdDispObj); ISymUnmanagedReader symReader; var binder = (ISymUnmanagedBinder)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CorSymBinder_SxS)); stream = new ImageStreamIStream(pdbStream, null) { UserData = pinnedMd }; hr = binder.GetReaderFromStream((IMetaDataImport)mdImportObj, stream, out symReader); Marshal.FinalReleaseComObject(mdImportObj); Marshal.FinalReleaseComObject(binder); if (hr >= 0) { error = false; return new SymbolReader(symReader); } } catch (IOException) { } catch (InvalidCastException) { } catch (COMException) { } finally { if (error) { if (stream != null) stream.Dispose(); if (pinnedMd != null) pinnedMd.Dispose(); if (mdStream != null) mdStream.Dispose(); if (pdbStream != null) pdbStream.Dispose(); } } return null; }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="mdStream">.NET metadata stream which is now owned by this method</param> /// <param name="pdbData">PDB file data</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if any of the COM /// methods fail.</returns> public static ISymbolReader Create(IImageStream mdStream, byte[] pdbData) { if (pdbData == null) { if (mdStream != null) mdStream.Dispose(); return null; } try { return Create(mdStream, MemoryImageStream.Create(pdbData)); } catch { if (mdStream != null) mdStream.Dispose(); throw; } }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="mdStream">.NET metadata stream which is now owned by this method</param> /// <param name="pdbFileName">Path to PDB file</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if there's no PDB /// file on disk or if any of the COM methods fail.</returns> public static ISymbolReader Create(IImageStream mdStream, string pdbFileName) { try { return Create(mdStream, OpenImageStream(pdbFileName)); } catch { if (mdStream != null) mdStream.Dispose(); throw; } }
/// <summary> /// Creates a new <see cref="ISymbolReader"/> instance /// </summary> /// <param name="pdbImpl">PDB implementation to use</param> /// <param name="mdStream">.NET metadata stream which is now owned by us. Only need to be /// non-null if MS COM API should be used</param> /// <param name="pdbData">PDB file data</param> /// <returns>A new <see cref="ISymbolReader"/> instance or <c>null</c> if it's not possible /// to create a <see cref="ISymbolReader"/>.</returns> public static ISymbolReader Create(PdbImplType pdbImpl, IImageStream mdStream, byte[] pdbData) { switch (pdbImpl) { case PdbImplType.MicrosoftCOM: return Dss.SymbolReaderCreator.Create(mdStream, pdbData); case PdbImplType.Managed: if (mdStream != null) mdStream.Dispose(); return Managed.SymbolReaderCreator.Create(pdbData); default: if (mdStream != null) mdStream.Dispose(); throw new InvalidOperationException(); } }
public void Dispose() { stream.Dispose(); }