Exemple #1
0
        public override void ReadBinary(PListBinaryReader reader)
        {
            byte[] buffer = new byte[1 << reader.CurrentElementLength];
            if (reader.BaseStream.Read(buffer, 0, buffer.Length) != buffer.Length)
            {
                throw new PListFormatException();
            }
            switch (reader.CurrentElementLength)
            {
            case 0:
                throw new PListFormatException("Real < 32Bit");

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

            case 2:
                this.Value = (double)BitConverter.ToSingle(((IEnumerable <byte>)buffer).Reverse <byte>().ToArray <byte>(), 0);
                break;

            case 3:
                this.Value = BitConverter.ToDouble(((IEnumerable <byte>)buffer).Reverse <byte>().ToArray <byte>(), 0);
                break;

            default:
                throw new PListFormatException("Real > 64Bit");
            }
        }
Exemple #2
0
        public override void ReadBinary(PListBinaryReader reader)
        {
            byte[] buffer = new byte[1 << reader.CurrentElementLength];
            if (reader.BaseStream.Read(buffer, 0, buffer.Length) != buffer.Length)
            {
                throw new PListFormatException();
            }
            switch (reader.CurrentElementLength)
            {
            case 0:
                this.Value = (long)buffer[0];
                break;

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

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

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

            default:
                throw new PListFormatException("Int > 64Bit");
            }
        }
Exemple #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 != 0x0F)
     {
         throw new PListFormatException();
     }
 }
Exemple #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)
        {
            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);
        }
Exemple #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 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);
            }
        }
Exemple #6
0
        public override void ReadBinary(PListBinaryReader reader)
        {
            byte[] buffer = new byte[1 << reader.CurrentElementLength];
            if (reader.BaseStream.Read(buffer, 0, buffer.Length) != buffer.Length)
            {
                throw new PListFormatException();
            }
            double single;

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

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

            case 2:
                single = (double)BitConverter.ToSingle(((IEnumerable <byte>)buffer).Reverse <byte>().ToArray <byte>(), 0);
                break;

            case 3:
                single = BitConverter.ToDouble(((IEnumerable <byte>)buffer).Reverse <byte>().ToArray <byte>(), 0);
                break;

            default:
                throw new PListFormatException("Date > 64Bit");
            }
            this.Value = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(single);
        }
Exemple #7
0
 public override void ReadBinary(PListBinaryReader reader)
 {
     if (reader.CurrentElementLength != 8 && reader.CurrentElementLength != 9)
     {
         throw new PListFormatException();
     }
     this.Value = reader.CurrentElementLength == 9;
 }
Exemple #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)
 {
     Value = new Byte[reader.CurrentElementLength];
     if (reader.BaseStream.Read(Value, 0, Value.Length) != Value.Length)
     {
         throw new PListFormatException();
     }
 }
 public override void ReadBinary(PListBinaryReader reader)
 {
     byte[] numArray = new byte[reader.CurrentElementLength * ((int)reader.CurrentElementTypeCode == 5 ? 1 : 2)];
     if (reader.BaseStream.Read(numArray, 0, numArray.Length) != numArray.Length)
     {
         throw new PListFormatException();
     }
     this.Value = ((int)reader.CurrentElementTypeCode == 5 ? Encoding.UTF8 : Encoding.BigEndianUnicode).GetString(numArray);
 }
Exemple #10
0
 public void ReadBinary(PListBinaryReader reader)
 {
     byte[] buffer = new byte[reader.CurrentElementLength * (int)reader.ElementIdxSize];
     if (reader.BaseStream.Read(buffer, 0, buffer.Length) != buffer.Length)
     {
         throw new PListFormatException();
     }
     for (int index = 0; index < reader.CurrentElementLength; ++index)
     {
         this.Add(reader.ReadInternal((int)reader.ElementIdxSize == 1 ? (int)buffer[index] : (int)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 2 * index))));
     }
 }
Exemple #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 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);
        }
Exemple #12
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))));
            }
        }
Exemple #13
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");
            }
        }
Exemple #14
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");
            }
        }
Exemple #15
0
 public void ReadBinary(PListBinaryReader reader)
 {
     byte[] buffer1 = new byte[reader.CurrentElementLength * (int)reader.ElementIdxSize];
     byte[] buffer2 = new byte[reader.CurrentElementLength * (int)reader.ElementIdxSize];
     if (reader.BaseStream.Read(buffer1, 0, buffer1.Length) != buffer1.Length)
     {
         throw new PListFormatException();
     }
     if (reader.BaseStream.Read(buffer2, 0, buffer2.Length) != buffer2.Length)
     {
         throw new PListFormatException();
     }
     for (int index = 0; index < reader.CurrentElementLength; ++index)
     {
         IPListElement plistElement1 = reader.ReadInternal((int)reader.ElementIdxSize == 1 ? (int)buffer1[index] : (int)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer1, 2 * index)));
         if (!(plistElement1 is PListString))
         {
             throw new PListFormatException("Key is no String");
         }
         IPListElement plistElement2 = reader.ReadInternal((int)reader.ElementIdxSize == 1 ? (int)buffer2[index] : (int)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer2, 2 * index)));
         this.Add((string)((PListElement <string>)plistElement1), plistElement2);
     }
 }
Exemple #16
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);
        }
Exemple #17
0
        public static PListRoot Load(Stream stream)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(PListRoot));

            byte[] numArray = new byte[8];
            stream.Read(numArray, 0, numArray.Length);
            stream.Seek(0L, SeekOrigin.Begin);
            PListRoot plistRoot;

            if (Encoding.Default.GetString(numArray) == "bplist00")
            {
                PListBinaryReader plistBinaryReader = new PListBinaryReader();
                plistRoot        = new PListRoot();
                plistRoot.Format = PListFormat.Binary;
                plistRoot.Root   = plistBinaryReader.Read(stream);
            }
            else
            {
                plistRoot        = (PListRoot)xmlSerializer.Deserialize(stream);
                plistRoot.Format = PListFormat.Xml;
            }
            return(plistRoot);
        }