Last active
January 30, 2019 06:53
-
-
Save decalage2/844ce29eff0ab6e4c799ebf30f27b0f0 to your computer and use it in GitHub Desktop.
Quick example showing how to extract VBA macros to files using olevba (Python 2 or 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quick example showing how to extract VBA macros to files using olevba | |
# works with python 2 or 3 | |
# ref: https://github.com/decalage2/oletools/wiki/olevba#extract-vba-macro-source-code | |
import sys | |
if sys.version_info[0] <= 2: | |
# Python 2.x | |
from oletools.olevba import VBA_Parser | |
else: | |
# Python 3.x | |
from oletools.olevba3 import VBA_Parser | |
vbaparser = VBA_Parser(sys.argv[1]) | |
for (filename, stream_path, vba_filename, vba_code) in vbaparser.extract_macros(): | |
print('-'*79) | |
print('Filename: %s' % filename) | |
print('OLE stream: %s' % stream_path) | |
print('VBA filename: %s' % vba_filename) | |
with open(vba_filename, 'wb') as f: | |
f.write(vba_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment