summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2020-04-11 22:22:12 -0400
committerRusty Wagner <rusty@vector35.com>2020-04-17 14:20:33 -0400
commitbe72df48408a4f3ae7cd92e9a89adf04d43025bf (patch)
treec3729612296f2622bcae61a45c7c69d9a1b3daa9 /python
parent9c1577c370d76b1797d55176cb59a10666b6ef2f (diff)
Remove old linear view implementation
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py85
-rw-r--r--python/lineardisassembly.py40
2 files changed, 24 insertions, 101 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index e9a8cca8..3d2bf78c 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -4414,13 +4414,13 @@ class BinaryView(object):
def get_linear_disassembly_position_at(self, addr, settings=None):
"""
- ``get_linear_disassembly_position_at`` instantiates a :py:class:`LinearDisassemblyPosition <binaryninja.lineardisassembly.LinearDisassemblyPosition>` object for use in
+ ``get_linear_disassembly_position_at`` instantiates a :py:class:`LinearViewCursor <binaryninja.lineardisassembly.LinearViewCursor>` object for use in
:py:meth:`get_previous_linear_disassembly_lines` or :py:meth:`get_next_linear_disassembly_lines`.
:param int addr: virtual address of linear disassembly position
:param DisassemblySettings settings: an instantiated :py:class:`DisassemblySettings` object, defaults to None which will use default settings
- :return: An instantiated :py:class:`LinearDisassemblyPosition` object for the provided virtual address
- :rtype: LinearDisassemblyPosition
+ :return: An instantiated :py:class:`LinearViewCursor` object for the provided virtual address
+ :rtype: LinearViewCursor
:Example:
>>> settings = DisassemblySettings()
@@ -4432,65 +4432,17 @@ class BinaryView(object):
"""
if settings is not None:
settings = settings.handle
- pos = core.BNGetLinearDisassemblyPositionForAddress(self.handle, addr, settings)
- func = None
- block = None
- if pos.function:
- func = binaryninja.function.Function(self, pos.function)
- if pos.block:
- block = basicblock.BasicBlock(pos.block, self)
- return lineardisassembly.LinearDisassemblyPosition(func, block, pos.address)
-
- def _get_linear_disassembly_lines(self, api, pos, settings=None):
- pos_obj = core.BNLinearDisassemblyPosition()
- pos_obj.function = None
- pos_obj.block = None
- pos_obj.address = pos.address
- if pos.function is not None:
- pos_obj.function = core.BNNewFunctionReference(pos.function.handle)
- if pos.block is not None:
- pos_obj.block = core.BNNewBasicBlockReference(pos.block.handle)
-
- if settings is not None:
- settings = settings.handle
-
- count = ctypes.c_ulonglong(0)
- lines = api(self.handle, pos_obj, settings, count)
-
- result = []
- for i in range(0, count.value):
- func = None
- block = None
- if lines[i].function:
- func = binaryninja.function.Function(self, core.BNNewFunctionReference(lines[i].function))
- if lines[i].block:
- block = basicblock.BasicBlock(core.BNNewBasicBlockReference(lines[i].block), self)
- color = highlight.HighlightColor._from_core_struct(lines[i].contents.highlight)
- addr = lines[i].contents.addr
- tokens = binaryninja.function.InstructionTextToken.get_instruction_lines(lines[i].contents.tokens, lines[i].contents.count)
- contents = binaryninja.function.DisassemblyTextLine(tokens, addr, color = color)
- result.append(lineardisassembly.LinearDisassemblyLine(lines[i].type, func, block, contents))
-
- func = None
- block = None
- if pos_obj.function:
- func = binaryninja.function.Function(self, pos_obj.function)
- if pos_obj.block:
- block = basicblock.BasicBlock(pos_obj.block, self)
- pos.function = func
- pos.block = block
- pos.address = pos_obj.address
-
- core.BNFreeLinearDisassemblyLines(lines, count.value)
- return result
+ pos = lineardisassembly.LinearViewCursor(lineardisassembly.LinearViewObject.disassembly_by_block(self, settings))
+ pos.seek_to_address(addr)
+ return pos
def get_previous_linear_disassembly_lines(self, pos, settings=None):
"""
``get_previous_linear_disassembly_lines`` retrieves a list of :py:class:`LinearDisassemblyLine` objects for the
- previous disassembly lines, and updates the LinearDisassemblyPosition passed in. This function can be called
+ previous disassembly lines, and updates the LinearViewCursor passed in. This function can be called
repeatedly to get more lines of linear disassembly.
- :param LinearDisassemblyPosition pos: Position to start retrieving linear disassembly lines from
+ :param LinearViewCursor pos: Position to start retrieving linear disassembly lines from
:param DisassemblySettings settings: DisassemblySettings display settings for the linear disassembly, defaults to None which will use default settings
:return: a list of :py:class:`LinearDisassemblyLine` objects for the previous lines.
:Example:
@@ -4502,15 +4454,20 @@ class BinaryView(object):
>>> bv.get_previous_linear_disassembly_lines(pos, settings)
[<0x10001483: xor eax, eax {0x0}>, ... , <0x10001488: >]
"""
- return self._get_linear_disassembly_lines(core.BNGetPreviousLinearDisassemblyLines, pos, settings)
+ result = []
+ while len(result) == 0:
+ if not pos.previous():
+ return result
+ result = pos.lines
+ return result
def get_next_linear_disassembly_lines(self, pos, settings=None):
"""
``get_next_linear_disassembly_lines`` retrieves a list of :py:class:`LinearDisassemblyLine` objects for the
- next disassembly lines, and updates the LinearDisassemblyPosition passed in. This function can be called
+ next disassembly lines, and updates the LinearViewCursor passed in. This function can be called
repeatedly to get more lines of linear disassembly.
- :param LinearDisassemblyPosition pos: Position to start retrieving linear disassembly lines from
+ :param LinearViewCursor pos: Position to start retrieving linear disassembly lines from
:param DisassemblySettings settings: DisassemblySettings display settings for the linear disassembly, defaults to None which will use default settings
:return: a list of :py:class:`LinearDisassemblyLine` objects for the next lines.
:Example:
@@ -4523,7 +4480,12 @@ class BinaryView(object):
[<0x10001488: push dword [ebp+0x10 {arg_c}]>, ... , <0x1000149a: >]
>>>
"""
- return self._get_linear_disassembly_lines(core.BNGetNextLinearDisassemblyLines, pos, settings)
+ result = []
+ while len(result) == 0:
+ result = pos.lines
+ if not pos.next():
+ return result
+ return result
def get_linear_disassembly(self, settings=None):
"""
@@ -4552,7 +4514,8 @@ class BinaryView(object):
self._settings = settings
def __iter__(self):
- pos = self._view.get_linear_disassembly_position_at(self._view.start, self.settings)
+ pos = lineardisassembly.LinearViewCursor(lineardisassembly.LinearViewObject.disassembly_by_block(
+ self.view, self.settings))
while True:
lines = self._view.get_next_linear_disassembly_lines(pos, self.settings)
if len(lines) == 0:
diff --git a/python/lineardisassembly.py b/python/lineardisassembly.py
index 24574e48..9a94b08b 100644
--- a/python/lineardisassembly.py
+++ b/python/lineardisassembly.py
@@ -28,46 +28,6 @@ from binaryninja import basicblock
from binaryninja.enums import LinearViewObjectIdentifierType
-class LinearDisassemblyPosition(object):
- """
- ``class LinearDisassemblyPosition`` is a helper object containing the position of the current Linear Disassembly
-
- .. note:: This object should not be instantiated directly. Rather call \
- :py:meth:`get_linear_disassembly_position_at <binaryninja.binaryview.BinaryView.get_linear_disassembly_position_at>` which instantiates this object.
- """
- def __init__(self, func, block, addr):
- self._function = func
- self._block = block
- self._address = addr
-
- @property
- def function(self):
- """ """
- return self._function
-
- @function.setter
- def function(self, value):
- self._function = value
-
- @property
- def block(self):
- """ """
- return self._block
-
- @block.setter
- def block(self, value):
- self._block = value
-
- @property
- def address(self):
- """ """
- return self._address
-
- @address.setter
- def address(self, value):
- self._address = value
-
-
class LinearDisassemblyLine(object):
def __init__(self, line_type, func, block, contents):
self.type = line_type