Skip to content

Commit

Permalink
Bug fix on incorrectly positioned argument
Browse files Browse the repository at this point in the history
This commit also made `dry_run` and `keyfile_stream` keyword arguments

Affects #130
  • Loading branch information
KnugiHK committed Feb 26, 2025
1 parent a7496f8 commit 457ab20
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
24 changes: 20 additions & 4 deletions Whatsapp_Chat_Exporter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,35 @@ def main():
crypt = Crypt.CRYPT15
if not os.path.isfile(args.key) and all(char in string.hexdigits for char in args.key.replace(" ", "")):
key = bytes.fromhex(args.key.replace(" ", ""))
key_stream = False
keyfile_stream = False
else:
key = open(args.key, "rb")
key_stream = True
keyfile_stream = True
db = open(args.backup, "rb").read()
if args.wab:
wab = open(args.wab, "rb").read()
error_wa = android_crypt.decrypt_backup(wab, key, contact_db, crypt, args.showkey, DbType.CONTACT, key_stream)
error_wa = android_crypt.decrypt_backup(
wab,
key,
contact_db,
crypt,
args.showkey,
DbType.CONTACT,
keyfile_stream=keyfile_stream
)
if isinstance(key, io.IOBase):
key.seek(0)
else:
error_wa = 0
error_message = android_crypt.decrypt_backup(db, key, msg_db, crypt, args.showkey, DbType.MESSAGE, key_stream)
error_message = android_crypt.decrypt_backup(
db,
key,
msg_db,
crypt,
args.showkey,
DbType.MESSAGE,
keyfile_stream=keyfile_stream
)
if error_wa != 0:
error = error_wa
elif error_message != 0:
Expand Down
5 changes: 3 additions & 2 deletions Whatsapp_Chat_Exporter/android_crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def decrypt_backup(
crypt: Crypt = Crypt.CRYPT14,
show_crypt15: bool = False,
db_type: DbType = DbType.MESSAGE,
*,
dry_run: bool = False,
key_stream: bool = False
keyfile_stream: bool = False
) -> int:
"""
Decrypt the WhatsApp backup database.
Expand Down Expand Up @@ -152,7 +153,7 @@ def decrypt_backup(
raise ValueError("The signature of key file and backup file mismatch")

if crypt == Crypt.CRYPT15:
if key_stream:
if keyfile_stream:
main_key, hex_key = _extract_enc_key(key)
else:
main_key, hex_key = _derive_main_enc_key(key)
Expand Down

0 comments on commit 457ab20

Please sign in to comment.