Ejemplo n.º 1
0
        public static bool ReadOperationRequest(IBinaryReader binaryReader, out object result)
        {
            OperationRequest request = new OperationRequest
            {
                OperationCode = binaryReader.ReadByte()
            };
            short capacity = binaryReader.ReadInt16();

            if ((capacity < 0) || (capacity > ((binaryReader.BaseStream.Length - binaryReader.BaseStream.Position) / 2L)))
            {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Invalid parameter count: count={0}, bytesLeft={1}", new object[] { capacity, binaryReader.BaseStream.Length - binaryReader.BaseStream.Position });
                }
                result = null;
                return(false);
            }
            request.Parameters = new Dictionary <byte, object>(capacity);
            for (short i = 0; i < capacity; i = (short)(i + 1))
            {
                object obj2;
                byte   num3 = binaryReader.ReadByte();
                if (Read(binaryReader, out obj2))
                {
                    request.Parameters[num3] = obj2;
                }
                else
                {
                    result = null;
                    return(false);
                }
            }
            result = request;
            return(true);
        }
Ejemplo n.º 2
0
        public static ErrorResponse Decode(byte id, IBinaryReader reader)
        {
            byte num1 = reader.ReadByte();
            byte num2 = reader.ReadByte();

            return(new ErrorResponse(id, num1, num2));
        }
Ejemplo n.º 3
0
        private static Type ReadDictionaryType(IBinaryReader reader)
        {
            Type   clrArrayType;
            Type   dictArrayType;
            GpType gpType = (GpType)reader.ReadByte();
            GpType type2  = (GpType)reader.ReadByte();

            if (gpType == GpType.Unknown)
            {
                clrArrayType = typeof(object);
            }
            else
            {
                clrArrayType = GpBinaryByteTypeConverter.GetClrArrayType(gpType);
            }
            switch (type2)
            {
            case GpType.Unknown:
                dictArrayType = typeof(object);
                break;

            case GpType.Dictionary:
                dictArrayType = ReadDictionaryType(reader);
                break;

            case GpType.Array:
                dictArrayType = GetDictArrayType(reader);
                break;

            default:
                dictArrayType = GpBinaryByteTypeConverter.GetClrArrayType(type2);
                break;
            }
            return(typeof(Dictionary <,>).MakeGenericType(new Type[] { clrArrayType, dictArrayType }));
        }
Ejemplo n.º 4
0
        private static Type ReadDictionaryType(IBinaryReader reader, out ReadDelegate keyReadDelegate, out ReadDelegate valueReadDelegate)
        {
            Type   clrArrayType;
            Type   type4;
            GpType gpType = (GpType)reader.ReadByte();
            GpType type2  = (GpType)reader.ReadByte();

            if (gpType == GpType.Unknown)
            {
                clrArrayType    = typeof(object);
                keyReadDelegate = new ReadDelegate(GpBinaryByteReader.Read);
            }
            else
            {
                clrArrayType    = GpBinaryByteTypeConverter.GetClrArrayType(gpType);
                keyReadDelegate = GetReadDelegate(gpType);
            }
            if (type2 == GpType.Unknown)
            {
                type4             = typeof(object);
                valueReadDelegate = new ReadDelegate(GpBinaryByteReader.Read);
            }
            else
            {
                type4             = GpBinaryByteTypeConverter.GetClrArrayType(type2);
                valueReadDelegate = GetReadDelegate(type2);
            }
            return(typeof(Dictionary <,>).MakeGenericType(new Type[] { clrArrayType, type4 }));
        }
Ejemplo n.º 5
0
        void ReadSmallExceptionHandlers(IBinaryReader ehReader)
        {
            int num = GetNumberOfExceptionHandlers((uint)ehReader.ReadByte() / 12);

            ehReader.Position += 2;
            for (int i = 0; i < num; i++)
            {
                var  eh   = new ExceptionHandler((ExceptionHandlerType)ehReader.ReadUInt16());
                uint offs = ehReader.ReadUInt16();
                eh.TryStart     = GetInstruction(offs);
                eh.TryEnd       = GetInstruction(offs + ehReader.ReadByte());
                offs            = ehReader.ReadUInt16();
                eh.HandlerStart = GetInstruction(offs);
                eh.HandlerEnd   = GetInstruction(offs + ehReader.ReadByte());
                if (eh.HandlerType == ExceptionHandlerType.Catch)
                {
                    eh.CatchType = opResolver.ResolveToken(ehReader.ReadUInt32(), gpContext) as ITypeDefOrRef;
                }
                else if (eh.HandlerType == ExceptionHandlerType.Filter)
                {
                    eh.FilterStart = GetInstruction(ehReader.ReadUInt32());
                }
                else
                {
                    ehReader.ReadUInt32();
                }
                Add(eh);
            }
        }
Ejemplo n.º 6
0
		static bool ReadHeader(IBinaryReader reader, out ushort flags, out uint codeSize) {
			byte b = reader.ReadByte();
			switch (b & 7) {
			case 2:
			case 6:
				flags = 2;
				codeSize = (uint)(b >> 2);
				return true;

			case 3:
				flags = (ushort)((reader.ReadByte() << 8) | b);
				uint headerSize = (byte)(flags >> 12);
				ushort maxStack = reader.ReadUInt16();
				codeSize = reader.ReadUInt32();
				uint localVarSigTok = reader.ReadUInt32();

				reader.Position += -12 + headerSize * 4;
				if (headerSize < 3)
					flags &= 0xFFF7;
				return true;

			default:
				flags = 0;
				codeSize = 0;
				return false;
			}
		}
Ejemplo n.º 7
0
        private IEnumerable <byte> ReadCustomMetadata(ManagedProcedureSymbol function)
        {
            foreach (OemSymbol oem in function.Children.OfType <OemSymbol>())
            {
                if (oem.Id == MsilMetadataGuid)
                {
                    IBinaryReader reader = oem.UserDataReader;
                    string        name   = reader.ReadCStringWide().String;

                    if (name == "MD2")
                    {
                        byte version = reader.ReadByte();

                        if (version == 4)
                        {
                            int count = reader.ReadByte();

                            reader.Align(4);
                            for (int i = 0; i < count; i++)
                            {
                                long start        = reader.Position;
                                byte entryVersion = reader.ReadByte();
                                byte kind         = reader.ReadByte();

                                reader.Align(4);
                                yield return(kind);

                                uint numberOfBytesInItem = reader.ReadUint();
                                reader.Position = start + numberOfBytesInItem;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        static bool ReadHeader(IBinaryReader reader, out ushort flags, out uint codeSize)
        {
            byte b = reader.ReadByte();

            switch (b & 7)
            {
            case 2:
            case 6:
                flags    = 2;
                codeSize = (uint)(b >> 2);
                return(true);

            case 3:
                flags = (ushort)((reader.ReadByte() << 8) | b);
                uint   headerSize = (byte)(flags >> 12);
                ushort maxStack   = reader.ReadUInt16();
                codeSize = reader.ReadUInt32();
                uint localVarSigTok = reader.ReadUInt32();

                reader.Position += -12 + headerSize * 4;
                if (headerSize < 3)
                {
                    flags &= 0xFFF7;
                }
                return(true);

            default:
                flags    = 0;
                codeSize = 0;
                return(false);
            }
        }
Ejemplo n.º 9
0
        static void ParseSection(IBinaryReader reader)
        {
            byte flags;

            do
            {
                Align(reader, 4);

                flags = reader.ReadByte();
                if ((flags & 1) == 0)
                {
                    throw new InvalidMethodBody("Not an exception section");
                }
                if ((flags & 0x3E) != 0)
                {
                    throw new InvalidMethodBody("Invalid bits set");
                }

                if ((flags & 0x40) != 0)
                {
                    reader.Position--;
                    int num = (int)(reader.ReadUInt32() >> 8) / 24;
                    reader.Position += num * 24;
                }
                else
                {
                    int num = reader.ReadByte() / 12;
                    reader.Position += 2 + num * 12;
                }
            } while ((flags & 0x80) != 0);
        }
Ejemplo n.º 10
0
		static byte[] TryCreateIcon(IBinaryReader reader, ResourceDirectory iconDir) {
			try {
				reader.Position = 0;
				var outStream = new MemoryStream();
				var writer = new BinaryWriter(outStream);
				// Write GRPICONDIR
				writer.Write(reader.ReadUInt16());
				writer.Write(reader.ReadUInt16());
				ushort numImages;
				writer.Write(numImages = reader.ReadUInt16());

				var entries = new List<GrpIconDirEntry>();
				for (int i = 0; i < numImages; i++) {
					var e = new GrpIconDirEntry();
					entries.Add(e);
					e.bWidth = reader.ReadByte();
					e.bHeight = reader.ReadByte();
					e.bColorCount = reader.ReadByte();
					e.bReserved = reader.ReadByte();
					e.wPlanes = reader.ReadUInt16();
					e.wBitCount = reader.ReadUInt16();
					e.dwBytesInRes = reader.ReadUInt32();
					e.nID = reader.ReadUInt16();
				}

				uint dataOffset = 2 * 3 + (uint)entries.Count * 0x10;
				foreach (var e in entries) {
					writer.Write(e.bWidth);
					writer.Write(e.bHeight);
					writer.Write(e.bColorCount);
					writer.Write(e.bReserved);
					writer.Write(e.wPlanes);
					writer.Write(e.wBitCount);
					writer.Write(e.dwBytesInRes);
					writer.Write(dataOffset);
					dataOffset += e.dwBytesInRes;
				}

				foreach (var e in entries) {
					var d = iconDir.Directories.FirstOrDefault(a => a.Name == new ResourceName(e.nID));
					if (d == null || d.Data.Count == 0)
						return null;
					var r = d.Data[0].Data;
					Debug.Assert(r.Length == e.dwBytesInRes);
					if (r.Length < e.dwBytesInRes)
						return null;
					r.Position = 0;
					writer.Write(r.ReadBytes((int)e.dwBytesInRes), 0, (int)e.dwBytesInRes);
				}

				return outStream.ToArray();
			}
			catch (IOException) {
			}
			return null;
		}
Ejemplo n.º 11
0
 /// <summary>
 /// Reads <see cref="BitFieldRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static BitFieldRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new BitFieldRecord
     {
         Kind = kind,
         Type = TypeIndex.Read(reader),
         BitSize = reader.ReadByte(),
         BitOffset = reader.ReadByte(),
     });
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Reads the next OpCode from the current position
        /// </summary>
        OpCode ReadOpCode()
        {
            var op = reader.ReadByte();

            if (op != 0xFE)
            {
                return(OpCodes.OneByteOpCodes[op]);
            }
            return(OpCodes.TwoByteOpCodes[reader.ReadByte()]);
        }
Ejemplo n.º 13
0
        private string ReadOfflineString(IBinaryReader binaryReader)
        {
            byte   length = binaryReader.ReadByte();
            string result = binaryReader.ReadBytes(length)
                            .Let(Encoding.ASCII.GetString);

            // Read string termination character
            binaryReader.ReadByte();

            return(result);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Reads <see cref="ProcedureRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static ProcedureRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new ProcedureRecord
     {
         Kind = kind,
         ReturnType = TypeIndex.Read(reader),
         CallingConvention = (CallingConvention)reader.ReadByte(),
         Options = (FunctionOptions)reader.ReadByte(),
         ParameterCount = reader.ReadUshort(),
         ArgumentList = TypeIndex.Read(reader),
     });
 }
Ejemplo n.º 15
0
 /** <inheritDoc /> */
 void IBinarizable.ReadBinary(IBinaryReader reader)
 {
     Id         = reader.ReadInt("id");
     CompanyId  = reader.ReadInt("companyId");
     Age        = reader.ReadInt("age");
     Points     = reader.ReadInt("points");
     SexType    = (Sex)reader.ReadByte("sex");
     Department = (Department)reader.ReadByte("department");
     Salary     = reader.ReadLong("salary");
     Payload    = reader.ReadByteArray("payload");
     Name       = reader.ReadString("name");
     Address    = reader.ReadObject <Address>("address");
 }
Ejemplo n.º 16
0
        public static OpCode ReadOpCode(IBinaryReader binaryReader)
        {
            byte instruction = binaryReader.ReadByte();

            if (instruction != DoubleByteInstructionPrefix)
            {
                return(singleByteOpCode[instruction]);
            }
            else
            {
                return(doubleByteOpCode[binaryReader.ReadByte()]);
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Reads <see cref="FrameCookieSymbol"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="symbolStream">Symbol stream that contains this symbol record.</param>
 /// <param name="symbolStreamIndex">Index in symbol stream <see cref="SymbolStream.References"/> array.</param>
 /// <param name="kind">Symbol record kind.</param>
 public static FrameCookieSymbol Read(IBinaryReader reader, SymbolStream symbolStream, int symbolStreamIndex, SymbolRecordKind kind)
 {
     return(new FrameCookieSymbol
     {
         SymbolStream = symbolStream,
         SymbolStreamIndex = symbolStreamIndex,
         Kind = kind,
         CodeOffset = reader.ReadUint(),
         Register = (RegisterId)reader.ReadUshort(),
         CookieKind = (FrameCookieKind)reader.ReadByte(),
         Flags = reader.ReadByte(),
     });
 }
Ejemplo n.º 18
0
            public static DecrypterV100 Create(IBinaryReader reader)
            {
                reader.Position = 0;
                if (reader.Length < 12)
                {
                    return(null);
                }
                if (reader.ReadUInt32() != RESOURCE_MAGIC)
                {
                    return(null);
                }

                return(new DecrypterV100(new Version(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte())));
            }
Ejemplo n.º 19
0
 /// <summary>
 /// Reads <see cref="SectionSymbol"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Symbol record kind.</param>
 public static SectionSymbol Read(IBinaryReader reader, SymbolRecordKind kind)
 {
     return(new SectionSymbol
     {
         Kind = kind,
         SectionNumber = reader.ReadUshort(),
         Alignment = reader.ReadByte(),
         Padding = reader.ReadByte(),
         RelativeVirtualAddress = reader.ReadUint(),
         Length = reader.ReadUint(),
         Characteristics = (ImageSectionCharacteristics)reader.ReadUint(),
         Name = reader.ReadCString(),
     });
 }
        /// <summary>
        /// Reads <see cref="FileChecksumSubsection"/> from the stream.
        /// </summary>
        /// <param name="reader">Stream binary reader.</param>
        /// <param name="kind">Debug subsection kind.</param>
        public static FileChecksumSubsection Read(IBinaryReader reader, DebugSubsectionKind kind)
        {
            uint nameIndex  = reader.ReadUint();
            byte hashLength = reader.ReadByte();
            FileChecksumHashType hashType = (FileChecksumHashType)reader.ReadByte();

            reader.Align(4);
            return(new FileChecksumSubsection
            {
                Kind = kind,
                NameIndex = nameIndex,
                HashType = hashType,
                HashReader = reader.ReadSubstream(hashLength),
            });
        }
Ejemplo n.º 21
0
            public static DecrypterV105 Create(IBinaryReader reader)
            {
                reader.Position = 0;
                if (reader.Length < 0xA4)
                {
                    return(null);
                }
                var key = reader.ReadBytes(0x94);

                if (!Utils.Compare(reader.ReadBytes(8), ilpPublicKeyToken))
                {
                    return(null);
                }
                return(new DecrypterV105(new Version(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()), key));
            }
Ejemplo n.º 22
0
 /// <summary>
 /// Reads <see cref="MemberFunctionRecord"/> from the stream.
 /// </summary>
 /// <param name="reader">Stream binary reader.</param>
 /// <param name="kind">Type record kind.</param>
 public static MemberFunctionRecord Read(IBinaryReader reader, TypeLeafKind kind)
 {
     return(new MemberFunctionRecord
     {
         Kind = kind,
         ReturnType = TypeIndex.Read(reader),
         ClassType = TypeIndex.Read(reader),
         ThisType = TypeIndex.Read(reader),
         CallingConvention = (CallingConvention)reader.ReadByte(),
         Options = (FunctionOptions)reader.ReadByte(),
         ParameterCount = reader.ReadUshort(),
         ArgumentList = TypeIndex.Read(reader),
         ThisPointerAdjustment = reader.ReadInt(),
     });
 }
Ejemplo n.º 23
0
 /** <inheritDoc /> */
 void IBinarizable.ReadBinary(IBinaryReader reader)
 {
     Id         = reader.ReadInt("id");
     CompanyId  = reader.ReadInt("companyId");
     Age        = reader.ReadInt("age");
     Points     = reader.ReadInt("points");
     SexType    = (Sex)reader.ReadByte("sex");
     Department = (Department)reader.ReadByte("department");
     Salary     = reader.ReadLong("salary");
     Payload    = reader.ReadByteArray("payload");
     Name       = reader.ReadString("name");
     Address    = reader.ReadObject <Address>("address");
     Birthday   = reader.ReadObject <DateTime>("birthday");
     Timestamp  = reader.ReadTimestamp("timestamp").GetValueOrDefault();
 }
Ejemplo n.º 24
0
        static byte Peek(IBinaryReader reader)
        {
            byte b = reader.ReadByte();

            reader.Position--;
            return(b);
        }
Ejemplo n.º 25
0
			protected static byte[] Decompress(byte[] decrypted, IBinaryReader reader, byte[] key, int keyMod) {
				int destIndex = 0;
				while (reader.Position < reader.Length) {
					if (destIndex >= decrypted.Length)
						break;
					byte flags = reader.ReadByte();
					for (int mask = 1; mask != 0x100; mask <<= 1) {
						if (reader.Position >= reader.Length)
							break;
						if (destIndex >= decrypted.Length)
							break;
						if ((flags & mask) != 0) {
							int displ = (int)reader.Read7BitEncodedUInt32();
							int size = (int)reader.Read7BitEncodedUInt32();
							Copy(decrypted, destIndex - displ, decrypted, destIndex, size);
							destIndex += size;
						}
						else {
							byte b = reader.ReadByte();
							if (key != null)
								b ^= key[destIndex % keyMod];
							decrypted[destIndex++] = b;
						}
					}
				}

				return decrypted;
			}
Ejemplo n.º 26
0
        /// <summary>
        /// Reads encoded integer from the stream.
        /// </summary>
        /// <param name="reader">Stream binary reader.</param>
        /// <returns>Integer, but also carries type info, so it is returned as object.</returns>
        public static object ReadEncodedInteger(this IBinaryReader reader)
        {
            ushort type = reader.ReadUshort();

            if (type < (ushort)TypeLeafKind.LF_NUMERIC)
            {
                return(type);
            }

            switch ((TypeLeafKind)type)
            {
            case TypeLeafKind.LF_CHAR:
                return((sbyte)reader.ReadByte());

            case TypeLeafKind.LF_SHORT:
                return(reader.ReadShort());

            case TypeLeafKind.LF_USHORT:
                return(reader.ReadUshort());

            case TypeLeafKind.LF_LONG:
                return(reader.ReadInt());

            case TypeLeafKind.LF_ULONG:
                return(reader.ReadUint());

            case TypeLeafKind.LF_QUADWORD:
                return(reader.ReadLong());

            case TypeLeafKind.LF_UQUADWORD:
                return(reader.ReadUlong());
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 27
0
        public void ReadByByteTooMuchDataFromShortArray()
        {
            var           buffer = new byte[] { 0, 1, 2 };
            IBinaryReader reader = BinaryHelper.CreateReader(buffer);

            Assert.IsNotNull(reader);

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual((byte)i, reader.ReadByte());
            }

            // should trigger exception here
            reader.ReadByte();
            Assert.Fail("Expected exception before");
        }
Ejemplo n.º 28
0
 /** <inheritDoc /> */
 public void ReadBinary(IBinaryReader reader)
 {
     Byte         = reader.ReadByte("Byte");
     ByteArray    = reader.ReadByteArray("ByteArray");
     Char         = reader.ReadChar("Char");
     CharArray    = reader.ReadCharArray("CharArray");
     Short        = reader.ReadShort("Short");
     ShortArray   = reader.ReadShortArray("ShortArray");
     Int          = reader.ReadInt("Int");
     IntArray     = reader.ReadIntArray("IntArray");
     Long         = reader.ReadLong("Long");
     LongArray    = reader.ReadLongArray("LongArray");
     Boolean      = reader.ReadBoolean("Boolean");
     BooleanArray = reader.ReadBooleanArray("BooleanArray");
     Float        = reader.ReadFloat("Float");
     FloatArray   = reader.ReadFloatArray("FloatArray");
     Double       = reader.ReadDouble("Double");
     DoubleArray  = reader.ReadDoubleArray("DoubleArray");
     Decimal      = reader.ReadDecimal("Decimal");
     DecimalArray = reader.ReadDecimalArray("DecimalArray");
     Date         = reader.ReadTimestamp("Date");
     DateArray    = reader.ReadTimestampArray("DateArray");
     String       = reader.ReadString("String");
     StringArray  = reader.ReadStringArray("StringArray");
     Guid         = reader.ReadObject <Guid>("Guid");
     GuidArray    = reader.ReadGuidArray("GuidArray");
 }
Ejemplo n.º 29
0
        bool IsBytes(IList <byte> bytes)
        {
            long oldPos = reader.Position;
            bool result = true;

            for (int i = 0; i < bytes.Count; i++)
            {
                if (bytes[i] != reader.ReadByte())
                {
                    result = false;
                    break;
                }
            }
            reader.Position = oldPos;
            return(result);
        }
Ejemplo n.º 30
0
        protected void readSdrAndBitStream(IBinaryReader reader)
        {
            // the kind of information contained in the structured data record will
            // depend on the compression type
            DataRecord = reader.ReadSDR();

            if (CompressionType == CompressionType.BASELINE_JPEG || CompressionType == CompressionType.PNG)
            {
                Image = new MemoryStream(reader.ArgumentsCount - reader.CurrentArg);

                while (reader.CurrentArg < reader.ArgumentsCount)
                {
                    Image.WriteByte(reader.ReadByte());
                }
            }
            else
            {
                switch (CompressionType)
                {
                case CompressionType.BITMAP:
                    ReadBitmap(reader);
                    break;

                default:
                    reader.Unsupported("unsupported compression type " + CompressionType);
                    break;
                }
            }
        }
        private static MobileOriginatedLocation DecodeLocation(
            IBinaryReader reader)
        {
            byte   num1      = reader.ReadByte();
            int    num2      = (num1 & 2) >> 1;
            byte   num3      = reader.ReadByte();
            ushort num4      = reader.ReadUInt16();
            double latitude  = (num2 == 0 ? 1 : -1) * num3 + num4 / 1000.0 / 60.0;
            int    num5      = num1 & 1;
            byte   num6      = reader.ReadByte();
            ushort num7      = reader.ReadUInt16();
            double longitude = (num5 == 0 ? 1 : -1) * num6 + num7 / 1000.0 / 60.0;
            uint   cepRadius = reader.ReadUInt32();

            return(new MobileOriginatedLocation(latitude, longitude, cepRadius));
        }
Ejemplo n.º 32
0
 /** <inheritDoc /> */
 public void ReadBinary(IBinaryReader reader)
 {
     Byte = reader.ReadByte("Byte");
     ByteArray = reader.ReadByteArray("ByteArray");
     Char = reader.ReadChar("Char");
     CharArray = reader.ReadCharArray("CharArray");
     Short = reader.ReadShort("Short");
     ShortArray = reader.ReadShortArray("ShortArray");
     Int = reader.ReadInt("Int");
     IntArray = reader.ReadIntArray("IntArray");
     Long = reader.ReadLong("Long");
     LongArray = reader.ReadLongArray("LongArray");
     Boolean = reader.ReadBoolean("Boolean");
     BooleanArray = reader.ReadBooleanArray("BooleanArray");
     Float = reader.ReadFloat("Float");
     FloatArray = reader.ReadFloatArray("FloatArray");
     Double = reader.ReadDouble("Double");
     DoubleArray = reader.ReadDoubleArray("DoubleArray");
     Decimal = reader.ReadDecimal("Decimal");
     DecimalArray = reader.ReadDecimalArray("DecimalArray");
     Date = reader.ReadTimestamp("Date");
     DateArray = reader.ReadTimestampArray("DateArray");
     String = reader.ReadString("String");
     StringArray = reader.ReadStringArray("StringArray");
     Guid = reader.ReadObject<Guid>("Guid");
     GuidArray = reader.ReadGuidArray("GuidArray");
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Tries to read a custom type.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="result">The result.</param>
        /// <returns>True if the custom type could be readed successfully; otherwise false.</returns>
        public static bool ReadCustomType(IBinaryReader reader, out object result)
        {
            CustomTypeInfo info;
            byte           typeCode = reader.ReadByte();

            if (!CustomTypeCache.TryGet(typeCode, out info) && !Protocol.AllowRawCustomValues)
            {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Could not find custom type for type code {0}", new object[] { typeCode });
                }
                result = null;
                return(false);
            }
            short length = reader.ReadInt16();

            if ((length < 0) || ((reader.BaseStream.Length - reader.BaseStream.Position) < length))
            {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Invalid length for custom type: length={0}, bytesLeft={1}", new object[] { length, reader.BaseStream.Length - reader.BaseStream.Position });
                }
                result = null;
                return(false);
            }
            byte[] arg = reader.ReadBytes(length);
            result = (info != null) ? info.DeserializeFunction(arg) : new RawCustomValue(typeCode, arg);
            return(true);
        }
 private static IEnumerable <IoProperty> ReadIoProperties(
     IBinaryReader reader)
 {
     return(new IoProperty[9]
     {
         IoProperty.Create(10, reader.ReadInt16()),
         IoProperty.Create(1, reader.ReadInt16()),
         IoProperty.Create(2, reader.ReadInt16()),
         IoProperty.Create(3, reader.ReadInt16()),
         IoProperty.Create(12, reader.ReadInt16()),
         IoProperty.Create(11, reader.ReadByte()),
         IoProperty.Create(5, reader.ReadByte()),
         IoProperty.Create(4, reader.ReadByte()),
         IoProperty.Create(6, reader.ReadByte())
     });
 }
Ejemplo n.º 35
0
		/// <summary>
		/// Reads the column
		/// </summary>
		/// <param name="reader">A reader positioned on this column</param>
		/// <returns>The column value</returns>
		public uint Read(IBinaryReader reader) {
			switch (size) {
			case 1: return reader.ReadByte();
			case 2: return reader.ReadUInt16();
			case 4: return reader.ReadUInt32();
			default: throw new InvalidOperationException("Invalid column size");
			}
		}
Ejemplo n.º 36
0
			public virtual bool Decrypt(IBinaryReader fileDataReader, DumpedMethod dm) {
				if (fileDataReader.ReadByte() != 0x2A)
					return false;	// Not a RET
				methodsDataReader.Position = fileDataReader.ReadCompressedUInt32();

				dm.mhCodeSize = methodsDataReader.ReadCompressedUInt32();
				dm.code = methodsDataReader.ReadBytes((int)dm.mhCodeSize);
				if ((dm.mhFlags & 8) != 0)
					dm.extraSections = MethodBodyParser.ReadExtraSections(methodsDataReader);

				if (!DecryptCode(dm))
					return false;

				return true;
			}
Ejemplo n.º 37
0
		static MethodBodyHeader ParseMethodBody2(IBinaryReader reader, out byte[] code, out byte[] extraSections) {
			var mbHeader = new MethodBodyHeader();

			uint codeOffset;
			byte b = Peek(reader);
			if ((b & 3) == 2) {
				mbHeader.flags = 2;
				mbHeader.maxStack = 8;
				mbHeader.codeSize = (uint)(reader.ReadByte() >> 2);
				mbHeader.localVarSigTok = 0;
				codeOffset = 1;
			}
			else if ((b & 7) == 3) {
				mbHeader.flags = reader.ReadUInt16();
				codeOffset = (uint)(4 * (mbHeader.flags >> 12));
				if (codeOffset != 12)
					throw new InvalidMethodBody();
				mbHeader.maxStack = reader.ReadUInt16();
				mbHeader.codeSize = reader.ReadUInt32();
				if (mbHeader.codeSize > int.MaxValue)
					throw new InvalidMethodBody();
				mbHeader.localVarSigTok = reader.ReadUInt32();
				if (mbHeader.localVarSigTok != 0 && (mbHeader.localVarSigTok >> 24) != 0x11)
					throw new InvalidMethodBody();
			}
			else
				throw new InvalidMethodBody();

			if (mbHeader.codeSize + codeOffset > reader.Length)
				throw new InvalidMethodBody();
			code = reader.ReadBytes((int)mbHeader.codeSize);

			if ((mbHeader.flags & 8) != 0)
				extraSections = ReadExtraSections2(reader);
			else
				extraSections = null;

			return mbHeader;
		}
Ejemplo n.º 38
0
		void ReadSmallExceptionHandlers(IBinaryReader ehReader) {
			int num = GetNumberOfExceptionHandlers((uint)ehReader.ReadByte() / 12);
			ehReader.Position += 2;
			for (int i = 0; i < num; i++) {
				var eh = new ExceptionHandler((ExceptionHandlerType)ehReader.ReadUInt16());
				uint offs = ehReader.ReadUInt16();
				eh.TryStart = GetInstruction(offs);
				eh.TryEnd = GetInstruction(offs + ehReader.ReadByte());
				offs = ehReader.ReadUInt16();
				eh.HandlerStart = GetInstruction(offs);
				eh.HandlerEnd = GetInstruction(offs + ehReader.ReadByte());
				if (eh.HandlerType == ExceptionHandlerType.Catch)
					eh.CatchType = opResolver.ResolveToken(ehReader.ReadUInt32(), gpContext) as ITypeDefOrRef;
				else if (eh.HandlerType == ExceptionHandlerType.Filter)
					eh.FilterStart = GetInstruction(ehReader.ReadUInt32());
				else
					ehReader.ReadUInt32();
				Add(eh);
			}
		}
Ejemplo n.º 39
0
 /** <inheritDoc /> */
 void IBinarizable.ReadBinary(IBinaryReader reader)
 {
     Id = reader.ReadInt("id");
     CompanyId = reader.ReadInt("companyId");
     Age = reader.ReadInt("age");
     Points = reader.ReadInt("points");
     SexType = (Sex)reader.ReadByte("sex");
     Department = (Department)reader.ReadByte("department");
     Salary = reader.ReadLong("salary");
     Payload = reader.ReadByteArray("payload");
     Name = reader.ReadString("name");
     Address = reader.ReadObject<Address>("address");
 }
Ejemplo n.º 40
0
		static void ParseSection(IBinaryReader reader) {
			byte flags;
			do {
				Align(reader, 4);

				flags = reader.ReadByte();
				if ((flags & 1) == 0)
					throw new InvalidMethodBody("Not an exception section");
				if ((flags & 0x3E) != 0)
					throw new InvalidMethodBody("Invalid bits set");

				if ((flags & 0x40) != 0) {
					reader.Position--;
					int num = (int)(reader.ReadUInt32() >> 8) / 24;
					reader.Position += num * 24;
				}
				else {
					int num = reader.ReadByte() / 12;
					reader.Position += 2 + num * 12;
				}
			} while ((flags & 0x80) != 0);
		}
Ejemplo n.º 41
0
		static byte Peek(IBinaryReader reader) {
			byte b = reader.ReadByte();
			reader.Position--;
			return b;
		}
Ejemplo n.º 42
0
        internal byte DecodeByte(IBinaryReader reader)
        {
            int pos = reader.Position + 0x8000000;
            byte raw = reader.ReadByte();

            if (encodingParameters == null)
            {
                return raw;
            }

            bool even = (pos & 1) == 0;

            if (even)
            {
                int offset = ((pos >> 1) % encodingParameters.EvenPadModulus);
                byte pad = encodingParameters.EvenPad[offset];
                return (byte)(((raw + encodingParameters.EvenOffset1) ^ pad) + encodingParameters.EvenOffset2);
            }
            else
            {
                int offset = ((pos >> 1) % encodingParameters.OddPadModulus);
                byte pad = encodingParameters.OddPad[offset];
                return (byte)(((raw + encodingParameters.OddOffset1) ^ pad) + encodingParameters.OddOffset2);
            }
        }
Ejemplo n.º 43
0
            public void ReadBinary(IBinaryReader reader)
            {
                Assert.AreEqual(1, reader.ReadByte("Byte"));
                Assert.AreEqual(new byte[] {1}, reader.ReadByteArray("ByteArray"));
                Assert.AreEqual('1', reader.ReadChar("Char"));
                Assert.AreEqual(new[] {'1'}, reader.ReadCharArray("CharArray"));
                Assert.AreEqual(1, reader.ReadShort("Short"));
                Assert.AreEqual(new short[] {1}, reader.ReadShortArray("ShortArray"));
                Assert.AreEqual(1, reader.ReadInt("Int"));
                Assert.AreEqual(new[] {1}, reader.ReadIntArray("IntArray"));
                Assert.AreEqual(1, reader.ReadLong("Long"));
                Assert.AreEqual(new long[] {1}, reader.ReadLongArray("LongArray"));
                Assert.AreEqual(true, reader.ReadBoolean("Boolean"));
                Assert.AreEqual(new[] {true}, reader.ReadBooleanArray("BooleanArray"));
                Assert.AreEqual(1, reader.ReadFloat("Float"));
                Assert.AreEqual(new float[] {1}, reader.ReadFloatArray("FloatArray"));
                Assert.AreEqual(1, reader.ReadDouble("Double"));
                Assert.AreEqual(new double[] {1}, reader.ReadDoubleArray("DoubleArray"));
                Assert.AreEqual(1, reader.ReadDecimal("Decimal"));
                Assert.AreEqual(new decimal?[] {1}, reader.ReadDecimalArray("DecimalArray"));
                Assert.AreEqual(Date, reader.ReadTimestamp("Timestamp"));
                Assert.AreEqual(new DateTime?[] {Date}, reader.ReadTimestampArray("TimestampArray"));
                Assert.AreEqual("1", reader.ReadString("String"));
                Assert.AreEqual(new[] {"1"}, reader.ReadStringArray("StringArray"));
                Assert.AreEqual(Guid, reader.ReadGuid("Guid"));
                Assert.AreEqual(new Guid?[] {Guid}, reader.ReadGuidArray("GuidArray"));
                Assert.AreEqual(MyEnum.Bar, reader.ReadEnum<MyEnum>("Enum"));
                Assert.AreEqual(new[] {MyEnum.Bar}, reader.ReadEnumArray<MyEnum>("EnumArray"));

                var raw = reader.GetRawReader();

                Assert.AreEqual(1, raw.ReadByte());
                Assert.AreEqual(new byte[] { 1 }, raw.ReadByteArray());
                Assert.AreEqual('1', raw.ReadChar());
                Assert.AreEqual(new[] { '1' }, raw.ReadCharArray());
                Assert.AreEqual(1, raw.ReadShort());
                Assert.AreEqual(new short[] { 1 }, raw.ReadShortArray());
                Assert.AreEqual(1, raw.ReadInt());
                Assert.AreEqual(new[] { 1 }, raw.ReadIntArray());
                Assert.AreEqual(1, raw.ReadLong());
                Assert.AreEqual(new long[] { 1 }, raw.ReadLongArray());
                Assert.AreEqual(true, raw.ReadBoolean());
                Assert.AreEqual(new[] { true }, raw.ReadBooleanArray());
                Assert.AreEqual(1, raw.ReadFloat());
                Assert.AreEqual(new float[] { 1 }, raw.ReadFloatArray());
                Assert.AreEqual(1, raw.ReadDouble());
                Assert.AreEqual(new double[] { 1 }, raw.ReadDoubleArray());
                Assert.AreEqual(1, raw.ReadDecimal());
                Assert.AreEqual(new decimal?[] { 1 }, raw.ReadDecimalArray());
                Assert.AreEqual(Date, raw.ReadTimestamp());
                Assert.AreEqual(new DateTime?[] { Date }, raw.ReadTimestampArray());
                Assert.AreEqual("1", raw.ReadString());
                Assert.AreEqual(new[] { "1" }, raw.ReadStringArray());
                Assert.AreEqual(Guid, raw.ReadGuid());
                Assert.AreEqual(new Guid?[] { Guid }, raw.ReadGuidArray());
                Assert.AreEqual(MyEnum.Bar, raw.ReadEnum<MyEnum>());
                Assert.AreEqual(new[] { MyEnum.Bar }, raw.ReadEnumArray<MyEnum>());
            }
Ejemplo n.º 44
0
        internal string ReadCodedStringInternal(IBinaryReader reader, int? maxLength)
        {
            StringBuilder sb = new StringBuilder();
            int count = 0;

            for (count = 0; (!maxLength.HasValue) ||
                (maxLength.HasValue && count < maxLength);)
            {
                // Check for custom codes
                ushort peek = reader.PeekUShort();
                byte upper = (byte)((peek >> 8) & 0xFF);

                if (upper == 0xEF)
                {
                    // Custom code with one-byte argument inline
                    reader.ReadByte();
                    byte arg = reader.ReadByte();
                    count++;

                    sb.Append($"[EF{arg:X2}]");
                }

                else if (peek == 0xFEFF)
                {
                    // Custom code (hot springs) with two-byte argument following
                    reader.ReadShort();
                    ushort arg = reader.ReadUShort();
                    count += 2;

                    sb.Append($"[HOTSPRING {arg:X4}]");
                }

                else
                {
                    ControlCode code = ProcessChar(reader, sb, ref count);

                    if (code != null && code.Flags.HasFlag(ControlCodeFlags.Terminate))
                    {
                        break;
                    }
                }
            }

            // Advance the position past the end of the string if applicable
            while (maxLength.HasValue && count++ < maxLength)
            {
                reader.ReadShort();
            }

            return sb.ToString();
        }
Ejemplo n.º 45
0
			public static DecrypterV100 Create(IBinaryReader reader) {
				reader.Position = 0;
				if (reader.Length < 12)
					return null;
				if (reader.ReadUInt32() != RESOURCE_MAGIC)
					return null;

				return new DecrypterV100(new Version(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()));
			}
Ejemplo n.º 46
0
			public static DecrypterV105 Create(IBinaryReader reader) {
				reader.Position = 0;
				if (reader.Length < 0xA4)
					return null;
				var key = reader.ReadBytes(0x94);
				if (!Utils.Compare(reader.ReadBytes(8), ilpPublicKeyToken))
					return null;
				return new DecrypterV105(new Version(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()), key);
			}
Ejemplo n.º 47
0
			static byte[] GetKey(IBinaryReader reader, byte[] sha1Sum, int offs) {
				var key = (byte[])sha1Sum.Clone();
				reader.Position = offs;
				for (int i = 0; i < key.Length; i++)
					key[i] ^= reader.ReadByte();
				return key;
			}
Ejemplo n.º 48
0
			static byte ReadByteAt(IBinaryReader reader, int offs) {
				reader.Position = offs;
				return reader.ReadByte();
			}