本文整理汇总了C#中System.Reflection.Metadata.BlobBuilder类的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder类的具体用法?C# BlobBuilder怎么用?C# BlobBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlobBuilder类属于System.Reflection.Metadata命名空间,在下文中一共展示了BlobBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WritePEImage
private static void WritePEImage(
Stream peStream,
MetadataBuilder metadataBuilder,
BlobBuilder ilBuilder,
MethodDefinitionHandle entryPointHandle,
Blob mvidFixup = default(Blob),
byte[] privateKeyOpt = null)
{
var peBuilder = new ManagedPEBuilder(
entryPointHandle.IsNil ? PEHeaderBuilder.CreateLibraryHeader() : PEHeaderBuilder.CreateExecutableHeader(),
new MetadataRootBuilder(metadataBuilder),
ilBuilder,
entryPoint: entryPointHandle,
flags: CorFlags.ILOnly | (privateKeyOpt != null ? CorFlags.StrongNameSigned : 0),
deterministicIdProvider: content => s_contentId);
var peBlob = new BlobBuilder();
var contentId = peBuilder.Serialize(peBlob);
if (!mvidFixup.IsDefault)
{
new BlobWriter(mvidFixup).WriteGuid(contentId.Guid);
}
if (privateKeyOpt != null)
{
peBuilder.Sign(peBlob, content => SigningUtilities.CalculateRsaSignature(content, privateKeyOpt));
}
peBlob.WriteContentTo(peStream);
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:32,代码来源:PEBuilderTests.cs
示例2: 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());
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:9,代码来源:DebugDirectoryBuilderTests.cs
示例3: SerializedSection
public SerializedSection(BlobBuilder builder, string name, SectionCharacteristics characteristics, int relativeVirtualAddress, int sizeOfRawData, int pointerToRawData)
{
Name = name;
Characteristics = characteristics;
Builder = builder;
RelativeVirtualAddress = relativeVirtualAddress;
SizeOfRawData = sizeOfRawData;
PointerToRawData = pointerToRawData;
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:9,代码来源:PEBuilder.cs
示例4: 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);
}
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:56,代码来源:DebugDirectoryBuilderTests.cs
示例5: AddEmbeddedPortablePdbEntry_Args
public void AddEmbeddedPortablePdbEntry_Args()
{
var bb = new BlobBuilder();
var builder = new DebugDirectoryBuilder();
Assert.Throws<ArgumentNullException>(() => builder.AddEmbeddedPortablePdbEntry(null, 0x0100));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.AddEmbeddedPortablePdbEntry(bb, 0x0000));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.AddEmbeddedPortablePdbEntry(bb, 0x00ff));
builder.AddEmbeddedPortablePdbEntry(bb, 0x0100);
builder.AddEmbeddedPortablePdbEntry(bb, 0xffff);
}
开发者ID:Corillian,项目名称:corefx,代码行数:11,代码来源:DebugDirectoryBuilderTests.cs
示例6: SerializeMetadata
public void SerializeMetadata(BlobBuilder builder, Func<BlobBuilder, ContentId> idProvider, out ContentId contentId)
{
SerializeMetadataImpl(builder, methodBodyStreamRva: 0, mappedFieldDataStreamRva: 0);
contentId = idProvider(builder);
// fill in the id:
var idWriter = new BlobWriter(_pdbIdBlob);
idWriter.WriteBytes(contentId.Guid);
idWriter.WriteBytes(contentId.Stamp);
Debug.Assert(idWriter.RemainingBytes == 0);
}
开发者ID:nbilling,项目名称:corefx,代码行数:12,代码来源:MetadataSerializer.cs
示例7: MethodBodyEncoder
internal MethodBodyEncoder(
BlobBuilder builder,
ushort maxStack,
int exceptionRegionCount,
StandaloneSignatureHandle localVariablesSignature,
MethodBodyAttributes attributes)
{
Builder = builder;
_maxStack = maxStack;
_localVariablesSignature = localVariablesSignature;
_attributes = (byte)attributes;
_exceptionRegionCount = exceptionRegionCount;
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:13,代码来源:MethodBodyEncoder.cs
示例8: BasicValidation
public void BasicValidation()
{
using (var peStream = new MemoryStream())
{
var ilBuilder = new BlobBuilder();
var metadataBuilder = new MetadataBuilder();
var entryPoint = BasicValidationEmit(metadataBuilder, ilBuilder);
WritePEImage(peStream, metadataBuilder, ilBuilder, entryPoint);
peStream.Position = 0;
VerifyPE(peStream);
}
}
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:13,代码来源:PEBuilderTests.cs
示例9: AddEmbeddedPortablePdbEntry
public void AddEmbeddedPortablePdbEntry(BlobBuilder debugMetadata, ushort portablePdbVersion)
{
if (debugMetadata == null)
{
Throw.ArgumentNull(nameof(debugMetadata));
}
int dataSize = WriteEmbeddedPortablePdbData(_dataBuilder, debugMetadata);
AddEntry(
type: DebugDirectoryEntryType.EmbeddedPortablePdb,
version: PortablePdbVersions.DebugDirectoryEmbeddedVersion(portablePdbVersion),
stamp: 0,
dataSize: dataSize);
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:15,代码来源:DebugDirectoryBuilder.cs
示例10: SerializeStandalonePdbStream
/// <summary>
/// Serialized #Pdb stream.
/// </summary>
protected override void SerializeStandalonePdbStream(BlobBuilder builder)
{
int startPosition = builder.Position;
// the id will be filled in later
_pdbIdBlob = builder.ReserveBytes(MetadataSizes.PdbIdSize);
builder.WriteInt32(_entryPoint.IsNil ? 0 : MetadataTokens.GetToken(_entryPoint));
builder.WriteUInt64(MetadataSizes.ExternalTablesMask);
MetadataWriterUtilities.SerializeRowCounts(builder, MetadataSizes.ExternalRowCounts);
int endPosition = builder.Position;
Debug.Assert(MetadataSizes.CalculateStandalonePdbStreamSize() == endPosition - startPosition);
}
开发者ID:nbilling,项目名称:corefx,代码行数:18,代码来源:MetadataSerializer.cs
示例11: WritePEImage
private static void WritePEImage(Stream peStream, MetadataBuilder metadataBuilder, BlobBuilder ilBuilder, MethodDefinitionHandle entryPointHandle)
{
var mappedFieldDataBuilder = new BlobBuilder();
var managedResourceDataBuilder = new BlobBuilder();
var peBuilder = new PEBuilder(
machine: 0,
sectionAlignment: 0x2000,
fileAlignment: 0x200,
imageBase: 0x00400000,
majorLinkerVersion: 0x30, // (what is ref.emit using?)
minorLinkerVersion: 0,
majorOperatingSystemVersion: 4,
minorOperatingSystemVersion: 0,
majorImageVersion: 0,
minorImageVersion: 0,
majorSubsystemVersion: 4,
minorSubsystemVersion: 0,
subsystem: Subsystem.WindowsCui,
dllCharacteristics: DllCharacteristics.DynamicBase | DllCharacteristics.NxCompatible | DllCharacteristics.NoSeh | DllCharacteristics.TerminalServerAware,
imageCharacteristics: entryPointHandle.IsNil ? Characteristics.Dll : Characteristics.ExecutableImage,
sizeOfStackReserve: 0x00100000,
sizeOfStackCommit: 0x1000,
sizeOfHeapReserve: 0x00100000,
sizeOfHeapCommit: 0x1000);
var peDirectoriesBuilder = new PEDirectoriesBuilder();
peBuilder.AddManagedSections(
peDirectoriesBuilder,
new TypeSystemMetadataSerializer(metadataBuilder, "v4.0.30319", isMinimalDelta: false),
ilBuilder,
mappedFieldDataBuilder,
managedResourceDataBuilder,
nativeResourceSectionSerializer: null,
strongNameSignatureSize: 0,
entryPoint: entryPointHandle,
pdbPathOpt: null,
nativePdbContentId: default(ContentId),
portablePdbContentId: default(ContentId),
corFlags: CorFlags.ILOnly);
var peBlob = new BlobBuilder();
ContentId peContentId;
peBuilder.Serialize(peBlob, peDirectoriesBuilder, out peContentId);
peBlob.WriteContentTo(peStream);
}
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:48,代码来源:PEBuilderTests.cs
示例12: 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();
}
开发者ID:Corillian,项目名称:corefx,代码行数:16,代码来源:TestBuilders.cs
示例13: BlobBuilder
public BlobBuilder(int capacity = DefaultChunkSize)
{
if (capacity < 0)
{
Throw.ArgumentOutOfRange(nameof(capacity));
}
// the writer assumes little-endian architecture:
if (!BitConverter.IsLittleEndian)
{
Throw.LitteEndianArchitectureRequired();
}
_nextOrPrevious = this;
_buffer = new byte[Math.Max(MinChunkSize, capacity)];
}
开发者ID:Corillian,项目名称:corefx,代码行数:16,代码来源:BlobBuilder.cs
示例14: ManagedPEBuilder
public ManagedPEBuilder(
PEHeaderBuilder header,
MetadataRootBuilder metadataRootBuilder,
BlobBuilder ilStream,
BlobBuilder mappedFieldData = null,
BlobBuilder managedResources = null,
ResourceSectionBuilder nativeResources = null,
DebugDirectoryBuilder debugDirectoryBuilder = null,
int strongNameSignatureSize = DefaultStrongNameSignatureSize,
MethodDefinitionHandle entryPoint = default(MethodDefinitionHandle),
CorFlags flags = CorFlags.ILOnly,
Func<IEnumerable<Blob>, BlobContentId> deterministicIdProvider = null)
: base(header, deterministicIdProvider)
{
if (header == null)
{
Throw.ArgumentNull(nameof(header));
}
if (metadataRootBuilder == null)
{
Throw.ArgumentNull(nameof(metadataRootBuilder));
}
if (ilStream == null)
{
Throw.ArgumentNull(nameof(ilStream));
}
if (strongNameSignatureSize < 0)
{
Throw.ArgumentOutOfRange(nameof(strongNameSignatureSize));
}
_metadataRootBuilder = metadataRootBuilder;
_ilStream = ilStream;
_mappedFieldDataOpt = mappedFieldData;
_managedResourcesOpt = managedResources;
_nativeResourcesOpt = nativeResources;
_strongNameSignatureSize = strongNameSignatureSize;
_entryPointOpt = entryPoint;
_debugDirectoryBuilderOpt = debugDirectoryBuilder ?? CreateDefaultDebugDirectoryBuilder();
_corFlags = flags;
_peDirectoriesBuilder = new PEDirectoriesBuilder();
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:46,代码来源:ManagedPEBuilder.cs
示例15: MethodBodiesEncoder
public MethodBodiesEncoder(BlobBuilder builder = null)
{
if (builder == null)
{
builder = new BlobBuilder();
}
// Fat methods are 4-byte aligned. We calculate the alignment relative to the start of the ILStream.
//
// See ECMA-335 paragraph 25.4.5, Method data section:
// "At the next 4-byte boundary following the method body can be extra method data sections."
if ((builder.Count % 4) != 0)
{
// TODO: error message
throw new ArgumentException("Builder has to be aligned to 4 byte boundary", nameof(builder));
}
Builder = builder;
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:19,代码来源:MethodBodyEncoder.cs
示例16: WriteCompressedInteger
internal static void WriteCompressedInteger(BlobBuilder writer, uint value)
{
unchecked
{
if (value <= SingleByteCompressedIntegerMaxValue)
{
writer.WriteByte((byte)value);
}
else if (value <= TwoByteCompressedIntegerMaxValue)
{
writer.WriteUInt16BE((ushort)(0x8000 | value));
}
else if (value <= MaxCompressedIntegerValue)
{
writer.WriteUInt32BE(0xc0000000 | value);
}
else
{
Throw.ValueArgumentOutOfRange();
}
}
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:22,代码来源:BlobWriterImpl.cs
示例17: WriteCodeViewData
private static int WriteCodeViewData(BlobBuilder builder, string pdbPath, Guid pdbGuid)
{
int start = builder.Count;
builder.WriteByte((byte)'R');
builder.WriteByte((byte)'S');
builder.WriteByte((byte)'D');
builder.WriteByte((byte)'S');
// PDB id:
builder.WriteGuid(pdbGuid);
// age
builder.WriteUInt32(1);
// UTF-8 encoded zero-terminated path to PDB
int pathStart = builder.Count;
builder.WriteUTF8(pdbPath, allowUnpairedSurrogates: true);
builder.WriteByte(0);
return builder.Count - start;
}
开发者ID:AndreGleichner,项目名称:corefx,代码行数:22,代码来源:DebugDirectoryBuilder.cs
示例18: WriteEmbeddedPortablePdbData
private static int WriteEmbeddedPortablePdbData(BlobBuilder builder, BlobBuilder debugMetadata)
{
int start = builder.Count;
// header (signature, decompressed size):
builder.WriteUInt32(PortablePdbVersions.DebugDirectoryEmbeddedSignature);
builder.WriteInt32(debugMetadata.Count);
// compressed data:
var compressed = new MemoryStream();
using (var deflate = new DeflateStream(compressed, CompressionLevel.Optimal, leaveOpen: true))
{
foreach (var blob in debugMetadata.GetBlobs())
{
var segment = blob.GetBytes();
deflate.Write(segment.Array, segment.Offset, segment.Count);
}
}
// TODO: avoid multiple copies:
builder.WriteBytes(compressed.ToArray());
return builder.Count - start;
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:24,代码来源:DebugDirectoryBuilder.cs
示例19: DebugDirectoryBuilder
public DebugDirectoryBuilder()
{
_entries = new List<Entry>(2);
_dataBuilder = new BlobBuilder();
}
开发者ID:Corillian,项目名称:corefx,代码行数:5,代码来源:DebugDirectoryBuilder.cs
示例20: Serialize
/// <summary>
/// Serialize the Debug Table and Data.
/// </summary>
/// <param name="builder">Builder.</param>
/// <param name="sectionLocation">The containing PE section location.</param>
/// <param name="sectionOffset">Offset of the table within the containing section.</param>
internal void Serialize(BlobBuilder builder, SectionLocation sectionLocation, int sectionOffset)
{
int dataOffset = sectionOffset + TableSize;
foreach (var entry in _entries)
{
int addressOfRawData;
int pointerToRawData;
if (entry.DataSize > 0)
{
addressOfRawData = sectionLocation.RelativeVirtualAddress + dataOffset;
pointerToRawData = sectionLocation.PointerToRawData + dataOffset;
}
else
{
addressOfRawData = 0;
pointerToRawData = 0;
}
builder.WriteUInt32(0); // characteristics, always 0
builder.WriteUInt32(entry.Stamp);
builder.WriteUInt32(entry.Version);
builder.WriteInt32((int)entry.Type);
builder.WriteInt32(entry.DataSize);
builder.WriteInt32(addressOfRawData);
builder.WriteInt32(pointerToRawData);
dataOffset += entry.DataSize;
}
builder.LinkSuffix(_dataBuilder);
}
开发者ID:Corillian,项目名称:corefx,代码行数:37,代码来源:DebugDirectoryBuilder.cs
注:本文中的System.Reflection.Metadata.BlobBuilder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论