Skip to content

olevba: detect ANSI escape codes in plain VBA code (fixes #874) - #899

Open
hakarrr wants to merge 3 commits into
decalage2:masterfrom
hakarrr:olevba-ansi-874
Open

hakarrr wants to merge 3 commits into
decalage2:masterfrom
hakarrr:olevba-ansi-874

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 13, 2026

Copy link
Copy Markdown

Fixes #874.

What

olevba now reports ANSI escape sequences (ESC[) found in plain VBA source as suspicious: "May use ANSI escape codes to manipulate console output, which is unusual in VBA code" (new SUSPICIOUS_KEYWORDS_NOREGEX entry).

  • Plain source only: sequences that appear only in deobfuscated content (Base64, Hex, Hex+StrReverse, StrReverse+Hex, Dridex, VBA expressions) are not reported, following the existing backspace guard in detect_suspicious.
  • Display-safe reporting: the reported keyword is rendered as ESC[, so a raw ESC character never reaches reports or the console (complements the display-path sanitization from Prevent parsing of escape characters #873).

Tests

Five new tests in tests/olevba/test_ansi_escape.py: plain-source detection, no raw ESC in the reported keyword, clean-code negative, and Base64/Hex deobfuscation negatives.

Verification

  • python -m unittest discover (the CI command): 94 tests, OK, on Python 3.10.12 with pyparsing 2.4.7 (within the declared range >=2.1.0,<4).
  • pylint -E --ignore=thirdparty oletools tests (the CI lint): clean.
  • With pyparsing 3.3.3 (also within the declared range), unmodified master already shows 3 failures + 1 error (the PyparsingDeprecationWarning output trips the strict output assertions, and test_xlm hits a JSONDecodeError). This change adds none: the failure set is identical with and without the patch.

hakarrr and others added 3 commits November 13, 2026 13:18
Report ANSI escape sequences (ESC[) found in plain VBA source as suspicious, with display-safe reporting (ESC rendered as text). Sequences found only in deobfuscated content are not reported, matching the existing backspace guard.

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Trim the trailing blank line so the file ends exactly like upstream master.

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
…bfuscated content (issue decalage2#874)

Five regression tests: plain-source detection, display-safe keyword (no raw ESC), clean-code negative, and Base64/Hex-deobfuscation negatives matching the backspace guard.

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr

hakarrr commented Nov 13, 2026

Copy link
Copy Markdown
Author

Could a maintainer review this plain-VBA ANSI escape-code detection for #874? Please let me know if the detection approach needs changing or if additional cases are needed before review. Thanks.

@hakarrr

hakarrr commented Nov 16, 2026

Copy link
Copy Markdown
Author

One more follow-up on this. Please let me know if there's a preferred next step, or if anything in the change needs rework - glad to iterate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

olevba - warning when ANSI escape codes are present in VBA code

1 participant