mirror of
https://github.com/mandiant/capa.git
synced 2025-12-05 20:40:05 -08:00
rd: debugging helper formatting
This commit is contained in:
committed by
Willi Ballenthin
parent
6eb55d2f39
commit
8329abd3c8
@@ -105,6 +105,25 @@ class Result:
|
||||
def __nonzero__(self):
|
||||
return self.success
|
||||
|
||||
def __str__(self):
|
||||
# as this object isn't user facing, this formatting is just to help with debugging
|
||||
|
||||
lines = []
|
||||
def rec(m: "Result", indent: int):
|
||||
if isinstance(m.statement, capa.engine.Statement):
|
||||
line = (" " * indent) + str(m.statement.name) + " " + str(m.success)
|
||||
else:
|
||||
line = (" " * indent) + str(m.statement) + " " + str(m.success) + " " + str(m.locations)
|
||||
|
||||
lines.append(line)
|
||||
|
||||
for child in m.children:
|
||||
rec(child, indent + 1)
|
||||
|
||||
rec(self, 0)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
|
||||
class Feature(abc.ABC): # noqa: B024
|
||||
# this is an abstract class, since we don't want anyone to instantiate it directly,
|
||||
|
||||
@@ -474,6 +474,26 @@ class Match(FrozenModel):
|
||||
children=children,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
# as this object isn't user facing, this formatting is just to help with debugging
|
||||
|
||||
lines = []
|
||||
def rec(m: "Match", indent: int):
|
||||
if isinstance(m.node, StatementNode):
|
||||
line = (" " * indent) + str(m.node.statement.type) + " " + str(m.success)
|
||||
elif isinstance(m.node, FeatureNode):
|
||||
line = (" " * indent) + str(m.node.feature) + " " + str(m.success) + " " + str(m.locations)
|
||||
else:
|
||||
raise ValueError("unexpected node type")
|
||||
|
||||
lines.append(line)
|
||||
|
||||
for child in m.children:
|
||||
rec(child, indent + 1)
|
||||
|
||||
rec(self, 0)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def parse_parts_id(s: str):
|
||||
id_ = ""
|
||||
|
||||
Reference in New Issue
Block a user