本文整理汇总了C#中System.Reflection.Metadata.BlobBuilder.WriteUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.WriteUInt32方法的具体用法?C# BlobBuilder.WriteUInt32怎么用?C# BlobBuilder.WriteUInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.WriteUInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: WritePESignature
private void WritePESignature(BlobBuilder builder)
{
// MS-DOS stub (128 bytes)
builder.WriteBytes(s_dosHeader);
// PE Signature "PE\0\0"
builder.WriteUInt32(0x00004550);
}
示例3: 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;
}
示例4: SerializeLocalScopeTable
private void SerializeLocalScopeTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
#if DEBUG
// Spec: The table is required to be sorted first by Method in ascending order, then by StartOffset in ascending order, then by Length in descending order.
for (int i = 1; i < _localScopeTable.Count; i++)
{
Debug.Assert(_localScopeTable[i - 1].Method <= _localScopeTable[i].Method);
if (_localScopeTable[i - 1].Method == _localScopeTable[i].Method)
{
Debug.Assert(_localScopeTable[i - 1].StartOffset <= _localScopeTable[i].StartOffset);
if (_localScopeTable[i - 1].StartOffset == _localScopeTable[i].StartOffset)
{
Debug.Assert(_localScopeTable[i - 1].Length >= _localScopeTable[i].Length);
}
}
}
#endif
foreach (var row in _localScopeTable)
{
writer.WriteReference(row.Method, metadataSizes.MethodDefIndexSize);
writer.WriteReference(row.ImportScope, metadataSizes.ImportScopeIndexSize);
writer.WriteReference(row.VariableList, metadataSizes.LocalVariableIndexSize);
writer.WriteReference(row.ConstantList, metadataSizes.LocalConstantIndexSize);
writer.WriteUInt32(row.StartOffset);
writer.WriteUInt32(row.Length);
}
}
示例5: SerializeExportedTypeTable
private void SerializeExportedTypeTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
foreach (ExportedTypeRow exportedType in _exportedTypeTable)
{
writer.WriteUInt32((uint)exportedType.Flags);
writer.WriteUInt32(exportedType.TypeDefId);
writer.WriteReference((uint)GetHeapOffset(exportedType.TypeName), metadataSizes.StringIndexSize);
writer.WriteReference((uint)GetHeapOffset(exportedType.TypeNamespace), metadataSizes.StringIndexSize);
writer.WriteReference(exportedType.Implementation, metadataSizes.ImplementationCodedIndexSize);
}
}
示例6: SerializeAssemblyRefTable
private void SerializeAssemblyRefTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
foreach (AssemblyRefTableRow row in _assemblyRefTable)
{
writer.WriteUInt16((ushort)row.Version.Major);
writer.WriteUInt16((ushort)row.Version.Minor);
writer.WriteUInt16((ushort)row.Version.Build);
writer.WriteUInt16((ushort)row.Version.Revision);
writer.WriteUInt32(row.Flags);
writer.WriteReference((uint)GetHeapOffset(row.PublicKeyToken), metadataSizes.BlobIndexSize);
writer.WriteReference((uint)GetHeapOffset(row.Name), metadataSizes.StringIndexSize);
writer.WriteReference((uint)GetHeapOffset(row.Culture), metadataSizes.StringIndexSize);
writer.WriteReference((uint)GetHeapOffset(row.HashValue), metadataSizes.BlobIndexSize);
}
}
示例7: SerializeFieldLayoutTable
private void SerializeFieldLayoutTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
#if DEBUG
for (int i = 1; i < _fieldLayoutTable.Count; i++)
{
Debug.Assert(_fieldLayoutTable[i - 1].Field < _fieldLayoutTable[i].Field);
}
#endif
foreach (FieldLayoutRow fieldLayout in _fieldLayoutTable)
{
writer.WriteUInt32(fieldLayout.Offset);
writer.WriteReference(fieldLayout.Field, metadataSizes.FieldDefIndexSize);
}
}
示例8: SerializeMethodDefTable
private void SerializeMethodDefTable(BlobBuilder writer, MetadataSizes metadataSizes, int methodBodyStreamRva)
{
foreach (MethodRow method in _methodDefTable)
{
if (method.BodyOffset == -1)
{
writer.WriteUInt32(0);
}
else
{
writer.WriteUInt32((uint)(methodBodyStreamRva + method.BodyOffset));
}
writer.WriteUInt16(method.ImplFlags);
writer.WriteUInt16(method.Flags);
writer.WriteReference((uint)GetHeapOffset(method.Name), metadataSizes.StringIndexSize);
writer.WriteReference((uint)GetHeapOffset(method.Signature), metadataSizes.BlobIndexSize);
writer.WriteReference(method.ParamList, metadataSizes.ParameterIndexSize);
}
}
示例9: WriteCorHeader
private void WriteCorHeader(BlobBuilder builder, int textSectionRva, int entryPointTokenOrRva, CorFlags corFlags)
{
const ushort majorRuntimeVersion = 2;
const ushort minorRuntimeVersion = 5;
int metadataRva = textSectionRva + ComputeOffsetToMetadata();
int resourcesRva = metadataRva + MetadataSize;
int signatureRva = resourcesRva + ResourceDataSize;
int start = builder.Count;
// Size:
builder.WriteUInt32(CorHeaderSize);
// Version:
builder.WriteUInt16(majorRuntimeVersion);
builder.WriteUInt16(minorRuntimeVersion);
// MetadataDirectory:
builder.WriteUInt32((uint)metadataRva);
builder.WriteUInt32((uint)MetadataSize);
// COR Flags:
builder.WriteUInt32((uint)corFlags);
// EntryPoint:
builder.WriteUInt32((uint)entryPointTokenOrRva);
// ResourcesDirectory:
builder.WriteUInt32((uint)(ResourceDataSize == 0 ? 0 : resourcesRva)); // 28
builder.WriteUInt32((uint)ResourceDataSize);
// StrongNameSignatureDirectory:
builder.WriteUInt32((uint)(StrongNameSignatureSize == 0 ? 0 : signatureRva)); // 36
builder.WriteUInt32((uint)StrongNameSignatureSize);
// CodeManagerTableDirectory (not supported):
builder.WriteUInt32(0);
builder.WriteUInt32(0);
// VtableFixupsDirectory (not supported):
builder.WriteUInt32(0);
builder.WriteUInt32(0);
// ExportAddressTableJumpsDirectory (not supported):
builder.WriteUInt32(0);
builder.WriteUInt32(0);
// ManagedNativeHeaderDirectory (not supported):
builder.WriteUInt32(0);
builder.WriteUInt32(0);
Debug.Assert(builder.Count - start == CorHeaderSize);
Debug.Assert(builder.Count % 4 == 0);
}
示例10: WriteImportTable
private void WriteImportTable(BlobBuilder builder, int importTableRva, int importAddressTableRva)
{
int start = builder.Count;
int ilRVA = importTableRva + 40;
int hintRva = ilRVA + (Is32Bit ? 12 : 16);
int nameRva = hintRva + 12 + 2;
// Import table
builder.WriteUInt32((uint)ilRVA); // 4
builder.WriteUInt32(0); // 8
builder.WriteUInt32(0); // 12
builder.WriteUInt32((uint)nameRva); // 16
builder.WriteUInt32((uint)importAddressTableRva); // 20
builder.WriteBytes(0, 20); // 40
// Import Lookup table
if (Is32Bit)
{
builder.WriteUInt32((uint)hintRva); // 44
builder.WriteUInt32(0); // 48
builder.WriteUInt32(0); // 52
}
else
{
builder.WriteUInt64((uint)hintRva); // 48
builder.WriteUInt64(0); // 56
}
// Hint table
builder.WriteUInt16(0); // Hint 54|58
foreach (char ch in CorEntryPointName)
{
builder.WriteByte((byte)ch); // 65|69
}
builder.WriteByte(0); // 66|70
Debug.Assert(builder.Count - start == SizeOfImportTable);
}
示例11: WriteImportAddressTable
private void WriteImportAddressTable(BlobBuilder builder, int importTableRva)
{
int start = builder.Count;
int ilRva = importTableRva + 40;
int hintRva = ilRva + (Is32Bit ? 12 : 16);
// Import Address Table
if (Is32Bit)
{
builder.WriteUInt32((uint)hintRva); // 4
builder.WriteUInt32(0); // 8
}
else
{
builder.WriteUInt64((uint)hintRva); // 8
builder.WriteUInt64(0); // 16
}
Debug.Assert(builder.Count - start == SizeOfImportAddressTable);
}
示例12: WriteSectionHeader
private static void WriteSectionHeader(BlobBuilder builder, SerializedSection serializedSection)
{
if (serializedSection.VirtualSize == 0)
{
return;
}
for (int j = 0, m = serializedSection.Name.Length; j < 8; j++)
{
if (j < m)
{
builder.WriteByte((byte)serializedSection.Name[j]);
}
else
{
builder.WriteByte(0);
}
}
builder.WriteUInt32((uint)serializedSection.VirtualSize);
builder.WriteUInt32((uint)serializedSection.RelativeVirtualAddress);
builder.WriteUInt32((uint)serializedSection.SizeOfRawData);
builder.WriteUInt32((uint)serializedSection.PointerToRawData);
// PointerToRelocations (TODO: not supported):
builder.WriteUInt32(0);
// PointerToLinenumbers (TODO: not supported):
builder.WriteUInt32(0);
// NumberOfRelocations (TODO: not supported):
builder.WriteUInt16(0);
// NumberOfLinenumbers (TODO: not supported):
builder.WriteUInt16(0);
builder.WriteUInt32((uint)serializedSection.Characteristics);
}
示例13: WritePEHeader
private void WritePEHeader(BlobBuilder builder, PEDirectoriesBuilder directories, ImmutableArray<SerializedSection> sections)
{
builder.WriteUInt16((ushort)(Header.Is32Bit ? PEMagic.PE32 : PEMagic.PE32Plus));
builder.WriteByte(Header.MajorLinkerVersion);
builder.WriteByte(Header.MinorLinkerVersion);
// SizeOfCode:
builder.WriteUInt32((uint)SumRawDataSizes(sections, SectionCharacteristics.ContainsCode));
// SizeOfInitializedData:
builder.WriteUInt32((uint)SumRawDataSizes(sections, SectionCharacteristics.ContainsInitializedData));
// SizeOfUninitializedData:
builder.WriteUInt32((uint)SumRawDataSizes(sections, SectionCharacteristics.ContainsUninitializedData));
// AddressOfEntryPoint:
builder.WriteUInt32((uint)directories.AddressOfEntryPoint);
// BaseOfCode:
int codeSectionIndex = IndexOfSection(sections, SectionCharacteristics.ContainsCode);
builder.WriteUInt32((uint)(codeSectionIndex != -1 ? sections[codeSectionIndex].RelativeVirtualAddress : 0));
if (Header.Is32Bit)
{
// BaseOfData:
int dataSectionIndex = IndexOfSection(sections, SectionCharacteristics.ContainsInitializedData);
builder.WriteUInt32((uint)(dataSectionIndex != -1 ? sections[dataSectionIndex].RelativeVirtualAddress : 0));
builder.WriteUInt32((uint)Header.ImageBase);
}
else
{
builder.WriteUInt64(Header.ImageBase);
}
// NT additional fields:
builder.WriteUInt32((uint)Header.SectionAlignment);
builder.WriteUInt32((uint)Header.FileAlignment);
builder.WriteUInt16(Header.MajorOperatingSystemVersion);
builder.WriteUInt16(Header.MinorOperatingSystemVersion);
builder.WriteUInt16(Header.MajorImageVersion);
builder.WriteUInt16(Header.MinorImageVersion);
builder.WriteUInt16(Header.MajorSubsystemVersion);
builder.WriteUInt16(Header.MinorSubsystemVersion);
// Win32VersionValue (reserved, should be 0)
builder.WriteUInt32(0);
// SizeOfImage:
var lastSection = sections[sections.Length - 1];
builder.WriteUInt32((uint)BitArithmetic.Align(lastSection.RelativeVirtualAddress + lastSection.VirtualSize, Header.SectionAlignment));
// SizeOfHeaders:
builder.WriteUInt32((uint)BitArithmetic.Align(Header.ComputeSizeOfPeHeaders(sections.Length), Header.FileAlignment));
// Checksum:
// Shall be zero for strong name signing.
builder.WriteUInt32(0);
builder.WriteUInt16((ushort)Header.Subsystem);
builder.WriteUInt16((ushort)Header.DllCharacteristics);
if (Header.Is32Bit)
{
builder.WriteUInt32((uint)Header.SizeOfStackReserve);
builder.WriteUInt32((uint)Header.SizeOfStackCommit);
builder.WriteUInt32((uint)Header.SizeOfHeapReserve);
builder.WriteUInt32((uint)Header.SizeOfHeapCommit);
}
else
{
builder.WriteUInt64(Header.SizeOfStackReserve);
builder.WriteUInt64(Header.SizeOfStackCommit);
builder.WriteUInt64(Header.SizeOfHeapReserve);
builder.WriteUInt64(Header.SizeOfHeapCommit);
}
// LoaderFlags
builder.WriteUInt32(0);
// The number of data-directory entries in the remainder of the header.
builder.WriteUInt32(16);
// directory entries:
builder.WriteUInt32((uint)directories.ExportTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)directories.ExportTable.Size);
builder.WriteUInt32((uint)directories.ImportTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)directories.ImportTable.Size);
builder.WriteUInt32((uint)directories.ResourceTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)directories.ResourceTable.Size);
builder.WriteUInt32((uint)directories.ExceptionTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)directories.ExceptionTable.Size);
// Authenticode CertificateTable directory. Shall be zero before the PE is signed.
builder.WriteUInt32(0);
builder.WriteUInt32(0);
builder.WriteUInt32((uint)directories.BaseRelocationTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)directories.BaseRelocationTable.Size);
builder.WriteUInt32((uint)directories.DebugTable.RelativeVirtualAddress);
//.........这里部分代码省略.........
示例14: WriteCoffHeader
private void WriteCoffHeader(BlobBuilder builder, ImmutableArray<SerializedSection> sections, out Blob stampFixup)
{
// Machine
builder.WriteUInt16((ushort)(Header.Machine == 0 ? Machine.I386 : Header.Machine));
// NumberOfSections
builder.WriteUInt16((ushort)sections.Length);
// TimeDateStamp:
stampFixup = builder.ReserveBytes(sizeof(uint));
// PointerToSymbolTable (TODO: not supported):
// The file pointer to the COFF symbol table, or zero if no COFF symbol table is present.
// This value should be zero for a PE image.
builder.WriteUInt32(0);
// NumberOfSymbols (TODO: not supported):
// The number of entries in the symbol table. This data can be used to locate the string table,
// which immediately follows the symbol table. This value should be zero for a PE image.
builder.WriteUInt32(0);
// SizeOfOptionalHeader:
// The size of the optional header, which is required for executable files but not for object files.
// This value should be zero for an object file (TODO).
builder.WriteUInt16((ushort)(Header.Is32Bit ? 224 : 240));
// Characteristics
builder.WriteUInt16((ushort)Header.ImageCharacteristics);
}
示例15: SerializeEncMapTable
private void SerializeEncMapTable(BlobBuilder writer)
{
foreach (EncMapRow encMap in _encMapTable)
{
writer.WriteUInt32(encMap.Token);
}
}