Skip to content

Commit 2c8be1e

Browse files
committed
Optimize printable string detection
1 parent 66acbd4 commit 2c8be1e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

smda/utility/StringExtractor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from smda.common import SmdaFunction
66

7+
_IS_PRINTABLE_CHAR_CODE = tuple(chr(char) in string.printable for char in range(127))
8+
79
# ported back from our PR to capa v4.0.0
810
# https://github.com/mandiant/capa/blob/v4.0.0/capa/features/extractors/smda/insn.py
911

@@ -64,7 +66,7 @@ def detect_ascii_len(smda_report, offset, maxlen=None):
6466
char = smda_report.buffer[rva]
6567
while (
6668
char < 127
67-
and chr(char) in string.printable
69+
and _IS_PRINTABLE_CHAR_CODE[char]
6870
and (maxlen is None or ascii_len < maxlen)
6971
and rva + 1 < len(smda_report.buffer)
7072
):
@@ -87,7 +89,7 @@ def detect_unicode_len(smda_report, offset, maxlen=None):
8789
second_char = smda_report.buffer[rva + 1]
8890
while (
8991
char < 127
90-
and chr(char) in string.printable
92+
and _IS_PRINTABLE_CHAR_CODE[char]
9193
and second_char == 0
9294
and (maxlen is None or unicode_len < 2 * maxlen)
9395
and rva + 3 < len(smda_report.buffer)

0 commit comments

Comments
 (0)