Commit 26b433902f143b04b86e4ec890d67a928c34dac9

Authored by decalage2
1 parent 539454c9

olevba: backspace characters are displayed in red using colorclass (issue #358)

Showing 1 changed file with 12 additions and 1 deletions
oletools/olevba.py
@@ -279,6 +279,12 @@ except ImportError: @@ -279,6 +279,12 @@ except ImportError:
279 + "see http://codespeak.net/lxml " \ 279 + "see http://codespeak.net/lxml " \
280 + "or http://effbot.org/zone/element-index.htm") 280 + "or http://effbot.org/zone/element-index.htm")
281 281
  282 +import colorclass
  283 +
  284 +# On Windows, colorclass needs to be enabled:
  285 +if os.name == 'nt':
  286 + colorclass.Windows.enable(auto_colors=True)
  287 +
282 288
283 # IMPORTANT: it should be possible to run oletools directly as scripts 289 # IMPORTANT: it should be possible to run oletools directly as scripts
284 # in any directory without installing them with pip or setup.py. 290 # in any directory without installing them with pip or setup.py.
@@ -3236,8 +3242,13 @@ class VBA_Parser_CLI(VBA_Parser): @@ -3236,8 +3242,13 @@ class VBA_Parser_CLI(VBA_Parser):
3236 # check if the VBA code contains special characters such as backspace (issue #358) 3242 # check if the VBA code contains special characters such as backspace (issue #358)
3237 if b'\x08' in vba_code_filtered: 3243 if b'\x08' in vba_code_filtered:
3238 log.warning('The VBA code contains special characters such as backspace, that may be used for obfuscation.') 3244 log.warning('The VBA code contains special characters such as backspace, that may be used for obfuscation.')
  3245 + if sys.stdout.isatty():
  3246 + # if the standard output is the console, we'll display colors
  3247 + backspace = colorclass.Color(b'{autored}\\x08{/red}')
  3248 + else:
  3249 + backspace = b'\\x08'
3239 # replace backspace by "\x08" for display 3250 # replace backspace by "\x08" for display
3240 - vba_code_filtered = vba_code_filtered.replace(b'\x08', b'\\x08') 3251 + vba_code_filtered = vba_code_filtered.replace(b'\x08', backspace)
3241 print(vba_code_filtered) 3252 print(vba_code_filtered)
3242 for (subfilename, stream_path, form_string) in self.extract_form_strings(): 3253 for (subfilename, stream_path, form_string) in self.extract_form_strings():
3243 print('-' * 79) 3254 print('-' * 79)