Commit 27a69e14b95727a70bc05d444b8d6bd7047b646d

Authored by Christian Herdtweck
1 parent 52dc2d70

introduce return codes

Showing 1 changed file with 9 additions and 0 deletions
oletools/olevba.py
@@ -314,6 +314,13 @@ class MsoExtractionError(RuntimeError): @@ -314,6 +314,13 @@ class MsoExtractionError(RuntimeError):
314 314
315 #--- CONSTANTS ---------------------------------------------------------------- 315 #--- CONSTANTS ----------------------------------------------------------------
316 316
  317 +# return codes
  318 +RETURN_OK = 0
  319 +RETURN_PARSE_ERROR = 1
  320 +RETURN_OPEN_ERROR = 2
  321 +RETURN_FILE_NOT_FOUND = 3
  322 +RETURN_UNEXPECTED = 4
  323 +
317 # URL and message to report issues: 324 # URL and message to report issues:
318 URL_OLEVBA_ISSUES = 'https://bitbucket.org/decalage/oletools/issues' 325 URL_OLEVBA_ISSUES = 'https://bitbucket.org/decalage/oletools/issues'
319 MSG_OLEVBA_ISSUES = 'Please report this issue on %s' % URL_OLEVBA_ISSUES 326 MSG_OLEVBA_ISSUES = 'Please report this issue on %s' % URL_OLEVBA_ISSUES
@@ -2886,6 +2893,7 @@ def main(): @@ -2886,6 +2893,7 @@ def main():
2886 count = 0 2893 count = 0
2887 container = filename = data = None 2894 container = filename = data = None
2888 vba_parser = None 2895 vba_parser = None
  2896 + return_code = RETURN_OK
2889 for container, filename, data in xglob.iter_files(args, recursive=options.recursive, 2897 for container, filename, data in xglob.iter_files(args, recursive=options.recursive,
2890 zip_password=options.zip_password, zip_fname=options.zip_fname): 2898 zip_password=options.zip_password, zip_fname=options.zip_fname):
2891 # ignore directory names stored in zip files: 2899 # ignore directory names stored in zip files:
@@ -2896,6 +2904,7 @@ def main(): @@ -2896,6 +2904,7 @@ def main():
2896 vba_parser = VBA_Parser_CLI(filename, data=data, container=container) 2904 vba_parser = VBA_Parser_CLI(filename, data=data, container=container)
2897 except FileOpenError as exc: 2905 except FileOpenError as exc:
2898 log.exception('Failed to open %s (%s)!' % (filename, exc)) 2906 log.exception('Failed to open %s (%s)!' % (filename, exc))
  2907 + return_code = max(return_code, RETURN_OPEN_ERROR)
2899 continue 2908 continue
2900 2909
2901 if options.output_mode == 'detailed': 2910 if options.output_mode == 'detailed':