Commit 3e29e3617fe9f7f558939ca558068cb10e7b00c1

Authored by Christian Herdtweck
1 parent 6ec331df

msodde: minor fixes

- fix some whitespace and docs
- replace bare-except
- omit empty dde links in output
Showing 1 changed file with 8 additions and 6 deletions
oletools/msodde.py
@@ -109,8 +109,8 @@ Please report any issue at https://github.com/decalage2/oletools/issues @@ -109,8 +109,8 @@ Please report any issue at https://github.com/decalage2/oletools/issues
109 BANNER_JSON = dict(type='meta', version=__version__, name='msodde', 109 BANNER_JSON = dict(type='meta', version=__version__, name='msodde',
110 link='http://decalage.info/python/oletools', 110 link='http://decalage.info/python/oletools',
111 message='THIS IS WORK IN PROGRESS - Check updates regularly! ' 111 message='THIS IS WORK IN PROGRESS - Check updates regularly! '
112 - 'Please report any issue at '  
113 - 'https://github.com/decalage2/oletools/issues') 112 + 'Please report any issue at '
  113 + 'https://github.com/decalage2/oletools/issues')
114 114
115 # === LOGGING ================================================================= 115 # === LOGGING =================================================================
116 116
@@ -231,6 +231,7 @@ def existing_file(filename): @@ -231,6 +231,7 @@ def existing_file(filename):
231 231
232 232
233 def process_args(cmd_line_args=None): 233 def process_args(cmd_line_args=None):
  234 + """ parse command line arguments (given ones or per default sys.argv) """
234 parser = ArgParserWithBanner(description='A python tool to detect and extract DDE links in MS Office files') 235 parser = ArgParserWithBanner(description='A python tool to detect and extract DDE links in MS Office files')
235 parser.add_argument("filepath", help="path of the file to be analyzed", 236 parser.add_argument("filepath", help="path of the file to be analyzed",
236 type=existing_file, metavar='FILE') 237 type=existing_file, metavar='FILE')
@@ -339,7 +340,7 @@ def process_ole_stream(stream): @@ -339,7 +340,7 @@ def process_ole_stream(stream):
339 340
340 341
341 def process_ole_storage(ole): 342 def process_ole_storage(ole):
342 - """ process a "directory" inside an ole stream """ 343 + """ process a "directory" inside an ole file; recursive """
343 results = [] 344 results = []
344 for st in ole.listdir(streams=True, storages=True): 345 for st in ole.listdir(streams=True, storages=True):
345 st_type = ole.get_type(st) 346 st_type = ole.get_type(st)
@@ -350,7 +351,7 @@ def process_ole_storage(ole): @@ -350,7 +351,7 @@ def process_ole_storage(ole):
350 stream = ole.openstream(st) 351 stream = ole.openstream(st)
351 log.debug('Checking stream {0}'.format(st)) 352 log.debug('Checking stream {0}'.format(st))
352 links = process_ole_stream(stream) 353 links = process_ole_stream(stream)
353 - except: 354 + except Exception:
354 raise 355 raise
355 finally: 356 finally:
356 if stream: 357 if stream:
@@ -370,7 +371,7 @@ def process_ole_storage(ole): @@ -370,7 +371,7 @@ def process_ole_storage(ole):
370 371
371 372
372 def process_ole(filepath): 373 def process_ole(filepath):
373 - """ 374 + """
374 find dde links in ole file 375 find dde links in ole file
375 376
376 like process_xml, returns a concatenated unicode string of dde links or 377 like process_xml, returns a concatenated unicode string of dde links or
@@ -524,7 +525,8 @@ def main(cmd_line_args=None): @@ -524,7 +525,8 @@ def main(cmd_line_args=None):
524 525
525 if args.json: 526 if args.json:
526 for line in text.splitlines(): 527 for line in text.splitlines():
527 - jout.append(dict(type='dde-link', link=line.strip())) 528 + if line.strip():
  529 + jout.append(dict(type='dde-link', link=line.strip()))
528 json.dump(jout, sys.stdout, check_circular=False, indent=4) 530 json.dump(jout, sys.stdout, check_circular=False, indent=4)
529 print() # add a newline after closing "]" 531 print() # add a newline after closing "]"
530 return return_code # required if we catch an exception in json-mode 532 return return_code # required if we catch an exception in json-mode