mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-04-24 15:01:36 +00:00
Implement dry-run for decrypting Android backup #130
This commit is contained in:
@@ -53,9 +53,11 @@ def _extract_encrypted_key(keyfile):
|
|||||||
return _generate_hmac_of_hmac(key_stream)
|
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:
|
if not support_backup:
|
||||||
return 1
|
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):
|
if isinstance(key, io.IOBase):
|
||||||
key = key.read()
|
key = key.read()
|
||||||
if crypt is not Crypt.CRYPT15:
|
if crypt is not Crypt.CRYPT15:
|
||||||
@@ -146,8 +148,9 @@ def decrypt_backup(database, key, output, crypt=Crypt.CRYPT14, show_crypt15=Fals
|
|||||||
else:
|
else:
|
||||||
decompressed = True
|
decompressed = True
|
||||||
if db[0:6].upper() == b"SQLITE":
|
if db[0:6].upper() == b"SQLITE":
|
||||||
with open(output, "wb") as f:
|
if not dry_run:
|
||||||
f.write(db)
|
with open(output, "wb") as f:
|
||||||
|
f.write(db)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
raise ValueError("The plaintext is not a SQLite database. Did you use the key to encrypt something...")
|
raise ValueError("The plaintext is not a SQLite database. Did you use the key to encrypt something...")
|
||||||
|
|||||||
Reference in New Issue
Block a user