Make necessary changes for adopting the latest iphone_backup_decrypt

This commit is contained in:
KnugiHK
2024-06-22 20:02:29 +08:00
parent f080e2d4ea
commit 7e2800d89a
2 changed files with 21 additions and 37 deletions

View File

@@ -188,13 +188,6 @@ def main():
action='store_true', action='store_true',
help="Use Whatsapp Business default files (iOS only)" help="Use Whatsapp Business default files (iOS only)"
) )
parser.add_argument(
"--preserve-timestamp",
dest="preserve_timestamp",
default=False,
action='store_true',
help="Preserve the modification timestamp of the extracted files (iOS only)"
)
parser.add_argument( parser.add_argument(
"--wab", "--wab",
"--wa-backup", "--wa-backup",
@@ -403,7 +396,7 @@ def main():
args.media = identifiers.DOMAIN args.media = identifiers.DOMAIN
if args.backup is not None: if args.backup is not None:
if not os.path.isdir(args.media): if not os.path.isdir(args.media):
ios_media_handler.extract_media(args.backup, identifiers, args.preserve_timestamp) ios_media_handler.extract_media(args.backup, identifiers)
else: else:
print("WhatsApp directory already exists, skipping WhatsApp file extraction.") print("WhatsApp directory already exists, skipping WhatsApp file extraction.")
if args.db is None: if args.db is None:

View File

@@ -3,55 +3,49 @@
import shutil import shutil
import sqlite3 import sqlite3
import os import os
import time
import getpass import getpass
import threading
from Whatsapp_Chat_Exporter.utility import WhatsAppIdentifier from Whatsapp_Chat_Exporter.utility import WhatsAppIdentifier
try: try:
from iphone_backup_decrypt import EncryptedBackup, RelativePath from iphone_backup_decrypt import EncryptedBackup, RelativePath
from iphone_backup_decrypt import FailedToDecryptError
except ModuleNotFoundError: except ModuleNotFoundError:
support_encrypted = False support_encrypted = False
else: else:
support_encrypted = True support_encrypted = True
def extract_encrypted(base_dir, password, identifiers, bplist_reader=None): def extract_encrypted(base_dir, password, identifiers):
print("Trying to decrypt the iOS backup...", end="")
backup = EncryptedBackup(backup_directory=base_dir, passphrase=password, cleanup=False, check_same_thread=False) backup = EncryptedBackup(backup_directory=base_dir, passphrase=password, cleanup=False, check_same_thread=False)
print("Decrypting WhatsApp database...", end="") print("Done\nDecrypting WhatsApp database...", end="")
try: try:
backup.extract_file( backup.extract_file(
relative_path=RelativePath.WHATSAPP_MESSAGES, relative_path=RelativePath.WHATSAPP_MESSAGES,
domain=identifiers.DOMAIN, domain_like=identifiers.DOMAIN,
output_filename=identifiers.MESSAGE output_filename=identifiers.MESSAGE
) )
backup.extract_file( backup.extract_file(
relative_path=RelativePath.WHATSAPP_CONTACTS, relative_path=RelativePath.WHATSAPP_CONTACTS,
domain=identifiers.DOMAIN, domain_like=identifiers.DOMAIN,
output_filename=identifiers.CONTACT output_filename=identifiers.CONTACT
) )
except FailedToDecryptError: except ValueError:
print("Failed to decrypt backup: incorrect password?") print("Failed to decrypt backup: incorrect password?")
exit() exit()
else: else:
print("Done") print("Done")
extract_thread = threading.Thread(
target=backup.extract_files_by_domain, def extract_progress_handler(file_id, domain, relative_path, n, total_files):
args=(identifiers.DOMAIN, identifiers.DOMAIN, bplist_reader) if n % 100 == 0:
print(f"Decrypting and extracting files...({n}/{total_files})", end="\r")
return True
backup.extract_files(
domain_like=identifiers.DOMAIN,
output_folder=identifiers.DOMAIN,
preserve_folders=True,
filter_callback=extract_progress_handler
) )
extract_thread.daemon = True print(f"All required files are decrypted and extracted. ", end="\n")
extract_thread.start()
dot = 0
while extract_thread.is_alive():
print(f"Decrypting and extracting files{'.' * dot}{' ' * (3 - dot)}", end="\r")
if dot < 3:
dot += 1
time.sleep(0.5)
else:
dot = 0
time.sleep(0.4)
print(f"All required files decrypted and extracted.", end="\n")
extract_thread.handled = True
return backup return backup
@@ -70,10 +64,7 @@ def is_encrypted(base_dir):
return False return False
def extract_media(base_dir, identifiers, preserve_timestamp=False): def extract_media(base_dir, identifiers):
if preserve_timestamp:
from Whatsapp_Chat_Exporter.bplist import BPListReader
preserve_timestamp = BPListReader
if is_encrypted(base_dir): if is_encrypted(base_dir):
if not support_encrypted: if not support_encrypted:
print("You don't have the dependencies to handle encrypted backup.") print("You don't have the dependencies to handle encrypted backup.")
@@ -82,7 +73,7 @@ def extract_media(base_dir, identifiers, preserve_timestamp=False):
return False return False
print("Encryption detected on the backup!") print("Encryption detected on the backup!")
password = getpass.getpass("Enter the password for the backup:") password = getpass.getpass("Enter the password for the backup:")
extract_encrypted(base_dir, password, identifiers, preserve_timestamp) extract_encrypted(base_dir, password, identifiers)
else: else:
wts_db = os.path.join(base_dir, identifiers.MESSAGE[:2], identifiers.MESSAGE) wts_db = os.path.join(base_dir, identifiers.MESSAGE[:2], identifiers.MESSAGE)
contact_db = os.path.join(base_dir, identifiers.CONTACT[:2], identifiers.CONTACT) contact_db = os.path.join(base_dir, identifiers.CONTACT[:2], identifiers.CONTACT)