summaryrefslogtreecommitdiff
path: root/python/mediumlevelil.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/mediumlevelil.py')
-rw-r--r--python/mediumlevelil.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 61cc420f..fdc4c2e9 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -1265,6 +1265,55 @@ class MediumLevelILFunction(object):
def source_function(self) -> 'function.Function':
return self._source_function
+ @source_function.setter
+ def source_function(self, value):
+ self._source_function = value
+
+ @property
+ def il_form(self) -> "binaryninja.enums.FunctionGraphType":
+ if len(self.basic_blocks) < 1:
+ return FunctionGraphType.InvalidILViewType
+ return FunctionGraphType(core.BNGetBasicBlockFunctionGraphType(self.basic_blocks[0].handle))
+
+ @property
+ def vars(self) -> List["binaryninja.function.Variable"]:
+ """This gets just the MLIL variables - you may be interested in the union of `MediumLevelIlFunction.source_function.param_vars` for all the variables used in the function"""
+ if self.source_function is None:
+ return []
+
+ if self.il_form in [FunctionGraphType.MediumLevelILFunctionGraph, FunctionGraphType.MediumLevelILSSAFormFunctionGraph, FunctionGraphType.MappedMediumLevelILFunctionGraph, FunctionGraphType.MappedMediumLevelILSSAFormFunctionGraph]:
+ count = ctypes.c_ulonglong()
+ core_variables = core.BNGetMediumLevelILVariables(self.handle, count)
+ result = []
+ for var_i in range(count.value):
+ result.append(function.Variable(self.source_function, core_variables[var_i].type, core_variables[var_i].index, core_variables[var_i].storage))
+ core.BNFreeVariableList(core_variables)
+ return result
+ return []
+
+ @property
+ def ssa_vars(self) -> List["binaryninja.mediumlevelil.SSAVariable"]:
+ """This gets just the MLIL SSA variables - you may be interested in the union of `MediumLevelIlFunction.source_function.param_vars` for all the variables used in the function"""
+ if self.source_function is None:
+ return []
+
+ if self.il_form in [FunctionGraphType.MediumLevelILSSAFormFunctionGraph, FunctionGraphType.MappedMediumLevelILSSAFormFunctionGraph]:
+ variable_count = ctypes.c_ulonglong()
+ core_variables = core.BNGetMediumLevelILVariables(self.handle, variable_count)
+ result = []
+ for var_i in range(variable_count.value):
+ version_count = ctypes.c_ulonglong()
+ versions = core.BNGetMediumLevelILVariableSSAVersions(self.handle, core_variables[var_i], version_count)
+
+ for version_i in range(version_count.value):
+ result.append(SSAVariable(function.Variable(self.source_function, core_variables[var_i].type, core_variables[var_i].index, core_variables[var_i].storage), versions[version_i]))
+ core.BNFreeILInstructionList(versions)
+
+ core.BNFreeVariableList(core_variables)
+ return result
+
+ return []
+
class MediumLevelILBasicBlock(basicblock.BasicBlock):
def __init__(self, handle:core.BNBasicBlock, owner:MediumLevelILFunction, view:Optional['binaryview.BinaryView']=None):