本文整理汇总了C#中System.Reflection.PortableExecutable.PEHeaders类的典型用法代码示例。如果您正苦于以下问题:C# PEHeaders类的具体用法?C# PEHeaders怎么用?C# PEHeaders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PEHeaders类属于System.Reflection.PortableExecutable命名空间,在下文中一共展示了PEHeaders类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetMetadataReader
internal static unsafe MetadataReader GetMetadataReader(byte[] peImage, out int metadataStartOffset, bool isModule = false, MetadataReaderOptions options = MetadataReaderOptions.Default, MetadataStringDecoder decoder = null)
{
GCHandle pinned = GetPinnedPEImage(peImage);
var headers = new PEHeaders(new MemoryStream(peImage));
metadataStartOffset = headers.MetadataStartOffset;
return new MetadataReader((byte*)pinned.AddrOfPinnedObject() + headers.MetadataStartOffset, headers.MetadataSize, options, decoder);
}
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:7,代码来源:MetadataReaderTests.cs
示例2: ToXml
public unsafe static void ToXml(TextWriter xmlWriter, Stream pdbStream, Stream peStream, PdbToXmlOptions options = PdbToXmlOptions.Default, string methodName = null)
{
IEnumerable<MethodHandle> methodHandles;
var headers = new PEHeaders(peStream);
byte[] metadata = new byte[headers.MetadataSize];
peStream.Seek(headers.MetadataStartOffset, SeekOrigin.Begin);
peStream.Read(metadata, 0, headers.MetadataSize);
fixed (byte* metadataPtr = metadata)
{
var metadataReader = new MetadataReader((IntPtr)metadataPtr, metadata.Length);
if (string.IsNullOrEmpty(methodName))
{
methodHandles = metadataReader.MethodDefinitions;
}
else
{
methodHandles = metadataReader.MethodDefinitions.
Where(methodHandle => GetQualifiedMethodName(metadataReader, methodHandle) == methodName);
}
ToXml(xmlWriter, pdbStream, metadataReader, options, methodHandles);
}
}
开发者ID:riversky,项目名称:roslyn,代码行数:25,代码来源:PdbToXml.cs
示例3: CreateFromMetadata_Module
public unsafe void CreateFromMetadata_Module()
{
var netModule = TestResources.MetadataTests.NetModule01.ModuleCS00;
PEHeaders h = new PEHeaders(new MemoryStream(netModule));
fixed (byte* ptr = &netModule[h.MetadataStartOffset])
{
ModuleMetadata.CreateFromMetadata((IntPtr)ptr, h.MetadataSize);
}
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:ModuleMetadataTests.cs
示例4: CreateFromMetadata_Assembly
public unsafe void CreateFromMetadata_Assembly()
{
var assembly = TestResources.MetadataTests.Basic.Members;
PEHeaders h = new PEHeaders(new MemoryStream(assembly));
fixed (byte* ptr = &assembly[h.MetadataStartOffset])
{
var metadata = ModuleMetadata.CreateFromMetadata((IntPtr)ptr, h.MetadataSize);
Assert.Equal(new AssemblyIdentity("Members"), metadata.Module.ReadAssemblyIdentityOrThrow());
}
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:11,代码来源:ModuleMetadataTests.cs
示例5: GetMetadataReader
internal static unsafe MetadataReader GetMetadataReader(byte[] peImage, out int metadataStartOffset, bool isModule = false, MetadataStringDecoder decoder = null)
{
GCHandle pinned;
if (!peImages.TryGetValue(peImage, out pinned))
{
peImages.Add(peImage, pinned = GCHandle.Alloc(peImage, GCHandleType.Pinned));
}
var headers = new PEHeaders(new MemoryStream(peImage));
metadataStartOffset = headers.MetadataStartOffset;
return new MetadataReader((byte*)pinned.AddrOfPinnedObject() + headers.MetadataStartOffset, headers.MetadataSize, MetadataReaderOptions.Default, decoder);
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:11,代码来源:MetadataReaderTests.cs
示例6: ToXml
public unsafe static void ToXml(TextWriter xmlWriter, Stream pdbStream, Stream peStream, PdbToXmlOptions options = PdbToXmlOptions.Default, string methodName = null)
{
IEnumerable<MethodHandle> methodHandles;
var headers = new PEHeaders(peStream);
byte[] metadata = new byte[headers.MetadataSize];
peStream.Seek(headers.MetadataStartOffset, SeekOrigin.Begin);
peStream.Read(metadata, 0, headers.MetadataSize);
fixed (byte* metadataPtr = metadata)
{
var metadataReader = new MetadataReader((IntPtr)metadataPtr, metadata.Length);
if (string.IsNullOrEmpty(methodName))
{
methodHandles = metadataReader.MethodDefinitions;
}
else
{
var matching = metadataReader.MethodDefinitions.
Where(methodHandle => GetQualifiedMethodName(metadataReader, methodHandle) == methodName).ToArray();
if (matching.Length == 0)
{
xmlWriter.WriteLine("<error>");
xmlWriter.WriteLine(string.Format("<message>No method '{0}' found in metadata.</message>", methodName));
xmlWriter.WriteLine("<available-methods>");
foreach (var methodHandle in metadataReader.MethodDefinitions)
{
xmlWriter.Write("<method><![CDATA[");
xmlWriter.Write(GetQualifiedMethodName(metadataReader, methodHandle));
xmlWriter.Write("]]></method>");
xmlWriter.WriteLine();
}
xmlWriter.WriteLine("</available-methods>");
xmlWriter.WriteLine("</error>");
return;
}
methodHandles = matching;
}
ToXml(xmlWriter, pdbStream, metadataReader, options, methodHandles);
}
}
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:47,代码来源:PdbToXml.cs
示例7: CheckCOFFAndPEOptionalHeaders32Exe
public void CheckCOFFAndPEOptionalHeaders32Exe()
{
string source = @"
class C
{
public static void Main()
{
}
}";
var compilation = CreateCompilationWithMscorlib(source,
compOptions: TestOptions.Exe.WithPlatform(Platform.AnyCpu));
var peHeaders = new PEHeaders(compilation.EmitToStream());
//interesting COFF bits
Assert.False(peHeaders.Requires64Bits());
Assert.True(peHeaders.IsExe);
Assert.False(peHeaders.IsDll);
//interesting Optional PE header bits
//We will use a range beginning with 0x30 to identify the Roslyn compiler family.
Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion);
Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion);
Assert.Equal(0x00400000ul, peHeaders.PEHeader.ImageBase);
Assert.Equal(0x00000200, peHeaders.PEHeader.FileAlignment);
Assert.True(peHeaders.IsConsoleApplication); //should change if this is a windows app.
Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE
Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfStackReserve);
Assert.Equal(0x1000u, peHeaders.PEHeader.SizeOfStackCommit);
Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfHeapReserve);
Assert.Equal(0x1000u, peHeaders.PEHeader.SizeOfHeapCommit);
//The following ensure that the runtime startup stub was emitted. It is not needed on modern operating systems.
Assert.NotEqual(0, peHeaders.PEHeader.ImportAddressTableDirectory.RelativeVirtualAddress);
Assert.NotEqual(0, peHeaders.PEHeader.ImportAddressTableDirectory.Size);
Assert.NotEqual(0, peHeaders.PEHeader.ImportTableDirectory.RelativeVirtualAddress);
Assert.NotEqual(0, peHeaders.PEHeader.ImportTableDirectory.Size);
Assert.NotEqual(0, peHeaders.PEHeader.BaseRelocationTableDirectory.RelativeVirtualAddress);
Assert.NotEqual(0, peHeaders.PEHeader.BaseRelocationTableDirectory.Size);
}
开发者ID:riversky,项目名称:roslyn,代码行数:39,代码来源:CompilationEmitTests.cs
示例8: CheckCOFFAndPEOptionalHeadersARM
public void CheckCOFFAndPEOptionalHeadersARM()
{
string source = @"
class C
{
public static void Main()
{
}
}";
var compilation = CreateCompilationWithMscorlib(source,
compOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.Arm));
var peHeaders = new PEHeaders(compilation.EmitToStream());
//interesting COFF bits
Assert.False(peHeaders.Requires64Bits());
Assert.True(peHeaders.IsDll);
Assert.False(peHeaders.IsExe);
//interesting Optional PE header bits
//We will use a range beginning with 0x30 to identify the Roslyn compiler family.
Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion);
Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion);
// the default value is the same as the 32 bit default value
Assert.Equal(0x10000000u, peHeaders.PEHeader.ImageBase);
Assert.Equal(0x200, peHeaders.PEHeader.FileAlignment);
Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE
Assert.Equal(0x01c4, (ushort)peHeaders.CoffHeader.Machine);
Assert.Equal(6, peHeaders.PEHeader.MajorSubsystemVersion); //Arm targets only run on 6.2 and above
Assert.Equal(2, peHeaders.PEHeader.MinorSubsystemVersion);
//The following ensure that the runtime startup stub was not emitted. It is not needed on modern operating systems.
Assert.Equal(0, peHeaders.PEHeader.ImportAddressTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeaders.PEHeader.ImportAddressTableDirectory.Size);
Assert.Equal(0, peHeaders.PEHeader.ImportTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeaders.PEHeader.ImportTableDirectory.Size);
Assert.Equal(0, peHeaders.PEHeader.BaseRelocationTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeaders.PEHeader.BaseRelocationTableDirectory.Size);
}
开发者ID:riversky,项目名称:roslyn,代码行数:37,代码来源:CompilationEmitTests.cs
示例9: CheckCOFFAndPEOptionalHeaders64
public void CheckCOFFAndPEOptionalHeaders64()
{
string source = @"
class C
{
public static void Main()
{
}
}";
var compilation = CreateCompilationWithMscorlib(source,
compOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.X64));
var peHeaders = new PEHeaders(compilation.EmitToStream());
//interesting COFF bits
Assert.True(peHeaders.Requires64Bits());
Assert.True(peHeaders.IsDll);
Assert.False(peHeaders.IsExe);
//interesting Optional PE header bits
//We will use a range beginning with 0x30 to identify the Roslyn compiler family.
Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion);
Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion);
// the default value is the same as the 32 bit default value
Assert.Equal(0x0000000180000000u, peHeaders.PEHeader.ImageBase);
Assert.Equal(0x00000200, peHeaders.PEHeader.FileAlignment); //doesn't change based on architecture.
Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE
//Verify additional items
Assert.Equal(0x00400000u, peHeaders.PEHeader.SizeOfStackReserve);
Assert.Equal(0x4000u, peHeaders.PEHeader.SizeOfStackCommit);
Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfHeapReserve);
Assert.Equal(0x2000u, peHeaders.PEHeader.SizeOfHeapCommit);
Assert.Equal(0x8664, (ushort)peHeaders.CoffHeader.Machine); //AMD64 (K8)
//default for non-arm, non-appcontainer outputs. EDMAURER: This is an intentional change from Dev11.
//Should we find that it is too disruptive. We will consider rolling back.
//It turns out to be too disruptive. Rolling back to 4.0
Assert.Equal(4, peHeaders.PEHeader.MajorSubsystemVersion);
Assert.Equal(0, peHeaders.PEHeader.MinorSubsystemVersion);
//The following ensure that the runtime startup stub was not emitted. It is not needed on modern operating systems.
Assert.Equal(0, peHeaders.PEHeader.ImportAddressTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeaders.PEHeader.ImportAddressTableDirectory.Size);
Assert.Equal(0, peHeaders.PEHeader.ImportTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeaders.PEHeader.ImportTableDirectory.Size);
Assert.Equal(0, peHeaders.PEHeader.BaseRelocationTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeaders.PEHeader.BaseRelocationTableDirectory.Size);
}
开发者ID:riversky,项目名称:roslyn,代码行数:47,代码来源:CompilationEmitTests.cs
示例10: CheckCOFFAndPEOptionalHeaders32
public void CheckCOFFAndPEOptionalHeaders32()
{
string source = @"
class C
{
public static void Main()
{
}
}";
var compilation = CreateCompilationWithMscorlib(source,
compOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
var peHeaders = new PEHeaders(compilation.EmitToStream());
//interesting COFF bits
Assert.False(peHeaders.Requires64Bits());
Assert.True(peHeaders.IsDll);
Assert.False(peHeaders.IsExe);
//interesting Optional PE header bits
//We will use a range beginning with 0x30 to identify the Roslyn compiler family.
Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion);
Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion);
Assert.Equal(0x10000000u, peHeaders.PEHeader.ImageBase);
Assert.Equal(0x200, peHeaders.PEHeader.FileAlignment);
Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE
//Verify additional items
Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfStackReserve);
Assert.Equal(0x1000u, peHeaders.PEHeader.SizeOfStackCommit);
Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfHeapReserve);
Assert.Equal(0x1000u, peHeaders.PEHeader.SizeOfHeapCommit);
}
开发者ID:riversky,项目名称:roslyn,代码行数:31,代码来源:CompilationEmitTests.cs
示例11: CheckCorflags
public void CheckCorflags()
{
string source = @"
class C
{
public static void Main()
{
}
}";
PEHeaders peHeaders;
var compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.AnyCpu));
peHeaders = new PEHeaders(compilation.EmitToStream());
Assert.Equal(CorFlags.ILOnly, peHeaders.CorHeader.Flags);
compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.X86));
peHeaders = new PEHeaders(compilation.EmitToStream());
Assert.Equal(CorFlags.ILOnly | CorFlags.Requires32Bit, peHeaders.CorHeader.Flags);
compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.X64));
peHeaders = new PEHeaders(compilation.EmitToStream());
Assert.Equal(CorFlags.ILOnly, peHeaders.CorHeader.Flags);
Assert.True(peHeaders.Requires64Bits());
Assert.True(peHeaders.RequiresAmdInstructionSet());
compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.AnyCpu32BitPreferred));
peHeaders = new PEHeaders(compilation.EmitToStream());
Assert.False(peHeaders.Requires64Bits());
Assert.False(peHeaders.RequiresAmdInstructionSet());
Assert.Equal(CorFlags.ILOnly | CorFlags.Requires32Bit | CorFlags.Prefers32Bit, peHeaders.CorHeader.Flags);
compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.Arm));
peHeaders = new PEHeaders(compilation.EmitToStream());
Assert.False(peHeaders.Requires64Bits());
Assert.False(peHeaders.RequiresAmdInstructionSet());
Assert.Equal(CorFlags.ILOnly, peHeaders.CorHeader.Flags);
}
开发者ID:riversky,项目名称:roslyn,代码行数:37,代码来源:CompilationEmitTests.cs
示例12: ReadMetadata
public byte[] ReadMetadata(string fileName)
{
using (var stream = File.OpenRead(fileName))
{
var peHeader = new PEHeaders(stream);
var metadata = new byte[peHeader.MetadataSize];
stream.Position = peHeader.MetadataStartOffset;
stream.Read(metadata, 0, peHeader.MetadataSize);
return metadata;
}
}
开发者ID:RainsSoft,项目名称:SharpLang,代码行数:13,代码来源:Compiler.cs
示例13: PEHeaders2
public void PEHeaders2()
{
var options = EmitOptions.Default.
WithFileAlignment(512).
WithBaseAddress(0x123456789ABCDEF).
WithHighEntropyVirtualAddressSpace(true).
WithSubsystemVersion(SubsystemVersion.WindowsXP);
var syntax = SyntaxFactory.ParseSyntaxTree(@"class C { static void Main() { } }", TestOptions.Regular);
var peStream = CreateCompilationWithMscorlib(
syntax,
options: TestOptions.DebugExe.WithPlatform(Platform.X64).WithDeterministic(true),
assemblyName: "B37A4FCD-ED76-4924-A2AD-298836056E00").EmitToStream(options);
peStream.Position = 0;
var peHeaders = new PEHeaders(peStream);
var peHeader = peHeaders.PEHeader;
var coffHeader = peHeaders.CoffHeader;
var corHeader = peHeaders.CorHeader;
Assert.Equal(PEMagic.PE32Plus, peHeader.Magic);
Assert.Equal(0x00000000, peHeader.AddressOfEntryPoint);
Assert.Equal(0x00002000, peHeader.BaseOfCode);
Assert.Equal(0x00000000, peHeader.BaseOfData);
Assert.Equal(0x00000200, peHeader.SizeOfHeaders);
Assert.Equal(0x00000400, peHeader.SizeOfCode);
Assert.Equal(0x00002000u, peHeader.SizeOfHeapCommit);
Assert.Equal(0x00100000u, peHeader.SizeOfHeapReserve);
Assert.Equal(0x00004000, peHeader.SizeOfImage);
Assert.Equal(0x00000000, peHeader.SizeOfInitializedData);
Assert.Equal(0x00004000u, peHeader.SizeOfStackCommit);
Assert.Equal(0x0400000u, peHeader.SizeOfStackReserve);
Assert.Equal(0, peHeader.SizeOfUninitializedData);
Assert.Equal(Subsystem.WindowsCui, peHeader.Subsystem);
Assert.Equal(0u, peHeader.CheckSum);
Assert.Equal(0x200, peHeader.FileAlignment);
Assert.Equal(0x0123456789ac0000u, peHeader.ImageBase);
Assert.Equal(0x2000, peHeader.SectionAlignment);
Assert.Equal(0, peHeader.MajorImageVersion);
Assert.Equal(0, peHeader.MinorImageVersion);
Assert.Equal(0x30, peHeader.MajorLinkerVersion);
Assert.Equal(0, peHeader.MinorLinkerVersion);
Assert.Equal(4, peHeader.MajorOperatingSystemVersion);
Assert.Equal(0, peHeader.MinorOperatingSystemVersion);
Assert.Equal(5, peHeader.MajorSubsystemVersion);
Assert.Equal(1, peHeader.MinorSubsystemVersion);
Assert.Equal(16, peHeader.NumberOfRvaAndSizes);
Assert.Equal(0x200, peHeader.SizeOfHeaders);
Assert.Equal(0, peHeader.BaseRelocationTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.BaseRelocationTableDirectory.Size);
Assert.Equal(0, peHeader.BoundImportTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.BoundImportTableDirectory.Size);
Assert.Equal(0, peHeader.CertificateTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.CertificateTableDirectory.Size);
Assert.Equal(0, peHeader.CopyrightTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.CopyrightTableDirectory.Size);
Assert.Equal(0x2000, peHeader.CorHeaderTableDirectory.RelativeVirtualAddress);
Assert.Equal(0x48, peHeader.CorHeaderTableDirectory.Size);
Assert.Equal(0x2324, peHeader.DebugTableDirectory.RelativeVirtualAddress);
Assert.Equal(0x1C, peHeader.DebugTableDirectory.Size);
Assert.Equal(0, peHeader.ExceptionTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.ExceptionTableDirectory.Size);
Assert.Equal(0, peHeader.ExportTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.ExportTableDirectory.Size);
Assert.Equal(0, peHeader.ImportAddressTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.ImportAddressTableDirectory.Size);
Assert.Equal(0, peHeader.ImportTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.ImportTableDirectory.Size);
Assert.Equal(0, peHeader.LoadConfigTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.LoadConfigTableDirectory.Size);
Assert.Equal(0, peHeader.ResourceTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.ResourceTableDirectory.Size);
Assert.Equal(0, peHeader.ThreadLocalStorageTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, peHeader.ThreadLocalStorageTableDirectory.Size);
Assert.Equal(Characteristics.LargeAddressAware | Characteristics.ExecutableImage, coffHeader.Characteristics);
Assert.Equal(Machine.Amd64, coffHeader.Machine);
Assert.Equal(1, coffHeader.NumberOfSections);
Assert.Equal(0, coffHeader.NumberOfSymbols);
Assert.Equal(0, coffHeader.PointerToSymbolTable);
Assert.Equal(240, coffHeader.SizeOfOptionalHeader);
Assert.Equal(-862605524, coffHeader.TimeDateStamp);
Assert.Equal(0x06000001, corHeader.EntryPointTokenOrRelativeVirtualAddress);
Assert.Equal(CorFlags.ILOnly, corHeader.Flags);
Assert.Equal(2, corHeader.MajorRuntimeVersion);
Assert.Equal(5, corHeader.MinorRuntimeVersion);
Assert.Equal(0, corHeader.CodeManagerTableDirectory.RelativeVirtualAddress);
Assert.Equal(0, corHeader.CodeManagerTableDirectory.Size);
Assert.Equal(0, corHeader.ExportAddressTableJumpsDirectory.RelativeVirtualAddress);
Assert.Equal(0, corHeader.ExportAddressTableJumpsDirectory.Size);
Assert.Equal(0, corHeader.ManagedNativeHeaderDirectory.RelativeVirtualAddress);
Assert.Equal(0, corHeader.ManagedNativeHeaderDirectory.Size);
Assert.Equal(0x2054, corHeader.MetadataDirectory.RelativeVirtualAddress);
Assert.Equal(0x02d0, corHeader.MetadataDirectory.Size);
Assert.Equal(0, corHeader.ResourcesDirectory.RelativeVirtualAddress);
//.........这里部分代码省略.........
开发者ID:rgani,项目名称:roslyn,代码行数:101,代码来源:EmitMetadata.cs
示例14: CheckFileAlignment
public void CheckFileAlignment()
{
string source = @"
class C
{
public static void Main()
{
}
}";
var compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithFileAlignment(1024));
var peHeaders = new PEHeaders(compilation.EmitToStream());
Assert.Equal(1024, peHeaders.PEHeader.FileAlignment);
}
开发者ID:riversky,项目名称:roslyn,代码行数:13,代码来源:CompilationEmitTests.cs
示例15: CheckDllCharacteristicsWinRtApp
public void CheckDllCharacteristicsWinRtApp()
{
string source = @"
class C
{
public static void Main()
{
}
}";
var compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.WinRtExe);
var peHeaders = new PEHeaders(compilation.EmitToStream());
//interesting COFF bits
Assert.Equal(0x9540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE | IMAGE_DLLCHARACTERISTICS_APPCONTAINER (0x1000)
}
开发者ID:riversky,项目名称:roslyn,代码行数:15,代码来源:CompilationEmitTests.cs
示例16: PointerAndLength
public unsafe void PointerAndLength()
{
GCHandle pinned = GetPinnedPEImage(NetModule.AppCS);
var headers = new PEHeaders(new MemoryStream(NetModule.AppCS));
byte* ptr = (byte*)pinned.AddrOfPinnedObject() + headers.MetadataStartOffset;
var reader = new MetadataReader(ptr, headers.MetadataSize);
Assert.True(ptr == reader.MetadataPointer);
Assert.Equal(headers.MetadataSize, reader.MetadataLength);
}
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:10,代码来源:MetadataReaderTests.cs
示例17: GetStorageInfoFromTemporaryStorage
private void GetStorageInfoFromTemporaryStorage(FileKey moduleFileKey, out ITemporaryStreamStorage storage, out Stream stream, out IntPtr pImage)
{
int size;
using (var copyStream = SerializableBytes.CreateWritableStream())
{
// open a file and let it go as soon as possible
using (var fileStream = FileUtilities.OpenRead(moduleFileKey.FullPath))
{
var headers = new PEHeaders(fileStream);
var offset = headers.MetadataStartOffset;
size = headers.MetadataSize;
// given metadata contains no metadata info.
// throw bad image format exception so that we can show right diagnostic to user.
if (size <= 0)
{
throw new BadImageFormatException();
}
StreamCopy(fileStream, copyStream, offset, size);
}
// copy over the data to temp storage and let pooled stream go
storage = _temporaryStorageService.CreateTemporaryStreamStorage(CancellationToken.None);
copyStream.Position = 0;
storage.WriteStream(copyStream);
}
// get stream that owns direct access memory
stream = storage.ReadStream(CancellationToken.None);
// stream size must be same as what metadata reader said the size should be.
Contract.ThrowIfFalse(stream.Length == size);
// under VS host, direct access should be supported
var directAccess = (ISupportDirectMemoryAccess)stream;
pImage = directAccess.GetPointer();
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:40,代码来源:VisualStudioMetadataReferenceManager.cs
示例18: EmittedSubsystemVersion
public void EmittedSubsystemVersion()
{
var compilation = CSharpCompilation.Create("a.dll", options: TestOptions.Dll.WithSubsystemVersion(SubsystemVersion.Create(5, 1)));
var peHeaders = new PEHeaders(compilation.EmitToStream());
Assert.Equal(5, peHeaders.PEHeader.MajorSubsystemVersion);
Assert.Equal(1, peHeaders.PEHeader.MinorSubsystemVersion);
}
开发者ID:nagyist,项目名称:roslyn,代码行数:7,代码来源:CommandLineTests.cs
示例19: CheckCOFFAndPEOptionalHeaders64Exe
public void CheckCOFFAndPEOptionalHeaders64Exe()
{
string source = @"
class C
{
public static void Main()
{
}
}";
var compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.X64));
var peHeaders = new PEHeaders(compilation.EmitToStream());
//interesting COFF bits
Assert.True(peHeaders.Requires64Bits());
Assert.True(peHeaders.IsExe);
Assert.False(peHeaders.IsDll);
//interesting Optional PE header bits
//We will use a range beginning with 0x30 to identify the Roslyn compiler family.
Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion);
Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion);
Assert.Equal(0x0000000140000000ul, peHeaders.PEHeader.ImageBase);
Assert.Equal(0x200, peHeaders.PEHeader.FileAlignment); //doesn't change based on architecture
Assert.True(peHeaders.IsConsoleApplication); //should change if this is a windows app.
Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE
Assert.Equal(0x00400000u, peHeaders.PEHeader.SizeOfStackReserve);
Assert.Equal(0x4000u, peHeaders.PEHeader.SizeOfStackCommit);
Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfHeapReserve); //no sure why we don't bump this up relative to 32bit as well.
Assert.Equal(0x2000u, peHeaders.PEHeader.SizeOfHeapCommit);
}
开发者ID:riversky,项目名称:roslyn,代码行数:29,代码来源:CompilationEmitTests.cs
示例20: CheckDllCharacteristicsHighEntropyVA
public void CheckDllCharacteristicsHighEntropyVA()
{
string source = @"
class C
{
public static void Main()
{
}
}";
var compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithHighEntropyVirtualAddressSpace(true));
var peHeaders = new PEHeaders(compilation.EmitToStream());
//interesting COFF bits
Assert.Equal(0x8560u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE | HIGH_ENTROPY_VA (0x20)
}
开发者ID:riversky,项目名称:roslyn,代码行数:15,代码来源:CompilationEmitTests.cs
注:本文中的System.Reflection.PortableExecutable.PEHeaders类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论