本文整理汇总了C#中System.Reflection.Metadata.BlobReader.ReadUInt64方法的典型用法代码示例。如果您正苦于以下问题:C# BlobReader.ReadUInt64方法的具体用法?C# BlobReader.ReadUInt64怎么用?C# BlobReader.ReadUInt64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.BlobReader
的用法示例。
在下文中一共展示了BlobReader.ReadUInt64方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInstructions
public static ILResult GetInstructions(BlobReader reader)
{
var instructions = ImmutableArray.CreateBuilder<Instruction>();
List<int[]> switches = null;
while (reader.RemainingBytes > 0)
{
ushort pos = (ushort)reader.Offset;
byte op0 = reader.ReadByte();
InstrCode code = (InstrCode)(op0 == 0xFE ? unchecked(0xFE00 + reader.ReadByte()) : op0);
OperandType opType = code.GetOperandType();
ulong operand = 0;
if (code == InstrCode.Switch)
{
if (switches == null)
switches = new List<int[]>();
operand = (ulong)switches.Count;
uint branchCount = reader.ReadUInt32();
int[] branches = new int[branchCount];
for (int i = 0; i < branchCount; i++)
{
branches[i] = reader.ReadInt32();
}
switches.Add(branches);
}
else
{
byte operandSize = opType.GetOperandSize();
operand = operandSize == 8 ? reader.ReadUInt64()
: operandSize == 4 ? reader.ReadUInt32()
: operandSize == 2 ? reader.ReadUInt16()
: operandSize == 1 ? (ulong)reader.ReadByte()
: 0;
}
instructions.Add(new Instruction(pos, code, opType, operand));
}
return new ILResult
{
Instructions = instructions.ToImmutable(),
Switches = switches?.ToArray()
};
}
示例2: ReadMetadataTableHeader
private void ReadMetadataTableHeader(ref BlobReader memReader, out uint[] metadataTableRowCounts)
{
if (memReader.RemainingBytes < MetadataStreamConstants.SizeOfMetadataTableHeader)
{
throw new BadImageFormatException(MetadataResources.MetadataTableHeaderTooSmall);
}
this.MetadataTableHeader.Reserved = memReader.ReadUInt32();
this.MetadataTableHeader.MajorVersion = memReader.ReadByte();
this.MetadataTableHeader.MinorVersion = memReader.ReadByte();
this.MetadataTableHeader.HeapSizeFlags = (HeapSizeFlag)memReader.ReadByte();
this.MetadataTableHeader.RowId = memReader.ReadByte();
this.MetadataTableHeader.ValidTables = (TableMask)memReader.ReadUInt64();
this.MetadataTableHeader.SortedTables = (TableMask)memReader.ReadUInt64();
ulong presentTables = (ulong)this.MetadataTableHeader.ValidTables;
// According to ECMA-335, MajorVersion and MinorVersion have fixed values and,
// based on recommendation in 24.1 Fixed fields: When writing these fields it
// is best that they be set to the value indicated, on reading they should be ignored.?
// we will not be checking version values. We will continue checking that the set of
// present tables is within the set we understand.
ulong validTables = (ulong)TableMask.V2_0_TablesMask;
if ((presentTables & ~validTables) != 0)
{
throw new BadImageFormatException(string.Format(MetadataResources.UnknownTables, presentTables));
}
if (this.metadataStreamKind == MetadataStreamKind.Compressed)
{
// In general Ptr tables and EnC tables are not allowed in a compressed stream.
// However when asked for a snapshot of the current metadata after an EnC change has been applied
// the CLR includes the EnCLog table into the snapshot. We need to be able to read the image,
// so we'll allow the table here but pretend it's empty later.
if ((presentTables & (ulong)(TableMask.PtrTables | TableMask.EnCMap)) != 0)
{
throw new BadImageFormatException(MetadataResources.IllegalTablesInCompressedMetadataStream);
}
}
int numberOfTables = this.MetadataTableHeader.GetNumberOfTablesPresent();
if (memReader.RemainingBytes < numberOfTables * sizeof(int))
{
throw new BadImageFormatException(MetadataResources.TableRowCountSpaceTooSmall);
}
var rowCounts = new uint[numberOfTables];
for (int i = 0; i < rowCounts.Length; i++)
{
rowCounts[i] = memReader.ReadUInt32();
}
metadataTableRowCounts = rowCounts;
}
示例3: ReadStandalonePortablePdbStream
// internal for testing
internal static void ReadStandalonePortablePdbStream(MemoryBlock block, out DebugMetadataHeader debugMetadataHeader, out int[] externalTableRowCounts)
{
var reader = new BlobReader(block);
const int PdbIdSize = 20;
byte[] pdbId = reader.ReadBytes(PdbIdSize);
// ECMA-335 15.4.1.2:
// The entry point to an application shall be static.
// This entry point method can be a global method or it can appear inside a type.
// The entry point method shall either accept no arguments or a vector of strings.
// The return type of the entry point method shall be void, int32, or unsigned int32.
// The entry point method cannot be defined in a generic class.
uint entryPointToken = reader.ReadUInt32();
int entryPointRowId = (int)(entryPointToken & TokenTypeIds.RIDMask);
if (entryPointToken != 0 && ((entryPointToken & TokenTypeIds.TypeMask) != TokenTypeIds.MethodDef || entryPointRowId == 0))
{
throw new BadImageFormatException(string.Format(SR.InvalidEntryPointToken, entryPointToken));
}
ulong externalTableMask = reader.ReadUInt64();
// EnC & Ptr tables can't be referenced from standalone PDB metadata:
const ulong validTables = (ulong)TableMask.ValidPortablePdbExternalTables;
if ((externalTableMask & ~validTables) != 0)
{
throw new BadImageFormatException(string.Format(SR.UnknownTables, (TableMask)externalTableMask));
}
externalTableRowCounts = ReadMetadataTableRowCounts(ref reader, externalTableMask);
debugMetadataHeader = new DebugMetadataHeader(
ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref pdbId),
MethodDefinitionHandle.FromRowId(entryPointRowId));
}
示例4: ReadMetadataTableHeader
private void ReadMetadataTableHeader(ref BlobReader reader, out HeapSizes heapSizes, out int[] metadataTableRowCounts, out TableMask sortedTables)
{
if (reader.RemainingBytes < MetadataStreamConstants.SizeOfMetadataTableHeader)
{
throw new BadImageFormatException(SR.MetadataTableHeaderTooSmall);
}
// reserved (shall be ignored):
reader.ReadUInt32();
// major version (shall be ignored):
reader.ReadByte();
// minor version (shall be ignored):
reader.ReadByte();
// heap sizes:
heapSizes = (HeapSizes)reader.ReadByte();
// reserved (shall be ignored):
reader.ReadByte();
ulong presentTables = reader.ReadUInt64();
sortedTables = (TableMask)reader.ReadUInt64();
// According to ECMA-335, MajorVersion and MinorVersion have fixed values and,
// based on recommendation in 24.1 Fixed fields: When writing these fields it
// is best that they be set to the value indicated, on reading they should be ignored.
// We will not be checking version values. We will continue checking that the set of
// present tables is within the set we understand.
ulong validTables = (ulong)(TableMask.TypeSystemTables | TableMask.DebugTables);
if ((presentTables & ~validTables) != 0)
{
throw new BadImageFormatException(SR.Format(SR.UnknownTables, presentTables));
}
if (_metadataStreamKind == MetadataStreamKind.Compressed)
{
// In general Ptr tables and EnC tables are not allowed in a compressed stream.
// However when asked for a snapshot of the current metadata after an EnC change has been applied
// the CLR includes the EnCLog table into the snapshot. We need to be able to read the image,
// so we'll allow the table here but pretend it's empty later.
if ((presentTables & (ulong)(TableMask.PtrTables | TableMask.EnCMap)) != 0)
{
throw new BadImageFormatException(SR.IllegalTablesInCompressedMetadataStream);
}
}
metadataTableRowCounts = ReadMetadataTableRowCounts(ref reader, presentTables);
if ((heapSizes & HeapSizes.ExtraData) == HeapSizes.ExtraData)
{
// Skip "extra data" used by some obfuscators. Although it is not mentioned in the CLI spec,
// it is honored by the native metadata reader.
reader.ReadUInt32();
}
}
示例5: ReadAndTranslateValue
private object ReadAndTranslateValue(ref BlobReader sigReader, SignatureTypeCode typeCode, out bool isEnumTypeCode)
{
switch (typeCode)
{
case SignatureTypeCode.Boolean:
isEnumTypeCode = true;
return (short)(sigReader.ReadBoolean() ? 1 : 0);
case SignatureTypeCode.Char:
isEnumTypeCode = true;
return (ushort)sigReader.ReadChar();
case SignatureTypeCode.SByte:
isEnumTypeCode = true;
return (short)sigReader.ReadSByte();
case SignatureTypeCode.Byte:
isEnumTypeCode = true;
return (short)sigReader.ReadByte();
case SignatureTypeCode.Int16:
isEnumTypeCode = true;
return sigReader.ReadInt16();
case SignatureTypeCode.UInt16:
isEnumTypeCode = true;
return sigReader.ReadUInt16();
case SignatureTypeCode.Int32:
isEnumTypeCode = true;
return sigReader.ReadInt32();
case SignatureTypeCode.UInt32:
isEnumTypeCode = true;
return sigReader.ReadUInt32();
case SignatureTypeCode.Int64:
isEnumTypeCode = true;
return sigReader.ReadInt64();
case SignatureTypeCode.UInt64:
isEnumTypeCode = true;
return sigReader.ReadUInt64();
case SignatureTypeCode.Single:
isEnumTypeCode = false;
return sigReader.ReadSingle();
case SignatureTypeCode.Double:
isEnumTypeCode = false;
return sigReader.ReadDouble();
case SignatureTypeCode.String:
isEnumTypeCode = false;
if (sigReader.RemainingBytes == 1)
{
if (sigReader.ReadByte() != 0xff)
{
throw new BadImageFormatException();
}
return NullReferenceValue;
}
if (sigReader.RemainingBytes % 2 != 0)
{
throw new BadImageFormatException();
}
return sigReader.ReadUTF16(sigReader.RemainingBytes);
case SignatureTypeCode.Object:
// null reference
isEnumTypeCode = false;
return NullReferenceValue;
default:
throw new BadImageFormatException();
}
}