Code Monkey home page Code Monkey logo

Comments (8)

wooster avatar wooster commented on August 19, 2024

@paulr4 Any chance you could attach the plist as a file here?

from biplist.

paulr4 avatar paulr4 commented on August 19, 2024

Sure, here:

plistfile.zip

from biplist.

wooster avatar wooster commented on August 19, 2024

Oh. That file looks like it was printed in a Python interactive session. Those sequences like "\xae" are replacing the actual binary contents.

Do you have the original file generated by the program?

from biplist.

paulr4 avatar paulr4 commented on August 19, 2024

No, sorry, it was embedded in an SQLite file and I read it directly into Python variable from there. I wrote it to a file using plistfile.write(str(plist)), I guess that was my mistake. What should I have done?

from biplist.

paulr4 avatar paulr4 commented on August 19, 2024

I think I've got it - open the output file in binary mode ('wb') and write using bytes():

plistfile = open('tempfile','wb')
plistfile.write(bytes(plist))

from biplist.

paulr4 avatar paulr4 commented on August 19, 2024

Unfortunately I still can't get anything useful out of the file.

plistfile.zip

I've tried every combination of BinaryPlist, readPlist, and Parse I can think of, trying to adapt the examples given here, but no luck so far sadly.

from biplist.

wooster avatar wooster commented on August 19, 2024

Google's binplist project isn't the same as my biplist project.

If you're reading from a file on the filesystem, you can do something like:

>>> import biplist 
>>> biplist.readPlist("/Users/andrew/Downloads/plistfile_new.plist")
{'$objects': ['$null', {'NS.keys': [Uid(2), Uid(4), Uid(6), Uid(8)], 'NS.objects': [Uid(10), Uid(12), Uid(14), Uid(16)], '$class': Uid(18)}, {'$class': Uid(3), 'NS.string': 'fullname'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(5), 'NS.string': 'address'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(7), 'NS.string': 'phone'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(9), 'NS.string': 'email'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(11), 'NS.string': 'Test Client'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(13), 'NS.string': '123 ABC Street'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(15), 'NS.string': '1234'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(17), 'NS.string': '[email protected]'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$classes': ['NSDictionary', 'NSObject'], '$classname': 'NSDictionary'}], '$archiver': 'NSKeyedArchiver', '$version': 100000, '$top': {'root': Uid(1)}}

If you're reading from SQLite into a variable, you can use StringIO to turn that variable into a file-like object and read from there:

>>> import StringIO
>>> contents = open("plistfile.plist").read()
>>> file_like_object = StringIO.StringIO(contents)
>>> biplist.readPlist(file_like_object)
{'$objects': ['$null', {'NS.keys': [Uid(2), Uid(4), Uid(6), Uid(8)], 'NS.objects': [Uid(10), Uid(12), Uid(14), Uid(16)], '$class': Uid(18)}, {'$class': Uid(3), 'NS.string': 'fullname'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(5), 'NS.string': 'address'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(7), 'NS.string': 'phone'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(9), 'NS.string': 'email'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(11), 'NS.string': 'Test Client'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(13), 'NS.string': '123 ABC Street'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(15), 'NS.string': '1234'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(17), 'NS.string': '[email protected]'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$classes': ['NSDictionary', 'NSObject'], '$classname': 'NSDictionary'}], '$archiver': 'NSKeyedArchiver', '$version': 100000, '$top': {'root': Uid(1)}}

This particular plist is a keyed archive, used by the program to encode an object in memory. The format can be fairly opaque to decode.

If you're on OS X, you can use the Foundation bindings to more easily process the file, eg:

>>> import Foundation
>>> data = Foundation.NSData.dataWithContentsOfFile_("plistfile.plist")
>>> Foundation.NSKeyedUnarchiver.unarchiveObjectWithData_(data)
{
    address = "123 ABC Street";
    email = "[email protected]";
    fullname = "Test Client";
    phone = 1234;
}

from biplist.

paulr4 avatar paulr4 commented on August 19, 2024

Thank you for your help! I finally implemented this with the following code, where ClientDetails contains the impenetrable raw plist data:

import io
import biplist
tmp = io.BytesIO()
tmp.write(ClientDetails)
plist = biplist.readPlist(tmp)
tmp.close()

'plist' then contained a complicated nested arrangement of variables, which could at least be rooted through using usual python methods.

from biplist.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.