本文整理汇总了C#中BlobBuilder.Align方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.Align方法的具体用法?C# BlobBuilder.Align怎么用?C# BlobBuilder.Align使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.Align方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteData
public void WriteData(BlobBuilder resourceWriter)
{
if (_fileReference == null)
{
try
{
using (Stream stream = _streamProvider())
{
if (stream == null)
{
throw new InvalidOperationException(CodeAnalysisResources.ResourceStreamProviderShouldReturnNonNullStream);
}
var count = (int)(stream.Length - stream.Position);
resourceWriter.WriteInt32(count);
int bytesWritten = resourceWriter.TryWriteBytes(stream, count);
if (bytesWritten != count)
{
throw new EndOfStreamException(
string.Format(CultureInfo.CurrentUICulture, CodeAnalysisResources.ResourceStreamEndedUnexpectedly, bytesWritten, count));
}
resourceWriter.Align(8);
}
}
catch (Exception e)
{
throw new ResourceException(_name, e);
}
}
}
示例2: WriteTextSection
private void WriteTextSection(
Stream peStream,
SectionHeader textSection,
int importTableRva,
int importAddressTableRva,
int entryPointToken,
BlobBuilder metadataWriter,
BlobBuilder ilWriter,
BlobBuilder mappedFieldDataWriter,
BlobBuilder managedResourceWriter,
MetadataSizes metadataSizes,
ContentId nativePdbContentId,
ContentId portablePdbContentId,
out long metadataPosition)
{
// TODO: zero out all bytes:
peStream.Position = textSection.PointerToRawData;
if (_properties.RequiresStartupStub)
{
WriteImportAddressTable(peStream, importTableRva);
}
var corHeader = CreateCorHeader(metadataSizes, textSection.RelativeVirtualAddress, entryPointToken);
WriteCorHeader(peStream, corHeader);
// IL:
ilWriter.Align(4);
ilWriter.WriteContentTo(peStream);
// metadata:
metadataPosition = peStream.Position;
Debug.Assert(metadataWriter.Count % 4 == 0);
metadataWriter.WriteContentTo(peStream);
// managed resources:
Debug.Assert(managedResourceWriter.Count % 4 == 0);
managedResourceWriter.WriteContentTo(peStream);
// strong name signature:
WriteSpaceForHash(peStream, metadataSizes.StrongNameSignatureSize);
if (EmitPdb)
{
WriteDebugTable(peStream, textSection, nativePdbContentId, portablePdbContentId, metadataSizes);
}
if (_properties.RequiresStartupStub)
{
WriteImportTable(peStream, importTableRva, importAddressTableRva);
WriteNameTable(peStream);
WriteRuntimeStartupStub(peStream, importAddressTableRva);
}
// mapped field data:
mappedFieldDataWriter.WriteContentTo(peStream);
// TODO: zero out all bytes:
int alignedPosition = textSection.PointerToRawData + textSection.SizeOfRawData;
if (peStream.Position != alignedPosition)
{
peStream.Position = alignedPosition - 1;
peStream.WriteByte(0);
}
}
示例3: 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);
}
示例4: SerializeWin32Resources
public static void SerializeWin32Resources(BlobBuilder builder, IEnumerable<IWin32Resource> theResources, int resourcesRva)
{
theResources = SortResources(theResources);
Directory typeDirectory = new Directory(string.Empty, 0);
Directory nameDirectory = null;
Directory languageDirectory = null;
int lastTypeID = int.MinValue;
string lastTypeName = null;
int lastID = int.MinValue;
string lastName = null;
uint sizeOfDirectoryTree = 16;
//EDMAURER note that this list is assumed to be sorted lowest to highest
//first by typeId, then by Id.
foreach (IWin32Resource r in theResources)
{
bool typeDifferent = (r.TypeId < 0 && r.TypeName != lastTypeName) || r.TypeId > lastTypeID;
if (typeDifferent)
{
lastTypeID = r.TypeId;
lastTypeName = r.TypeName;
if (lastTypeID < 0)
{
Debug.Assert(typeDirectory.NumberOfIdEntries == 0, "Not all Win32 resources with types encoded as strings precede those encoded as ints");
typeDirectory.NumberOfNamedEntries++;
}
else
{
typeDirectory.NumberOfIdEntries++;
}
sizeOfDirectoryTree += 24;
typeDirectory.Entries.Add(nameDirectory = new Directory(lastTypeName, lastTypeID));
}
if (typeDifferent || (r.Id < 0 && r.Name != lastName) || r.Id > lastID)
{
lastID = r.Id;
lastName = r.Name;
if (lastID < 0)
{
Debug.Assert(nameDirectory.NumberOfIdEntries == 0, "Not all Win32 resources with names encoded as strings precede those encoded as ints");
nameDirectory.NumberOfNamedEntries++;
}
else
{
nameDirectory.NumberOfIdEntries++;
}
sizeOfDirectoryTree += 24;
nameDirectory.Entries.Add(languageDirectory = new Directory(lastName, lastID));
}
languageDirectory.NumberOfIdEntries++;
sizeOfDirectoryTree += 8;
languageDirectory.Entries.Add(r);
}
var dataWriter = new BlobBuilder();
//'dataWriter' is where opaque resource data goes as well as strings that are used as type or name identifiers
WriteDirectory(typeDirectory, builder, 0, 0, sizeOfDirectoryTree, resourcesRva, dataWriter);
builder.LinkSuffix(dataWriter);
builder.WriteByte(0);
builder.Align(4);
}
示例5: 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
}
}
示例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="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());
}
示例7: SerializeTableHeader
internal static ExceptionRegionEncoder SerializeTableHeader(BlobBuilder builder, int exceptionRegionCount, bool hasSmallRegions)
{
Debug.Assert(exceptionRegionCount > 0);
const byte EHTableFlag = 0x01;
const byte FatFormatFlag = 0x40;
bool hasSmallFormat = hasSmallRegions && IsSmallRegionCount(exceptionRegionCount);
int dataSize = GetExceptionTableSize(exceptionRegionCount, hasSmallFormat);
builder.Align(4);
if (hasSmallFormat)
{
builder.WriteByte(EHTableFlag);
builder.WriteByte(unchecked((byte)dataSize));
builder.WriteInt16(0);
}
else
{
Debug.Assert(dataSize <= 0x00ffffff);
builder.WriteByte(EHTableFlag | FatFormatFlag);
builder.WriteByte(unchecked((byte)dataSize));
builder.WriteUInt16(unchecked((ushort)(dataSize >> 8)));
}
return new ExceptionRegionEncoder(builder, hasSmallFormat);
}
示例8: WriteAlignPad
public void WriteAlignPad()
{
var writer = new BlobBuilder(4);
writer.WriteByte(0x01);
writer.PadTo(2);
writer.WriteByte(0x02);
writer.Align(4);
writer.Align(4);
writer.WriteByte(0x03);
writer.Align(4);
writer.WriteByte(0x04);
writer.WriteByte(0x05);
writer.Align(8);
writer.WriteByte(0x06);
writer.Align(2);
writer.Align(1);
AssertEx.Equal(new byte[]
{
0x01, 0x00, 0x02, 0x00,
0x03, 0x00, 0x00, 0x00,
0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x06, 0x00
}, writer.ToArray());
}
示例9: 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.Count;
Debug.Assert(metadataSizes.MetadataTableStreamSize == endPosition - startPosition);
}