diff options
| author | KyleMiles <krm504@nyu.edu> | 2021-07-20 16:28:33 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2021-07-26 16:09:18 -0400 |
| commit | d999ff47c7c81030e5c592f93d8a1415de058882 (patch) | |
| tree | 1f8fa0df54d4a3324ebc713179e128b0a662e9d8 /python/mediumlevelil.py | |
| parent | 661d7c953e7a81e82f3eb6a70c03041354d73bfd (diff) | |
Python API : Fix copyright year, add .vars to IL functions, remove BNGetFunctionILVariables, prevent variables without types (from Mapped MLIL) from erroring out in function.Variable's __repr__, added BNGetLowLevel-Registers, RegisterStacks, Flags, MemoryVersions, and their respective SSA versions, added `LowLevelILFunction`- `.vars`, `.ssa_vars`, `.registers`, `.register_stacks`, `.flags`, `.memory_versions` and ssa versions.
Diffstat (limited to 'python/mediumlevelil.py')
| -rw-r--r-- | python/mediumlevelil.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index 93f83d1b..c2e9a5eb 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -20,11 +20,12 @@ import ctypes import struct +from typing import List # Binary Ninja components import binaryninja from binaryninja import _binaryninjacore as core -from binaryninja.enums import MediumLevelILOperation, InstructionTextTokenType, ILBranchDependence, DataFlowQueryOption +from binaryninja.enums import MediumLevelILOperation, FunctionGraphType, ILBranchDependence from binaryninja import basicblock #required for MediumLevelILBasicBlock argument from binaryninja import function from binaryninja import types @@ -1239,6 +1240,51 @@ class MediumLevelILFunction(object): 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, view, handle, owner): |
