当前位置: 首页>>代码示例>>C#>>正文


C# MemoryReader.ReadByte方法代码示例

本文整理汇总了C#中Microsoft.Cci.UtilityDataStructures.MemoryReader.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryReader.ReadByte方法的具体用法?C# MemoryReader.ReadByte怎么用?C# MemoryReader.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Cci.UtilityDataStructures.MemoryReader的用法示例。


在下文中一共展示了MemoryReader.ReadByte方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMethodIL

 internal MethodIL/*?*/ GetMethodIL(
   uint methodDefRowId
 ) {
   MethodRow methodRow = this.MethodTable[methodDefRowId];
   if (
     (methodRow.ImplFlags & MethodImplFlags.CodeTypeMask) != MethodImplFlags.ILCodeType
     || methodRow.RVA == 0
   ) {
     return null;
   }
   MemoryBlock memBlock = this.RVAToMemoryBlock(methodRow.RVA);
   //  Error need to check if the Memory Block is empty. This is calse for all the calls...
   MemoryReader memReader = new MemoryReader(memBlock);
   byte headByte = memReader.ReadByte();
   if ((headByte & CILMethodFlags.ILFormatMask) == CILMethodFlags.ILTinyFormat) {
     int size = headByte >> CILMethodFlags.ILTinyFormatSizeShift;
     return new MethodIL(
       true,
       8,
       0x00000000,
       memReader.GetMemoryBlockAt(0, size),
       null
     );
   } else if ((headByte & CILMethodFlags.ILFormatMask) != CILMethodFlags.ILFatFormat) {
     //  PEFileFormat Error...
     return null;
   }
   //  FatILFormat
   byte headByte2 = memReader.ReadByte();
   if ((headByte2 >> CILMethodFlags.ILFatFormatHeaderSizeShift) != CILMethodFlags.ILFatFormatHeaderSize) {
     //  PEFile Format Error...
     return null;
   }
   bool localVarInited = (headByte & CILMethodFlags.ILInitLocals) == CILMethodFlags.ILInitLocals;
   bool moreSectsPresent = (headByte & CILMethodFlags.ILMoreSects) == CILMethodFlags.ILMoreSects;
   ushort maxStack = memReader.ReadUInt16();
   int codeSize = memReader.ReadInt32();
   uint localSignatureToken = memReader.ReadUInt32();
   MemoryBlock ilCodeMemBlock = memReader.GetMemoryBlockAt(0, codeSize);
   SEHTableEntry[]/*?*/ sehTableEntries = null;
   if (moreSectsPresent) {
     memReader.SkipBytes(codeSize);
     memReader.Align(4);
     byte sectHeader = memReader.ReadByte();
     if ((sectHeader & CILMethodFlags.SectEHTable) != CILMethodFlags.SectEHTable) {
       //  PEFile Format Error...
       return null;
     }
     bool sectFatFormat = (sectHeader & CILMethodFlags.SectFatFormat) == CILMethodFlags.SectFatFormat;
     int dataSize = memReader.ReadByte();
     if (sectFatFormat) {
       dataSize += (int)memReader.ReadUInt16() << 8;
       sehTableEntries = PEFileReader.GetFatSEHEntries(memReader, dataSize / 24);
     } else {
       memReader.SkipBytes(2); //skip over reserved field
       sehTableEntries = PEFileReader.GetSmallSEHEntries(memReader, dataSize / 12);
     }
   }
   return new MethodIL(
     localVarInited,
     maxStack,
     localSignatureToken,
     ilCodeMemBlock,
     sehTableEntries
   );
 }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:66,代码来源:PEFileReader.cs

示例2: PopulateCilInstructions

 bool PopulateCilInstructions() {
   MethodBodyDocument document = new MethodBodyDocument(this.MethodDefinition);
   MemoryReader memReader = new MemoryReader(this.MethodIL.EncodedILMemoryBlock);
   var numInstructions = CountCilInstructions(memReader);
   if (numInstructions == 0) return true;
   CilInstruction[] instrList = new CilInstruction[numInstructions];
   int instructionNumber = 0;
   while (memReader.NotEndOfBytes) {
     object/*?*/ value = null;
     uint offset = (uint)memReader.Offset;
     OperationCode cilOpCode = memReader.ReadOpcode();
     switch (cilOpCode) {
       case OperationCode.Nop:
       case OperationCode.Break:
         break;
       case OperationCode.Ldarg_0:
       case OperationCode.Ldarg_1:
       case OperationCode.Ldarg_2:
       case OperationCode.Ldarg_3:
         value = this.GetParameter((uint)(cilOpCode - OperationCode.Ldarg_0));
         break;
       case OperationCode.Ldloc_0:
       case OperationCode.Ldloc_1:
       case OperationCode.Ldloc_2:
       case OperationCode.Ldloc_3:
         value = this.GetLocal((uint)(cilOpCode - OperationCode.Ldloc_0));
         break;
       case OperationCode.Stloc_0:
       case OperationCode.Stloc_1:
       case OperationCode.Stloc_2:
       case OperationCode.Stloc_3:
         value = this.GetLocal((uint)(cilOpCode - OperationCode.Stloc_0));
         break;
       case OperationCode.Ldarg_S:
       case OperationCode.Ldarga_S:
       case OperationCode.Starg_S:
         value = this.GetParameter(memReader.ReadByte());
         break;
       case OperationCode.Ldloc_S:
       case OperationCode.Ldloca_S:
       case OperationCode.Stloc_S:
         value = this.GetLocal(memReader.ReadByte());
         break;
       case OperationCode.Ldnull:
       case OperationCode.Ldc_I4_M1:
       case OperationCode.Ldc_I4_0:
       case OperationCode.Ldc_I4_1:
       case OperationCode.Ldc_I4_2:
       case OperationCode.Ldc_I4_3:
       case OperationCode.Ldc_I4_4:
       case OperationCode.Ldc_I4_5:
       case OperationCode.Ldc_I4_6:
       case OperationCode.Ldc_I4_7:
       case OperationCode.Ldc_I4_8:
         break;
       case OperationCode.Ldc_I4_S:
         value = (int)memReader.ReadSByte();
         break;
       case OperationCode.Ldc_I4:
         value = memReader.ReadInt32();
         break;
       case OperationCode.Ldc_I8:
         value = memReader.ReadInt64();
         break;
       case OperationCode.Ldc_R4:
         value = memReader.ReadSingle();
         break;
       case OperationCode.Ldc_R8:
         value = memReader.ReadDouble();
         break;
       case OperationCode.Dup:
       case OperationCode.Pop:
         break;
       case OperationCode.Jmp:
         value = this.GetMethod(memReader.ReadUInt32());
         break;
       case OperationCode.Call: {
           IMethodReference methodReference = this.GetMethod(memReader.ReadUInt32());
           IArrayTypeReference/*?*/ arrayType = methodReference.ContainingType as IArrayTypeReference;
           if (arrayType != null) {
             // For Get(), Set() and Address() on arrays, the runtime provides method implementations.
             // Hence, CCI2 replaces these with pseudo instrcutions Array_Set, Array_Get and Array_Addr.
             // All other methods on arrays will not use pseudo instruction and will have methodReference as their operand. 
             if (methodReference.Name.UniqueKey == this.PEFileToObjectModel.NameTable.Set.UniqueKey) {
               cilOpCode = OperationCode.Array_Set;
               value = arrayType;
             } else if (methodReference.Name.UniqueKey == this.PEFileToObjectModel.NameTable.Get.UniqueKey) {
               cilOpCode = OperationCode.Array_Get;
               value = arrayType;
             } else if (methodReference.Name.UniqueKey == this.PEFileToObjectModel.NameTable.Address.UniqueKey) {
               cilOpCode = OperationCode.Array_Addr;
               value = arrayType;
             } else {
               value = methodReference;
             }
           } else {
             value = methodReference;
           }
         }
         break;
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:101,代码来源:ILReader.cs

示例3: ReadMetadataTableInformation

 bool ReadMetadataTableInformation(
   ref MemoryReader memReader
 )
   //^ requires this.ReaderState >= ReaderState.CORModule;
 {
   if (memReader.RemainingBytes < MetadataStreamConstants.SizeOfMetadataTableHeader) {
     this.ErrorContainer.AddMetadataStreamError(this.MetadataStreamName, 0, MetadataReaderErrorKind.MetadataTableHeaderTooSmall);
     return false;
   }
   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;
   ulong validTablesForVersion = 0;
   int version = this.MetadataTableHeader.MajorVersion << 16 | this.MetadataTableHeader.MinorVersion;
   switch (version) {
     case 0x00010000:
       validTablesForVersion = (ulong)TableMask.V1_0_TablesMask;
       break;
     case 0x00010001:
       validTablesForVersion = (ulong)TableMask.V1_1_TablesMask;
       break;
     case 0x00020000:
       validTablesForVersion = (ulong)TableMask.V2_0_TablesMask;
       break;
     default:
       this.ErrorContainer.AddMetadataStreamError(this.MetadataStreamName, 4, MetadataReaderErrorKind.UnknownVersionOfMetadata);
       return false;
   }
   if ((presentTables & ~validTablesForVersion) != 0) {
     this.ErrorContainer.AddMetadataStreamError(this.MetadataStreamName, 8, MetadataReaderErrorKind.UnknownTables);
     return false;
   }
   if (this.MetadataStreamKind == MetadataStreamKind.Compressed && (presentTables & (ulong)TableMask.CompressedStreamNotAllowedMask) != 0) {
     this.ErrorContainer.AddMetadataStreamError(this.MetadataStreamName, 8, MetadataReaderErrorKind.IllegalTablesInCompressedMetadataStream);
     return false;
   }
   ulong requiredSortedTables = presentTables & validTablesForVersion & (ulong)TableMask.SortedTablesMask;
   if ((requiredSortedTables & (ulong)this.MetadataTableHeader.SortedTables) != requiredSortedTables) {
     this.ErrorContainer.AddMetadataStreamError(this.MetadataStreamName, 16, MetadataReaderErrorKind.SomeRequiredTablesNotSorted);
     //Carry on regardless. There are/were compiler out there that sort the required tables, but fail to set the bit in SortedTables.
   }
   int numberOfTables = this.MetadataTableHeader.GetNumberOfTablesPresent();
   if (memReader.RemainingBytes < numberOfTables * sizeof(Int32)) {
     this.ErrorContainer.AddMetadataStreamError(this.MetadataStreamName, memReader.Offset, MetadataReaderErrorKind.TableRowCountSpaceTooSmall);
     return false;
   }
   this.MetadataTableRowCount = new uint[numberOfTables];
   uint[] metadataTableRowCount = this.MetadataTableRowCount;
   for (int i = 0; i < numberOfTables; ++i) {
     metadataTableRowCount[i] = memReader.ReadUInt32();
   }
   return true;
 }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:58,代码来源:PEFileReader.cs

示例4: GetSmallSEHEntries

 internal static SEHTableEntry[] GetSmallSEHEntries(
   MemoryReader memReader,
   int numEntries
 ) {
   SEHTableEntry[] retSEHEntries = new SEHTableEntry[numEntries];
   for (int i = 0; i < numEntries; ++i) {
     SEHFlags sehFlags = (SEHFlags)memReader.ReadUInt16();
     uint tryOffset = memReader.ReadUInt16();
     uint tryLength = memReader.ReadByte();
     uint handlerOffset = memReader.ReadUInt16();
     uint handlerLength = memReader.ReadByte();
     uint classTokenOrFilterOffset = memReader.ReadUInt32();
     retSEHEntries[i] = new SEHTableEntry(sehFlags, tryOffset, tryLength, handlerOffset, handlerLength, classTokenOrFilterOffset);
   }
   return retSEHEntries;
 }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:16,代码来源:PEFileReader.cs

示例5: ReadOptionalHeaderStandardFields64

 bool ReadOptionalHeaderStandardFields64(
   ref MemoryReader memReader
 )
   //^ requires this.ReaderState >= ReaderState.Initialized;
 {
   if (memReader.RemainingBytes < PEFileConstants.SizeofOptionalHeaderStandardFields64) {
     this.ErrorContainer.AddBinaryError(memReader.Offset, MetadataReaderErrorKind.OptionalHeaderStandardFields64TooSmall);
     return false;
   }
   this.OptionalHeaderStandardFields.PEMagic = (PEMagic)memReader.ReadUInt16();
   this.OptionalHeaderStandardFields.MajorLinkerVersion = memReader.ReadByte();
   this.OptionalHeaderStandardFields.MinorLinkerVersion = memReader.ReadByte();
   this.OptionalHeaderStandardFields.SizeOfCode = memReader.ReadInt32();
   this.OptionalHeaderStandardFields.SizeOfInitializedData = memReader.ReadInt32();
   this.OptionalHeaderStandardFields.SizeOfUninitializedData = memReader.ReadInt32();
   this.OptionalHeaderStandardFields.RVAOfEntryPoint = memReader.ReadInt32();
   this.OptionalHeaderStandardFields.BaseOfCode = memReader.ReadInt32();
   return true;
 }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:19,代码来源:PEFileReader.cs

示例6: GetMethodRefGenericParameterCount

 internal int GetMethodRefGenericParameterCount(
   MethodReference moduleMethodReference
 ) {
   uint signatureBlobOffset = this.PEFileReader.MemberRefTable.GetSignature(moduleMethodReference.MemberRefRowId);
   //  TODO: error checking offset in range
   MemoryBlock signatureMemoryBlock = this.PEFileReader.BlobStream.GetMemoryBlockAt(signatureBlobOffset);
   //  TODO: Error checking enough space in signature memoryBlock.
   MemoryReader memoryReader = new MemoryReader(signatureMemoryBlock);
   //  TODO: Check if this is really method signature there.
   byte firstByte = memoryReader.ReadByte();
   if (SignatureHeader.IsGeneric(firstByte)) {
     return memoryReader.ReadCompressedUInt32();
   }
   return 0;
 }
开发者ID:Biegal,项目名称:Afterthought,代码行数:15,代码来源:PEFileToObjectModel.cs

示例7: GetMarshallingInformation

 internal IMarshallingInformation GetMarshallingInformation(
   MetadataObject metadataObject
 ) {
   uint fieldMarshalRowId = this.PEFileReader.FieldMarshalTable.GetFieldMarshalRowId(metadataObject.TokenValue);
   if (fieldMarshalRowId == 0)
     return Dummy.MarshallingInformation;
   FieldMarshalRow fieldMarshalRow = this.PEFileReader.FieldMarshalTable[fieldMarshalRowId];
   MemoryBlock fieldMarshalMemoryBlock = this.PEFileReader.BlobStream.GetMemoryBlockAt(fieldMarshalRow.NativeType);
   MemoryReader memoryReader = new MemoryReader(fieldMarshalMemoryBlock);
   System.Runtime.InteropServices.UnmanagedType unmanagedType = (System.Runtime.InteropServices.UnmanagedType)memoryReader.ReadByte();
   if (memoryReader.NotEndOfBytes) {
     if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.ByValArray) {
       uint numElements = (uint)memoryReader.ReadCompressedUInt32();
       System.Runtime.InteropServices.UnmanagedType elementType = System.Runtime.InteropServices.UnmanagedType.AsAny;
       if (memoryReader.NotEndOfBytes)
         elementType = (System.Runtime.InteropServices.UnmanagedType)memoryReader.ReadByte();
       return new ByValArrayMarshallingInformation(elementType, numElements);
     } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.CustomMarshaler) {
       string marshallerName;
       string marshallerArgument;
       memoryReader.ReadInt16(); //  Deliberate Skip...
       int byteLen = memoryReader.ReadCompressedUInt32();
       if (byteLen == -1 || byteLen == 0)
         marshallerName = string.Empty;
       else
         marshallerName = memoryReader.ReadUTF8WithSize(byteLen);
       ITypeReference/*?*/ marshaller = this.GetSerializedTypeNameAsTypeReference(marshallerName);
       if (marshaller == null) marshaller = Dummy.TypeReference;
       byteLen = memoryReader.ReadCompressedUInt32();
       if (byteLen == -1 || byteLen == 0)
         marshallerArgument = string.Empty;
       else
         marshallerArgument = memoryReader.ReadUTF8WithSize(byteLen);
       return new CustomMarshallingInformation(marshaller, marshallerArgument);
     } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.LPArray) {
       System.Runtime.InteropServices.UnmanagedType elementType = (System.Runtime.InteropServices.UnmanagedType)memoryReader.ReadByte();
       int paramIndex = -1;
       uint flag = 0;
       uint numElements = 0;
       if (memoryReader.NotEndOfBytes)
         paramIndex = (int)memoryReader.ReadCompressedUInt32();
       if (memoryReader.NotEndOfBytes)
         numElements = (uint)memoryReader.ReadCompressedUInt32();
       if (memoryReader.NotEndOfBytes) {
         flag = (uint)memoryReader.ReadCompressedUInt32();
         if (flag == 0) {
           //TODO: check that paramIndex is 0
           paramIndex = -1; //paramIndex is just a place holder so that numElements can be present
         }
       }
       return new LPArrayMarshallingInformation(elementType, paramIndex, numElements);
     } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.SafeArray) {
       System.Runtime.InteropServices.VarEnum elementType = (System.Runtime.InteropServices.VarEnum)memoryReader.ReadByte();
       string subType = string.Empty;
       if (memoryReader.NotEndOfBytes) {
         int byteLen = memoryReader.ReadCompressedUInt32();
         if (byteLen > 0)
           subType = memoryReader.ReadUTF8WithSize(byteLen);
       }
       ITypeReference/*?*/ subTypeRef = this.GetSerializedTypeNameAsTypeReference(subType);
       if (subTypeRef == null) subTypeRef = Dummy.TypeReference;
       return new SafeArrayMarshallingInformation(elementType, subTypeRef);
     } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.ByValTStr) {
       uint numElements = (uint)memoryReader.ReadCompressedUInt32();
       return new ByValTStrMarshallingInformation(numElements);
     } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.Interface) {
       uint iidParameterIndex = (uint)memoryReader.ReadCompressedUInt32();
       return new IidParameterIndexMarshallingInformation(iidParameterIndex);
     } else {
       //TODO: error blob should not have extra info unless one of the above types.
     }
   }
   return new SimpleMarshallingInformation(unmanagedType);
 }
开发者ID:Biegal,项目名称:Afterthought,代码行数:74,代码来源:PEFileToObjectModel.cs

示例8: GetDefaultValue

 internal IMetadataConstant GetDefaultValue(
   MetadataObject metadataObject
 ) {
   uint constRowId = this.PEFileReader.ConstantTable.GetConstantRowId(metadataObject.TokenValue);
   if (constRowId == 0)
     return Dummy.Constant;
   ConstantRow constRow = this.PEFileReader.ConstantTable[constRowId];
   MemoryBlock constValueMemoryBlock = this.PEFileReader.BlobStream.GetMemoryBlockAt(constRow.Value);
   MemoryReader memoryReader = new MemoryReader(constValueMemoryBlock);
   switch (constRow.Type) {
     case ElementType.Boolean: {
         byte val = memoryReader.ReadByte();
         return new ConstantExpression(this.PlatformType.SystemBoolean, val != 0);
       }
     case ElementType.Char:
       return new ConstantExpression(this.PlatformType.SystemChar, memoryReader.ReadChar());
     case ElementType.Int8:
       return new ConstantExpression(this.PlatformType.SystemInt8, memoryReader.ReadSByte());
     case ElementType.Int16:
       return new ConstantExpression(this.PlatformType.SystemInt16, memoryReader.ReadInt16());
     case ElementType.Int32:
       return new ConstantExpression(this.PlatformType.SystemInt32, memoryReader.ReadInt32());
     case ElementType.Int64:
       return new ConstantExpression(this.PlatformType.SystemInt64, memoryReader.ReadInt64());
     case ElementType.UInt8:
       return new ConstantExpression(this.PlatformType.SystemUInt8, memoryReader.ReadByte());
     case ElementType.UInt16:
       return new ConstantExpression(this.PlatformType.SystemUInt16, memoryReader.ReadUInt16());
     case ElementType.UInt32:
       return new ConstantExpression(this.PlatformType.SystemUInt32, memoryReader.ReadUInt32());
     case ElementType.UInt64:
       return new ConstantExpression(this.PlatformType.SystemUInt64, memoryReader.ReadUInt64());
     case ElementType.Single:
       return new ConstantExpression(this.PlatformType.SystemFloat32, memoryReader.ReadSingle());
     case ElementType.Double:
       return new ConstantExpression(this.PlatformType.SystemFloat64, memoryReader.ReadDouble());
     case ElementType.String: {
         int byteLen = memoryReader.Length;
         string/*?*/ value;
         if (byteLen == -1) {
           value = null;
         } else if (byteLen == 0) {
           value = string.Empty;
         } else {
           value = memoryReader.ReadUTF16WithSize(byteLen);
         }
         return new ConstantExpression(this.PlatformType.SystemString, value);
       }
     case ElementType.Class:
       return new ConstantExpression(this.PlatformType.SystemObject, null);
   }
   //  MDError...
   return Dummy.Constant;
 }
开发者ID:Biegal,项目名称:Afterthought,代码行数:54,代码来源:PEFileToObjectModel.cs

示例9: GetMethodParameterCount

 internal ushort GetMethodParameterCount(
   MethodDefinition moduleMethod
 ) {
   uint signatureBlobOffset = this.PEFileReader.MethodTable.GetSignature(moduleMethod.MethodDefRowId);
   //  TODO: error checking offset in range
   MemoryBlock signatureMemoryBlock = this.PEFileReader.BlobStream.GetMemoryBlockAt(signatureBlobOffset);
   //  TODO: Error checking enough space in signature memoryBlock.
   MemoryReader memoryReader = new MemoryReader(signatureMemoryBlock);
   byte firstByte = memoryReader.ReadByte();
   if (SignatureHeader.IsGeneric(firstByte)) {
     memoryReader.ReadCompressedUInt32();
   }
   return (ushort)memoryReader.ReadCompressedUInt32();
 }
开发者ID:Biegal,项目名称:Afterthought,代码行数:14,代码来源:PEFileToObjectModel.cs


注:本文中的Microsoft.Cci.UtilityDataStructures.MemoryReader.ReadByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。