From 276fe51ad71b341fb7f3e7209501b588a4637d0f Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Tue, 19 Mar 2019 13:43:46 +0100 Subject: [PATCH] crypto: Raise different error if trying to decrypt ppt --- oletools/crypto.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/oletools/crypto.py b/oletools/crypto.py index 4648a31..ffd16ec 100644 --- a/oletools/crypto.py +++ b/oletools/crypto.py @@ -84,6 +84,7 @@ http://www.decalage.info/python/oletools __version__ = '0.01' +import sys import struct import os from os.path import splitext, isfile @@ -246,7 +247,18 @@ def decrypt(filename, passwords=None, **temp_file_args): decrypt_file = None with open(filename, 'rb') as reader: - crypto_file = msoffcrypto.OfficeFile(reader) + try: + crypto_file = msoffcrypto.OfficeFile(reader) + except Exception as exc: # e.g. ppt, not yet supported by msoffcrypto + if 'Unrecognized file format' in str(exc): + # raise different exception without stack trace of original exc + if sys.version_info.major == 2: + raise UnsupportedEncryptionError(filename) + else: + # this is a syntax error in python 2, so wrap it in exec() + exec('raise UnsupportedEncryptionError(filename) from None') + else: + raise if not crypto_file.is_encrypted(): raise ValueError('Given input file {} is not encrypted!' .format(filename)) -- libgit2 0.21.4