本文整理汇总了C#中System.Reflection.Metadata.BlobReader.ReadUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# BlobReader.ReadUInt16方法的具体用法?C# BlobReader.ReadUInt16怎么用?C# BlobReader.ReadUInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.BlobReader
的用法示例。
在下文中一共展示了BlobReader.ReadUInt16方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ReadStreamHeaders
/// <summary>
/// Reads stream headers described in Ecma-335 24.2.2 Stream header
/// </summary>
private StreamHeader[] ReadStreamHeaders(ref BlobReader memReader)
{
// storage header:
memReader.ReadUInt16();
int streamCount = memReader.ReadInt16();
var streamHeaders = new StreamHeader[streamCount];
for (int i = 0; i < streamHeaders.Length; i++)
{
if (memReader.RemainingBytes < COR20Constants.MinimumSizeofStreamHeader)
{
throw new BadImageFormatException(MetadataResources.StreamHeaderTooSmall);
}
streamHeaders[i].Offset = memReader.ReadUInt32();
streamHeaders[i].Size = memReader.ReadInt32();
streamHeaders[i].Name = memReader.ReadUtf8NullTerminated();
bool aligned = memReader.TryAlign(4);
if (!aligned || memReader.RemainingBytes == 0)
{
throw new BadImageFormatException(MetadataResources.NotEnoughSpaceForStreamHeaderName);
}
}
return streamHeaders;
}
示例3: ReadMetadataHeader
/// <summary>
/// Looks like this function reads beginning of the header described in
/// Ecma-335 24.2.1 Metadata root
/// </summary>
private void ReadMetadataHeader(ref BlobReader memReader)
{
if (memReader.RemainingBytes < COR20Constants.MinimumSizeofMetadataHeader)
{
throw new BadImageFormatException(MetadataResources.MetadataHeaderTooSmall);
}
this.metadataHeader.Signature = memReader.ReadUInt32();
if (this.metadataHeader.Signature != COR20Constants.COR20MetadataSignature)
{
throw new BadImageFormatException(MetadataResources.MetadataSignature);
}
this.metadataHeader.MajorVersion = memReader.ReadUInt16();
this.metadataHeader.MinorVersion = memReader.ReadUInt16();
this.metadataHeader.ExtraData = memReader.ReadUInt32();
this.metadataHeader.VersionStringSize = memReader.ReadInt32();
if (memReader.RemainingBytes < this.metadataHeader.VersionStringSize)
{
throw new BadImageFormatException(MetadataResources.NotEnoughSpaceForVersionString);
}
int numberOfBytesRead;
this.metadataHeader.VersionString = memReader.GetMemoryBlockAt(0, this.metadataHeader.VersionStringSize).PeekUtf8NullTerminated(0, null, utf8Decoder, out numberOfBytesRead, '\0');
memReader.SkipBytes(this.metadataHeader.VersionStringSize);
this.metadataKind = GetMetadataKind(metadataHeader.VersionString);
}
示例4: ReadDebugDirectoryEntries
internal static ImmutableArray<DebugDirectoryEntry> ReadDebugDirectoryEntries(BlobReader reader)
{
int entryCount = reader.Length / DebugDirectoryEntry.Size;
var builder = ImmutableArray.CreateBuilder<DebugDirectoryEntry>(entryCount);
for (int i = 0; i < entryCount; i++)
{
// Reserved, must be zero.
int characteristics = reader.ReadInt32();
if (characteristics != 0)
{
throw new BadImageFormatException(SR.InvalidDebugDirectoryEntryCharacteristics);
}
uint stamp = reader.ReadUInt32();
ushort majorVersion = reader.ReadUInt16();
ushort minorVersion = reader.ReadUInt16();
var type = (DebugDirectoryEntryType)reader.ReadInt32();
int dataSize = reader.ReadInt32();
int dataRva = reader.ReadInt32();
int dataPointer = reader.ReadInt32();
builder.Add(new DebugDirectoryEntry(stamp, majorVersion, minorVersion, type, dataSize, dataRva, dataPointer));
}
return builder.MoveToImmutable();
}
示例5: ReadMetadataHeader
/// <summary>
/// Looks like this function reads beginning of the header described in
/// ECMA-335 24.2.1 Metadata root
/// </summary>
private void ReadMetadataHeader(ref BlobReader memReader, out string versionString)
{
if (memReader.RemainingBytes < COR20Constants.MinimumSizeofMetadataHeader)
{
throw new BadImageFormatException(SR.MetadataHeaderTooSmall);
}
uint signature = memReader.ReadUInt32();
if (signature != COR20Constants.COR20MetadataSignature)
{
throw new BadImageFormatException(SR.MetadataSignature);
}
// major version
memReader.ReadUInt16();
// minor version
memReader.ReadUInt16();
// reserved:
memReader.ReadUInt32();
int versionStringSize = memReader.ReadInt32();
if (memReader.RemainingBytes < versionStringSize)
{
throw new BadImageFormatException(SR.NotEnoughSpaceForVersionString);
}
int numberOfBytesRead;
versionString = memReader.GetMemoryBlockAt(0, versionStringSize).PeekUtf8NullTerminated(0, null, UTF8Decoder, out numberOfBytesRead, '\0');
memReader.SkipBytes(versionStringSize);
}
示例6: 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();
}
}
示例7: ReadDebugDirectory
/// <summary>
/// Reads all Debug Directory table entries.
/// </summary>
/// <exception cref="BadImageFormatException">Bad format of the entry.</exception>
public unsafe ImmutableArray<DebugDirectoryEntry> ReadDebugDirectory()
{
var debugDirectory = PEHeaders.PEHeader.DebugTableDirectory;
if (debugDirectory.Size == 0)
{
return ImmutableArray<DebugDirectoryEntry>.Empty;
}
int position;
if (!PEHeaders.TryGetDirectoryOffset(debugDirectory, out position))
{
throw new BadImageFormatException(SR.InvalidDirectoryRVA);
}
const int entrySize = 0x1c;
if (debugDirectory.Size % entrySize != 0)
{
throw new BadImageFormatException(SR.InvalidDirectorySize);
}
using (AbstractMemoryBlock block = _peImage.GetMemoryBlock(position, debugDirectory.Size))
{
var reader = new BlobReader(block.Pointer, block.Size);
int entryCount = debugDirectory.Size / entrySize;
var builder = ImmutableArray.CreateBuilder<DebugDirectoryEntry>(entryCount);
for (int i = 0; i < entryCount; i++)
{
// Reserved, must be zero.
int characteristics = reader.ReadInt32();
if (characteristics != 0)
{
throw new BadImageFormatException(SR.InvalidDebugDirectoryEntryCharacteristics);
}
uint stamp = reader.ReadUInt32();
ushort majorVersion = reader.ReadUInt16();
ushort minorVersion = reader.ReadUInt16();
var type = (DebugDirectoryEntryType)reader.ReadInt32();
int dataSize = reader.ReadInt32();
int dataRva = reader.ReadInt32();
int dataPointer = reader.ReadInt32();
builder.Add(new DebugDirectoryEntry(stamp, majorVersion, minorVersion, type, dataSize, dataRva, dataPointer));
}
return builder.MoveToImmutable();
}
}
示例8: Create
public static MethodBodyBlock Create(BlobReader reader)
{
int startOffset = reader.Offset;
int ilSize;
// Error need to check if the Memory Block is empty. This is calse for all the calls...
byte headByte = reader.ReadByte();
if ((headByte & ILFormatMask) == ILTinyFormat)
{
// tiny IL can't have locals so technically this shouldn't matter,
// but false is consistent with other metadata readers and helps
// for use cases involving comparing our output with theirs.
const bool initLocalsForTinyIL = false;
ilSize = headByte >> ILTinyFormatSizeShift;
return new MethodBodyBlock(
initLocalsForTinyIL,
8,
default(StandaloneSignatureHandle),
reader.GetMemoryBlockAt(0, ilSize),
ImmutableArray<ExceptionRegion>.Empty,
1 + ilSize // header + IL
);
}
if ((headByte & ILFormatMask) != ILFatFormat)
{
throw new BadImageFormatException(string.Format(MetadataResources.InvalidMethodHeader1, headByte));
}
// FatILFormat
byte headByte2 = reader.ReadByte();
if ((headByte2 >> ILFatFormatHeaderSizeShift) != ILFatFormatHeaderSize)
{
throw new BadImageFormatException(string.Format(MetadataResources.InvalidMethodHeader2, headByte, headByte2));
}
bool localsInitialized = (headByte & ILInitLocals) == ILInitLocals;
bool hasExceptionHandlers = (headByte & ILMoreSects) == ILMoreSects;
ushort maxStack = reader.ReadUInt16();
ilSize = reader.ReadInt32();
int localSignatureToken = reader.ReadInt32();
StandaloneSignatureHandle localSignatureHandle;
if (localSignatureToken == 0)
{
localSignatureHandle = default(StandaloneSignatureHandle);
}
else if ((localSignatureToken & TokenTypeIds.TokenTypeMask) == TokenTypeIds.Signature)
{
localSignatureHandle = StandaloneSignatureHandle.FromRowId((uint)localSignatureToken & TokenTypeIds.RIDMask);
}
else
{
throw new BadImageFormatException(string.Format(MetadataResources.InvalidLocalSignatureToken, unchecked((uint)localSignatureToken)));
}
var ilBlock = reader.GetMemoryBlockAt(0, ilSize);
reader.SkipBytes(ilSize);
ImmutableArray<ExceptionRegion> exceptionHandlers;
if (hasExceptionHandlers)
{
reader.Align(4);
byte sehHeader = reader.ReadByte();
if ((sehHeader & SectEHTable) != SectEHTable)
{
throw new BadImageFormatException(string.Format(MetadataResources.InvalidSehHeader, sehHeader));
}
bool sehFatFormat = (sehHeader & SectFatFormat) == SectFatFormat;
int dataSize = reader.ReadByte();
if (sehFatFormat)
{
dataSize += reader.ReadUInt16() << 8;
exceptionHandlers = ReadFatExceptionHandlers(ref reader, dataSize / 24);
}
else
{
reader.SkipBytes(2); // skip over reserved field
exceptionHandlers = ReadSmallExceptionHandlers(ref reader, dataSize / 12);
}
}
else
{
exceptionHandlers = ImmutableArray<ExceptionRegion>.Empty;
}
return new MethodBodyBlock(
localsInitialized,
maxStack,
localSignatureHandle,
ilBlock,
exceptionHandlers,
reader.Offset - startOffset);
}
示例9: ReadSmallExceptionHandlers
private static ImmutableArray<ExceptionRegion> ReadSmallExceptionHandlers(ref BlobReader memReader, int count)
{
var result = new ExceptionRegion[count];
for (int i = 0; i < result.Length; i++)
{
var kind = (ExceptionRegionKind)memReader.ReadUInt16();
var tryOffset = memReader.ReadUInt16();
var tryLength = memReader.ReadByte();
var handlerOffset = memReader.ReadUInt16();
var handlerLength = memReader.ReadByte();
var classTokenOrFilterOffset = memReader.ReadInt32();
result[i] = new ExceptionRegion(kind, tryOffset, tryLength, handlerOffset, handlerLength, classTokenOrFilterOffset);
}
return ImmutableArray.Create(result);
}
示例10: ReadReference
private static int ReadReference(ref BlobReader reader, bool smallRefSize)
{
return smallRefSize ? reader.ReadUInt16() : reader.ReadInt32();
}