From 3e9d76313484cb9b419c3657937c0fd62fbfc630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavol=20Plasko=C5=88?= Date: Fri, 12 Apr 2019 12:07:28 +0200 Subject: [PATCH] Fix TypeError in VBA_Parser.analyze_macros() (can't concat bytes to str). Similar to PR #288. `decompress_stream()` yields bytes but vba_code value returned from `extract_macros()` should be AFAIK string in Python 3. --- oletools/olevba.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/oletools/olevba.py b/oletools/olevba.py index 34eedfdb..5ca1334b 100644 --- a/oletools/olevba.py +++ b/oletools/olevba.py @@ -3273,7 +3273,8 @@ def extract_macros(self): compressed_code = data[start:] try: vba_code = decompress_stream(bytearray(compressed_code)) - # TODO vba_code = self.encode_string(vba_code) + encoding = chardet.detect(vba_code)['encoding'] or 'utf-8' + vba_code = bytes2str(vba_code, encoding) yield (self.filename, d.name, d.name, vba_code) except Exception as exc: # display the exception with full stack trace for debugging