From 99daa6370d415fbf72247725c75a5f54c958f47a Mon Sep 17 00:00:00 2001 From: Willi Ballenthin Date: Wed, 27 Nov 2024 12:28:02 +0000 Subject: [PATCH] binary ninja: fix computation of call graph --- capa/features/extractors/binja/extractor.py | 2 -- capa/features/extractors/binja/function.py | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/capa/features/extractors/binja/extractor.py b/capa/features/extractors/binja/extractor.py index 568a8e21f..32e1325c6 100644 --- a/capa/features/extractors/binja/extractor.py +++ b/capa/features/extractors/binja/extractor.py @@ -62,8 +62,6 @@ def _build_call_graph(self): f: Function for f in self.bv.functions: for caller in f.callers: - if caller == f: - logger.debug("recursive: 0x%x", f.start) calls_from[caller.start].add(f.start) calls_to[f.start].add(caller.start) diff --git a/capa/features/extractors/binja/function.py b/capa/features/extractors/binja/function.py index 347c2c16e..a2d284ec7 100644 --- a/capa/features/extractors/binja/function.py +++ b/capa/features/extractors/binja/function.py @@ -21,7 +21,7 @@ def extract_function_calls_to(fh: FunctionHandle): func: Function = fh.inner caller: int - for caller in fh.ctx["call_graph"].get("calls_to", []): + for caller in fh.ctx["call_graph"]["calls_to"].get(func.start, []): if caller == func.start: continue @@ -33,7 +33,7 @@ def extract_function_calls_from(fh: FunctionHandle): func: Function = fh.inner callee: int - for callee in fh.ctx["call_graph"].get("calls_from", []): + for callee in fh.ctx["call_graph"]["calls_from"].get(func.start, []): if callee == func.start: continue @@ -60,7 +60,7 @@ def extract_recursive_call(fh: FunctionHandle): func: Function = fh.inner caller: int - for caller in fh.ctx["call_graph"].get("calls_to", []): + for caller in fh.ctx["call_graph"]["calls_to"].get(func.start, []): if caller == func.start: yield Characteristic("recursive call"), fh.address return