patsplat / plist

All-purpose Property List manipulation library

Home Page:http://www.rubydoc.info/gems/plist

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Binary Plists

patsplat opened this issue · comments

I have a problem with Plist::parse_xml when parse binary plist
(plist: https://www.dropbox.com/s/so8h9nk0x3pemwq/Info.plist?dl=0)

/Library/Ruby/Gems/2.0.0/gems/plist-3.1.0/lib/plist/parser.rb:91:in `scan': invalid byte sequence in UTF-8 (ArgumentError)

#21 (comment)

Same problem here trying to parse ~/Library/Safari/Bookmarks.plist with plist-3.2.0 using
ruby 2.0.0p598 on Mac OS X 10.11.5

The Safari bookmarks file can be converted to XML (which plist gem can process) with:

plutil -convert xml1 -o Bookmarks.xml ~/Library/Safari/Bookmarks.plist

This issue is a placeholder for integrating backends from other ruby plist libraries

https://github.com/ckruse/CFPropertyList

@vesan thanks for the pointer to the OSX plutil utility

Was trying to pass the plist file content instead of filename to solve the issue but had the File.exist? ArgumentError because of some null bytes, so the

File.exist? plist_data_or_file.encode("UTF-8", invalid: :replace, undef: :replace).delete(?\x0)

fixed that for me and I was going to make a pull request but found this issue and now I guess that won't help anyway...

@Nakilon are you working with a binary plist, or are you having a different issue?

@patsplat yes, the file I need to parse appears to be binary.

To solve this I've used https://github.com/ckruse/CFPropertyList but that probably results in more code because of these .value, I'm not sure:

    displays = CFPropertyList::List.new(file: "/Library/Preferences/com.apple.windowserver.plist").
      value.value["DisplayAnyUserSets"].value.flat_map(&:value).map{ |i| i.value.values_at("OriginX", "OriginY", "Width", "Height").map(&:value) }