com.taptap.sdk.core 4.3.0-aplha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/Editor/BuildTargetUtils.cs +14 -0
  2. package/Editor/BuildTargetUtils.cs.meta +11 -0
  3. package/Editor/LinkXMLGenerator.cs +70 -0
  4. package/Editor/LinkXMLGenerator.cs.meta +11 -0
  5. package/Editor/Plist.cs +954 -0
  6. package/Editor/Plist.cs.meta +3 -0
  7. package/Editor/SDKLinkProcessBuild.cs +119 -0
  8. package/Editor/SDKLinkProcessBuild.cs.meta +11 -0
  9. package/Editor/TapFileHelper.cs +168 -0
  10. package/Editor/TapFileHelper.cs.meta +3 -0
  11. package/Editor/TapSDK.Core.Editor.asmdef +15 -0
  12. package/Editor/TapSDK.Core.Editor.asmdef.meta +7 -0
  13. package/Editor/TapSDKCoreCompile.cs +284 -0
  14. package/Editor/TapSDKCoreCompile.cs.meta +3 -0
  15. package/Editor/TapSDKCoreIOSProcessor.cs +74 -0
  16. package/Editor/TapSDKCoreIOSProcessor.cs.meta +3 -0
  17. package/Editor/UI/ScrollViewEditor.cs +267 -0
  18. package/Editor/UI/ScrollViewEditor.cs.meta +12 -0
  19. package/Editor/UI/ScrollViewExEditor.cs +34 -0
  20. package/Editor/UI/ScrollViewExEditor.cs.meta +12 -0
  21. package/Editor/UI/TapSDK.UI.Editor.asmdef +17 -0
  22. package/Editor/UI/TapSDK.UI.Editor.asmdef.meta +7 -0
  23. package/Editor/UI.meta +9 -0
  24. package/Editor.meta +8 -0
  25. package/Mobile/Editor/NativeDependencies.xml +22 -0
  26. package/Mobile/Editor/NativeDependencies.xml.meta +7 -0
  27. package/Mobile/Editor/TapCommonMobileProcessBuild.cs +20 -0
  28. package/Mobile/Editor/TapCommonMobileProcessBuild.cs.meta +11 -0
  29. package/Mobile/Editor/TapSDK.Core.Mobile.Editor.asmdef +17 -0
  30. package/Mobile/Editor/TapSDK.Core.Mobile.Editor.asmdef.meta +7 -0
  31. package/Mobile/Editor.meta +8 -0
  32. package/Mobile/Runtime/AndroidNativeWrapper.cs +50 -0
  33. package/Mobile/Runtime/AndroidNativeWrapper.cs.meta +11 -0
  34. package/Mobile/Runtime/Bridge.cs +84 -0
  35. package/Mobile/Runtime/Bridge.cs.meta +11 -0
  36. package/Mobile/Runtime/BridgeAndroid.cs +73 -0
  37. package/Mobile/Runtime/BridgeAndroid.cs.meta +11 -0
  38. package/Mobile/Runtime/BridgeCallback.cs +35 -0
  39. package/Mobile/Runtime/BridgeCallback.cs.meta +11 -0
  40. package/Mobile/Runtime/BridgeIOS.cs +113 -0
  41. package/Mobile/Runtime/BridgeIOS.cs.meta +11 -0
  42. package/Mobile/Runtime/Command.cs +119 -0
  43. package/Mobile/Runtime/Command.cs.meta +11 -0
  44. package/Mobile/Runtime/Constants.cs +9 -0
  45. package/Mobile/Runtime/Constants.cs.meta +11 -0
  46. package/Mobile/Runtime/EngineBridgeInitializer.cs +33 -0
  47. package/Mobile/Runtime/EngineBridgeInitializer.cs.meta +11 -0
  48. package/Mobile/Runtime/IBridge.cs +15 -0
  49. package/Mobile/Runtime/IBridge.cs.meta +11 -0
  50. package/Mobile/Runtime/IOSNativeWrapper.cs +273 -0
  51. package/Mobile/Runtime/IOSNativeWrapper.cs.meta +11 -0
  52. package/Mobile/Runtime/Result.cs +37 -0
  53. package/Mobile/Runtime/Result.cs.meta +11 -0
  54. package/Mobile/Runtime/TapCoreMobile.cs +71 -0
  55. package/Mobile/Runtime/TapCoreMobile.cs.meta +11 -0
  56. package/Mobile/Runtime/TapEventMobile.cs +265 -0
  57. package/Mobile/Runtime/TapEventMobile.cs.meta +11 -0
  58. package/Mobile/Runtime/TapSDK.Core.Mobile.Runtime.asmdef +18 -0
  59. package/Mobile/Runtime/TapSDK.Core.Mobile.Runtime.asmdef.meta +7 -0
  60. package/Mobile/Runtime/TapUUID.cs +9 -0
  61. package/Mobile/Runtime/TapUUID.cs.meta +11 -0
  62. package/Mobile/Runtime.meta +8 -0
  63. package/Mobile.meta +8 -0
  64. package/Plugins/iOS.meta +8 -0
  65. package/Plugins.meta +8 -0
  66. package/Resources/Fonts/taptap-sdk-bold.ttf +0 -0
  67. package/Resources/Fonts/taptap-sdk-bold.ttf.meta +22 -0
  68. package/Resources/Fonts/taptap-sdk.ttf +0 -0
  69. package/Resources/Fonts/taptap-sdk.ttf.meta +21 -0
  70. package/Resources/Fonts.meta +8 -0
  71. package/Resources/Loading.prefab +260 -0
  72. package/Resources/Loading.prefab.meta +7 -0
  73. package/Resources/TapCommonTip.prefab +194 -0
  74. package/Resources/TapCommonTip.prefab.meta +7 -0
  75. package/Resources/TapCommonToastBlack.prefab +528 -0
  76. package/Resources/TapCommonToastBlack.prefab.meta +7 -0
  77. package/Resources/TapCommonToastWhite.prefab +411 -0
  78. package/Resources/TapCommonToastWhite.prefab.meta +7 -0
  79. package/Resources/TapSDKCommonTapIcon-v2.png +0 -0
  80. package/Resources/TapSDKCommonTapIcon-v2.png.meta +128 -0
  81. package/Resources/TapSDKCommonTapIcon.png +0 -0
  82. package/Resources/TapSDKCommonTapIcon.png.meta +128 -0
  83. package/Resources/TapSDKCommonToastBg.png +0 -0
  84. package/Resources/TapSDKCommonToastBg.png.meta +128 -0
  85. package/Resources/TapSDKConstantUIRoot.prefab +100 -0
  86. package/Resources/TapSDKConstantUIRoot.prefab.meta +7 -0
  87. package/Resources/TapSDKUIRoot.prefab +100 -0
  88. package/Resources/TapSDKUIRoot.prefab.meta +7 -0
  89. package/Resources/TapTapBtn_White.png +0 -0
  90. package/Resources/TapTapBtn_White.png.meta +128 -0
  91. package/Resources/TapTapBtn_White_2.png +0 -0
  92. package/Resources/TapTapBtn_White_2.png.meta +128 -0
  93. package/Resources/ToastBackground.png +0 -0
  94. package/Resources/ToastBackground.png.meta +128 -0
  95. package/Resources/detail_bg.png +0 -0
  96. package/Resources/detail_bg.png.meta +92 -0
  97. package/Resources/success.png +0 -0
  98. package/Resources/success.png.meta +128 -0
  99. package/Resources/taptap-bg.png +0 -0
  100. package/Resources/taptap-bg.png.meta +140 -0
  101. package/Resources/taptap-close.png +0 -0
  102. package/Resources/taptap-close.png.meta +146 -0
  103. package/Resources/taptap-router-v2.png +0 -0
  104. package/Resources/taptap-router-v2.png.meta +128 -0
  105. package/Resources/taptap-router.png +0 -0
  106. package/Resources/taptap-router.png.meta +146 -0
  107. package/Resources/taptap-sdk-refresh 1.png +0 -0
  108. package/Resources/taptap-sdk-refresh 1.png.meta +128 -0
  109. package/Resources/taptap-toast-error.png +0 -0
  110. package/Resources/taptap-toast-error.png.meta +128 -0
  111. package/Resources/taptap-toast-info.png +0 -0
  112. package/Resources/taptap-toast-info.png.meta +128 -0
  113. package/Resources/taptap-toast-success.png +0 -0
  114. package/Resources/taptap-toast-success.png.meta +128 -0
  115. package/Resources/taptap-toast-warning.png +0 -0
  116. package/Resources/taptap-toast-warning.png.meta +128 -0
  117. package/Resources.meta +8 -0
  118. package/Runtime/Internal/Http/TapHttpClient.cs +176 -0
  119. package/Runtime/Internal/Http/TapHttpClient.cs.meta +11 -0
  120. package/Runtime/Internal/Http/TapHttpUtils.cs +83 -0
  121. package/Runtime/Internal/Http/TapHttpUtils.cs.meta +11 -0
  122. package/Runtime/Internal/Http.meta +8 -0
  123. package/Runtime/Internal/Init/IInitTask.cs +18 -0
  124. package/Runtime/Internal/Init/IInitTask.cs.meta +11 -0
  125. package/Runtime/Internal/Init.meta +8 -0
  126. package/Runtime/Internal/Json/TapJsonConverter.cs +40 -0
  127. package/Runtime/Internal/Json/TapJsonConverter.cs.meta +11 -0
  128. package/Runtime/Internal/Json.meta +8 -0
  129. package/Runtime/Internal/Platform/ITapCorePlatform.cs +12 -0
  130. package/Runtime/Internal/Platform/ITapCorePlatform.cs.meta +11 -0
  131. package/Runtime/Internal/Platform/ITapEventPlatform.cs +37 -0
  132. package/Runtime/Internal/Platform/ITapEventPlatform.cs.meta +11 -0
  133. package/Runtime/Internal/Platform/PlatformTypeUtils.cs +46 -0
  134. package/Runtime/Internal/Platform/PlatformTypeUtils.cs.meta +11 -0
  135. package/Runtime/Internal/Platform.meta +8 -0
  136. package/Runtime/Internal/UI/Base/Const.cs +27 -0
  137. package/Runtime/Internal/UI/Base/Const.cs.meta +11 -0
  138. package/Runtime/Internal/UI/Base/GraphicRaycasterBugFixed.cs +240 -0
  139. package/Runtime/Internal/UI/Base/GraphicRaycasterBugFixed.cs.meta +3 -0
  140. package/Runtime/Internal/UI/Base/LoadingPanelController.cs +29 -0
  141. package/Runtime/Internal/UI/Base/LoadingPanelController.cs.meta +11 -0
  142. package/Runtime/Internal/UI/Base/MonoSingleton.cs +102 -0
  143. package/Runtime/Internal/UI/Base/MonoSingleton.cs.meta +11 -0
  144. package/Runtime/Internal/UI/Base/Singleton.cs +29 -0
  145. package/Runtime/Internal/UI/Base/Singleton.cs.meta +11 -0
  146. package/Runtime/Internal/UI/Base/TipPanelController.cs +45 -0
  147. package/Runtime/Internal/UI/Base/TipPanelController.cs.meta +3 -0
  148. package/Runtime/Internal/UI/Base/ToastBlackPanelController.cs +95 -0
  149. package/Runtime/Internal/UI/Base/ToastBlackPanelController.cs.meta +11 -0
  150. package/Runtime/Internal/UI/Base/ToastWhitePanelController.cs +79 -0
  151. package/Runtime/Internal/UI/Base/ToastWhitePanelController.cs.meta +3 -0
  152. package/Runtime/Internal/UI/Base/UIManager.cs +724 -0
  153. package/Runtime/Internal/UI/Base/UIManager.cs.meta +11 -0
  154. package/Runtime/Internal/UI/Base.meta +8 -0
  155. package/Runtime/Internal/UI/BasePanel/BasePanelController.cs +385 -0
  156. package/Runtime/Internal/UI/BasePanel/BasePanelController.cs.meta +11 -0
  157. package/Runtime/Internal/UI/BasePanel.meta +8 -0
  158. package/Runtime/Internal/UI/Params/BasePanelConfig.cs +18 -0
  159. package/Runtime/Internal/UI/Params/BasePanelConfig.cs.meta +11 -0
  160. package/Runtime/Internal/UI/Params/IOpenPanelParameter.cs +7 -0
  161. package/Runtime/Internal/UI/Params/IOpenPanelParameter.cs.meta +11 -0
  162. package/Runtime/Internal/UI/Params.meta +8 -0
  163. package/Runtime/Internal/UI/ScrollViewEx/ObjPool/SimpleObjPool.cs +76 -0
  164. package/Runtime/Internal/UI/ScrollViewEx/ObjPool/SimpleObjPool.cs.meta +12 -0
  165. package/Runtime/Internal/UI/ScrollViewEx/ObjPool.meta +9 -0
  166. package/Runtime/Internal/UI/ScrollViewEx/ScrollView/ScrollView.cs +828 -0
  167. package/Runtime/Internal/UI/ScrollViewEx/ScrollView/ScrollView.cs.meta +12 -0
  168. package/Runtime/Internal/UI/ScrollViewEx/ScrollView/ScrollViewEx.cs +245 -0
  169. package/Runtime/Internal/UI/ScrollViewEx/ScrollView/ScrollViewEx.cs.meta +12 -0
  170. package/Runtime/Internal/UI/ScrollViewEx/ScrollView.meta +9 -0
  171. package/Runtime/Internal/UI/ScrollViewEx.meta +8 -0
  172. package/Runtime/Internal/UI.meta +8 -0
  173. package/Runtime/Internal/Utils/BridgeUtils.cs +29 -0
  174. package/Runtime/Internal/Utils/BridgeUtils.cs.meta +11 -0
  175. package/Runtime/Internal/Utils/ImageUtils.cs +147 -0
  176. package/Runtime/Internal/Utils/ImageUtils.cs.meta +11 -0
  177. package/Runtime/Internal/Utils/TapLoom.cs +155 -0
  178. package/Runtime/Internal/Utils/TapLoom.cs.meta +11 -0
  179. package/Runtime/Internal/Utils/UrlUtils.cs +34 -0
  180. package/Runtime/Internal/Utils/UrlUtils.cs.meta +11 -0
  181. package/Runtime/Internal/Utils.meta +8 -0
  182. package/Runtime/Internal.meta +8 -0
  183. package/Runtime/Public/DataStorage.cs +141 -0
  184. package/Runtime/Public/DataStorage.cs.meta +11 -0
  185. package/Runtime/Public/ITapPropertiesProxy.cs +6 -0
  186. package/Runtime/Public/ITapPropertiesProxy.cs.meta +11 -0
  187. package/Runtime/Public/Json.cs +636 -0
  188. package/Runtime/Public/Json.cs.meta +11 -0
  189. package/Runtime/Public/Log/TapLogLevel.cs +7 -0
  190. package/Runtime/Public/Log/TapLogLevel.cs.meta +11 -0
  191. package/Runtime/Public/Log/TapLogger.cs +48 -0
  192. package/Runtime/Public/Log/TapLogger.cs.meta +11 -0
  193. package/Runtime/Public/Log.meta +8 -0
  194. package/Runtime/Public/Platform.cs +27 -0
  195. package/Runtime/Public/Platform.cs.meta +11 -0
  196. package/Runtime/Public/RegionType.cs +8 -0
  197. package/Runtime/Public/RegionType.cs.meta +11 -0
  198. package/Runtime/Public/SafeDictionary.cs +27 -0
  199. package/Runtime/Public/SafeDictionary.cs.meta +11 -0
  200. package/Runtime/Public/TapError.cs +62 -0
  201. package/Runtime/Public/TapError.cs.meta +11 -0
  202. package/Runtime/Public/TapErrorCode.cs +44 -0
  203. package/Runtime/Public/TapErrorCode.cs.meta +11 -0
  204. package/Runtime/Public/TapException.cs +24 -0
  205. package/Runtime/Public/TapException.cs.meta +11 -0
  206. package/Runtime/Public/TapLanguage.cs +21 -0
  207. package/Runtime/Public/TapLanguage.cs.meta +11 -0
  208. package/Runtime/Public/TapLocalizeManager.cs +128 -0
  209. package/Runtime/Public/TapLocalizeManager.cs.meta +11 -0
  210. package/Runtime/Public/TapTapEvent.cs +93 -0
  211. package/Runtime/Public/TapTapEvent.cs.meta +11 -0
  212. package/Runtime/Public/TapTapSDK.cs +96 -0
  213. package/Runtime/Public/TapTapSDK.cs.meta +11 -0
  214. package/Runtime/Public/TapTapSDKCoreOptions.cs +104 -0
  215. package/Runtime/Public/TapTapSDKCoreOptions.cs.meta +11 -0
  216. package/Runtime/Public.meta +8 -0
  217. package/Runtime/TapSDK.Core.Runtime.asmdef +3 -0
  218. package/Runtime/TapSDK.Core.Runtime.asmdef.meta +7 -0
  219. package/Runtime.meta +8 -0
  220. package/Standalone/Editor/TapCoreStandaloneProcessBuild.cs +20 -0
  221. package/Standalone/Editor/TapCoreStandaloneProcessBuild.cs.meta +11 -0
  222. package/Standalone/Editor/TapSDK.Core.Standalone.Editor.asmdef +17 -0
  223. package/Standalone/Editor/TapSDK.Core.Standalone.Editor.asmdef.meta +7 -0
  224. package/Standalone/Editor.meta +8 -0
  225. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/Info.plist +46 -0
  226. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/Info.plist.meta +7 -0
  227. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/MacOS/TapDBDeviceInfo +0 -0
  228. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/MacOS/TapDBDeviceInfo.meta +7 -0
  229. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/MacOS.meta +8 -0
  230. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/_CodeSignature/CodeResources +115 -0
  231. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/_CodeSignature/CodeResources.meta +7 -0
  232. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/_CodeSignature.meta +8 -0
  233. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents.meta +8 -0
  234. package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle.meta +33 -0
  235. package/Standalone/Plugins/macOS.meta +8 -0
  236. package/Standalone/Plugins.meta +8 -0
  237. package/Standalone/Runtime/Internal/Constants.cs +37 -0
  238. package/Standalone/Runtime/Internal/Constants.cs.meta +11 -0
  239. package/Standalone/Runtime/Internal/DeviceInfo.cs +152 -0
  240. package/Standalone/Runtime/Internal/DeviceInfo.cs.meta +11 -0
  241. package/Standalone/Runtime/Internal/EventSender.cs +239 -0
  242. package/Standalone/Runtime/Internal/EventSender.cs.meta +11 -0
  243. package/Standalone/Runtime/Internal/Http/HttpClient.cs +211 -0
  244. package/Standalone/Runtime/Internal/Http/HttpClient.cs.meta +11 -0
  245. package/Standalone/Runtime/Internal/Http/NetUtils.cs +48 -0
  246. package/Standalone/Runtime/Internal/Http/NetUtils.cs.meta +11 -0
  247. package/Standalone/Runtime/Internal/Http/TimeUtil.cs +30 -0
  248. package/Standalone/Runtime/Internal/Http/TimeUtil.cs.meta +11 -0
  249. package/Standalone/Runtime/Internal/Http.meta +8 -0
  250. package/Standalone/Runtime/Internal/Identity.cs +43 -0
  251. package/Standalone/Runtime/Internal/Identity.cs.meta +11 -0
  252. package/Standalone/Runtime/Internal/PlayRecorder.cs +53 -0
  253. package/Standalone/Runtime/Internal/PlayRecorder.cs.meta +11 -0
  254. package/Standalone/Runtime/Internal/Prefs.cs +85 -0
  255. package/Standalone/Runtime/Internal/Prefs.cs.meta +11 -0
  256. package/Standalone/Runtime/Internal/Tracker.cs +318 -0
  257. package/Standalone/Runtime/Internal/Tracker.cs.meta +11 -0
  258. package/Standalone/Runtime/Internal/User.cs +51 -0
  259. package/Standalone/Runtime/Internal/User.cs.meta +11 -0
  260. package/Standalone/Runtime/Internal.meta +8 -0
  261. package/Standalone/Runtime/Public/EventManager.cs +41 -0
  262. package/Standalone/Runtime/Public/EventManager.cs.meta +11 -0
  263. package/Standalone/Runtime/Public/TapCoreStandalone.cs +197 -0
  264. package/Standalone/Runtime/Public/TapCoreStandalone.cs.meta +11 -0
  265. package/Standalone/Runtime/Public/TapEventStandalone.cs +281 -0
  266. package/Standalone/Runtime/Public/TapEventStandalone.cs.meta +11 -0
  267. package/Standalone/Runtime/Public.meta +8 -0
  268. package/Standalone/Runtime/TapSDK.Core.Standalone.Runtime.asmdef +21 -0
  269. package/Standalone/Runtime/TapSDK.Core.Standalone.Runtime.asmdef.meta +7 -0
  270. package/Standalone/Runtime.meta +8 -0
  271. package/Standalone.meta +8 -0
  272. package/package.json +8 -0
  273. package/package.json.meta +7 -0
@@ -0,0 +1,954 @@
1
+ using System;
2
+ using System.Collections;
3
+ using System.Collections.Generic;
4
+ using System.IO;
5
+ using System.Text;
6
+ using System.Xml;
7
+
8
+ namespace TapSDK.Core.Editor
9
+ {
10
+ public static class Plist
11
+ {
12
+ private static List<int> offsetTable = new List<int>();
13
+ private static List<byte> objectTable = new List<byte>();
14
+ private static int refCount;
15
+ private static int objRefSize;
16
+ private static int offsetByteSize;
17
+ private static long offsetTableOffset;
18
+
19
+ #region Public Functions
20
+
21
+ public static object readPlist(string path)
22
+ {
23
+ using (FileStream f = new FileStream(path, FileMode.Open, FileAccess.Read))
24
+ {
25
+ return readPlist(f, plistType.Auto);
26
+ }
27
+ }
28
+
29
+ public static object readPlistSource(string source)
30
+ {
31
+ return readPlist(System.Text.Encoding.UTF8.GetBytes(source));
32
+ }
33
+
34
+ public static object readPlist(byte[] data)
35
+ {
36
+ return readPlist(new MemoryStream(data), plistType.Auto);
37
+ }
38
+
39
+ public static plistType getPlistType(Stream stream)
40
+ {
41
+ byte[] magicHeader = new byte[8];
42
+ stream.Read(magicHeader, 0, 8);
43
+
44
+ if (BitConverter.ToInt64(magicHeader, 0) == 3472403351741427810)
45
+ {
46
+ return plistType.Binary;
47
+ }
48
+ else
49
+ {
50
+ return plistType.Xml;
51
+ }
52
+ }
53
+
54
+ public static object readPlist(Stream stream, plistType type)
55
+ {
56
+ if (type == plistType.Auto)
57
+ {
58
+ type = getPlistType(stream);
59
+ stream.Seek(0, SeekOrigin.Begin);
60
+ }
61
+
62
+ if (type == plistType.Binary)
63
+ {
64
+ using (BinaryReader reader = new BinaryReader(stream))
65
+ {
66
+ byte[] data = reader.ReadBytes((int) reader.BaseStream.Length);
67
+ return readBinary(data);
68
+ }
69
+ }
70
+ else
71
+ {
72
+ XmlDocument xml = new XmlDocument();
73
+ xml.XmlResolver = null;
74
+ xml.Load(stream);
75
+ return readXml(xml);
76
+ }
77
+ }
78
+
79
+ public static void writeXml(object value, string path)
80
+ {
81
+ using (StreamWriter writer = new StreamWriter(path))
82
+ {
83
+ writer.Write(writeXml(value));
84
+ }
85
+ }
86
+
87
+ public static void writeXml(object value, Stream stream)
88
+ {
89
+ using (StreamWriter writer = new StreamWriter(stream))
90
+ {
91
+ writer.Write(writeXml(value));
92
+ }
93
+ }
94
+
95
+ public static string writeXml(object value)
96
+ {
97
+ using (MemoryStream ms = new MemoryStream())
98
+ {
99
+ XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
100
+ xmlWriterSettings.Encoding = new System.Text.UTF8Encoding(false);
101
+ xmlWriterSettings.ConformanceLevel = ConformanceLevel.Document;
102
+ xmlWriterSettings.Indent = true;
103
+
104
+ using (XmlWriter xmlWriter = XmlWriter.Create(ms, xmlWriterSettings))
105
+ {
106
+ xmlWriter.WriteStartDocument();
107
+ //xmlWriter.WriteComment("DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " + "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
108
+ xmlWriter.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN",
109
+ "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
110
+ xmlWriter.WriteStartElement("plist");
111
+ xmlWriter.WriteAttributeString("version", "1.0");
112
+ compose(value, xmlWriter);
113
+ xmlWriter.WriteEndElement();
114
+ xmlWriter.WriteEndDocument();
115
+ xmlWriter.Flush();
116
+ xmlWriter.Close();
117
+ return System.Text.Encoding.UTF8.GetString(ms.ToArray());
118
+ }
119
+ }
120
+ }
121
+
122
+ public static void writeBinary(object value, string path)
123
+ {
124
+ using (BinaryWriter writer = new BinaryWriter(new FileStream(path, FileMode.Create)))
125
+ {
126
+ writer.Write(writeBinary(value));
127
+ }
128
+ }
129
+
130
+ public static void writeBinary(object value, Stream stream)
131
+ {
132
+ using (BinaryWriter writer = new BinaryWriter(stream))
133
+ {
134
+ writer.Write(writeBinary(value));
135
+ }
136
+ }
137
+
138
+ public static byte[] writeBinary(object value)
139
+ {
140
+ offsetTable.Clear();
141
+ objectTable.Clear();
142
+ refCount = 0;
143
+ objRefSize = 0;
144
+ offsetByteSize = 0;
145
+ offsetTableOffset = 0;
146
+
147
+ //Do not count the root node, subtract by 1
148
+ int totalRefs = countObject(value) - 1;
149
+
150
+ refCount = totalRefs;
151
+
152
+ objRefSize = RegulateNullBytes(BitConverter.GetBytes(refCount)).Length;
153
+
154
+ composeBinary(value);
155
+
156
+ writeBinaryString("bplist00", false);
157
+
158
+ offsetTableOffset = (long) objectTable.Count;
159
+
160
+ offsetTable.Add(objectTable.Count - 8);
161
+
162
+ offsetByteSize = RegulateNullBytes(BitConverter.GetBytes(offsetTable[offsetTable.Count - 1])).Length;
163
+
164
+ List<byte> offsetBytes = new List<byte>();
165
+
166
+ offsetTable.Reverse();
167
+
168
+ for (int i = 0; i < offsetTable.Count; i++)
169
+ {
170
+ offsetTable[i] = objectTable.Count - offsetTable[i];
171
+ byte[] buffer = RegulateNullBytes(BitConverter.GetBytes(offsetTable[i]), offsetByteSize);
172
+ Array.Reverse(buffer);
173
+ offsetBytes.AddRange(buffer);
174
+ }
175
+
176
+ objectTable.AddRange(offsetBytes);
177
+
178
+ objectTable.AddRange(new byte[6]);
179
+ objectTable.Add(Convert.ToByte(offsetByteSize));
180
+ objectTable.Add(Convert.ToByte(objRefSize));
181
+
182
+ var a = BitConverter.GetBytes((long) totalRefs + 1);
183
+ Array.Reverse(a);
184
+ objectTable.AddRange(a);
185
+
186
+ objectTable.AddRange(BitConverter.GetBytes((long) 0));
187
+ a = BitConverter.GetBytes(offsetTableOffset);
188
+ Array.Reverse(a);
189
+ objectTable.AddRange(a);
190
+
191
+ return objectTable.ToArray();
192
+ }
193
+
194
+ #endregion
195
+
196
+ #region Private Functions
197
+
198
+ private static object readXml(XmlDocument xml)
199
+ {
200
+ XmlNode rootNode = xml.DocumentElement.ChildNodes[0];
201
+ return parse(rootNode);
202
+ }
203
+
204
+ private static object readBinary(byte[] data)
205
+ {
206
+ offsetTable.Clear();
207
+ List<byte> offsetTableBytes = new List<byte>();
208
+ objectTable.Clear();
209
+ refCount = 0;
210
+ objRefSize = 0;
211
+ offsetByteSize = 0;
212
+ offsetTableOffset = 0;
213
+
214
+ List<byte> bList = new List<byte>(data);
215
+
216
+ List<byte> trailer = bList.GetRange(bList.Count - 32, 32);
217
+
218
+ parseTrailer(trailer);
219
+
220
+ objectTable = bList.GetRange(0, (int) offsetTableOffset);
221
+
222
+ offsetTableBytes = bList.GetRange((int) offsetTableOffset, bList.Count - (int) offsetTableOffset - 32);
223
+
224
+ parseOffsetTable(offsetTableBytes);
225
+
226
+ return parseBinary(0);
227
+ }
228
+
229
+ private static Dictionary<string, object> parseDictionary(XmlNode node)
230
+ {
231
+ XmlNodeList children = node.ChildNodes;
232
+ if (children.Count % 2 != 0)
233
+ {
234
+ throw new DataMisalignedException("Dictionary elements must have an even number of child nodes");
235
+ }
236
+
237
+ Dictionary<string, object> dict = new Dictionary<string, object>();
238
+
239
+ for (int i = 0; i < children.Count; i += 2)
240
+ {
241
+ XmlNode keynode = children[i];
242
+ XmlNode valnode = children[i + 1];
243
+
244
+ if (keynode.Name != "key")
245
+ {
246
+ throw new ApplicationException("expected a key node");
247
+ }
248
+
249
+ object result = parse(valnode);
250
+
251
+ if (result != null)
252
+ {
253
+ dict.Add(keynode.InnerText, result);
254
+ }
255
+ }
256
+
257
+ return dict;
258
+ }
259
+
260
+ private static List<object> parseArray(XmlNode node)
261
+ {
262
+ List<object> array = new List<object>();
263
+
264
+ foreach (XmlNode child in node.ChildNodes)
265
+ {
266
+ object result = parse(child);
267
+ if (result != null)
268
+ {
269
+ array.Add(result);
270
+ }
271
+ }
272
+
273
+ return array;
274
+ }
275
+
276
+ private static void composeArray(List<object> value, XmlWriter writer)
277
+ {
278
+ writer.WriteStartElement("array");
279
+ foreach (object obj in value)
280
+ {
281
+ compose(obj, writer);
282
+ }
283
+
284
+ writer.WriteEndElement();
285
+ }
286
+
287
+ private static object parse(XmlNode node)
288
+ {
289
+ switch (node.Name)
290
+ {
291
+ case "dict":
292
+ return parseDictionary(node);
293
+ case "array":
294
+ return parseArray(node);
295
+ case "string":
296
+ return node.InnerText;
297
+ case "integer":
298
+ // int result;
299
+ //int.TryParse(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo, out result);
300
+ return Convert.ToInt32(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo);
301
+ case "real":
302
+ return Convert.ToDouble(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo);
303
+ case "false":
304
+ return false;
305
+ case "true":
306
+ return true;
307
+ case "null":
308
+ return null;
309
+ case "date":
310
+ return XmlConvert.ToDateTime(node.InnerText, XmlDateTimeSerializationMode.Utc);
311
+ case "data":
312
+ return Convert.FromBase64String(node.InnerText);
313
+ }
314
+
315
+ throw new ApplicationException(String.Format("Plist Node `{0}' is not supported", node.Name));
316
+ }
317
+
318
+ private static void compose(object value, XmlWriter writer)
319
+ {
320
+ if (value == null || value is string)
321
+ {
322
+ writer.WriteElementString("string", value as string);
323
+ }
324
+ else if (value is int || value is long)
325
+ {
326
+ writer.WriteElementString("integer",
327
+ ((int) value).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
328
+ }
329
+ else if (value is System.Collections.Generic.Dictionary<string, object> ||
330
+ value.GetType().ToString().StartsWith("System.Collections.Generic.Dictionary`2[System.String"))
331
+ {
332
+ //Convert to Dictionary<string, object>
333
+ Dictionary<string, object> dic = value as Dictionary<string, object>;
334
+ if (dic == null)
335
+ {
336
+ dic = new Dictionary<string, object>();
337
+ IDictionary idic = (IDictionary) value;
338
+ foreach (var key in idic.Keys)
339
+ {
340
+ dic.Add(key.ToString(), idic[key]);
341
+ }
342
+ }
343
+
344
+ writeDictionaryValues(dic, writer);
345
+ }
346
+ else if (value is List<object>)
347
+ {
348
+ composeArray((List<object>) value, writer);
349
+ }
350
+ else if (value is byte[])
351
+ {
352
+ writer.WriteElementString("data", Convert.ToBase64String((Byte[]) value));
353
+ }
354
+ else if (value is float || value is double)
355
+ {
356
+ writer.WriteElementString("real",
357
+ ((double) value).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
358
+ }
359
+ else if (value is DateTime)
360
+ {
361
+ DateTime time = (DateTime) value;
362
+ string theString = XmlConvert.ToString(time, XmlDateTimeSerializationMode.Utc);
363
+ writer.WriteElementString("date", theString); //, "yyyy-MM-ddTHH:mm:ssZ"));
364
+ }
365
+ else if (value is bool)
366
+ {
367
+ writer.WriteElementString(value.ToString().ToLower(), "");
368
+ }
369
+ else
370
+ {
371
+ throw new Exception(String.Format("Value type '{0}' is unhandled", value.GetType().ToString()));
372
+ }
373
+ }
374
+
375
+ private static void writeDictionaryValues(Dictionary<string, object> dictionary, XmlWriter writer)
376
+ {
377
+ writer.WriteStartElement("dict");
378
+ foreach (string key in dictionary.Keys)
379
+ {
380
+ object value = dictionary[key];
381
+ writer.WriteElementString("key", key);
382
+ compose(value, writer);
383
+ }
384
+
385
+ writer.WriteEndElement();
386
+ }
387
+
388
+ private static int countObject(object value)
389
+ {
390
+ int count = 0;
391
+ switch (value.GetType().ToString())
392
+ {
393
+ case "System.Collections.Generic.Dictionary`2[System.String,System.Object]":
394
+ Dictionary<string, object> dict = (Dictionary<string, object>) value;
395
+ foreach (string key in dict.Keys)
396
+ {
397
+ count += countObject(dict[key]);
398
+ }
399
+
400
+ count += dict.Keys.Count;
401
+ count++;
402
+ break;
403
+ case "System.Collections.Generic.List`1[System.Object]":
404
+ List<object> list = (List<object>) value;
405
+ foreach (object obj in list)
406
+ {
407
+ count += countObject(obj);
408
+ }
409
+
410
+ count++;
411
+ break;
412
+ default:
413
+ count++;
414
+ break;
415
+ }
416
+
417
+ return count;
418
+ }
419
+
420
+ private static byte[] writeBinaryDictionary(Dictionary<string, object> dictionary)
421
+ {
422
+ List<byte> buffer = new List<byte>();
423
+ List<byte> header = new List<byte>();
424
+ List<int> refs = new List<int>();
425
+ for (int i = dictionary.Count - 1; i >= 0; i--)
426
+ {
427
+ var o = new object[dictionary.Count];
428
+ dictionary.Values.CopyTo(o, 0);
429
+ composeBinary(o[i]);
430
+ offsetTable.Add(objectTable.Count);
431
+ refs.Add(refCount);
432
+ refCount--;
433
+ }
434
+
435
+ for (int i = dictionary.Count - 1; i >= 0; i--)
436
+ {
437
+ var o = new string[dictionary.Count];
438
+ dictionary.Keys.CopyTo(o, 0);
439
+ composeBinary(o[i]); //);
440
+ offsetTable.Add(objectTable.Count);
441
+ refs.Add(refCount);
442
+ refCount--;
443
+ }
444
+
445
+ if (dictionary.Count < 15)
446
+ {
447
+ header.Add(Convert.ToByte(0xD0 | Convert.ToByte(dictionary.Count)));
448
+ }
449
+ else
450
+ {
451
+ header.Add(0xD0 | 0xf);
452
+ header.AddRange(writeBinaryInteger(dictionary.Count, false));
453
+ }
454
+
455
+
456
+ foreach (int val in refs)
457
+ {
458
+ byte[] refBuffer = RegulateNullBytes(BitConverter.GetBytes(val), objRefSize);
459
+ Array.Reverse(refBuffer);
460
+ buffer.InsertRange(0, refBuffer);
461
+ }
462
+
463
+ buffer.InsertRange(0, header);
464
+
465
+
466
+ objectTable.InsertRange(0, buffer);
467
+
468
+ return buffer.ToArray();
469
+ }
470
+
471
+ private static byte[] composeBinaryArray(List<object> objects)
472
+ {
473
+ List<byte> buffer = new List<byte>();
474
+ List<byte> header = new List<byte>();
475
+ List<int> refs = new List<int>();
476
+
477
+ for (int i = objects.Count - 1; i >= 0; i--)
478
+ {
479
+ composeBinary(objects[i]);
480
+ offsetTable.Add(objectTable.Count);
481
+ refs.Add(refCount);
482
+ refCount--;
483
+ }
484
+
485
+ if (objects.Count < 15)
486
+ {
487
+ header.Add(Convert.ToByte(0xA0 | Convert.ToByte(objects.Count)));
488
+ }
489
+ else
490
+ {
491
+ header.Add(0xA0 | 0xf);
492
+ header.AddRange(writeBinaryInteger(objects.Count, false));
493
+ }
494
+
495
+ foreach (int val in refs)
496
+ {
497
+ byte[] refBuffer = RegulateNullBytes(BitConverter.GetBytes(val), objRefSize);
498
+ Array.Reverse(refBuffer);
499
+ buffer.InsertRange(0, refBuffer);
500
+ }
501
+
502
+ buffer.InsertRange(0, header);
503
+
504
+ objectTable.InsertRange(0, buffer);
505
+
506
+ return buffer.ToArray();
507
+ }
508
+
509
+ private static byte[] composeBinary(object obj)
510
+ {
511
+ byte[] value;
512
+ switch (obj.GetType().ToString())
513
+ {
514
+ case "System.Collections.Generic.Dictionary`2[System.String,System.Object]":
515
+ value = writeBinaryDictionary((Dictionary<string, object>) obj);
516
+ return value;
517
+
518
+ case "System.Collections.Generic.List`1[System.Object]":
519
+ value = composeBinaryArray((List<object>) obj);
520
+ return value;
521
+
522
+ case "System.Byte[]":
523
+ value = writeBinaryByteArray((byte[]) obj);
524
+ return value;
525
+
526
+ case "System.Double":
527
+ value = writeBinaryDouble((double) obj);
528
+ return value;
529
+
530
+ case "System.Int32":
531
+ value = writeBinaryInteger((int) obj, true);
532
+ return value;
533
+
534
+ case "System.String":
535
+ value = writeBinaryString((string) obj, true);
536
+ return value;
537
+
538
+ case "System.DateTime":
539
+ value = writeBinaryDate((DateTime) obj);
540
+ return value;
541
+
542
+ case "System.Boolean":
543
+ value = writeBinaryBool((bool) obj);
544
+ return value;
545
+
546
+ default:
547
+ return new byte[0];
548
+ }
549
+ }
550
+
551
+ public static byte[] writeBinaryDate(DateTime obj)
552
+ {
553
+ List<byte> buffer =
554
+ new List<byte>(RegulateNullBytes(BitConverter.GetBytes(PlistDateConverter.ConvertToAppleTimeStamp(obj)),
555
+ 8));
556
+ buffer.Reverse();
557
+ buffer.Insert(0, 0x33);
558
+ objectTable.InsertRange(0, buffer);
559
+ return buffer.ToArray();
560
+ }
561
+
562
+ public static byte[] writeBinaryBool(bool obj)
563
+ {
564
+ List<byte> buffer = new List<byte>(new byte[1] {(bool) obj ? (byte) 9 : (byte) 8});
565
+ objectTable.InsertRange(0, buffer);
566
+ return buffer.ToArray();
567
+ }
568
+
569
+ private static byte[] writeBinaryInteger(int value, bool write)
570
+ {
571
+ List<byte> buffer = new List<byte>(BitConverter.GetBytes((long) value));
572
+ buffer = new List<byte>(RegulateNullBytes(buffer.ToArray()));
573
+ while (buffer.Count != Math.Pow(2, Math.Log(buffer.Count) / Math.Log(2)))
574
+ buffer.Add(0);
575
+ int header = 0x10 | (int) (Math.Log(buffer.Count) / Math.Log(2));
576
+
577
+ buffer.Reverse();
578
+
579
+ buffer.Insert(0, Convert.ToByte(header));
580
+
581
+ if (write)
582
+ objectTable.InsertRange(0, buffer);
583
+
584
+ return buffer.ToArray();
585
+ }
586
+
587
+ private static byte[] writeBinaryDouble(double value)
588
+ {
589
+ List<byte> buffer = new List<byte>(RegulateNullBytes(BitConverter.GetBytes(value), 4));
590
+ while (buffer.Count != Math.Pow(2, Math.Log(buffer.Count) / Math.Log(2)))
591
+ buffer.Add(0);
592
+ int header = 0x20 | (int) (Math.Log(buffer.Count) / Math.Log(2));
593
+
594
+ buffer.Reverse();
595
+
596
+ buffer.Insert(0, Convert.ToByte(header));
597
+
598
+ objectTable.InsertRange(0, buffer);
599
+
600
+ return buffer.ToArray();
601
+ }
602
+
603
+ private static byte[] writeBinaryByteArray(byte[] value)
604
+ {
605
+ List<byte> buffer = new List<byte>(value);
606
+ List<byte> header = new List<byte>();
607
+ if (value.Length < 15)
608
+ {
609
+ header.Add(Convert.ToByte(0x40 | Convert.ToByte(value.Length)));
610
+ }
611
+ else
612
+ {
613
+ header.Add(0x40 | 0xf);
614
+ header.AddRange(writeBinaryInteger(buffer.Count, false));
615
+ }
616
+
617
+ buffer.InsertRange(0, header);
618
+
619
+ objectTable.InsertRange(0, buffer);
620
+
621
+ return buffer.ToArray();
622
+ }
623
+
624
+ private static byte[] writeBinaryString(string value, bool head)
625
+ {
626
+ List<byte> buffer = new List<byte>();
627
+ List<byte> header = new List<byte>();
628
+ foreach (char chr in value.ToCharArray())
629
+ buffer.Add(Convert.ToByte(chr));
630
+
631
+ if (head)
632
+ {
633
+ if (value.Length < 15)
634
+ {
635
+ header.Add(Convert.ToByte(0x50 | Convert.ToByte(value.Length)));
636
+ }
637
+ else
638
+ {
639
+ header.Add(0x50 | 0xf);
640
+ header.AddRange(writeBinaryInteger(buffer.Count, false));
641
+ }
642
+ }
643
+
644
+ buffer.InsertRange(0, header);
645
+
646
+ objectTable.InsertRange(0, buffer);
647
+
648
+ return buffer.ToArray();
649
+ }
650
+
651
+ private static byte[] RegulateNullBytes(byte[] value)
652
+ {
653
+ return RegulateNullBytes(value, 1);
654
+ }
655
+
656
+ private static byte[] RegulateNullBytes(byte[] value, int minBytes)
657
+ {
658
+ Array.Reverse(value);
659
+ List<byte> bytes = new List<byte>(value);
660
+ for (int i = 0; i < bytes.Count; i++)
661
+ {
662
+ if (bytes[i] == 0 && bytes.Count > minBytes)
663
+ {
664
+ bytes.Remove(bytes[i]);
665
+ i--;
666
+ }
667
+ else
668
+ break;
669
+ }
670
+
671
+ if (bytes.Count < minBytes)
672
+ {
673
+ int dist = minBytes - bytes.Count;
674
+ for (int i = 0; i < dist; i++)
675
+ bytes.Insert(0, 0);
676
+ }
677
+
678
+ value = bytes.ToArray();
679
+ Array.Reverse(value);
680
+ return value;
681
+ }
682
+
683
+ private static void parseTrailer(List<byte> trailer)
684
+ {
685
+ offsetByteSize = BitConverter.ToInt32(RegulateNullBytes(trailer.GetRange(6, 1).ToArray(), 4), 0);
686
+ objRefSize = BitConverter.ToInt32(RegulateNullBytes(trailer.GetRange(7, 1).ToArray(), 4), 0);
687
+ byte[] refCountBytes = trailer.GetRange(12, 4).ToArray();
688
+ Array.Reverse(refCountBytes);
689
+ refCount = BitConverter.ToInt32(refCountBytes, 0);
690
+ byte[] offsetTableOffsetBytes = trailer.GetRange(24, 8).ToArray();
691
+ Array.Reverse(offsetTableOffsetBytes);
692
+ offsetTableOffset = BitConverter.ToInt64(offsetTableOffsetBytes, 0);
693
+ }
694
+
695
+ private static void parseOffsetTable(List<byte> offsetTableBytes)
696
+ {
697
+ for (int i = 0; i < offsetTableBytes.Count; i += offsetByteSize)
698
+ {
699
+ byte[] buffer = offsetTableBytes.GetRange(i, offsetByteSize).ToArray();
700
+ Array.Reverse(buffer);
701
+ offsetTable.Add(BitConverter.ToInt32(RegulateNullBytes(buffer, 4), 0));
702
+ }
703
+ }
704
+
705
+ private static object parseBinaryDictionary(int objRef)
706
+ {
707
+ Dictionary<string, object> buffer = new Dictionary<string, object>();
708
+ List<int> refs = new List<int>();
709
+ int refCount = 0;
710
+
711
+ int refStartPosition;
712
+ refCount = getCount(offsetTable[objRef], out refStartPosition);
713
+
714
+
715
+ if (refCount < 15)
716
+ refStartPosition = offsetTable[objRef] + 1;
717
+ else
718
+ refStartPosition = offsetTable[objRef] + 2 +
719
+ RegulateNullBytes(BitConverter.GetBytes(refCount), 1).Length;
720
+
721
+ for (int i = refStartPosition; i < refStartPosition + refCount * 2 * objRefSize; i += objRefSize)
722
+ {
723
+ byte[] refBuffer = objectTable.GetRange(i, objRefSize).ToArray();
724
+ Array.Reverse(refBuffer);
725
+ refs.Add(BitConverter.ToInt32(RegulateNullBytes(refBuffer, 4), 0));
726
+ }
727
+
728
+ for (int i = 0; i < refCount; i++)
729
+ {
730
+ buffer.Add((string) parseBinary(refs[i]), parseBinary(refs[i + refCount]));
731
+ }
732
+
733
+ return buffer;
734
+ }
735
+
736
+ private static object parseBinaryArray(int objRef)
737
+ {
738
+ List<object> buffer = new List<object>();
739
+ List<int> refs = new List<int>();
740
+ int refCount = 0;
741
+
742
+ int refStartPosition;
743
+ refCount = getCount(offsetTable[objRef], out refStartPosition);
744
+
745
+
746
+ if (refCount < 15)
747
+ refStartPosition = offsetTable[objRef] + 1;
748
+ else
749
+ //The following integer has a header aswell so we increase the refStartPosition by two to account for that.
750
+ refStartPosition = offsetTable[objRef] + 2 +
751
+ RegulateNullBytes(BitConverter.GetBytes(refCount), 1).Length;
752
+
753
+ for (int i = refStartPosition; i < refStartPosition + refCount * objRefSize; i += objRefSize)
754
+ {
755
+ byte[] refBuffer = objectTable.GetRange(i, objRefSize).ToArray();
756
+ Array.Reverse(refBuffer);
757
+ refs.Add(BitConverter.ToInt32(RegulateNullBytes(refBuffer, 4), 0));
758
+ }
759
+
760
+ for (int i = 0; i < refCount; i++)
761
+ {
762
+ buffer.Add(parseBinary(refs[i]));
763
+ }
764
+
765
+ return buffer;
766
+ }
767
+
768
+ private static int getCount(int bytePosition, out int newBytePosition)
769
+ {
770
+ byte headerByte = objectTable[bytePosition];
771
+ byte headerByteTrail = Convert.ToByte(headerByte & 0xf);
772
+ int count;
773
+ if (headerByteTrail < 15)
774
+ {
775
+ count = headerByteTrail;
776
+ newBytePosition = bytePosition + 1;
777
+ }
778
+ else
779
+ count = (int) parseBinaryInt(bytePosition + 1, out newBytePosition);
780
+
781
+ return count;
782
+ }
783
+
784
+ private static object parseBinary(int objRef)
785
+ {
786
+ byte header = objectTable[offsetTable[objRef]];
787
+ switch (header & 0xF0)
788
+ {
789
+ case 0:
790
+ {
791
+ //If the byte is
792
+ //0 return null
793
+ //9 return true
794
+ //8 return false
795
+ return (objectTable[offsetTable[objRef]] == 0)
796
+ ? (object) null
797
+ : ((objectTable[offsetTable[objRef]] == 9) ? true : false);
798
+ }
799
+ case 0x10:
800
+ {
801
+ return parseBinaryInt(offsetTable[objRef]);
802
+ }
803
+ case 0x20:
804
+ {
805
+ return parseBinaryReal(offsetTable[objRef]);
806
+ }
807
+ case 0x30:
808
+ {
809
+ return parseBinaryDate(offsetTable[objRef]);
810
+ }
811
+ case 0x40:
812
+ {
813
+ return parseBinaryByteArray(offsetTable[objRef]);
814
+ }
815
+ case 0x50: //String ASCII
816
+ {
817
+ return parseBinaryAsciiString(offsetTable[objRef]);
818
+ }
819
+ case 0x60: //String Unicode
820
+ {
821
+ return parseBinaryUnicodeString(offsetTable[objRef]);
822
+ }
823
+ case 0xD0:
824
+ {
825
+ return parseBinaryDictionary(objRef);
826
+ }
827
+ case 0xA0:
828
+ {
829
+ return parseBinaryArray(objRef);
830
+ }
831
+ }
832
+
833
+ throw new Exception("This type is not supported");
834
+ }
835
+
836
+ public static object parseBinaryDate(int headerPosition)
837
+ {
838
+ byte[] buffer = objectTable.GetRange(headerPosition + 1, 8).ToArray();
839
+ Array.Reverse(buffer);
840
+ double appleTime = BitConverter.ToDouble(buffer, 0);
841
+ DateTime result = PlistDateConverter.ConvertFromAppleTimeStamp(appleTime);
842
+ return result;
843
+ }
844
+
845
+ private static object parseBinaryInt(int headerPosition)
846
+ {
847
+ int output;
848
+ return parseBinaryInt(headerPosition, out output);
849
+ }
850
+
851
+ private static object parseBinaryInt(int headerPosition, out int newHeaderPosition)
852
+ {
853
+ byte header = objectTable[headerPosition];
854
+ int byteCount = (int) Math.Pow(2, header & 0xf);
855
+ byte[] buffer = objectTable.GetRange(headerPosition + 1, byteCount).ToArray();
856
+ Array.Reverse(buffer);
857
+ //Add one to account for the header byte
858
+ newHeaderPosition = headerPosition + byteCount + 1;
859
+ return BitConverter.ToInt32(RegulateNullBytes(buffer, 4), 0);
860
+ }
861
+
862
+ private static object parseBinaryReal(int headerPosition)
863
+ {
864
+ byte header = objectTable[headerPosition];
865
+ int byteCount = (int) Math.Pow(2, header & 0xf);
866
+ byte[] buffer = objectTable.GetRange(headerPosition + 1, byteCount).ToArray();
867
+ Array.Reverse(buffer);
868
+
869
+ return BitConverter.ToDouble(RegulateNullBytes(buffer, 8), 0);
870
+ }
871
+
872
+ private static object parseBinaryAsciiString(int headerPosition)
873
+ {
874
+ int charStartPosition;
875
+ int charCount = getCount(headerPosition, out charStartPosition);
876
+
877
+ var buffer = objectTable.GetRange(charStartPosition, charCount);
878
+ return buffer.Count > 0 ? Encoding.ASCII.GetString(buffer.ToArray()) : string.Empty;
879
+ }
880
+
881
+ private static object parseBinaryUnicodeString(int headerPosition)
882
+ {
883
+ int charStartPosition;
884
+ int charCount = getCount(headerPosition, out charStartPosition);
885
+ charCount = charCount * 2;
886
+
887
+ byte[] buffer = new byte[charCount];
888
+ byte one, two;
889
+
890
+ for (int i = 0; i < charCount; i += 2)
891
+ {
892
+ one = objectTable.GetRange(charStartPosition + i, 1)[0];
893
+ two = objectTable.GetRange(charStartPosition + i + 1, 1)[0];
894
+
895
+ if (BitConverter.IsLittleEndian)
896
+ {
897
+ buffer[i] = two;
898
+ buffer[i + 1] = one;
899
+ }
900
+ else
901
+ {
902
+ buffer[i] = one;
903
+ buffer[i + 1] = two;
904
+ }
905
+ }
906
+
907
+ return Encoding.Unicode.GetString(buffer);
908
+ }
909
+
910
+ private static object parseBinaryByteArray(int headerPosition)
911
+ {
912
+ int byteStartPosition;
913
+ int byteCount = getCount(headerPosition, out byteStartPosition);
914
+ return objectTable.GetRange(byteStartPosition, byteCount).ToArray();
915
+ }
916
+
917
+ #endregion
918
+ }
919
+
920
+ public enum plistType
921
+ {
922
+ Auto,
923
+ Binary,
924
+ Xml
925
+ }
926
+
927
+ public static class PlistDateConverter
928
+ {
929
+ public static long timeDifference = 978307200;
930
+
931
+ public static long GetAppleTime(long unixTime)
932
+ {
933
+ return unixTime - timeDifference;
934
+ }
935
+
936
+ public static long GetUnixTime(long appleTime)
937
+ {
938
+ return appleTime + timeDifference;
939
+ }
940
+
941
+ public static DateTime ConvertFromAppleTimeStamp(double timestamp)
942
+ {
943
+ DateTime origin = new DateTime(2001, 1, 1, 0, 0, 0, 0);
944
+ return origin.AddSeconds(timestamp);
945
+ }
946
+
947
+ public static double ConvertToAppleTimeStamp(DateTime date)
948
+ {
949
+ DateTime begin = new DateTime(2001, 1, 1, 0, 0, 0, 0);
950
+ TimeSpan diff = date - begin;
951
+ return Math.Floor(diff.TotalSeconds);
952
+ }
953
+ }
954
+ }