本文整理汇总了C#中PEReader类的典型用法代码示例。如果您正苦于以下问题:C# PEReader类的具体用法?C# PEReader怎么用?C# PEReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PEReader类属于命名空间,在下文中一共展示了PEReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:28,代码来源:DebugDirectoryTests.cs
示例2: 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)?
}
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:8,代码来源:PEBuilderTests.cs
示例3: Deterministic
public void Deterministic()
{
var peStream = new MemoryStream(Misc.Deterministic);
using (var reader = new PEReader(peStream))
{
ValidateDeterministic(reader);
}
}
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:8,代码来源:DebugDirectoryTests.cs
示例4: CodeView
public void CodeView()
{
var peStream = new MemoryStream(Misc.Debug);
using (var reader = new PEReader(peStream))
{
ValidateCodeView(reader);
}
}
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:8,代码来源:DebugDirectoryTests.cs
示例5: NoDebugDirectory
public void NoDebugDirectory()
{
var peStream = new MemoryStream(Misc.Members);
using (var reader = new PEReader(peStream))
{
var entries = reader.ReadDebugDirectory();
Assert.Empty(entries);
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:9,代码来源:DebugDirectoryTests.cs
示例6: Sections
public void Sections()
{
var peHeaders = new PEReader(SynthesizedPeImages.Image1).PEHeaders;
AssertEx.Equal(new[]
{
".s1 offset=0x200 rva=0x200 size=512",
".s2 offset=0x400 rva=0x400 size=512",
".s3 offset=0x600 rva=0x600 size=512"
}, peHeaders.SectionHeaders.Select(h => $"{h.Name} offset=0x{h.PointerToRawData:x3} rva=0x{h.VirtualAddress:x3} size={h.SizeOfRawData}"));
}
开发者ID:Corillian,项目名称:corefx,代码行数:10,代码来源:PEHeadersTests.cs
示例7: 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);
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:12,代码来源:PEReaderTests.cs
示例8: GetContainingSectionIndex
public void GetContainingSectionIndex()
{
var peHeaders = new PEReader(SynthesizedPeImages.Image1).PEHeaders;
Assert.Equal(-1, peHeaders.GetContainingSectionIndex(0));
Assert.Equal(-1, peHeaders.GetContainingSectionIndex(0x200 - 1));
Assert.Equal(0, peHeaders.GetContainingSectionIndex(0x200));
Assert.Equal(1, peHeaders.GetContainingSectionIndex(0x400));
Assert.Equal(2, peHeaders.GetContainingSectionIndex(0x600));
Assert.Equal(2, peHeaders.GetContainingSectionIndex(0x600 + 9));
Assert.Equal(-1, peHeaders.GetContainingSectionIndex(0x600 + 10));
}
开发者ID:Corillian,项目名称:corefx,代码行数:12,代码来源:PEHeadersTests.cs
示例9: VerifyStrongNameSignatureDirectory
private unsafe static void VerifyStrongNameSignatureDirectory(PEReader peReader, byte[] expectedSignature)
{
var headers = peReader.PEHeaders;
int rva = headers.CorHeader.StrongNameSignatureDirectory.RelativeVirtualAddress;
int size = headers.CorHeader.StrongNameSignatureDirectory.Size;
// Even if the image is not signed we reserve space for a signature.
// Validate that the signature is in .text section.
Assert.Equal(".text", headers.SectionHeaders[headers.GetContainingSectionIndex(rva)].Name);
var signature = peReader.GetSectionData(rva).GetContent(0, size);
AssertEx.Equal(expectedSignature ?? new byte[size], signature);
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:13,代码来源:PEBuilderTests.cs
示例10: 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));
}
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:17,代码来源:PEBuilderTests.cs
示例11: 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));
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:44,代码来源:DebugDirectoryTests.cs
示例12: TryGetDirectoryOffset
public void TryGetDirectoryOffset()
{
var peHeaders = new PEReader(SynthesizedPeImages.Image1).PEHeaders;
var dir = peHeaders.PEHeader.CopyrightTableDirectory;
Assert.Equal(0x400 + 5, dir.RelativeVirtualAddress);
Assert.Equal(10, dir.Size);
int dirOffset;
Assert.True(peHeaders.TryGetDirectoryOffset(dir, out dirOffset));
Assert.Equal(0x400 + 5, dirOffset);
Assert.False(peHeaders.TryGetDirectoryOffset(new DirectoryEntry(0, 10), out dirOffset));
Assert.Equal(-1, dirOffset);
Assert.True(peHeaders.TryGetDirectoryOffset(new DirectoryEntry(0x600, 0x300), out dirOffset));
Assert.Equal(0x600, dirOffset);
Assert.False(peHeaders.TryGetDirectoryOffset(new DirectoryEntry(0x1000, 10), out dirOffset));
Assert.Equal(-1, dirOffset);
}
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:21,代码来源:PEHeadersTests.cs
示例13: Ctor
public void Ctor()
{
Assert.Throws<ArgumentNullException>(() => new PEReader(null, PEStreamOptions.Default));
var invalid = new MemoryStream(new byte[] { 1, 2, 3, 4 });
// the stream should not be disposed if the arguments are bad
Assert.Throws<ArgumentOutOfRangeException>(() => new PEReader(invalid, (PEStreamOptions)int.MaxValue));
Assert.True(invalid.CanRead);
// no BadImageFormatException if we're prefetching the entire image:
var peReader0 = new PEReader(invalid, PEStreamOptions.PrefetchEntireImage | PEStreamOptions.LeaveOpen);
Assert.True(invalid.CanRead);
Assert.Throws<BadImageFormatException>(() => peReader0.PEHeaders);
invalid.Position = 0;
// BadImageFormatException if we're prefetching the entire image and metadata:
Assert.Throws<BadImageFormatException>(() => new PEReader(invalid, PEStreamOptions.PrefetchEntireImage | PEStreamOptions.PrefetchMetadata | PEStreamOptions.LeaveOpen));
Assert.True(invalid.CanRead);
invalid.Position = 0;
// the stream should be disposed if the content is bad:
Assert.Throws<BadImageFormatException>(() => new PEReader(invalid, PEStreamOptions.PrefetchMetadata));
Assert.False(invalid.CanRead);
// the stream should not be disposed if we specified LeaveOpen flag:
invalid = new MemoryStream(new byte[] { 1, 2, 3, 4 });
Assert.Throws<BadImageFormatException>(() => new PEReader(invalid, PEStreamOptions.PrefetchMetadata | PEStreamOptions.LeaveOpen));
Assert.True(invalid.CanRead);
// valid metadata:
var valid = new MemoryStream(Misc.Members);
var peReader = new PEReader(valid, PEStreamOptions.Default);
Assert.True(valid.CanRead);
peReader.Dispose();
Assert.False(valid.CanRead);
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:37,代码来源:PEReaderTests.cs
示例14: 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));
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:11,代码来源:PEReaderTests.cs
示例15: 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));
}
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:12,代码来源:DebugDirectoryTests.cs
示例16: EntireImage_EagerLoad
public void EntireImage_EagerLoad()
{
var peStream = new MemoryStream(Misc.Members);
using (var reader = new PEReader(peStream, PEStreamOptions.LeaveOpen | PEStreamOptions.PrefetchMetadata | PEStreamOptions.PrefetchEntireImage))
{
Assert.Equal(4608, reader.GetEntireImage().Length);
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:8,代码来源:PEReaderTests.cs
示例17: EntireImage_LazyLoad
public void EntireImage_LazyLoad()
{
var peStream = new MemoryStream(Misc.Members);
using (var reader = new PEReader(peStream, PEStreamOptions.LeaveOpen))
{
Assert.Equal(4608, reader.GetEntireImage().Length);
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:8,代码来源:PEReaderTests.cs
示例18: 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));
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:13,代码来源:PEReaderTests.cs
示例19: 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();
}
开发者ID:mlacouture,项目名称:corefx,代码行数:26,代码来源:PEReaderTests.cs
示例20: GetSectionData_Errors
public void GetSectionData_Errors()
{
var peStream = new MemoryStream(Misc.Members);
using (var reader = new PEReader(peStream))
{
Assert.Throws<ArgumentNullException>(() => reader.GetSectionData(null));
Assert.Throws<ArgumentOutOfRangeException>(() => reader.GetSectionData(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => reader.GetSectionData(int.MinValue));
}
}
开发者ID:mlacouture,项目名称:corefx,代码行数:10,代码来源:PEReaderTests.cs
注:本文中的PEReader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论