From 920da93a153ff0e6cff405c76f6d5175a9cbcfa4 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Wed, 23 Jun 2021 11:03:34 -0400 Subject: Convert the following to dataclasses: AddressRange BoolWithConfidence ConstantReference EnumerationMember FunctionParameter ILFlag ILIntrinsic ILRegister ILRegisterStack ILSemanticFlagClass ILSemanticFlagGroup IndirectBranchInfo InstructionBranch InstructionInfo IntrinsicInfo IntrinsicInput LowLevelILExpr LowLevelILOperationAndSize PossibleValueSet RegisterInfo RegisterSet RegisterStackAdjustmentWithConfidence RegisterStackInfo SSAFlag SSARegister SSARegisterOrFlag SSARegisterStack SizeWithConfidence StackVariableReference StructureMember TypeFieldReference TypeParserResult ValueRange BasicBlockEdge --- python/mediumlevelil.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'python/mediumlevelil.py') 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): -- cgit v1.3.1