本文整理汇总了C#中System.Reflection.Metadata.BlobBuilder.Align方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.Align方法的具体用法?C# BlobBuilder.Align怎么用?C# BlobBuilder.Align使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.Align方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeMetadataTables
//.........这里部分代码省略.........
this.SerializeEncLogTable(writer);
}
if (metadataSizes.IsPresent(TableIndex.EncMap))
{
this.SerializeEncMapTable(writer);
}
if (metadataSizes.IsPresent(TableIndex.Assembly))
{
this.SerializeAssemblyTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.AssemblyRef))
{
this.SerializeAssemblyRefTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.File))
{
this.SerializeFileTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.ExportedType))
{
this.SerializeExportedTypeTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.ManifestResource))
{
this.SerializeManifestResourceTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.NestedClass))
{
this.SerializeNestedClassTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.GenericParam))
{
this.SerializeGenericParamTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.MethodSpec))
{
this.SerializeMethodSpecTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.GenericParamConstraint))
{
this.SerializeGenericParamConstraintTable(writer, metadataSizes);
}
// debug tables
if (metadataSizes.IsPresent(TableIndex.Document))
{
this.SerializeDocumentTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.MethodDebugInformation))
{
this.SerializeMethodDebugInformationTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.LocalScope))
{
this.SerializeLocalScopeTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.LocalVariable))
{
this.SerializeLocalVariableTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.LocalConstant))
{
this.SerializeLocalConstantTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.ImportScope))
{
this.SerializeImportScopeTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.StateMachineMethod))
{
this.SerializeStateMachineMethodTable(writer, metadataSizes);
}
if (metadataSizes.IsPresent(TableIndex.CustomDebugInformation))
{
this.SerializeCustomDebugInformationTable(writer, metadataSizes);
}
writer.WriteByte(0);
writer.Align(4);
int endPosition = writer.Position;
Debug.Assert(metadataSizes.MetadataTableStreamSize == endPosition - startPosition);
}
示例2: WriteRuntimeStartupStub
private void WriteRuntimeStartupStub(BlobBuilder sectionBuilder, int importAddressTableRva, ulong baseAddress)
{
// entry point code, consisting of a jump indirect to _CorXXXMain
if (Is32Bit)
{
// Write zeros (nops) to pad the entry point code so that the target address is aligned on a 4 byte boundary.
// Note that the section is aligned to FileAlignment, which is at least 512, so we can align relatively to the start of the section.
sectionBuilder.Align(4);
sectionBuilder.WriteUInt16(0);
sectionBuilder.WriteByte(0xff);
sectionBuilder.WriteByte(0x25); //4
sectionBuilder.WriteUInt32((uint)importAddressTableRva + (uint)baseAddress); //8
}
else
{
// Write zeros (nops) to pad the entry point code so that the target address is aligned on a 8 byte boundary.
// Note that the section is aligned to FileAlignment, which is at least 512, so we can align relatively to the start of the section.
sectionBuilder.Align(8);
sectionBuilder.WriteUInt32(0);
sectionBuilder.WriteUInt16(0);
sectionBuilder.WriteByte(0xff);
sectionBuilder.WriteByte(0x25); //8
sectionBuilder.WriteUInt64((ulong)importAddressTableRva + baseAddress); //16
}
}
示例3: Serialize
/// <summary>
/// Serializes .text section data into a specified <paramref name="builder"/>.
/// </summary>
/// <param name="builder">An empty builder to serialize section data to.</param>
/// <param name="relativeVirtualAddess">Relative virtual address of the section within the containing PE file.</param>
/// <param name="entryPointTokenOrRelativeVirtualAddress">Entry point token or RVA (<see cref="CorHeader.EntryPointTokenOrRelativeVirtualAddress"/>)</param>
/// <param name="corFlags">COR Flags (<see cref="CorHeader.Flags"/>).</param>
/// <param name="baseAddress">Base address of the PE image.</param>
/// <param name="metadataBuilder"><see cref="BlobBuilder"/> containing metadata. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
/// <param name="ilBuilder"><see cref="BlobBuilder"/> containing IL stream. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
/// <param name="mappedFieldDataBuilder"><see cref="BlobBuilder"/> containing mapped field data. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
/// <param name="resourceBuilder"><see cref="BlobBuilder"/> containing managed resource data. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
/// <param name="debugTableBuilderOpt"><see cref="BlobBuilder"/> containing debug table data. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
public void Serialize(
BlobBuilder builder,
int relativeVirtualAddess,
int entryPointTokenOrRelativeVirtualAddress,
CorFlags corFlags,
ulong baseAddress,
BlobBuilder metadataBuilder,
BlobBuilder ilBuilder,
BlobBuilder mappedFieldDataBuilder,
BlobBuilder resourceBuilder,
BlobBuilder debugTableBuilderOpt)
{
Debug.Assert(builder.Count == 0);
Debug.Assert(metadataBuilder.Count == MetadataSize);
Debug.Assert(metadataBuilder.Count % 4 == 0);
Debug.Assert(ilBuilder.Count == ILStreamSize);
Debug.Assert(mappedFieldDataBuilder.Count == MappedFieldDataSize);
Debug.Assert(resourceBuilder.Count == ResourceDataSize);
Debug.Assert(resourceBuilder.Count % 4 == 0);
// TODO: avoid recalculation
int importTableRva = GetImportTableDirectoryEntry(relativeVirtualAddess).RelativeVirtualAddress;
int importAddressTableRva = GetImportAddressTableDirectoryEntry(relativeVirtualAddess).RelativeVirtualAddress;
if (RequiresStartupStub)
{
WriteImportAddressTable(builder, importTableRva);
}
WriteCorHeader(builder, relativeVirtualAddess, entryPointTokenOrRelativeVirtualAddress, corFlags);
// IL:
ilBuilder.Align(4);
builder.LinkSuffix(ilBuilder);
// metadata:
builder.LinkSuffix(metadataBuilder);
// managed resources:
builder.LinkSuffix(resourceBuilder);
// strong name signature:
builder.WriteBytes(0, StrongNameSignatureSize);
if (debugTableBuilderOpt != null)
{
builder.LinkSuffix(debugTableBuilderOpt);
}
if (RequiresStartupStub)
{
WriteImportTable(builder, importTableRva, importAddressTableRva);
WriteNameTable(builder);
WriteRuntimeStartupStub(builder, importAddressTableRva, baseAddress);
}
// mapped field data:
builder.LinkSuffix(mappedFieldDataBuilder);
Debug.Assert(builder.Count == ComputeSizeOfTextSection());
}
示例4: Serialize
public BlobContentId Serialize(BlobBuilder builder)
{
// Define and serialize sections in two steps.
// We need to know about all sections before serializing them.
var serializedSections = SerializeSections();
// The positions and sizes of directories are calculated during section serialization.
var directories = GetDirectories();
Blob stampFixup;
WritePESignature(builder);
WriteCoffHeader(builder, serializedSections, out stampFixup);
WritePEHeader(builder, directories, serializedSections);
WriteSectionHeaders(builder, serializedSections);
builder.Align(Header.FileAlignment);
foreach (var section in serializedSections)
{
builder.LinkSuffix(section.Builder);
builder.Align(Header.FileAlignment);
}
var contentId = IdProvider(builder.GetBlobs());
// patch timestamp in COFF header:
var stampWriter = new BlobWriter(stampFixup);
stampWriter.WriteUInt32(contentId.Stamp);
Debug.Assert(stampWriter.RemainingBytes == 0);
return contentId;
}
示例5: Serialize
public void Serialize(BlobBuilder builder, PEDirectoriesBuilder headers, out ContentId contentId)
{
var serializedSections = SerializeSections();
Blob stampFixup;
WritePESignature(builder);
WriteCoffHeader(builder, serializedSections, out stampFixup);
WritePEHeader(builder, headers, serializedSections);
WriteSectionHeaders(builder, serializedSections);
builder.Align(FileAlignment);
foreach (var section in serializedSections)
{
builder.LinkSuffix(section.Builder);
builder.Align(FileAlignment);
}
contentId = IdProvider(builder);
// patch timestamp in COFF header:
var stampWriter = new BlobWriter(stampFixup);
stampWriter.WriteBytes(contentId.Stamp);
Debug.Assert(stampWriter.RemainingBytes == 0);
}
示例6: Serialize
/// <summary>
/// Serializes .text section data into a specified <paramref name="builder"/>.
/// </summary>
/// <param name="builder">An empty builder to serialize section data to.</param>
/// <param name="relativeVirtualAddess">Relative virtual address of the section within the containing PE file.</param>
/// <param name="entryPointTokenOrRelativeVirtualAddress">Entry point token or RVA (<see cref="CorHeader.EntryPointTokenOrRelativeVirtualAddress"/>)</param>
/// <param name="corFlags">COR Flags (<see cref="CorHeader.Flags"/>).</param>
/// <param name="baseAddress">Base address of the PE image.</param>
/// <param name="metadataBuilder"><see cref="BlobBuilder"/> containing metadata. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
/// <param name="ilBuilder"><see cref="BlobBuilder"/> containing IL stream. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
/// <param name="mappedFieldDataBuilderOpt"><see cref="BlobBuilder"/> containing mapped field data. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
/// <param name="resourceBuilderOpt"><see cref="BlobBuilder"/> containing managed resource data. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
/// <param name="debugDataBuilderOpt"><see cref="BlobBuilder"/> containing PE debug table and data. Must be populated with data. Linked into the <paramref name="builder"/> and can't be expanded afterwards.</param>
/// <param name="strongNameSignature">Blob reserved in the <paramref name="builder"/> for strong name signature.</param>
public void Serialize(
BlobBuilder builder,
int relativeVirtualAddess,
int entryPointTokenOrRelativeVirtualAddress,
CorFlags corFlags,
ulong baseAddress,
BlobBuilder metadataBuilder,
BlobBuilder ilBuilder,
BlobBuilder mappedFieldDataBuilderOpt,
BlobBuilder resourceBuilderOpt,
BlobBuilder debugDataBuilderOpt,
out Blob strongNameSignature)
{
Debug.Assert(builder.Count == 0);
Debug.Assert(metadataBuilder.Count == MetadataSize);
Debug.Assert(metadataBuilder.Count % 4 == 0);
Debug.Assert(ilBuilder.Count == ILStreamSize);
Debug.Assert((mappedFieldDataBuilderOpt?.Count ?? 0) == MappedFieldDataSize);
Debug.Assert((resourceBuilderOpt?.Count ?? 0) == ResourceDataSize);
Debug.Assert((resourceBuilderOpt?.Count ?? 0) % 4 == 0);
// TODO: avoid recalculation
int importTableRva = GetImportTableDirectoryEntry(relativeVirtualAddess).RelativeVirtualAddress;
int importAddressTableRva = GetImportAddressTableDirectoryEntry(relativeVirtualAddess).RelativeVirtualAddress;
if (RequiresStartupStub)
{
WriteImportAddressTable(builder, importTableRva);
}
WriteCorHeader(builder, relativeVirtualAddess, entryPointTokenOrRelativeVirtualAddress, corFlags);
// IL:
ilBuilder.Align(4);
builder.LinkSuffix(ilBuilder);
// metadata:
builder.LinkSuffix(metadataBuilder);
// managed resources:
if (resourceBuilderOpt != null)
{
builder.LinkSuffix(resourceBuilderOpt);
}
// strong name signature:
strongNameSignature = builder.ReserveBytes(StrongNameSignatureSize);
// The bytes are required to be 0 for the purpose of calculating hash of the PE content
// when strong name signing.
new BlobWriter(strongNameSignature).WriteBytes(0, StrongNameSignatureSize);
// debug directory and data:
if (debugDataBuilderOpt != null)
{
builder.LinkSuffix(debugDataBuilderOpt);
}
if (RequiresStartupStub)
{
WriteImportTable(builder, importTableRva, importAddressTableRva);
WriteNameTable(builder);
WriteRuntimeStartupStub(builder, importAddressTableRva, baseAddress);
}
// mapped field data:
if (mappedFieldDataBuilderOpt != null)
{
builder.LinkSuffix(mappedFieldDataBuilderOpt);
}
Debug.Assert(builder.Count == ComputeSizeOfTextSection());
}