本文整理汇总了C#中System.Reflection.Metadata.BlobBuilder类的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder类的具体用法?C# BlobBuilder怎么用?C# BlobBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlobBuilder类属于System.Reflection.Metadata命名空间,在下文中一共展示了BlobBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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());
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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)];
}
示例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();
}
示例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;
}