Commit 41a30509f5c8e3708e8a610dac1b2cf3ce3c79b8

Authored by Pavol Plaskoň
1 parent 595e0c5a

Fix AttributeError: 'str' object has no attribute 'decode'.

extract_macros() returns vba_code as bytes or string (string only for
OpenXML/PPT -- open_text() decodes bytes to string).

This way it is already implemented in process_file() and process_file_json().

Sample hash: 586DB43601FB55E89E67DFE569E1E9983779722ED47A8E1F23ADF54D04D3DF4B
Showing 1 changed file with 3 additions and 1 deletions
oletools/olevba3.py
... ... @@ -2878,7 +2878,9 @@ class VBA_Parser(object):
2878 2878 self.vba_code_all_modules = ''
2879 2879 for (_, _, _, vba_code) in self.extract_all_macros():
2880 2880 #TODO: filter code? (each module)
2881   - self.vba_code_all_modules += vba_code.decode('utf-8', 'ignore') + '\n'
  2881 + if isinstance(vba_code, bytes):
  2882 + vba_code = vba_code.decode('utf-8', 'ignore')
  2883 + self.vba_code_all_modules += vba_code + '\n'
2882 2884 for (_, _, form_string) in self.extract_form_strings():
2883 2885 self.vba_code_all_modules += form_string.decode('utf-8', 'ignore') + '\n'
2884 2886 # Analyze the whole code at once:
... ...