From 725878619196187b918c5cf3e6c5350ea889346c Mon Sep 17 00:00:00 2001 From: Yu-Tu <1185575452@qq.com> Date: Tue, 13 Jul 2021 15:05:44 +0800 Subject: [PATCH] add comment delete function --- oletools/mraptor.py | 2 ++ oletools/olevba.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/oletools/mraptor.py b/oletools/mraptor.py index 80cfe351..16d1f4ef 100644 --- a/oletools/mraptor.py +++ b/oletools/mraptor.py @@ -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 diff --git a/oletools/olevba.py b/oletools/olevba.py index 5dd75bbe..1225e981 100644 --- a/oletools/olevba.py +++ b/oletools/olevba.py @@ -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_",