Skip to content

Commit

Permalink
Support preservation of file timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
KnugiHK committed Oct 8, 2023
1 parent c47df99 commit 1bf55e7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/iphone_backup_decrypt/iphone_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def extract_files(self, *, relative_paths_like=None, domain=None, output_folder)
elif domain is not None:
return self.extract_files_by_domain(domain, output_folder)

def extract_files_by_relative_path(self, relative_paths_like, output_folder):
def extract_files_by_relative_path(self, relative_paths_like, output_folder, bplist_reader=None):
"""
Decrypt files matching a relative path query and output them to a folder.
Expand Down Expand Up @@ -331,8 +331,10 @@ def extract_files_by_relative_path(self, relative_paths_like, output_folder):
if decrypted_data is not None:
with open(output_path, 'wb') as outfile:
outfile.write(decrypted_data)
if bplist_reader:
self.modify_timestamp(output_path, bplist_reader, file_bplist)

def extract_files_by_domain(self, domain, output_folder):
def extract_files_by_domain(self, domain, output_folder, bplist_reader=None):
"""
Decrypt files matching a domain query and output them to a folder.
Expand Down Expand Up @@ -381,6 +383,8 @@ def extract_files_by_domain(self, domain, output_folder):
destination = os.path.join(output_folder, relative_path)
with open(destination, 'wb') as outfile:
outfile.write(decrypted_data)
if bplist_reader:
self.modify_timestamp(destination, bplist_reader, file_bplist)

def execute_sql(self, sql):
if self._temp_manifest_db_conn is None:
Expand All @@ -398,3 +402,9 @@ def execute_sql(self, sql):

def get_connection(self):
return self._temp_manifest_db_conn

def modify_timestamp(self, destination, bplist_reader, file_bplist):
metadata = bplist_reader(file_bplist).parse()
creation = metadata["$objects"][1]["Birth"]
modification = metadata["$objects"][1]["LastModified"]
os.utime(destination, (modification, modification))

0 comments on commit 1bf55e7

Please sign in to comment.