summaryrefslogtreecommitdiff
path: root/python/binaryview.py
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/binaryview.py
parent7cbb40a71ffb2583862191b7999e436807f9a0e8 (diff)
parent77e09a2d02efbb2d6aa9758b503e37cbe7655f7f (diff)
Merge branch 'dev'
Diffstat (limited to 'python/binaryview.py')
-rw-r--r--python/binaryview.py71
1 files changed, 66 insertions, 5 deletions
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