Skip to content

Commit

Permalink
service_connection: fix parse_plist() for supprting even older lega…
Browse files Browse the repository at this point in the history
…cy devices

Tested with iPad 1 (iPad 1,1)
  • Loading branch information
prosch88 authored Nov 13, 2024
1 parent 28098d6 commit b3757b6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pymobiledevice3/service_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ssl
import struct
import time
import xml
from enum import Enum
from typing import Any, Optional

Expand Down Expand Up @@ -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()}')

Expand Down

0 comments on commit b3757b6

Please sign in to comment.