mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-03-13 01:22:59 +00:00
Refactoring
This commit is contained in:
@@ -104,10 +104,19 @@ def main():
|
||||
key = open(options.key, "rb").read()
|
||||
db = open(options.backup, "rb").read()
|
||||
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")
|
||||
exit(3)
|
||||
error = extract.decrypt_backup(db, key, msg_db, is_crypt14)
|
||||
if error != 0:
|
||||
if error == 1:
|
||||
print("Dependencies of decrypt_backup are not "
|
||||
"present. For details, see README.md.")
|
||||
exit(3)
|
||||
elif error == 2:
|
||||
print("Failed when decompressing the decrypted backup."
|
||||
"Possibly incorrect offsets used in decryption.")
|
||||
exit(4)
|
||||
else:
|
||||
print("Unknown error occurred.")
|
||||
exit(5)
|
||||
if options.wa is None:
|
||||
contact_db = "wa.db"
|
||||
else:
|
||||
|
||||
@@ -37,7 +37,7 @@ def determine_day(last, current):
|
||||
|
||||
def decrypt_backup(database, key, output, crypt14=True):
|
||||
if not support_backup:
|
||||
return False
|
||||
return 1
|
||||
if len(key) != 158:
|
||||
raise ValueError("The key file must be 158 bytes")
|
||||
t1 = key[30:62]
|
||||
@@ -62,11 +62,11 @@ def decrypt_backup(database, key, output, crypt14=True):
|
||||
try:
|
||||
db = zlib.decompress(db_compressed)
|
||||
except zlib.error:
|
||||
print("Decompressing failed. Possibly incorrect offsets used in decryption.")
|
||||
return 2
|
||||
if db[0:6].upper() == b"SQLITE":
|
||||
with open(output, "wb") as f:
|
||||
f.write(db)
|
||||
return True
|
||||
return 0
|
||||
else:
|
||||
raise ValueError("The plaintext is not a SQLite database. Did you use the key to encrypt something...")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user