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 109 BANNER_JSON = dict(type='meta', version=__version__, name='msodde',
110 110 link='http://decalage.info/python/oletools',
111 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 115 # === LOGGING =================================================================
116 116  
... ... @@ -231,6 +231,7 @@ def existing_file(filename):
231 231  
232 232  
233 233 def process_args(cmd_line_args=None):
  234 + """ parse command line arguments (given ones or per default sys.argv) """
234 235 parser = ArgParserWithBanner(description='A python tool to detect and extract DDE links in MS Office files')
235 236 parser.add_argument("filepath", help="path of the file to be analyzed",
236 237 type=existing_file, metavar='FILE')
... ... @@ -339,7 +340,7 @@ def process_ole_stream(stream):
339 340  
340 341  
341 342 def process_ole_storage(ole):
342   - """ process a "directory" inside an ole stream """
  343 + """ process a "directory" inside an ole file; recursive """
343 344 results = []
344 345 for st in ole.listdir(streams=True, storages=True):
345 346 st_type = ole.get_type(st)
... ... @@ -350,7 +351,7 @@ def process_ole_storage(ole):
350 351 stream = ole.openstream(st)
351 352 log.debug('Checking stream {0}'.format(st))
352 353 links = process_ole_stream(stream)
353   - except:
  354 + except Exception:
354 355 raise
355 356 finally:
356 357 if stream:
... ... @@ -370,7 +371,7 @@ def process_ole_storage(ole):
370 371  
371 372  
372 373 def process_ole(filepath):
373   - """
  374 + """
374 375 find dde links in ole file
375 376  
376 377 like process_xml, returns a concatenated unicode string of dde links or
... ... @@ -524,7 +525,8 @@ def main(cmd_line_args=None):
524 525  
525 526 if args.json:
526 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 530 json.dump(jout, sys.stdout, check_circular=False, indent=4)
529 531 print() # add a newline after closing "]"
530 532 return return_code # required if we catch an exception in json-mode
... ...