From 5de327770ec8c3f1aca9c774d850442edb9a3610 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Fri, 5 Apr 2019 21:53:36 -0400 Subject: Add callee/caller properties to function objects --- python/function.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'python/function.py') diff --git a/python/function.py b/python/function.py index 14e140c1..c33ac97f 100644 --- a/python/function.py +++ b/python/function.py @@ -33,7 +33,7 @@ from binaryninja import types from binaryninja.enums import (AnalysisSkipReason, FunctionGraphType, BranchType, SymbolType, InstructionTextTokenType, HighlightStandardColor, HighlightColorStyle, RegisterValueType, ImplicitRegisterExtend, DisassemblyOption, IntegerDisplayType, InstructionTextTokenContext, VariableSourceType, - FunctionAnalysisSkipOverride) + FunctionAnalysisSkipOverride, MediumLevelILOperation) # 2-3 compatibility from binaryninja import range @@ -1600,6 +1600,35 @@ class Function(object): core.BNRequestFunctionDebugReport(self.handle, name) self.view.update_analysis() + @property + def callees(self): + called = [] + for bb in self.medium_level_il: + for i in bb: + if i.operation in (MediumLevelILOperation.MLIL_CALL, MediumLevelILOperation.MLIL_CALL_UNTYPED): + if i.dest.value.type == RegisterValueType.ConstantPointerValue: + func = self.view.get_function_at(i.dest.value.value, self.platform) + if func is not None: + called.append(func) + return called + + @property + def callee_addresses(self): + called = [] + for bb in self.medium_level_il: + for i in bb: + if i.operation in (MediumLevelILOperation.MLIL_CALL, MediumLevelILOperation.MLIL_CALL_UNTYPED): + if i.dest.value.type == RegisterValueType.ConstantPointerValue: + called.append(i.dest.value.value) + return called + + @property + def callers(self): + functions = [] + for ref in self.view.get_code_refs(self.start): + if ref.function is not None: + functions.append(ref.function) + return functions class AdvancedFunctionAnalysisDataRequestor(object): def __init__(self, func = None): -- cgit v1.3.1