Skip to content

Commit

Permalink
Merge pull request #145 from doronz88/restore/support_iphone12_ios14
Browse files Browse the repository at this point in the history
restore: bugfix: support iphone12 ios14.x
  • Loading branch information
doronz88 committed Sep 14, 2021
2 parents f2519af + a386c01 commit 1491a50
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
14 changes: 11 additions & 3 deletions pymobiledevice3/restore/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_build_identity_from_request(self, msg):

def send_buildidentity(self, message: Mapping):
logging.info('About to send BuildIdentity Dict...')
req = {'BuildIdentityDict': Mapping(self.get_build_identity_from_request(message))}
req = {'BuildIdentityDict': dict(self.get_build_identity_from_request(message))}
arguments = message['Arguments']
variant = arguments.get('Variant')

Expand Down Expand Up @@ -516,6 +516,14 @@ def send_image_data(self, message, image_list_k, image_type_k, image_data_k):
arguments = message['Arguments']
want_image_list = arguments.get(image_list_k)
image_name = arguments.get('ImageName')
build_id_manifest = self.build_identity['Manifest']

if not want_image_list and image_name is not None:
if image_name not in build_id_manifest:
if image_name.startswith('Ap'):
image_name = image_name.replace('Ap', 'Ap,')
if image_name not in build_id_manifest:
raise PyMobileDevice3Exception(f'{image_name} not in build_id_manifest')

if image_type_k is None:
image_type_k = arguments['ImageType']
Expand All @@ -529,8 +537,6 @@ def send_image_data(self, message, image_list_k, image_type_k, image_data_k):
matched_images = []
data_dict = dict()

build_id_manifest = self.build_identity['Manifest']

for component, manifest_entry in build_id_manifest.items():
if not isinstance(manifest_entry, dict):
continue
Expand All @@ -543,6 +549,8 @@ def send_image_data(self, message, image_list_k, image_type_k, image_data_k):
elif image_name is None or image_name == component:
if image_name is None:
logging.info(f'found {image_type_k} component \'{component}\'')
else:
logging.info(f'found component \'{component}\'')

data_dict[component] = self.build_identity.get_component(component,
tss=self.recovery.tss).personalized_data
Expand Down
33 changes: 23 additions & 10 deletions pymobiledevice3/restore/tss.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"""


def get_with_or_without_comma(obj: typing.Mapping, k: str):
return obj.get(k, obj.get(k.replace(',', '')))


class TSSResponse(dict):
@property
def ap_img4_ticket(self):
Expand Down Expand Up @@ -275,7 +279,7 @@ def add_savage_tags(self, parameters: typing.Mapping, overrides=None, component_
self._request['@Savage,Ticket'] = True

# add Savage,UID
self._request['Savage,UID'] = parameters['Savage,UID']
self._request['Savage,UID'] = get_with_or_without_comma(parameters, 'Savage,UID')

# add SEP
self._request['SEP'] = {'Digest': manifest['SEP']['Digest']}
Expand All @@ -285,14 +289,16 @@ def add_savage_tags(self, parameters: typing.Mapping, overrides=None, component_
'Savage,ProductionMode', 'Savage,Nonce', 'Savage,Nonce')

for k in keys_to_copy:
if k in parameters:
self._request[k] = parameters[k]
value = get_with_or_without_comma(parameters, k)
if value is None:
continue
self._request[k] = value

isprod = parameters['Savage,ProductionMode']
isprod = get_with_or_without_comma(parameters, 'Savage,ProductionMode')

# get the right component name
comp_name = 'Savage,B0-Prod-Patch' if isprod else 'Savage,B0-Dev-Patch'
node = parameters.get('Savage,Revision')
node = get_with_or_without_comma(parameters, 'Savage,Revision')

if isinstance(node, bytes):
savage_rev = node
Expand Down Expand Up @@ -405,15 +411,22 @@ def add_rose_tags(self, parameters: typing.Mapping, overrides: typing.Mapping =

keys_to_copy_uint = ('Rap,BoardID', 'Rap,ChipID', 'Rap,ECID', 'Rap,SecurityDomain',)

for k in keys_to_copy_uint:
self._request[k] = bytes_to_uint(parameters[k])
for key in keys_to_copy_uint:
value = get_with_or_without_comma(parameters, key)

if isinstance(value, bytes):
self._request[key] = bytes_to_uint(value)
else:
self._request[key] = value

keys_to_copy_bool = ('Rap,ProductionMode', 'Rap,SecurityMode',)

for k in keys_to_copy_bool:
self._request[k] = bytes_to_uint(parameters[k]) == 1
for key in keys_to_copy_bool:
value = get_with_or_without_comma(parameters, key)
self._request[key] = bytes_to_uint(value) == 1

nonce = get_with_or_without_comma(parameters, 'Rap,Nonce')

nonce = parameters.get('Rap,Nonce')
if nonce is not None:
self._request['Rap,Nonce'] = nonce

Expand Down

0 comments on commit 1491a50

Please sign in to comment.