示例#1
0
        /// <summary>
        /// Reads this element binary from the reader.
        /// </summary>
        /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
        /// <remarks>Provided for internal use only.</remarks>
        public void ReadBinary(PListBinaryReader reader)
        {
            Byte[] bufKeys = new Byte[reader.CurrentElementLength * reader.ElementIdxSize];
            Byte[] bufVals = new Byte[reader.CurrentElementLength * reader.ElementIdxSize];
            if (reader.BaseStream.Read(bufKeys, 0, bufKeys.Length) != bufKeys.Length)
            {
                throw new PListFormatException();
            }

            if (reader.BaseStream.Read(bufVals, 0, bufVals.Length) != bufVals.Length)
            {
                throw new PListFormatException();
            }

            for (int i = 0; i < reader.CurrentElementLength; i++)
            {
                IPListElement plKey = reader.ReadInternal(reader.ElementIdxSize == 1 ?
                                                          bufKeys[i] : IPAddress.NetworkToHostOrder(BitConverter.ToInt16(bufKeys, 2 * i)));

                if (!(plKey is PListString))
                {
                    throw new PListFormatException("Key is no String");
                }

                IPListElement plVal = reader.ReadInternal(reader.ElementIdxSize == 1 ?
                                                          bufVals[i] : IPAddress.NetworkToHostOrder(BitConverter.ToInt16(bufVals, 2 * i)));

                Add((PListString)plKey, plVal);
            }
        }
示例#2
0
        /// <summary>
        /// Reads this element binary from the reader.
        /// </summary>
        /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
        /// <remarks>Provided for internal use only.</remarks>
        public override void ReadBinary(PListBinaryReader reader)
        {
            Debug.WriteLine("Unverified", "WARNING");

            Byte[] buf = new Byte[1 << (int)reader.CurrentElementLength];
            if (reader.BaseStream.Read(buf, 0, buf.Length) != buf.Length)
            {
                throw new PListFormatException();
            }

            double ticks = -1;

            switch (reader.CurrentElementLength)
            {
            case 0: throw new PListFormatException("Date < 32Bit");

            case 1: throw new PListFormatException("Date < 32Bit");

            case 2: ticks = BitConverter.ToSingle(buf.Reverse().ToArray(), 0); break;

            case 3: ticks = BitConverter.ToDouble(buf.Reverse().ToArray(), 0); break;

            default: throw new PListFormatException("Date > 64Bit");
            }

            Value = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(ticks);
        }
示例#3
0
 /// <summary>
 /// Reads this element binary from the reader.
 /// </summary>
 /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
 /// <remarks>Provided for internal use only.</remarks>
 public void ReadBinary(PListBinaryReader reader)
 {
     if (reader.CurrentElementLength != 0x00)
     {
         throw new PListFormatException();
     }
 }
示例#4
0
 /// <summary>
 /// Reads this element binary from the reader.
 /// </summary>
 /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
 /// <remarks>Provided for internal use only.</remarks>
 public override void ReadBinary(PListBinaryReader reader)
 {
     Value = new Byte[reader.CurrentElementLength];
     if (reader.BaseStream.Read(Value, 0, Value.Length) != Value.Length)
     {
         throw new PListFormatException();
     }
 }
示例#5
0
        /// <summary>
        /// Reads this element binary from the reader.
        /// </summary>
        /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
        /// <remarks>Provided for internal use only.</remarks>
        public override void ReadBinary(PListBinaryReader reader)
        {
            if (reader.CurrentElementLength != 8 && reader.CurrentElementLength != 9)
            {
                throw new PListFormatException();
            }

            Value = reader.CurrentElementLength == 9;
        }
示例#6
0
        /// <summary>
        /// Reads this element binary from the reader.
        /// </summary>
        /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
        /// <remarks>Provided for internal use only.</remarks>
        public override void ReadBinary(PListBinaryReader reader)
        {
            Byte[] buf = new Byte[reader.CurrentElementLength * (reader.CurrentElementTypeCode == 5 ? 1 : 2)];
            if (reader.BaseStream.Read(buf, 0, buf.Length) != buf.Length)
            {
                throw new PListFormatException();
            }

            Encoding enc = reader.CurrentElementTypeCode == 5 ? Encoding.UTF8 : Encoding.BigEndianUnicode;

            Value = enc.GetString(buf);

            //Value = Convert.ToBase64String(buf);
        }
示例#7
0
        /// <summary>
        /// Reads this element binary from the reader.
        /// </summary>
        /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
        /// <remarks>Provided for internal use only.</remarks>
        public void ReadBinary(PListBinaryReader reader)
        {
            Byte[] buf = new Byte[reader.CurrentElementLength * reader.ElementIdxSize];
            if (reader.BaseStream.Read(buf, 0, buf.Length) != buf.Length)
            {
                throw new PListFormatException();
            }

            for (int i = 0; i < reader.CurrentElementLength; i++)
            {
                Add(reader.ReadInternal(reader.ElementIdxSize == 1 ?
                                        buf[i] : IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buf, 2 * i))));
            }
        }
示例#8
0
        /// <summary>
        /// Reads this element binary from the reader.
        /// </summary>
        /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
        /// <remarks>Provided for internal use only.</remarks>
        public override void ReadBinary(PListBinaryReader reader)
        {
            Byte[] buf = new Byte[1 << (int)reader.CurrentElementLength];
            if (reader.BaseStream.Read(buf, 0, buf.Length) != buf.Length)
            {
                throw new PListFormatException();
            }


            switch (reader.CurrentElementLength)
            {
            case 0: throw new PListFormatException("Real < 32Bit");

            case 1: throw new PListFormatException("Real < 32Bit");

            case 2: Value = BitConverter.ToSingle(buf.Reverse().ToArray(), 0); break;

            case 3: Value = BitConverter.ToDouble(buf.Reverse().ToArray(), 0); break;

            default: throw new PListFormatException("Real > 64Bit");
            }
        }
示例#9
0
        /// <summary>
        /// Reads this element binary from the reader.
        /// </summary>
        /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
        /// <remarks>Provided for internal use only.</remarks>
        public override void ReadBinary(PListBinaryReader reader)
        {
            Byte[] buf = new Byte[1 << (int)reader.CurrentElementLength];
            if (reader.BaseStream.Read(buf, 0, buf.Length) != buf.Length)
            {
                throw new PListFormatException();
            }


            switch (reader.CurrentElementLength)
            {
            case 0: Value = buf[0]; break;

            case 1: Value = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buf, 0)); break;

            case 2: Value = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(buf, 0)); break;

            case 3: Value = IPAddress.NetworkToHostOrder(BitConverter.ToInt64(buf, 0)); break;

            default: throw new PListFormatException("Int > 64Bit");
            }
        }
示例#10
0
        /// <summary>
        /// Loads the PList from specified stream.
        /// </summary>
        /// <param name="stream">The stream containing the PList.</param>
        /// <returns>A <see cref="PListRoot"/> object loaded from the stream</returns>
        public static PListRoot Load(Stream stream)
        {
            PListRoot     root = null;
            XmlSerializer ser  = new XmlSerializer(typeof(PListRoot));

            Byte[] buf = new Byte[8];
            stream.Read(buf, 0, buf.Length);
            stream.Seek(0, SeekOrigin.Begin);
            if (Encoding.Default.GetString(buf) == "bplist00")
            {
                PListBinaryReader reader = new PListBinaryReader();
                root        = new PListRoot();
                root.Format = PListFormat.Binary;
                root.Root   = reader.Read(stream);
            }
            else
            {
                root        = (PListRoot)ser.Deserialize(stream);
                root.Format = PListFormat.Xml;
            }

            return(root);
        }
示例#11
0
 /// <summary>
 /// Reads this element binary from the reader.
 /// </summary>
 /// <param name="reader">The <see cref="T:CE.iPhone.PListBinaryReader"/> from which the element is read.</param>
 /// <remarks>Provided for internal use only.</remarks>
 public abstract void ReadBinary(PListBinaryReader reader);