From b3757b692db06cdf5d91022bfcb607c4a3a5b442 Mon Sep 17 00:00:00 2001 From: C_Peter <48532778+prosch88@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:46:28 +0100 Subject: [PATCH] service_connection: fix `parse_plist()` for supprting even older legacy devices Tested with iPad 1 (iPad 1,1) --- pymobiledevice3/service_connection.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pymobiledevice3/service_connection.py b/pymobiledevice3/service_connection.py index 548a74d0..8aa02e3b 100755 --- a/pymobiledevice3/service_connection.py +++ b/pymobiledevice3/service_connection.py @@ -5,6 +5,7 @@ import ssl import struct import time +import xml from enum import Enum from typing import Any, Optional @@ -59,9 +60,16 @@ def parse_plist(payload: bytes) -> dict: :param payload: The plist-formatted byte string to parse. :return: The parsed dictionary. :raises PyMobileDevice3Exception: If the payload is invalid. + :retries with a filtered payload if plistlib compains about "not well-formed (invalid token)" """ try: return plistlib.loads(payload) + except xml.parsers.expat.ExpatError: + payload = bytes([b for b in payload if b not in (0x00, 0x10)]) + try: + return plistlib.loads(payload) + except plistlib.InvalidFileException: + raise PyMobileDevice3Exception(f'parse_plist invalid data: {payload[:100].hex()}') except plistlib.InvalidFileException: raise PyMobileDevice3Exception(f'parse_plist invalid data: {payload[:100].hex()}')