Commit 44ec0bd851e561350f04830f7713e1f0bcb15bf5
1 parent
ce32342a
olevba: fixed issue #58 with format() to support Python 2.6
Showing
1 changed file
with
19 additions
and
19 deletions
oletools/olevba.py
| ... | ... | @@ -175,9 +175,10 @@ https://github.com/unixfreak0037/officeparser |
| 175 | 175 | # 2016-05-12 CH: - added support for PowerPoint 97-2003 files |
| 176 | 176 | # 2016-06-06 CH: - improved handling of unicode VBA module names |
| 177 | 177 | # 2016-06-07 CH: - added option --relaxed, stricter parsing by default |
| 178 | -# 2016-06-12 v0.47.1 PL: - fixed small bugs in VBA parsing code | |
| 178 | +# 2016-06-12 v0.48 PL: - fixed small bugs in VBA parsing code | |
| 179 | +# 2016-07-01 PL: - fixed issue #58 with format() to support Python 2.6 | |
| 179 | 180 | |
| 180 | -__version__ = '0.47.1' | |
| 181 | +__version__ = '0.48' | |
| 181 | 182 | |
| 182 | 183 | #------------------------------------------------------------------------------ |
| 183 | 184 | # TODO: |
| ... | ... | @@ -307,7 +308,7 @@ class OlevbaBaseException(Exception): |
| 307 | 308 | def __init__(self, msg, filename=None, orig_exc=None, **kwargs): |
| 308 | 309 | if orig_exc: |
| 309 | 310 | super(OlevbaBaseException, self).__init__(msg + |
| 310 | - ' ({})'.format(orig_exc), | |
| 311 | + ' ({0})'.format(orig_exc), | |
| 311 | 312 | **kwargs) |
| 312 | 313 | else: |
| 313 | 314 | super(OlevbaBaseException, self).__init__(msg, **kwargs) |
| ... | ... | @@ -358,8 +359,8 @@ class UnexpectedDataError(OlevbaBaseException): |
| 358 | 359 | |
| 359 | 360 | def __init__(self, stream_path, variable, expected, value): |
| 360 | 361 | super(UnexpectedDataError, self).__init__(self, |
| 361 | - 'Unexpected value in {} for variable {}: ' | |
| 362 | - 'expected {:04X but found {:04X}!' | |
| 362 | + 'Unexpected value in {0} for variable {1}: ' | |
| 363 | + 'expected {2:04X} but found {3:04X}!' | |
| 363 | 364 | .format(stream_path, variable, expected, value)) |
| 364 | 365 | self.stream_path = stream_path |
| 365 | 366 | self.variable = variable |
| ... | ... | @@ -1148,7 +1149,7 @@ def _extract_vba(ole, vba_root, project_path, dir_path, relaxed=False): |
| 1148 | 1149 | """ |
| 1149 | 1150 | # Open the PROJECT stream: |
| 1150 | 1151 | project = ole.openstream(project_path) |
| 1151 | - log.debug('relaxed is {}'.format(relaxed)) | |
| 1152 | + log.debug('relaxed is %s' % relaxed) | |
| 1152 | 1153 | |
| 1153 | 1154 | # sample content of the PROJECT stream: |
| 1154 | 1155 | |
| ... | ... | @@ -1577,12 +1578,12 @@ def _extract_vba(ole, vba_root, project_path, dir_path, relaxed=False): |
| 1577 | 1578 | code_data = ole.openstream(code_path).read() |
| 1578 | 1579 | break |
| 1579 | 1580 | except IOError as ioe: |
| 1580 | - log.debug('failed to open stream VBA/{} ({}), try other name' | |
| 1581 | - .format(uni_out(stream_name), ioe)) | |
| 1581 | + log.debug('failed to open stream VBA/%r (%r), try other name' | |
| 1582 | + % (uni_out(stream_name), ioe)) | |
| 1582 | 1583 | |
| 1583 | 1584 | if code_data is None: |
| 1584 | - log.info("Could not open stream {} of {} ('VBA/' + one of {})!" | |
| 1585 | - .format(projectmodule_index, projectmodules_count, | |
| 1585 | + log.info("Could not open stream %d of %d ('VBA/' + one of %r)!" | |
| 1586 | + % (projectmodule_index, projectmodules_count, | |
| 1586 | 1587 | '/'.join("'" + uni_out(stream_name) + "'" |
| 1587 | 1588 | for stream_name in try_names))) |
| 1588 | 1589 | if relaxed: |
| ... | ... | @@ -1612,7 +1613,7 @@ def _extract_vba(ole, vba_root, project_path, dir_path, relaxed=False): |
| 1612 | 1613 | except (UnexpectedDataError, SubstreamOpenError): |
| 1613 | 1614 | raise |
| 1614 | 1615 | except Exception as exc: |
| 1615 | - log.info('Error parsing module {} of {} in _extract_vba:' | |
| 1616 | + log.info('Error parsing module {0} of {1} in _extract_vba:' | |
| 1616 | 1617 | .format(projectmodule_index, projectmodules_count), |
| 1617 | 1618 | exc_info=True) |
| 1618 | 1619 | if not relaxed: |
| ... | ... | @@ -1897,7 +1898,7 @@ def print_json(json_dict=None, _json_is_last=False, **json_parts): |
| 1897 | 1898 | 'key=value parts but got both)') |
| 1898 | 1899 | elif (json_dict is not None) and (not isinstance(json_dict, dict)): |
| 1899 | 1900 | raise ValueError('Invalid json argument: want either single dict or ' |
| 1900 | - 'key=value parts but got {} instead of dict)' | |
| 1901 | + 'key=value parts but got {0} instead of dict)' | |
| 1901 | 1902 | .format(type(json_dict))) |
| 1902 | 1903 | if json_parts: |
| 1903 | 1904 | json_dict = json_parts |
| ... | ... | @@ -1909,12 +1910,12 @@ def print_json(json_dict=None, _json_is_last=False, **json_parts): |
| 1909 | 1910 | lines = json.dumps(json2ascii(json_dict), check_circular=False, |
| 1910 | 1911 | indent=4, ensure_ascii=False).splitlines() |
| 1911 | 1912 | for line in lines[:-1]: |
| 1912 | - print ' {}'.format(line) | |
| 1913 | + print ' {0}'.format(line) | |
| 1913 | 1914 | if _json_is_last: |
| 1914 | - print ' {}'.format(lines[-1]) # print last line without comma | |
| 1915 | + print ' {0}'.format(lines[-1]) # print last line without comma | |
| 1915 | 1916 | print ']' |
| 1916 | 1917 | else: |
| 1917 | - print ' {},'.format(lines[-1]) # print last line with comma | |
| 1918 | + print ' {0},'.format(lines[-1]) # print last line with comma | |
| 1918 | 1919 | |
| 1919 | 1920 | |
| 1920 | 1921 | class VBA_Scanner(object): |
| ... | ... | @@ -2260,7 +2261,7 @@ class VBA_Parser(object): |
| 2260 | 2261 | self.type = TYPE_OpenXML |
| 2261 | 2262 | except OlevbaBaseException as exc: |
| 2262 | 2263 | if self.relaxed: |
| 2263 | - log.info('Error {} caught in Zip/OpenXML parsing for file {}' | |
| 2264 | + log.info('Error {0} caught in Zip/OpenXML parsing for file {1}' | |
| 2264 | 2265 | .format(exc, self.filename)) |
| 2265 | 2266 | log.debug('Trace:', exc_info=True) |
| 2266 | 2267 | else: |
| ... | ... | @@ -2300,7 +2301,7 @@ class VBA_Parser(object): |
| 2300 | 2301 | relaxed=self.relaxed)) |
| 2301 | 2302 | except OlevbaBaseException as exc: |
| 2302 | 2303 | if self.relaxed: |
| 2303 | - log.info('Error parsing subfile {}: {}' | |
| 2304 | + log.info('Error parsing subfile {0}: {1}' | |
| 2304 | 2305 | .format(fname, exc)) |
| 2305 | 2306 | log.debug('Trace:', exc_info=True) |
| 2306 | 2307 | else: |
| ... | ... | @@ -2583,8 +2584,7 @@ class VBA_Parser(object): |
| 2583 | 2584 | data = ole._open(d.isectStart, d.size).read() |
| 2584 | 2585 | log.debug('Read %d bytes' % len(data)) |
| 2585 | 2586 | if len(data) > 200: |
| 2586 | - log.debug('{}...[much more data]...{}' | |
| 2587 | - .format(repr(data[:100]), repr(data[-50:]))) | |
| 2587 | + log.debug('%r...[much more data]...%r' % (data[:100], data[-50:])) | |
| 2588 | 2588 | else: |
| 2589 | 2589 | log.debug(repr(data)) |
| 2590 | 2590 | if 'Attribut' in data: | ... | ... |