summaryrefslogtreecommitdiff
path: root/python/function.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2018-08-29 15:26:00 -0400
committerPeter LaFosse <peter@vector35.com>2018-08-31 14:21:07 -0400
commitf0ccb75e7d80a6c0ae8b01d794b929f03bc6ea6d (patch)
tree7569fe7689062b265329ad0f649705aa8caab922 /python/function.py
parenta6b801afadada75afd2b1779edee8d203f3b3140 (diff)
parent426bb3d8b47b93658bf969c429a8b98adae13c30 (diff)
Merging with dev
Diffstat (limited to 'python/function.py')
-rw-r--r--python/function.py175
1 files changed, 92 insertions, 83 deletions
diff --git a/python/function.py b/python/function.py
index 2f794f47..0589a5e2 100644
--- a/python/function.py
+++ b/python/function.py
@@ -18,27 +18,25 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
+from __future__ import absolute_import
import threading
import traceback
import ctypes
# Binary Ninja components
-import _binaryninjacore as core
-from enums import (AnalysisSkipReason, FunctionGraphType, BranchType, SymbolType, InstructionTextTokenType,
+import binaryninja
+from binaryninja import _binaryninjacore as core
+from binaryninja import associateddatastore # Required in the main scope due to being an argument for _FunctionAssociatedDataStore
+from binaryninja import highlight
+from binaryninja import log
+from binaryninja import types
+from binaryninja.enums import (AnalysisSkipReason, FunctionGraphType, BranchType, SymbolType, InstructionTextTokenType,
HighlightStandardColor, HighlightColorStyle, RegisterValueType, ImplicitRegisterExtend,
DisassemblyOption, IntegerDisplayType, InstructionTextTokenContext, VariableSourceType,
FunctionAnalysisSkipOverride)
-import architecture
-import platform
-import highlight
-import associateddatastore
-import types
-import basicblock
-import lowlevelil
-import mediumlevelil
-import binaryview
-import log
-import callingconvention
+
+# 2-3 compatibility
+from binaryninja import range
class LookupTableEntry(object):
@@ -179,7 +177,7 @@ class PossibleValueSet(object):
elif value.state == RegisterValueType.SignedRangeValue:
self.offset = value.value
self.ranges = []
- for i in xrange(0, value.count):
+ for i in range(0, value.count):
start = value.ranges[i].start
end = value.ranges[i].end
step = value.ranges[i].step
@@ -191,7 +189,7 @@ class PossibleValueSet(object):
elif value.state == RegisterValueType.UnsignedRangeValue:
self.offset = value.value
self.ranges = []
- for i in xrange(0, value.count):
+ for i in range(0, value.count):
start = value.ranges[i].start
end = value.ranges[i].end
step = value.ranges[i].step
@@ -199,15 +197,15 @@ class PossibleValueSet(object):
elif value.state == RegisterValueType.LookupTableValue:
self.table = []
self.mapping = {}
- for i in xrange(0, value.count):
+ for i in range(0, value.count):
from_list = []
- for j in xrange(0, value.table[i].fromCount):
+ for j in range(0, value.table[i].fromCount):
from_list.append(value.table[i].fromValues[j])
self.mapping[value.table[i].fromValues[j]] = value.table[i].toValue
self.table.append(LookupTableEntry(from_list, value.table[i].toValue))
elif (value.state == RegisterValueType.InSetOfValues) or (value.state == RegisterValueType.NotInSetOfValues):
self.values = set()
- for i in xrange(0, value.count):
+ for i in range(0, value.count):
self.values.add(value.valueSet[i])
def __repr__(self):
@@ -420,7 +418,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
@@ -432,7 +430,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
@@ -485,8 +483,8 @@ class Function(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetFunctionBasicBlockList(self.handle, count)
result = []
- for i in xrange(0, count.value):
- result.append(basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i])))
+ for i in range(0, count.value):
+ result.append(binaryninja.basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i])))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -496,7 +494,7 @@ class Function(object):
count = ctypes.c_ulonglong()
addrs = core.BNGetCommentedAddresses(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result[addrs[i]] = self.get_comment_at(addrs[i])
core.BNFreeAddressList(addrs)
return result
@@ -504,17 +502,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):
@@ -531,7 +529,7 @@ class Function(object):
count = ctypes.c_ulonglong()
v = core.BNGetStackLayout(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(Variable(self, v[i].var.type, v[i].var.index, v[i].var.storage, v[i].name,
types.Type(handle = core.BNNewTypeReference(v[i].type), platform = self.platform, confidence = v[i].typeConfidence)))
result.sort(key = lambda x: x.identifier)
@@ -544,7 +542,7 @@ class Function(object):
count = ctypes.c_ulonglong()
v = core.BNGetFunctionVariables(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(Variable(self, v[i].var.type, v[i].var.index, v[i].var.storage, v[i].name,
types.Type(handle = core.BNNewTypeReference(v[i].type), platform = self.platform, confidence = v[i].typeConfidence)))
result.sort(key = lambda x: x.identifier)
@@ -557,8 +555,8 @@ class Function(object):
count = ctypes.c_ulonglong()
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))
+ for i in range(0, count.value):
+ 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
@@ -578,7 +576,7 @@ class Function(object):
count = ctypes.c_ulonglong()
info = core.BNGetFunctionAnalysisPerformanceInfo(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result[info[i].name] = info[i].seconds
core.BNFreeAnalysisPerformanceInfo(info, count.value)
return result
@@ -612,7 +610,7 @@ class Function(object):
"""Registers that are used for the return value"""
result = core.BNGetFunctionReturnRegisters(self.handle)
reg_set = []
- for i in xrange(0, result.count):
+ for i in range(0, result.count):
reg_set.append(self.arch.get_reg_name(result.regs[i]))
regs = types.RegisterSet(reg_set, confidence = result.confidence)
core.BNFreeRegisterSet(result)
@@ -623,7 +621,7 @@ class Function(object):
regs = core.BNRegisterSetWithConfidence()
regs.regs = (ctypes.c_uint * len(value))()
regs.count = len(value)
- for i in xrange(0, len(value)):
+ for i in range(0, len(value)):
regs.regs[i] = self.arch.get_reg_index(value[i])
if hasattr(value, 'confidence'):
regs.confidence = value.confidence
@@ -637,7 +635,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):
@@ -655,7 +653,7 @@ class Function(object):
"""List of variables for the incoming function parameters"""
result = core.BNGetFunctionParameterVariables(self.handle)
var_list = []
- for i in xrange(0, result.count):
+ for i in range(0, result.count):
var_list.append(Variable(self, result.vars[i].type, result.vars[i].index, result.vars[i].storage))
confidence = result.confidence
core.BNFreeParameterVariables(result)
@@ -670,7 +668,7 @@ class Function(object):
var_conf = core.BNParameterVariablesWithConfidence()
var_conf.vars = (core.BNVariable * len(var_list))()
var_conf.count = len(var_list)
- for i in xrange(0, len(var_list)):
+ for i in range(0, len(var_list)):
var_conf.vars[i].type = var_list[i].source_type
var_conf.vars[i].index = var_list[i].index
var_conf.vars[i].storage = var_list[i].storage
@@ -720,7 +718,7 @@ class Function(object):
count = ctypes.c_ulonglong()
adjust = core.BNGetFunctionRegisterStackAdjustments(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = self.arch.get_reg_stack_name(adjust[i].regStack)
value = types.RegisterStackAdjustmentWithConfidence(adjust[i].adjustment,
confidence = adjust[i].confidence)
@@ -748,7 +746,7 @@ class Function(object):
"""Registers that are modified by this function"""
result = core.BNGetFunctionClobberedRegisters(self.handle)
reg_set = []
- for i in xrange(0, result.count):
+ for i in range(0, result.count):
reg_set.append(self.arch.get_reg_name(result.regs[i]))
regs = types.RegisterSet(reg_set, confidence = result.confidence)
core.BNFreeRegisterSet(result)
@@ -759,7 +757,7 @@ class Function(object):
regs = core.BNRegisterSetWithConfidence()
regs.regs = (ctypes.c_uint * len(value))()
regs.count = len(value)
- for i in xrange(0, len(value)):
+ for i in range(0, len(value)):
regs.regs[i] = self.arch.get_reg_index(value[i])
if hasattr(value, 'confidence'):
regs.confidence = value.confidence
@@ -853,8 +851,8 @@ class Function(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetFunctionBasicBlockList(self.handle, count)
try:
- for i in xrange(0, count.value):
- yield basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i]))
+ for i in range(0, count.value):
+ yield binaryninja.basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i]))
finally:
core.BNFreeBasicBlockList(blocks, count.value)
@@ -924,7 +922,7 @@ class Function(object):
count = ctypes.c_ulonglong()
exits = core.BNGetLowLevelILExitsForInstruction(self.handle, arch.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(exits[i])
core.BNFreeILInstructionList(exits)
return result
@@ -936,7 +934,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')
@@ -956,7 +954,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')
@@ -978,7 +976,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
@@ -1023,7 +1021,7 @@ class Function(object):
count = ctypes.c_ulonglong()
regs = core.BNGetRegistersReadByInstruction(self.handle, arch.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(arch.get_reg_name(regs[i]))
core.BNFreeRegisterList(regs)
return result
@@ -1034,7 +1032,7 @@ class Function(object):
count = ctypes.c_ulonglong()
regs = core.BNGetRegistersWrittenByInstruction(self.handle, arch.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(arch.get_reg_name(regs[i]))
core.BNFreeRegisterList(regs)
return result
@@ -1045,7 +1043,7 @@ class Function(object):
count = ctypes.c_ulonglong()
refs = core.BNGetStackVariablesReferencedByInstruction(self.handle, arch.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
var_type = types.Type(core.BNNewTypeReference(refs[i].type), platform = self.platform, confidence = refs[i].typeConfidence)
result.append(StackVariableReference(refs[i].sourceOperand, var_type,
refs[i].name, Variable.from_identifier(self, refs[i].varIdentifier, refs[i].name, var_type),
@@ -1059,7 +1057,7 @@ class Function(object):
count = ctypes.c_ulonglong()
refs = core.BNGetConstantsReferencedByInstruction(self.handle, arch.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(ConstantReference(refs[i].value, refs[i].size, refs[i].pointer, refs[i].intermediate))
core.BNFreeConstantReferenceList(refs)
return result
@@ -1080,7 +1078,7 @@ class Function(object):
count = ctypes.c_ulonglong()
instrs = core.BNGetLiftedILFlagUsesForDefinition(self.handle, i, flag, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(instrs[i])
core.BNFreeILInstructionList(instrs)
return result
@@ -1090,7 +1088,7 @@ class Function(object):
count = ctypes.c_ulonglong()
instrs = core.BNGetLiftedILFlagDefinitionsForUse(self.handle, i, flag, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(instrs[i])
core.BNFreeILInstructionList(instrs)
return result
@@ -1099,7 +1097,7 @@ class Function(object):
count = ctypes.c_ulonglong()
flags = core.BNGetFlagsReadByLiftedILInstruction(self.handle, i, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(self.arch._flags_by_index[flags[i]])
core.BNFreeRegisterList(flags)
return result
@@ -1108,7 +1106,7 @@ class Function(object):
count = ctypes.c_ulonglong()
flags = core.BNGetFlagsWrittenByLiftedILInstruction(self.handle, i, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(self.arch._flags_by_index[flags[i]])
core.BNFreeRegisterList(flags)
return result
@@ -1126,7 +1124,7 @@ class Function(object):
if source_arch is None:
source_arch = self.arch
branch_list = (core.BNArchitectureAndAddress * len(branches))()
- for i in xrange(len(branches)):
+ for i in range(len(branches)):
branch_list[i].arch = branches[i][0].handle
branch_list[i].address = branches[i][1]
core.BNSetAutoIndirectBranches(self.handle, source_arch.handle, source, branch_list, len(branches))
@@ -1135,7 +1133,7 @@ class Function(object):
if source_arch is None:
source_arch = self.arch
branch_list = (core.BNArchitectureAndAddress * len(branches))()
- for i in xrange(len(branches)):
+ for i in range(len(branches)):
branch_list[i].arch = branches[i][0].handle
branch_list[i].address = branches[i][1]
core.BNSetUserIndirectBranches(self.handle, source_arch.handle, source, branch_list, len(branches))
@@ -1146,8 +1144,8 @@ class Function(object):
count = ctypes.c_ulonglong()
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))
+ for i in range(0, count.value):
+ 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
@@ -1157,11 +1155,13 @@ class Function(object):
count = ctypes.c_ulonglong(0)
lines = core.BNGetFunctionBlockAnnotations(self.handle, arch.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
tokens = []
- for j in xrange(0, lines[i].count):
+ for j in range(0, lines[i].count):
token_type = InstructionTextTokenType(lines[i].tokens[j].type)
text = lines[i].tokens[j].text
+ if not isinstance(text, str):
+ text = text.encode("charmap")
value = lines[i].tokens[j].value
size = lines[i].tokens[j].size
operand = lines[i].tokens[j].operand
@@ -1193,7 +1193,7 @@ class Function(object):
regs = core.BNRegisterSetWithConfidence()
regs.regs = (ctypes.c_uint * len(value))()
regs.count = len(value)
- for i in xrange(0, len(value)):
+ for i in range(0, len(value)):
regs.regs[i] = self.arch.get_reg_index(value[i])
if hasattr(value, 'confidence'):
regs.confidence = value.confidence
@@ -1219,7 +1219,7 @@ class Function(object):
var_conf = core.BNParameterVariablesWithConfidence()
var_conf.vars = (core.BNVariable * len(var_list))()
var_conf.count = len(var_list)
- for i in xrange(0, len(var_list)):
+ for i in range(0, len(var_list)):
var_conf.vars[i].type = var_list[i].source_type
var_conf.vars[i].index = var_list[i].index
var_conf.vars[i].storage = var_list[i].storage
@@ -1276,7 +1276,7 @@ class Function(object):
regs = core.BNRegisterSetWithConfidence()
regs.regs = (ctypes.c_uint * len(value))()
regs.count = len(value)
- for i in xrange(0, len(value)):
+ for i in range(0, len(value)):
regs.regs[i] = self.arch.get_reg_index(value[i])
if hasattr(value, 'confidence'):
regs.confidence = value.confidence
@@ -1336,7 +1336,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):
"""
@@ -1464,10 +1464,10 @@ class Function(object):
count = ctypes.c_ulonglong()
lines = core.BNGetFunctionTypeTokens(self.handle, settings, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
addr = lines[i].addr
tokens = []
- for j in xrange(0, lines[i].count):
+ for j in range(0, lines[i].count):
token_type = InstructionTextTokenType(lines[i].tokens[j].type)
text = lines[i].tokens[j].text
value = lines[i].tokens[j].value
@@ -1559,7 +1559,7 @@ class Function(object):
count = ctypes.c_ulonglong()
adjust = core.BNGetCallRegisterStackAdjustment(self.handle, arch.handle, addr, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result[arch.get_reg_stack_name(adjust[i].regStack)] = types.RegisterStackAdjustmentWithConfidence(
adjust[i].adjustment, confidence = adjust[i].confidence)
core.BNFreeRegisterStackAdjustments(adjust)
@@ -1657,17 +1657,17 @@ class FunctionGraphBlock(object):
core.BNFreeBasicBlock(block)
return None
- view = binaryview.BinaryView(handle = core.BNGetFunctionData(func_handle))
+ view = binaryninja.binaryview.BinaryView(handle = core.BNGetFunctionData(func_handle))
func = Function(view, func_handle)
if core.BNIsLowLevelILBasicBlock(block):
- block = lowlevelil.LowLevelILBasicBlock(view, block,
+ block = binaryninja.lowlevelil.LowLevelILBasicBlock(view, block,
lowlevelil.LowLevelILFunction(func.arch, core.BNGetBasicBlockLowLevelILFunction(block), func))
elif core.BNIsMediumLevelILBasicBlock(block):
- block = mediumlevelil.MediumLevelILBasicBlock(view, block,
+ block = binaryninja.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
@@ -1676,7 +1676,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):
@@ -1715,14 +1715,14 @@ class FunctionGraphBlock(object):
lines = core.BNGetFunctionGraphBlockLines(self.handle, count)
block = self.basic_block
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
addr = lines[i].addr
if (lines[i].instrIndex != 0xffffffffffffffff) and hasattr(block, 'il_function'):
il_instr = block.il_function[lines[i].instrIndex]
else:
il_instr = None
tokens = []
- for j in xrange(0, lines[i].count):
+ for j in range(0, lines[i].count):
token_type = InstructionTextTokenType(lines[i].tokens[j].type)
text = lines[i].tokens[j].text
value = lines[i].tokens[j].value
@@ -1742,7 +1742,7 @@ class FunctionGraphBlock(object):
count = ctypes.c_ulonglong()
edges = core.BNGetFunctionGraphBlockOutgoingEdges(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
branch_type = BranchType(edges[i].type)
target = edges[i].target
if target:
@@ -1751,11 +1751,11 @@ 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 = []
- for j in xrange(0, edges[i].pointCount):
+ for j in range(0, edges[i].pointCount):
points.append((edges[i].points[j].x, edges[i].points[j].y))
result.append(FunctionGraphEdge(branch_type, self, target, points, edges[i].backEdge))
core.BNFreeFunctionGraphBlockOutgoingEdgeList(edges, count.value)
@@ -1779,14 +1779,14 @@ class FunctionGraphBlock(object):
lines = core.BNGetFunctionGraphBlockLines(self.handle, count)
block = self.basic_block
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
addr = lines[i].addr
if (lines[i].instrIndex != 0xffffffffffffffff) and hasattr(block, 'il_function'):
il_instr = block.il_function[lines[i].instrIndex]
else:
il_instr = None
tokens = []
- for j in xrange(0, lines[i].count):
+ for j in range(0, lines[i].count):
token_type = InstructionTextTokenType(lines[i].tokens[j].type)
text = lines[i].tokens[j].text
value = lines[i].tokens[j].value
@@ -1838,6 +1838,7 @@ class DisassemblySettings(object):
core.BNSetDisassemblySettingsOption(self.handle, option, state)
+_pending_function_graph_completion_events = {}
class FunctionGraph(object):
def __init__(self, view, handle):
self.view = view
@@ -1883,7 +1884,7 @@ class FunctionGraph(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetFunctionGraphBlocks(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(FunctionGraphBlock(core.BNNewFunctionGraphBlockReference(blocks[i]), self))
core.BNFreeFunctionGraphBlockList(blocks, count.value)
return result
@@ -1941,12 +1942,12 @@ class FunctionGraph(object):
il_func = core.BNGetFunctionGraphLowLevelILFunction(self.handle)
if not il_func:
return None
- return lowlevelil.LowLevelILFunction(self.function.arch, il_func, self.function)
+ return binaryninja.lowlevelil.LowLevelILFunction(self.function.arch, il_func, self.function)
if self.is_medium_level_il:
il_func = core.BNGetFunctionGraphMediumLevelILFunction(self.handle)
if not il_func:
return None
- return mediumlevelil.MediumLevelILFunction(self.function.arch, il_func, self.function)
+ return binaryninja.mediumlevelil.MediumLevelILFunction(self.function.arch, il_func, self.function)
return None
def __setattr__(self, name, value):
@@ -1962,7 +1963,7 @@ class FunctionGraph(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetFunctionGraphBlocks(self.handle, count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield FunctionGraphBlock(core.BNNewFunctionGraphBlockReference(blocks[i]), self)
finally:
core.BNFreeFunctionGraphBlockList(blocks, count.value)
@@ -1971,6 +1972,9 @@ class FunctionGraph(object):
try:
if self._on_complete is not None:
self._on_complete()
+ global _pending_function_graph_completion_events
+ if id(self) in _pending_function_graph_completion_events:
+ del _pending_function_graph_completion_events[id(self)]
except:
log.log_error(traceback.format_exc())
@@ -1995,17 +1999,22 @@ class FunctionGraph(object):
self._wait_cond.release()
def on_complete(self, callback):
+ global _pending_function_graph_completion_events
+ _pending_function_graph_completion_events[id(self)] = self
self._on_complete = callback
core.BNSetFunctionGraphCompleteCallback(self.handle, None, self._cb)
def abort(self):
core.BNAbortFunctionGraph(self.handle)
+ global _pending_function_graph_completion_events
+ if id(self) in _pending_function_graph_completion_events:
+ del _pending_function_graph_completion_events[id(self)]
def get_blocks_in_region(self, left, top, right, bottom):
count = ctypes.c_ulonglong()
blocks = core.BNGetFunctionGraphBlocksInRegion(self.handle, left, top, right, bottom, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(FunctionGraphBlock(core.BNNewFunctionGraphBlockReference(blocks[i]), self))
core.BNFreeFunctionGraphBlockList(blocks, count.value)
return result