本文整理汇总了C#中PEReader.GetMetadataReader方法的典型用法代码示例。如果您正苦于以下问题:C# PEReader.GetMetadataReader方法的具体用法?C# PEReader.GetMetadataReader怎么用?C# PEReader.GetMetadataReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PEReader
的用法示例。
在下文中一共展示了PEReader.GetMetadataReader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyPE
private void VerifyPE(Stream peStream)
{
var peReader = new PEReader(peStream);
var headers = peReader.PEHeaders;
var mdReader = peReader.GetMetadataReader();
// TODO: more validation (can we use MetadataVisualizer until managed PEVerifier is available)?
}
示例2: IL_LazyLoad
public void IL_LazyLoad()
{
var peStream = new MemoryStream(Misc.Members);
using (var reader = new PEReader(peStream, PEStreamOptions.LeaveOpen))
{
var md = reader.GetMetadataReader();
var il = reader.GetMethodBody(md.GetMethodDefinition(MetadataTokens.MethodDefinitionHandle(1)).RelativeVirtualAddress);
Assert.Equal(new byte[] { 0, 42 }, il.GetILBytes());
Assert.Equal(8, il.MaxStack);
}
}
示例3: VerifyPE
private void VerifyPE(Stream peStream, byte[] expectedSignature = null)
{
peStream.Position = 0;
using (var peReader = new PEReader(peStream))
{
var headers = peReader.PEHeaders;
var mdReader = peReader.GetMetadataReader();
// TODO: more validation (can we use MetadataVisualizer until managed PEVerifier is available)?
VerifyStrongNameSignatureDirectory(peReader, expectedSignature);
Assert.Equal(s_contentId.Stamp, unchecked((uint)peReader.PEHeaders.CoffHeader.TimeDateStamp));
Assert.Equal(s_guid, mdReader.GetGuid(mdReader.GetModuleDefinition().Mvid));
}
}
示例4: Metadata_LazyLoad
public void Metadata_LazyLoad()
{
var peStream = new MemoryStream(Misc.Members);
using (var reader = new PEReader(peStream, PEStreamOptions.LeaveOpen))
{
var md = reader.GetMetadataReader();
var method = md.GetMethodDefinition(MetadataTokens.MethodDefinitionHandle(1));
Assert.Equal("MC1", md.GetString(method.Name));
}
}
示例5: Metadata_EagerLoad
public void Metadata_EagerLoad()
{
var peStream = new MemoryStream(Misc.Members);
using (var reader = new PEReader(peStream, PEStreamOptions.LeaveOpen | PEStreamOptions.PrefetchMetadata))
{
var md = reader.GetMetadataReader();
var method = md.GetMethodDefinition(MetadataTokens.MethodDefinitionHandle(1));
Assert.Equal("MC1", md.GetString(method.Name));
Assert.Throws<InvalidOperationException>(() => reader.GetEntireImage());
Assert.Throws<InvalidOperationException>(() => reader.GetMethodBody(method.RelativeVirtualAddress));
}
}
示例6: SubStream
public void SubStream()
{
var stream = new MemoryStream();
stream.WriteByte(0xff);
stream.Write(Misc.Members, 0, Misc.Members.Length);
stream.WriteByte(0xff);
stream.WriteByte(0xff);
stream.Position = 1;
var peReader1 = new PEReader(stream, PEStreamOptions.LeaveOpen, Misc.Members.Length);
Assert.Equal(Misc.Members.Length, peReader1.GetEntireImage().Length);
peReader1.GetMetadataReader();
stream.Position = 1;
var peReader2 = new PEReader(stream, PEStreamOptions.LeaveOpen | PEStreamOptions.PrefetchMetadata, Misc.Members.Length);
Assert.Equal(Misc.Members.Length, peReader2.GetEntireImage().Length);
peReader2.GetMetadataReader();
stream.Position = 1;
var peReader3 = new PEReader(stream, PEStreamOptions.LeaveOpen | PEStreamOptions.PrefetchEntireImage, Misc.Members.Length);
Assert.Equal(Misc.Members.Length, peReader3.GetEntireImage().Length);
peReader3.GetMetadataReader();
}
示例7: 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();
}