Commit 84ea7425939d691d82e096bad655587fcc8cb502
1 parent
1363c4f0
msodde: Make password list optional for processing function
Showing
1 changed file
with
8 additions
and
2 deletions
oletools/msodde.py
| @@ -935,7 +935,8 @@ def process_file(filepath, field_filter_mode=None): | @@ -935,7 +935,8 @@ def process_file(filepath, field_filter_mode=None): | ||
| 935 | # === MAIN ================================================================= | 935 | # === MAIN ================================================================= |
| 936 | 936 | ||
| 937 | 937 | ||
| 938 | -def process_maybe_encrypted(filepath, passwords, crypto_nesting=0, **kwargs): | 938 | +def process_maybe_encrypted(filepath, passwords=None, crypto_nesting=0, |
| 939 | + **kwargs): | ||
| 939 | """ | 940 | """ |
| 940 | Process a file that might be encrypted. | 941 | Process a file that might be encrypted. |
| 941 | 942 | ||
| @@ -944,7 +945,7 @@ def process_maybe_encrypted(filepath, passwords, crypto_nesting=0, **kwargs): | @@ -944,7 +945,7 @@ def process_maybe_encrypted(filepath, passwords, crypto_nesting=0, **kwargs): | ||
| 944 | :py:mod:`oletools.crypto`. | 945 | :py:mod:`oletools.crypto`. |
| 945 | 946 | ||
| 946 | :param str filepath: path to file on disc. | 947 | :param str filepath: path to file on disc. |
| 947 | - :param passwords: list of passwords (str) to try for decryption | 948 | + :param passwords: list of passwords (str) to try for decryption or None |
| 948 | :param int crypto_nesting: How many decryption layers were already used to | 949 | :param int crypto_nesting: How many decryption layers were already used to |
| 949 | get the given file. | 950 | get the given file. |
| 950 | :param kwargs: same as :py:func:`process_file` | 951 | :param kwargs: same as :py:func:`process_file` |
| @@ -965,6 +966,11 @@ def process_maybe_encrypted(filepath, passwords, crypto_nesting=0, **kwargs): | @@ -965,6 +966,11 @@ def process_maybe_encrypted(filepath, passwords, crypto_nesting=0, **kwargs): | ||
| 965 | raise crypto.MaxCryptoNestingReached(crypto_nesting, filepath) | 966 | raise crypto.MaxCryptoNestingReached(crypto_nesting, filepath) |
| 966 | 967 | ||
| 967 | decrypted_file = None | 968 | decrypted_file = None |
| 969 | + if passwords is None: | ||
| 970 | + passwords = [crypto.WRITE_PROTECT_ENCRYPTION_PASSWORD, ] | ||
| 971 | + else: | ||
| 972 | + passwords = list(passwords) + \ | ||
| 973 | + [crypto.WRITE_PROTECT_ENCRYPTION_PASSWORD, ] | ||
| 968 | try: | 974 | try: |
| 969 | logger.debug('Trying to decrypt file') | 975 | logger.debug('Trying to decrypt file') |
| 970 | decrypted_file = crypto.decrypt(filepath, passwords) | 976 | decrypted_file = crypto.decrypt(filepath, passwords) |