mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-04-26 16:01:33 +00:00
Allow users to set the number of threads for bruteforcing offsets
This commit is contained in:
@@ -229,6 +229,10 @@ def setup_argument_parser() -> ArgumentParser:
|
|||||||
"--decrypt-chunk-size", dest="decrypt_chunk_size", default=1 * 1024 * 1024, type=int,
|
"--decrypt-chunk-size", dest="decrypt_chunk_size", default=1 * 1024 * 1024, type=int,
|
||||||
help="Specify the chunk size for decrypting iOS backup, which may affect the decryption speed."
|
help="Specify the chunk size for decrypting iOS backup, which may affect the decryption speed."
|
||||||
)
|
)
|
||||||
|
misc_group.add_argument(
|
||||||
|
"--max-bruteforce-worker", dest="max_bruteforce_worker", default=10, type=int,
|
||||||
|
help="Specify the maximum number of worker for bruteforce decryption."
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@@ -398,7 +402,8 @@ def decrypt_android_backup(args) -> int:
|
|||||||
crypt,
|
crypt,
|
||||||
args.showkey,
|
args.showkey,
|
||||||
DbType.CONTACT,
|
DbType.CONTACT,
|
||||||
keyfile_stream=keyfile_stream
|
keyfile_stream=keyfile_stream,
|
||||||
|
max_worker=args.max_bruteforce_worker
|
||||||
)
|
)
|
||||||
if isinstance(key, io.IOBase):
|
if isinstance(key, io.IOBase):
|
||||||
key.seek(0)
|
key.seek(0)
|
||||||
@@ -411,7 +416,8 @@ def decrypt_android_backup(args) -> int:
|
|||||||
crypt,
|
crypt,
|
||||||
args.showkey,
|
args.showkey,
|
||||||
DbType.MESSAGE,
|
DbType.MESSAGE,
|
||||||
keyfile_stream=keyfile_stream
|
keyfile_stream=keyfile_stream,
|
||||||
|
max_worker=args.max_bruteforce_worker
|
||||||
)
|
)
|
||||||
|
|
||||||
# Handle errors
|
# Handle errors
|
||||||
|
|||||||
@@ -114,12 +114,13 @@ def _decrypt_database(db_ciphertext: bytes, main_key: bytes, iv: bytes) -> bytes
|
|||||||
)
|
)
|
||||||
return db
|
return db
|
||||||
|
|
||||||
def _decrypt_crypt14(database: bytes, main_key: bytes) -> bytes:
|
def _decrypt_crypt14(database: bytes, main_key: bytes, max_worker: int = 10) -> bytes:
|
||||||
"""Decrypt a crypt14 database using multithreading for brute-force offset detection.
|
"""Decrypt a crypt14 database using multithreading for brute-force offset detection.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
database (bytes): The encrypted database.
|
database (bytes): The encrypted database.
|
||||||
main_key (bytes): The decryption key.
|
main_key (bytes): The decryption key.
|
||||||
|
max_worker (int, optional): The maximum number of threads to use for brute force. Defaults to 10.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bytes: The decrypted database.
|
bytes: The decrypted database.
|
||||||
@@ -164,7 +165,7 @@ def _decrypt_crypt14(database: bytes, main_key: bytes) -> bytes:
|
|||||||
except (zlib.error, ValueError):
|
except (zlib.error, ValueError):
|
||||||
return None # Decryption failed, move to next
|
return None # Decryption failed, move to next
|
||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(10) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_worker) as executor:
|
||||||
future_to_offset = {executor.submit(attempt_decrypt, offset): offset for offset in offset_combinations}
|
future_to_offset = {executor.submit(attempt_decrypt, offset): offset for offset in offset_combinations}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -247,7 +248,8 @@ def decrypt_backup(
|
|||||||
db_type: DbType = DbType.MESSAGE,
|
db_type: DbType = DbType.MESSAGE,
|
||||||
*,
|
*,
|
||||||
dry_run: bool = False,
|
dry_run: bool = False,
|
||||||
keyfile_stream: bool = False
|
keyfile_stream: bool = False,
|
||||||
|
max_worker: int = 10
|
||||||
) -> int:
|
) -> int:
|
||||||
"""
|
"""
|
||||||
Decrypt the WhatsApp backup database.
|
Decrypt the WhatsApp backup database.
|
||||||
@@ -308,7 +310,7 @@ def decrypt_backup(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if crypt == Crypt.CRYPT14:
|
if crypt == Crypt.CRYPT14:
|
||||||
db = _decrypt_crypt14(database, main_key)
|
db = _decrypt_crypt14(database, main_key, max_worker)
|
||||||
elif crypt == Crypt.CRYPT12:
|
elif crypt == Crypt.CRYPT12:
|
||||||
db = _decrypt_crypt12(database, main_key)
|
db = _decrypt_crypt12(database, main_key)
|
||||||
elif crypt == Crypt.CRYPT15:
|
elif crypt == Crypt.CRYPT15:
|
||||||
|
|||||||
Reference in New Issue
Block a user