Skip to content

Instantly share code, notes, and snippets.

@decalage2
Last active January 30, 2019 06:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decalage2/844ce29eff0ab6e4c799ebf30f27b0f0 to your computer and use it in GitHub Desktop.
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)
# 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