本文整理汇总了C#中System.Reflection.Metadata.BlobBuilder.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.ToArray方法的具体用法?C# BlobBuilder.ToArray怎么用?C# BlobBuilder.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.ToArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Empty
public void Empty()
{
var b = new DebugDirectoryBuilder();
var id = new BlobContentId(new Guid("3C88E66E-E0B9-4508-9290-11E0DB51A1C5"), 0x12345678);
var blob = new BlobBuilder();
b.Serialize(blob, new SectionLocation(0x1000, 0x2000), 0x50);
AssertEx.Equal(new byte[0], blob.ToArray());
}
示例2: AddCodeViewEntry2
public void AddCodeViewEntry2()
{
var b = new DebugDirectoryBuilder();
var id = new BlobContentId(new Guid("3C88E66E-E0B9-4508-9290-11E0DB51A1C5"), 0x12345678);
b.AddCodeViewEntry("foo.pdb" + new string('\0', 260 - "foo.pdb".Length - 1), id, 0xABCD);
var blob = new BlobBuilder();
b.Serialize(blob, new SectionLocation(0x1000, 0x2000), 0x50);
var bytes = blob.ToArray();
AssertEx.Equal(new byte[]
{
0x00, 0x00, 0x00, 0x00, // Characteristics
0x78, 0x56, 0x34, 0x12, // Stamp
0xCD, 0xAB, 0x4D, 0x50, // Version
0x02, 0x00, 0x00, 0x00, // Type
0x1C, 0x01, 0x00, 0x00, // SizeOfData
0x6C, 0x10, 0x00, 0x00, // AddressOfRawData
0x6C, 0x20, 0x00, 0x00, // PointerToRawData
// data
(byte)'R', (byte)'S', (byte)'D', (byte)'S',
0x6E, 0xE6, 0x88, 0x3C, 0xB9, 0xE0, 0x08, 0x45, 0x92, 0x90, 0x11, 0xE0, 0xDB, 0x51, 0xA1, 0xC5, // GUID
0x01, 0x00, 0x00, 0x00, // age
(byte)'f', (byte)'o', (byte)'o', (byte)'.', (byte)'p', (byte)'d', (byte)'b', 0x00, // path
// path padding:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}, bytes);
using (var pinned = new PinnedBlob(bytes))
{
var actual = PEReader.ReadDebugDirectoryEntries(pinned.CreateReader(0, DebugDirectoryEntry.Size));
Assert.Equal(1, actual.Length);
Assert.Equal(id.Stamp, actual[0].Stamp);
Assert.Equal(0xABCD, actual[0].MajorVersion);
Assert.Equal(0x504d, actual[0].MinorVersion);
Assert.Equal(DebugDirectoryEntryType.CodeView, actual[0].Type);
Assert.Equal(0x0000011c, actual[0].DataSize);
Assert.Equal(0x0000106c, actual[0].DataRelativeVirtualAddress);
Assert.Equal(0x0000206c, actual[0].DataPointer);
}
}
示例3: BuildPEWithDebugDirectory
public static byte[] BuildPEWithDebugDirectory(DebugDirectoryBuilder debugDirectoryBuilder)
{
var peStream = new MemoryStream();
var ilBuilder = new BlobBuilder();
var metadataBuilder = new MetadataBuilder();
var peBuilder = new ManagedPEBuilder(
PEHeaderBuilder.CreateLibraryHeader(),
new MetadataRootBuilder(metadataBuilder),
ilBuilder,
debugDirectoryBuilder: debugDirectoryBuilder);
var peImageBuilder = new BlobBuilder();
peBuilder.Serialize(peImageBuilder);
return peImageBuilder.ToArray();
}
示例4: MultipleEntries
public void MultipleEntries()
{
var b = new DebugDirectoryBuilder();
var id = new BlobContentId(new Guid("3C88E66E-E0B9-4508-9290-11E0DB51A1C5"), 0x12345678);
b.AddReproducibleEntry();
b.AddCodeViewEntry("x", id, 0);
b.AddReproducibleEntry();
b.AddCodeViewEntry("y", id, 0xABCD);
var blob = new BlobBuilder();
b.Serialize(blob, new SectionLocation(0x1000, 0x2000), 0x50);
AssertEx.Equal(new byte[]
{
0x00, 0x00, 0x00, 0x00, // Characteristics
0x00, 0x00, 0x00, 0x00, // Stamp
0x00, 0x00, 0x00, 0x00, // Version
0x10, 0x00, 0x00, 0x00, // Type
0x00, 0x00, 0x00, 0x00, // SizeOfData
0x00, 0x00, 0x00, 0x00, // AddressOfRawData
0x00, 0x00, 0x00, 0x00, // PointerToRawData
0x00, 0x00, 0x00, 0x00, // Characteristics
0x78, 0x56, 0x34, 0x12, // Stamp
0x00, 0x00, 0x00, 0x00, // Version
0x02, 0x00, 0x00, 0x00, // Type
0x1A, 0x00, 0x00, 0x00, // SizeOfData
0xC0, 0x10, 0x00, 0x00, // AddressOfRawData
0xC0, 0x20, 0x00, 0x00, // PointerToRawData
0x00, 0x00, 0x00, 0x00, // Characteristics
0x00, 0x00, 0x00, 0x00, // Stamp
0x00, 0x00, 0x00, 0x00, // Version
0x10, 0x00, 0x00, 0x00, // Type
0x00, 0x00, 0x00, 0x00, // SizeOfData
0x00, 0x00, 0x00, 0x00, // AddressOfRawData
0x00, 0x00, 0x00, 0x00, // PointerToRawData
0x00, 0x00, 0x00, 0x00, // Characteristics
0x78, 0x56, 0x34, 0x12, // Stamp
0xCD, 0xAB, 0x4D, 0x50, // Version
0x02, 0x00, 0x00, 0x00, // Type
0x1A, 0x00, 0x00, 0x00, // SizeOfData
0xDA, 0x10, 0x00, 0x00, // AddressOfRawData
0xDA, 0x20, 0x00, 0x00, // PointerToRawData
// data
(byte)'R', (byte)'S', (byte)'D', (byte)'S',
0x6E, 0xE6, 0x88, 0x3C, 0xB9, 0xE0, 0x08, 0x45, 0x92, 0x90, 0x11, 0xE0, 0xDB, 0x51, 0xA1, 0xC5, // GUID
0x01, 0x00, 0x00, 0x00, // age
(byte)'x', 0x00, // path
// data
(byte)'R', (byte)'S', (byte)'D', (byte)'S',
0x6E, 0xE6, 0x88, 0x3C, 0xB9, 0xE0, 0x08, 0x45, 0x92, 0x90, 0x11, 0xE0, 0xDB, 0x51, 0xA1, 0xC5, // GUID
0x01, 0x00, 0x00, 0x00, // age
(byte)'y', 0x00, // path
}, blob.ToArray());
}
示例5: AddReproducibleEntry
public void AddReproducibleEntry()
{
var b = new DebugDirectoryBuilder();
b.AddReproducibleEntry();
var blob = new BlobBuilder();
b.Serialize(blob, new SectionLocation(0x1000, 0x2000), 0x50);
var bytes = blob.ToArray();
AssertEx.Equal(new byte[]
{
0x00, 0x00, 0x00, 0x00, // Characteristics
0x00, 0x00, 0x00, 0x00, // Stamp
0x00, 0x00, 0x00, 0x00, // Version
0x10, 0x00, 0x00, 0x00, // Type
0x00, 0x00, 0x00, 0x00, // SizeOfData
0x00, 0x00, 0x00, 0x00, // AddressOfRawData
0x00, 0x00, 0x00, 0x00, // PointerToRawData
}, bytes);
using (var pinned = new PinnedBlob(bytes))
{
var actual = PEReader.ReadDebugDirectoryEntries(pinned.CreateReader(0, DebugDirectoryEntry.Size));
Assert.Equal(1, actual.Length);
Assert.Equal(0u, actual[0].Stamp);
Assert.Equal(0, actual[0].MajorVersion);
Assert.Equal(0, actual[0].MinorVersion);
Assert.Equal(DebugDirectoryEntryType.Reproducible, actual[0].Type);
Assert.Equal(0, actual[0].DataSize);
Assert.Equal(0, actual[0].DataRelativeVirtualAddress);
Assert.Equal(0, actual[0].DataPointer);
}
}