From 97f3b648a3f56124ba67287fe43c224195775e83 Mon Sep 17 00:00:00 2001 From: William Gibb Date: Fri, 3 Feb 2017 10:57:21 -0500 Subject: [PATCH] Allow UnexpectedDataError's to accept a tuple as the expected data. Without this, exceptions raised when checking REFERENCENAME will cause an error. --- oletools/olevba.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/oletools/olevba.py b/oletools/olevba.py index dba5a3a..9f06ff4 100644 --- a/oletools/olevba.py +++ b/oletools/olevba.py @@ -385,10 +385,17 @@ class UnexpectedDataError(OlevbaBaseException): """ raised when parsing is strict (=not relaxed) and data is unexpected """ def __init__(self, stream_path, variable, expected, value): + if isinstance(expected, int): + es = '{0:04X}'.format(expected) + elif isinstance(expected, tuple): + es = ','.join('{0:04X}'.format(e) for e in expected) + es = '({0})'.format(es) + else: + raise ValueError('Unknown type encountered: {0}'.format(type(expected))) super(UnexpectedDataError, self).__init__( 'Unexpected value in {0} for variable {1}: ' - 'expected {2:04X} but found {3:04X}!' - .format(stream_path, variable, expected, value)) + 'expected {2} but found {3:04X}!' + .format(stream_path, variable, es, value)) self.stream_path = stream_path self.variable = variable self.expected = expected -- libgit2 0.21.4