From 79459d4a141d505ff4f22d9c109401e78551aac0 Mon Sep 17 00:00:00 2001 From: William Ballenthin Date: Mon, 14 Jun 2021 09:50:12 -0600 Subject: [PATCH] mypy fixes type checker doesn't like a list that contains tuples with both length 2 and length 3. so keep length constant with None values. --- capa/render/default.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/capa/render/default.py b/capa/render/default.py index 949d33c0..b4ebae6e 100644 --- a/capa/render/default.py +++ b/capa/render/default.py @@ -131,20 +131,18 @@ def render_attack(doc, ostream: StringIO): if attack.get("subtechnique"): tactics[attack["tactic"]].add((attack["technique"], attack["subtechnique"], attack["id"])) else: - tactics[attack["tactic"]].add((attack["technique"], attack["id"])) + tactics[attack["tactic"]].add((attack["technique"], attack["id"], None)) rows = [] for tactic, techniques in sorted(tactics.items()): inner_rows = [] for spec in sorted(techniques): - if len(spec) == 2: - technique, id = spec + if spec[-1] is None: + technique, id, _ = spec inner_rows.append("%s %s" % (rutils.bold(technique), id)) - elif len(spec) == 3: + else: technique, subtechnique, id = spec inner_rows.append("%s::%s %s" % (rutils.bold(technique), subtechnique, id)) - else: - raise RuntimeError("unexpected ATT&CK spec format") rows.append( ( rutils.bold(tactic.upper()), @@ -184,20 +182,18 @@ def render_mbc(doc, ostream: StringIO): if mbc.get("method"): objectives[mbc["objective"]].add((mbc["behavior"], mbc["method"], mbc["id"])) else: - objectives[mbc["objective"]].add((mbc["behavior"], mbc["id"])) + objectives[mbc["objective"]].add((mbc["behavior"], mbc["id"], None)) rows = [] for objective, behaviors in sorted(objectives.items()): inner_rows = [] for spec in sorted(behaviors): - if len(spec) == 2: - behavior, id = spec + if spec[-1] is None: + behavior, id, _ = spec inner_rows.append("%s [%s]" % (rutils.bold(behavior), id)) - elif len(spec) == 3: + else: behavior, method, id = spec inner_rows.append("%s::%s [%s]" % (rutils.bold(behavior), method, id)) - else: - raise RuntimeError("unexpected MBC spec format") rows.append( ( rutils.bold(objective.upper()),