本文整理汇总了C#中PEReader.ReadDebugDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# PEReader.ReadDebugDirectory方法的具体用法?C# PEReader.ReadDebugDirectory怎么用?C# PEReader.ReadDebugDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PEReader
的用法示例。
在下文中一共展示了PEReader.ReadDebugDirectory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeView
public void CodeView()
{
var peStream = new MemoryStream(Misc.Debug);
using (var reader = new PEReader(peStream))
{
// dumpbin:
//
// Debug Directories
//
// Time Type Size RVA Pointer
// -------------- - ------------------------
// 5670C4E6 cv 11C 0000230C 50C Format: RSDS, { 0C426227-31E6-4EC2-BD5F-712C4D96C0AB}, 1, C:\Temp\Debug.pdb
var cvEntry = reader.ReadDebugDirectory().Single();
Assert.Equal(DebugDirectoryEntryType.CodeView, cvEntry.Type);
Assert.Equal(0x050c, cvEntry.DataPointer);
Assert.Equal(0x230c, cvEntry.DataRelativeVirtualAddress);
Assert.Equal(0x011c, cvEntry.DataSize); // includes NUL padding
Assert.Equal(0, cvEntry.MajorVersion);
Assert.Equal(0, cvEntry.MinorVersion);
Assert.Equal(0x5670c4e6u, cvEntry.Stamp);
var cv = reader.ReadCodeViewDebugDirectoryData(cvEntry);
Assert.Equal(1, cv.Age);
Assert.Equal(new Guid("0C426227-31E6-4EC2-BD5F-712C4D96C0AB"), cv.Guid);
Assert.Equal(@"C:\Temp\Debug.pdb", cv.Path);
}
}
示例2: NoDebugDirectory
public void NoDebugDirectory()
{
var peStream = new MemoryStream(Misc.Members);
using (var reader = new PEReader(peStream))
{
var entries = reader.ReadDebugDirectory();
Assert.Empty(entries);
}
}
示例3: Deterministic
public void Deterministic()
{
var peStream = new MemoryStream(Misc.Deterministic);
using (var reader = new PEReader(peStream))
{
// dumpbin:
//
// Debug Directories
//
// Time Type Size RVA Pointer
// -------- ------- -------- -------- --------
// D2FC74D3 cv 32 00002338 538 Format: RSDS, {814C578F-7676-0263-4F8A-2D3E8528EAF1}, 1, C:\Temp\Deterministic.pdb
// 00000000 repro 0 00000000 0
var entries = reader.ReadDebugDirectory();
var cvEntry = entries[0];
Assert.Equal(DebugDirectoryEntryType.CodeView, cvEntry.Type);
Assert.Equal(0x0538, cvEntry.DataPointer);
Assert.Equal(0x2338, cvEntry.DataRelativeVirtualAddress);
Assert.Equal(0x0032, cvEntry.DataSize); // no NUL padding
Assert.Equal(0, cvEntry.MajorVersion);
Assert.Equal(0, cvEntry.MinorVersion);
Assert.Equal(0xD2FC74D3u, cvEntry.Stamp);
var cv = reader.ReadCodeViewDebugDirectoryData(cvEntry);
Assert.Equal(1, cv.Age);
Assert.Equal(new Guid("814C578F-7676-0263-4F8A-2D3E8528EAF1"), cv.Guid);
Assert.Equal(@"C:\Temp\Deterministic.pdb", cv.Path);
var detEntry = entries[1];
Assert.Equal(DebugDirectoryEntryType.Deterministic, detEntry.Type);
Assert.Equal(0, detEntry.DataPointer);
Assert.Equal(0, detEntry.DataRelativeVirtualAddress);
Assert.Equal(0, detEntry.DataSize);
Assert.Equal(0, detEntry.MajorVersion);
Assert.Equal(0, detEntry.MinorVersion);
Assert.Equal(0u, detEntry.Stamp);
Assert.Equal(2, entries.Length);
Assert.Throws<ArgumentException>(() => reader.ReadCodeViewDebugDirectoryData(detEntry));
}
}
示例4: ValidateDeterministic
private void ValidateDeterministic(PEReader reader)
{
// dumpbin:
//
// Debug Directories
//
// Time Type Size RVA Pointer
// -------- ------- -------- -------- --------
// D2FC74D3 cv 32 00002338 538 Format: RSDS, {814C578F-7676-0263-4F8A-2D3E8528EAF1}, 1, C:\Temp\Deterministic.pdb
// 00000000 repro 0 00000000 0
var entries = reader.ReadDebugDirectory();
var cvEntry = entries[0];
Assert.Equal(DebugDirectoryEntryType.CodeView, cvEntry.Type);
Assert.False(cvEntry.IsPortableCodeView);
Assert.Equal(0x0538, cvEntry.DataPointer);
Assert.Equal(0x2338, cvEntry.DataRelativeVirtualAddress);
Assert.Equal(0x0032, cvEntry.DataSize); // no NUL padding
Assert.Equal(0, cvEntry.MajorVersion);
Assert.Equal(0, cvEntry.MinorVersion);
Assert.Equal(0xD2FC74D3u, cvEntry.Stamp);
var cv = reader.ReadCodeViewDebugDirectoryData(cvEntry);
Assert.Equal(1, cv.Age);
Assert.Equal(new Guid("814C578F-7676-0263-4F8A-2D3E8528EAF1"), cv.Guid);
Assert.Equal(@"C:\Temp\Deterministic.pdb", cv.Path);
var detEntry = entries[1];
Assert.Equal(DebugDirectoryEntryType.Reproducible, detEntry.Type);
Assert.False(detEntry.IsPortableCodeView);
Assert.Equal(0, detEntry.DataPointer);
Assert.Equal(0, detEntry.DataRelativeVirtualAddress);
Assert.Equal(0, detEntry.DataSize);
Assert.Equal(0, detEntry.MajorVersion);
Assert.Equal(0, detEntry.MinorVersion);
Assert.Equal(0u, detEntry.Stamp);
Assert.Equal(2, entries.Length);
}
示例5: ValidateEmbeddedPortablePdb
private void ValidateEmbeddedPortablePdb(PEReader reader)
{
var entries = reader.ReadDebugDirectory();
Assert.Equal(DebugDirectoryEntryType.CodeView, entries[0].Type);
Assert.Equal(DebugDirectoryEntryType.Reproducible, entries[1].Type);
Assert.Equal(DebugDirectoryEntryType.EmbeddedPortablePdb, entries[2].Type);
var provider = reader.ReadEmbeddedPortablePdbDebugDirectoryData(entries[2]);
var pdbReader = provider.GetMetadataReader();
var document = pdbReader.GetDocument(pdbReader.Documents.First());
Assert.Equal(@"C:\Documents.cs", pdbReader.GetString(document.Name));
}
示例6: Dispose
public void Dispose()
{
var peStream = new MemoryStream(PortablePdbs.DocumentsEmbeddedDll);
var reader = new PEReader(peStream);
MetadataReaderProvider pdbProvider;
string pdbPath;
Assert.True(reader.TryOpenAssociatedPortablePdb(@"x", _ => null, out pdbProvider, out pdbPath));
Assert.NotNull(pdbProvider);
Assert.Null(pdbPath);
var ddEntries = reader.ReadDebugDirectory();
var ddCodeView = ddEntries[0];
var ddEmbedded = ddEntries[2];
var embeddedPdbProvider = reader.ReadEmbeddedPortablePdbDebugDirectoryData(ddEmbedded);
// dispose the PEReader:
reader.Dispose();
Assert.False(reader.IsEntireImageAvailable);
Assert.Throws<ObjectDisposedException>(() => reader.PEHeaders);
Assert.Throws<ObjectDisposedException>(() => reader.HasMetadata);
Assert.Throws<ObjectDisposedException>(() => reader.GetMetadata());
Assert.Throws<ObjectDisposedException>(() => reader.GetSectionData(1000));
Assert.Throws<ObjectDisposedException>(() => reader.GetMetadataReader());
Assert.Throws<ObjectDisposedException>(() => reader.GetMethodBody(0));
Assert.Throws<ObjectDisposedException>(() => reader.GetEntireImage());
Assert.Throws<ObjectDisposedException>(() => reader.ReadDebugDirectory());
Assert.Throws<ObjectDisposedException>(() => reader.ReadCodeViewDebugDirectoryData(ddCodeView));
Assert.Throws<ObjectDisposedException>(() => reader.ReadEmbeddedPortablePdbDebugDirectoryData(ddEmbedded));
MetadataReaderProvider __;
string ___;
Assert.Throws<ObjectDisposedException>(() => reader.TryOpenAssociatedPortablePdb(@"x", _ => null, out __, out ___));
// ok to use providers after PEReader disposed:
var pdbReader = pdbProvider.GetMetadataReader();
Assert.Equal(13, pdbReader.Documents.Count);
pdbReader = embeddedPdbProvider.GetMetadataReader();
Assert.Equal(13, pdbReader.Documents.Count);
embeddedPdbProvider.Dispose();
}
示例7: TryOpenAssociatedPortablePdb_EmbeddedUnused
public unsafe void TryOpenAssociatedPortablePdb_EmbeddedUnused()
{
var peStream = new MemoryStream(PortablePdbs.DocumentsEmbeddedDll);
using (var reader = new PEReader(peStream))
{
using (MetadataReaderProvider embeddedProvider = reader.ReadEmbeddedPortablePdbDebugDirectoryData(reader.ReadDebugDirectory()[2]))
{
var embeddedReader = embeddedProvider.GetMetadataReader();
var embeddedBytes = new BlobReader(embeddedReader.MetadataPointer, embeddedReader.MetadataLength).ReadBytes(embeddedReader.MetadataLength);
string pathQueried = null;
Func<string, Stream> streamProvider = p =>
{
Assert.Null(pathQueried);
pathQueried = p;
return new MemoryStream(embeddedBytes);
};
MetadataReaderProvider pdbProvider;
string pdbPath;
Assert.True(reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), streamProvider, out pdbProvider, out pdbPath));
Assert.Equal(Path.Combine("pedir", "Documents.Embedded.pdb"), pathQueried);
Assert.Equal(Path.Combine("pedir", "Documents.Embedded.pdb"), pdbPath);
var pdbReader = pdbProvider.GetMetadataReader();
Assert.Equal(13, pdbReader.Documents.Count);
}
}
}