Commit faa0d805a77b13d9b21782d04c47713d7941261a
1 parent
0bc67280
crypto: Add more debug output
Showing
1 changed file
with
6 additions
and
0 deletions
oletools/crypto.py
| @@ -361,6 +361,8 @@ def decrypt(filename, passwords=None, **temp_file_args): | @@ -361,6 +361,8 @@ def decrypt(filename, passwords=None, **temp_file_args): | ||
| 361 | crypto_file = msoffcrypto.OfficeFile(reader) | 361 | crypto_file = msoffcrypto.OfficeFile(reader) |
| 362 | except Exception as exc: # e.g. ppt, not yet supported by msoffcrypto | 362 | except Exception as exc: # e.g. ppt, not yet supported by msoffcrypto |
| 363 | if 'Unrecognized file format' in str(exc): | 363 | if 'Unrecognized file format' in str(exc): |
| 364 | + log.debug('Caught exception', exc_info=True) | ||
| 365 | + | ||
| 364 | # raise different exception without stack trace of original exc | 366 | # raise different exception without stack trace of original exc |
| 365 | if sys.version_info.major == 2: | 367 | if sys.version_info.major == 2: |
| 366 | raise UnsupportedEncryptionError(filename) | 368 | raise UnsupportedEncryptionError(filename) |
| @@ -374,6 +376,7 @@ def decrypt(filename, passwords=None, **temp_file_args): | @@ -374,6 +376,7 @@ def decrypt(filename, passwords=None, **temp_file_args): | ||
| 374 | .format(filename)) | 376 | .format(filename)) |
| 375 | 377 | ||
| 376 | for password in passwords: | 378 | for password in passwords: |
| 379 | + log.debug('Trying to decrypt with password {!r}'.format(password)) | ||
| 377 | write_descriptor = None | 380 | write_descriptor = None |
| 378 | write_handle = None | 381 | write_handle = None |
| 379 | decrypt_file = None | 382 | decrypt_file = None |
| @@ -391,6 +394,8 @@ def decrypt(filename, passwords=None, **temp_file_args): | @@ -391,6 +394,8 @@ def decrypt(filename, passwords=None, **temp_file_args): | ||
| 391 | write_handle = None | 394 | write_handle = None |
| 392 | break | 395 | break |
| 393 | except Exception: | 396 | except Exception: |
| 397 | + log.debug('Failed to decrypt', exc_info=True) | ||
| 398 | + | ||
| 394 | # error-clean up: close everything and del temp file | 399 | # error-clean up: close everything and del temp file |
| 395 | if write_handle: | 400 | if write_handle: |
| 396 | write_handle.close() | 401 | write_handle.close() |
| @@ -400,4 +405,5 @@ def decrypt(filename, passwords=None, **temp_file_args): | @@ -400,4 +405,5 @@ def decrypt(filename, passwords=None, **temp_file_args): | ||
| 400 | os.unlink(decrypt_file) | 405 | os.unlink(decrypt_file) |
| 401 | decrypt_file = None | 406 | decrypt_file = None |
| 402 | # if we reach this, all passwords were tried without success | 407 | # if we reach this, all passwords were tried without success |
| 408 | + log.debug('All passwords failed') | ||
| 403 | return decrypt_file | 409 | return decrypt_file |