コード例 #1
0
        private static int countObject(object value)
        {
            int    count = 0;
            string str   = value.GetType().ToString();

            if (str == "System.Collections.Generic.Dictionary`2[System.String,System.Object]")
            {
                Dictionary <string, object> strs = (Dictionary <string, object>)value;
                foreach (string key in strs.Keys)
                {
                    count += Plist.countObject(strs[key]);
                }
                count += strs.Keys.Count;
                count++;
            }
            else if (str == "System.Collections.Generic.List`1[System.Object]")
            {
                foreach (object obj in (List <object>)value)
                {
                    count += Plist.countObject(obj);
                }
                count++;
            }
            else
            {
                count++;
            }
            return(count);
        }
コード例 #2
0
        public static byte[] writeBinary(object value)
        {
            Plist.offsetTable.Clear();
            Plist.objectTable.Clear();
            Plist.refCount          = 0;
            Plist.objRefSize        = 0;
            Plist.offsetByteSize    = 0;
            Plist.offsetTableOffset = (long)0;
            int num = Plist.countObject(value) - 1;

            Plist.refCount   = num;
            Plist.objRefSize = (int)Plist.RegulateNullBytes(BitConverter.GetBytes(Plist.refCount)).Length;
            Plist.composeBinary(value);
            Plist.writeBinaryString("bplist00", false);
            Plist.offsetTableOffset = (long)Plist.objectTable.Count;
            Plist.offsetTable.Add(Plist.objectTable.Count - 8);
            Plist.offsetByteSize = (int)Plist.RegulateNullBytes(BitConverter.GetBytes(Plist.offsetTable[Plist.offsetTable.Count - 1])).Length;
            List <byte> nums = new List <byte>();

            Plist.offsetTable.Reverse();
            for (int i = 0; i < Plist.offsetTable.Count; i++)
            {
                Plist.offsetTable[i] = Plist.objectTable.Count - Plist.offsetTable[i];
                byte[] numArray = Plist.RegulateNullBytes(BitConverter.GetBytes(Plist.offsetTable[i]), Plist.offsetByteSize);
                Array.Reverse(numArray);
                nums.AddRange(numArray);
            }
            Plist.objectTable.AddRange(nums);
            Plist.objectTable.AddRange(new byte[6]);
            Plist.objectTable.Add(Convert.ToByte(Plist.offsetByteSize));
            Plist.objectTable.Add(Convert.ToByte(Plist.objRefSize));
            byte[] bytes = BitConverter.GetBytes((long)num + (long)1);
            Array.Reverse(bytes);
            Plist.objectTable.AddRange(bytes);
            Plist.objectTable.AddRange(BitConverter.GetBytes((long)0));
            bytes = BitConverter.GetBytes(Plist.offsetTableOffset);
            Array.Reverse(bytes);
            Plist.objectTable.AddRange(bytes);
            return(Plist.objectTable.ToArray());
        }