summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJordan Wiens <jordan@psifertex.com>2019-06-08 23:46:19 -0400
committerJordan Wiens <jordan@psifertex.com>2019-06-08 23:46:19 -0400
commit3c7a00172b3b86add668257ca35b873fc85a7017 (patch)
tree73fa2eadacb5b8722258c159076bf48082eb607e /python
parentef4e70f68d8c0855bcc64ad49f8f47a78dd3552a (diff)
final refactor for missing parameters
Diffstat (limited to 'python')
-rw-r--r--python/architecture.py7
-rw-r--r--python/interaction.py530
-rw-r--r--python/lineardisassembly.py94
-rw-r--r--python/lowlevelil.py788
-rw-r--r--python/mediumlevelil.py426
-rw-r--r--python/platform.py13
-rw-r--r--python/plugin.py185
-rw-r--r--python/settings.py53
-rw-r--r--python/transform.py25
-rw-r--r--python/types.py408
-rw-r--r--python/undoaction.py11
-rw-r--r--python/update.py97
12 files changed, 2013 insertions, 624 deletions
diff --git a/python/architecture.py b/python/architecture.py
index eabcbaa0..79ba6185 100644
--- a/python/architecture.py
+++ b/python/architecture.py
@@ -1289,6 +1289,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
Deprecated method provided for compatibility. Architecture plugins should override :func:`is_never_branch_patch_available`.
.. note:: Architecture subclasses should implement this method.
+
.. warning:: This method should never be called directly.
:param str data: bytes to be checked
@@ -1420,7 +1421,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
.. note:: Architecture subclasses should implement this method.
- .. note :: The instruction info object should always set the InstructionInfo.length to the instruction length, \
+ .. note:: The instruction info object should always set the InstructionInfo.length to the instruction length, \
and the branches of the proper types should be added if the instruction is a branch.
If the instruction is a branch instruction architecture plugins should add a branch of the proper type:
@@ -1776,7 +1777,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
Architecture plugins can override this method to provide assembler functionality. This can be done by
simply shelling out to an assembler like yasm or llvm-mc, since this method isn't performance sensitive.
- .. note :: It is important that the assembler used accepts a syntax identical to the one emitted by the \
+ .. note:: It is important that the assembler used accepts a syntax identical to the one emitted by the \
disassembler. This will prevent confusing the user.
If there is an error in the input assembly, this function should raise a ValueError (with a reasonable error message).
@@ -2284,7 +2285,7 @@ class CoreArchitecture(Architecture):
``get_instruction_info`` returns an InstructionInfo object for the instruction at the given virtual address
``addr`` with data ``data``.
- .. note :: The instruction info object should always set the InstructionInfo.length to the instruction length, \
+ .. note:: The instruction info object should always set the InstructionInfo.length to the instruction length, \
and the branches of the proper types should be added if the instruction is a branch.
:param str data: max_instruction_length bytes from the binary at virtual address ``addr``
diff --git a/python/interaction.py b/python/interaction.py
index e9528397..7e90e2ae 100644
--- a/python/interaction.py
+++ b/python/interaction.py
@@ -37,11 +37,11 @@ class LabelField(object):
``LabelField`` adds a text label to the display.
"""
def __init__(self, text):
- self.text = text
+ self._text = text
def _fill_core_struct(self, value):
value.type = FormInputFieldType.LabelFormField
- value.prompt = self.text
+ value.prompt = self._text
def _fill_core_result(self, value):
pass
@@ -49,6 +49,15 @@ class LabelField(object):
def _get_result(self, value):
pass
+ @property
+ def text(self):
+ """ """
+ return self._text
+
+ @text.setter
+ def text(self, value):
+ self._text = value
+
class SeparatorField(object):
"""
@@ -69,18 +78,36 @@ class TextLineField(object):
``TextLineField`` Adds prompt for text string input. Result is stored in self.result as a string on completion.
"""
def __init__(self, prompt):
- self.prompt = prompt
- self.result = None
+ self._prompt = prompt
+ self._result = None
def _fill_core_struct(self, value):
value.type = FormInputFieldType.TextLineFormField
- value.prompt = self.prompt
+ value.prompt = self._prompt
def _fill_core_result(self, value):
- value.stringResult = core.BNAllocString(str(self.result))
+ value.stringResult = core.BNAllocString(str(self._result))
def _get_result(self, value):
- self.result = value.stringResult
+ self._result = value.stringResult
+
+ @property
+ def prompt(self):
+ """ """
+ return self._prompt
+
+ @prompt.setter
+ def prompt(self, value):
+ self._prompt = value
+
+ @property
+ def result(self):
+ """ """
+ return self._result
+
+ @result.setter
+ def result(self, value):
+ self._result = value
class MultilineTextField(object):
@@ -89,18 +116,36 @@ class MultilineTextField(object):
as a string. This option is not supported on the command-line.
"""
def __init__(self, prompt):
- self.prompt = prompt
- self.result = None
+ self._prompt = prompt
+ self._result = None
def _fill_core_struct(self, value):
value.type = FormInputFieldType.MultilineTextFormField
- value.prompt = self.prompt
+ value.prompt = self._prompt
def _fill_core_result(self, value):
- value.stringResult = core.BNAllocString(str(self.result))
+ value.stringResult = core.BNAllocString(str(self._result))
def _get_result(self, value):
- self.result = value.stringResult
+ self._result = value.stringResult
+
+ @property
+ def prompt(self):
+ """ """
+ return self._prompt
+
+ @prompt.setter
+ def prompt(self, value):
+ self._prompt = value
+
+ @property
+ def result(self):
+ """ """
+ return self._result
+
+ @result.setter
+ def result(self, value):
+ self._result = value
class IntegerField(object):
@@ -108,18 +153,36 @@ class IntegerField(object):
``IntegerField`` add prompt for integer. Result is stored in self.result as an int.
"""
def __init__(self, prompt):
- self.prompt = prompt
- self.result = None
+ self._prompt = prompt
+ self._result = None
def _fill_core_struct(self, value):
value.type = FormInputFieldType.IntegerFormField
- value.prompt = self.prompt
+ value.prompt = self._prompt
def _fill_core_result(self, value):
- value.intResult = self.result
+ value.intResult = self._result
def _get_result(self, value):
- self.result = value.intResult
+ self._result = value.intResult
+
+ @property
+ def prompt(self):
+ """ """
+ return self._prompt
+
+ @prompt.setter
+ def prompt(self, value):
+ self._prompt = value
+
+ @property
+ def result(self):
+ """ """
+ return self._result
+
+ @result.setter
+ def result(self, value):
+ self._result = value
class AddressField(object):
@@ -132,24 +195,60 @@ class AddressField(object):
specified.
"""
def __init__(self, prompt, view=None, current_address=0):
- self.prompt = prompt
- self.view = view
- self.current_address = current_address
- self.result = None
+ self._prompt = prompt
+ self._view = view
+ self._current_address = current_address
+ self._result = None
def _fill_core_struct(self, value):
value.type = FormInputFieldType.AddressFormField
- value.prompt = self.prompt
+ value.prompt = self._prompt
value.view = None
- if self.view is not None:
- value.view = self.view.handle
- value.currentAddress = self.current_address
+ if self._view is not None:
+ value.view = self._view.handle
+ value.currentAddress = self._current_address
def _fill_core_result(self, value):
- value.addressResult = self.result
+ value.addressResult = self._result
def _get_result(self, value):
- self.result = value.addressResult
+ self._result = value.addressResult
+
+ @property
+ def prompt(self):
+ """ """
+ return self._prompt
+
+ @prompt.setter
+ def prompt(self, value):
+ self._prompt = value
+
+ @property
+ def view(self):
+ """ """
+ return self._view
+
+ @view.setter
+ def view(self, value):
+ self._view = value
+
+ @property
+ def current_address(self):
+ """ """
+ return self._current_address
+
+ @current_address.setter
+ def current_address(self, value):
+ self._current_address = value
+
+ @property
+ def result(self):
+ """ """
+ return self._result
+
+ @result.setter
+ def result(self, value):
+ self._result = value
class ChoiceField(object):
@@ -162,24 +261,51 @@ class ChoiceField(object):
"""
def __init__(self, prompt, choices):
- self.prompt = prompt
- self.choices = choices
- self.result = None
+ self._prompt = prompt
+ self._choices = choices
+ self._result = None
def _fill_core_struct(self, value):
value.type = FormInputFieldType.ChoiceFormField
- value.prompt = self.prompt
- choice_buf = (ctypes.c_char_p * len(self.choices))()
- for i in range(0, len(self.choices)):
- choice_buf[i] = self.choices[i].encode('charmap')
+ value.prompt = self._prompt
+ choice_buf = (ctypes.c_char_p * len(self._choices))()
+ for i in range(0, len(self._choices)):
+ choice_buf[i] = self._choices[i].encode('charmap')
value.choices = choice_buf
- value.count = len(self.choices)
+ value.count = len(self._choices)
def _fill_core_result(self, value):
- value.indexResult = self.result
+ value.indexResult = self._result
def _get_result(self, value):
- self.result = value.indexResult
+ self._result = value.indexResult
+
+ @property
+ def prompt(self):
+ """ """
+ return self._prompt
+
+ @prompt.setter
+ def prompt(self, value):
+ self._prompt = value
+
+ @property
+ def choices(self):
+ """ """
+ return self._choices
+
+ @choices.setter
+ def choices(self, value):
+ self._choices = value
+
+ @property
+ def result(self):
+ """ """
+ return self._result
+
+ @result.setter
+ def result(self, value):
+ self._result = value
class OpenFileNameField(object):
@@ -187,20 +313,47 @@ class OpenFileNameField(object):
``OpenFileNameField`` prompts the user to specify a file name to open. Result is stored in self.result as a string.
"""
def __init__(self, prompt, ext=""):
- self.prompt = prompt
- self.ext = ext
- self.result = None
+ self._prompt = prompt
+ self._ext = ext
+ self._result = None
def _fill_core_struct(self, value):
value.type = FormInputFieldType.OpenFileNameFormField
- value.prompt = self.prompt
- value.ext = self.ext
+ value.prompt = self._prompt
+ value.ext = self._ext
def _fill_core_result(self, value):
value.stringResult = core.BNAllocString(str(self.result))
def _get_result(self, value):
- self.result = value.stringResult
+ self._result = value.stringResult
+
+ @property
+ def prompt(self):
+ """ """
+ return self._prompt
+
+ @prompt.setter
+ def prompt(self, value):
+ self._prompt = value
+
+ @property
+ def ext(self):
+ """ """
+ return self._ext
+
+ @ext.setter
+ def ext(self, value):
+ self._ext = value
+
+ @property
+ def result(self):
+ """ """
+ return self._result
+
+ @result.setter
+ def result(self, value):
+ self._result = value
class SaveFileNameField(object):
@@ -208,22 +361,58 @@ class SaveFileNameField(object):
``SaveFileNameField`` prompts the user to specify a file name to save. Result is stored in self.result as a string.
"""
def __init__(self, prompt, ext="", default_name=""):
- self.prompt = prompt
- self.ext = ext
- self.default_name = default_name
- self.result = None
+ self._prompt = prompt
+ self._ext = ext
+ self._default_name = default_name
+ self._result = None
def _fill_core_struct(self, value):
value.type = FormInputFieldType.SaveFileNameFormField
- value.prompt = self.prompt
- value.ext = self.ext
- value.defaultName = self.default_name
+ value.prompt = self._prompt
+ value.ext = self._ext
+ value.defaultName = self._default_name
def _fill_core_result(self, value):
- value.stringResult = core.BNAllocString(str(self.result))
+ value.stringResult = core.BNAllocString(str(self._result))
def _get_result(self, value):
- self.result = value.stringResult
+ self._result = value.stringResult
+
+ @property
+ def prompt(self):
+ """ """
+ return self._prompt
+
+ @prompt.setter
+ def prompt(self, value):
+ self._prompt = value
+
+ @property
+ def ext(self):
+ """ """
+ return self._ext
+
+ @ext.setter
+ def ext(self, value):
+ self._ext = value
+
+ @property
+ def default_name(self):
+ """ """
+ return self._default_name
+
+ @default_name.setter
+ def default_name(self, value):
+ self._default_name = value
+
+ @property
+ def result(self):
+ """ """
+ return self._result
+
+ @result.setter
+ def result(self, value):
+ self._result = value
class DirectoryNameField(object):
@@ -232,20 +421,47 @@ class DirectoryNameField(object):
a string.
"""
def __init__(self, prompt, default_name=""):
- self.prompt = prompt
- self.default_name = default_name
- self.result = None
+ self._prompt = prompt
+ self._default_name = default_name
+ self._result = None
def _fill_core_struct(self, value):
value.type = FormInputFieldType.DirectoryNameFormField
- value.prompt = self.prompt
- value.defaultName = self.default_name
+ value.prompt = self._prompt
+ value.defaultName = self._default_name
def _fill_core_result(self, value):
- value.stringResult = core.BNAllocString(str(self.result))
+ value.stringResult = core.BNAllocString(str(self._result))
def _get_result(self, value):
- self.result = value.stringResult
+ self._result = value.stringResult
+
+ @property
+ def prompt(self):
+ """ """
+ return self._prompt
+
+ @prompt.setter
+ def prompt(self, value):
+ self._prompt = value
+
+ @property
+ def default_name(self):
+ """ """
+ return self._default_name
+
+ @default_name.setter
+ def default_name(self, value):
+ self._default_name = value
+
+ @property
+ def result(self):
+ """ """
+ return self._result
+
+ @result.setter
+ def result(self, value):
+ self._result = value
class InteractionHandler(object):
@@ -495,53 +711,179 @@ class InteractionHandler(object):
class PlainTextReport(object):
def __init__(self, title, contents, view = None):
- self.view = view
- self.title = title
- self.contents = contents
+ self._view = view
+ self._title = title
+ self._contents = contents
def __repr__(self):
- return "<plaintext report: %s>" % self.title
+ return "<plaintext report: %s>" % self._title
def __str__(self):
- return self.contents
+ return self._contents
+
+ @property
+ def view(self):
+ """ """
+ return self._view
+
+ @view.setter
+ def view(self, value):
+ self._view = value
+
+ @property
+ def title(self):
+ """ """
+ return self._title
+
+ @title.setter
+ def title(self, value):
+ self._title = value
+
+ @property
+ def contents(self):
+ """ """
+ return self._contents
+
+ @contents.setter
+ def contents(self, value):
+ self._contents = value
class MarkdownReport(object):
def __init__(self, title, contents, plaintext = "", view = None):
- self.view = view
- self.title = title
- self.contents = contents
- self.plaintext = plaintext
+ self._view = view
+ self._title = title
+ self._contents = contents
+ self._plaintext = plaintext
def __repr__(self):
- return "<markdown report: %s>" % self.title
+ return "<markdown report: %s>" % self._title
def __str__(self):
- return self.contents
+ return self._contents
+
+ @property
+ def view(self):
+ """ """
+ return self._view
+
+ @view.setter
+ def view(self, value):
+ self._view = value
+
+ @property
+ def title(self):
+ """ """
+ return self._title
+
+ @title.setter
+ def title(self, value):
+ self._title = value
+
+ @property
+ def contents(self):
+ """ """
+ return self._contents
+
+ @contents.setter
+ def contents(self, value):
+ self._contents = value
+
+ @property
+ def plaintext(self):
+ """ """
+ return self._plaintext
+
+ @plaintext.setter
+ def plaintext(self, value):
+ self._plaintext = value
class HTMLReport(object):
def __init__(self, title, contents, plaintext = "", view = None):
- self.view = view
- self.title = title
- self.contents = contents
- self.plaintext = plaintext
+ self._view = view
+ self._title = title
+ self._contents = contents
+ self._plaintext = plaintext
def __repr__(self):
- return "<html report: %s>" % self.title
+ return "<html report: %s>" % self._title
def __str__(self):
- return self.contents
+ return self._contents
+
+ @property
+ def view(self):
+ """ """
+ return self._view
+
+ @view.setter
+ def view(self, value):
+ self._view = value
+
+ @property
+ def title(self):
+ """ """
+ return self._title
+
+ @title.setter
+ def title(self, value):
+ self._title = value
+
+ @property
+ def contents(self):
+ """ """
+ return self._contents
+
+ @contents.setter
+ def contents(self, value):
+ self._contents = value
+
+ @property
+ def plaintext(self):
+ """ """
+ return self._plaintext
+
+ @plaintext.setter
+ def plaintext(self, value):
+ self._plaintext = value
class FlowGraphReport(object):
def __init__(self, title, graph, view = None):
- self.view = view
- self.title = title
- self.graph = graph
+ self._view = view
+ self._title = title
+ self._graph = graph
def __repr__(self):
- return "<graph report: %s>" % self.title
+ return "<graph report: %s>" % self._title
+
+ @property
+ def view(self):
+ """ """
+ return self._view
+
+ @view.setter
+ def view(self, value):
+ self._view = value
+
+ @property
+ def title(self):
+ """ """
+ return self._title
+
+ @title.setter
+ def title(self, value):
+ self._title = value
+
+ @property
+ def graph(self):
+ """ """
+ return self._graph
+
+ @graph.setter
+ def graph(self, value):
+ self._graph = value
class ReportCollection(object):
@@ -612,9 +954,9 @@ class ReportCollection(object):
def markdown_to_html(contents):
"""
- ``markdown_to_html`` converts the provided markdown to HTML.
+ ``markdown_to_html`` converts the provided markdown to HTML
- :param string contents: Markdown contents to convert to HTML.
+ :param string contents: Markdown contents to convert to HTML
:rtype: string
:Example:
>>> markdown_to_html("##Yay")
@@ -625,12 +967,12 @@ def markdown_to_html(contents):
def show_plain_text_report(title, contents):
"""
- ``show_plain_text_report`` displays contents to the user in the UI or on the command-line.
+ ``show_plain_text_report`` displays contents to the user in the UI or on the command-line
- Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line
+ Note: This API functions differently on the command-line vs the UI. In the UI, a pop-up is used. On the command-line,
a simple text prompt is used.
- :param str title: title to display in the UI pop-up.
+ :param str title: title to display in the UI pop-up
:param str contents: plaintext contents to display
:rtype: None
:Example:
@@ -680,7 +1022,7 @@ def show_html_report(title, contents, plaintext=""):
def show_graph_report(title, graph):
"""
- ``show_graph_report`` displays a flow graph in UI applications.
+ ``show_graph_report`` displays a flow graph in UI applications
Note: This API function will have no effect outside the UI.
@@ -696,7 +1038,7 @@ def show_graph_report(title, graph):
def show_report_collection(title, reports):
"""
- ``show_report_collection`` displays multiple reports in UI applications.
+ ``show_report_collection`` displays multiple reports in UI applications
Note: This API function will have no effect outside the UI.
@@ -708,7 +1050,7 @@ def show_report_collection(title, reports):
def get_text_line_input(prompt, title):
"""
- ``get_text_line_input`` prompts the user to input a string with the given prompt and title.
+ ``get_text_line_input`` prompts the user to input a string with the given prompt and title
Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line
a simple text prompt is used.
@@ -731,7 +1073,7 @@ def get_text_line_input(prompt, title):
def get_int_input(prompt, title):
"""
- ``get_int_input`` prompts the user to input a integer with the given prompt and title.
+ ``get_int_input`` prompts the user to input a integer with the given prompt and title
Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line
a simple text prompt is used.
@@ -752,7 +1094,7 @@ def get_int_input(prompt, title):
def get_address_input(prompt, title):
"""
- ``get_address_input`` prompts the user for an address with the given prompt and title.
+ ``get_address_input`` prompts the user for an address with the given prompt and title
Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line
a simple text prompt is used.
@@ -773,7 +1115,7 @@ def get_address_input(prompt, title):
def get_choice_input(prompt, title, choices):
"""
- ``get_choice_input`` prompts the user to select the one of the provided choices.
+ ``get_choice_input`` prompts the user to select the one of the provided choices
Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line
a simple text prompt is used. The UI uses a combo box.
@@ -802,7 +1144,7 @@ def get_choice_input(prompt, title, choices):
def get_open_filename_input(prompt, ext=""):
"""
- ``get_open_filename_input`` prompts the user for a file name to open.
+ ``get_open_filename_input`` prompts the user for a file name to open
Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line
a simple text prompt is used. The UI uses the native window pop-up for file selection.
@@ -825,7 +1167,7 @@ def get_open_filename_input(prompt, ext=""):
def get_save_filename_input(prompt, ext="", default_name=""):
"""
``get_save_filename_input`` prompts the user for a file name to save as, optionally providing a file extension and
- default_name.
+ default_name
Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line
a simple text prompt is used. The UI uses the native window pop-up for file selection.
@@ -848,7 +1190,7 @@ def get_save_filename_input(prompt, ext="", default_name=""):
def get_directory_name_input(prompt, default_name=""):
"""
- ``get_directory_name_input`` prompts the user for a directory name to save as, optionally providing a default_name.
+ ``get_directory_name_input`` prompts the user for a directory name to save as, optionally providing a default_name
Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line a simple text prompt is used. The UI uses the native window pop-up for file selection.
diff --git a/python/lineardisassembly.py b/python/lineardisassembly.py
index d88c1e8f..517e64c4 100644
--- a/python/lineardisassembly.py
+++ b/python/lineardisassembly.py
@@ -21,27 +21,99 @@
class LinearDisassemblyPosition(object):
"""
- ``class LinearDisassemblyPosition`` is a helper object containing the position of the current Linear Disassembly.
+ ``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` which instantiates this object.
"""
def __init__(self, func, block, addr):
- self.function = func
- self.block = block
- self.address = 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, line_offset, contents):
- self.type = line_type
- self.function = func
- self.block = block
- self.line_offset = line_offset
- self.contents = contents
+ self._type = line_type
+ self._function = func
+ self._block = block
+ self._line_offset = line_offset
+ self._contents = contents
def __str__(self):
- return str(self.contents)
+ return str(self._contents)
def __repr__(self):
- return repr(self.contents)
+ return repr(self._contents)
+
+ @property
+ def type(self):
+ """ """
+ return self._type
+
+ @type.setter
+ def type(self, value):
+ self._type = value
+
+ @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 line_offset(self):
+ """ """
+ return self._line_offset
+
+ @line_offset.setter
+ def line_offset(self, value):
+ self._line_offset = value
+
+ @property
+ def contents(self):
+ """ """
+ return self.contents
+
+ @contents.setter
+ def contents(self, value):
+ self.contents = value
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index ff5829e7..472dac10 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -42,171 +42,459 @@ class LowLevelILLabel(object):
class ILRegister(object):
def __init__(self, arch, reg):
- self.arch = arch
- self.index = reg
- self.temp = (self.index & 0x80000000) != 0
- if self.temp:
- self.name = "temp%d" % (self.index & 0x7fffffff)
+ self._arch = arch
+ self._index = reg
+ self._temp = (self._index & 0x80000000) != 0
+ if self._temp:
+ self._name = "temp%d" % (self._index & 0x7fffffff)
else:
- self.name = self.arch.get_reg_name(self.index)
+ self._name = self._arch.get_reg_name(self._index)
@property
def info(self):
- return self.arch.regs[self.name]
+ return self._arch.regs[self._name]
def __str__(self):
- return self.name
+ return self._name
def __repr__(self):
- return self.name
+ return self._name
def __eq__(self, other):
if not isinstance(other, type(self)):
return False
return self.info == other.info
+ @property
+ def arch(self):
+ """ """
+ return self._arch
+
+ @arch.setter
+ def arch(self, value):
+ self._arch = value
+
+ @property
+ def index(self):
+ """ """
+ return self._index
+
+ @index.setter
+ def index(self, value):
+ self._index = value
+
+ @property
+ def temp(self):
+ """ """
+ return self._temp
+
+ @temp.setter
+ def temp(self, value):
+ self._temp = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
+
class ILRegisterStack(object):
def __init__(self, arch, reg_stack):
- self.arch = arch
- self.index = reg_stack
- self.name = self.arch.get_reg_stack_name(self.index)
+ self._arch = arch
+ self._index = reg_stack
+ self._name = self._arch.get_reg_stack_name(self._index)
@property
def info(self):
- return self.arch.reg_stacks[self.name]
+ return self._arch.reg_stacks[self._name]
def __str__(self):
- return self.name
+ return self._name
def __repr__(self):
- return self.name
+ return self._name
def __eq__(self, other):
if not isinstance(other, type(self)):
return False
return self.info == other.info
+ @property
+ def arch(self):
+ """ """
+ return self._arch
+
+ @arch.setter
+ def arch(self, value):
+ self._arch = value
+
+ @property
+ def index(self):
+ """ """
+ return self._index
+
+ @index.setter
+ def index(self, value):
+ self._index = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
+
class ILFlag(object):
def __init__(self, arch, flag):
- self.arch = arch
- self.index = flag
- self.temp = (self.index & 0x80000000) != 0
- if self.temp:
- self.name = "cond:%d" % (self.index & 0x7fffffff)
+ self._arch = arch
+ self._index = flag
+ self._temp = (self._index & 0x80000000) != 0
+ if self._temp:
+ self._name = "cond:%d" % (self._index & 0x7fffffff)
else:
- self.name = self.arch.get_flag_name(self.index)
+ self._name = self._arch.get_flag_name(self._index)
def __str__(self):
- return self.name
+ return self._name
def __repr__(self):
- return self.name
+ return self._name
+
+ @property
+ def arch(self):
+ """ """
+ return self._arch
+
+ @arch.setter
+ def arch(self, value):
+ self._arch = value
+
+ @property
+ def index(self):
+ """ """
+ return self._index
+
+ @index.setter
+ def index(self, value):
+ self._index = value
+
+ @property
+ def temp(self):
+ """ """
+ return self._temp
+
+ @temp.setter
+ def temp(self, value):
+ self._temp = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
class ILSemanticFlagClass(object):
def __init__(self, arch, sem_class):
- self.arch = arch
- self.index = sem_class
- self.name = self.arch.get_semantic_flag_class_name(self.index)
+ self._arch = arch
+ self._index = sem_class
+ self._name = self._arch.get_semantic_flag_class_name(self._index)
def __str__(self):
- return self.name
+ return self._name
def __repr__(self):
- return self.name
+ return self._name
def __eq__(self, other):
if not isinstance(other, type(self)):
return False
- return self.index == other.index
+ return self._index == other._index
+
+ @property
+ def arch(self):
+ """ """
+ return self._arch
+
+ @arch.setter
+ def arch(self, value):
+ self._arch = value
+
+ @property
+ def index(self):
+ """ """
+ return self._index
+
+ @index.setter
+ def index(self, value):
+ self._index = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
class ILSemanticFlagGroup(object):
def __init__(self, arch, sem_group):
- self.arch = arch
- self.index = sem_group
- self.name = self.arch.get_semantic_flag_group_name(self.index)
+ self._arch = arch
+ self._index = sem_group
+ self._name = self._arch.get_semantic_flag_group_name(self._index)
def __str__(self):
- return self.name
+ return self._name
def __repr__(self):
- return self.name
+ return self._name
def __eq__(self, other):
if not isinstance(other, type(self)):
return False
- return self.index == other.index
+ return self._index == other.index
+
+ @property
+ def arch(self):
+ """ """
+ return self._arch
+
+ @arch.setter
+ def arch(self, value):
+ self._arch = value
+
+ @property
+ def index(self):
+ """ """
+ return self._index
+
+ @index.setter
+ def index(self, value):
+ self._index = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
class ILIntrinsic(object):
def __init__(self, arch, intrinsic):
- self.arch = arch
- self.index = intrinsic
- self.name = self.arch.get_intrinsic_name(self.index)
- if self.name in self.arch.intrinsics:
- self.inputs = self.arch.intrinsics[self.name].inputs
- self.outputs = self.arch.intrinsics[self.name].outputs
+ self._arch = arch
+ self._index = intrinsic
+ self._name = self._arch.get_intrinsic_name(self._index)
+ if self._name in self._arch.intrinsics:
+ self._inputs = self._arch.intrinsics[self._name].inputs
+ self._outputs = self._arch.intrinsics[self._name].outputs
def __str__(self):
- return self.name
+ return self._name
def __repr__(self):
- return self.name
+ return self._name
def __eq__(self, other):
if not isinstance(other, type(self)):
return False
- return self.index == other.index
+ return self._index == other.index
+
+ @property
+ def arch(self):
+ """ """
+ return self._arch
+
+ @arch.setter
+ def arch(self, value):
+ self._arch = value
+
+ @property
+ def index(self):
+ """ """
+ return self._index
+
+ @index.setter
+ def index(self, value):
+ self._index = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
+
+ @property
+ def inputs(self):
+ """``inputs`` is only available if the IL intrinsic is an Architecture intrinsic """
+ return self._inputs
+
+ @inputs.setter
+ def inputs(self, value):
+ self._inputs = value
+
+ @property
+ def outputs(self):
+ """``outputs`` is only available if the IL intrinsic is an Architecture intrinsic """
+ return self._outputs
+
+ @outputs.setter
+ def outputs(self, value):
+ self._outputs = value
class SSARegister(object):
def __init__(self, reg, version):
- self.reg = reg
- self.version = version
+ self._reg = reg
+ self._version = version
def __repr__(self):
- return "<ssa %s version %d>" % (repr(self.reg), self.version)
+ return "<ssa %s version %d>" % (repr(self._reg), self._version)
+
+ @property
+ def reg(self):
+ """ """
+ return self._reg
+
+ @reg.setter
+ def reg(self, value):
+ self._reg = value
+
+ @property
+ def version(self):
+ """ """
+ return self._version
+
+ @version.setter
+ def version(self, value):
+ self._version = value
class SSARegisterStack(object):
def __init__(self, reg_stack, version):
- self.reg_stack = reg_stack
- self.version = version
+ self._reg_stack = reg_stack
+ self._version = version
def __repr__(self):
- return "<ssa %s version %d>" % (repr(self.reg_stack), self.version)
+ return "<ssa %s version %d>" % (repr(self._reg_stack), self._version)
+
+ @property
+ def reg_stack(self):
+ """ """
+ return self._reg_stack
+
+ @reg_stack.setter
+ def reg_stack(self, value):
+ self._reg_stack = value
+
+ @property
+ def version(self):
+ """ """
+ return self._version
+
+ @version.setter
+ def version(self, value):
+ self._version = value
class SSAFlag(object):
def __init__(self, flag, version):
- self.flag = flag
- self.version = version
+ self._flag = flag
+ self._version = version
def __repr__(self):
- return "<ssa %s version %d>" % (repr(self.flag), self.version)
+ return "<ssa %s version %d>" % (repr(self._flag), self._version)
+
+ @property
+ def flag(self):
+ """ """
+ return self._flag
+
+ @flag.setter
+ def flag(self, value):
+ self._flag = value
+
+ @property
+ def version(self):
+ """ """
+ return self._version
+
+ @version.setter
+ def version(self, value):
+ self._version = value
class SSARegisterOrFlag(object):
def __init__(self, reg_or_flag, version):
- self.reg_or_flag = reg_or_flag
- self.version = version
+ self._reg_or_flag = reg_or_flag
+ self._version = version
def __repr__(self):
- return "<ssa %s version %d>" % (repr(self.reg_or_flag), self.version)
+ return "<ssa %s version %d>" % (repr(self._reg_or_flag), self._version)
+
+ @property
+ def reg_or_flag(self):
+ """ """
+ return self._reg_or_flag
+
+ @reg_or_flag.setter
+ def reg_or_flag(self, value):
+ self._reg_or_flag = value
+
+ @property
+ def version(self):
+ """ """
+ return self._version
+
+ @version.setter
+ def version(self, value):
+ self._version = value
class LowLevelILOperationAndSize(object):
def __init__(self, operation, size):
- self.operation = operation
- self.size = size
+ self._operation = operation
+ self._size = size
def __repr__(self):
- if self.size == 0:
- return "<%s>" % self.operation.name
- return "<%s %d>" % (self.operation.name, self.size)
+ if self._size == 0:
+ return "<%s>" % self._operation.name
+ return "<%s %d>" % (self._operation.name, self._size)
+
+ @property
+ def operation(self):
+ """ """
+ return self._operation
+
+ @operation.setter
+ def operation(self, value):
+ self._operation = value
+
+ @property
+ def size(self):
+ """ """
+ return self._size
+
+ @size.setter
+ def size(self, value):
+ self._size = value
class LowLevelILInstruction(object):
@@ -356,21 +644,21 @@ class LowLevelILInstruction(object):
def __init__(self, func, expr_index, instr_index=None):
instr = core.BNGetLowLevelILByIndex(func.handle, expr_index)
- self.function = func
- self.expr_index = expr_index
- self.instr_index = instr_index
- self.operation = LowLevelILOperation(instr.operation)
- self.size = instr.size
- self.address = instr.address
- self.source_operand = instr.sourceOperand
+ self._function = func
+ self._expr_index = expr_index
+ self._instr_index = instr_index
+ self._operation = LowLevelILOperation(instr.operation)
+ self._size = instr.size
+ self._address = instr.address
+ self._source_operand = instr.sourceOperand
if instr.flags == 0:
- self.flags = None
+ self._flags = None
else:
- self.flags = func.arch.get_flag_write_type_name(instr.flags)
- if self.source_operand == 0xffffffff:
- self.source_operand = None
+ self._flags = func.arch.get_flag_write_type_name(instr.flags)
+ if self._source_operand == 0xffffffff:
+ self._source_operand = None
operands = LowLevelILInstruction.ILOperations[instr.operation]
- self.operands = []
+ self._operands = []
i = 0
for operand in operands:
name, operand_type = operand
@@ -405,8 +693,8 @@ class LowLevelILInstruction(object):
i += 1
value = SSARegisterStack(reg_stack, instr.operands[i])
i += 1
- self.operands.append(value)
- self.dest = value
+ self._operands.append(value)
+ self._dest = value
value = SSARegisterStack(reg_stack, instr.operands[i])
elif operand_type == "flag":
value = ILFlag(func.arch, instr.operands[i])
@@ -505,7 +793,7 @@ class LowLevelILInstruction(object):
adjust |= ~0x80000000
value[func.arch.get_reg_stack_name(reg_stack)] = adjust
core.BNLowLevelILFreeOperandList(operand_list)
- self.operands.append(value)
+ self._operands.append(value)
self.__dict__[name] = value
i += 1
@@ -524,19 +812,19 @@ class LowLevelILInstruction(object):
def __eq__(self, value):
if not isinstance(value, type(self)):
return False
- return self.function == value.function and self.expr_index == value.expr_index
+ return self._function == value.function and self.expr_index == value.expr_index
@property
def tokens(self):
"""LLIL tokens (read-only)"""
count = ctypes.c_ulonglong()
tokens = ctypes.POINTER(core.BNInstructionTextToken)()
- if (self.instr_index is not None) and (self.function.source_function is not None):
- if not core.BNGetLowLevelILInstructionText(self.function.handle, self.function.source_function.handle,
- self.function.arch.handle, self.instr_index, tokens, count):
+ if (self._instr_index is not None) and (self._function.source_function is not None):
+ if not core.BNGetLowLevelILInstructionText(self._function.handle, self._function.source_function.handle,
+ self._function.arch.handle, self._instr_index, tokens, count):
return None
else:
- if not core.BNGetLowLevelILExprText(self.function.handle, self.function.arch.handle,
+ if not core.BNGetLowLevelILExprText(self._function.handle, self._function.arch.handle,
self.expr_index, tokens, count):
return None
result = binaryninja.function.InstructionTextToken.get_instruction_lines(tokens, count.value)
@@ -547,29 +835,29 @@ class LowLevelILInstruction(object):
def il_basic_block(self):
"""IL basic block object containing this expression (read-only) (only available on finalized functions)"""
view = None
- if self.function.source_function is not None:
- view = self.function.source_function.view
- return LowLevelILBasicBlock(view, core.BNGetLowLevelILBasicBlockForInstruction(self.function.handle, self.instr_index), self.function)
+ if self._function.source_function is not None:
+ view = self._function.source_function.view
+ return LowLevelILBasicBlock(view, core.BNGetLowLevelILBasicBlockForInstruction(self._function.handle, self._instr_index), self._function)
@property
def ssa_form(self):
"""SSA form of expression (read-only)"""
- return LowLevelILInstruction(self.function.ssa_form,
- core.BNGetLowLevelILSSAExprIndex(self.function.handle, self.expr_index))
+ return LowLevelILInstruction(self._function.ssa_form,
+ core.BNGetLowLevelILSSAExprIndex(self._function.handle, self.expr_index))
@property
def non_ssa_form(self):
"""Non-SSA form of expression (read-only)"""
- return LowLevelILInstruction(self.function.non_ssa_form,
- core.BNGetLowLevelILNonSSAExprIndex(self.function.handle, self.expr_index))
+ return LowLevelILInstruction(self._function.non_ssa_form,
+ core.BNGetLowLevelILNonSSAExprIndex(self._function.handle, self.expr_index))
@property
def medium_level_il(self):
"""Gets the medium level IL expression corresponding to this expression (may be None for eliminated instructions)"""
- expr = self.function.get_medium_level_il_expr_index(self.expr_index)
+ expr = self._function.get_medium_level_il_expr_index(self.expr_index)
if expr is None:
return None
- return binaryninja.mediumlevelil.MediumLevelILInstruction(self.function.medium_level_il, expr)
+ return binaryninja.mediumlevelil.MediumLevelILInstruction(self._function.medium_level_il, expr)
@property
def mlil(self):
@@ -578,10 +866,10 @@ class LowLevelILInstruction(object):
@property
def mapped_medium_level_il(self):
"""Gets the mapped medium level IL expression corresponding to this expression"""
- expr = self.function.get_mapped_medium_level_il_expr_index(self.expr_index)
+ expr = self._function.get_mapped_medium_level_il_expr_index(self.expr_index)
if expr is None:
return None
- return binaryninja.mediumlevelil.MediumLevelILInstruction(self.function.mapped_medium_level_il, expr)
+ return binaryninja.mediumlevelil.MediumLevelILInstruction(self._function.mapped_medium_level_il, expr)
@property
def mmlil(self):
@@ -590,23 +878,23 @@ class LowLevelILInstruction(object):
@property
def value(self):
"""Value of expression if constant or a known value (read-only)"""
- value = core.BNGetLowLevelILExprValue(self.function.handle, self.expr_index)
- result = binaryninja.function.RegisterValue(self.function.arch, value)
+ value = core.BNGetLowLevelILExprValue(self._function.handle, self.expr_index)
+ result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
@property
def possible_values(self):
"""Possible values of expression using path-sensitive static data flow analysis (read-only)"""
- value = core.BNGetLowLevelILPossibleExprValues(self.function.handle, self.expr_index)
- result = binaryninja.function.PossibleValueSet(self.function.arch, value)
+ value = core.BNGetLowLevelILPossibleExprValues(self._function.handle, self.expr_index)
+ result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@property
def prefix_operands(self):
"""All operands in the expression tree in prefix order"""
- result = [LowLevelILOperationAndSize(self.operation, self.size)]
- for operand in self.operands:
+ result = [LowLevelILOperationAndSize(self._operation, self._size)]
+ for operand in self._operands:
if isinstance(operand, LowLevelILInstruction):
result += operand.prefix_operands
else:
@@ -617,85 +905,85 @@ class LowLevelILInstruction(object):
def postfix_operands(self):
"""All operands in the expression tree in postfix order"""
result = []
- for operand in self.operands:
+ for operand in self._operands:
if isinstance(operand, LowLevelILInstruction):
result += operand.postfix_operands
else:
result.append(operand)
- result.append(LowLevelILOperationAndSize(self.operation, self.size))
+ result.append(LowLevelILOperationAndSize(self._operation, self._size))
return result
def get_reg_value(self, reg):
- reg = self.function.arch.get_reg_index(reg)
- value = core.BNGetLowLevelILRegisterValueAtInstruction(self.function.handle, reg, self.instr_index)
- result = binaryninja.function.RegisterValue(self.function.arch, value)
+ reg = self._function.arch.get_reg_index(reg)
+ value = core.BNGetLowLevelILRegisterValueAtInstruction(self._function.handle, reg, self._instr_index)
+ result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
def get_reg_value_after(self, reg):
- reg = self.function.arch.get_reg_index(reg)
- value = core.BNGetLowLevelILRegisterValueAfterInstruction(self.function.handle, reg, self.instr_index)
- result = binaryninja.function.RegisterValue(self.function.arch, value)
+ reg = self._function.arch.get_reg_index(reg)
+ value = core.BNGetLowLevelILRegisterValueAfterInstruction(self._function.handle, reg, self._instr_index)
+ result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
def get_possible_reg_values(self, reg):
- reg = self.function.arch.get_reg_index(reg)
- value = core.BNGetLowLevelILPossibleRegisterValuesAtInstruction(self.function.handle, reg, self.instr_index)
- result = binaryninja.function.PossibleValueSet(self.function.arch, value)
+ reg = self._function.arch.get_reg_index(reg)
+ value = core.BNGetLowLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index)
+ result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_reg_values_after(self, reg):
- reg = self.function.arch.get_reg_index(reg)
- value = core.BNGetLowLevelILPossibleRegisterValuesAfterInstruction(self.function.handle, reg, self.instr_index)
- result = binaryninja.function.PossibleValueSet(self.function.arch, value)
+ reg = self._function.arch.get_reg_index(reg)
+ value = core.BNGetLowLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index)
+ result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_flag_value(self, flag):
- flag = self.function.arch.get_flag_index(flag)
- value = core.BNGetLowLevelILFlagValueAtInstruction(self.function.handle, flag, self.instr_index)
- result = binaryninja.function.RegisterValue(self.function.arch, value)
+ flag = self._function.arch.get_flag_index(flag)
+ value = core.BNGetLowLevelILFlagValueAtInstruction(self._function.handle, flag, self._instr_index)
+ result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
def get_flag_value_after(self, flag):
- flag = self.function.arch.get_flag_index(flag)
- value = core.BNGetLowLevelILFlagValueAfterInstruction(self.function.handle, flag, self.instr_index)
- result = binaryninja.function.RegisterValue(self.function.arch, value)
+ flag = self._function.arch.get_flag_index(flag)
+ value = core.BNGetLowLevelILFlagValueAfterInstruction(self._function.handle, flag, self._instr_index)
+ result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
def get_possible_flag_values(self, flag):
- flag = self.function.arch.get_flag_index(flag)
- value = core.BNGetLowLevelILPossibleFlagValuesAtInstruction(self.function.handle, flag, self.instr_index)
- result = binaryninja.function.PossibleValueSet(self.function.arch, value)
+ flag = self._function.arch.get_flag_index(flag)
+ value = core.BNGetLowLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index)
+ result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_flag_values_after(self, flag):
- flag = self.function.arch.get_flag_index(flag)
- value = core.BNGetLowLevelILPossibleFlagValuesAfterInstruction(self.function.handle, flag, self.instr_index)
- result = binaryninja.function.PossibleValueSet(self.function.arch, value)
+ flag = self._function.arch.get_flag_index(flag)
+ value = core.BNGetLowLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index)
+ result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_stack_contents(self, offset, size):
- value = core.BNGetLowLevelILStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
- result = binaryninja.function.RegisterValue(self.function.arch, value)
+ value = core.BNGetLowLevelILStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index)
+ result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
def get_stack_contents_after(self, offset, size):
- value = core.BNGetLowLevelILStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
- result = binaryninja.function.RegisterValue(self.function.arch, value)
+ value = core.BNGetLowLevelILStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index)
+ result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
def get_possible_stack_contents(self, offset, size):
- value = core.BNGetLowLevelILPossibleStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
- result = binaryninja.function.PossibleValueSet(self.function.arch, value)
+ value = core.BNGetLowLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index)
+ result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_stack_contents_after(self, offset, size):
- value = core.BNGetLowLevelILPossibleStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
- result = binaryninja.function.PossibleValueSet(self.function.arch, value)
+ value = core.BNGetLowLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index)
+ result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -705,6 +993,96 @@ class LowLevelILInstruction(object):
except AttributeError:
raise AttributeError("attribute '%s' is read only" % name)
+ @property
+ def function(self):
+ """ """
+ return self._function
+
+ @function.setter
+ def function(self, value):
+ self._function = value
+
+ @property
+ def expr_index(self):
+ """ """
+ return self._expr_index
+
+ @expr_index.setter
+ def expr_index(self, value):
+ self._expr_index = value
+
+ @property
+ def instr_index(self):
+ """ """
+ return self._instr_index
+
+ @instr_index.setter
+ def instr_index(self, value):
+ self._instr_index = value
+
+ @property
+ def operation(self):
+ """ """
+ return self._operation
+
+ @operation.setter
+ def operation(self, value):
+ self._operation = value
+
+ @property
+ def size(self):
+ """ """
+ return self._size
+
+ @size.setter
+ def size(self, value):
+ self._size = value
+
+ @property
+ def address(self):
+ """ """
+ return self._address
+
+ @address.setter
+ def address(self, value):
+ self._address = value
+
+ @property
+ def source_operand(self):
+ """ """
+ return self._source_operand
+
+ @source_operand.setter
+ def source_operand(self, value):
+ self._source_operand = value
+
+ @property
+ def flags(self):
+ """ """
+ return self._flags
+
+ @flags.setter
+ def flags(self, value):
+ self._flags = value
+
+ @property
+ def operands(self):
+ """ """
+ return self._operands
+
+ @operands.setter
+ def operands(self, value):
+ self._operands = value
+
+ @property
+ def dest(self):
+ """ """
+ return self._dest
+
+ @dest.setter
+ def dest(self, value):
+ self._dest = value
+
class LowLevelILExpr(object):
"""
@@ -714,7 +1092,16 @@ class LowLevelILExpr(object):
used instead.
"""
def __init__(self, index):
- self.index = index
+ self._index = index
+
+ @property
+ def index(self):
+ """ """
+ return self._index
+
+ @index.setter
+ def index(self, value):
+ self._index = value
class LowLevelILFunction(object):
@@ -746,29 +1133,29 @@ class LowLevelILFunction(object):
======================= ========== ===============================
"""
def __init__(self, arch = None, handle = None, source_func = None):
- self.arch = arch
- self.source_function = source_func
+ self._arch = arch
+ self._source_function = source_func
if handle is not None:
self.handle = core.handle_of_type(handle, core.BNLowLevelILFunction)
- if self.source_function is None:
+ if self._source_function is None:
source_handle = core.BNGetLowLevelILOwnerFunction(self.handle)
if source_handle:
- self.source_function = binaryninja.function.Function(handle = source_handle)
+ self._source_function = binaryninja.function.Function(handle = source_handle)
else:
- self.source_function = None
- if self.arch is None:
- self.arch = self.source_function.arch
+ self._source_function = None
+ if self._arch is None:
+ self._arch = self._source_function.arch
else:
- if self.arch is None:
- self.arch = self.source_function.arch
- if self.source_function is None:
+ if self._arch is None:
+ self._arch = self._source_function.arch
+ if self._source_function is None:
func_handle = None
else:
- func_handle = self.source_function.handle
+ func_handle = self._source_function.handle
self.handle = core.BNCreateLowLevelILFunction(arch.handle, func_handle)
def __hash__(self):
- return hash(('LLIL', self.source_function))
+ return hash(('LLIL', self._source_function))
def __del__(self):
if self.handle is not None:
@@ -791,11 +1178,11 @@ class LowLevelILFunction(object):
@current_address.setter
def current_address(self, value):
- core.BNLowLevelILSetCurrentAddress(self.handle, self.arch.handle, value)
+ core.BNLowLevelILSetCurrentAddress(self.handle, self._arch.handle, value)
def set_current_address(self, value, arch = None):
if arch is None:
- arch = self.arch
+ arch = self._arch
core.BNLowLevelILSetCurrentAddress(self.handle, arch.handle, value)
def set_current_source_block(self, block):
@@ -818,8 +1205,8 @@ class LowLevelILFunction(object):
blocks = core.BNGetLowLevelILBasicBlockList(self.handle, count)
result = []
view = None
- if self.source_function is not None:
- view = self.source_function.view
+ if self._source_function is not None:
+ view = self._source_function.view
for i in range(0, count.value):
result.append(LowLevelILBasicBlock(view, core.BNNewBasicBlockReference(blocks[i]), self))
core.BNFreeBasicBlockList(blocks, count.value)
@@ -838,7 +1225,7 @@ class LowLevelILFunction(object):
result = core.BNGetLowLevelILSSAForm(self.handle)
if not result:
return None
- return LowLevelILFunction(self.arch, result, self.source_function)
+ return LowLevelILFunction(self._arch, result, self._source_function)
@property
def non_ssa_form(self):
@@ -846,7 +1233,7 @@ class LowLevelILFunction(object):
result = core.BNGetLowLevelILNonSSAForm(self.handle)
if not result:
return None
- return LowLevelILFunction(self.arch, result, self.source_function)
+ return LowLevelILFunction(self._arch, result, self._source_function)
@property
def medium_level_il(self):
@@ -854,7 +1241,7 @@ class LowLevelILFunction(object):
result = core.BNGetMediumLevelILForLowLevelIL(self.handle)
if not result:
return None
- return binaryninja.mediumlevelil.MediumLevelILFunction(self.arch, result, self.source_function)
+ return binaryninja.mediumlevelil.MediumLevelILFunction(self._arch, result, self._source_function)
@property
def mlil(self):
@@ -868,7 +1255,7 @@ class LowLevelILFunction(object):
result = core.BNGetMappedMediumLevelIL(self.handle)
if not result:
return None
- return binaryninja.mediumlevelil.MediumLevelILFunction(self.arch, result, self.source_function)
+ return binaryninja.mediumlevelil.MediumLevelILFunction(self._arch, result, self._source_function)
@property
def mmlil(self):
@@ -902,8 +1289,8 @@ class LowLevelILFunction(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetLowLevelILBasicBlockList(self.handle, count)
view = None
- if self.source_function is not None:
- view = self.source_function.view
+ if self._source_function is not None:
+ view = self._source_function.view
try:
for i in range(0, count.value):
yield LowLevelILBasicBlock(view, core.BNNewBasicBlockReference(blocks[i]), self)
@@ -912,7 +1299,7 @@ class LowLevelILFunction(object):
def get_instruction_start(self, addr, arch = None):
if arch is None:
- arch = self.arch
+ arch = self._arch
result = core.BNLowLevelILGetInstructionStart(self.handle, arch.handle, addr)
if result >= core.BNGetLowLevelILInstructionCount(self.handle):
return None
@@ -934,7 +1321,7 @@ class LowLevelILFunction(object):
elif isinstance(operation, LowLevelILOperation):
operation = operation.value
if isinstance(flags, str):
- flags = self.arch.get_flag_write_type_by_name(flags)
+ flags = self._arch.get_flag_write_type_by_name(flags)
elif flags is None:
flags = 0
return LowLevelILExpr(core.BNLowLevelILAddExpr(self.handle, operation, size, flags, a, b, c, d))
@@ -991,7 +1378,7 @@ class LowLevelILFunction(object):
:return: The expression ``reg = value``
:rtype: LowLevelILExpr
"""
- reg = self.arch.get_reg_index(reg)
+ reg = self._arch.get_reg_index(reg)
return self.expr(LowLevelILOperation.LLIL_SET_REG, reg, value.index, size = size, flags = flags)
def set_reg_split(self, size, hi, lo, value, flags = 0):
@@ -1007,8 +1394,8 @@ class LowLevelILFunction(object):
:return: The expression ``hi:lo = value``
:rtype: LowLevelILExpr
"""
- hi = self.arch.get_reg_index(hi)
- lo = self.arch.get_reg_index(lo)
+ hi = self._arch.get_reg_index(hi)
+ lo = self._arch.get_reg_index(lo)
return self.expr(LowLevelILOperation.LLIL_SET_REG_SPLIT, hi, lo, value.index, size = size, flags = flags)
def set_reg_stack_top_relative(self, size, reg_stack, entry, value, flags = 0):
@@ -1024,7 +1411,7 @@ class LowLevelILFunction(object):
:return: The expression ``reg_stack[entry] = value``
:rtype: LowLevelILExpr
"""
- reg_stack = self.arch.get_reg_stack_index(reg_stack)
+ reg_stack = self._arch.get_reg_stack_index(reg_stack)
return self.expr(LowLevelILOperation.LLIL_SET_REG_STACK_REL, reg_stack, entry.index, value.index,
size = size, flags = flags)
@@ -1040,7 +1427,7 @@ class LowLevelILFunction(object):
:return: The expression ``reg_stack.push(value)``
:rtype: LowLevelILExpr
"""
- reg_stack = self.arch.get_reg_stack_index(reg_stack)
+ reg_stack = self._arch.get_reg_stack_index(reg_stack)
return self.expr(LowLevelILOperation.LLIL_REG_STACK_PUSH, reg_stack, value.index, size = size, flags = flags)
def set_flag(self, flag, value):
@@ -1052,7 +1439,7 @@ class LowLevelILFunction(object):
:return: The expression FLAG.flag = value
:rtype: LowLevelILExpr
"""
- return self.expr(LowLevelILOperation.LLIL_SET_FLAG, self.arch.get_flag_by_name(flag), value.index)
+ return self.expr(LowLevelILOperation.LLIL_SET_FLAG, self._arch.get_flag_by_name(flag), value.index)
def load(self, size, addr):
"""
@@ -1108,7 +1495,7 @@ class LowLevelILFunction(object):
:return: A register expression for the given string
:rtype: LowLevelILExpr
"""
- reg = self.arch.get_reg_index(reg)
+ reg = self._arch.get_reg_index(reg)
return self.expr(LowLevelILOperation.LLIL_REG, reg, size=size)
def reg_split(self, size, hi, lo):
@@ -1121,8 +1508,8 @@ class LowLevelILFunction(object):
:return: The expression ``hi:lo``
:rtype: LowLevelILExpr
"""
- hi = self.arch.get_reg_index(hi)
- lo = self.arch.get_reg_index(lo)
+ hi = self._arch.get_reg_index(hi)
+ lo = self._arch.get_reg_index(lo)
return self.expr(LowLevelILOperation.LLIL_REG_SPLIT, hi, lo, size=size)
def reg_stack_top_relative(self, size, reg_stack, entry):
@@ -1136,7 +1523,7 @@ class LowLevelILFunction(object):
:return: The expression ``reg_stack[entry]``
:rtype: LowLevelILExpr
"""
- reg_stack = self.arch.get_reg_stack_index(reg_stack)
+ reg_stack = self._arch.get_reg_stack_index(reg_stack)
return self.expr(LowLevelILOperation.LLIL_REG_STACK_REL, reg_stack, entry.index, size=size)
def reg_stack_pop(self, size, reg_stack):
@@ -1149,7 +1536,7 @@ class LowLevelILFunction(object):
:return: The expression ``reg_stack.pop``
:rtype: LowLevelILExpr
"""
- reg_stack = self.arch.get_reg_stack_index(reg_stack)
+ reg_stack = self._arch.get_reg_stack_index(reg_stack)
return self.expr(LowLevelILOperation.LLIL_REG_STACK_POP, reg_stack, size=size)
def const(self, size, value):
@@ -1225,7 +1612,7 @@ class LowLevelILFunction(object):
:return: A flag expression of given flag name
:rtype: LowLevelILExpr
"""
- return self.expr(LowLevelILOperation.LLIL_FLAG, self.arch.get_flag_by_name(reg))
+ return self.expr(LowLevelILOperation.LLIL_FLAG, self._arch.get_flag_by_name(reg))
def flag_bit(self, size, reg, bit):
"""
@@ -1237,7 +1624,7 @@ class LowLevelILFunction(object):
:return: A constant expression of given value and size ``FLAG.reg = bit``
:rtype: LowLevelILExpr
"""
- return self.expr(LowLevelILOperation.LLIL_FLAG_BIT, self.arch.get_flag_by_name(reg), bit, size=size)
+ return self.expr(LowLevelILOperation.LLIL_FLAG_BIT, self._arch.get_flag_by_name(reg), bit, size=size)
def add(self, size, a, b, flags=None):
"""
@@ -1731,7 +2118,7 @@ class LowLevelILFunction(object):
cond = LowLevelILFlagCondition[cond]
elif isinstance(cond, LowLevelILFlagCondition):
cond = cond.value
- class_index = self.arch.get_semantic_flag_class_index(sem_class)
+ class_index = self._arch.get_semantic_flag_class_index(sem_class)
return self.expr(LowLevelILOperation.LLIL_FLAG_COND, cond, class_index)
def flag_group(self, sem_group):
@@ -1742,7 +2129,7 @@ class LowLevelILFunction(object):
:return: A flag_group expression
:rtype: LowLevelILExpr
"""
- group = self.arch.get_semantic_flag_group_index(sem_group)
+ group = self._arch.get_semantic_flag_group_index(sem_group)
return self.expr(LowLevelILOperation.LLIL_FLAG_GROUP, group)
def compare_equal(self, size, a, b):
@@ -1905,7 +2292,7 @@ class LowLevelILFunction(object):
param_list.append(param.index)
call_param = self.expr(LowLevelILOperation.LLIL_CALL_PARAM, len(params), self.add_operand_list(param_list).index)
return self.expr(LowLevelILOperation.LLIL_INTRINSIC, len(outputs), self.add_operand_list(output_list).index,
- self.arch.get_intrinsic_index(intrinsic), call_param.index, flags = flags)
+ self._arch.get_intrinsic_index(intrinsic), call_param.index, flags = flags)
def breakpoint(self):
"""
@@ -2344,14 +2731,14 @@ class LowLevelILFunction(object):
return core.BNGetLowLevelILNonSSAInstructionIndex(self.handle, instr)
def get_ssa_reg_definition(self, reg_ssa):
- reg = self.arch.get_reg_index(reg_ssa.reg)
+ reg = self._arch.get_reg_index(reg_ssa.reg)
result = core.BNGetLowLevelILSSARegisterDefinition(self.handle, reg, reg_ssa.version)
if result >= core.BNGetLowLevelILInstructionCount(self.handle):
return None
return self[result]
def get_ssa_flag_definition(self, flag_ssa):
- flag = self.arch.get_flag_index(flag_ssa.flag)
+ flag = self._arch.get_flag_index(flag_ssa.flag)
result = core.BNGetLowLevelILSSAFlagDefinition(self.handle, flag, flag_ssa.version)
if result >= core.BNGetLowLevelILInstructionCount(self.handle):
return None
@@ -2364,7 +2751,7 @@ class LowLevelILFunction(object):
return self[result]
def get_ssa_reg_uses(self, reg_ssa):
- reg = self.arch.get_reg_index(reg_ssa.reg)
+ reg = self._arch.get_reg_index(reg_ssa.reg)
count = ctypes.c_ulonglong()
instrs = core.BNGetLowLevelILSSARegisterUses(self.handle, reg, reg_ssa.version, count)
result = []
@@ -2374,7 +2761,7 @@ class LowLevelILFunction(object):
return result
def get_ssa_flag_uses(self, flag_ssa):
- flag = self.arch.get_flag_index(flag_ssa.flag)
+ flag = self._arch.get_flag_index(flag_ssa.flag)
count = ctypes.c_ulonglong()
instrs = core.BNGetLowLevelILSSAFlagUses(self.handle, flag, flag_ssa.version, count)
result = []
@@ -2393,15 +2780,15 @@ class LowLevelILFunction(object):
return result
def get_ssa_reg_value(self, reg_ssa):
- reg = self.arch.get_reg_index(reg_ssa.reg)
+ reg = self._arch.get_reg_index(reg_ssa.reg)
value = core.BNGetLowLevelILSSARegisterValue(self.handle, reg, reg_ssa.version)
- result = binaryninja.function.RegisterValue(self.arch, value)
+ result = binaryninja.function.RegisterValue(self._arch, value)
return result
def get_ssa_flag_value(self, flag_ssa):
- flag = self.arch.get_flag_index(flag_ssa.flag)
+ flag = self._arch.get_flag_index(flag_ssa.flag)
value = core.BNGetLowLevelILSSAFlagValue(self.handle, flag, flag_ssa.version)
- result = binaryninja.function.RegisterValue(self.arch, value)
+ result = binaryninja.function.RegisterValue(self._arch, value)
return result
def get_medium_level_il_instruction_index(self, instr):
@@ -2447,31 +2834,58 @@ class LowLevelILFunction(object):
settings_obj = None
return binaryninja.flowgraph.CoreFlowGraph(core.BNCreateLowLevelILFunctionGraph(self.handle, settings_obj))
+ @property
+ def arch(self):
+ """ """
+ return self._arch
+
+ @arch.setter
+ def arch(self, value):
+ self._arch = value
+
+ @property
+ def source_function(self):
+ """ """
+ return self._source_function
+
+ @source_function.setter
+ def source_function(self, value):
+ self._source_function = value
+
class LowLevelILBasicBlock(basicblock.BasicBlock):
def __init__(self, view, handle, owner):
super(LowLevelILBasicBlock, self).__init__(handle, view)
- self.il_function = owner
+ self._il_function = owner
def __iter__(self):
for idx in range(self.start, self.end):
- yield self.il_function[idx]
+ yield self._il_function[idx]
def __getitem__(self, idx):
size = self.end - self.start
if idx > size or idx < -size:
raise IndexError("list index is out of range")
if idx >= 0:
- return self.il_function[idx + self.start]
+ return self._il_function[idx + self.start]
else:
- return self.il_function[self.end + idx]
+ return self._il_function[self.end + idx]
def _create_instance(self, handle, view):
"""Internal method by super to instantiate child instances"""
- return LowLevelILBasicBlock(view, handle, self.il_function)
+ return LowLevelILBasicBlock(view, handle, self._il_function)
def __hash__(self):
- return hash((self.start, self.end, self.il_function))
+ return hash((self.start, self.end, self._il_function))
+
+ @property
+ def il_function(self):
+ """ """
+ return self._il_function
+
+ @il_function.setter
+ def il_function(self, value):
+ self._il_function = value
def LLIL_TEMP(n):
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 8b8500e4..14481c30 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -36,22 +36,40 @@ from binaryninja import range
class SSAVariable(object):
def __init__(self, var, version):
- self.var = var
- self.version = version
+ self._var = var
+ self._version = version
def __repr__(self):
- return "<ssa %s version %d>" % (repr(self.var), self.version)
+ return "<ssa %s version %d>" % (repr(self._var), self._version)
def __eq__(self, other):
if not isinstance(other, type(self)):
return False
return isinstance(other, SSAVariable) and (
- (self.var, self.version) ==
+ (self._var, self._version) ==
(other.var, other.version)
)
def __hash__(self):
- return hash((self.var, self.version))
+ return hash((self._var, self._version))
+
+ @property
+ def var(self):
+ """ """
+ return self._var
+
+ @var.setter
+ def var(self, value):
+ self._var = value
+
+ @property
+ def version(self):
+ """ """
+ return self._version
+
+ @version.setter
+ def version(self, value):
+ self._version = value
class MediumLevelILLabel(object):
@@ -65,22 +83,40 @@ class MediumLevelILLabel(object):
class MediumLevelILOperationAndSize(object):
def __init__(self, operation, size):
- self.operation = operation
- self.size = size
+ self._operation = operation
+ self._size = size
def __repr__(self):
- if self.size == 0:
- return "<%s>" % self.operation.name
- return "<%s %d>" % (self.operation.name, self.size)
+ if self._size == 0:
+ return "<%s>" % self._operation.name
+ return "<%s %d>" % (self._operation.name, self._size)
def __eq__(self, other):
if isinstance(other, MediumLevelILOperation):
- return other == self.operation
+ return other == self._operation
if isinstance(other, MediumLevelILOperationAndSize):
- return other.size == self.size and other.operation == self.operation
+ return other.size == self._size and other.operation == self._operation
else:
return False
+ @property
+ def operation(self):
+ """ """
+ return self._operation
+
+ @operation.setter
+ def operation(self, value):
+ self._operation = value
+
+ @property
+ def size(self):
+ """ """
+ return self._size
+
+ @size.setter
+ def size(self, value):
+ self._size = value
+
class MediumLevelILInstruction(object):
"""
@@ -225,18 +261,18 @@ class MediumLevelILInstruction(object):
def __init__(self, func, expr_index, instr_index=None):
instr = core.BNGetMediumLevelILByIndex(func.handle, expr_index)
- self.function = func
- self.expr_index = expr_index
+ self._function = func
+ self._expr_index = expr_index
if instr_index is None:
- self.instr_index = core.BNGetMediumLevelILInstructionForExpr(func.handle, expr_index)
+ self._instr_index = core.BNGetMediumLevelILInstructionForExpr(func.handle, expr_index)
else:
- self.instr_index = instr_index
- self.operation = MediumLevelILOperation(instr.operation)
- self.size = instr.size
- self.address = instr.address
- self.source_operand = instr.sourceOperand
+ self._instr_index = instr_index
+ self._operation = MediumLevelILOperation(instr.operation)
+ self._size = instr.size
+ self._address = instr.address
+ self._source_operand = instr.sourceOperand
operands = MediumLevelILInstruction.ILOperations[instr.operation]
- self.operands = []
+ self._operands = []
i = 0
for operand in operands:
name, operand_type = operand
@@ -255,55 +291,55 @@ class MediumLevelILInstruction(object):
elif operand_type == "intrinsic":
value = lowlevelil.ILIntrinsic(func.arch, instr.operands[i])
elif operand_type == "var":
- value = function.Variable.from_identifier(self.function.source_function, instr.operands[i])
+ value = function.Variable.from_identifier(self._function.source_function, instr.operands[i])
elif operand_type == "var_ssa":
- var = function.Variable.from_identifier(self.function.source_function, instr.operands[i])
+ var = function.Variable.from_identifier(self._function.source_function, instr.operands[i])
version = instr.operands[i + 1]
i += 1
value = SSAVariable(var, version)
elif operand_type == "var_ssa_dest_and_src":
- var = function.Variable.from_identifier(self.function.source_function, instr.operands[i])
+ var = function.Variable.from_identifier(self._function.source_function, instr.operands[i])
dest_version = instr.operands[i + 1]
src_version = instr.operands[i + 2]
i += 2
- self.operands.append(SSAVariable(var, dest_version))
- self.dest = SSAVariable(var, dest_version)
+ self._operands.append(SSAVariable(var, dest_version))
+ self._dest = SSAVariable(var, dest_version)
value = SSAVariable(var, src_version)
elif operand_type == "int_list":
count = ctypes.c_ulonglong()
- operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count)
+ operand_list = core.BNMediumLevelILGetOperandList(func.handle, self._expr_index, i, count)
value = []
for j in range(count.value):
value.append(operand_list[j])
core.BNMediumLevelILFreeOperandList(operand_list)
elif operand_type == "var_list":
count = ctypes.c_ulonglong()
- operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count)
+ operand_list = core.BNMediumLevelILGetOperandList(func.handle, self._expr_index, i, count)
i += 1
value = []
for j in range(count.value):
- value.append(function.Variable.from_identifier(self.function.source_function, operand_list[j]))
+ value.append(function.Variable.from_identifier(self._function.source_function, operand_list[j]))
core.BNMediumLevelILFreeOperandList(operand_list)
elif operand_type == "var_ssa_list":
count = ctypes.c_ulonglong()
- operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count)
+ operand_list = core.BNMediumLevelILGetOperandList(func.handle, self._expr_index, i, count)
i += 1
value = []
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,
+ value.append(SSAVariable(function.Variable.from_identifier(self._function.source_function,
var_id), var_version))
core.BNMediumLevelILFreeOperandList(operand_list)
elif operand_type == "expr_list":
count = ctypes.c_ulonglong()
- operand_list = core.BNMediumLevelILGetOperandList(func.handle, self.expr_index, i, count)
+ operand_list = core.BNMediumLevelILGetOperandList(func.handle, self._expr_index, i, count)
i += 1
value = []
for j in range(count.value):
value.append(MediumLevelILInstruction(func, operand_list[j]))
core.BNMediumLevelILFreeOperandList(operand_list)
- self.operands.append(value)
+ self._operands.append(value)
self.__dict__[name] = value
i += 1
@@ -322,21 +358,21 @@ class MediumLevelILInstruction(object):
def __eq__(self, value):
if not isinstance(value, type(self)):
return False
- return self.function == value.function and self.expr_index == value.expr_index
+ return self._function == value.function and self._expr_index == value.expr_index
@property
def tokens(self):
"""MLIL tokens (read-only)"""
count = ctypes.c_ulonglong()
tokens = ctypes.POINTER(core.BNInstructionTextToken)()
- if ((self.instr_index is not None) and (self.function.source_function is not None) and
- (self.expr_index == core.BNGetMediumLevelILIndexForInstruction(self.function.handle, self.instr_index))):
- if not core.BNGetMediumLevelILInstructionText(self.function.handle, self.function.source_function.handle,
- self.function.arch.handle, self.instr_index, tokens, count):
+ if ((self._instr_index is not None) and (self._function.source_function is not None) and
+ (self._expr_index == core.BNGetMediumLevelILIndexForInstruction(self._function.handle, self._instr_index))):
+ if not core.BNGetMediumLevelILInstructionText(self._function.handle, self._function.source_function.handle,
+ self._function.arch.handle, self._instr_index, tokens, count):
return None
else:
- if not core.BNGetMediumLevelILExprText(self.function.handle, self.function.arch.handle,
- self.expr_index, tokens, count):
+ if not core.BNGetMediumLevelILExprText(self._function.handle, self._function.arch.handle,
+ self._expr_index, tokens, count):
return None
result = binaryninja.function.InstructionTextToken.get_instruction_lines(tokens, count.value)
core.BNFreeInstructionText(tokens, count.value)
@@ -345,32 +381,32 @@ class MediumLevelILInstruction(object):
@property
def il_basic_block(self):
"""IL basic block object containing this expression (read-only) (only available on finalized functions)"""
- return MediumLevelILBasicBlock(self.function.source_function.view, core.BNGetMediumLevelILBasicBlockForInstruction(self.function.handle, self.instr_index), self.function)
+ return MediumLevelILBasicBlock(self._function.source_function.view, core.BNGetMediumLevelILBasicBlockForInstruction(self._function.handle, self._instr_index), self._function)
@property
def ssa_form(self):
"""SSA form of expression (read-only)"""
- return MediumLevelILInstruction(self.function.ssa_form,
- core.BNGetMediumLevelILSSAExprIndex(self.function.handle, self.expr_index))
+ return MediumLevelILInstruction(self._function.ssa_form,
+ core.BNGetMediumLevelILSSAExprIndex(self._function.handle, self._expr_index))
@property
def non_ssa_form(self):
"""Non-SSA form of expression (read-only)"""
- return MediumLevelILInstruction(self.function.non_ssa_form,
- core.BNGetMediumLevelILNonSSAExprIndex(self.function.handle, self.expr_index))
+ return MediumLevelILInstruction(self._function.non_ssa_form,
+ core.BNGetMediumLevelILNonSSAExprIndex(self._function.handle, self._expr_index))
@property
def value(self):
"""Value of expression if constant or a known value (read-only)"""
- value = core.BNGetMediumLevelILExprValue(self.function.handle, self.expr_index)
- result = function.RegisterValue(self.function.arch, value)
+ value = core.BNGetMediumLevelILExprValue(self._function.handle, self._expr_index)
+ result = function.RegisterValue(self._function.arch, value)
return result
@property
def possible_values(self):
"""Possible values of expression using path-sensitive static data flow analysis (read-only)"""
- value = core.BNGetMediumLevelILPossibleExprValues(self.function.handle, self.expr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ value = core.BNGetMediumLevelILPossibleExprValues(self._function.handle, self._expr_index)
+ result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -378,7 +414,7 @@ class MediumLevelILInstruction(object):
def branch_dependence(self):
"""Set of branching instructions that must take the true or false path to reach this instruction"""
count = ctypes.c_ulonglong()
- deps = core.BNGetAllMediumLevelILBranchDependence(self.function.handle, self.instr_index, count)
+ deps = core.BNGetAllMediumLevelILBranchDependence(self._function.handle, self._instr_index, count)
result = {}
for i in range(0, count.value):
result[deps[i].branch] = ILBranchDependence(deps[i].dependence)
@@ -388,10 +424,10 @@ class MediumLevelILInstruction(object):
@property
def low_level_il(self):
"""Low level IL form of this expression"""
- expr = self.function.get_low_level_il_expr_index(self.expr_index)
+ expr = self._function.get_low_level_il_expr_index(self._expr_index)
if expr is None:
return None
- return lowlevelil.LowLevelILInstruction(self.function.low_level_il.ssa_form, expr)
+ return lowlevelil.LowLevelILInstruction(self._function.low_level_il.ssa_form, expr)
@property
def llil(self):
@@ -401,13 +437,13 @@ class MediumLevelILInstruction(object):
@property
def ssa_memory_version(self):
"""Version of active memory contents in SSA form for this instruction"""
- return core.BNGetMediumLevelILSSAMemoryVersionAtILInstruction(self.function.handle, self.instr_index)
+ return core.BNGetMediumLevelILSSAMemoryVersionAtILInstruction(self._function.handle, self._instr_index)
@property
def prefix_operands(self):
"""All operands in the expression tree in prefix order"""
- result = [MediumLevelILOperationAndSize(self.operation, self.size)]
- for operand in self.operands:
+ result = [MediumLevelILOperationAndSize(self._operation, self._size)]
+ for operand in self._operands:
if isinstance(operand, MediumLevelILInstruction):
result += operand.prefix_operands
else:
@@ -418,61 +454,61 @@ class MediumLevelILInstruction(object):
def postfix_operands(self):
"""All operands in the expression tree in postfix order"""
result = []
- for operand in self.operands:
+ for operand in self._operands:
if isinstance(operand, MediumLevelILInstruction):
result += operand.postfix_operands
else:
result.append(operand)
- result.append(MediumLevelILOperationAndSize(self.operation, self.size))
+ result.append(MediumLevelILOperationAndSize(self._operation, self._size))
return result
@property
def vars_written(self):
"""List of variables written by instruction"""
- if self.operation in [MediumLevelILOperation.MLIL_SET_VAR, MediumLevelILOperation.MLIL_SET_VAR_FIELD,
+ if self._operation in [MediumLevelILOperation.MLIL_SET_VAR, MediumLevelILOperation.MLIL_SET_VAR_FIELD,
MediumLevelILOperation.MLIL_SET_VAR_SSA, MediumLevelILOperation.MLIL_SET_VAR_SSA_FIELD,
MediumLevelILOperation.MLIL_SET_VAR_ALIASED, MediumLevelILOperation.MLIL_SET_VAR_ALIASED_FIELD,
MediumLevelILOperation.MLIL_VAR_PHI]:
- return [self.dest]
- elif self.operation in [MediumLevelILOperation.MLIL_SET_VAR_SPLIT, MediumLevelILOperation.MLIL_SET_VAR_SPLIT_SSA]:
+ return [self._dest]
+ elif self._operation in [MediumLevelILOperation.MLIL_SET_VAR_SPLIT, MediumLevelILOperation.MLIL_SET_VAR_SPLIT_SSA]:
return [self.high, self.low]
- elif self.operation in [MediumLevelILOperation.MLIL_CALL, MediumLevelILOperation.MLIL_SYSCALL, MediumLevelILOperation.MLIL_TAILCALL]:
+ elif self._operation in [MediumLevelILOperation.MLIL_CALL, MediumLevelILOperation.MLIL_SYSCALL, MediumLevelILOperation.MLIL_TAILCALL]:
return self.output
- elif self.operation in [MediumLevelILOperation.MLIL_CALL_UNTYPED, MediumLevelILOperation.MLIL_SYSCALL_UNTYPED, MediumLevelILOperation.MLIL_TAILCALL_UNTYPED,
+ elif self._operation in [MediumLevelILOperation.MLIL_CALL_UNTYPED, MediumLevelILOperation.MLIL_SYSCALL_UNTYPED, MediumLevelILOperation.MLIL_TAILCALL_UNTYPED,
MediumLevelILOperation.MLIL_CALL_SSA, MediumLevelILOperation.MLIL_CALL_UNTYPED_SSA,
MediumLevelILOperation.MLIL_SYSCALL_SSA, MediumLevelILOperation.MLIL_SYSCALL_UNTYPED_SSA,
MediumLevelILOperation.MLIL_TAILCALL_SSA, MediumLevelILOperation.MLIL_TAILCALL_UNTYPED_SSA]:
return self.output.vars_written
- elif self.operation in [MediumLevelILOperation.MLIL_CALL_OUTPUT, MediumLevelILOperation.MLIL_CALL_OUTPUT_SSA]:
- return self.dest
+ elif self._operation in [MediumLevelILOperation.MLIL_CALL_OUTPUT, MediumLevelILOperation.MLIL_CALL_OUTPUT_SSA]:
+ return self._dest
return []
@property
def vars_read(self):
"""List of variables read by instruction"""
- if self.operation in [MediumLevelILOperation.MLIL_SET_VAR, MediumLevelILOperation.MLIL_SET_VAR_FIELD,
+ if self._operation in [MediumLevelILOperation.MLIL_SET_VAR, MediumLevelILOperation.MLIL_SET_VAR_FIELD,
MediumLevelILOperation.MLIL_SET_VAR_SPLIT, MediumLevelILOperation.MLIL_SET_VAR_SSA,
MediumLevelILOperation.MLIL_SET_VAR_SPLIT_SSA, MediumLevelILOperation.MLIL_SET_VAR_ALIASED]:
return self.src.vars_read
- elif self.operation in [MediumLevelILOperation.MLIL_SET_VAR_SSA_FIELD,
+ elif self._operation in [MediumLevelILOperation.MLIL_SET_VAR_SSA_FIELD,
MediumLevelILOperation.MLIL_SET_VAR_ALIASED_FIELD]:
return [self.prev] + self.src.vars_read
- elif self.operation in [MediumLevelILOperation.MLIL_CALL, MediumLevelILOperation.MLIL_SYSCALL, MediumLevelILOperation.MLIL_TAILCALL,
+ elif self._operation in [MediumLevelILOperation.MLIL_CALL, MediumLevelILOperation.MLIL_SYSCALL, MediumLevelILOperation.MLIL_TAILCALL,
MediumLevelILOperation.MLIL_CALL_SSA, MediumLevelILOperation.MLIL_SYSCALL_SSA, MediumLevelILOperation.MLIL_TAILCALL_SSA]:
result = []
for param in self.params:
result += param.vars_read
return result
- elif self.operation in [MediumLevelILOperation.MLIL_CALL_UNTYPED, MediumLevelILOperation.MLIL_SYSCALL_UNTYPED, MediumLevelILOperation.MLIL_TAILCALL_UNTYPED,
+ elif self._operation in [MediumLevelILOperation.MLIL_CALL_UNTYPED, MediumLevelILOperation.MLIL_SYSCALL_UNTYPED, MediumLevelILOperation.MLIL_TAILCALL_UNTYPED,
MediumLevelILOperation.MLIL_CALL_UNTYPED_SSA, MediumLevelILOperation.MLIL_SYSCALL_UNTYPED_SSA, MediumLevelILOperation.MLIL_TAILCALL_UNTYPED_SSA]:
return self.params.vars_read
- elif self.operation in [MediumLevelILOperation.MLIL_CALL_PARAM, MediumLevelILOperation.MLIL_CALL_PARAM_SSA,
+ elif self._operation in [MediumLevelILOperation.MLIL_CALL_PARAM, MediumLevelILOperation.MLIL_CALL_PARAM_SSA,
MediumLevelILOperation.MLIL_VAR_PHI]:
return self.src
- elif self.operation in [MediumLevelILOperation.MLIL_CALL_OUTPUT, MediumLevelILOperation.MLIL_CALL_OUTPUT_SSA]:
+ elif self._operation in [MediumLevelILOperation.MLIL_CALL_OUTPUT, MediumLevelILOperation.MLIL_CALL_OUTPUT_SSA]:
return []
result = []
- for operand in self.operands:
+ for operand in self._operands:
if (isinstance(operand, function.Variable)) or (isinstance(operand, SSAVariable)):
result.append(operand)
elif isinstance(operand, MediumLevelILInstruction):
@@ -482,11 +518,11 @@ class MediumLevelILInstruction(object):
@property
def expr_type(self):
"""Type of expression"""
- result = core.BNGetMediumLevelILExprType(self.function.handle, self.expr_index)
+ result = core.BNGetMediumLevelILExprType(self._function.handle, self._expr_index)
if result.type:
platform = None
- if self.function.source_function:
- platform = self.function.source_function.platform
+ if self._function.source_function:
+ platform = self._function.source_function.platform
return types.Type(result.type, platform = platform, confidence = result.confidence)
return None
@@ -495,8 +531,8 @@ class MediumLevelILInstruction(object):
var_data.type = ssa_var.var.source_type
var_data.index = ssa_var.var.index
var_data.storage = ssa_var.var.storage
- value = core.BNGetMediumLevelILPossibleSSAVarValues(self.function.handle, var_data, ssa_var.version, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ value = core.BNGetMediumLevelILPossibleSSAVarValues(self._function.handle, var_data, ssa_var.version, self._instr_index)
+ result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -505,98 +541,98 @@ class MediumLevelILInstruction(object):
var_data.type = var.source_type
var_data.index = var.index
var_data.storage = var.storage
- return core.BNGetMediumLevelILSSAVarVersionAtILInstruction(self.function.handle, var_data, self.instr_index)
+ return core.BNGetMediumLevelILSSAVarVersionAtILInstruction(self._function.handle, var_data, self._instr_index)
def get_var_for_reg(self, reg):
- reg = self.function.arch.get_reg_index(reg)
- result = core.BNGetMediumLevelILVariableForRegisterAtInstruction(self.function.handle, reg, self.instr_index)
- return function.Variable(self.function.source_function, result.type, result.index, result.storage)
+ reg = self._function.arch.get_reg_index(reg)
+ result = core.BNGetMediumLevelILVariableForRegisterAtInstruction(self._function.handle, reg, self._instr_index)
+ return function.Variable(self._function.source_function, result.type, result.index, result.storage)
def get_var_for_flag(self, flag):
- flag = self.function.arch.get_flag_index(flag)
- result = core.BNGetMediumLevelILVariableForFlagAtInstruction(self.function.handle, flag, self.instr_index)
- return function.Variable(self.function.source_function, result.type, result.index, result.storage)
+ flag = self._function.arch.get_flag_index(flag)
+ result = core.BNGetMediumLevelILVariableForFlagAtInstruction(self._function.handle, flag, self._instr_index)
+ return function.Variable(self._function.source_function, result.type, result.index, result.storage)
def get_var_for_stack_location(self, offset):
- result = core.BNGetMediumLevelILVariableForStackLocationAtInstruction(self.function.handle, offset, self.instr_index)
- return function.Variable(self.function.source_function, result.type, result.index, result.storage)
+ result = core.BNGetMediumLevelILVariableForStackLocationAtInstruction(self._function.handle, offset, self._instr_index)
+ return function.Variable(self._function.source_function, result.type, result.index, result.storage)
def get_reg_value(self, reg):
- reg = self.function.arch.get_reg_index(reg)
- value = core.BNGetMediumLevelILRegisterValueAtInstruction(self.function.handle, reg, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ reg = self._function.arch.get_reg_index(reg)
+ value = core.BNGetMediumLevelILRegisterValueAtInstruction(self._function.handle, reg, self._instr_index)
+ result = function.RegisterValue(self._function.arch, value)
return result
def get_reg_value_after(self, reg):
- reg = self.function.arch.get_reg_index(reg)
- value = core.BNGetMediumLevelILRegisterValueAfterInstruction(self.function.handle, reg, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ reg = self._function.arch.get_reg_index(reg)
+ value = core.BNGetMediumLevelILRegisterValueAfterInstruction(self._function.handle, reg, self._instr_index)
+ result = function.RegisterValue(self._function.arch, value)
return result
def get_possible_reg_values(self, reg):
- reg = self.function.arch.get_reg_index(reg)
- value = core.BNGetMediumLevelILPossibleRegisterValuesAtInstruction(self.function.handle, reg, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ reg = self._function.arch.get_reg_index(reg)
+ value = core.BNGetMediumLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index)
+ result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_reg_values_after(self, reg):
- reg = self.function.arch.get_reg_index(reg)
- value = core.BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(self.function.handle, reg, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ reg = self._function.arch.get_reg_index(reg)
+ value = core.BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index)
+ result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_flag_value(self, flag):
- flag = self.function.arch.get_flag_index(flag)
- value = core.BNGetMediumLevelILFlagValueAtInstruction(self.function.handle, flag, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ flag = self._function.arch.get_flag_index(flag)
+ value = core.BNGetMediumLevelILFlagValueAtInstruction(self._function.handle, flag, self._instr_index)
+ result = function.RegisterValue(self._function.arch, value)
return result
def get_flag_value_after(self, flag):
- flag = self.function.arch.get_flag_index(flag)
- value = core.BNGetMediumLevelILFlagValueAfterInstruction(self.function.handle, flag, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ flag = self._function.arch.get_flag_index(flag)
+ value = core.BNGetMediumLevelILFlagValueAfterInstruction(self._function.handle, flag, self._instr_index)
+ result = function.RegisterValue(self._function.arch, value)
return result
def get_possible_flag_values(self, flag):
- flag = self.function.arch.get_flag_index(flag)
- value = core.BNGetMediumLevelILPossibleFlagValuesAtInstruction(self.function.handle, flag, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ flag = self._function.arch.get_flag_index(flag)
+ value = core.BNGetMediumLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index)
+ result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_flag_values_after(self, flag):
- flag = self.function.arch.get_flag_index(flag)
- value = core.BNGetMediumLevelILPossibleFlagValuesAfterInstruction(self.function.handle, flag, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ flag = self._function.arch.get_flag_index(flag)
+ value = core.BNGetMediumLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index)
+ result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_stack_contents(self, offset, size):
- value = core.BNGetMediumLevelILStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ value = core.BNGetMediumLevelILStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index)
+ result = function.RegisterValue(self._function.arch, value)
return result
def get_stack_contents_after(self, offset, size):
- value = core.BNGetMediumLevelILStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ value = core.BNGetMediumLevelILStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index)
+ result = function.RegisterValue(self._function.arch, value)
return result
def get_possible_stack_contents(self, offset, size):
- value = core.BNGetMediumLevelILPossibleStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ value = core.BNGetMediumLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index)
+ result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_stack_contents_after(self, offset, size):
- value = core.BNGetMediumLevelILPossibleStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ value = core.BNGetMediumLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index)
+ result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_branch_dependence(self, branch_instr):
- return ILBranchDependence(core.BNGetMediumLevelILBranchDependence(self.function.handle, self.instr_index, branch_instr))
+ return ILBranchDependence(core.BNGetMediumLevelILBranchDependence(self._function.handle, self._instr_index, branch_instr))
def __setattr__(self, name, value):
try:
@@ -604,6 +640,87 @@ class MediumLevelILInstruction(object):
except AttributeError:
raise AttributeError("attribute '%s' is read only" % name)
+ @property
+ def function(self):
+ """ """
+ return self._function
+
+ @function.setter
+ def function(self, value):
+ self._function = value
+
+ @property
+ def expr_index(self):
+ """ """
+ return self._expr_index
+
+ @expr_index.setter
+ def expr_index(self, value):
+ self._expr_index = value
+
+ @property
+ def instr_index(self):
+ """ """
+ return self._instr_index
+
+ @instr_index.setter
+ def instr_index(self, value):
+ self._instr_index = value
+
+ @property
+ def operation(self):
+ """ """
+ return self._operation
+
+ @operation.setter
+ def operation(self, value):
+ self._operation = value
+
+ @property
+ def size(self):
+ """ """
+ return self._size
+
+ @size.setter
+ def size(self, value):
+ self._size = value
+
+ @property
+ def address(self):
+ """ """
+ return self._address
+
+ @address.setter
+ def address(self, value):
+ self._address = value
+
+ @property
+ def source_operand(self):
+ """ """
+ return self._source_operand
+
+ @source_operand.setter
+ def source_operand(self, value):
+ self._source_operand = value
+
+ @property
+ def operands(self):
+ """ """
+ return self._operands
+
+ @operands.setter
+ def operands(self, value):
+ self._operands = value
+
+ @property
+ def dest(self):
+ """ """
+ return self._dest
+
+ @dest.setter
+ def dest(self, value):
+ self._dest = value
+
class MediumLevelILExpr(object):
"""
@@ -613,7 +730,16 @@ class MediumLevelILExpr(object):
used instead.
"""
def __init__(self, index):
- self.index = index
+ self._index = index
+
+ @property
+ def index(self):
+ """ """
+ return self._index
+
+ @index.setter
+ def index(self, value):
+ self._index = value
class MediumLevelILFunction(object):
@@ -623,25 +749,25 @@ class MediumLevelILFunction(object):
methods which return MediumLevelILExpr objects.
"""
def __init__(self, arch = None, handle = None, source_func = None):
- self.arch = arch
- self.source_function = source_func
+ self._arch = arch
+ self._source_function = source_func
if handle is not None:
self.handle = core.handle_of_type(handle, core.BNMediumLevelILFunction)
- if self.source_function is None:
- self.source_function = binaryninja.function.Function(handle = core.BNGetMediumLevelILOwnerFunction(self.handle))
- if self.arch is None:
- self.arch = self.source_function.arch
+ if self._source_function is None:
+ self._source_function = binaryninja.function.Function(handle = core.BNGetMediumLevelILOwnerFunction(self.handle))
+ if self._arch is None:
+ self._arch = self._source_function.arch
else:
- if self.source_function is None:
+ if self._source_function is None:
self.handle = None
raise ValueError("IL functions must be created with an associated function")
- if self.arch is None:
- self.arch = self.source_function.arch
- func_handle = self.source_function.handle
+ if self._arch is None:
+ self._arch = self._source_function.arch
+ func_handle = self._source_function.handle
self.handle = core.BNCreateMediumLevelILFunction(arch.handle, func_handle)
def __hash__(self):
- return hash(('MLIL', self.source_function))
+ return hash(('MLIL', self._source_function))
def __del__(self):
if self.handle is not None:
@@ -664,11 +790,11 @@ class MediumLevelILFunction(object):
@current_address.setter
def current_address(self, value):
- core.BNMediumLevelILSetCurrentAddress(self.handle, self.arch.handle, value)
+ core.BNMediumLevelILSetCurrentAddress(self.handle, self._arch.handle, value)
def set_current_address(self, value, arch = None):
if arch is None:
- arch = self.arch
+ arch = self._arch
core.BNMediumLevelILSetCurrentAddress(self.handle, arch.handle, value)
@property
@@ -678,8 +804,8 @@ class MediumLevelILFunction(object):
blocks = core.BNGetMediumLevelILBasicBlockList(self.handle, count)
result = []
view = None
- if self.source_function is not None:
- view = self.source_function.view
+ if self._source_function is not None:
+ view = self._source_function.view
for i in range(0, count.value):
result.append(MediumLevelILBasicBlock(view, core.BNNewBasicBlockReference(blocks[i]), self))
core.BNFreeBasicBlockList(blocks, count.value)
@@ -698,7 +824,7 @@ class MediumLevelILFunction(object):
result = core.BNGetMediumLevelILSSAForm(self.handle)
if not result:
return None
- return MediumLevelILFunction(self.arch, result, self.source_function)
+ return MediumLevelILFunction(self._arch, result, self._source_function)
@property
def non_ssa_form(self):
@@ -706,7 +832,7 @@ class MediumLevelILFunction(object):
result = core.BNGetMediumLevelILNonSSAForm(self.handle)
if not result:
return None
- return MediumLevelILFunction(self.arch, result, self.source_function)
+ return MediumLevelILFunction(self._arch, result, self._source_function)
@property
def low_level_il(self):
@@ -714,7 +840,7 @@ class MediumLevelILFunction(object):
result = core.BNGetLowLevelILForMediumLevelIL(self.handle)
if not result:
return None
- return lowlevelil.LowLevelILFunction(self.arch, result, self.source_function)
+ return lowlevelil.LowLevelILFunction(self._arch, result, self._source_function)
@property
def llil(self):
@@ -749,8 +875,8 @@ class MediumLevelILFunction(object):
count = ctypes.c_ulonglong()
blocks = core.BNGetMediumLevelILBasicBlockList(self.handle, count)
view = None
- if self.source_function is not None:
- view = self.source_function.view
+ if self._source_function is not None:
+ view = self._source_function.view
try:
for i in range(0, count.value):
yield MediumLevelILBasicBlock(view, core.BNNewBasicBlockReference(blocks[i]), self)
@@ -759,7 +885,7 @@ class MediumLevelILFunction(object):
def get_instruction_start(self, addr, arch = None):
if arch is None:
- arch = self.arch
+ arch = self._arch
result = core.BNMediumLevelILGetInstructionStart(self.handle, arch.handle, addr)
if result >= core.BNGetMediumLevelILInstructionCount(self.handle):
return None
@@ -950,7 +1076,7 @@ class MediumLevelILFunction(object):
var_data.index = ssa_var.var.index
var_data.storage = ssa_var.var.storage
value = core.BNGetMediumLevelILSSAVarValue(self.handle, var_data, ssa_var.version)
- result = function.RegisterValue(self.arch, value)
+ result = function.RegisterValue(self._arch, value)
return result
def get_low_level_il_instruction_index(self, instr):
@@ -1009,3 +1135,21 @@ class MediumLevelILBasicBlock(basicblock.BasicBlock):
def __hash__(self):
return hash((self.start, self.end, self.il_function))
+
+ @property
+ def arch(self):
+ """ """
+ return self._arch
+
+ @arch.setter
+ def arch(self, value):
+ self._arch = value
+
+ @property
+ def source_function(self):
+ """ """
+ return self._source_function
+
+ @source_function.setter
+ def source_function(self, value):
+ self._source_function = value
diff --git a/python/platform.py b/python/platform.py
index 0ac8858b..0b628225 100644
--- a/python/platform.py
+++ b/python/platform.py
@@ -105,12 +105,12 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
if arch is None:
self.handle = None
raise ValueError("platform must have an associated architecture")
- self.arch = arch
+ self._arch = arch
self.handle = core.BNCreatePlatform(arch.handle, self.__class__.name)
else:
self.handle = handle
self.__dict__["name"] = core.BNGetPlatformName(self.handle)
- self.arch = binaryninja.architecture.CoreArchitecture._from_cache(core.BNGetPlatformArchitecture(self.handle))
+ self._arch = binaryninja.architecture.CoreArchitecture._from_cache(core.BNGetPlatformArchitecture(self.handle))
def __del__(self):
if self.handle is not None:
@@ -464,3 +464,12 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
functions[name] = types.Type(core.BNNewTypeReference(parse.functions[i].type), platform = self)
core.BNFreeTypeParserResult(parse)
return types.TypeParserResult(type_dict, variables, functions)
+
+ @property
+ def arch(self):
+ """ """
+ return self._arch
+
+ @arch.setter
+ def arch(self, value):
+ self._arch = value
diff --git a/python/plugin.py b/python/plugin.py
index afaf3032..9e1380c8 100644
--- a/python/plugin.py
+++ b/python/plugin.py
@@ -37,11 +37,56 @@ from binaryninja import with_metaclass
class PluginCommandContext(object):
def __init__(self, view):
- self.view = view
- self.address = 0
- self.length = 0
- self.function = None
- self.instruction = None
+ self._view = view
+ self._address = 0
+ self._length = 0
+ self._function = None
+ self._instruction = None
+
+ @property
+ def view(self):
+ """ """
+ return self._view
+
+ @view.setter
+ def view(self, value):
+ self._view = value
+
+ @property
+ def address(self):
+ """ """
+ return self._address
+
+ @address.setter
+ def address(self, value):
+ self._address = value
+
+ @property
+ def length(self):
+ """ """
+ return self._length
+
+ @length.setter
+ def length(self, value):
+ self._length = value
+
+ @property
+ def function(self):
+ """ """
+ return self._function
+
+ @function.setter
+ def function(self, value):
+ self._function = value
+
+ @property
+ def instruction(self):
+ """ """
+ return self._instruction
+
+ @instruction.setter
+ def instruction(self, value):
+ self._instruction = value
class _PluginCommandMetaClass(type):
@@ -77,11 +122,11 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
_registered_commands = []
def __init__(self, cmd):
- self.command = core.BNPluginCommand()
- ctypes.memmove(ctypes.byref(self.command), ctypes.byref(cmd), ctypes.sizeof(core.BNPluginCommand))
- self.name = str(cmd.name)
- self.description = str(cmd.description)
- self.type = PluginCommandType(cmd.type)
+ self._command = core.BNPluginCommand()
+ ctypes.memmove(ctypes.byref(self._command), ctypes.byref(cmd), ctypes.sizeof(core.BNPluginCommand))
+ self._name = str(cmd.name)
+ self._description = str(cmd.description)
+ self._type = PluginCommandType(cmd.type)
@property
def list(self):
@@ -279,7 +324,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
"""
``register`` Register a plugin
- :param str name: name of the plugin
+ :param str name: name of the plugin (use 'Folder\\Name' to have the menu item nested in a folder)
:param str description: description of the plugin
:param action: function to call with the :class:`~binaryninja.binaryview.BinaryView` as an argument
:param is_valid: optional argument of a function passed a :class:`~binaryninja.binaryview.BinaryView` to determine whether the plugin should be enabled for that view
@@ -439,82 +484,118 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
def is_valid(self, context):
if context.view is None:
return False
- if self.command.type == PluginCommandType.DefaultPluginCommand:
- if not self.command.defaultIsValid:
+ if self._command.type == PluginCommandType.DefaultPluginCommand:
+ if not self._command.defaultIsValid:
return True
- return self.command.defaultIsValid(self.command.context, context.view.handle)
- elif self.command.type == PluginCommandType.AddressPluginCommand:
- if not self.command.addressIsValid:
+ return self._command.defaultIsValid(self._command.context, context.view.handle)
+ elif self._command.type == PluginCommandType.AddressPluginCommand:
+ if not self._command.addressIsValid:
return True
- return self.command.addressIsValid(self.command.context, context.view.handle, context.address)
- elif self.command.type == PluginCommandType.RangePluginCommand:
+ return self._command.addressIsValid(self._command.context, context.view.handle, context.address)
+ elif self._command.type == PluginCommandType.RangePluginCommand:
if context.length == 0:
return False
- if not self.command.rangeIsValid:
+ if not self._command.rangeIsValid:
return True
- return self.command.rangeIsValid(self.command.context, context.view.handle, context.address, context.length)
- elif self.command.type == PluginCommandType.FunctionPluginCommand:
+ return self._command.rangeIsValid(self._command.context, context.view.handle, context.address, context.length)
+ elif self._command.type == PluginCommandType.FunctionPluginCommand:
if context.function is None:
return False
- if not self.command.functionIsValid:
+ if not self._command.functionIsValid:
return True
- return self.command.functionIsValid(self.command.context, context.view.handle, context.function.handle)
- elif self.command.type == PluginCommandType.LowLevelILFunctionPluginCommand:
+ return self._command.functionIsValid(self._command.context, context.view.handle, context.function.handle)
+ elif self._command.type == PluginCommandType.LowLevelILFunctionPluginCommand:
if context.function is None:
return False
- if not self.command.lowLevelILFunctionIsValid:
+ if not self._command.lowLevelILFunctionIsValid:
return True
- return self.command.lowLevelILFunctionIsValid(self.command.context, context.view.handle, context.function.handle)
- elif self.command.type == PluginCommandType.LowLevelILInstructionPluginCommand:
+ return self._command.lowLevelILFunctionIsValid(self._command.context, context.view.handle, context.function.handle)
+ elif self._command.type == PluginCommandType.LowLevelILInstructionPluginCommand:
if context.instruction is None:
return False
if not isinstance(context.instruction, binaryninja.lowlevelil.LowLevelILInstruction):
return False
- if not self.command.lowLevelILInstructionIsValid:
+ if not self._command.lowLevelILInstructionIsValid:
return True
- return self.command.lowLevelILInstructionIsValid(self.command.context, context.view.handle,
+ return self._command.lowLevelILInstructionIsValid(self._command.context, context.view.handle,
context.instruction.function.handle, context.instruction.instr_index)
- elif self.command.type == PluginCommandType.MediumLevelILFunctionPluginCommand:
+ elif self._command.type == PluginCommandType.MediumLevelILFunctionPluginCommand:
if context.function is None:
return False
- if not self.command.mediumLevelILFunctionIsValid:
+ if not self._command.mediumLevelILFunctionIsValid:
return True
- return self.command.mediumLevelILFunctionIsValid(self.command.context, context.view.handle, context.function.handle)
- elif self.command.type == PluginCommandType.MediumLevelILInstructionPluginCommand:
+ return self._command.mediumLevelILFunctionIsValid(self._command.context, context.view.handle, context.function.handle)
+ elif self._command.type == PluginCommandType.MediumLevelILInstructionPluginCommand:
if context.instruction is None:
return False
if not isinstance(context.instruction, binaryninja.mediumlevelil.MediumLevelILInstruction):
return False
- if not self.command.mediumLevelILInstructionIsValid:
+ if not self._command.mediumLevelILInstructionIsValid:
return True
- return self.command.mediumLevelILInstructionIsValid(self.command.context, context.view.handle,
+ return self._command.mediumLevelILInstructionIsValid(self._command.context, context.view.handle,
context.instruction.function.handle, context.instruction.instr_index)
return False
def execute(self, context):
if not self.is_valid(context):
return
- if self.command.type == PluginCommandType.DefaultPluginCommand:
- self.command.defaultCommand(self.command.context, context.view.handle)
- elif self.command.type == PluginCommandType.AddressPluginCommand:
- self.command.addressCommand(self.command.context, context.view.handle, context.address)
- elif self.command.type == PluginCommandType.RangePluginCommand:
- self.command.rangeCommand(self.command.context, context.view.handle, context.address, context.length)
- elif self.command.type == PluginCommandType.FunctionPluginCommand:
- self.command.functionCommand(self.command.context, context.view.handle, context.function.handle)
- elif self.command.type == PluginCommandType.LowLevelILFunctionPluginCommand:
- self.command.lowLevelILFunctionCommand(self.command.context, context.view.handle, context.function.handle)
- elif self.command.type == PluginCommandType.LowLevelILInstructionPluginCommand:
- self.command.lowLevelILInstructionCommand(self.command.context, context.view.handle,
+ if self._command.type == PluginCommandType.DefaultPluginCommand:
+ self._command.defaultCommand(self._command.context, context.view.handle)
+ elif self._command.type == PluginCommandType.AddressPluginCommand:
+ self._command.addressCommand(self._command.context, context.view.handle, context.address)
+ elif self._command.type == PluginCommandType.RangePluginCommand:
+ self._command.rangeCommand(self._command.context, context.view.handle, context.address, context.length)
+ elif self._command.type == PluginCommandType.FunctionPluginCommand:
+ self._command.functionCommand(self._command.context, context.view.handle, context.function.handle)
+ elif self._command.type == PluginCommandType.LowLevelILFunctionPluginCommand:
+ self._command.lowLevelILFunctionCommand(self._command.context, context.view.handle, context.function.handle)
+ elif self._command.type == PluginCommandType.LowLevelILInstructionPluginCommand:
+ self._command.lowLevelILInstructionCommand(self._command.context, context.view.handle,
context.instruction.function.handle, context.instruction.instr_index)
- elif self.command.type == PluginCommandType.MediumLevelILFunctionPluginCommand:
- self.command.mediumLevelILFunctionCommand(self.command.context, context.view.handle, context.function.handle)
- elif self.command.type == PluginCommandType.MediumLevelILInstructionPluginCommand:
- self.command.mediumLevelILInstructionCommand(self.command.context, context.view.handle,
+ elif self._command.type == PluginCommandType.MediumLevelILFunctionPluginCommand:
+ self._command.mediumLevelILFunctionCommand(self._command.context, context.view.handle, context.function.handle)
+ elif self._command.type == PluginCommandType.MediumLevelILInstructionPluginCommand:
+ self._command.mediumLevelILInstructionCommand(self._command.context, context.view.handle,
context.instruction.function.handle, context.instruction.instr_index)
def __repr__(self):
- return "<PluginCommand: %s>" % self.name
+ return "<PluginCommand: %s>" % self._name
+
+ @property
+ def command(self):
+ """ """
+ return self._command
+
+ @command.setter
+ def command(self, value):
+ self._command = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
+
+ @property
+ def description(self):
+ """ """
+ return self._description
+
+ @description.setter
+ def description(self, value):
+ self._description = value
+
+ @property
+ def type(self):
+ """ """
+ return self._type
+
+ @type.setter
+ def type(self, value):
+ self._type = value
class MainThreadAction(object):
diff --git a/python/settings.py b/python/settings.py
index 92136460..b16e9763 100644
--- a/python/settings.py
+++ b/python/settings.py
@@ -31,7 +31,12 @@ from binaryninja.enums import SettingsScope
class Settings(object):
def __init__(self, registry_id = "default"):
- self.registry_id = registry_id
+ self._registry_id = registry_id
+
+ @property
+ def registry_id(self):
+ """(read-only)"""
+ return self._registry_id
def register_group(self, group, title):
"""
@@ -47,7 +52,7 @@ class Settings(object):
True
>>>
"""
- return core.BNSettingsRegisterGroup(self.registry_id, group, title)
+ return core.BNSettingsRegisterGroup(self._registry_id, group, title)
def register_setting(self, id, properties):
"""
@@ -64,11 +69,11 @@ class Settings(object):
>>> Settings().register_setting("solver.basicBlockSlicing", '{"description" : "Enable the basic block slicing in the solver.", "title" : "Basic Block Slicing", "default" : true, "type" : "boolean", "id" : "basicBlockSlicing"}')
True
"""
- return core.BNSettingsRegisterSetting(self.registry_id, id, properties)
+ return core.BNSettingsRegisterSetting(self._registry_id, id, properties)
def query_property_string_list(self, id, property_name):
length = ctypes.c_ulonglong()
- result = core.BNSettingsQueryPropertyStringList(self.registry_id, id, property_name, ctypes.byref(length))
+ result = core.BNSettingsQueryPropertyStringList(self._registry_id, id, property_name, ctypes.byref(length))
out_list = []
for i in range(length.value):
out_list.append(pyNativeStr(result[i]))
@@ -76,49 +81,49 @@ class Settings(object):
return out_list
def update_property(self, id, setting_property):
- return core.BNSettingsUpdateProperty(self.registry_id, tr(), id, setting_property)
+ return core.BNSettingsUpdateProperty(self._registry_id, tr(), id, setting_property)
def get_schema(self):
- return core.BNSettingsGetSchema(self.registry_id)
+ return core.BNSettingsGetSchema(self._registry_id)
def copy_value(self, dest_registry_id, id):
- return core.BNSettingsCopyValue(self.registry_id, dest_registry_id, id)
+ return core.BNSettingsCopyValue(self._registry_id, dest_registry_id, id)
def reset(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
- return core.BNSettingsReset(self.registry_id, id, view, scope)
+ return core.BNSettingsReset(self._registry_id, id, view, scope)
def reset_all(self, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
- return core.BNSettingsResetAll(self.registry_id, view, scope)
+ return core.BNSettingsResetAll(self._registry_id, view, scope)
def get_bool(self, id, view = None):
if view is not None:
view = view.handle
- return core.BNSettingsGetBool(self.registry_id, id, view, None)
+ return core.BNSettingsGetBool(self._registry_id, id, view, None)
def get_double(self, id, view = None):
if view is not None:
view = view.handle
- return core.BNSettingsGetDouble(self.registry_id, id, view, None)
+ return core.BNSettingsGetDouble(self._registry_id, id, view, None)
def get_integer(self, id, view = None):
if view is not None:
view = view.handle
- return core.BNSettingsGetUInt64(self.registry_id, id, view, None)
+ return core.BNSettingsGetUInt64(self._registry_id, id, view, None)
def get_string(self, id, view = None):
if view is not None:
view = view.handle
- return core.BNSettingsGetString(self.registry_id, id, view, None)
+ return core.BNSettingsGetString(self._registry_id, id, view, None)
def get_string_list(self, id, view = None):
if view is not None:
view = view.handle
length = ctypes.c_ulonglong()
- result = core.BNSettingsGetStringList(self.registry_id, id, view, None, ctypes.byref(length))
+ result = core.BNSettingsGetStringList(self._registry_id, id, view, None, ctypes.byref(length))
out_list = []
for i in range(length.value):
out_list.append(pyNativeStr(result[i]))
@@ -129,28 +134,28 @@ class Settings(object):
if view is not None:
view = view.handle
c_scope = core.SettingsScopeEnum(scope)
- result = core.BNSettingsGetBool(self.registry_id, id, view, ctypes.byref(c_scope))
+ result = core.BNSettingsGetBool(self._registry_id, id, view, ctypes.byref(c_scope))
return (result, SettingsScope(c_scope.value))
def get_double_with_scope(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
c_scope = core.SettingsScopeEnum(scope)
- result = core.BNSettingsGetDouble(self.registry_id, id, view, ctypes.byref(c_scope))
+ result = core.BNSettingsGetDouble(self._registry_id, id, view, ctypes.byref(c_scope))
return (result, SettingsScope(c_scope.value))
def get_integer_with_scope(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
c_scope = core.SettingsScopeEnum(scope)
- result = core.BNSettingsGetUInt64(self.registry_id, id, view, ctypes.byref(c_scope))
+ result = core.BNSettingsGetUInt64(self._registry_id, id, view, ctypes.byref(c_scope))
return (result, SettingsScope(c_scope.value))
def get_string_with_scope(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
c_scope = core.SettingsScopeEnum(scope)
- result = core.BNSettingsGetString(self.registry_id, id, view, ctypes.byref(c_scope))
+ result = core.BNSettingsGetString(self._registry_id, id, view, ctypes.byref(c_scope))
return (result, SettingsScope(c_scope.value))
def get_string_list_with_scope(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
@@ -158,7 +163,7 @@ class Settings(object):
view = view.handle
c_scope = core.SettingsScopeEnum(scope)
length = ctypes.c_ulonglong()
- result = core.BNSettingsGetStringList(self.registry_id, id, view, ctypes.byref(c_scope), ctypes.byref(length))
+ result = core.BNSettingsGetStringList(self._registry_id, id, view, ctypes.byref(c_scope), ctypes.byref(length))
out_list = []
for i in range(length.value):
out_list.append(pyNativeStr(result[i]))
@@ -168,22 +173,22 @@ class Settings(object):
def set_bool(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
- return core.BNSettingsSetBool(self.registry_id, view, scope, id, value)
+ return core.BNSettingsSetBool(self._registry_id, view, scope, id, value)
def set_double(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
- return core.BNSettingsSetDouble(self.registry_id, view, scope, id, value)
+ return core.BNSettingsSetDouble(self._registry_id, view, scope, id, value)
def set_integer(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
- return core.BNSettingsSetUInt64(self.registry_id, view, scope, id, value)
+ return core.BNSettingsSetUInt64(self._registry_id, view, scope, id, value)
def set_string(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
- return core.BNSettingsSetString(self.registry_id, view, scope, id, value)
+ return core.BNSettingsSetString(self._registry_id, view, scope, id, value)
def set_string_list(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
@@ -193,4 +198,4 @@ class Settings(object):
string_list = (ctypes.c_char_p * len(value))()
for i in range(len(value)):
string_list[i] = value[i].encode('charmap')
- return core.BNSettingsSetStringList(self.registry_id, view, scope, id, string_list, length)
+ return core.BNSettingsSetStringList(self._registry_id, view, scope, id, string_list, length)
diff --git a/python/transform.py b/python/transform.py
index a441ef7b..3afaaa59 100644
--- a/python/transform.py
+++ b/python/transform.py
@@ -87,18 +87,33 @@ class _TransformMetaClass(type):
class TransformParameter(object):
def __init__(self, name, long_name = None, fixed_length = 0):
- self.name = name
+ self._name = name
if long_name is None:
- self.long_name = name
+ self._long_name = name
else:
- self.long_name = long_name
- self.fixed_length = fixed_length
+ self._long_name = long_name
+ self._fixed_length = fixed_length
def __repr__(self):
return "<TransformParameter: {} fixed length: {}>".format(
- self.long_name, self.fixed_length
+ self._long_name, self._fixed_length
)
+ @property
+ def name(self):
+ """(read-only)"""
+ return self._name
+
+ @property
+ def long_name(self):
+ """(read-only)"""
+ return self._long_name
+
+ @property
+ def fixed_length(self):
+ """(read-only)"""
+ return self._fixed_length
+
class Transform(with_metaclass(_TransformMetaClass, object)):
transform_type = None
diff --git a/python/types.py b/python/types.py
index 68d20997..03f56a7b 100644
--- a/python/types.py
+++ b/python/types.py
@@ -36,23 +36,23 @@ from binaryninja import pyNativeStr
class QualifiedName(object):
def __init__(self, name = []):
if isinstance(name, str):
- self.name = [name]
- self.byte_name = [name.encode('charmap')]
+ self._name = [name]
+ self._byte_name = [name.encode('charmap')]
elif isinstance(name, QualifiedName):
- self.name = name.name
- self.byte_name = [n.encode('charmap') for n in name.name]
+ self._name = name.name
+ self._byte_name = [n.encode('charmap') for n in name.name]
else:
- self.name = [pyNativeStr(i) for i in name]
- self.byte_name = name
+ self._name = [pyNativeStr(i) for i in name]
+ self._byte_name = name
def __str__(self):
- return "::".join(self.name)
+ return "::".join(self._name)
def __repr__(self):
return repr(str(self))
def __len__(self):
- return len(self.name)
+ return len(self._name)
def __hash__(self):
return hash(str(self))
@@ -61,9 +61,9 @@ class QualifiedName(object):
if isinstance(other, str):
return str(self) == other
elif isinstance(other, list):
- return self.name == other
+ return self._name == other
elif isinstance(other, QualifiedName):
- return self.name == other.name
+ return self._name == other.name
return False
def __ne__(self, other):
@@ -71,22 +71,22 @@ class QualifiedName(object):
def __lt__(self, other):
if isinstance(other, QualifiedName):
- return self.name < other.name
+ return self._name < other.name
return False
def __le__(self, other):
if isinstance(other, QualifiedName):
- return self.name <= other.name
+ return self._name <= other.name
return False
def __gt__(self, other):
if isinstance(other, QualifiedName):
- return self.name > other.name
+ return self._name > other.name
return False
def __ge__(self, other):
if isinstance(other, QualifiedName):
- return self.name >= other.name
+ return self._name >= other.name
return False
def __cmp__(self, other):
@@ -97,18 +97,18 @@ class QualifiedName(object):
return 1
def __getitem__(self, key):
- return self.name[key]
+ return self._name[key]
def __iter__(self):
- return iter(self.name)
+ return iter(self._name)
def _get_core_struct(self):
result = core.BNQualifiedName()
- name_list = (ctypes.c_char_p * len(self.name))()
- for i in range(0, len(self.name)):
- name_list[i] = self.name[i].encode('charmap')
+ name_list = (ctypes.c_char_p * len(self._name))()
+ for i in range(0, len(self._name)):
+ name_list[i] = self._name[i].encode('charmap')
result.name = name_list
- result.nameCount = len(self.name)
+ result.nameCount = len(self._name)
return result
@classmethod
@@ -118,6 +118,24 @@ class QualifiedName(object):
result.append(name.name[i])
return QualifiedName(result)
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
+
+ @property
+ def byte_name(self):
+ """ """
+ return self._byte_name
+
+ @byte_name.setter
+ def byte_name(self, value):
+ self._byte_name = value
+
class NameSpace(QualifiedName):
def __str__(self):
@@ -249,21 +267,48 @@ class Symbol(object):
class FunctionParameter(object):
def __init__(self, param_type, name = "", location = None):
- self.type = param_type
- self.name = name
- self.location = location
+ self._type = param_type
+ self._name = name
+ self._location = location
def __repr__(self):
- if (self.location is not None) and (self.location.name != self.name):
- return "%s %s%s @ %s" % (self.type.get_string_before_name(), self.name, self.type.get_string_after_name(), self.location.name)
- return "%s %s%s" % (self.type.get_string_before_name(), self.name, self.type.get_string_after_name())
+ if (self._location is not None) and (self._location.name != self._name):
+ return "%s %s%s @ %s" % (self._type.get_string_before_name(), self._name, self._type.get_string_after_name(), self._location.name)
+ return "%s %s%s" % (self._type.get_string_before_name(), self._name, self._type.get_string_after_name())
+
+ @property
+ def type(self):
+ """ """
+ return self._type
+
+ @type.setter
+ def type(self, value):
+ self._type = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
+
+ @property
+ def location(self):
+ """ """
+ return self._location
+
+ @location.setter
+ def location(self, value):
+ self._location = value
class Type(object):
def __init__(self, handle, platform = None, confidence = max_confidence):
self.handle = handle
- self.confidence = confidence
- self.platform = platform
+ self._confidence = confidence
+ self._platform = platform
def __del__(self):
core.BNFreeType(self.handle)
@@ -326,7 +371,7 @@ class Type(object):
result = core.BNGetChildType(self.handle)
if not result.type:
return None
- return Type(result.type, platform = self.platform, confidence = result.confidence)
+ return Type(result.type, platform = self._platform, confidence = result.confidence)
@property
def element_type(self):
@@ -334,7 +379,7 @@ class Type(object):
result = core.BNGetChildType(self.handle)
if not result.type:
return None
- return Type(result.type, platform = self.platform, confidence = result.confidence)
+ return Type(result.type, platform = self._platform, confidence = result.confidence)
@property
def return_value(self):
@@ -342,7 +387,7 @@ class Type(object):
result = core.BNGetChildType(self.handle)
if not result.type:
return None
- return Type(result.type, platform = self.platform, confidence = result.confidence)
+ return Type(result.type, platform = self._platform, confidence = result.confidence)
@property
def calling_convention(self):
@@ -359,13 +404,13 @@ class Type(object):
params = core.BNGetTypeParameters(self.handle, count)
result = []
for i in range(0, count.value):
- param_type = Type(core.BNNewTypeReference(params[i].type), platform = self.platform, confidence = params[i].typeConfidence)
+ param_type = Type(core.BNNewTypeReference(params[i].type), platform = self._platform, confidence = params[i].typeConfidence)
if params[i].defaultLocation:
param_location = None
else:
name = params[i].name
- if (params[i].location.type == VariableSourceType.RegisterVariableSourceType) and (self.platform is not None):
- name = self.platform.arch.get_reg_name(params[i].location.storage)
+ if (params[i].location.type == VariableSourceType.RegisterVariableSourceType) and (self._platform is not None):
+ name = self._platform.arch.get_reg_name(params[i].location.storage)
elif params[i].location.type == VariableSourceType.StackVariableSourceType:
name = "arg_%x" % params[i].location.storage
param_location = binaryninja.function.Variable(None, params[i].location.type, params[i].location.index,
@@ -431,25 +476,25 @@ class Type(object):
def __str__(self):
platform = None
- if self.platform is not None:
- platform = self.platform.handle
+ if self._platform is not None:
+ platform = self._platform.handle
return core.BNGetTypeString(self.handle, platform)
def __repr__(self):
- if self.confidence < max_confidence:
- return "<type: %s, %d%% confidence>" % (str(self), (self.confidence * 100) // max_confidence)
+ if self._confidence < max_confidence:
+ return "<type: %s, %d%% confidence>" % (str(self), (self._confidence * 100) // max_confidence)
return "<type: %s>" % str(self)
def get_string_before_name(self):
platform = None
- if self.platform is not None:
- platform = self.platform.handle
+ if self._platform is not None:
+ platform = self._platform.handle
return core.BNGetTypeStringBeforeName(self.handle, platform)
def get_string_after_name(self):
platform = None
- if self.platform is not None:
- platform = self.platform.handle
+ if self._platform is not None:
+ platform = self._platform.handle
return core.BNGetTypeStringAfterName(self.handle, platform)
@property
@@ -460,8 +505,8 @@ class Type(object):
def get_tokens(self, base_confidence = max_confidence):
count = ctypes.c_ulonglong()
platform = None
- if self.platform is not None:
- platform = self.platform.handle
+ if self._platform is not None:
+ platform = self._platform.handle
tokens = core.BNGetTypeTokens(self.handle, platform, base_confidence, count)
result = binaryninja.function.InstructionTextToken.get_instruction_lines(tokens, count.value)
core.BNFreeInstructionText(tokens, count.value)
@@ -470,8 +515,8 @@ class Type(object):
def get_tokens_before_name(self, base_confidence = max_confidence):
count = ctypes.c_ulonglong()
platform = None
- if self.platform is not None:
- platform = self.platform.handle
+ if self._platform is not None:
+ platform = self._platform.handle
tokens = core.BNGetTypeTokensBeforeName(self.handle, platform, base_confidence, count)
result = binaryninja.function.InstructionTextToken.get_instruction_lines(tokens, count.value)
core.BNFreeInstructionText(tokens, count.value)
@@ -480,8 +525,8 @@ class Type(object):
def get_tokens_after_name(self, base_confidence = max_confidence):
count = ctypes.c_ulonglong()
platform = None
- if self.platform is not None:
- platform = self.platform.handle
+ if self._platform is not None:
+ platform = self._platform.handle
tokens = core.BNGetTypeTokensAfterName(self.handle, platform, base_confidence, count)
result = binaryninja.function.InstructionTextToken.get_instruction_lines(tokens, count.value)
core.BNFreeInstructionText(tokens, count.value)
@@ -680,7 +725,7 @@ class Type(object):
return core.BNGetAutoDemangledTypeIdSource()
def with_confidence(self, confidence):
- return Type(handle = core.BNNewTypeReference(self.handle), platform = self.platform, confidence = confidence)
+ return Type(handle = core.BNNewTypeReference(self.handle), platform = self._platform, confidence = confidence)
def __setattr__(self, name, value):
try:
@@ -688,87 +733,195 @@ class Type(object):
except AttributeError:
raise AttributeError("attribute '%s' is read only" % name)
+ @property
+ def confidence(self):
+ """ """
+ return self._confidence
+
+ @confidence.setter
+ def confidence(self, value):
+ self._confidence = value
+
+ @property
+ def platform(self):
+ """ """
+ return self._platform
+
+ @platform.setter
+ def platform(self, value):
+ self._platform = value
+
class BoolWithConfidence(object):
def __init__(self, value, confidence = max_confidence):
- self.value = value
- self.confidence = confidence
+ self._value = value
+ self._confidence = confidence
def __str__(self):
- return str(self.value)
+ return str(self._value)
def __repr__(self):
- return repr(self.value)
+ return repr(self._value)
def __bool__(self):
- return self.value
+ return self._value
def __nonzero__(self):
- return self.value
+ return self._value
+
+ @property
+ def value(self):
+ """ """
+ return self._value
+
+ @value.setter
+ def value(self, value):
+ self._value = value
+
+ @property
+ def confidence(self):
+ """ """
+ return self._confidence
+
+ @confidence.setter
+ def confidence(self, value):
+ self._confidence = value
class SizeWithConfidence(object):
def __init__(self, value, confidence = max_confidence):
- self.value = value
- self.confidence = confidence
+ self._value = value
+ self._confidence = confidence
def __str__(self):
- return str(self.value)
+ return str(self._value)
def __repr__(self):
- return repr(self.value)
+ return repr(self._value)
def __int__(self):
- return self.value
+ return self._value
+
+ @property
+ def value(self):
+ """ """
+ return self._value
+
+ @value.setter
+ def value(self, value):
+ self._value = value
+
+ @property
+ def confidence(self):
+ """ """
+ return self._confidence
+
+ @confidence.setter
+ def confidence(self, value):
+ self._confidence = value
class RegisterStackAdjustmentWithConfidence(object):
def __init__(self, value, confidence = max_confidence):
- self.value = value
- self.confidence = confidence
+ self._value = value
+ self._confidence = confidence
def __str__(self):
- return str(self.value)
+ return str(self._value)
def __repr__(self):
- return repr(self.value)
+ return repr(self._value)
def __int__(self):
- return self.value
+ return self._value
+
+ @property
+ def value(self):
+ """ """
+ return self._value
+
+ @value.setter
+ def value(self, value):
+ self._value = value
+
+ @property
+ def confidence(self):
+ """ """
+ return self._confidence
+
+ @confidence.setter
+ def confidence(self, value):
+ self._confidence = value
class RegisterSet(object):
def __init__(self, reg_list, confidence = max_confidence):
- self.regs = reg_list
- self.confidence = confidence
+ self._regs = reg_list
+ self._confidence = confidence
def __repr__(self):
- return repr(self.regs)
+ return repr(self._regs)
def __iter__(self):
- for reg in self.regs:
+ for reg in self._regs:
yield reg
def __getitem__(self, idx):
- return self.regs[idx]
+ return self._regs[idx]
def __len__(self):
- return len(self.regs)
+ return len(self._regs)
def with_confidence(self, confidence):
- return RegisterSet(list(self.regs), confidence = confidence)
+ return RegisterSet(list(self._regs), confidence = confidence)
+
+ @property
+ def regs(self):
+ """ """
+ return self._regs
+
+ @regs.setter
+ def regs(self, value):
+ self._regs = value
+
+ @property
+ def confidence(self):
+ """ """
+ return self._confidence
+
+ @confidence.setter
+ def confidence(self, value):
+ self._confidence = value
class ReferenceTypeWithConfidence(object):
def __init__(self, value, confidence = max_confidence):
- self.value = value
- self.confidence = confidence
+ self._value = value
+ self._confidence = confidence
def __str__(self):
- return str(self.value)
+ return str(self._value)
def __repr__(self):
- return repr(self.value)
+ return repr(self._value)
+
+ @property
+ def value(self):
+ """ """
+ return self._value
+
+ @value.setter
+ def value(self, value):
+ self._value = value
+
+ @property
+ def confidence(self):
+ """ """
+ return self._confidence
+
+ @confidence.setter
+ def confidence(self, value):
+ self._confidence = value
class NamedTypeReference(object):
@@ -849,15 +1002,42 @@ class NamedTypeReference(object):
class StructureMember(object):
def __init__(self, t, name, offset):
- self.type = t
- self.name = name
- self.offset = offset
+ self._type = t
+ self._name = name
+ self._offset = offset
def __repr__(self):
- if len(self.name) == 0:
- return "<member: %s, offset %#x>" % (str(self.type), self.offset)
- return "<%s %s%s, offset %#x>" % (self.type.get_string_before_name(), self.name,
- self.type.get_string_after_name(), self.offset)
+ if len(self._name) == 0:
+ return "<member: %s, offset %#x>" % (str(self._type), self._offset)
+ return "<%s %s%s, offset %#x>" % (self._type.get_string_before_name(), self._name,
+ self._type.get_string_after_name(), self._offset)
+
+ @property
+ def type(self):
+ """ """
+ return self._type
+
+ @type.setter
+ def type(self, value):
+ self._type = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
+
+ @property
+ def offset(self):
+ """ """
+ return self._offset
+
+ @offset.setter
+ def offset(self, value):
+ self._offset = value
class Structure(object):
@@ -980,6 +1160,33 @@ class EnumerationMember(object):
def __repr__(self):
return "<%s = %#x>" % (self.name, self.value)
+ @property
+ def value(self):
+ """ """
+ return self._value
+
+ @value.setter
+ def value(self, value):
+ self._value = value
+
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
+
+ @property
+ def default(self):
+ """ """
+ return self._default
+
+ @default.setter
+ def default(self, value):
+ self._default = value
+
class Enumeration(object):
def __init__(self, handle=None):
@@ -1036,12 +1243,39 @@ class Enumeration(object):
class TypeParserResult(object):
def __init__(self, types, variables, functions):
- self.types = types
- self.variables = variables
- self.functions = functions
+ self._types = types
+ self._variables = variables
+ self._functions = functions
def __repr__(self):
- return "<types: %s, variables: %s, functions: %s>" % (self.types, self.variables, self.functions)
+ return "<types: %s, variables: %s, functions: %s>" % (self._types, self._variables, self._functions)
+
+ @property
+ def types(self):
+ """ """
+ return self._types
+
+ @types.setter
+ def types(self, value):
+ self._types = value
+
+ @property
+ def variables(self):
+ """ """
+ return self._variables
+
+ @variables.setter
+ def variables(self, value):
+ self._variables = value
+
+ @property
+ def functions(self):
+ """ """
+ return self._functions
+
+ @functions.setter
+ def functions(self, value):
+ self._functions = value
def preprocess_source(source, filename=None, include_dirs=[]):
diff --git a/python/undoaction.py b/python/undoaction.py
index 7690f930..d35c8d42 100644
--- a/python/undoaction.py
+++ b/python/undoaction.py
@@ -47,7 +47,7 @@ class UndoAction(object):
self._cb.undo = self._cb.undo.__class__(self._undo)
self._cb.redo = self._cb.redo.__class__(self._redo)
self._cb.serialize = self._cb.serialize.__class__(self._serialize)
- self.view = view
+ self._view = view
@classmethod
def register(cls):
@@ -96,3 +96,12 @@ class UndoAction(object):
except:
log.log_error(traceback.format_exc())
return "null"
+
+ @property
+ def view(self):
+ """ """
+ return self._view
+
+ @view.setter
+ def view(self, value):
+ self._view = value
diff --git a/python/update.py b/python/update.py
index 5bcd9a98..36c1a520 100644
--- a/python/update.py
+++ b/python/update.py
@@ -115,16 +115,16 @@ class UpdateProgressCallback(object):
class UpdateChannel(with_metaclass(_UpdateChannelMetaClass, object)):
def __init__(self, name, desc, ver):
- self.name = name
- self.description = desc
- self.latest_version_num = ver
+ self._name = name
+ self._description = desc
+ self._latest_version_num = ver
@property
def versions(self):
"""List of versions (read-only)"""
count = ctypes.c_ulonglong()
errors = ctypes.c_char_p()
- versions = core.BNGetUpdateChannelVersions(self.name, count, errors)
+ versions = core.BNGetUpdateChannelVersions(self._name, count, errors)
if errors:
error_str = errors.value
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
@@ -140,14 +140,14 @@ class UpdateChannel(with_metaclass(_UpdateChannelMetaClass, object)):
"""Latest version (read-only)"""
count = ctypes.c_ulonglong()
errors = ctypes.c_char_p()
- versions = core.BNGetUpdateChannelVersions(self.name, count, errors)
+ versions = core.BNGetUpdateChannelVersions(self._name, count, errors)
if errors:
error_str = errors.value
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
raise IOError(error_str)
result = None
for i in range(0, count.value):
- if versions[i].version == self.latest_version_num:
+ if versions[i].version == self._latest_version_num:
result = UpdateVersion(self, versions[i].version, versions[i].notes, versions[i].time)
break
core.BNFreeUpdateChannelVersionList(versions, count.value)
@@ -157,7 +157,7 @@ class UpdateChannel(with_metaclass(_UpdateChannelMetaClass, object)):
def updates_available(self):
"""Whether updates are available (read-only)"""
errors = ctypes.c_char_p()
- result = core.BNAreUpdatesAvailable(self.name, None, None, 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)))
@@ -171,45 +171,108 @@ class UpdateChannel(with_metaclass(_UpdateChannelMetaClass, object)):
raise AttributeError("attribute '%s' is read only" % name)
def __repr__(self):
- return "<channel: %s>" % self.name
+ return "<channel: %s>" % self._name
def __str__(self):
- return self.name
+ return self._name
def update_to_latest(self, progress = None):
cb = UpdateProgressCallback(progress)
errors = ctypes.c_char_p()
- result = core.BNUpdateToLatestVersion(self.name, errors, cb.cb, None)
+ result = core.BNUpdateToLatestVersion(self._name, errors, cb.cb, None)
if errors:
error_str = errors.value
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
raise IOError(error_str)
return UpdateResult(result)
+ @property
+ def name(self):
+ """ """
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ self._name = value
+
+ @property
+ def description(self):
+ """ """
+ return self._description
+
+ @description.setter
+ def description(self, value):
+ self._description = value
+
+ @property
+ def latest_version_num(self):
+ """ """
+ return self._latest_version_num
+
+ @latest_version_num.setter
+ def latest_version_num(self, value):
+ self._latest_version_num = value
+
class UpdateVersion(object):
def __init__(self, channel, ver, notes, t):
- self.channel = channel
- self.version = ver
- self.notes = notes
- self.time = t
+ self._channel = channel
+ self._version = ver
+ self._notes = notes
+ self._time = t
def __repr__(self):
- return "<version: %s>" % self.version
+ return "<version: %s>" % self._version
def __str__(self):
- return self.version
+ return self._version
def update(self, progress = None):
cb = UpdateProgressCallback(progress)
errors = ctypes.c_char_p()
- result = core.BNUpdateToVersion(self.channel.name, self.version, errors, cb.cb, None)
+ result = core.BNUpdateToVersion(self._channel.name, self._version, errors, cb.cb, None)
if errors:
error_str = errors.value
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
raise IOError(error_str)
return UpdateResult(result)
+ @property
+ def channel(self):
+ """ """
+ return self._channel
+
+ @channel.setter
+ def channel(self, value):
+ self._channel = value
+
+ @property
+ def version(self):
+ """ """
+ return self._version
+
+ @version.setter
+ def version(self, value):
+ self._version = value
+
+ @property
+ def notes(self):
+ """ """
+ return self._notes
+
+ @notes.setter
+ def notes(self, value):
+ self._notes = value
+
+ @property
+ def time(self):
+ """ """
+ return self._time
+
+ @time.setter
+ def time(self, value):
+ self._time = value
+
def are_auto_updates_enabled():
"""