public byte[] WriteBinary(object value) { SharedDataSet.OffsetTable.Clear(); SharedDataSet.ObjectTable.Clear(); SharedDataSet.ReferenceCount = 0; SharedDataSet.ObjectReferenceSize = 0; SharedDataSet.OffsetByteSize = 0; SharedDataSet.OffSetTableSize = 0; //Do not count the root node, subtract by 1 int totalRefs = XmlParser.CountObject(value) - 1; SharedDataSet.ReferenceCount = totalRefs; SharedDataSet.ObjectReferenceSize = Tools.RegulateNullBytes(BitConverter.GetBytes(SharedDataSet.ReferenceCount)).Length; Tools.ComposeBinary(value); WriteBinaryString("bplist00", false); SharedDataSet.OffSetTableSize = (long)SharedDataSet.ObjectTable.Count; SharedDataSet.OffsetTable.Add(SharedDataSet.ObjectTable.Count - 8); SharedDataSet.OffsetByteSize = Tools.RegulateNullBytes(BitConverter.GetBytes(SharedDataSet.OffsetTable[SharedDataSet.OffsetTable.Count - 1])).Length; List <byte> offsetBytes = new List <byte>(); SharedDataSet.OffsetTable.Reverse(); for (int i = 0; i < SharedDataSet.OffsetTable.Count; i++) { SharedDataSet.OffsetTable[i] = SharedDataSet.OffsetTable.Count - SharedDataSet.OffsetTable[i]; byte[] buffer = Tools.RegulateNullBytes(BitConverter.GetBytes(SharedDataSet.OffsetTable[i]), SharedDataSet.OffsetByteSize); Array.Reverse(buffer); offsetBytes.AddRange(buffer); } SharedDataSet.ObjectTable.AddRange(offsetBytes); SharedDataSet.ObjectTable.AddRange(new byte[6]); SharedDataSet.ObjectTable.Add(Convert.ToByte(SharedDataSet.OffsetByteSize)); SharedDataSet.ObjectTable.Add(Convert.ToByte(SharedDataSet.ObjectReferenceSize)); var a = BitConverter.GetBytes((long)totalRefs + 1); Array.Reverse(a); SharedDataSet.ObjectTable.AddRange(a); SharedDataSet.ObjectTable.AddRange(BitConverter.GetBytes((long)0)); a = BitConverter.GetBytes(SharedDataSet.OffSetTableSize); Array.Reverse(a); SharedDataSet.ObjectTable.AddRange(a); return(SharedDataSet.ObjectTable.ToArray()); }