Commit 0d0d7853d981c0e348999e12f238bd97d660baef
1 parent
f1fcb31e
handle errors from xglob; change return codes again (add RETURN_XGLOB_ERR)
Showing
1 changed file
with
26 additions
and
6 deletions
oletools/olevba.py
| ... | ... | @@ -238,7 +238,7 @@ except ImportError: |
| 238 | 238 | |
| 239 | 239 | import thirdparty.olefile as olefile |
| 240 | 240 | from thirdparty.prettytable import prettytable |
| 241 | -from thirdparty.xglob import xglob | |
| 241 | +from thirdparty.xglob import xglob, PathNotFoundException | |
| 242 | 242 | from thirdparty.pyparsing.pyparsing import * |
| 243 | 243 | |
| 244 | 244 | # monkeypatch email to fix issue #32: |
| ... | ... | @@ -327,11 +327,12 @@ class MsoExtractionError(RuntimeError): |
| 327 | 327 | RETURN_OK = 0 |
| 328 | 328 | RETURN_WARNINGS = 1 # (reserved, not used yet) |
| 329 | 329 | RETURN_WRONG_ARGS = 2 # (fixed, built into optparse) |
| 330 | -RETURN_OPEN_ERROR = 3 | |
| 331 | -RETURN_PARSE_ERROR = 4 | |
| 332 | -RETURN_FILE_NOT_FOUND = 5 | |
| 333 | -RETURN_SEVERAL_ERRS = 6 | |
| 334 | -RETURN_UNEXPECTED = 7 | |
| 330 | +RETURN_FILE_NOT_FOUND = 3 | |
| 331 | +RETURN_XGLOB_ERR = 4 | |
| 332 | +RETURN_OPEN_ERROR = 5 | |
| 333 | +RETURN_PARSE_ERROR = 6 | |
| 334 | +RETURN_SEVERAL_ERRS = 7 | |
| 335 | +RETURN_UNEXPECTED = 8 | |
| 335 | 336 | |
| 336 | 337 | # URL and message to report issues: |
| 337 | 338 | URL_OLEVBA_ISSUES = 'https://bitbucket.org/decalage/oletools/issues' |
| ... | ... | @@ -2892,6 +2893,25 @@ def main(): |
| 2892 | 2893 | if container and filename.endswith('/'): |
| 2893 | 2894 | continue |
| 2894 | 2895 | |
| 2896 | + # handle errors from xglob | |
| 2897 | + if isinstance(data, Exception): | |
| 2898 | + if isinstance(data, PathNotFoundException): | |
| 2899 | + if options.output_mode in ('triage', 'unspecified'): | |
| 2900 | + print '%-12s %s - File not found' % ('?', filename) | |
| 2901 | + else: | |
| 2902 | + log.exception('Given path %r does not exist!' % filename) | |
| 2903 | + return_code = RETURN_FILE_NOT_FOUND if return_code == 0 \ | |
| 2904 | + else RETURN_SEVERAL_ERRS | |
| 2905 | + else: | |
| 2906 | + if options.output_mode in ('triage', 'unspecified'): | |
| 2907 | + print '%-12s %s - Failed to read from zip file %s' % ('?', filename, container) | |
| 2908 | + else: | |
| 2909 | + log.exception('Exception opening/reading %r from zip file %r: %s' | |
| 2910 | + % (filename, container, data)) | |
| 2911 | + return_code = RETURN_XGLOB_ERR if return_code == 0 \ | |
| 2912 | + else RETURN_SEVERAL_ERRS | |
| 2913 | + continue | |
| 2914 | + | |
| 2895 | 2915 | try: |
| 2896 | 2916 | # Open the file |
| 2897 | 2917 | vba_parser = VBA_Parser_CLI(filename, data=data, container=container) | ... | ... |