Commit e87c0b102e1f98375576419e80f55468f10724a4
1 parent
698fabf4
olevba: hide first lines with VB attributes
Showing
1 changed file
with
23 additions
and
2 deletions
oletools/olevba.py
| @@ -81,8 +81,9 @@ Usage: olevba.py <file> | @@ -81,8 +81,9 @@ Usage: olevba.py <file> | ||
| 81 | # 2014-11-29 v0.04 PL: - use olefile instead of OleFileIO_PL | 81 | # 2014-11-29 v0.04 PL: - use olefile instead of OleFileIO_PL |
| 82 | # 2014-12-05 v0.05 PL: - refactored most functions into a class, new API | 82 | # 2014-12-05 v0.05 PL: - refactored most functions into a class, new API |
| 83 | # - added detect_vba_macros | 83 | # - added detect_vba_macros |
| 84 | +# 2014-12-10 v0.06 PL: - hide first lines with VB attributes | ||
| 84 | 85 | ||
| 85 | -__version__ = '0.05' | 86 | +__version__ = '0.06' |
| 86 | 87 | ||
| 87 | #------------------------------------------------------------------------------ | 88 | #------------------------------------------------------------------------------ |
| 88 | # TODO: | 89 | # TODO: |
| @@ -644,6 +645,26 @@ def _extract_vba (ole, vba_root, project_path, dir_path): | @@ -644,6 +645,26 @@ def _extract_vba (ole, vba_root, project_path, dir_path): | ||
| 644 | return | 645 | return |
| 645 | 646 | ||
| 646 | 647 | ||
| 648 | +def filter_vba(vba_code): | ||
| 649 | + """ | ||
| 650 | + Filter VBA source code to remove the first lines starting with "Attribute VB_" | ||
| 651 | + | ||
| 652 | + :param vba_code: str, VBA source code | ||
| 653 | + :return: str, filtered VBA source code | ||
| 654 | + """ | ||
| 655 | + vba_lines = vba_code.splitlines() | ||
| 656 | + start = 0 | ||
| 657 | + for line in vba_lines: | ||
| 658 | + if line.startswith("Attribute VB_"): | ||
| 659 | + start += 1 | ||
| 660 | + else: | ||
| 661 | + break | ||
| 662 | + #TODO: also remove empty lines? | ||
| 663 | + vba = '\n'.join(vba_lines[start:]) | ||
| 664 | + return vba | ||
| 665 | + | ||
| 666 | + | ||
| 667 | + | ||
| 647 | #=== CLASSES ================================================================= | 668 | #=== CLASSES ================================================================= |
| 648 | 669 | ||
| 649 | class VBA_Parser(object): | 670 | class VBA_Parser(object): |
| @@ -878,7 +899,7 @@ if __name__ == '__main__': | @@ -878,7 +899,7 @@ if __name__ == '__main__': | ||
| 878 | print 'OLE stream :', stream_path | 899 | print 'OLE stream :', stream_path |
| 879 | print 'VBA filename:', vba_filename | 900 | print 'VBA filename:', vba_filename |
| 880 | print '- '*39 | 901 | print '- '*39 |
| 881 | - print vba_code | 902 | + print filter_vba(vba_code) |
| 882 | else: | 903 | else: |
| 883 | print 'No VBA macros found.' | 904 | print 'No VBA macros found.' |
| 884 | except TypeError: | 905 | except TypeError: |