mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-02-05 00:49:28 +00:00
Support crypt12
This commit is contained in:
@@ -94,7 +94,8 @@ def main():
|
||||
print("Decryption key specified, decrypting WhatsApp backup...")
|
||||
key = open(options.key, "rb").read()
|
||||
db = open(options.backup, "rb").read()
|
||||
if not extract.decrypt_backup(db, key, msg_db):
|
||||
is_crypt14 = False if "crypt12" in options.backup else True
|
||||
if not extract.decrypt_backup(db, key, msg_db, is_crypt14):
|
||||
print("Dependencies of decrypt_backup are not present. For details, see README.md")
|
||||
return False
|
||||
if options.wa is None:
|
||||
|
||||
@@ -28,20 +28,27 @@ def determine_day(last, current):
|
||||
return current
|
||||
|
||||
|
||||
def decrypt_backup(database, key, output):
|
||||
def decrypt_backup(database, key, output, crypt14=True):
|
||||
if not support_backup:
|
||||
return False
|
||||
if len(key) != 158:
|
||||
raise ValueError("The key file must be 158 bytes")
|
||||
if len(database) < 191:
|
||||
raise ValueError("The database file must be at least 191 bytes")
|
||||
t1 = key[30:62]
|
||||
t2 = database[15:47]
|
||||
if crypt14:
|
||||
if len(database) < 191:
|
||||
raise ValueError("The crypt14 file must be at least 191 bytes")
|
||||
t2 = database[15:47]
|
||||
iv = database[67:83]
|
||||
db_ciphertext = database[191:]
|
||||
else:
|
||||
if len(database) < 67:
|
||||
raise ValueError("The crypt12 file must be at least 67 bytes")
|
||||
t2 = database[3:35]
|
||||
iv = database[51:67]
|
||||
db_ciphertext = database[67:-20]
|
||||
if t1 != t2:
|
||||
raise ValueError("The signature of key file and backup file mismatch")
|
||||
|
||||
iv = database[67:83]
|
||||
db_ciphertext = database[191:]
|
||||
main_key = key[126:]
|
||||
cipher = AES.new(main_key, AES.MODE_GCM, iv)
|
||||
db_compressed = cipher.decrypt(db_ciphertext)
|
||||
|
||||
Reference in New Issue
Block a user