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