summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJordan Wiens <jordan@psifertex.com>2018-05-29 14:32:08 -0400
committerRyan Snyder <ryan@vector35.com>2018-07-10 18:11:08 -0400
commit1c03ac08aa94f5bedf21ec8f48ee1ec998e0e50c (patch)
tree0c10026079b3f0a50affb6b5d42cc3684056e5fc /python
parentd4d1fbb390c9a31045cea8e612c02e242d11c438 (diff)
addition 3 compatibility changes
Diffstat (limited to 'python')
-rw-r--r--python/__init__.py8
-rw-r--r--python/architecture.py96
-rw-r--r--python/basicblock.py22
-rw-r--r--python/binaryview.py53
-rw-r--r--python/callingconvention.py20
-rw-r--r--python/demangle.py7
-rw-r--r--python/function.py100
-rw-r--r--python/generator.cpp45
-rw-r--r--python/interaction.py19
-rw-r--r--python/lowlevelil.py39
-rw-r--r--python/mediumlevelil.py33
-rw-r--r--python/metadata.py9
-rw-r--r--python/platform.py35
-rw-r--r--python/plugin.py9
-rw-r--r--python/pluginmanager.py8
-rw-r--r--python/scriptingprovider.py7
-rw-r--r--python/setting.py11
-rw-r--r--python/transform.py17
-rw-r--r--python/types.py23
-rw-r--r--python/update.py11
20 files changed, 325 insertions, 247 deletions
diff --git a/python/__init__.py b/python/__init__.py
index d88703cc..a3ba0453 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -118,8 +118,10 @@ class PluginManagerLoadPluginCallback(object):
def __init__(self):
self.cb = ctypes.CFUNCTYPE(
ctypes.c_bool,
- ctypes.c_char_p,
- ctypes.c_char_p,
+ core.compatstring,
+ core.compatstring,
+ # ctypes.c_char_p,
+ # ctypes.c_char_p,
ctypes.c_void_p)(self._load_plugin)
def _load_plugin(self, repo_path, plugin_path, ctx):
@@ -147,7 +149,7 @@ class PluginManagerLoadPluginCallback(object):
load_plugin = PluginManagerLoadPluginCallback()
-core.BNRegisterForPluginLoading(_plugin_api_name.encode("utf8"), load_plugin.cb, 0)
+core.BNRegisterForPluginLoading(_plugin_api_name, load_plugin.cb, 0)
class _DestructionCallbackHandler(object):
diff --git a/python/architecture.py b/python/architecture.py
index a705f2d9..b99da184 100644
--- a/python/architecture.py
+++ b/python/architecture.py
@@ -38,7 +38,7 @@ from binaryninja import callingconvention
# 2-3 compatibility
from six import with_metaclass
-
+from six.moves import range
class _ArchitectureMetaClass(type):
@@ -48,7 +48,7 @@ class _ArchitectureMetaClass(type):
count = ctypes.c_ulonglong()
archs = core.BNGetArchitectureList(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(CoreArchitecture._from_cache(archs[i]))
core.BNFreeArchitectureList(archs)
return result
@@ -58,7 +58,7 @@ class _ArchitectureMetaClass(type):
count = ctypes.c_ulonglong()
archs = core.BNGetArchitectureList(count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield CoreArchitecture._from_cache(archs[i])
finally:
core.BNFreeArchitectureList(archs)
@@ -369,7 +369,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
for intrinsic in self.__class__.intrinsics.keys():
if intrinsic not in self._intrinsics:
info = self.__class__.intrinsics[intrinsic]
- for i in xrange(0, len(info.inputs)):
+ for i in range(0, len(info.inputs)):
if isinstance(info.inputs[i], types.Type):
info.inputs[i] = binaryninja.function.IntrinsicInput(info.inputs[i])
elif isinstance(info.inputs[i], tuple):
@@ -406,7 +406,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
count = ctypes.c_ulonglong()
regs = core.BNGetFullWidthArchitectureRegisters(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(core.BNGetArchitectureRegisterName(self.handle, regs[i]))
core.BNFreeRegisterList(regs)
return result
@@ -417,7 +417,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
count = ctypes.c_ulonglong()
cc = core.BNGetArchitectureCallingConventions(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
obj = callingconvention.CallingConvention(handle=core.BNNewCallingConventionReference(cc[i]))
result[obj.name] = obj
core.BNFreeCallingConventionList(cc, count)
@@ -508,7 +508,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
result[0].archTransitionByTargetAddr = info.arch_transition_by_target_addr
result[0].branchDelay = info.branch_delay
result[0].branchCount = len(info.branches)
- for i in xrange(0, len(info.branches)):
+ for i in range(0, len(info.branches)):
if isinstance(info.branches[i].type, str):
result[0].branchType[i] = BranchType[info.branches[i].type]
else:
@@ -534,7 +534,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
length[0] = info[1]
count[0] = len(tokens)
token_buf = (core.BNInstructionTextToken * len(tokens))()
- for i in xrange(0, len(tokens)):
+ for i in range(0, len(tokens)):
if isinstance(tokens[i].type, str):
token_buf[i].type = InstructionTextTokenType[tokens[i].type]
else:
@@ -627,7 +627,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
regs = self._full_width_regs.values()
count[0] = len(regs)
reg_buf = (ctypes.c_uint * len(regs))()
- for i in xrange(0, len(regs)):
+ for i in range(0, len(regs)):
reg_buf[i] = regs[i]
result = ctypes.cast(reg_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, reg_buf)
@@ -642,7 +642,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
regs = self._regs_by_index.keys()
count[0] = len(regs)
reg_buf = (ctypes.c_uint * len(regs))()
- for i in xrange(0, len(regs)):
+ for i in range(0, len(regs)):
reg_buf[i] = regs[i]
result = ctypes.cast(reg_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, reg_buf)
@@ -657,7 +657,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
flags = self._flags_by_index.keys()
count[0] = len(flags)
flag_buf = (ctypes.c_uint * len(flags))()
- for i in xrange(0, len(flags)):
+ for i in range(0, len(flags)):
flag_buf[i] = flags[i]
result = ctypes.cast(flag_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, flag_buf)
@@ -672,7 +672,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
write_types = self._flag_write_types_by_index.keys()
count[0] = len(write_types)
type_buf = (ctypes.c_uint * len(write_types))()
- for i in xrange(0, len(write_types)):
+ for i in range(0, len(write_types)):
type_buf[i] = write_types[i]
result = ctypes.cast(type_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, type_buf)
@@ -687,7 +687,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
sem_classes = self._semantic_flag_classes_by_index.keys()
count[0] = len(sem_classes)
class_buf = (ctypes.c_uint * len(sem_classes))()
- for i in xrange(0, len(sem_classes)):
+ for i in range(0, len(sem_classes)):
class_buf[i] = sem_classes[i]
result = ctypes.cast(class_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, class_buf)
@@ -702,7 +702,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
sem_groups = self._semantic_flag_groups_by_index.keys()
count[0] = len(sem_groups)
group_buf = (ctypes.c_uint * len(sem_groups))()
- for i in xrange(0, len(sem_groups)):
+ for i in range(0, len(sem_groups)):
group_buf[i] = sem_groups[i]
result = ctypes.cast(group_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, group_buf)
@@ -735,7 +735,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
flags.append(self._flags[name])
count[0] = len(flags)
flag_buf = (ctypes.c_uint * len(flags))()
- for i in xrange(0, len(flags)):
+ for i in range(0, len(flags)):
flag_buf[i] = flags[i]
result = ctypes.cast(flag_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, flag_buf)
@@ -753,7 +753,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
flags = []
count[0] = len(flags)
flag_buf = (ctypes.c_uint * len(flags))()
- for i in xrange(0, len(flags)):
+ for i in range(0, len(flags)):
flag_buf[i] = flags[i]
result = ctypes.cast(flag_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, flag_buf)
@@ -801,7 +801,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
flags = []
count[0] = len(flags)
flag_buf = (ctypes.c_uint * len(flags))()
- for i in xrange(0, len(flags)):
+ for i in range(0, len(flags)):
flag_buf[i] = flags[i]
result = ctypes.cast(flag_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, flag_buf)
@@ -828,7 +828,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
write_type_name = self._flag_write_types_by_index[write_type]
flag_name = self._flags_by_index[flag]
operand_list = []
- for i in xrange(operand_count):
+ for i in range(operand_count):
if operands[i].constant:
operand_list.append(operands[i].value)
elif lowlevelil.LLIL_REG_IS_TEMP(operands[i].reg):
@@ -917,7 +917,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
try:
count[0] = len(self.global_regs)
reg_buf = (ctypes.c_uint * len(self.global_regs))()
- for i in xrange(0, len(self.global_regs)):
+ for i in range(0, len(self.global_regs)):
reg_buf[i] = self._all_regs[self.global_regs[i]]
result = ctypes.cast(reg_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, reg_buf)
@@ -941,7 +941,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
regs = self._reg_stacks_by_index.keys()
count[0] = len(regs)
reg_buf = (ctypes.c_uint * len(regs))()
- for i in xrange(0, len(regs)):
+ for i in range(0, len(regs)):
reg_buf[i] = regs[i]
result = ctypes.cast(reg_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, reg_buf)
@@ -992,7 +992,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
regs = self._intrinsics_by_index.keys()
count[0] = len(regs)
reg_buf = (ctypes.c_uint * len(regs))()
- for i in xrange(0, len(regs)):
+ for i in range(0, len(regs)):
reg_buf[i] = regs[i]
result = ctypes.cast(reg_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, reg_buf)
@@ -1008,7 +1008,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
inputs = self._intrinsics_by_index[intrinsic][1].inputs
count[0] = len(inputs)
input_buf = (core.BNNameAndType * len(inputs))()
- for i in xrange(0, len(inputs)):
+ for i in range(0, len(inputs)):
input_buf[i].name = inputs[i].name
input_buf[i].type = core.BNNewTypeReference(inputs[i].type.handle)
input_buf[i].typeConfidence = inputs[i].type.confidence
@@ -1029,7 +1029,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
raise ValueError("freeing name and type list that wasn't allocated")
name_and_types = self._pending_name_and_type_lists[buf.value][1]
count = self._pending_name_and_type_lists[buf.value][2]
- for i in xrange(0, count):
+ for i in range(0, count):
core.BNFreeType(name_and_types[i].type)
del self._pending_name_and_type_lists[buf.value]
except (ValueError, KeyError):
@@ -1041,7 +1041,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
outputs = self._intrinsics_by_index[intrinsic][1].outputs
count[0] = len(outputs)
output_buf = (core.BNTypeWithConfidence * len(outputs))()
- for i in xrange(0, len(outputs)):
+ for i in range(0, len(outputs)):
output_buf[i].type = core.BNNewTypeReference(outputs[i].handle)
output_buf[i].confidence = outputs[i].confidence
result = ctypes.cast(output_buf, ctypes.c_void_p)
@@ -1061,7 +1061,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
raise ValueError("freeing type list that wasn't allocated")
types = self._pending_type_lists[buf.value][1]
count = self._pending_type_lists[buf.value][2]
- for i in xrange(0, count):
+ for i in range(0, count):
core.BNFreeType(types[i].type)
del self._pending_type_lists[buf.value]
except (ValueError, KeyError):
@@ -1710,7 +1710,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
:rtype: LowLevelILExpr index
"""
operand_list = (core.BNRegisterOrConstant * len(operands))()
- for i in xrange(len(operands)):
+ for i in range(len(operands)):
if isinstance(operands[i], str):
operand_list[i].constant = False
operand_list[i].reg = self.regs[operands[i]].index
@@ -1765,7 +1765,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
count = ctypes.c_ulonglong()
regs = core.BNGetModifiedArchitectureRegistersOnWrite(self.handle, reg, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(core.BNGetArchitectureRegisterName(self.handle, regs[i]))
core.BNFreeRegisterList(regs)
return result
@@ -2074,7 +2074,7 @@ class CoreArchitecture(Architecture):
self._regs_by_index = {}
self._full_width_regs = {}
self.__dict__["regs"] = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = core.BNGetArchitectureRegisterName(self.handle, regs[i])
info = core.BNGetArchitectureRegisterInfo(self.handle, regs[i])
full_width_reg = core.BNGetArchitectureRegisterName(self.handle, info.fullWidthRegister)
@@ -2082,7 +2082,7 @@ class CoreArchitecture(Architecture):
ImplicitRegisterExtend(info.extend), regs[i])
self._all_regs[name] = regs[i]
self._regs_by_index[regs[i]] = name
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
info = core.BNGetArchitectureRegisterInfo(self.handle, regs[i])
full_width_reg = core.BNGetArchitectureRegisterName(self.handle, info.fullWidthRegister)
if full_width_reg not in self._full_width_regs:
@@ -2094,7 +2094,7 @@ class CoreArchitecture(Architecture):
self._flags = {}
self._flags_by_index = {}
self.__dict__["flags"] = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = core.BNGetArchitectureFlagName(self.handle, flags[i])
self._flags[name] = flags[i]
self._flags_by_index[flags[i]] = name
@@ -2106,7 +2106,7 @@ class CoreArchitecture(Architecture):
self._flag_write_types = {}
self._flag_write_types_by_index = {}
self.__dict__["flag_write_types"] = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = core.BNGetArchitectureFlagWriteTypeName(self.handle, write_types[i])
self._flag_write_types[name] = write_types[i]
self._flag_write_types_by_index[write_types[i]] = name
@@ -2118,7 +2118,7 @@ class CoreArchitecture(Architecture):
self._semantic_flag_classes = {}
self._semantic_flag_classes_by_index = {}
self.__dict__["semantic_flag_classes"] = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = core.BNGetArchitectureSemanticFlagClassName(self.handle, sem_classes[i])
self._semantic_flag_classes[name] = sem_classes[i]
self._semantic_flag_classes_by_index[sem_classes[i]] = name
@@ -2130,7 +2130,7 @@ class CoreArchitecture(Architecture):
self._semantic_flag_groups = {}
self._semantic_flag_groups_by_index = {}
self.__dict__["semantic_flag_groups"] = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = core.BNGetArchitectureSemanticFlagGroupName(self.handle, sem_groups[i])
self._semantic_flag_groups[name] = sem_groups[i]
self._semantic_flag_groups_by_index[sem_groups[i]] = name
@@ -2149,7 +2149,7 @@ class CoreArchitecture(Architecture):
count = ctypes.c_ulonglong()
flags = core.BNGetArchitectureFlagsRequiredForFlagCondition(self.handle, cond, 0, count)
flag_names = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
flag_names.append(self._flags_by_index[flags[i]])
core.BNFreeRegisterList(flags)
self.__dict__["flags_required_for_flag_condition"][cond] = flag_names
@@ -2162,7 +2162,7 @@ class CoreArchitecture(Architecture):
self._semantic_flag_groups[group], count)
flag_indexes = []
flag_names = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
flag_indexes.append(flags[i])
flag_names.append(self._flags_by_index[flags[i]])
core.BNFreeRegisterList(flags)
@@ -2177,7 +2177,7 @@ class CoreArchitecture(Architecture):
self._semantic_flag_groups[group], count)
class_index_cond = {}
class_cond = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
class_index_cond[conditions[i].semanticClass] = conditions[i].condition
if conditions[i].semanticClass == 0:
class_cond[None] = conditions[i].condition
@@ -2195,7 +2195,7 @@ class CoreArchitecture(Architecture):
self._flag_write_types[write_type], count)
flag_indexes = []
flag_names = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
flag_indexes.append(flags[i])
flag_names.append(self._flags_by_index[flags[i]])
core.BNFreeRegisterList(flags)
@@ -2217,7 +2217,7 @@ class CoreArchitecture(Architecture):
count = ctypes.c_ulonglong()
regs = core.BNGetArchitectureGlobalRegisters(self.handle, count)
self.__dict__["global_regs"] = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
self.global_regs.append(core.BNGetArchitectureRegisterName(self.handle, regs[i]))
core.BNFreeRegisterList(regs)
@@ -2226,14 +2226,14 @@ class CoreArchitecture(Architecture):
self._all_reg_stacks = {}
self._reg_stacks_by_index = {}
self.__dict__["reg_stacks"] = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = core.BNGetArchitectureRegisterStackName(self.handle, regs[i])
info = core.BNGetArchitectureRegisterStackInfo(self.handle, regs[i])
storage = []
- for j in xrange(0, info.storageCount):
+ for j in range(0, info.storageCount):
storage.append(core.BNGetArchitectureRegisterName(self.handle, info.firstStorageReg + j))
top_rel = []
- for j in xrange(0, info.topRelativeCount):
+ for j in range(0, info.topRelativeCount):
top_rel.append(core.BNGetArchitectureRegisterName(self.handle, info.firstTopRelativeReg + j))
top = core.BNGetArchitectureRegisterName(self.handle, info.stackTopReg)
self.reg_stacks[name] = binaryninja.function.RegisterStackInfo(storage, top_rel, top, regs[i])
@@ -2246,12 +2246,12 @@ class CoreArchitecture(Architecture):
self._intrinsics = {}
self._intrinsics_by_index = {}
self.__dict__["intrinsics"] = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = core.BNGetArchitectureIntrinsicName(self.handle, intrinsics[i])
input_count = ctypes.c_ulonglong()
inputs = core.BNGetArchitectureIntrinsicInputs(self.handle, intrinsics[i], input_count)
input_list = []
- for j in xrange(0, input_count.value):
+ for j in range(0, input_count.value):
input_name = inputs[j].name
type_obj = types.Type(core.BNNewTypeReference(inputs[j].type), confidence = inputs[j].typeConfidence)
input_list.append(binaryninja.function.IntrinsicInput(type_obj, input_name))
@@ -2259,7 +2259,7 @@ class CoreArchitecture(Architecture):
output_count = ctypes.c_ulonglong()
outputs = core.BNGetArchitectureIntrinsicOutputs(self.handle, intrinsics[i], output_count)
output_list = []
- for j in xrange(0, output_count.value):
+ for j in range(0, output_count.value):
output_list.append(types.Type(core.BNNewTypeReference(outputs[j].type), confidence = outputs[j].confidence))
core.BNFreeOutputTypeList(outputs, output_count.value)
self.intrinsics[name] = binaryninja.function.IntrinsicInfo(input_list, output_list)
@@ -2303,7 +2303,7 @@ class CoreArchitecture(Architecture):
result.length = info.length
result.arch_transition_by_target_addr = info.archTransitionByTargetAddr
result.branch_delay = info.branchDelay
- for i in xrange(0, info.branchCount):
+ for i in range(0, info.branchCount):
target = info.branchTarget[i]
if info.branchArch[i]:
arch = CoreArchitecture._from_cache(info.branchArch[i])
@@ -2332,7 +2332,7 @@ class CoreArchitecture(Architecture):
if not core.BNGetInstructionText(self.handle, buf, addr, length, tokens, count):
return None, 0
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
token_type = InstructionTextTokenType(tokens[i].type)
text = tokens[i].text
value = tokens[i].value
@@ -2379,7 +2379,7 @@ class CoreArchitecture(Architecture):
"""
flag = self.get_flag_index(flag)
operand_list = (core.BNRegisterOrConstant * len(operands))()
- for i in xrange(len(operands)):
+ for i in range(len(operands)):
if isinstance(operands[i], str):
operand_list[i].constant = False
operand_list[i].reg = self.regs[operands[i]].index
@@ -2664,7 +2664,7 @@ class CoreArchitecture(Architecture):
count = ctypes.c_ulonglong()
flags = core.BNGetArchitectureFlagsRequiredForFlagCondition(self.handle, cond, sem_class, count)
flag_names = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
flag_names.append(self._flags_by_index[flags[i]])
core.BNFreeRegisterList(flags)
return flag_names
diff --git a/python/basicblock.py b/python/basicblock.py
index ee754863..b1f95ba3 100644
--- a/python/basicblock.py
+++ b/python/basicblock.py
@@ -26,6 +26,8 @@ from binaryninja import highlight
from binaryninja import _binaryninjacore as core
from binaryninja.enums import BranchType, HighlightColorStyle, HighlightStandardColor, InstructionTextTokenType
+# 2-3 compatibility
+from six.moves import range
class BasicBlockEdge(object):
def __init__(self, branch_type, source, target, back_edge):
@@ -128,7 +130,7 @@ class BasicBlock(object):
count = ctypes.c_ulonglong(0)
edges = core.BNGetBasicBlockOutgoingEdges(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
branch_type = BranchType(edges[i].type)
if edges[i].target:
target = self._create_instance(self.view, core.BNNewBasicBlockReference(edges[i].target))
@@ -144,7 +146,7 @@ class BasicBlock(object):
count = ctypes.c_ulonglong(0)
edges = core.BNGetBasicBlockIncomingEdges(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
branch_type = BranchType(edges[i].type)
if edges[i].target:
target = self._create_instance(self.view, core.BNNewBasicBlockReference(edges[i].target))
@@ -170,7 +172,7 @@ class BasicBlock(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetBasicBlockDominators(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(self._create_instance(self.view, core.BNNewBasicBlockReference(blocks[i])))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -181,7 +183,7 @@ class BasicBlock(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetBasicBlockStrictDominators(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(self._create_instance(self.view, core.BNNewBasicBlockReference(blocks[i])))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -200,7 +202,7 @@ class BasicBlock(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetBasicBlockDominatorTreeChildren(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(self._create_instance(self.view, core.BNNewBasicBlockReference(blocks[i])))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -211,7 +213,7 @@ class BasicBlock(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetBasicBlockDominanceFrontier(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(self._create_instance(self.view, core.BNNewBasicBlockReference(blocks[i])))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -275,12 +277,12 @@ class BasicBlock(object):
if len(blocks) == 0:
return []
block_set = (ctypes.POINTER(core.BNBasicBlock) * len(blocks))()
- for i in xrange(len(blocks)):
+ for i in range(len(blocks)):
block_set[i] = blocks[i].handle
count = ctypes.c_ulonglong()
out_blocks = core.BNGetBasicBlockIteratedDominanceFrontier(block_set, len(blocks), count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(BasicBlock(blocks[0].view, core.BNNewBasicBlockReference(out_blocks[i])))
core.BNFreeBasicBlockList(out_blocks, count.value)
return result
@@ -336,14 +338,14 @@ class BasicBlock(object):
count = ctypes.c_ulonglong()
lines = core.BNGetBasicBlockDisassemblyText(self.handle, settings_obj, count)
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(self, 'il_function'):
il_instr = self.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
diff --git a/python/binaryview.py b/python/binaryview.py
index b3314c5c..ac08ad76 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -39,6 +39,7 @@ from binaryninja import metadata
# 2-3 compatibility
from six import with_metaclass
+from six.moves import range
class BinaryDataNotification(object):
@@ -325,7 +326,7 @@ class _BinaryViewTypeMetaclass(type):
count = ctypes.c_ulonglong()
types = core.BNGetBinaryViewTypes(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(BinaryViewType(types[i]))
core.BNFreeBinaryViewTypeList(types)
return result
@@ -335,7 +336,7 @@ class _BinaryViewTypeMetaclass(type):
count = ctypes.c_ulonglong()
types = core.BNGetBinaryViewTypes(count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield BinaryViewType(types[i])
finally:
core.BNFreeBinaryViewTypeList(types)
@@ -371,12 +372,12 @@ class BinaryViewType(with_metaclass(_BinaryViewTypeMetaclass, object)):
@property
def name(self):
"""BinaryView name (read-only)"""
- return core.BNGetBinaryViewTypeName(self.handle)
+ return core.BNGetBinaryViewTypeName(self.handle).decode('utf8')
@property
def long_name(self):
"""BinaryView long name (read-only)"""
- return core.BNGetBinaryViewTypeLongName(self.handle)
+ return core.BNGetBinaryViewTypeLongName(self.handle).decode('utf8')
def __repr__(self):
return "<view type: '%s'>" % self.name
@@ -780,7 +781,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
funcs = core.BNGetAnalysisFunctionList(self.handle, count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield binaryninja.function.Function(self, core.BNNewFunctionReference(funcs[i]))
finally:
core.BNFreeFunctionList(funcs, count.value)
@@ -899,7 +900,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
funcs = core.BNGetAnalysisFunctionList(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(binaryninja.function.Function(self, core.BNNewFunctionReference(funcs[i])))
core.BNFreeFunctionList(funcs, count.value)
return result
@@ -923,7 +924,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
syms = core.BNGetSymbols(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
sym = types.Symbol(None, None, None, handle=core.BNNewSymbolReference(syms[i]))
result[sym.raw_name] = sym
core.BNFreeSymbolList(syms, count.value)
@@ -940,7 +941,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
types = core.BNGetBinaryViewTypesForData(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(BinaryViewType(types[i]))
core.BNFreeBinaryViewTypeList(types)
return result
@@ -990,7 +991,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
var_list = core.BNGetDataVariables(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
addr = var_list[i].address
var_type = types.Type(core.BNNewTypeReference(var_list[i].type), platform = self.platform, confidence = var_list[i].typeConfidence)
auto_discovered = var_list[i].autoDiscovered
@@ -1004,7 +1005,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
type_list = core.BNGetAnalysisTypeList(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = types.QualifiedName._from_core_struct(type_list[i].name)
result[name] = types.Type(core.BNNewTypeReference(type_list[i].type), platform = self.platform)
core.BNFreeTypeList(type_list, count.value)
@@ -1016,7 +1017,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
segment_list = core.BNGetSegments(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(Segment(segment_list[i].start, segment_list[i].length,
segment_list[i].dataOffset, segment_list[i].dataLength, segment_list[i].flags, segment_list[i].autoDefined))
core.BNFreeSegmentList(segment_list)
@@ -1028,7 +1029,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
section_list = core.BNGetSections(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result[section_list[i].name] = Section(section_list[i].name, section_list[i].type, section_list[i].start,
section_list[i].length, section_list[i].linkedSection, section_list[i].infoSection,
section_list[i].infoData, section_list[i].align, section_list[i].entrySize,
@@ -1042,7 +1043,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
range_list = core.BNGetAllocatedRanges(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(AddressRange(range_list[i].start, range_list[i].end))
core.BNFreeAddressRanges(range_list)
return result
@@ -2184,7 +2185,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
funcs = core.BNGetAnalysisFunctionsForAddress(self.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(binaryninja.function.Function(self, core.BNNewFunctionReference(funcs[i])))
core.BNFreeFunctionList(funcs, count.value)
return result
@@ -2206,7 +2207,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
blocks = core.BNGetBasicBlocksForAddress(self.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(basicblock.BasicBlock(self, core.BNNewBasicBlockReference(blocks[i])))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -2222,7 +2223,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
blocks = core.BNGetBasicBlocksStartingAtAddress(self.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(basicblock.BasicBlock(self, core.BNNewBasicBlockReference(blocks[i])))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -2253,7 +2254,7 @@ class BinaryView(object):
else:
refs = core.BNGetCodeReferencesInRange(self.handle, addr, length, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
if refs[i].func:
func = binaryninja.function.Function(self, core.BNNewFunctionReference(refs[i].func))
else:
@@ -2319,7 +2320,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
syms = core.BNGetSymbolsByName(self.handle, name, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(types.Symbol(None, None, None, handle = core.BNNewSymbolReference(syms[i])))
core.BNFreeSymbolList(syms, count.value)
return result
@@ -2344,7 +2345,7 @@ class BinaryView(object):
else:
syms = core.BNGetSymbolsInRange(self.handle, start, length, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(types.Symbol(None, None, None, handle = core.BNNewSymbolReference(syms[i])))
core.BNFreeSymbolList(syms, count.value)
return result
@@ -2373,7 +2374,7 @@ class BinaryView(object):
else:
syms = core.BNGetSymbolsOfTypeInRange(self.handle, sym_type, start, length, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(types.Symbol(None, None, None, handle = core.BNNewSymbolReference(syms[i])))
core.BNFreeSymbolList(syms, count.value)
return result
@@ -2772,7 +2773,7 @@ class BinaryView(object):
length = self.end - start
strings = core.BNGetStringsInRange(self.handle, start, length, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(StringReference(self, StringType(strings[i].type), strings[i].start, strings[i].length))
core.BNFreeStringReferenceList(strings)
return result
@@ -3004,7 +3005,7 @@ class BinaryView(object):
lines = api(self.handle, pos_obj, settings, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
func = None
block = None
if lines[i].function:
@@ -3013,7 +3014,7 @@ class BinaryView(object):
block = basicblock.BasicBlock(self, core.BNNewBasicBlockReference(lines[i].block))
addr = lines[i].contents.addr
tokens = []
- for j in xrange(0, lines[i].contents.count):
+ for j in range(0, lines[i].contents.count):
token_type = InstructionTextTokenType(lines[i].contents.tokens[j].type)
text = lines[i].contents.tokens[j].text
value = lines[i].contents.tokens[j].value
@@ -3456,7 +3457,7 @@ class BinaryView(object):
count = ctypes.c_ulonglong(0)
section_list = core.BNGetSectionsAt(self.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(Section(section_list[i].name, section_list[i].type, section_list[i].start,
section_list[i].length, section_list[i].linkedSection, section_list[i].infoSection,
section_list[i].infoData, section_list[i].align, section_list[i].entrySize,
@@ -3476,11 +3477,11 @@ class BinaryView(object):
def get_unique_section_names(self, name_list):
incoming_names = (ctypes.c_char_p * len(name_list))()
- for i in xrange(0, len(name_list)):
+ for i in range(0, len(name_list)):
incoming_names[i] = name_list[i]
outgoing_names = core.BNGetUniqueSectionNames(self.handle, incoming_names, len(name_list))
result = []
- for i in xrange(0, len(name_list)):
+ for i in range(0, len(name_list)):
result.append(str(outgoing_names[i]))
core.BNFreeStringList(outgoing_names, len(name_list))
return result
diff --git a/python/callingconvention.py b/python/callingconvention.py
index 268d914f..1b0d068e 100644
--- a/python/callingconvention.py
+++ b/python/callingconvention.py
@@ -27,6 +27,10 @@ from binaryninja import _binaryninjacore as core
from binaryninja import log
from binaryninja.enums import VariableSourceType
+# 2-3 compatibility
+from six.moves import range
+
+
class CallingConvention(object):
from binaryninja import types
name = None
@@ -82,7 +86,7 @@ class CallingConvention(object):
regs = core.BNGetCallerSavedRegisters(self.handle, count)
result = []
arch = self.arch
- 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, count.value)
self.__dict__["caller_saved_regs"] = result
@@ -91,7 +95,7 @@ class CallingConvention(object):
regs = core.BNGetIntegerArgumentRegisters(self.handle, count)
result = []
arch = self.arch
- 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, count.value)
self.__dict__["int_arg_regs"] = result
@@ -100,7 +104,7 @@ class CallingConvention(object):
regs = core.BNGetFloatArgumentRegisters(self.handle, count)
result = []
arch = self.arch
- 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, count.value)
self.__dict__["float_arg_regs"] = result
@@ -133,7 +137,7 @@ class CallingConvention(object):
regs = core.BNGetImplicitlyDefinedRegisters(self.handle, count)
result = []
arch = self.arch
- 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, count.value)
self.__dict__["implicitly_defined_regs"] = result
@@ -158,7 +162,7 @@ class CallingConvention(object):
regs = self.__class__.caller_saved_regs
count[0] = len(regs)
reg_buf = (ctypes.c_uint * len(regs))()
- for i in xrange(0, len(regs)):
+ for i in range(0, len(regs)):
reg_buf[i] = self.arch.regs[regs[i]].index
result = ctypes.cast(reg_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, reg_buf)
@@ -173,7 +177,7 @@ class CallingConvention(object):
regs = self.__class__.int_arg_regs
count[0] = len(regs)
reg_buf = (ctypes.c_uint * len(regs))()
- for i in xrange(0, len(regs)):
+ for i in range(0, len(regs)):
reg_buf[i] = self.arch.regs[regs[i]].index
result = ctypes.cast(reg_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, reg_buf)
@@ -188,7 +192,7 @@ class CallingConvention(object):
regs = self.__class__.float_arg_regs
count[0] = len(regs)
reg_buf = (ctypes.c_uint * len(regs))()
- for i in xrange(0, len(regs)):
+ for i in range(0, len(regs)):
reg_buf[i] = self.arch.regs[regs[i]].index
result = ctypes.cast(reg_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, reg_buf)
@@ -267,7 +271,7 @@ class CallingConvention(object):
regs = self.__class__.implicitly_defined_regs
count[0] = len(regs)
reg_buf = (ctypes.c_uint * len(regs))()
- for i in xrange(0, len(regs)):
+ for i in range(0, len(regs)):
reg_buf[i] = self.arch.regs[regs[i]].index
result = ctypes.cast(reg_buf, ctypes.c_void_p)
self._pending_reg_lists[result.value] = (result, reg_buf)
diff --git a/python/demangle.py b/python/demangle.py
index 50322694..ceb1e48b 100644
--- a/python/demangle.py
+++ b/python/demangle.py
@@ -23,6 +23,9 @@ import ctypes
# Binary Ninja components -- additional imports belong in the appropriate class
from binaryninja import _binaryninjacore as core
+# 2-3 compatibility
+from six.moves import range
+
def get_qualified_name(names):
"""
@@ -61,7 +64,7 @@ def demangle_ms(arch, mangled_name):
outSize = ctypes.c_ulonglong()
names = []
if core.BNDemangleMS(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize)):
- for i in xrange(outSize.value):
+ for i in range(outSize.value):
names.append(outName[i])
core.BNFreeDemangledName(ctypes.byref(outName), outSize.value)
return (types.Type(handle), names)
@@ -75,7 +78,7 @@ def demangle_gnu3(arch, mangled_name):
outSize = ctypes.c_ulonglong()
names = []
if core.BNDemangleGNU3(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize)):
- for i in xrange(outSize.value):
+ for i in range(outSize.value):
names.append(outName[i])
core.BNFreeDemangledName(ctypes.byref(outName), outSize.value)
if not handle:
diff --git a/python/function.py b/python/function.py
index a0269e75..6392d7f2 100644
--- a/python/function.py
+++ b/python/function.py
@@ -35,6 +35,10 @@ from binaryninja import types
from binaryninja import highlight
from binaryninja import log
+# 2-3 compatibility
+from six.moves import range
+
+
class LookupTableEntry(object):
def __init__(self, from_values, to_value):
self.from_values = from_values
@@ -173,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
@@ -185,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
@@ -193,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):
@@ -479,7 +483,7 @@ class Function(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetFunctionBasicBlockList(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ 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
@@ -490,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
@@ -525,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)
@@ -538,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)
@@ -551,7 +555,7 @@ class Function(object):
count = ctypes.c_ulonglong()
branches = core.BNGetIndirectBranches(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ 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
@@ -572,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
@@ -606,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)
@@ -617,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
@@ -649,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)
@@ -664,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
@@ -714,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)
@@ -742,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)
@@ -753,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
@@ -847,7 +851,7 @@ class Function(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetFunctionBasicBlockList(self.handle, count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield binaryninja.basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i]))
finally:
core.BNFreeBasicBlockList(blocks, count.value)
@@ -918,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
@@ -1017,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
@@ -1028,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
@@ -1039,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),
@@ -1053,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
@@ -1074,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
@@ -1084,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
@@ -1093,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
@@ -1102,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
@@ -1120,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))
@@ -1129,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))
@@ -1140,7 +1144,7 @@ class Function(object):
count = ctypes.c_ulonglong()
branches = core.BNGetIndirectBranchesAt(self.handle, arch.handle, addr, count)
result = []
- for i in xrange(0, count.value):
+ 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
@@ -1151,9 +1155,9 @@ 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
value = lines[i].tokens[j].value
@@ -1187,7 +1191,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
@@ -1213,7 +1217,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
@@ -1270,7 +1274,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
@@ -1458,10 +1462,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
@@ -1553,7 +1557,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)
@@ -1709,14 +1713,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
@@ -1736,7 +1740,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:
@@ -1749,7 +1753,7 @@ class FunctionGraphBlock(object):
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)
@@ -1773,14 +1777,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
@@ -1877,7 +1881,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
@@ -1956,7 +1960,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)
@@ -1999,7 +2003,7 @@ class FunctionGraph(object):
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
diff --git a/python/generator.cpp b/python/generator.cpp
index bb32ab69..8fc415b0 100644
--- a/python/generator.cpp
+++ b/python/generator.cpp
@@ -117,12 +117,14 @@ void OutputType(FILE* out, Type* type, bool isReturnType = false, bool isCallbac
break;
}
else if ((type->GetChildType()->GetClass() == IntegerTypeClass) &&
- (type->GetChildType()->GetWidth() == 1) && (type->GetChildType()->IsSigned()))
+ (type->GetChildType()->GetWidth() == 1) && (type->GetChildType()->IsSigned()))
{
if (isReturnType)
fprintf(out, "ctypes.POINTER(ctypes.c_byte)");
- else
+ else {
+ //fprintf(out, "compatstring");
fprintf(out, "ctypes.c_char_p");
+ }
break;
}
else if (type->GetChildType()->GetClass() == FunctionTypeClass)
@@ -188,6 +190,7 @@ int main(int argc, char* argv[])
fprintf(out, "import platform\n");
fprintf(out, "core = None\n");
fprintf(out, "_base_path = None\n");
+ fprintf(out, "ctypes.set_conversion_mode('utf-8', 'strict')\n");
fprintf(out, "if platform.system() == \"Darwin\":\n");
fprintf(out, "\t_base_path = os.path.join(os.path.dirname(__file__), \"..\", \"..\", \"..\", \"MacOS\")\n");
fprintf(out, "\tcore = ctypes.CDLL(os.path.join(_base_path, \"libbinaryninjacore.dylib\"))\n\n");
@@ -199,6 +202,40 @@ int main(int argc, char* argv[])
fprintf(out, "\tcore = ctypes.CDLL(os.path.join(_base_path, \"binaryninjacore.dll\"))\n");
fprintf(out, "else:\n");
fprintf(out, "\traise Exception(\"OS not supported\")\n\n");
+ // fprintf(out, "class compatstring(ctypes.c_char_p):\n");
+ // fprintf(out, "\tdef __init__(self, value=None):\n");
+ // fprintf(out, "\t\tsuper(compatstring, self).__init__()\n");
+ // fprintf(out, "\t\tif value is not None:\n");
+ // fprintf(out, "\t\t\tself.value = value\n");
+ // fprintf(out, "\t@classmethod\n");
+ // fprintf(out, "\tdef from_param(cls, value):\n");
+ // fprintf(out, "\t\tif not isinstance(value, bytes):\n");
+ // fprintf(out, "\t\t\treturn super(compatstring, cls).from_param(value.encode('utf8'))\n");
+ // fprintf(out, "\t\treturn super(compatstring, cls).from_param(value)\n\n");
+ // fprintf(out, "\t@property\n");
+ // fprintf(out, "\tdef value(self, value):\n");
+ // fprintf(out, "\t\tif not isinstance(value, bytes):\n");
+ // fprintf(out, "\t\t\treturn super(compatstring, cls).from_param(value.encode('utf8'))\n");
+ // fprintf(out, "\t\treturn super(compatstring, cls).from_param(value)\n\n");
+ fprintf(out, "class compatstring(ctypes.c_char_p):\n");
+ fprintf(out, " @classmethod\n");
+ fprintf(out, " def from_param(cls, obj):\n");
+ fprintf(out, " if (obj is not None) and (not isinstance(obj, cls)):\n");
+ fprintf(out, " if not isinstance(obj, basestring):\n");
+ fprintf(out, " raise TypeError('parameter must be a string type instance')\n");
+ fprintf(out, " if not isinstance(obj, unicode):\n");
+ fprintf(out, " obj = unicode(obj)\n");
+ fprintf(out, " obj = obj.encode('utf-8')\n");
+ fprintf(out, " return ctypes.c_char_p.from_param(obj)\n");
+ fprintf(out, "\n");
+ fprintf(out, " def decode(self):\n");
+ fprintf(out, " if self.value is None:\n");
+ fprintf(out, " return None\n");
+ fprintf(out, " return self.value.decode('utf-8')\n");
+ fprintf(out, " @property\n");
+ fprintf(out, " def value(self, c_void_p=ctypes.c_void_p):\n");
+ fprintf(out, " addr = c_void_p.from_buffer(self).value\n");
+ fprintf(out, " return \n");
// Create type objects
fprintf(out, "# Type definitions\n");
@@ -227,7 +264,7 @@ int main(int argc, char* argv[])
}
}
else if ((i.second->GetClass() == BoolTypeClass) || (i.second->GetClass() == IntegerTypeClass) ||
- (i.second->GetClass() == FloatTypeClass) || (i.second->GetClass() == ArrayTypeClass))
+ (i.second->GetClass() == FloatTypeClass) || (i.second->GetClass() == ArrayTypeClass))
{
fprintf(out, "%s = ", name.c_str());
OutputType(out, i.second);
@@ -377,7 +414,7 @@ int main(int argc, char* argv[])
fprintf(out, "\traise ValueError('expected pointer to %%s' %% str(handle_type))\n");
fprintf(out, "\n# Set path for core plugins\n");
- fprintf(out, "BNSetBundledPluginDirectory(os.path.join(_base_path, \"plugins\").encode('utf-8'))\n");
+ fprintf(out, "BNSetBundledPluginDirectory(os.path.join(_base_path, \"plugins\"))\n");
fclose(out);
fclose(enums);
diff --git a/python/interaction.py b/python/interaction.py
index da6f792a..5b78b278 100644
--- a/python/interaction.py
+++ b/python/interaction.py
@@ -25,6 +25,9 @@ import traceback
from binaryninja import _binaryninjacore as core
from binaryninja.enums import FormInputFieldType, MessageBoxIcon, MessageBoxButtonSet, MessageBoxButtonResult
+# 2-3 compatibility
+from six.moves import range
+
class LabelField(object):
"""
@@ -160,7 +163,7 @@ class ChoiceField(object):
value.type = FormInputFieldType.ChoiceFormField
value.prompt = self.prompt
choice_buf = (ctypes.c_char_p * len(self.choices))()
- for i in xrange(0, len(self.choices)):
+ for i in range(0, len(self.choices)):
choice_buf[i] = str(self.choices[i])
value.choices = choice_buf
value.count = len(self.choices)
@@ -330,7 +333,7 @@ class InteractionHandler(object):
def _get_choice_input(self, ctxt, result, prompt, title, choice_buf, count):
try:
choices = []
- for i in xrange(0, count):
+ for i in range(0, count):
choices.append(choice_buf[i])
value = self.get_choice_input(prompt, title, choices)
if value is None:
@@ -373,7 +376,7 @@ class InteractionHandler(object):
def _get_form_input(self, ctxt, fields, count, title):
try:
field_objs = []
- for i in xrange(0, count):
+ for i in range(0, count):
if fields[i].type == FormInputFieldType.LabelFormField:
field_objs.append(LabelField(fields[i].prompt))
elif fields[i].type == FormInputFieldType.SeparatorFormField:
@@ -391,7 +394,7 @@ class InteractionHandler(object):
field_objs.append(AddressField(fields[i].prompt, view, fields[i].currentAddress))
elif fields[i].type == FormInputFieldType.ChoiceFormField:
choices = []
- for j in xrange(0, fields[i].count):
+ for j in range(0, fields[i].count):
choices.append(fields[i].choices[j])
field_objs.append(ChoiceField(fields[i].prompt, choices))
elif fields[i].type == FormInputFieldType.OpenFileNameFormField:
@@ -404,7 +407,7 @@ class InteractionHandler(object):
field_objs.append(LabelField(fields[i].prompt))
if not self.get_form_input(field_objs, title):
return False
- for i in xrange(0, count):
+ for i in range(0, count):
field_objs[i]._fill_core_result(fields[i])
return True
except:
@@ -613,7 +616,7 @@ def get_choice_input(prompt, title, choices):
0L
"""
choice_buf = (ctypes.c_char_p * len(choices))()
- for i in xrange(0, len(choices)):
+ for i in range(0, len(choices)):
choice_buf[i] = str(choices[i])
value = ctypes.c_ulonglong()
if not core.BNGetChoiceInput(value, prompt, title, choice_buf, len(choices)):
@@ -728,7 +731,7 @@ def get_form_input(fields, title):
Peter 1337 0
"""
value = (core.BNFormInputField * len(fields))()
- for i in xrange(0, len(fields)):
+ for i in range(0, len(fields)):
if isinstance(fields[i], str):
LabelField(fields[i])._fill_core_struct(value[i])
elif fields[i] is None:
@@ -737,7 +740,7 @@ def get_form_input(fields, title):
fields[i]._fill_core_struct(value[i])
if not core.BNGetFormInput(value, len(fields), title):
return False
- for i in xrange(0, len(fields)):
+ for i in range(0, len(fields)):
if not (isinstance(fields[i], str) or (fields[i] is None)):
fields[i]._get_result(value[i])
core.BNFreeFormInputResults(value, len(fields))
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 9c1db4cc..333bb5a1 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -27,6 +27,9 @@ from binaryninja import _binaryninjacore as core
from binaryninja.enums import LowLevelILOperation, LowLevelILFlagCondition, InstructionTextTokenType
from binaryninja import basicblock #required for LowLevelILBasicBlock
+# 2-3 compatibility
+from six.moves import range
+
class LowLevelILLabel(object):
def __init__(self, handle = None):
@@ -413,7 +416,7 @@ class LowLevelILInstruction(object):
operand_list = core.BNLowLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value):
+ for j in range(count.value):
value.append(operand_list[j])
core.BNLowLevelILFreeOperandList(operand_list)
elif operand_type == "expr_list":
@@ -421,7 +424,7 @@ class LowLevelILInstruction(object):
operand_list = core.BNLowLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value):
+ for j in range(count.value):
value.append(LowLevelILInstruction(func, operand_list[j]))
core.BNLowLevelILFreeOperandList(operand_list)
elif operand_type == "reg_or_flag_list":
@@ -429,7 +432,7 @@ class LowLevelILInstruction(object):
operand_list = core.BNLowLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value):
+ for j in range(count.value):
if (operand_list[j] & (1 << 32)) != 0:
value.append(ILFlag(func.arch, operand_list[j] & 0xffffffff))
else:
@@ -440,7 +443,7 @@ class LowLevelILInstruction(object):
operand_list = core.BNLowLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value // 2):
+ for j in range(count.value // 2):
reg = operand_list[j * 2]
reg_version = operand_list[(j * 2) + 1]
value.append(SSARegister(ILRegister(func.arch, reg), reg_version))
@@ -450,7 +453,7 @@ class LowLevelILInstruction(object):
operand_list = core.BNLowLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value // 2):
+ for j in range(count.value // 2):
reg_stack = operand_list[j * 2]
reg_version = operand_list[(j * 2) + 1]
value.append(SSARegisterStack(ILRegisterStack(func.arch, reg_stack), reg_version))
@@ -460,7 +463,7 @@ class LowLevelILInstruction(object):
operand_list = core.BNLowLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value // 2):
+ for j in range(count.value // 2):
flag = operand_list[j * 2]
flag_version = operand_list[(j * 2) + 1]
value.append(SSAFlag(ILFlag(func.arch, flag), flag_version))
@@ -470,7 +473,7 @@ class LowLevelILInstruction(object):
operand_list = core.BNLowLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value // 2):
+ for j in range(count.value // 2):
if (operand_list[j * 2] & (1 << 32)) != 0:
reg_or_flag = ILFlag(func.arch, operand_list[j * 2] & 0xffffffff)
else:
@@ -483,7 +486,7 @@ class LowLevelILInstruction(object):
operand_list = core.BNLowLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = {}
- for j in xrange(count.value // 2):
+ for j in range(count.value // 2):
reg_stack = operand_list[j * 2]
adjust = operand_list[(j * 2) + 1]
if adjust & 0x80000000:
@@ -520,7 +523,7 @@ class LowLevelILInstruction(object):
self.expr_index, tokens, count):
return None
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
token_type = InstructionTextTokenType(tokens[i].type)
text = tokens[i].text
value = tokens[i].value
@@ -777,7 +780,7 @@ class LowLevelILFunction(object):
view = None
if self.source_function is not None:
view = self.source_function.view
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(LowLevelILBasicBlock(view, core.BNNewBasicBlockReference(blocks[i]), self))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -844,7 +847,7 @@ class LowLevelILFunction(object):
if self.source_function is not None:
view = self.source_function.view
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield LowLevelILBasicBlock(view, core.BNNewBasicBlockReference(blocks[i]), self)
finally:
core.BNFreeBasicBlockList(blocks, count.value)
@@ -862,7 +865,7 @@ class LowLevelILFunction(object):
def set_indirect_branches(self, branches):
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.BNLowLevelILSetIndirectBranches(self.handle, branch_list, len(branches))
@@ -2178,7 +2181,7 @@ class LowLevelILFunction(object):
:rtype: LowLevelILExpr
"""
label_list = (ctypes.POINTER(core.BNLowLevelILLabel) * len(labels))()
- for i in xrange(len(labels)):
+ for i in range(len(labels)):
label_list[i] = labels[i].handle
return LowLevelILExpr(core.BNLowLevelILAddLabelList(self.handle, label_list, len(labels)))
@@ -2191,7 +2194,7 @@ class LowLevelILFunction(object):
:rtype: LowLevelILExpr
"""
operand_list = (ctypes.c_ulonglong * len(operands))()
- for i in xrange(len(operands)):
+ for i in range(len(operands)):
operand_list[i] = operands[i]
return LowLevelILExpr(core.BNLowLevelILAddOperandList(self.handle, operand_list, len(operands)))
@@ -2274,7 +2277,7 @@ class LowLevelILFunction(object):
count = ctypes.c_ulonglong()
instrs = core.BNGetLowLevelILSSARegisterUses(self.handle, reg, reg_ssa.version, 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
@@ -2284,7 +2287,7 @@ class LowLevelILFunction(object):
count = ctypes.c_ulonglong()
instrs = core.BNGetLowLevelILSSAFlagUses(self.handle, flag, flag_ssa.version, 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
@@ -2293,7 +2296,7 @@ class LowLevelILFunction(object):
count = ctypes.c_ulonglong()
instrs = core.BNGetLowLevelILSSAMemoryUses(self.handle, index, 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
@@ -2353,7 +2356,7 @@ class LowLevelILBasicBlock(basicblock.BasicBlock):
self.il_function = owner
def __iter__(self):
- for idx in xrange(self.start, self.end):
+ for idx in range(self.start, self.end):
yield self.il_function[idx]
def __getitem__(self, idx):
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index a62c5c04..707915d7 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -26,6 +26,9 @@ from binaryninja import _binaryninjacore as core
from binaryninja.enums import MediumLevelILOperation, InstructionTextTokenType, ILBranchDependence
from binaryninja import basicblock #required for MediumLevelILBasicBlock argument
+# 2-3 compatibility
+from six.moves import range
+
class SSAVariable(object):
def __init__(self, var, version):
@@ -256,7 +259,7 @@ class MediumLevelILInstruction(object):
count = ctypes.c_ulonglong()
operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count)
value = []
- for j in xrange(count.value):
+ for j in range(count.value):
value.append(operand_list[j])
core.BNMediumLevelILFreeOperandList(operand_list)
elif operand_type == "var_list":
@@ -264,7 +267,7 @@ class MediumLevelILInstruction(object):
operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value):
+ for j in range(count.value):
value.append(function.Variable.from_identifier(self.function.source_function, operand_list[j]))
core.BNMediumLevelILFreeOperandList(operand_list)
elif operand_type == "var_ssa_list":
@@ -272,7 +275,7 @@ class MediumLevelILInstruction(object):
operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value // 2):
+ for j in range(count.value // 2):
var_id = operand_list[j * 2]
var_version = operand_list[(j * 2) + 1]
value.append(SSAVariable(function.Variable.from_identifier(self.function.source_function,
@@ -283,7 +286,7 @@ class MediumLevelILInstruction(object):
operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count)
i += 1
value = []
- for j in xrange(count.value):
+ for j in range(count.value):
value.append(MediumLevelILInstruction(func, operand_list[j]))
core.BNMediumLevelILFreeOperandList(operand_list)
self.operands.append(value)
@@ -317,7 +320,7 @@ class MediumLevelILInstruction(object):
self.expr_index, tokens, count):
return None
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
token_type = InstructionTextTokenType(tokens[i].type)
text = tokens[i].text
value = tokens[i].value
@@ -363,7 +366,7 @@ class MediumLevelILInstruction(object):
count = ctypes.c_ulonglong()
deps = core.BNGetAllMediumLevelILBranchDependence(self.function.handle, self.instr_index, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result[deps[i].branch] = ILBranchDependence(deps[i].dependence)
core.BNFreeILBranchDependenceList(deps)
return result
@@ -647,7 +650,7 @@ class MediumLevelILFunction(object):
view = None
if self.source_function is not None:
view = self.source_function.view
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(MediumLevelILBasicBlock(view, core.BNNewBasicBlockReference(blocks[i]), self))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -704,7 +707,7 @@ class MediumLevelILFunction(object):
if self.source_function is not None:
view = self.source_function.view
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield MediumLevelILBasicBlock(view, core.BNNewBasicBlockReference(blocks[i]), self)
finally:
core.BNFreeBasicBlockList(blocks, count.value)
@@ -775,7 +778,7 @@ class MediumLevelILFunction(object):
:rtype: MediumLevelILExpr
"""
label_list = (ctypes.POINTER(core.BNMediumLevelILLabel) * len(labels))()
- for i in xrange(len(labels)):
+ for i in range(len(labels)):
label_list[i] = labels[i].handle
return MediumLevelILExpr(core.BNMediumLevelILAddLabelList(self.handle, label_list, len(labels)))
@@ -788,7 +791,7 @@ class MediumLevelILFunction(object):
:rtype: MediumLevelILExpr
"""
operand_list = (ctypes.c_ulonglong * len(operands))()
- for i in xrange(len(operands)):
+ for i in range(len(operands)):
operand_list[i] = operands[i]
return MediumLevelILExpr(core.BNMediumLevelILAddOperandList(self.handle, operand_list, len(operands)))
@@ -842,7 +845,7 @@ class MediumLevelILFunction(object):
var_data.storage = ssa_var.var.storage
instrs = core.BNGetMediumLevelILSSAVarUses(self.handle, var_data, ssa_var.version, 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
@@ -851,7 +854,7 @@ class MediumLevelILFunction(object):
count = ctypes.c_ulonglong()
instrs = core.BNGetMediumLevelILSSAMemoryUses(self.handle, version, 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
@@ -878,7 +881,7 @@ class MediumLevelILFunction(object):
var_data.storage = var.storage
instrs = core.BNGetMediumLevelILVariableDefinitions(self.handle, var_data, 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
@@ -891,7 +894,7 @@ class MediumLevelILFunction(object):
var_data.storage = var.storage
instrs = core.BNGetMediumLevelILVariableUses(self.handle, var_data, 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
@@ -936,7 +939,7 @@ class MediumLevelILBasicBlock(basicblock.BasicBlock):
self.il_function = owner
def __iter__(self):
- for idx in xrange(self.start, self.end):
+ for idx in range(self.start, self.end):
yield self.il_function[idx]
def __getitem__(self, idx):
diff --git a/python/metadata.py b/python/metadata.py
index 21e74533..64080060 100644
--- a/python/metadata.py
+++ b/python/metadata.py
@@ -26,6 +26,9 @@ import ctypes
from binaryninja import _binaryninjacore as core
from binaryninja.enums import MetadataType
+# 2-3 compatibility
+from six.moves import range
+
class Metadata(object):
def __init__(self, value=None, signed=None, raw=None, handle=None):
@@ -138,12 +141,12 @@ class Metadata(object):
def __iter__(self):
if self.is_array:
- for i in xrange(core.BNMetadataSize(self.handle)):
+ for i in range(core.BNMetadataSize(self.handle)):
yield Metadata(handle=core.BNMetadataGetForIndex(self.handle, i)).value
elif self.is_dict:
result = core.BNMetadataGetValueStore(self.handle)
try:
- for i in xrange(result.contents.size):
+ for i in range(result.contents.size):
yield result.contents.keys[i]
finally:
core.BNFreeMetadataValueStore(result)
@@ -175,7 +178,7 @@ class Metadata(object):
length.value = 0
native_list = core.BNMetadataGetRaw(self.handle, ctypes.byref(length))
out_list = []
- for i in xrange(length.value):
+ for i in range(length.value):
out_list.append(native_list[i])
core.BNFreeMetadataRaw(native_list)
return ''.join(chr(a) for a in out_list)
diff --git a/python/platform.py b/python/platform.py
index 083ebf06..c57315ce 100644
--- a/python/platform.py
+++ b/python/platform.py
@@ -26,6 +26,7 @@ from binaryninja import _binaryninjacore as core
#2-3 compatibility
from six import with_metaclass
+from six.moves import range
class _PlatformMetaClass(type):
@@ -37,7 +38,7 @@ class _PlatformMetaClass(type):
count = ctypes.c_ulonglong()
platforms = core.BNGetPlatformList(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(Platform(None, core.BNNewPlatformReference(platforms[i])))
core.BNFreePlatformList(platforms, count.value)
return result
@@ -48,7 +49,7 @@ class _PlatformMetaClass(type):
count = ctypes.c_ulonglong()
platforms = core.BNGetPlatformOSList(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(str(platforms[i]))
core.BNFreePlatformOSList(platforms, count.value)
return result
@@ -58,7 +59,7 @@ class _PlatformMetaClass(type):
count = ctypes.c_ulonglong()
platforms = core.BNGetPlatformList(count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield Platform(None, core.BNNewPlatformReference(platforms[i]))
finally:
core.BNFreePlatformList(platforms, count.value)
@@ -86,7 +87,7 @@ class _PlatformMetaClass(type):
else:
platforms = core.BNGetPlatformListByArchitecture(os, arch.handle)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(Platform(None, core.BNNewPlatformReference(platforms[i])))
core.BNFreePlatformList(platforms, count.value)
return result
@@ -227,7 +228,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
count = ctypes.c_ulonglong()
cc = core.BNGetPlatformCallingConventions(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(binaryninja.callingconvention.CallingConvention(handle=core.BNNewCallingConventionReference(cc[i])))
core.BNFreeCallingConventionList(cc, count.value)
return result
@@ -238,7 +239,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
count = ctypes.c_ulonglong(0)
type_list = core.BNGetPlatformTypes(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = binaryninja.types.QualifiedName._from_core_struct(type_list[i].name)
result[name] = binaryninja.types.Type(core.BNNewTypeReference(type_list[i].type), platform = self)
core.BNFreeTypeList(type_list, count.value)
@@ -250,7 +251,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
count = ctypes.c_ulonglong(0)
type_list = core.BNGetPlatformVariables(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = binaryninja.types.QualifiedName._from_core_struct(type_list[i].name)
result[name] = binaryninja.types.Type(core.BNNewTypeReference(type_list[i].type), platform = self)
core.BNFreeTypeList(type_list, count.value)
@@ -262,7 +263,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
count = ctypes.c_ulonglong(0)
type_list = core.BNGetPlatformFunctions(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = binaryninja.types.QualifiedName._from_core_struct(type_list[i].name)
result[name] = binaryninja.types.Type(core.BNNewTypeReference(type_list[i].type), platform = self)
core.BNFreeTypeList(type_list, count.value)
@@ -274,7 +275,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
count = ctypes.c_ulonglong(0)
call_list = core.BNGetPlatformSystemCalls(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = binaryninja.types.QualifiedName._from_core_struct(call_list[i].name)
t = binaryninja.types.Type(core.BNNewTypeReference(call_list[i].type), platform = self)
result[call_list[i].number] = (name, t)
@@ -389,7 +390,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
if filename is None:
filename = "input"
dir_buf = (ctypes.c_char_p * len(include_dirs))()
- for i in xrange(0, len(include_dirs)):
+ for i in range(0, len(include_dirs)):
dir_buf[i] = str(include_dirs[i])
parse = core.BNTypeParserResult()
errors = ctypes.c_char_p()
@@ -402,13 +403,13 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
type_dict = {}
variables = {}
functions = {}
- for i in xrange(0, parse.typeCount):
+ for i in range(0, parse.typeCount):
name = binaryninja.types.QualifiedName._from_core_struct(parse.types[i].name)
type_dict[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.types[i].type), platform = self)
- for i in xrange(0, parse.variableCount):
+ for i in range(0, parse.variableCount):
name = binaryninja.types.QualifiedName._from_core_struct(parse.variables[i].name)
variables[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.variables[i].type), platform = self)
- for i in xrange(0, parse.functionCount):
+ for i in range(0, parse.functionCount):
name = binaryninja.types.QualifiedName._from_core_struct(parse.functions[i].name)
functions[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.functions[i].type), platform = self)
core.BNFreeTypeParserResult(parse)
@@ -435,7 +436,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
>>>
"""
dir_buf = (ctypes.c_char_p * len(include_dirs))()
- for i in xrange(0, len(include_dirs)):
+ for i in range(0, len(include_dirs)):
dir_buf[i] = str(include_dirs[i])
parse = core.BNTypeParserResult()
errors = ctypes.c_char_p()
@@ -448,13 +449,13 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
type_dict = {}
variables = {}
functions = {}
- for i in xrange(0, parse.typeCount):
+ for i in range(0, parse.typeCount):
name = binaryninja.types.QualifiedName._from_core_struct(parse.types[i].name)
type_dict[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.types[i].type), platform = self)
- for i in xrange(0, parse.variableCount):
+ for i in range(0, parse.variableCount):
name = binaryninja.types.QualifiedName._from_core_struct(parse.variables[i].name)
variables[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.variables[i].type), platform = self)
- for i in xrange(0, parse.functionCount):
+ for i in range(0, parse.functionCount):
name = binaryninja.types.QualifiedName._from_core_struct(parse.functions[i].name)
functions[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.functions[i].type), platform = self)
core.BNFreeTypeParserResult(parse)
diff --git a/python/plugin.py b/python/plugin.py
index 4cf6fb77..52feced4 100644
--- a/python/plugin.py
+++ b/python/plugin.py
@@ -30,6 +30,7 @@ from binaryninja.enums import PluginCommandType
#2-3 compatibility
from six import with_metaclass
+from six.moves import range
class PluginCommandContext(object):
@@ -49,7 +50,7 @@ class _PluginCommandMetaClass(type):
count = ctypes.c_ulonglong()
commands = core.BNGetAllPluginCommands(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(PluginCommand(commands[i]))
core.BNFreePluginCommandList(commands)
return result
@@ -59,7 +60,7 @@ class _PluginCommandMetaClass(type):
count = ctypes.c_ulonglong()
commands = core.BNGetAllPluginCommands(count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield PluginCommand(commands[i])
finally:
core.BNFreePluginCommandList(commands)
@@ -568,7 +569,7 @@ class _BackgroundTaskMetaclass(type):
count = ctypes.c_ulonglong()
tasks = core.BNGetRunningBackgroundTasks(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(BackgroundTask(handle=core.BNNewBackgroundTaskReference(tasks[i])))
core.BNFreeBackgroundTaskList(tasks, count.value)
return result
@@ -578,7 +579,7 @@ class _BackgroundTaskMetaclass(type):
count = ctypes.c_ulonglong()
tasks = core.BNGetRunningBackgroundTasks(count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield BackgroundTask(handle=core.BNNewBackgroundTaskReference(tasks[i]))
finally:
core.BNFreeBackgroundTaskList(tasks, count.value)
diff --git a/python/pluginmanager.py b/python/pluginmanager.py
index 002db573..ad314629 100644
--- a/python/pluginmanager.py
+++ b/python/pluginmanager.py
@@ -23,6 +23,8 @@ import ctypes
# Binary Ninja components -- additional imports belong in the appropriate class
from binaryninja import _binaryninjacore as core
+# 2-3 compatibility
+from six.moves import range
class RepoPlugin(object):
"""
@@ -110,7 +112,7 @@ class RepoPlugin(object):
result = []
count = ctypes.c_ulonglong(0)
plugintypes = core.BNPluginGetPluginTypes(self.handle, count)
- for i in xrange(count.value):
+ for i in range(count.value):
result.append(PluginType(plugintypes[i]))
core.BNFreePluginTypes(plugintypes)
return result
@@ -182,7 +184,7 @@ class Repository(object):
pluginlist = []
count = ctypes.c_ulonglong(0)
result = core.BNRepositoryGetPlugins(self.handle, count)
- for i in xrange(count.value):
+ for i in range(count.value):
pluginlist.append(RepoPlugin(handle=result[i]))
core.BNFreeRepositoryPluginList(result, count.value)
del result
@@ -220,7 +222,7 @@ class RepositoryManager(object):
result = []
count = ctypes.c_ulonglong(0)
repos = core.BNRepositoryManagerGetRepositories(self.handle, count)
- for i in xrange(count.value):
+ for i in range(count.value):
result.append(Repository(handle=repos[i]))
core.BNFreeRepositoryManagerRepositoriesList(repos)
return result
diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py
index 0b15ee18..374b2f41 100644
--- a/python/scriptingprovider.py
+++ b/python/scriptingprovider.py
@@ -33,6 +33,7 @@ import binaryninja.log
#2-3 compatibility
from six import with_metaclass
+from six.moves import range
class _ThreadActionContext(object):
@@ -263,7 +264,7 @@ class _ScriptingProviderMetaclass(type):
count = ctypes.c_ulonglong()
types = core.BNGetScriptingProviderList(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(ScriptingProvider(types[i]))
core.BNFreeScriptingProviderList(types)
return result
@@ -273,7 +274,7 @@ class _ScriptingProviderMetaclass(type):
count = ctypes.c_ulonglong()
types = core.BNGetScriptingProviderList(count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield ScriptingProvider(types[i])
finally:
core.BNFreeScriptingProviderList(types)
@@ -313,7 +314,7 @@ class ScriptingProvider(with_metaclass(_ScriptingProviderMetaclass, object)):
self._cb = core.BNScriptingProviderCallbacks()
self._cb.context = 0
self._cb.createInstance = self._cb.createInstance.__class__(self._create_instance)
- self.handle = core.BNRegisterScriptingProvider(self.__class__.name.encode('utf8'), self._cb)
+ self.handle = core.BNRegisterScriptingProvider(self.__class__.name, self._cb)
self.__class__._registered_providers.append(self)
def _create_instance(self, ctxt):
diff --git a/python/setting.py b/python/setting.py
index 7cde3865..16d943e7 100644
--- a/python/setting.py
+++ b/python/setting.py
@@ -23,6 +23,9 @@ import ctypes
# Binary Ninja components -- additional imports belong in the appropriate class
from binaryninja import _binaryninjacore as core
+# 2-3 compatibility
+from six.moves import range
+
class Setting(object):
def __init__(self, plugin_name="core"):
@@ -45,7 +48,7 @@ class Setting(object):
default_list[i] = default_value[i]
result = core.BNSettingGetIntegerList(self.plugin_name, name, default_list, ctypes.byref(length))
out_list = []
- for i in xrange(length.value):
+ for i in range(length.value):
out_list.append(result[i])
core.BNFreeSettingIntegerList(result)
return out_list
@@ -58,7 +61,7 @@ class Setting(object):
default_list[i] = default_value[i]
result = core.BNSettingGetStringList(self.plugin_name, name, default_list, ctypes.byref(length))
out_list = []
- for i in xrange(length.value):
+ for i in range(length.value):
out_list.append(result[i])
core.BNFreeStringList(result, length)
return out_list
@@ -100,7 +103,7 @@ class Setting(object):
length = ctypes.c_ulonglong()
length.value = len(value)
default_list = (ctypes.c_longlong * len(value))()
- for i in xrange(len(value)):
+ for i in range(len(value)):
default_list[i] = value[i]
return core.BNSettingSetIntegerList(self.plugin_name, name, default_list, length, auto_flush)
@@ -109,7 +112,7 @@ class Setting(object):
length = ctypes.c_ulonglong()
length.value = len(value)
default_list = (ctypes.c_char_p * len(value))()
- for i in xrange(len(value)):
+ for i in range(len(value)):
default_list[i] = str(value[i])
return core.BNSettingSetStringList(self.plugin_name, name, default_list, length, auto_flush)
diff --git a/python/transform.py b/python/transform.py
index fd68a987..e16c6bfc 100644
--- a/python/transform.py
+++ b/python/transform.py
@@ -31,6 +31,7 @@ from binaryninja.enums import TransformType
#2-3 compatibility
from six import with_metaclass
+from six.moves import range
class _TransformMetaClass(type):
@@ -41,7 +42,7 @@ class _TransformMetaClass(type):
count = ctypes.c_ulonglong()
xforms = core.BNGetTransformTypeList(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(Transform(xforms[i]))
core.BNFreeTransformTypeList(xforms)
return result
@@ -51,7 +52,7 @@ class _TransformMetaClass(type):
count = ctypes.c_ulonglong()
xforms = core.BNGetTransformTypeList(count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield Transform(xforms[i])
finally:
core.BNFreeTransformTypeList(xforms)
@@ -129,7 +130,7 @@ class Transform(with_metaclass(_TransformMetaClass, object)):
count = ctypes.c_ulonglong()
params = core.BNGetTransformParameterList(self.handle, count)
self.parameters = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
self.parameters.append(TransformParameter(params[i].name, params[i].longName, params[i].fixedLength))
core.BNFreeTransformParameterList(params, count.value)
@@ -150,7 +151,7 @@ class Transform(with_metaclass(_TransformMetaClass, object)):
try:
count[0] = len(self.parameters)
param_buf = (core.BNTransformParameterInfo * len(self.parameters))()
- for i in xrange(0, len(self.parameters)):
+ for i in range(0, len(self.parameters)):
param_buf[i].name = self.parameters[i].name
param_buf[i].longName = self.parameters[i].long_name
param_buf[i].fixedLength = self.parameters[i].fixed_length
@@ -175,7 +176,7 @@ class Transform(with_metaclass(_TransformMetaClass, object)):
try:
input_obj = databuffer.DataBuffer(handle = core.BNDuplicateDataBuffer(input_buf))
param_map = {}
- for i in xrange(0, count):
+ for i in range(0, count):
data = databuffer.DataBuffer(handle = core.BNDuplicateDataBuffer(params[i].value))
param_map[params[i].name] = str(data)
result = self.perform_decode(str(input_obj), param_map)
@@ -192,7 +193,7 @@ class Transform(with_metaclass(_TransformMetaClass, object)):
try:
input_obj = databuffer.DataBuffer(handle = core.BNDuplicateDataBuffer(input_buf))
param_map = {}
- for i in xrange(0, count):
+ for i in range(0, count):
data = databuffer.DataBuffer(handle = core.BNDuplicateDataBuffer(params[i].value))
param_map[params[i].name] = str(data)
result = self.perform_encode(str(input_obj), param_map)
@@ -225,7 +226,7 @@ class Transform(with_metaclass(_TransformMetaClass, object)):
output_buf = databuffer.DataBuffer()
keys = params.keys()
param_buf = (core.BNTransformParameter * len(keys))()
- for i in xrange(0, len(keys)):
+ for i in range(0, len(keys)):
data = databuffer.DataBuffer(params[keys[i]])
param_buf[i].name = keys[i]
param_buf[i].value = data.handle
@@ -238,7 +239,7 @@ class Transform(with_metaclass(_TransformMetaClass, object)):
output_buf = databuffer.DataBuffer()
keys = params.keys()
param_buf = (core.BNTransformParameter * len(keys))()
- for i in xrange(0, len(keys)):
+ for i in range(0, len(keys)):
data = databuffer.DataBuffer(params[keys[i]])
param_buf[i].name = keys[i]
param_buf[i].value = data.handle
diff --git a/python/types.py b/python/types.py
index adb9e03a..857f67e6 100644
--- a/python/types.py
+++ b/python/types.py
@@ -28,6 +28,9 @@ import binaryninja
from binaryninja import _binaryninjacore as core
from binaryninja.enums import SymbolType, TypeClass, NamedTypeReferenceClass, InstructionTextTokenType, StructureType, ReferenceType, VariableSourceType
+#2-3 compatibility
+from six.moves import range
+
class QualifiedName(object):
def __init__(self, name = []):
@@ -98,7 +101,7 @@ class QualifiedName(object):
def _get_core_struct(self):
result = core.BNQualifiedName()
name_list = (ctypes.c_char_p * len(self.name))()
- for i in xrange(0, len(self.name)):
+ for i in range(0, len(self.name)):
name_list[i] = self.name[i]
result.name = name_list
result.nameCount = len(self.name)
@@ -107,7 +110,7 @@ class QualifiedName(object):
@classmethod
def _from_core_struct(cls, name):
result = []
- for i in xrange(0, name.nameCount):
+ for i in range(0, name.nameCount):
result.append(name.name[i])
return QualifiedName(result)
@@ -300,7 +303,7 @@ class Type(object):
count = ctypes.c_ulonglong()
params = core.BNGetTypeParameters(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
param_type = Type(core.BNNewTypeReference(params[i].type), platform = self.platform, confidence = params[i].typeConfidence)
if params[i].defaultLocation:
param_location = None
@@ -403,7 +406,7 @@ class Type(object):
platform = self.platform.handle
tokens = core.BNGetTypeTokens(self.handle, platform, base_confidence, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
token_type = InstructionTextTokenType(tokens[i].type)
text = tokens[i].text
value = tokens[i].value
@@ -423,7 +426,7 @@ class Type(object):
platform = self.platform.handle
tokens = core.BNGetTypeTokensBeforeName(self.handle, platform, base_confidence, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
token_type = InstructionTextTokenType(tokens[i].type)
text = tokens[i].text
value = tokens[i].value
@@ -443,7 +446,7 @@ class Type(object):
platform = self.platform.handle
tokens = core.BNGetTypeTokensAfterName(self.handle, platform, base_confidence, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
token_type = InstructionTextTokenType(tokens[i].type)
text = tokens[i].text
value = tokens[i].value
@@ -574,7 +577,7 @@ class Type(object):
:param bool variable_arguments: optional argument for functions that have a variable number of arguments
"""
param_buf = (core.BNFunctionParameter * len(params))()
- for i in xrange(0, len(params)):
+ for i in range(0, len(params)):
if isinstance(params[i], Type):
param_buf[i].name = ""
param_buf[i].type = params[i].handle
@@ -851,7 +854,7 @@ class Structure(object):
count = ctypes.c_ulonglong()
members = core.BNGetStructureMembers(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(StructureMember(Type(core.BNNewTypeReference(members[i].type), confidence = members[i].typeConfidence),
members[i].name, members[i].offset))
core.BNFreeStructureMemberList(members, count.value)
@@ -962,7 +965,7 @@ class Enumeration(object):
count = ctypes.c_ulonglong()
members = core.BNGetEnumerationMembers(self.handle, count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(EnumerationMember(members[i].name, members[i].value, members[i].isDefault))
core.BNFreeEnumerationMemberList(members, count.value)
return result
@@ -1018,7 +1021,7 @@ def preprocess_source(source, filename=None, include_dirs=[]):
if filename is None:
filename = "input"
dir_buf = (ctypes.c_char_p * len(include_dirs))()
- for i in xrange(0, len(include_dirs)):
+ for i in range(0, len(include_dirs)):
dir_buf[i] = str(include_dirs[i])
output = ctypes.c_char_p()
errors = ctypes.c_char_p()
diff --git a/python/update.py b/python/update.py
index 560f05ec..4c77b202 100644
--- a/python/update.py
+++ b/python/update.py
@@ -28,6 +28,7 @@ from binaryninja.enums import UpdateResult
#2-3 compatibility
from six import with_metaclass
+from six.moves import range
class _UpdateChannelMetaClass(type):
@@ -43,7 +44,7 @@ class _UpdateChannelMetaClass(type):
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
raise IOError(error_str)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(UpdateChannel(channels[i].name, channels[i].description, channels[i].latestVersion))
core.BNFreeUpdateChannelList(channels, count.value)
return result
@@ -66,7 +67,7 @@ class _UpdateChannelMetaClass(type):
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
raise IOError(error_str)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield UpdateChannel(channels[i].name, channels[i].description, channels[i].latestVersion)
finally:
core.BNFreeUpdateChannelList(channels, count.value)
@@ -87,7 +88,7 @@ class _UpdateChannelMetaClass(type):
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
raise IOError(error_str)
result = None
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
if channels[i].name == str(name):
result = UpdateChannel(channels[i].name, channels[i].description, channels[i].latestVersion)
break
@@ -130,7 +131,7 @@ class UpdateChannel(with_metaclass(_UpdateChannelMetaClass, object)):
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
raise IOError(error_str)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(UpdateVersion(self, versions[i].version, versions[i].notes, versions[i].time))
core.BNFreeUpdateChannelVersionList(versions, count.value)
return result
@@ -146,7 +147,7 @@ class UpdateChannel(with_metaclass(_UpdateChannelMetaClass, object)):
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
raise IOError(error_str)
result = None
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
if versions[i].version == self.latest_version_num:
result = UpdateVersion(self, versions[i].version, versions[i].notes, versions[i].time)
break