Skip to content

Commit

Permalink
logging improvements
Browse files Browse the repository at this point in the history
most notably, with '-v' information about the header of the DB will be printed, this is useful for re-encryption.

Co-authored-by: kingbtcvl <96168160+kingbtcvl@users.noreply.github.com>
  • Loading branch information
ElDavoo and kingbtcvl authored Mar 31, 2024
1 parent 2bc0db5 commit 2ae18b1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/wa_crypt_tools/lib/db/dbfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from wa_crypt_tools.lib.db.db12 import Database12
from wa_crypt_tools.lib.db.db14 import Database14
from wa_crypt_tools.lib.db.db15 import Database15
from wa_crypt_tools.lib.utils import header_info

l = logging.getLogger(__name__)

Expand Down Expand Up @@ -122,6 +123,7 @@ def from_file(encrypted):
raise DecodeError

# We are done here
l.debug(header_info(header))
if header.c15_iv.IV:
db = Database15(iv=iv)
db.file_hash = file_hash
Expand Down
2 changes: 1 addition & 1 deletion src/wa_crypt_tools/lib/logformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CustomFormatter(logging.Formatter):
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
format = "%(levelname)s\t - %(filename)s:%(lineno)d \t : %(message)s"
format = "%(filename)s:%(lineno)d \t: [%(levelname).1s] %(message)s"

FORMATS = {
logging.DEBUG: grey + format + reset,
Expand Down
29 changes: 29 additions & 0 deletions src/wa_crypt_tools/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from wa_crypt_tools.lib.constants import C

# FIXME a "utils" file shouldn't have its own logger
l = logging.getLogger(__name__)


Expand Down Expand Up @@ -150,3 +151,31 @@ def get_mcrypt1_name(*, key, name: str, md5: bytes) -> bytes:
hmac_n.update(md5)
media_hash = hmac_n.digest()
return media_hash

def header_info(header):
"""
shows all header, information including the feature vector
FIXME
"""
string: str = ""
if header.c15_iv.IV:
string += "Crypt15 info:\n"
string += str("Header information in your crypt15 file:")
string += str("IV: {}\n".format(header.c15_iv.IV.hex()))
if header.c14_cipher.IV:
string += str("Header information in your crypt14 file:\n")
string += str("Cipher version: {}\n".format(header.c14_cipher.cipher_version.hex()))
string += str("Key version: {}\n".format(header.c14_cipher.key_version.hex()))
string += str("Server satl: {}\n".format(header.c14_cipher.server_salt.hex()))
string += str("Google ID: {}\n".format(header.c14_cipher.google_id.hex()))
string += str("IV: {}\n".format(header.c14_cipher.IV.hex()))
string += str("Key type: {}\n".format(header.key_type))
string += str("WhatsApp version: {}\n".format(header.info.app_version))
#string += str("Device model: {}".format(header.info.device_model))
string += str("The last two numbers of the user's Jid: {}\n".format(header.info.jidSuffix))
string += str("Backup version: {}\n".format(header.info.backup_version))
#string += str("Size of the backup file: {}".format(header.backup_export_file_size))
features = [n for n in [*range(5,38), 39] if getattr(header.info, "f_" + str(n)) == True]
string += str("Features: {}\n".format(features))
string += str("Max feature number: {}\n".format(max(features)))
return string
3 changes: 3 additions & 0 deletions src/wa_crypt_tools/wadecrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ def main():
ch.setLevel(logging.DEBUG if args.verbose else logging.INFO)
ch.setFormatter(CustomFormatter())
l.addHandler(ch)
# also add to "wa_crypt_tools.lib" logger
logging.getLogger("wa_crypt_tools.lib").addHandler(ch)
logging.getLogger("wa_crypt_tools.lib").setLevel(logging.DEBUG if args.verbose else logging.INFO)
if args.buffer_size is not None:
if not 1 < args.buffer_size < maxsize:
l.fatal("Invalid buffer size")
Expand Down

0 comments on commit 2ae18b1

Please sign in to comment.