Skip to content

Commit

Permalink
Implement dry-run for decrypting Android backup #130
Browse files Browse the repository at this point in the history
  • Loading branch information
KnugiHK committed Feb 21, 2025
1 parent 8c85656 commit d6b1d94
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Whatsapp_Chat_Exporter/android_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ def _extract_encrypted_key(keyfile):
return _generate_hmac_of_hmac(key_stream)


def decrypt_backup(database, key, output, crypt=Crypt.CRYPT14, show_crypt15=False, db_type=DbType.MESSAGE):
def decrypt_backup(database, key, output=None, crypt=Crypt.CRYPT14, show_crypt15=False, db_type=DbType.MESSAGE, dry_run=False):
if not support_backup:
return 1
if not dry_run and output is None:
ValueError("The path to the decrypted database must be specified unless dry_run is true.")
if isinstance(key, io.IOBase):
key = key.read()
if crypt is not Crypt.CRYPT15:
Expand Down Expand Up @@ -146,8 +148,9 @@ def decrypt_backup(database, key, output, crypt=Crypt.CRYPT14, show_crypt15=Fals
else:
decompressed = True
if db[0:6].upper() == b"SQLITE":
with open(output, "wb") as f:
f.write(db)
if not dry_run:
with open(output, "wb") as f:
f.write(db)
return 0
else:
raise ValueError("The plaintext is not a SQLite database. Did you use the key to encrypt something...")
Expand Down

0 comments on commit d6b1d94

Please sign in to comment.