summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2017-10-26 09:55:42 -0400
committerBrian Potchik <brian@vector35.com>2017-10-26 09:55:42 -0400
commitc3c9be356d686a68b73422f17ccca67286d85b21 (patch)
tree9a45adbf13c593c4124373e0d3c263348c635931 /python
parent7cbb40a71ffb2583862191b7999e436807f9a0e8 (diff)
parent77e09a2d02efbb2d6aa9758b503e37cbe7655f7f (diff)
Merge branch 'dev'
Diffstat (limited to 'python')
-rw-r--r--python/__init__.py7
-rw-r--r--python/basicblock.py2
-rw-r--r--python/binaryview.py71
-rw-r--r--python/update.py2
4 files changed, 75 insertions, 7 deletions
diff --git a/python/__init__.py b/python/__init__.py
index f4a8fac8..729e4f8a 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -21,6 +21,7 @@
import atexit
import sys
+from time import gmtime
# Binary Ninja components
import _binaryninjacore as core
@@ -147,6 +148,12 @@ core_version = core.BNGetVersionString()
core_build_id = core.BNGetBuildId()
'''Build ID'''
+core_serial = core.BNGetSerialNumber()
+'''Serial Number'''
+
+core_expires = gmtime(core.BNGetLicenseExpirationTime())
+'''License Expiration'''
+
core_product = core.BNGetProduct()
'''Product string from the license file'''
diff --git a/python/basicblock.py b/python/basicblock.py
index 72f31876..26db925d 100644
--- a/python/basicblock.py
+++ b/python/basicblock.py
@@ -140,7 +140,7 @@ class BasicBlock(object):
target = self._create_instance(self.view, core.BNNewBasicBlockReference(edges[i].target))
else:
target = None
- result.append(BasicBlockEdge(branch_type, self, target, edges[i].backEdge))
+ result.append(BasicBlockEdge(branch_type, target, self, edges[i].backEdge))
core.BNFreeBasicBlockEdgeList(edges, count.value)
return result
diff --git a/python/binaryview.py b/python/binaryview.py
index d002b38f..9304d412 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -88,10 +88,15 @@ class BinaryDataNotification(object):
class StringReference(object):
- def __init__(self, string_type, start, length):
+ def __init__(self, bv, string_type, start, length):
self.type = string_type
self.start = start
self.length = length
+ self.view = bv
+
+ @property
+ def value(self):
+ return self.view.read(self.start, self.length)
def __repr__(self):
return "<%s: %#x, len %#x>" % (self.type, self.start, self.length)
@@ -408,6 +413,18 @@ class Segment(object):
self.flags = flags
@property
+ def executable(self):
+ return (self.flags & SegmentFlag.SegmentExecutable) != 0
+
+ @property
+ def writable(self):
+ return (self.flags & SegmentFlag.SegmentWritable) != 0
+
+ @property
+ def readable(self):
+ return (self.flags & SegmentFlag.SegmentReadable) != 0
+
+ @property
def end(self):
return self.start + self.length
@@ -416,9 +433,9 @@ class Segment(object):
def __repr__(self):
return "<segment: %#x-%#x, %s%s%s>" % (self.start, self.end,
- "r" if (self.flags & SegmentFlag.SegmentReadable) != 0 else "-",
- "w" if (self.flags & SegmentFlag.SegmentWritable) != 0 else "-",
- "x" if (self.flags & SegmentFlag.SegmentExecutable) != 0 else "-")
+ "r" if self.readable else "-",
+ "w" if self.writable else "-",
+ "x" if self.executable else "-")
class Section(object):
@@ -659,6 +676,50 @@ class BinaryView(object):
"""
_BinaryViewAssociatedDataStore.set_default(name, value)
+ @property
+ def basic_blocks(self):
+ """A generator of all BasicBlock objects in the BinaryView"""
+ for func in self:
+ for block in func.basic_blocks:
+ yield block
+
+ @property
+ def llil_basic_blocks(self):
+ """A generator of all LowLevelILBasicBlock objects in the BinaryView"""
+ for func in self:
+ for il_block in func.low_level_il.basic_blocks:
+ yield il_block
+
+ @property
+ def mlil_basic_blocks(self):
+ """A generator of all MediumLevelILBasicBlock objects in the BinaryView"""
+ for func in self:
+ for il_block in func.medium_level_il.basic_blocks:
+ yield il_block
+
+ @property
+ def instructions(self):
+ """A generator of instruction tokens and their start addresses"""
+ for block in self.basic_blocks:
+ start = block.start
+ for i in block:
+ yield (i[0], start)
+ start += i[1]
+
+ @property
+ def llil_instructions(self):
+ """A generator of llil instructions"""
+ for block in self.llil_basic_blocks:
+ for i in block:
+ yield i
+
+ @property
+ def mlil_instructions(self):
+ """A generator of mlil instructions"""
+ for block in self.mlil_basic_blocks:
+ for i in block:
+ yield i
+
def __del__(self):
for i in self.notifications.values():
i._unregister()
@@ -2601,7 +2662,7 @@ class BinaryView(object):
strings = core.BNGetStringsInRange(self.handle, start, length, count)
result = []
for i in xrange(0, count.value):
- result.append(StringReference(StringType(strings[i].type), strings[i].start, strings[i].length))
+ result.append(StringReference(self, StringType(strings[i].type), strings[i].start, strings[i].length))
core.BNFreeStringReferenceList(strings)
return result
diff --git a/python/update.py b/python/update.py
index be6962d7..1eb8ea61 100644
--- a/python/update.py
+++ b/python/update.py
@@ -154,7 +154,7 @@ class UpdateChannel(object):
def updates_available(self):
"""Whether updates are available (read-only)"""
errors = ctypes.c_char_p()
- result = core.BNAreUpdatesAvailable(self.name, errors)
+ result = core.BNAreUpdatesAvailable(self.name, None, None, errors)
if errors:
error_str = errors.value
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))