Commit 276fe51ad71b341fb7f3e7209501b588a4637d0f
1 parent
1e403e0e
crypto: Raise different error if trying to decrypt ppt
ppt is not (yet) support by msoffcrypto
Showing
1 changed file
with
13 additions
and
1 deletions
oletools/crypto.py
| ... | ... | @@ -84,6 +84,7 @@ http://www.decalage.info/python/oletools |
| 84 | 84 | |
| 85 | 85 | __version__ = '0.01' |
| 86 | 86 | |
| 87 | +import sys | |
| 87 | 88 | import struct |
| 88 | 89 | import os |
| 89 | 90 | from os.path import splitext, isfile |
| ... | ... | @@ -246,7 +247,18 @@ def decrypt(filename, passwords=None, **temp_file_args): |
| 246 | 247 | |
| 247 | 248 | decrypt_file = None |
| 248 | 249 | with open(filename, 'rb') as reader: |
| 249 | - crypto_file = msoffcrypto.OfficeFile(reader) | |
| 250 | + try: | |
| 251 | + crypto_file = msoffcrypto.OfficeFile(reader) | |
| 252 | + except Exception as exc: # e.g. ppt, not yet supported by msoffcrypto | |
| 253 | + if 'Unrecognized file format' in str(exc): | |
| 254 | + # raise different exception without stack trace of original exc | |
| 255 | + if sys.version_info.major == 2: | |
| 256 | + raise UnsupportedEncryptionError(filename) | |
| 257 | + else: | |
| 258 | + # this is a syntax error in python 2, so wrap it in exec() | |
| 259 | + exec('raise UnsupportedEncryptionError(filename) from None') | |
| 260 | + else: | |
| 261 | + raise | |
| 250 | 262 | if not crypto_file.is_encrypted(): |
| 251 | 263 | raise ValueError('Given input file {} is not encrypted!' |
| 252 | 264 | .format(filename)) | ... | ... |