From 93db2c5ce0419b7bc62e12093907190baca8f30b Mon Sep 17 00:00:00 2001 From: JJTech0130 Date: Thu, 1 Jun 2023 17:42:55 -0400 Subject: add AnalysisContext class --- python/workflow.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'python') diff --git a/python/workflow.py b/python/workflow.py index ab885be5..01da17a9 100644 --- a/python/workflow.py +++ b/python/workflow.py @@ -28,8 +28,99 @@ from .log import log_error from . import _binaryninjacore as core from .flowgraph import FlowGraph, CoreFlowGraph +from . import function as _function +from . import lowlevelil +from . import mediumlevelil +from . import highlevelil + ActivityType = Union['Activity', str] +class AnalysisContext: + """ + The ``AnalysisContext`` object is used to represent the current state of analysis for a given function. + It allows direct modification of IL and other analysis information. + """ + + def __init__(self, handle: core.BNAnalysisContextHandle): + assert handle is not None + self.handle = handle + + @property + def function(self) -> '_function.Function': + """ + Function for the current AnalysisContext (read-only) + """ + result = core.BNAnalysisContextGetFunction(self.handle) + if not result: + return None + return _function.Function(result) + + @property + def lifted_il(self) -> lowlevelil.LowLevelILFunction: + """ + LowLevelILFunction used to represent lifted IL (writable) + """ + return self.function.lifted_il + + @lifted_il.setter + def lifted_il(self, lifted_il: lowlevelil.LowLevelILFunction) -> None: + core.BNSetLiftedILFunction(self.handle, lifted_il.handle) + + @property + def llil(self) -> lowlevelil.LowLevelILFunction: + """ + LowLevelILFunction used to represent Low Level IL (writeable) + """ + result = core.BNAnalysisContextGetLowLevelILFunction(self.handle) + if not result: + return None + return lowlevelil.LowLevelILFunction(result) + + @llil.setter + def llil(self, value: lowlevelil.LowLevelILFunction) -> None: + core.BNSetLowLevelILFunction(self.handle, value.handle) + + @property + def mlil(self) -> mediumlevelil.MediumLevelILFunction: + """ + MediumLevelILFunction used to represent Medium Level IL (writeable) + """ + result = core.BNAnalysisContextGetMediumLevelILFunction(self.handle) + if not result: + return None + return mediumlevelil.MediumLevelILFunction(result) + + @mlil.setter + def mlil(self, value: mediumlevelil.MediumLevelILFunction) -> None: + core.BNSetMediumLevelILFunction(self.handle, value.handle) + + @property + def hlil(self) -> highlevelil.HighLevelILFunction: + """ + HighLevelILFunction used to represent High Level IL (writeable) + """ + result = core.BNAnalysisContextGetHighLevelILFunction(self.handle) + if not result: + return None + return highlevelil.HighLevelILFunction(result) + + @hlil.setter + def hlil(self, value: highlevelil.HighLevelILFunction) -> None: + core.BNSetHighLevelILFunction(self.handle, value.handle) + + @property + def basic_blocks(self) -> '_function.BasicBlockList': + """ + function.BasicBlockList of BasicBlocks in the current function (writeable) + """ + return _function.BasicBlockList(self.function) + + @basic_blocks.setter + def basic_blocks(self, value: '_function.BasicBlockList') -> None: + core.BNSetBasicBlockList(self.handle, value._blocks, value._count) + + def inform(self, request: str) -> bool: + return core.BNAnalysisContextInform(self.handle, request) class Activity(object): """ -- cgit v1.3.1