Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add comment delete function #702

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions oletools/mraptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def __init__(self, vba_code):
"""
# collapse long lines first
self.vba_code = olevba.vba_collapse_long_lines(vba_code)
# delete comments
self.vba_code = olevba.vba_delete_comments(vba_code)
self.autoexec = False
self.write = False
self.execute = False
Expand Down
20 changes: 20 additions & 0 deletions oletools/olevba.py
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,26 @@ def vba_collapse_long_lines(vba_code):
return vba_code


def vba_delete_comments(vba_code):
"""
Parse a VBA module code to remove the comments.

:param vba_code: str, VBA module code
:return: str, VBA module code without comments
"""
formit_lines = []
for code_line in vba_code.splitlines():
new_line = ''
for char in code_line:
if char != "'":
new_line += char
else:
break
formit_lines.append(new_line)
vba_code = '\r\n'.join(formit_lines)
return vba_code


def filter_vba(vba_code):
"""
Filter VBA source code to remove the first lines starting with "Attribute VB_",
Expand Down