diff options
| author | JJTech0130 <jjtech@jjtech.dev> | 2023-06-01 17:42:55 -0400 |
|---|---|---|
| committer | Kyle Martin <krm504@nyu.edu> | 2023-06-02 11:50:05 -0400 |
| commit | 93db2c5ce0419b7bc62e12093907190baca8f30b (patch) | |
| tree | 8140d26ea4b3c67883b01822e9f7859d43c1aeb9 /python/workflow.py | |
| parent | 7b816fc2e285aa9cd77fba33bc55afa16947095f (diff) | |
add AnalysisContext class
Diffstat (limited to 'python/workflow.py')
| -rw-r--r-- | python/workflow.py | 91 |
1 files changed, 91 insertions, 0 deletions
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): """ |
