Ejemplo n.º 1
0
        private static bool ReadArrayInArray(IBinaryReader reader, int size, out object result)
        {
            object obj2;

            if (!ReadArray(reader, out obj2))
            {
                result = null;
                return(false);
            }
            Array array = obj2 as Array;

            if (array != null)
            {
                Array array2 = Array.CreateInstance(array.GetType(), size);
                array2.SetValue(array, 0);
                for (short i = 1; i < size; i = (short)(i + 1))
                {
                    if (ReadArray(reader, out obj2))
                    {
                        array = (Array)obj2;
                        array2.SetValue(array, (int)i);
                    }
                    else
                    {
                        result = null;
                        return(false);
                    }
                }
                result = array2;
                return(true);
            }
            RawCustomArray array3 = obj2 as RawCustomArray;

            if (array3 != null)
            {
                Array array4 = new RawCustomArray[size];
                array4.SetValue(array3, 0);
                for (int j = 1; j < size; j++)
                {
                    if (!ReadArray(reader, out obj2))
                    {
                        result = null;
                        return(false);
                    }
                    array3 = obj2 as RawCustomArray;
                    if (array3 != null)
                    {
                        array4.SetValue(array3, j);
                    }
                }
                result = array4;
                return(true);
            }
            result = null;
            return(false);
        }
Ejemplo n.º 2
0
 private static void WriteCustomTypeArray(Stream stream, RawCustomArray array, [Optional, DefaultParameterValue(true)] bool writeArrayIdentifier)
 {
     if (writeArrayIdentifier)
     {
         stream.WriteByte(0xe3);
     }
     WriteIntLength(stream, array.Length);
     stream.WriteByte(array.Code);
     for (int i = 0; i < array.Length; i++)
     {
         WriteIntLength(stream, array[i].Length);
         stream.Write(array[i], 0, array[i].Length);
     }
 }
Ejemplo n.º 3
0
 private static void WriteCustomTypeArray(IBinaryWriter writer, RawCustomArray array, [Optional, DefaultParameterValue(true)] bool writeArrayIdentifier)
 {
     if (writeArrayIdentifier)
     {
         writer.WriteByte(0x79);
     }
     writer.WriteInt16((short)array.Length);
     writer.WriteByte(0x63);
     writer.WriteByte(array.Code);
     for (int i = 0; i < array.Length; i++)
     {
         writer.WriteInt16((short)array[i].Length);
         writer.WriteBytes(array[i]);
     }
 }
Ejemplo n.º 4
0
        private static bool ReadCustomTypeArray(IBinaryReader reader, int size, 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);
            }
            if ((size < 0) || ((size * 2) > (reader.BaseStream.Length - reader.BaseStream.Position)))
            {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Invalid length for array of type {2}: length={0}, bytesLeft={1}", new object[] { size, reader.BaseStream.Length - reader.BaseStream.Position, info.Type });
                }
                result = null;
                return(false);
            }
            if (info != null)
            {
                Array array = Array.CreateInstance(info.Type, size);
                for (short i = 0; i < size; i = (short)(i + 1))
                {
                    int    length = reader.ReadInt16();
                    byte[] arg    = reader.ReadBytes(length);
                    object obj2   = info.DeserializeFunction(arg);
                    array.SetValue(obj2, (int)i);
                }
                result = array;
            }
            else
            {
                RawCustomArray array2 = new RawCustomArray(typeCode, size);
                for (short j = 0; j < size; j = (short)(j + 1))
                {
                    int    num5    = reader.ReadInt16();
                    byte[] buffer2 = reader.ReadBytes(num5);
                    array2[j] = buffer2;
                }
                result = array2;
            }
            return(true);
        }
Ejemplo n.º 5
0
        private static bool ReadCustomTypeArray(byte[] data1, ref int offset, out object result)
        {
            uint           num;
            CustomTypeInfo info;

            if (!TryReadCompresssedUInt32(data1, ref offset, out num))
            {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Could not read size of custom type array custom type", new object[0]);
                }
                result = null;
                return(false);
            }
            if (offset >= data1.Length)
            {
                result = null;
                return(false);
            }
            byte typeCode = data1[offset++];

            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);
            }
            if (info != null)
            {
                Array array = Array.CreateInstance(info.Type, new long[] { (long)num });
                for (short i = 0; i < num; i = (short)(i + 1))
                {
                    uint   num4;
                    byte[] buffer;
                    if (!TryReadCompresssedUInt32(data1, ref offset, out num4))
                    {
                        result = null;
                        return(false);
                    }
                    if (!BigEndianReader.TryReadByteArray(data1, ref offset, (int)num4, out buffer))
                    {
                        result = null;
                        return(false);
                    }
                    object obj2 = info.DeserializeFunction(buffer);
                    array.SetValue(obj2, (int)i);
                }
                result = array;
            }
            else
            {
                RawCustomArray array2 = new RawCustomArray(typeCode, (int)num);
                for (short j = 0; j < num; j = (short)(j + 1))
                {
                    uint   num6;
                    byte[] buffer2;
                    if (!TryReadCompresssedUInt32(data1, ref offset, out num6))
                    {
                        result = null;
                        return(false);
                    }
                    if (!BigEndianReader.TryReadByteArray(data1, ref offset, (int)num6, out buffer2))
                    {
                        result = null;
                        return(false);
                    }
                    array2[j] = buffer2;
                }
                result = array2;
            }
            return(true);
        }