diff options
| author | Peter LaFosse <peter@vector35.com> | 2018-03-05 16:09:30 -0500 |
|---|---|---|
| committer | Ryan Snyder <ryan@vector35.com> | 2018-07-10 18:11:08 -0400 |
| commit | d4d1fbb390c9a31045cea8e612c02e242d11c438 (patch) | |
| tree | 11a1fcd229d1efc81440080ae0a26dda67b584f6 /python/function.py | |
| parent | 8849fb2b2b8dc824bd3f17ce1026a04856477a94 (diff) | |
Additional changes for python 2/3 compatibility
Diffstat (limited to 'python/function.py')
| -rw-r--r-- | python/function.py | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/python/function.py b/python/function.py index 2ee9b20d..a0269e75 100644 --- a/python/function.py +++ b/python/function.py @@ -24,13 +24,16 @@ import traceback import ctypes # Binary Ninja components -- additional imports belong in the appropriate class +import binaryninja from binaryninja import _binaryninjacore as core from binaryninja.enums import (AnalysisSkipReason, FunctionGraphType, BranchType, SymbolType, InstructionTextTokenType, HighlightStandardColor, HighlightColorStyle, RegisterValueType, ImplicitRegisterExtend, DisassemblyOption, IntegerDisplayType, InstructionTextTokenContext, VariableSourceType, FunctionAnalysisSkipOverride) from binaryninja import associateddatastore #required in the main scope due to being an argument for _FunctionAssociatedDataStore - +from binaryninja import types +from binaryninja import highlight +from binaryninja import log class LookupTableEntry(object): def __init__(self, from_values, to_value): @@ -42,8 +45,7 @@ class LookupTableEntry(object): class RegisterValue(object): - from binaryninja import types - def __init__(self, arch = None, value = None, confidence = types.max_confidence): + def __init__(self, arch = None, value = None, confidence = binaryninja.types.max_confidence): self.is_constant = False if value is None: self.type = RegisterValueType.UndeterminedValue @@ -321,7 +323,6 @@ class IndirectBranchInfo(object): class ParameterVariables(object): - from binaryninja import types def __init__(self, var_list, confidence = types.max_confidence): self.vars = var_list self.confidence = confidence @@ -348,14 +349,6 @@ class _FunctionAssociatedDataStore(associateddatastore._AssociatedDataStore): class Function(object): - from binaryninja import callingconvention - from binaryninja import mediumlevelil - from binaryninja import lowlevelil - from binaryninja import basicblock - from binaryninja import types - from binaryninja import highlight - from binaryninja import platform - from binaryninja import architecture _associated_data = {} def __init__(self, view, handle): @@ -421,7 +414,7 @@ class Function(object): arch = core.BNGetFunctionArchitecture(self.handle) if arch is None: return None - self._arch = architecture.CoreArchitecture._from_cache(arch) + self._arch = binaryninja.architecture.CoreArchitecture._from_cache(arch) return self._arch @property @@ -433,7 +426,7 @@ class Function(object): plat = core.BNGetFunctionPlatform(self.handle) if plat is None: return None - self._platform = platform.Platform(None, handle = plat) + self._platform = binaryninja.platform.Platform(None, handle = plat) return self._platform @property @@ -487,7 +480,7 @@ class Function(object): blocks = core.BNGetFunctionBasicBlockList(self.handle, count) result = [] for i in xrange(0, count.value): - result.append(basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i]))) + result.append(binaryninja.basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i]))) core.BNFreeBasicBlockList(blocks, count.value) return result @@ -505,17 +498,17 @@ class Function(object): @property def low_level_il(self): """returns LowLevelILFunction used to represent Function low level IL (read-only)""" - return lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLowLevelIL(self.handle), self) + return binaryninja.lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLowLevelIL(self.handle), self) @property def lifted_il(self): """returns LowLevelILFunction used to represent lifted IL (read-only)""" - return lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLiftedIL(self.handle), self) + return binaryninja.lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLiftedIL(self.handle), self) @property def medium_level_il(self): """Function medium level IL (read-only)""" - return mediumlevelil.MediumLevelILFunction(self.arch, core.BNGetFunctionMediumLevelIL(self.handle), self) + return binaryninja.mediumlevelil.MediumLevelILFunction(self.arch, core.BNGetFunctionMediumLevelIL(self.handle), self) @property def function_type(self): @@ -559,7 +552,7 @@ class Function(object): branches = core.BNGetIndirectBranches(self.handle, count) result = [] for i in xrange(0, count.value): - result.append(IndirectBranchInfo(architecture.CoreArchitecture._from_cache(branches[i].sourceArch), branches[i].sourceAddr, architecture.CoreArchitecture._from_cache(branches[i].destArch), branches[i].destAddr, branches[i].autoDefined)) + result.append(IndirectBranchInfo(binaryninja.architecture.CoreArchitecture._from_cache(branches[i].sourceArch), branches[i].sourceAddr, binaryninja.architecture.CoreArchitecture._from_cache(branches[i].destArch), branches[i].destAddr, branches[i].autoDefined)) core.BNFreeIndirectBranchList(branches) return result @@ -638,7 +631,7 @@ class Function(object): result = core.BNGetFunctionCallingConvention(self.handle) if not result.convention: return None - return callingconvention.CallingConvention(None, handle = result.convention, confidence = result.confidence) + return binaryninja.callingconvention.CallingConvention(None, handle = result.convention, confidence = result.confidence) @calling_convention.setter def calling_convention(self, value): @@ -855,7 +848,7 @@ class Function(object): blocks = core.BNGetFunctionBasicBlockList(self.handle, count) try: for i in xrange(0, count.value): - yield basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i])) + yield binaryninja.basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i])) finally: core.BNFreeBasicBlockList(blocks, count.value) @@ -937,7 +930,7 @@ class Function(object): :param int addr: virtual address of the instruction to query :param str reg: string value of native register to query :param Architecture arch: (optional) Architecture for the given function - :rtype: function.RegisterValue + :rtype: binaryninja.function.RegisterValue :Example: >>> func.get_reg_value_at(0x400dbe, 'rdi') @@ -957,7 +950,7 @@ class Function(object): :param int addr: virtual address of the instruction to query :param str reg: string value of native register to query :param Architecture arch: (optional) Architecture for the given function - :rtype: function.RegisterValue + :rtype: binaryninja.function.RegisterValue :Example: >>> func.get_reg_value_after(0x400dbe, 'rdi') @@ -979,7 +972,7 @@ class Function(object): :param int offset: stack offset base of stack :param int size: size of memory to query :param Architecture arch: (optional) Architecture for the given function - :rtype: function.RegisterValue + :rtype: binaryninja.function.RegisterValue .. note:: Stack base is zero on entry into the function unless the architecture places the return address on the stack as in (x86/x86_64) where the stack base will start at address_size @@ -1148,7 +1141,7 @@ class Function(object): branches = core.BNGetIndirectBranchesAt(self.handle, arch.handle, addr, count) result = [] for i in xrange(0, count.value): - result.append(IndirectBranchInfo(architecture.CoreArchitecture._from_cache(branches[i].sourceArch), branches[i].sourceAddr, architecture.CoreArchitecture._from_cache(branches[i].destArch), branches[i].destAddr, branches[i].autoDefined)) + result.append(IndirectBranchInfo(binaryninja.architecture.CoreArchitecture._from_cache(branches[i].sourceArch), branches[i].sourceAddr, binaryninja.architecture.CoreArchitecture._from_cache(branches[i].destArch), branches[i].destAddr, branches[i].autoDefined)) core.BNFreeIndirectBranchList(branches) return result @@ -1337,7 +1330,7 @@ class Function(object): block = core.BNGetFunctionBasicBlockAtAddress(self.handle, arch.handle, addr) if not block: return None - return basicblock.BasicBlock(self._view, handle = block) + return binaryninja.basicblock.BasicBlock(self._view, handle = block) def get_instr_highlight(self, addr, arch=None): """ @@ -1633,7 +1626,6 @@ class FunctionGraphEdge(object): class FunctionGraphBlock(object): def __init__(self, handle): - from binaryninja import binaryview self.handle = handle self.graph = graph @@ -1669,7 +1661,7 @@ class FunctionGraphBlock(object): block = mediumlevelil.MediumLevelILBasicBlock(view, block, mediumlevelil.MediumLevelILFunction(func.arch, core.BNGetBasicBlockMediumLevelILFunction(block), func)) else: - block = basicblock.BasicBlock(view, block) + block = binaryninja.basicblock.BasicBlock(view, block) return block @property @@ -1678,7 +1670,7 @@ class FunctionGraphBlock(object): arch = core.BNGetFunctionGraphBlockArchitecture(self.handle) if arch is None: return None - return architecture.CoreArchitecture._from_cache(arch) + return binaryninja.architecture.CoreArchitecture._from_cache(arch) @property def start(self): @@ -1753,7 +1745,7 @@ class FunctionGraphBlock(object): core.BNFreeBasicBlock(target) target = None else: - target = basicblock.BasicBlock(binaryview.BinaryView(handle = core.BNGetFunctionData(func)), + target = binaryninja.basicblock.BasicBlock(binaryninja.binaryview.BinaryView(handle = core.BNGetFunctionData(func)), core.BNNewBasicBlockReference(target)) core.BNFreeFunction(func) points = [] @@ -1841,8 +1833,6 @@ class DisassemblySettings(object): class FunctionGraph(object): - from binaryninja import log - from binaryninja import types def __init__(self, view, handle): self.view = view self.handle = handle @@ -2144,7 +2134,6 @@ class InstructionTextToken(object): ========================== ============================================ """ - from binaryninja import types def __init__(self, token_type, text, value = 0, size = 0, operand = 0xffffffff, context = InstructionTextTokenContext.NoTokenContext, address = 0, confidence = types.max_confidence): self.type = InstructionTextTokenType(token_type) |
