private static byte[] composeBinaryArray(List <object> objects) { List <byte> nums = new List <byte>(); List <byte> nums1 = new List <byte>(); List <int> nums2 = new List <int>(); for (int i = objects.Count - 1; i >= 0; i--) { Plist.composeBinary(objects[i]); Plist.offsetTable.Add(Plist.objectTable.Count); nums2.Add(Plist.refCount); Plist.refCount--; } if (objects.Count >= 15) { nums1.Add(175); nums1.AddRange(Plist.writeBinaryInteger(objects.Count, false)); } else { nums1.Add(Convert.ToByte(160 | Convert.ToByte(objects.Count))); } foreach (int num in nums2) { byte[] numArray = Plist.RegulateNullBytes(BitConverter.GetBytes(num), Plist.objRefSize); Array.Reverse(numArray); nums.InsertRange(0, numArray); } nums.InsertRange(0, nums1); Plist.objectTable.InsertRange(0, nums); return(nums.ToArray()); }
private static byte[] writeBinaryDictionary(Dictionary <string, object> dictionary) { List <byte> nums = new List <byte>(); List <byte> nums1 = new List <byte>(); List <int> nums2 = new List <int>(); for (int i = dictionary.Count - 1; i >= 0; i--) { object[] objArray = new object[dictionary.Count]; dictionary.Values.CopyTo(objArray, 0); Plist.composeBinary(objArray[i]); Plist.offsetTable.Add(Plist.objectTable.Count); nums2.Add(Plist.refCount); Plist.refCount--; } for (int j = dictionary.Count - 1; j >= 0; j--) { string[] strArrays = new string[dictionary.Count]; dictionary.Keys.CopyTo(strArrays, 0); Plist.composeBinary(strArrays[j]); Plist.offsetTable.Add(Plist.objectTable.Count); nums2.Add(Plist.refCount); Plist.refCount--; } if (dictionary.Count >= 15) { nums1.Add(223); nums1.AddRange(Plist.writeBinaryInteger(dictionary.Count, false)); } else { nums1.Add(Convert.ToByte(208 | Convert.ToByte(dictionary.Count))); } foreach (int num in nums2) { byte[] numArray = Plist.RegulateNullBytes(BitConverter.GetBytes(num), Plist.objRefSize); Array.Reverse(numArray); nums.InsertRange(0, numArray); } nums.InsertRange(0, nums1); Plist.objectTable.InsertRange(0, nums); return(nums.ToArray()); }
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()); }