Created
May 11, 2016 08:42
-
-
Save kosmakoff/1da2424447566c8c64de9d8fa1c6d32a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
namespace PlistDemo | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?> | |
<!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd""> | |
<plist version=""1.0""> | |
<dict> | |
<key>Last Backup Date</key> | |
<date>2016-04-06T10:16:17Z</date> | |
</dict> | |
</plist> | |
"; | |
IntPtr dictPtr; | |
Plist.plist_from_xml(xml, (uint) xml.Length, out dictPtr); | |
var backupDatePtr = Plist.plist_dict_get_item(dictPtr, "Last Backup Date"); | |
int sec, usec; | |
Plist.plist_get_date_val(backupDatePtr, out sec, out usec); | |
var date = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(sec); | |
Console.WriteLine($"Parsing XML:\n{xml}\n\n======================="); | |
Console.WriteLine($"{date} ({date.Kind}) from secs: {sec}"); | |
} | |
} | |
internal static class Plist | |
{ | |
private const string DllName = @"C:\Programs\imobiledevice\libplist.dll"; | |
[DllImport(DllName, EntryPoint = "plist_from_xml", CallingConvention = CallingConvention.Cdecl)] | |
public static extern void plist_from_xml([MarshalAs(UnmanagedType.LPStr)]string xml, uint length, out IntPtr nodePtr); | |
[DllImport(DllName, EntryPoint = "plist_dict_get_item", CallingConvention = CallingConvention.Cdecl)] | |
public static extern IntPtr plist_dict_get_item(IntPtr node, [In, MarshalAs(UnmanagedType.LPStr)] string key); | |
[DllImport(DllName, EntryPoint = "plist_get_date_val", CallingConvention = CallingConvention.Cdecl)] | |
public static extern void plist_get_date_val(IntPtr node, out int sec, out int usec); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output of the program is: