本文整理汇总了C#中BlobBuilder.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.WriteByte方法的具体用法?C# BlobBuilder.WriteByte怎么用?C# BlobBuilder.WriteByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.WriteByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteFakeILWithBranches
private static void WriteFakeILWithBranches(BlobBuilder builder, ControlFlowBuilder branchBuilder, int size)
{
Assert.Equal(0, builder.Count);
const byte filling = 0x01;
int ilOffset = 0;
foreach (var branch in branchBuilder.Branches)
{
builder.WriteBytes(filling, branch.ILOffset - ilOffset);
Assert.Equal(branch.ILOffset, builder.Count);
builder.WriteByte((byte)branch.OpCode);
int operandSize = branch.OpCode.GetBranchOperandSize();
if (operandSize == 1)
{
builder.WriteSByte(-1);
}
else
{
builder.WriteInt32(-1);
}
ilOffset = branch.ILOffset + sizeof(byte) + operandSize;
}
builder.WriteBytes(filling, size - ilOffset);
Assert.Equal(size, builder.Count);
}
示例2: WriteFakeILWithBranches
private static void WriteFakeILWithBranches(BlobBuilder builder, BranchBuilder branchBuilder, int size)
{
Assert.Equal(0, builder.Count);
const byte filling = 0x01;
int ilOffset = 0;
foreach (var branch in branchBuilder.Branches)
{
builder.WriteBytes(filling, branch.ILOffset - ilOffset);
Assert.Equal(branch.ILOffset, builder.Count);
builder.WriteByte(branch.ShortOpCode);
builder.WriteByte(0xff);
ilOffset = branch.ILOffset + 2;
}
builder.WriteBytes(filling, size - ilOffset);
Assert.Equal(size, builder.Count);
}
示例3: OpCode
public void OpCode()
{
var builder = new BlobBuilder();
builder.WriteByte(0xff);
var il = new InstructionEncoder(builder);
Assert.Equal(1, il.Offset);
il.OpCode(ILOpCode.Add);
Assert.Equal(2, il.Offset);
builder.WriteByte(0xee);
Assert.Equal(3, il.Offset);
il.OpCode(ILOpCode.Arglist);
Assert.Equal(5, il.Offset);
builder.WriteByte(0xdd);
Assert.Equal(6, il.Offset);
il.OpCode(ILOpCode.Readonly);
Assert.Equal(8, il.Offset);
builder.WriteByte(0xcc);
Assert.Equal(9, il.Offset);
AssertEx.Equal(new byte[]
{
0xFF,
0x58,
0xEE,
0xFE, 0x00,
0xDD,
0xFE, 0x1E,
0xCC
}, builder.ToArray());
}
示例4: SerializeTableHeader
public void SerializeTableHeader()
{
var builder = new BlobBuilder();
builder.WriteByte(0xff);
ExceptionRegionEncoder.SerializeTableHeader(builder, ExceptionRegionEncoder.MaxSmallExceptionRegions, hasSmallRegions: true);
AssertEx.Equal(new byte[]
{
0xff, 0x00, 0x00, 0x00, // padding
0x01, // flags
0xf4, // size
0x00, 0x00
}, builder.ToArray());
builder.Clear();
builder.WriteByte(0xff);
ExceptionRegionEncoder.SerializeTableHeader(builder, ExceptionRegionEncoder.MaxExceptionRegions, hasSmallRegions: false);
AssertEx.Equal(new byte[]
{
0xff, 0x00, 0x00, 0x00, // padding
0x41, // flags
0xf4, 0xff, 0xff, // size
}, builder.ToArray());
}
示例5: CountClear
public void CountClear()
{
var builder = new BlobBuilder();
Assert.Equal(0, builder.Count);
builder.WriteByte(1);
Assert.Equal(1, builder.Count);
builder.WriteInt32(4);
Assert.Equal(5, builder.Count);
builder.Clear();
Assert.Equal(0, builder.Count);
builder.WriteInt64(1);
Assert.Equal(8, builder.Count);
AssertEx.Equal(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, builder.ToArray());
}
示例6: WriteCompressedInteger
internal static void WriteCompressedInteger(BlobBuilder writer, int value)
{
unchecked
{
if (value <= SingleByteCompressedIntegerMaxValue)
{
writer.WriteByte((byte)value);
}
else if (value <= TwoByteCompressedIntegerMaxValue)
{
writer.WriteUInt16BE((ushort)(0x8000 | value));
}
else if (value <= MaxCompressedIntegerValue)
{
writer.WriteUInt32BE(0xc0000000 | (uint)value);
}
else
{
ThrowValueArgumentOutOfRange();
}
}
}
示例7: 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
}
}
示例8: WriteDebugTable
private readonly static byte[] zeroStamp = new byte[4]; // four bytes of zero
/// <summary>
/// Write the entire "Debug Directory (Image Only)" along with data that it points to.
/// </summary>
internal void WriteDebugTable(BlobBuilder builder, PESectionLocation textSectionLocation, ContentId nativePdbContentId, ContentId portablePdbContentId)
{
Debug.Assert(builder.Count == 0);
int tableSize = ImageDebugDirectoryBaseSize;
Debug.Assert(tableSize != 0);
Debug.Assert(nativePdbContentId.IsDefault || portablePdbContentId.IsDefault);
Debug.Assert(!EmitPdb || (nativePdbContentId.IsDefault ^ portablePdbContentId.IsDefault));
int dataSize = ComputeSizeOfDebugDirectoryData();
if (EmitPdb)
{
const int IMAGE_DEBUG_TYPE_CODEVIEW = 2; // from PE spec
uint dataOffset = (uint)(ComputeOffsetToDebugTable() + tableSize);
WriteDebugTableEntry(builder,
stamp: nativePdbContentId.Stamp ?? portablePdbContentId.Stamp,
version: portablePdbContentId.IsDefault ? (uint)0 : ('P' << 24 | 'M' << 16 | 0x01 << 8 | 0x00),
debugType: IMAGE_DEBUG_TYPE_CODEVIEW,
sizeOfData: (uint)dataSize,
addressOfRawData: (uint)textSectionLocation.RelativeVirtualAddress + dataOffset, // RVA of the data
pointerToRawData: (uint)textSectionLocation.PointerToRawData + dataOffset); // position of the data in the PE stream
}
if (IsDeterministic)
{
const int IMAGE_DEBUG_TYPE_NO_TIMESTAMP = 16; // from PE spec
WriteDebugTableEntry(builder,
stamp: zeroStamp,
version: 0,
debugType: IMAGE_DEBUG_TYPE_NO_TIMESTAMP,
sizeOfData: 0,
addressOfRawData: 0,
pointerToRawData: 0);
}
// We should now have written all and precisely the data we said we'd write for the table entries.
Debug.Assert(builder.Count == tableSize);
// ====================
// The following is additional data beyond the debug directory at the offset `dataOffset`
// pointed to by the ImageDebugTypeCodeView entry.
if (EmitPdb)
{
builder.WriteByte((byte)'R');
builder.WriteByte((byte)'S');
builder.WriteByte((byte)'D');
builder.WriteByte((byte)'S');
// PDB id:
builder.WriteBytes(nativePdbContentId.Guid ?? portablePdbContentId.Guid);
// age
builder.WriteUInt32(1); // TODO: allow specify for native PDBs
// UTF-8 encoded zero-terminated path to PDB
int pathStart = builder.Count;
builder.WriteUTF8(PdbPathOpt, allowUnpairedSurrogates: true);
builder.WriteByte(0);
// padding:
builder.WriteBytes(0, Math.Max(0, MinPdbPath - (builder.Count - pathStart)));
}
// We should now have written all and precisely the data we said we'd write for the table and its data.
Debug.Assert(builder.Count == tableSize + dataSize);
}
示例9: WriteDirectory
private void WriteDirectory(Directory directory, BlobBuilder writer, uint offset, uint level, uint sizeOfDirectoryTree, int virtualAddressBase, BlobBuilder dataWriter)
{
writer.WriteUInt32(0); // Characteristics
writer.WriteUInt32(0); // Timestamp
writer.WriteUInt32(0); // Version
writer.WriteUInt16(directory.NumberOfNamedEntries);
writer.WriteUInt16(directory.NumberOfIdEntries);
uint n = (uint)directory.Entries.Count;
uint k = offset + 16 + n * 8;
for (int i = 0; i < n; i++)
{
int id;
string name;
uint nameOffset = (uint)dataWriter.Position + sizeOfDirectoryTree;
uint directoryOffset = k;
Directory subDir = directory.Entries[i] as Directory;
if (subDir != null)
{
id = subDir.ID;
name = subDir.Name;
if (level == 0)
{
k += SizeOfDirectory(subDir);
}
else
{
k += 16 + 8 * (uint)subDir.Entries.Count;
}
}
else
{
//EDMAURER write out an IMAGE_RESOURCE_DATA_ENTRY followed
//immediately by the data that it refers to. This results
//in a layout different than that produced by pulling the resources
//from an OBJ. In that case all of the data bits of a resource are
//contiguous in .rsrc$02. After processing these will end up at
//the end of .rsrc following all of the directory
//info and IMAGE_RESOURCE_DATA_ENTRYs
IWin32Resource r = (IWin32Resource)directory.Entries[i];
id = level == 0 ? r.TypeId : level == 1 ? r.Id : (int)r.LanguageId;
name = level == 0 ? r.TypeName : level == 1 ? r.Name : null;
dataWriter.WriteUInt32((uint)(virtualAddressBase + sizeOfDirectoryTree + 16 + dataWriter.Position));
byte[] data = new List<byte>(r.Data).ToArray();
dataWriter.WriteUInt32((uint)data.Length);
dataWriter.WriteUInt32(r.CodePage);
dataWriter.WriteUInt32(0);
dataWriter.WriteBytes(data);
while ((dataWriter.Count % 4) != 0)
{
dataWriter.WriteByte(0);
}
}
if (id >= 0)
{
writer.WriteInt32(id);
}
else
{
if (name == null)
{
name = string.Empty;
}
writer.WriteUInt32(nameOffset | 0x80000000);
dataWriter.WriteUInt16((ushort)name.Length);
dataWriter.WriteUTF16(name);
}
if (subDir != null)
{
writer.WriteUInt32(directoryOffset | 0x80000000);
}
else
{
writer.WriteUInt32(nameOffset);
}
}
k = offset + 16 + n * 8;
for (int i = 0; i < n; i++)
{
Directory subDir = directory.Entries[i] as Directory;
if (subDir != null)
{
this.WriteDirectory(subDir, writer, k, level + 1, sizeOfDirectoryTree, virtualAddressBase, dataWriter);
if (level == 0)
{
k += SizeOfDirectory(subDir);
}
else
{
k += 16 + 8 * (uint)subDir.Entries.Count;
}
}
}
}
示例10: LinkSuffix1
public void LinkSuffix1()
{
var builder1 = new BlobBuilder(16);
builder1.WriteByte(1);
builder1.WriteByte(2);
builder1.WriteByte(3);
var builder2 = new BlobBuilder(16);
builder2.WriteByte(4);
builder1.LinkSuffix(builder2);
AssertEx.Equal(new byte[] { 1, 2, 3, 4 }, builder1.ToArray());
Assert.Equal(4, builder1.Count);
Assert.Equal(1, builder2.Count);
var builder3 = new BlobBuilder(16);
builder3.WriteByte(5);
var builder4 = new BlobBuilder(16);
builder4.WriteByte(6);
builder3.LinkSuffix(builder4);
builder1.LinkSuffix(builder3);
AssertEx.Equal(new byte[] { 1, 2, 3, 4, 5, 6 }, builder1.ToArray());
Assert.Equal(6, builder1.Count);
Assert.Equal(2, builder3.Count);
Assert.Equal(1, builder4.Count);
}
示例11: WritePEHeader
private void WritePEHeader(BlobBuilder builder, PEDirectoriesBuilder headers, ImmutableArray<SerializedSection> sections)
{
builder.WriteUInt16((ushort)(Is32Bit ? PEMagic.PE32 : PEMagic.PE32Plus));
builder.WriteByte(MajorLinkerVersion);
builder.WriteByte(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)headers.AddressOfEntryPoint);
// BaseOfCode:
int codeSectionIndex = IndexOfSection(sections, SectionCharacteristics.ContainsCode);
builder.WriteUInt32((uint)(codeSectionIndex != -1 ? sections[codeSectionIndex].RelativeVirtualAddress : 0));
if (Is32Bit)
{
// BaseOfData:
int dataSectionIndex = IndexOfSection(sections, SectionCharacteristics.ContainsInitializedData);
builder.WriteUInt32((uint)(dataSectionIndex != -1 ? sections[dataSectionIndex].RelativeVirtualAddress : 0));
builder.WriteUInt32((uint)ImageBase);
}
else
{
builder.WriteUInt64(ImageBase);
}
// NT additional fields:
builder.WriteUInt32((uint)SectionAlignment);
builder.WriteUInt32((uint)FileAlignment);
builder.WriteUInt16(MajorOperatingSystemVersion);
builder.WriteUInt16(MinorOperatingSystemVersion);
builder.WriteUInt16(MajorImageVersion);
builder.WriteUInt16(MinorImageVersion);
builder.WriteUInt16(MajorSubsystemVersion);
builder.WriteUInt16(MinorSubsystemVersion);
// Win32VersionValue (reserved, should be 0)
builder.WriteUInt32(0);
// SizeOfImage:
var lastSection = sections[sections.Length - 1];
builder.WriteUInt32((uint)BitArithmeticUtilities.Align(lastSection.RelativeVirtualAddress + lastSection.VirtualSize, SectionAlignment));
// SizeOfHeaders:
builder.WriteUInt32((uint)BitArithmeticUtilities.Align(ComputeSizeOfPeHeaders(sections.Length, Is32Bit), FileAlignment));
// Checksum (TODO: not supported):
builder.WriteUInt32(0);
builder.WriteUInt16((ushort)Subsystem);
builder.WriteUInt16((ushort)DllCharacteristics);
if (Is32Bit)
{
builder.WriteUInt32((uint)SizeOfStackReserve);
builder.WriteUInt32((uint)SizeOfStackCommit);
builder.WriteUInt32((uint)SizeOfHeapReserve);
builder.WriteUInt32((uint)SizeOfHeapCommit);
}
else
{
builder.WriteUInt64(SizeOfStackReserve);
builder.WriteUInt64(SizeOfStackCommit);
builder.WriteUInt64(SizeOfHeapReserve);
builder.WriteUInt64(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)headers.ExportTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)headers.ExportTable.Size);
builder.WriteUInt32((uint)headers.ImportTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)headers.ImportTable.Size);
builder.WriteUInt32((uint)headers.ResourceTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)headers.ResourceTable.Size);
builder.WriteUInt32((uint)headers.ExceptionTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)headers.ExceptionTable.Size);
builder.WriteUInt32((uint)headers.CertificateTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)headers.CertificateTable.Size);
builder.WriteUInt32((uint)headers.BaseRelocationTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)headers.BaseRelocationTable.Size);
builder.WriteUInt32((uint)headers.DebugTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)headers.DebugTable.Size);
builder.WriteUInt32((uint)headers.CopyrightTable.RelativeVirtualAddress);
builder.WriteUInt32((uint)headers.CopyrightTable.Size);
builder.WriteUInt32((uint)headers.GlobalPointerTable.RelativeVirtualAddress);
//.........这里部分代码省略.........
示例12: WritePrimitiveType
internal static void WritePrimitiveType(BlobBuilder builder, PrimitiveTypeCode type)
{
switch (type)
{
case PrimitiveTypeCode.Boolean:
case PrimitiveTypeCode.Byte:
case PrimitiveTypeCode.SByte:
case PrimitiveTypeCode.Char:
case PrimitiveTypeCode.Int16:
case PrimitiveTypeCode.UInt16:
case PrimitiveTypeCode.Int32:
case PrimitiveTypeCode.UInt32:
case PrimitiveTypeCode.Int64:
case PrimitiveTypeCode.UInt64:
case PrimitiveTypeCode.Single:
case PrimitiveTypeCode.Double:
case PrimitiveTypeCode.IntPtr:
case PrimitiveTypeCode.UIntPtr:
case PrimitiveTypeCode.String:
case PrimitiveTypeCode.Object:
builder.WriteByte((byte)type);
return;
// TODO: should we allow these?
case PrimitiveTypeCode.TypedReference:
case PrimitiveTypeCode.Void:
default:
Throw.ArgumentOutOfRange(nameof(type));
return;
}
}
示例13: 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());
}
示例14: WritePrimitive
public void WritePrimitive()
{
var writer = new BlobBuilder(17);
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);
var guid = new Guid("01020304-0506-0708-090A-0B0C0D0E0F10");
writer.WriteBytes(guid.ToByteArray());
writer.WriteGuid(guid);
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,
0x04, 0x03, 0x02, 0x01, 0x06, 0x05, 0x08, 0x07, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
0x04, 0x03, 0x02, 0x01, 0x06, 0x05, 0x08, 0x07, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
}, writer.ToArray());
}
示例15: Link
public void Link()
{
var builder1 = new BlobBuilder(16);
builder1.WriteByte(1);
var builder2 = new BlobBuilder(16);
builder2.WriteByte(2);
var builder3 = new BlobBuilder(16);
builder3.WriteByte(3);
var builder4 = new BlobBuilder(16);
builder4.WriteByte(4);
var builder5 = new BlobBuilder(16);
builder5.WriteByte(5);
builder2.LinkPrefix(builder1);
AssertEx.Equal(new byte[] { 1, 2 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder1.ToArray());
Assert.Throws<InvalidOperationException>(() => builder2.LinkPrefix(builder1));
Assert.Throws<InvalidOperationException>(() => builder1.WriteByte(0xff));
Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(1, 10));
Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(new byte[] { 1 }));
Assert.Throws<InvalidOperationException>(() => builder1.ReserveBytes(1));
Assert.Throws<InvalidOperationException>(() => builder1.GetBlobs());
Assert.Throws<InvalidOperationException>(() => builder1.ContentEquals(builder1));
Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF16("str"));
Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF8("str", allowUnpairedSurrogates: false));
builder2.LinkSuffix(builder3);
AssertEx.Equal(new byte[] { 1, 2, 3 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder3.LinkPrefix(builder5));
builder2.LinkPrefix(builder4);
AssertEx.Equal(new byte[] { 4, 1, 2, 3 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder4.LinkPrefix(builder5));
builder2.LinkSuffix(builder5);
AssertEx.Equal(new byte[] { 4, 1, 2, 3, 5 }, builder2.ToArray());
}