本文整理汇总了C#中PEReader.TryOpenAssociatedPortablePdb方法的典型用法代码示例。如果您正苦于以下问题:C# PEReader.TryOpenAssociatedPortablePdb方法的具体用法?C# PEReader.TryOpenAssociatedPortablePdb怎么用?C# PEReader.TryOpenAssociatedPortablePdb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PEReader
的用法示例。
在下文中一共展示了PEReader.TryOpenAssociatedPortablePdb方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: TryOpenAssociatedPortablePdb_ExpectedExceptionFromStreamProvider_NoFallback
public void TryOpenAssociatedPortablePdb_ExpectedExceptionFromStreamProvider_NoFallback()
{
var pdbBuilder = new BlobBuilder();
pdbBuilder.WriteBytes(PortablePdbs.DocumentsPdb);
var id = new BlobContentId(Guid.Parse("18091B06-32BB-46C2-9C3B-7C9389A2F6C6"), 0x12345678);
var ddBuilder = new DebugDirectoryBuilder();
ddBuilder.AddCodeViewEntry(@"/a/b/a.pdb", id, portablePdbVersion: 0x0100);
var peStream = new MemoryStream(TestBuilders.BuildPEWithDebugDirectory(ddBuilder));
using (var reader = new PEReader(peStream))
{
MetadataReaderProvider pdbProvider;
string pdbPath;
Assert.Throws<IOException>(() =>
reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { throw new IOException(); }, out pdbProvider, out pdbPath));
AssertEx.Throws<BadImageFormatException>(() =>
reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { throw new BadImageFormatException("Bang!"); }, out pdbProvider, out pdbPath),
e => Assert.Equal("Bang!", e.Message));
// file doesn't exist and no embedded => return false
Assert.False(reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { throw new FileNotFoundException(); }, out pdbProvider, out pdbPath));
}
}
示例3: TryOpenAssociatedPortablePdb_BadStreamProvider
public void TryOpenAssociatedPortablePdb_BadStreamProvider()
{
var pdbBuilder = new BlobBuilder();
pdbBuilder.WriteBytes(PortablePdbs.DocumentsPdb);
var id = new BlobContentId(Guid.Parse("18091B06-32BB-46C2-9C3B-7C9389A2F6C6"), 0x12345678);
var ddBuilder = new DebugDirectoryBuilder();
ddBuilder.AddCodeViewEntry(@"/a/b/a.pdb", id, portablePdbVersion: 0x0100);
var peStream = new MemoryStream(TestBuilders.BuildPEWithDebugDirectory(ddBuilder));
using (var reader = new PEReader(peStream))
{
MetadataReaderProvider pdbProvider;
string pdbPath;
// pass-thru:
Assert.Throws<ArgumentException>(() =>
reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { throw new ArgumentException(); }, out pdbProvider, out pdbPath));
Assert.Throws<InvalidOperationException>(() =>
reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { return new TestStream(canRead: false, canWrite: true, canSeek: true); }, out pdbProvider, out pdbPath));
Assert.Throws<InvalidOperationException>(() =>
reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { return new TestStream(canRead: true, canWrite: true, canSeek: false); }, out pdbProvider, out pdbPath));
}
}
示例4: TryOpenAssociatedPortablePdb_BadPdbFile_FallbackToEmbedded
public void TryOpenAssociatedPortablePdb_BadPdbFile_FallbackToEmbedded()
{
var pdbBuilder = new BlobBuilder();
pdbBuilder.WriteBytes(PortablePdbs.DocumentsPdb);
var id = new BlobContentId(Guid.Parse("18091B06-32BB-46C2-9C3B-7C9389A2F6C6"), 0x12345678);
var ddBuilder = new DebugDirectoryBuilder();
ddBuilder.AddCodeViewEntry(@"/a/b/a.pdb", id, portablePdbVersion: 0x0100);
ddBuilder.AddEmbeddedPortablePdbEntry(pdbBuilder, portablePdbVersion: 0x0100);
var peStream = new MemoryStream(TestBuilders.BuildPEWithDebugDirectory(ddBuilder));
using (var reader = new PEReader(peStream))
{
string pathQueried = null;
Func<string, Stream> streamProvider = p =>
{
Assert.Null(pathQueried);
pathQueried = p;
// Bad PDB
return new MemoryStream(new byte[] { 0x01 });
};
MetadataReaderProvider pdbProvider;
string pdbPath;
Assert.True(reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), streamProvider, out pdbProvider, out pdbPath));
Assert.Null(pdbPath);
Assert.Equal(PathUtilities.CombinePathWithRelativePath("pedir", "a.pdb"), pathQueried);
Assert.Equal(13, pdbProvider.GetMetadataReader().Documents.Count);
}
}
示例5: TryOpenAssociatedPortablePdb_ExpectedExceptionFromStreamProvider_FallbackOnEmbedded_Valid
public void TryOpenAssociatedPortablePdb_ExpectedExceptionFromStreamProvider_FallbackOnEmbedded_Valid()
{
var pdbBuilder = new BlobBuilder();
pdbBuilder.WriteBytes(PortablePdbs.DocumentsPdb);
var id = new BlobContentId(Guid.Parse("18091B06-32BB-46C2-9C3B-7C9389A2F6C6"), 0x12345678);
var ddBuilder = new DebugDirectoryBuilder();
ddBuilder.AddCodeViewEntry(@"/a/b/a.pdb", id, portablePdbVersion: 0x0100);
ddBuilder.AddEmbeddedPortablePdbEntry(pdbBuilder, portablePdbVersion: 0x0100);
var peStream = new MemoryStream(TestBuilders.BuildPEWithDebugDirectory(ddBuilder));
using (var reader = new PEReader(peStream))
{
MetadataReaderProvider pdbProvider;
string pdbPath;
Assert.True(reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { throw new IOException(); }, out pdbProvider, out pdbPath));
Assert.Null(pdbPath);
Assert.Equal(13, pdbProvider.GetMetadataReader().Documents.Count);
Assert.True(reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { throw new BadImageFormatException(); }, out pdbProvider, out pdbPath));
Assert.Null(pdbPath);
Assert.Equal(13, pdbProvider.GetMetadataReader().Documents.Count);
Assert.True(reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { throw new FileNotFoundException(); }, out pdbProvider, out pdbPath));
Assert.Null(pdbPath);
Assert.Equal(13, pdbProvider.GetMetadataReader().Documents.Count);
}
}
示例6: TryOpenAssociatedPortablePdb_DuplicateEntries_CodeView
public void TryOpenAssociatedPortablePdb_DuplicateEntries_CodeView()
{
var id = new BlobContentId(Guid.Parse("18091B06-32BB-46C2-9C3B-7C9389A2F6C6"), 0x12345678);
var ddBuilder = new DebugDirectoryBuilder();
ddBuilder.AddCodeViewEntry(@"/a/b/a.pdb", id, portablePdbVersion: 0);
ddBuilder.AddReproducibleEntry();
ddBuilder.AddCodeViewEntry(@"/a/b/c.pdb", id, portablePdbVersion: 0x0100);
ddBuilder.AddCodeViewEntry(@"/a/b/d.pdb", id, portablePdbVersion: 0x0100);
var peStream = new MemoryStream(TestBuilders.BuildPEWithDebugDirectory(ddBuilder));
using (var reader = new PEReader(peStream))
{
string pathQueried = null;
Func<string, Stream> streamProvider = p =>
{
Assert.Null(pathQueried);
pathQueried = p;
return null;
};
MetadataReaderProvider pdbProvider;
string pdbPath;
Assert.False(reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), streamProvider, out pdbProvider, out pdbPath));
Assert.Equal(PathUtilities.CombinePathWithRelativePath("pedir", "c.pdb"), pathQueried);
}
}
示例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);
}
}
}
示例8: TryOpenAssociatedPortablePdb_EmbeddedOnly
public void TryOpenAssociatedPortablePdb_EmbeddedOnly()
{
var peStream = new MemoryStream(PortablePdbs.DocumentsEmbeddedDll);
using (var reader = new PEReader(peStream))
{
MetadataReaderProvider pdbProvider;
string pdbPath;
Assert.True(reader.TryOpenAssociatedPortablePdb(@"x", _ => null, out pdbProvider, out pdbPath));
Assert.Null(pdbPath);
var pdbReader = pdbProvider.GetMetadataReader();
Assert.Equal(13, pdbReader.Documents.Count);
}
}
示例9: TryOpenAssociatedPortablePdb_Embedded
public void TryOpenAssociatedPortablePdb_Embedded()
{
var peStream = new MemoryStream(PortablePdbs.DocumentsEmbeddedDll);
using (var reader = new PEReader(peStream))
{
string pathQueried = null;
Func<string, Stream> streamProvider = p =>
{
Assert.Null(pathQueried);
pathQueried = p;
return null;
};
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.Null(pdbPath);
var pdbReader = pdbProvider.GetMetadataReader();
Assert.Equal(13, pdbReader.Documents.Count);
}
}
示例10: TryOpenAssociatedPortablePdb_Args
public void TryOpenAssociatedPortablePdb_Args()
{
var peStream = new MemoryStream(PortablePdbs.DocumentsDll);
using (var reader = new PEReader(peStream))
{
MetadataReaderProvider pdbProvider;
string pdbPath;
Assert.False(reader.TryOpenAssociatedPortablePdb(@"b.dll", _ => null, out pdbProvider, out pdbPath));
Assert.Throws<ArgumentNullException>(() => reader.TryOpenAssociatedPortablePdb(@"b.dll", null, out pdbProvider, out pdbPath));
Assert.Throws<ArgumentNullException>(() => reader.TryOpenAssociatedPortablePdb(null, _ => null, out pdbProvider, out pdbPath));
Assert.Throws<ArgumentException>("peImagePath", () => reader.TryOpenAssociatedPortablePdb("C:\\a\\\0\\b", _ => null, out pdbProvider, out pdbPath));
}
}