summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/architecture.py2
-rw-r--r--python/basicblock.py8
-rw-r--r--python/binaryview.py17
-rw-r--r--python/function.py5
-rw-r--r--python/functionrecognizer.py15
-rw-r--r--python/pluginmanager.py1
-rw-r--r--python/scriptingprovider.py17
7 files changed, 49 insertions, 16 deletions
diff --git a/python/architecture.py b/python/architecture.py
index ed03a6e6..a893c1d4 100644
--- a/python/architecture.py
+++ b/python/architecture.py
@@ -462,6 +462,7 @@ class Architecture(object):
if info is None:
return False
result[0].length = info.length
+ 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)):
@@ -1163,6 +1164,7 @@ class Architecture(object):
return None
result = function.InstructionInfo()
result.length = info.length
+ result.arch_transition_by_target_addr = info.archTransitionByTargetAddr
result.branch_delay = info.branchDelay
for i in xrange(0, info.branchCount):
target = info.branchTarget[i]
diff --git a/python/basicblock.py b/python/basicblock.py
index 66d96882..8e64c1c1 100644
--- a/python/basicblock.py
+++ b/python/basicblock.py
@@ -35,6 +35,14 @@ class BasicBlockEdge(object):
self.target = target
self.back_edge = back_edge
+ def __eq__(self, value):
+ if not isinstance(value, BasicBlockEdge):
+ return False
+ return (self.type, self.source, self.target, self.back_edge) == (value.type, value.source, value.target, value.back_edge)
+
+ def __hash__(self):
+ return hash((self.type, self.source, self.target, self.back_edge))
+
def __repr__(self):
if self.type == BranchType.UnresolvedBranch:
return "<%s>" % BranchType(self.type).name
diff --git a/python/binaryview.py b/python/binaryview.py
index 9f149ba8..6eb59db1 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -416,12 +416,13 @@ class BinaryViewType(object):
class Segment(object):
- def __init__(self, start, length, data_offset, data_length, flags):
+ def __init__(self, start, length, data_offset, data_length, flags, auto_defined):
self.start = start
self.length = length
self.data_offset = data_offset
self.data_length = data_length
self.flags = flags
+ self.auto_defined = auto_defined
@property
def executable(self):
@@ -450,7 +451,7 @@ class Segment(object):
class Section(object):
- def __init__(self, name, section_type, start, length, linked_section, info_section, info_data, align, entry_size, semantics):
+ def __init__(self, name, section_type, start, length, linked_section, info_section, info_data, align, entry_size, semantics, auto_defined):
self.name = name
self.type = section_type
self.start = start
@@ -461,6 +462,7 @@ class Section(object):
self.align = align
self.entry_size = entry_size
self.semantics = SectionSemantics(semantics)
+ self.auto_defined = auto_defined
@property
def end(self):
@@ -965,7 +967,7 @@ class BinaryView(object):
result = []
for i in xrange(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].dataOffset, segment_list[i].dataLength, segment_list[i].flags, segment_list[i].autoDefined))
core.BNFreeSegmentList(segment_list)
return result
@@ -979,7 +981,7 @@ class BinaryView(object):
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,
- section_list[i].semantics)
+ section_list[i].semantics, section_list[i].autoDefined)
core.BNFreeSectionList(section_list, count.value)
return result
@@ -3353,7 +3355,7 @@ class BinaryView(object):
if not core.BNGetSegmentAt(self.handle, addr, segment):
return None
result = Segment(segment.start, segment.length, segment.dataOffset, segment.dataLength,
- segment.flags)
+ segment.flags, segment.autoDefined)
return result
def get_address_for_data_offset(self, offset):
@@ -3386,7 +3388,7 @@ class BinaryView(object):
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,
- section_list[i].semantics))
+ section_list[i].semantics, section_list[i].autoDefined))
core.BNFreeSectionList(section_list, count.value)
return result
@@ -3395,7 +3397,8 @@ class BinaryView(object):
if not core.BNGetSectionByName(self.handle, name, section):
return None
result = Section(section.name, section.type, section.start, section.length, section.linkedSection,
- section.infoSection, section.infoData, section.align, section.entrySize, section.semantics)
+ section.infoSection, section.infoData, section.align, section.entrySize, section.semantics,
+ section_list.autoDefined)
core.BNFreeSection(section)
return result
diff --git a/python/function.py b/python/function.py
index 9547e34a..58bee8f4 100644
--- a/python/function.py
+++ b/python/function.py
@@ -123,6 +123,8 @@ class PossibleValueSet(object):
self.reg = arch.get_reg_name(value.value)
elif value.state == RegisterValueType.ConstantValue:
self.value = value.value
+ elif value.state == RegisterValueType.ConstantPointerValue:
+ self.value = value.value
elif value.state == RegisterValueType.StackFrameOffset:
self.offset = value.value
elif value.state == RegisterValueType.SignedRangeValue:
@@ -164,6 +166,8 @@ class PossibleValueSet(object):
return "<entry %s>" % self.reg
if self.type == RegisterValueType.ConstantValue:
return "<const %#x>" % self.value
+ if self.type == RegisterValueType.ConstantPointerValue:
+ return "<const ptr %#x>" % self.value
if self.type == RegisterValueType.StackFrameOffset:
return "<stack frame offset %#x>" % self.offset
if self.type == RegisterValueType.SignedRangeValue:
@@ -1751,6 +1755,7 @@ class InstructionBranch(object):
class InstructionInfo(object):
def __init__(self):
self.length = 0
+ self.arch_transition_by_target_addr = False
self.branch_delay = False
self.branches = []
diff --git a/python/functionrecognizer.py b/python/functionrecognizer.py
index 8514a2ee..4ac304ca 100644
--- a/python/functionrecognizer.py
+++ b/python/functionrecognizer.py
@@ -36,6 +36,7 @@ class FunctionRecognizer(object):
self._cb = core.BNFunctionRecognizer()
self._cb.context = 0
self._cb.recognizeLowLevelIL = self._cb.recognizeLowLevelIL.__class__(self._recognize_low_level_il)
+ self._cb.recognizeMediumLevelIL = self._cb.recognizeMediumLevelIL.__class__(self._recognize_medium_level_il)
@classmethod
def register_global(cls):
@@ -62,3 +63,17 @@ class FunctionRecognizer(object):
def recognize_low_level_il(self, data, func, il):
return False
+
+ def _recognize_medium_level_il(self, ctxt, data, func, il):
+ try:
+ file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(data))
+ view = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(data))
+ func = function.Function(view, handle = core.BNNewFunctionReference(func))
+ il = mediumlevelil.MediumLevelILFunction(func.arch, handle = core.BNNewMediumLevelILFunctionReference(il))
+ return self.recognize_medium_level_il(view, func, il)
+ except:
+ log.log_error(traceback.format_exc())
+ return False
+
+ def recognize_medium_level_il(self, data, func, il):
+ return False
diff --git a/python/pluginmanager.py b/python/pluginmanager.py
index 6896d699..2f293577 100644
--- a/python/pluginmanager.py
+++ b/python/pluginmanager.py
@@ -382,7 +382,6 @@ class RepositoryManager(object):
>>> mgr = RepositoryManager()
>>> mgr.add_repository(url="https://github.com/vector35/community-plugins.git",
repopath="myrepo",
- repomanifest="plugins",
localreference="master", remotereference="origin")
True
>>>
diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py
index f9758cc9..c92c249a 100644
--- a/python/scriptingprovider.py
+++ b/python/scriptingprovider.py
@@ -42,14 +42,14 @@ class _ThreadActionContext(object):
def __init__(self, func):
self.func = func
self.interpreter = None
- if "value" in dir(PythonScriptingInstance._interpreter):
+ if hasattr(PythonScriptingInstance._interpreter, "value"):
self.interpreter = PythonScriptingInstance._interpreter.value
self.__class__._actions.append(self)
self.callback = ctypes.CFUNCTYPE(None, ctypes.c_void_p)(lambda ctxt: self.execute())
def execute(self):
old_interpreter = None
- if "value" in dir(PythonScriptingInstance._interpreter):
+ if hasattr(PythonScriptingInstance._interpreter, "value"):
old_interpreter = PythonScriptingInstance._interpreter.value
PythonScriptingInstance._interpreter.value = self.interpreter
try:
@@ -380,7 +380,7 @@ class _PythonScriptingInstanceOutput(object):
def write(self, data):
interpreter = None
- if "value" in dir(PythonScriptingInstance._interpreter):
+ if hasattr(PythonScriptingInstance._interpreter, "value"):
interpreter = PythonScriptingInstance._interpreter.value
if interpreter is None:
@@ -419,7 +419,7 @@ class _PythonScriptingInstanceInput(object):
def read(self, size):
interpreter = None
- if "value" in dir(PythonScriptingInstance._interpreter):
+ if hasattr(PythonScriptingInstance._interpreter, "value"):
interpreter = PythonScriptingInstance._interpreter.value
if interpreter is None:
@@ -434,7 +434,7 @@ class _PythonScriptingInstanceInput(object):
def readline(self):
interpreter = None
- if "value" in dir(PythonScriptingInstance._interpreter):
+ if hasattr(PythonScriptingInstance._interpreter, "value"):
interpreter = PythonScriptingInstance._interpreter.value
if interpreter is None:
@@ -457,7 +457,7 @@ class PythonScriptingInstance(ScriptingInstance):
super(PythonScriptingInstance.InterpreterThread, self).__init__()
self.instance = instance
self.locals = {"__name__": "__console__", "__doc__": None, "binaryninja": sys.modules[__name__]}
- self.interpreter = code.InteractiveInterpreter(self.locals)
+ self.interpreter = code.InteractiveConsole(self.locals)
self.event = threading.Event()
self.daemon = True
@@ -484,7 +484,7 @@ class PythonScriptingInstance(ScriptingInstance):
self.code = None
self.input = ""
- self.interpreter.runsource("from binaryninja import *\n")
+ self.interpreter.push("from binaryninja import *\n")
def execute(self, code):
self.code = code
@@ -547,7 +547,8 @@ class PythonScriptingInstance(ScriptingInstance):
self.locals["current_llil"] = self.active_func.low_level_il
self.locals["current_mlil"] = self.active_func.medium_level_il
- self.interpreter.runsource(code)
+ for line in code.split("\n"):
+ self.interpreter.push(line)
if self.locals["here"] != self.active_addr:
if not self.active_view.file.navigate(self.active_view.file.view, self.locals["here"]):