本文整理汇总了C#中Microsoft.Cci.BlobBuilder.WriteUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.WriteUInt16方法的具体用法?C# BlobBuilder.WriteUInt16怎么用?C# BlobBuilder.WriteUInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Cci.BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.WriteUInt16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WritePrimitive
public void WritePrimitive()
{
var writer = new BlobBuilder(4);
writer.WriteUInt32(0x11223344);
writer.WriteUInt16(0x5566);
writer.WriteByte(0x77);
writer.WriteUInt64(0x8899aabbccddeeff);
writer.WriteInt32(-1);
writer.WriteInt16(-2);
writer.WriteSByte(-3);
writer.WriteBoolean(true);
writer.WriteBoolean(false);
writer.WriteInt64(unchecked((long)0xfedcba0987654321));
writer.WriteDateTime(new DateTime(0x1112223334445556));
writer.WriteDecimal(102030405060.70m);
writer.WriteDouble(double.NaN);
writer.WriteSingle(float.NegativeInfinity);
AssertEx.Equal(new byte[]
{
0x44, 0x33, 0x22, 0x11,
0x66, 0x55,
0x77,
0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
0xff, 0xff, 0xff, 0xff,
0xfe, 0xff,
0xfd,
0x01,
0x00,
0x21, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE,
0x56, 0x55, 0x44, 0x34, 0x33, 0x22, 0x12, 0x11,
0x02, 0xD6, 0xE0, 0x9A, 0x94, 0x47, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x00, 0x00, 0x80, 0xFF
}, writer.ToArray());
}
示例2: SerializeGenericParamTable
private void SerializeGenericParamTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
#if DEBUG
for (int i = 1; i < _genericParamTable.Count; i++)
{
Debug.Assert(
_genericParamTable[i - 1].Owner < _genericParamTable[i].Owner ||
_genericParamTable[i - 1].Owner == _genericParamTable[i].Owner && _genericParamTable[i - 1].Number < _genericParamTable[i].Number);
}
#endif
foreach (GenericParamRow genericParam in _genericParamTable)
{
writer.WriteUInt16(genericParam.Number);
writer.WriteUInt16(genericParam.Flags);
writer.WriteReference(genericParam.Owner, metadataSizes.TypeOrMethodDefCodedIndexSize);
writer.WriteReference((uint)_heaps.ResolveStringIndex(genericParam.Name), metadataSizes.StringIndexSize);
}
}
示例3: SerializeLocalVariableTable
private void SerializeLocalVariableTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
foreach (var row in _localVariableTable)
{
writer.WriteUInt16(row.Attributes);
writer.WriteUInt16(row.Index);
writer.WriteReference((uint)_debugHeapsOpt.ResolveStringIndex(row.Name), metadataSizes.StringIndexSize);
}
}
示例4: WriteRelocSection
private void WriteRelocSection(Stream peStream, SectionHeader relocSection, int entryPointAddress)
{
peStream.Position = relocSection.PointerToRawData;
var writer = new BlobBuilder(relocSection.SizeOfRawData);
writer.WriteUInt32((((uint)entryPointAddress + 2) / 0x1000) * 0x1000);
writer.WriteUInt32(_properties.Requires64bits && !_properties.RequiresAmdInstructionSet ? 14u : 12u);
uint offsetWithinPage = ((uint)entryPointAddress + 2) % 0x1000;
uint relocType = _properties.Requires64bits ? 10u : 3u;
ushort s = (ushort)((relocType << 12) | offsetWithinPage);
writer.WriteUInt16(s);
if (_properties.Requires64bits && !_properties.RequiresAmdInstructionSet)
{
writer.WriteUInt32(relocType << 12);
}
writer.WriteUInt16(0); // next chunk's RVA
writer.PadTo(relocSection.SizeOfRawData);
writer.WriteTo(peStream);
}
示例5: SerializeNamespaceScopeMetadata
private void SerializeNamespaceScopeMetadata(EmitContext context, IMethodBody methodBody, ArrayBuilder<BlobBuilder> customDebugInfo)
{
if (context.Module.GenerateVisualBasicStylePdb)
{
return;
}
if (ShouldForwardToPreviousMethodWithUsingInfo(context, methodBody))
{
Debug.Assert(!ReferenceEquals(_previousMethodBodyWithUsingInfo, methodBody));
SerializeReferenceToPreviousMethodWithUsingInfo(customDebugInfo);
return;
}
List<ushort> usingCounts = new List<ushort>();
var cmw = new BlobBuilder();
for (IImportScope scope = methodBody.ImportScope; scope != null; scope = scope.Parent)
{
usingCounts.Add((ushort)scope.GetUsedNamespaces().Length);
}
// ACASEY: This originally wrote (uint)12, (ushort)1, (ushort)0 in the
// case where usingCounts was empty, but I'm not sure why.
if (usingCounts.Count > 0)
{
uint streamLength;
cmw.WriteByte(CDI.CdiVersion);
cmw.WriteByte(CDI.CdiKindUsingInfo);
cmw.Align(4);
cmw.WriteUInt32(streamLength = BitArithmeticUtilities.Align((uint)usingCounts.Count * 2 + 10, 4));
cmw.WriteUInt16((ushort)usingCounts.Count);
foreach (ushort uc in usingCounts)
{
cmw.WriteUInt16(uc);
}
cmw.Align(4);
Debug.Assert(streamLength == cmw.Length);
customDebugInfo.Add(cmw);
}
if (_methodBodyWithModuleInfo != null && !ReferenceEquals(_methodBodyWithModuleInfo, methodBody))
{
SerializeReferenceToMethodWithModuleInfo(customDebugInfo);
}
}
示例6: WriteImportTable
private void WriteImportTable(Stream peStream, int importTableRva, int importAddressTableRva)
{
var writer = new BlobBuilder(SizeOfImportTable);
int ilRVA = importTableRva + 40;
int hintRva = ilRVA + (_is32bit ? 12 : 16);
int nameRva = hintRva + 12 + 2;
// Import table
writer.WriteUInt32((uint)ilRVA); // 4
writer.WriteUInt32(0); // 8
writer.WriteUInt32(0); // 12
writer.WriteUInt32((uint)nameRva); // 16
writer.WriteUInt32((uint)importAddressTableRva); // 20
writer.WriteBytes(0, 20); // 40
// Import Lookup table
if (_is32bit)
{
writer.WriteUInt32((uint)hintRva); // 44
writer.WriteUInt32(0); // 48
writer.WriteUInt32(0); // 52
}
else
{
writer.WriteUInt64((uint)hintRva); // 48
writer.WriteUInt64(0); // 56
}
// Hint table
writer.WriteUInt16(0); // Hint 54|58
foreach (char ch in CorEntryPointName)
{
writer.WriteByte((byte)ch); // 65|69
}
writer.WriteByte(0); // 66|70
Debug.Assert(writer.Length == SizeOfImportTable);
writer.WriteTo(peStream);
}
示例7: WriteCorHeader
private static void WriteCorHeader(Stream peStream, CorHeader corHeader)
{
var writer = new BlobBuilder(CorHeaderSize);
writer.WriteUInt32(CorHeaderSize);
writer.WriteUInt16(corHeader.MajorRuntimeVersion);
writer.WriteUInt16(corHeader.MinorRuntimeVersion);
writer.WriteUInt32((uint)corHeader.MetadataDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.MetadataDirectory.Size);
writer.WriteUInt32((uint)corHeader.Flags);
writer.WriteUInt32((uint)corHeader.EntryPointTokenOrRelativeVirtualAddress);
writer.WriteUInt32((uint)(corHeader.ResourcesDirectory.Size == 0 ? 0 : corHeader.ResourcesDirectory.RelativeVirtualAddress)); // 28
writer.WriteUInt32((uint)corHeader.ResourcesDirectory.Size);
writer.WriteUInt32((uint)(corHeader.StrongNameSignatureDirectory.Size == 0 ? 0 : corHeader.StrongNameSignatureDirectory.RelativeVirtualAddress)); // 36
writer.WriteUInt32((uint)corHeader.StrongNameSignatureDirectory.Size);
writer.WriteUInt32((uint)corHeader.CodeManagerTableDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.CodeManagerTableDirectory.Size);
writer.WriteUInt32((uint)corHeader.VtableFixupsDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.VtableFixupsDirectory.Size);
writer.WriteUInt32((uint)corHeader.ExportAddressTableJumpsDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.ExportAddressTableJumpsDirectory.Size);
writer.WriteUInt64(0);
Debug.Assert(writer.Length == CorHeaderSize);
Debug.Assert(writer.Length % 4 == 0);
writer.WriteTo(peStream);
}
示例8: SerializeClassLayoutTable
private void SerializeClassLayoutTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
#if DEBUG
for (int i = 1; i < _classLayoutTable.Count; i++)
{
Debug.Assert(_classLayoutTable[i - 1].Parent < _classLayoutTable[i].Parent);
}
#endif
foreach (ClassLayoutRow classLayout in _classLayoutTable)
{
writer.WriteUInt16(classLayout.PackingSize);
writer.WriteUInt32(classLayout.ClassSize);
writer.WriteReference(classLayout.Parent, metadataSizes.TypeDefIndexSize);
}
}
示例9: SerializeEventTable
private void SerializeEventTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
foreach (EventRow eventRow in _eventTable)
{
writer.WriteUInt16(eventRow.EventFlags);
writer.WriteReference((uint)_heaps.ResolveStringIndex(eventRow.Name), metadataSizes.StringIndexSize);
writer.WriteReference(eventRow.EventType, metadataSizes.TypeDefOrRefCodedIndexSize);
}
}
示例10: SerializeParamTable
private void SerializeParamTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
foreach (ParamRow param in _paramTable)
{
writer.WriteUInt16(param.Flags);
writer.WriteUInt16(param.Sequence);
writer.WriteReference((uint)_heaps.ResolveStringIndex(param.Name), metadataSizes.StringIndexSize);
}
}
示例11: SerializeDeclSecurityTable
private void SerializeDeclSecurityTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
// Note: we can sort the table at this point since no other table can reference its rows via RowId or CodedIndex (which would need updating otherwise).
// OrderBy performs a stable sort, so multiple attributes with the same parent will be sorted in the order they were added to the table.
var ordered = _declSecurityTableNeedsSorting ? _declSecurityTable.OrderBy((x, y) => (int)x.Parent - (int)y.Parent) : _declSecurityTable;
foreach (DeclSecurityRow declSecurity in ordered)
{
writer.WriteUInt16(declSecurity.Action);
writer.WriteReference(declSecurity.Parent, metadataSizes.DeclSecurityCodedIndexSize);
writer.WriteReference((uint)_heaps.ResolveBlobIndex(declSecurity.PermissionSet), metadataSizes.BlobIndexSize);
}
}
示例12: SerializeMethodDefTable
private void SerializeMethodDefTable(BlobBuilder writer, MetadataSizes metadataSizes, int methodBodyStreamRva)
{
foreach (MethodRow method in _methodDefTable)
{
if (method.Rva == -1)
{
writer.WriteUInt32(0);
}
else
{
writer.WriteUInt32((uint)(methodBodyStreamRva + method.Rva));
}
writer.WriteUInt16(method.ImplFlags);
writer.WriteUInt16(method.Flags);
writer.WriteReference((uint)_heaps.ResolveStringIndex(method.Name), metadataSizes.StringIndexSize);
writer.WriteReference((uint)_heaps.ResolveBlobIndex(method.Signature), metadataSizes.BlobIndexSize);
writer.WriteReference(method.ParamList, metadataSizes.ParameterIndexSize);
}
}
示例13: SerializeFieldTable
private void SerializeFieldTable(BlobBuilder writer, MetadataSizes metadataSizes)
{
foreach (FieldDefRow fieldDef in _fieldTable)
{
writer.WriteUInt16(fieldDef.Flags);
writer.WriteReference((uint)_heaps.ResolveStringIndex(fieldDef.Name), metadataSizes.StringIndexSize);
writer.WriteReference((uint)_heaps.ResolveBlobIndex(fieldDef.Signature), metadataSizes.BlobIndexSize);
}
}
示例14: SerializeModuleTable
private void SerializeModuleTable(BlobBuilder writer, MetadataSizes metadataSizes, MetadataHeapsBuilder heaps)
{
foreach (var moduleRow in _moduleTable)
{
writer.WriteUInt16(moduleRow.Generation);
writer.WriteReference((uint)heaps.ResolveStringIndex(moduleRow.Name), metadataSizes.StringIndexSize);
writer.WriteReference((uint)moduleRow.ModuleVersionId, metadataSizes.GuidIndexSize);
writer.WriteReference((uint)moduleRow.EncId, metadataSizes.GuidIndexSize);
writer.WriteReference((uint)moduleRow.EncBaseId, metadataSizes.GuidIndexSize);
}
}
示例15: WriteHeaders
private void WriteHeaders(Stream peStream, NtHeader ntHeader, CoffHeader coffHeader, List<SectionHeader> sectionHeaders, out long ntHeaderTimestampPosition)
{
var writer = new BlobBuilder(1024);
// MS-DOS stub (128 bytes)
writer.WriteBytes(s_dosHeader);
// PE Signature "PE\0\0"
writer.WriteUInt32(0x00004550);
// COFF Header (20 bytes)
writer.WriteUInt16((ushort)coffHeader.Machine);
writer.WriteUInt16((ushort)coffHeader.NumberOfSections);
ntHeaderTimestampPosition = writer.Position + peStream.Position;
writer.WriteUInt32((uint)coffHeader.TimeDateStamp);
writer.WriteUInt32((uint)coffHeader.PointerToSymbolTable);
writer.WriteUInt32((uint)coffHeader.NumberOfSymbols);
writer.WriteUInt16((ushort)(_is32bit ? 224 : 240)); // SizeOfOptionalHeader
writer.WriteUInt16((ushort)coffHeader.Characteristics);
// PE Headers:
writer.WriteUInt16((ushort)(_is32bit ? PEMagic.PE32 : PEMagic.PE32Plus)); // 2
writer.WriteByte(ntHeader.MajorLinkerVersion); // 3
writer.WriteByte(ntHeader.MinorLinkerVersion); // 4
writer.WriteUInt32((uint)ntHeader.SizeOfCode); // 8
writer.WriteUInt32((uint)ntHeader.SizeOfInitializedData); // 12
writer.WriteUInt32((uint)ntHeader.SizeOfUninitializedData); // 16
writer.WriteUInt32((uint)ntHeader.AddressOfEntryPoint); // 20
writer.WriteUInt32((uint)ntHeader.BaseOfCode); // 24
if (_is32bit)
{
writer.WriteUInt32((uint)ntHeader.BaseOfData); // 28
writer.WriteUInt32((uint)ntHeader.ImageBase); // 32
}
else
{
writer.WriteUInt64(ntHeader.ImageBase); // 32
}
// NT additional fields:
writer.WriteUInt32((uint)ntHeader.SectionAlignment); // 36
writer.WriteUInt32((uint)ntHeader.FileAlignment); // 40
writer.WriteUInt16(ntHeader.MajorOperatingSystemVersion); // 42
writer.WriteUInt16(ntHeader.MinorOperatingSystemVersion); // 44
writer.WriteUInt16(ntHeader.MajorImageVersion); // 46
writer.WriteUInt16(ntHeader.MinorImageVersion); // 48
writer.WriteUInt16(ntHeader.MajorSubsystemVersion); // MajorSubsystemVersion 50
writer.WriteUInt16(ntHeader.MinorSubsystemVersion); // MinorSubsystemVersion 52
// Win32VersionValue (reserved, should be 0)
writer.WriteUInt32(0); // 56
writer.WriteUInt32((uint)ntHeader.SizeOfImage); // 60
writer.WriteUInt32((uint)ntHeader.SizeOfHeaders); // 64
writer.WriteUInt32(ntHeader.Checksum); // 68
writer.WriteUInt16((ushort)ntHeader.Subsystem); // 70
writer.WriteUInt16((ushort)ntHeader.DllCharacteristics);
if (_is32bit)
{
writer.WriteUInt32((uint)ntHeader.SizeOfStackReserve); // 76
writer.WriteUInt32((uint)ntHeader.SizeOfStackCommit); // 80
writer.WriteUInt32((uint)ntHeader.SizeOfHeapReserve); // 84
writer.WriteUInt32((uint)ntHeader.SizeOfHeapCommit); // 88
}
else
{
writer.WriteUInt64(ntHeader.SizeOfStackReserve); // 80
writer.WriteUInt64(ntHeader.SizeOfStackCommit); // 88
writer.WriteUInt64(ntHeader.SizeOfHeapReserve); // 96
writer.WriteUInt64(ntHeader.SizeOfHeapCommit); // 104
}
// LoaderFlags
writer.WriteUInt32(0); // 92|108
// The number of data-directory entries in the remainder of the header.
writer.WriteUInt32(16); // 96|112
// directory entries:
writer.WriteUInt32((uint)ntHeader.ExportTable.RelativeVirtualAddress); // 100|116
writer.WriteUInt32((uint)ntHeader.ExportTable.Size); // 104|120
writer.WriteUInt32((uint)ntHeader.ImportTable.RelativeVirtualAddress); // 108|124
writer.WriteUInt32((uint)ntHeader.ImportTable.Size); // 112|128
writer.WriteUInt32((uint)ntHeader.ResourceTable.RelativeVirtualAddress); // 116|132
writer.WriteUInt32((uint)ntHeader.ResourceTable.Size); // 120|136
writer.WriteUInt32((uint)ntHeader.ExceptionTable.RelativeVirtualAddress); // 124|140
writer.WriteUInt32((uint)ntHeader.ExceptionTable.Size); // 128|144
writer.WriteUInt32((uint)ntHeader.CertificateTable.RelativeVirtualAddress); // 132|148
writer.WriteUInt32((uint)ntHeader.CertificateTable.Size); // 136|152
writer.WriteUInt32((uint)ntHeader.BaseRelocationTable.RelativeVirtualAddress); // 140|156
writer.WriteUInt32((uint)ntHeader.BaseRelocationTable.Size); // 144|160
writer.WriteUInt32((uint)ntHeader.DebugTable.RelativeVirtualAddress); // 148|164
writer.WriteUInt32((uint)ntHeader.DebugTable.Size); // 152|168
writer.WriteUInt32((uint)ntHeader.CopyrightTable.RelativeVirtualAddress); // 156|172
writer.WriteUInt32((uint)ntHeader.CopyrightTable.Size); // 160|176
writer.WriteUInt32((uint)ntHeader.GlobalPointerTable.RelativeVirtualAddress); // 164|180
writer.WriteUInt32((uint)ntHeader.GlobalPointerTable.Size); // 168|184
writer.WriteUInt32((uint)ntHeader.ThreadLocalStorageTable.RelativeVirtualAddress); // 172|188
//.........这里部分代码省略.........