render: capture and display matched regex string

This commit is contained in:
William Ballenthin
2020-06-28 09:19:53 -06:00
parent 50dc945103
commit bdc635a0f9
2 changed files with 6 additions and 1 deletions

View File

@@ -46,6 +46,8 @@ def convert_statement_to_result_document(statement):
return {
'type': 'regex',
'pattern': statement.pattern,
# the string that was matched
'match': statement.match,
}
elif isinstance(statement, capa.engine.Subscope):
return {

View File

@@ -23,7 +23,10 @@ def render_statement(ostream, statement, indent=0):
ostream.write(statement['subscope'])
ostream.writeln(':')
elif statement['type'] == 'regex':
ostream.writeln('string: /%s/' % (statement['pattern']))
# regex is a `Statement` not a `Feature`
# this is because it doesn't get extracted, but applies to all strings in scope.
# so we have to handle it here
ostream.writeln('string: %s' % (statement['match']))
else:
raise RuntimeError("unexpected match statement type: " + str(statement))