本文整理汇总了C#中System.Reflection.Metadata.BlobReader.ReadInt32方法的典型用法代码示例。如果您正苦于以下问题:C# BlobReader.ReadInt32方法的具体用法?C# BlobReader.ReadInt32怎么用?C# BlobReader.ReadInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.BlobReader
的用法示例。
在下文中一共展示了BlobReader.ReadInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ReadCodeViewDebugDirectoryData
/// <summary>
/// Reads the data pointed to by the specified Debug Directory entry and interprets them as CodeView.
/// </summary>
/// <exception cref="ArgumentException"><paramref name="entry"/> is not a CodeView entry.</exception>
/// <exception cref="BadImageFormatException">Bad format of the data.</exception>
/// <exception cref="IOException">IO error while reading from the underlying stream.</exception>
public unsafe CodeViewDebugDirectoryData ReadCodeViewDebugDirectoryData(DebugDirectoryEntry entry)
{
if (entry.Type != DebugDirectoryEntryType.CodeView)
{
throw new ArgumentException(SR.NotCodeViewEntry, nameof(entry));
}
using (AbstractMemoryBlock block = _peImage.GetMemoryBlock(entry.DataPointer, entry.DataSize))
{
var reader = new BlobReader(block.Pointer, block.Size);
if (reader.ReadByte() != (byte)'R' ||
reader.ReadByte() != (byte)'S' ||
reader.ReadByte() != (byte)'D' ||
reader.ReadByte() != (byte)'S')
{
throw new BadImageFormatException(SR.UnexpectedCodeViewDataSignature);
}
Guid guid = reader.ReadGuid();
int age = reader.ReadInt32();
string path = reader.ReadUtf8NullTerminated();
// path may be padded with NULs
while (reader.RemainingBytes > 0)
{
if (reader.ReadByte() != 0)
{
throw new BadImageFormatException(SR.InvalidPathPadding);
}
}
return new CodeViewDebugDirectoryData(guid, age, path);
}
}
示例5: 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();
}
示例6: 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);
}
示例7: 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();
}
}
示例8: 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();
}
}
示例9: 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);
}
示例10: 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);
}
示例11: ReadFatExceptionHandlers
private static ImmutableArray<ExceptionRegion> ReadFatExceptionHandlers(ref BlobReader memReader, int count)
{
var result = new ExceptionRegion[count];
for (int i = 0; i < result.Length; i++)
{
var sehFlags = (ExceptionRegionKind)memReader.ReadUInt32();
int tryOffset = memReader.ReadInt32();
int tryLength = memReader.ReadInt32();
int handlerOffset = memReader.ReadInt32();
int handlerLength = memReader.ReadInt32();
int classTokenOrFilterOffset = memReader.ReadInt32();
result[i] = new ExceptionRegion(sehFlags, tryOffset, tryLength, handlerOffset, handlerLength, classTokenOrFilterOffset);
}
return ImmutableArray.Create(result);
}
示例12: DynamicAnalysisDataReader
public DynamicAnalysisDataReader(byte* buffer, int size)
{
var reader = new BlobReader(buffer, size);
// header:
if (reader.ReadByte() != 'D' || reader.ReadByte() != 'A' || reader.ReadByte() != 'M' || reader.ReadByte() != 'D')
{
throw new BadImageFormatException();
}
// version
byte major = reader.ReadByte();
byte minor = reader.ReadByte();
if (major != 0 || minor < 1 || minor > 2)
{
throw new NotSupportedException();
}
// table sizes:
int documentRowCount = reader.ReadInt32();
int methodSpanRowCount = reader.ReadInt32();
// blob heap sizes:
int stringHeapSize = (minor == 1) ? reader.ReadInt32() : 0;
int userStringHeapSize = (minor == 1) ? reader.ReadInt32() : 0;
int guidHeapSize = reader.ReadInt32();
int blobHeapSize = reader.ReadInt32();
// TODO: check size ranges
bool isBlobHeapSmall = blobHeapSize <= ushort.MaxValue;
bool isGuidHeapSmall = guidHeapSize / GuidSize <= ushort.MaxValue;
var documentsBuilder = ArrayBuilder<DynamicAnalysisDocument>.GetInstance(documentRowCount);
for (int i = 0; i < documentRowCount; i++)
{
var name = MetadataTokens.BlobHandle(ReadReference(ref reader, isBlobHeapSmall));
var hashAlgorithm = MetadataTokens.GuidHandle(ReadReference(ref reader, isGuidHeapSmall));
var hash = MetadataTokens.BlobHandle(ReadReference(ref reader, isBlobHeapSmall));
documentsBuilder.Add(new DynamicAnalysisDocument(name, hashAlgorithm, hash));
}
Documents = documentsBuilder.ToImmutableAndFree();
var methodsBuilder = ArrayBuilder<DynamicAnalysisMethod>.GetInstance(methodSpanRowCount);
for (int i = 0; i < methodSpanRowCount; i++)
{
methodsBuilder.Add(new DynamicAnalysisMethod(MetadataTokens.BlobHandle(ReadReference(ref reader, isBlobHeapSmall))));
}
Methods = methodsBuilder.ToImmutableAndFree();
int stringHeapOffset = reader.Offset;
int userStringHeapOffset = stringHeapOffset + stringHeapSize;
int guidHeapOffset = userStringHeapOffset + userStringHeapSize;
int blobHeapOffset = guidHeapOffset + guidHeapSize;
if (reader.Length != blobHeapOffset + blobHeapSize)
{
throw new BadImageFormatException();
}
_guidHeapBlob = new Blob(buffer + guidHeapOffset, guidHeapSize);
_blobHeapBlob = new Blob(buffer + blobHeapOffset, blobHeapSize);
}
示例13: ReadReference
private static int ReadReference(ref BlobReader reader, bool smallRefSize)
{
return smallRefSize ? reader.ReadUInt16() : reader.ReadInt32();
}
示例14: NativeResources
public unsafe void NativeResources()
{
var peStream = new MemoryStream();
var ilBuilder = new BlobBuilder();
var metadataBuilder = new MetadataBuilder();
var peBuilder = new ManagedPEBuilder(
PEHeaderBuilder.CreateLibraryHeader(),
new MetadataRootBuilder(metadataBuilder),
ilBuilder,
nativeResources: new TestResourceSectionBuilder(),
deterministicIdProvider: content => s_contentId);
var peBlob = new BlobBuilder();
var contentId = peBuilder.Serialize(peBlob);
peBlob.WriteContentTo(peStream);
peStream.Position = 0;
var peReader = new PEReader(peStream);
var sectionHeader = peReader.PEHeaders.SectionHeaders.Single(s => s.Name == ".rsrc");
var image = peReader.GetEntireImage();
var reader = new BlobReader(image.Pointer + sectionHeader.PointerToRawData, sectionHeader.SizeOfRawData);
Assert.Equal(0x12345678, reader.ReadInt32());
Assert.Equal(sectionHeader.PointerToRawData, reader.ReadInt32());
Assert.Equal(sectionHeader.VirtualAddress, reader.ReadInt32());
}
示例15: DecodeEmbeddedPortablePdbDebugDirectoryData
// internal for testing
internal static unsafe ImmutableArray<byte> DecodeEmbeddedPortablePdbDebugDirectoryData(AbstractMemoryBlock block)
{
byte[] decompressed;
const int headerSize = 2 * sizeof(int);
var headerReader = new BlobReader(block.Pointer, headerSize);
if (headerReader.ReadUInt32() != PortablePdbVersions.DebugDirectoryEmbeddedSignature)
{
throw new BadImageFormatException(SR.UnexpectedEmbeddedPortablePdbDataSignature);
}
int decompressedSize = headerReader.ReadInt32();
try
{
decompressed = new byte[decompressedSize];
}
catch
{
throw new BadImageFormatException(SR.DataTooBig);
}
var compressed = new ReadOnlyUnmanagedMemoryStream(block.Pointer + headerSize, block.Size - headerSize);
var deflate = new DeflateStream(compressed, CompressionMode.Decompress, leaveOpen: true);
if (decompressedSize > 0)
{
int actualLength;
try
{
actualLength = deflate.TryReadAll(decompressed, 0, decompressed.Length);
}
catch (InvalidDataException e)
{
throw new BadImageFormatException(e.Message, e.InnerException);
}
if (actualLength != decompressed.Length)
{
throw new BadImageFormatException(SR.SizeMismatch);
}
}
// Check that there is no more compressed data left,
// in case the decompressed size specified in the header is smaller
// than the actual decompressed size of the data.
if (deflate.ReadByte() != -1)
{
throw new BadImageFormatException(SR.SizeMismatch);
}
return ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref decompressed);
}