使用Python读取Binary Plist文件

Zek*_*edi 3 python binary plist

我目前正在使用Plistlib模块读取Plist文件,但是在涉及Binary Plist文件时,我目前遇到了问题。

我想将数据读取为字符串以供稍后分析/打印等。我想知道它们是否仍是在不使用plutil函数的情况下读取Binary Plist文件并将二进制文件转换为XML?

感谢您的帮助和提前的时间。

ori*_*rip 5

尽管您指定了no plutil,但由于它已预先安装在Macs上,因此可行的解决方案可能对其他人有用:

import json
from subprocess import Popen, PIPE

def plist_to_dictionary(filename):
    "Pipe the binary plist through plutil and parse the JSON output"
    with open(filename, "rb") as f:
        content = f.read()
    args = ["plutil", "-convert", "json", "-o", "-", "--", "-"]
    p = Popen(args, stdin=PIPE, stdout=PIPE)
    out, err = p.communicate(content)
    return json.loads(out)

print plist_to_dictionary(path_to_plist_file)
Run Code Online (Sandbox Code Playgroud)