public static void writeBinary(object value, string path) { using (BinaryWriter binaryWriter = new BinaryWriter(new FileStream(path, FileMode.Create))) { binaryWriter.Write(Plist.writeBinary(value)); } }
public override void Update() { try { Dictionary <string, object> strs = (Dictionary <string, object>)Plist.readPlist(this.FilePath); bool flag = false; if (!string.IsNullOrWhiteSpace(this.mVersionOne)) { strs["CFBundleShortVersionString"] = this.mVersionOne; flag = true; } if (!string.IsNullOrWhiteSpace(this.mVersionTwo)) { strs["CFBundleVersion"] = this.mVersionTwo; flag = true; } if (flag) { Plist.writeXml(strs, this.FilePath); } } catch { } }
public static void writeBinary(object value, Stream stream) { using (BinaryWriter binaryWriter = new BinaryWriter(stream)) { binaryWriter.Write(Plist.writeBinary(value)); } }
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()); }
public static void writeXml(object value, Stream stream) { using (StreamWriter streamWriter = new StreamWriter(stream)) { streamWriter.Write(Plist.writeXml(value)); } }
public static string writeXml(object value) { string str; using (MemoryStream memoryStream = new MemoryStream()) { XmlWriterSettings xmlWriterSetting = new XmlWriterSettings() { Encoding = new UTF8Encoding(false), ConformanceLevel = ConformanceLevel.Document, Indent = true }; using (XmlWriter xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSetting)) { xmlWriter.WriteStartDocument(); xmlWriter.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null); xmlWriter.WriteStartElement("plist"); xmlWriter.WriteAttributeString("version", "1.0"); Plist.compose(value, xmlWriter); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); xmlWriter.Close(); str = Encoding.UTF8.GetString(memoryStream.ToArray()); } } return(str); }
private static Dictionary <string, object> parseDictionary(XmlNode node) { XmlNodeList childNodes = node.ChildNodes; if (childNodes.Count % 2 != 0) { throw new DataMisalignedException("Dictionary elements must have an even number of child nodes"); } Dictionary <string, object> strs = new Dictionary <string, object>(); for (int i = 0; i < childNodes.Count; i += 2) { XmlNode itemOf = childNodes[i]; XmlNode xmlNodes = childNodes[i + 1]; if (itemOf.Name != "key") { throw new ApplicationException("expected a key node"); } object obj = Plist.parse(xmlNodes); if (obj != null) { strs.Add(itemOf.InnerText, obj); } } return(strs); }
private static object parseBinaryByteArray(int headerPosition) { int num; int count = Plist.getCount(headerPosition, out num); return(Plist.objectTable.GetRange(num, count).ToArray()); }
public static void writeXml(object value, string path) { using (StreamWriter streamWriter = new StreamWriter(path)) { streamWriter.Write(Plist.writeXml(value)); } }
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); }
private static byte[] writeBinaryString(string value, bool head) { List <byte> nums = new List <byte>(); List <byte> nums1 = new List <byte>(); char[] charArray = value.ToCharArray(); for (int i = 0; i < (int)charArray.Length; i++) { nums.Add(Convert.ToByte(charArray[i])); } if (head) { if (value.Length >= 15) { nums1.Add(95); nums1.AddRange(Plist.writeBinaryInteger(nums.Count, false)); } else { nums1.Add(Convert.ToByte(80 | Convert.ToByte(value.Length))); } } nums.InsertRange(0, nums1); Plist.objectTable.InsertRange(0, nums); return(nums.ToArray()); }
private static void parseOffsetTable(List <byte> offsetTableBytes) { for (int i = 0; i < offsetTableBytes.Count; i += Plist.offsetByteSize) { byte[] array = offsetTableBytes.GetRange(i, Plist.offsetByteSize).ToArray(); Array.Reverse(array); Plist.offsetTable.Add(BitConverter.ToInt32(Plist.RegulateNullBytes(array, 4), 0)); } }
private static object parseBinaryReal(int headerPosition) { byte item = Plist.objectTable[headerPosition]; int num = (int)Math.Pow(2, (double)(item & 15)); byte[] array = Plist.objectTable.GetRange(headerPosition + 1, num).ToArray(); Array.Reverse((Array)array); return(BitConverter.ToDouble(Plist.RegulateNullBytes(array, 8), 0)); }
private static void composeArray(List <object> value, XmlWriter writer) { writer.WriteStartElement("array"); foreach (object obj in value) { Plist.compose(obj, writer); } writer.WriteEndElement(); }
public static byte[] writeBinaryDate(DateTime obj) { List <byte> nums = new List <byte>(Plist.RegulateNullBytes(BitConverter.GetBytes(PlistDateConverter.ConvertToAppleTimeStamp(obj)), 8)); nums.Reverse(); nums.Insert(0, 51); Plist.objectTable.InsertRange(0, nums); return(nums.ToArray()); }
public static object readPlist(string path) { object obj; using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { obj = Plist.readPlist(fileStream, plistType.Auto); } return(obj); }
private static void compose(object value, XmlWriter writer) { if (value == null || value is string) { writer.WriteElementString("string", value as string); return; } if (value is int || value is long) { int num = (int)value; writer.WriteElementString("integer", num.ToString(NumberFormatInfo.InvariantInfo)); return; } if (value is Dictionary <string, object> || value.GetType().ToString().StartsWith("System.Collections.Generic.Dictionary`2[System.String")) { Dictionary <string, object> strs = value as Dictionary <string, object>; if (strs == null) { strs = new Dictionary <string, object>(); IDictionary dictionaries = (IDictionary)value; foreach (object key in dictionaries.Keys) { strs.Add(key.ToString(), dictionaries[key]); } } Plist.writeDictionaryValues(strs, writer); return; } if (value is List <object> ) { Plist.composeArray((List <object>)value, writer); return; } if (value is byte[]) { writer.WriteElementString("data", Convert.ToBase64String((byte[])value)); return; } if (value is float || value is double) { double num1 = (double)value; writer.WriteElementString("real", num1.ToString(NumberFormatInfo.InvariantInfo)); return; } if (value is DateTime) { writer.WriteElementString("date", XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.Utc)); return; } if (!(value is bool)) { throw new Exception(string.Format("Value type '{0}' is unhandled", value.GetType().ToString())); } writer.WriteElementString(value.ToString().ToLower(), ""); }
private static void parseTrailer(List <byte> trailer) { Plist.offsetByteSize = BitConverter.ToInt32(Plist.RegulateNullBytes(trailer.GetRange(6, 1).ToArray(), 4), 0); Plist.objRefSize = BitConverter.ToInt32(Plist.RegulateNullBytes(trailer.GetRange(7, 1).ToArray(), 4), 0); byte[] array = trailer.GetRange(12, 4).ToArray(); Array.Reverse((Array)array); Plist.refCount = BitConverter.ToInt32(array, 0); byte[] numArray = trailer.GetRange(24, 8).ToArray(); Array.Reverse((Array)numArray); Plist.offsetTableOffset = BitConverter.ToInt64(numArray, 0); }
private static void writeDictionaryValues(Dictionary <string, object> dictionary, XmlWriter writer) { writer.WriteStartElement("dict"); foreach (string key in dictionary.Keys) { object item = dictionary[key]; writer.WriteElementString("key", key); Plist.compose(item, writer); } writer.WriteEndElement(); }
private static object parseBinaryAsciiString(int headerPosition) { int num; int count = Plist.getCount(headerPosition, out num); List <byte> range = Plist.objectTable.GetRange(num, count); if (range.Count <= 0) { return(string.Empty); } return(Encoding.ASCII.GetString(range.ToArray())); }
public string GetVersion(string Key) { string str; try { str = ((Dictionary <string, object>)Plist.readPlist(this.FilePath))[Key].ToString(); } catch { str = string.Empty; } return(str); }
private static List <object> parseArray(XmlNode node) { List <object> objs = new List <object>(); foreach (object childNode in node.ChildNodes) { object obj = Plist.parse((XmlNode)childNode); if (obj == null) { continue; } objs.Add(obj); } return(objs); }
private static byte[] writeBinaryDouble(double value) { List <byte> nums = new List <byte>(Plist.RegulateNullBytes(BitConverter.GetBytes(value), 4)); while ((double)nums.Count != Math.Pow(2, Math.Log((double)nums.Count) / Math.Log(2))) { nums.Add(0); } int num = 32 | (int)(Math.Log((double)nums.Count) / Math.Log(2)); nums.Reverse(); nums.Insert(0, Convert.ToByte(num)); Plist.objectTable.InsertRange(0, nums); return(nums.ToArray()); }
private static int getCount(int bytePosition, out int newBytePosition) { int num; byte num1 = Convert.ToByte(Plist.objectTable[bytePosition] & 15); if (num1 >= 15) { num = (int)Plist.parseBinaryInt(bytePosition + 1, out newBytePosition); } else { num = num1; newBytePosition = bytePosition + 1; } return(num); }
private static object readBinary(byte[] data) { Plist.offsetTable.Clear(); List <byte> nums = new List <byte>(); Plist.objectTable.Clear(); Plist.refCount = 0; Plist.objRefSize = 0; Plist.offsetByteSize = 0; Plist.offsetTableOffset = (long)0; List <byte> nums1 = new List <byte>(data); Plist.parseTrailer(nums1.GetRange(nums1.Count - 32, 32)); Plist.objectTable = nums1.GetRange(0, (int)Plist.offsetTableOffset); Plist.parseOffsetTable(nums1.GetRange((int)Plist.offsetTableOffset, nums1.Count - (int)Plist.offsetTableOffset - 32)); return(Plist.parseBinary(0)); }
private static object parse(XmlNode node) { string name = node.Name; if (name == "dict") { return(Plist.parseDictionary(node)); } if (name == "array") { return(Plist.parseArray(node)); } if (name == "string") { return(node.InnerText); } if (name == "integer") { return(Convert.ToInt32(node.InnerText, NumberFormatInfo.InvariantInfo)); } if (name == "real") { return(Convert.ToDouble(node.InnerText, NumberFormatInfo.InvariantInfo)); } if (name == "false") { return(false); } if (name == "true") { return(true); } if (name == "null") { return(null); } if (name == "date") { return(XmlConvert.ToDateTime(node.InnerText, XmlDateTimeSerializationMode.Utc)); } if (name != "data") { throw new ApplicationException(string.Format("Plist Node `{0}' is not supported", node.Name)); } return(Convert.FromBase64String(node.InnerText)); }
private static byte[] writeBinaryByteArray(byte[] value) { List <byte> nums = new List <byte>(value); List <byte> nums1 = new List <byte>(); if ((int)value.Length >= 15) { nums1.Add(79); nums1.AddRange(Plist.writeBinaryInteger(nums.Count, false)); } else { nums1.Add(Convert.ToByte(64 | Convert.ToByte((int)value.Length))); } 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()); }
private static byte[] writeBinaryInteger(int value, bool write) { List <byte> nums = new List <byte>(BitConverter.GetBytes((long)value)); nums = new List <byte>(Plist.RegulateNullBytes(nums.ToArray())); while ((double)nums.Count != Math.Pow(2, Math.Log((double)nums.Count) / Math.Log(2))) { nums.Add(0); } int num = 16 | (int)(Math.Log((double)nums.Count) / Math.Log(2)); nums.Reverse(); nums.Insert(0, Convert.ToByte(num)); if (write) { Plist.objectTable.InsertRange(0, nums); } return(nums.ToArray()); }
private static object parseBinaryDictionary(int objRef) { int num; Dictionary <string, object> strs = new Dictionary <string, object>(); List <int> nums = new List <int>(); int count = 0; count = Plist.getCount(Plist.offsetTable[objRef], out num); num = (count >= 15 ? Plist.offsetTable[objRef] + 2 + (int)Plist.RegulateNullBytes(BitConverter.GetBytes(count), 1).Length : Plist.offsetTable[objRef] + 1); for (int i = num; i < num + count * 2 * Plist.objRefSize; i += Plist.objRefSize) { byte[] array = Plist.objectTable.GetRange(i, Plist.objRefSize).ToArray(); Array.Reverse(array); nums.Add(BitConverter.ToInt32(Plist.RegulateNullBytes(array, 4), 0)); } for (int j = 0; j < count; j++) { strs.Add((string)Plist.parseBinary(nums[j]), Plist.parseBinary(nums[j + count])); } return(strs); }