summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJordan Wiens <jordan@psifertex.com>2020-03-11 19:38:45 -0400
committerJordan Wiens <jordan@psifertex.com>2020-03-11 19:38:45 -0400
commit53c08c119e1269822b0ace389e26b1172c419871 (patch)
treeb2fe20790e703fab19b1ed4c07472c928af8c932 /python
parentbf343d1fca2e9cd577489b36eac375715be1f07a (diff)
documentation for the Type class, setter for function_type can take a string, and __str__ for functions with the full prototype: Fixes #1549
Diffstat (limited to 'python')
-rw-r--r--python/function.py11
-rw-r--r--python/types.py11
2 files changed, 21 insertions, 1 deletions
diff --git a/python/function.py b/python/function.py
index 9eac5728..029b70f3 100644
--- a/python/function.py
+++ b/python/function.py
@@ -793,6 +793,12 @@ class Function(object):
except AttributeError:
raise AttributeError("attribute '%s' is read only" % name)
+ def __str__(self):
+ result = ""
+ for token in self.type_tokens:
+ result += token.text
+ return result
+
def __repr__(self):
arch = self.arch
if arch:
@@ -1220,11 +1226,14 @@ class Function(object):
@property
def function_type(self):
- """Function type object"""
+ """Function type object, can be set with either a string representing the function prototype (`str(function)` shows examples) or a :py:class:`Type` object"""
return types.Type(core.BNGetFunctionType(self.handle), platform = self.platform)
@function_type.setter
def function_type(self, value):
+ if isinstance(value, str):
+ (value, new_name) = self.view.parse_type_string(value)
+ self.name = str(new_name)
self.set_user_type(value)
@property
diff --git a/python/types.py b/python/types.py
index bd251e0d..00810c11 100644
--- a/python/types.py
+++ b/python/types.py
@@ -319,6 +319,17 @@ class FunctionParameter(object):
class Type(object):
+ """
+ ``class Type`` allows you to interact with the Binary Ninja type system. Note that the ``repr`` and ``str``
+ handlers respond differently on type objects.
+
+ Other related functions that may be helpful include:
+
+ :py:meth:`parse_type_string <binaryninja.binaryview.BinaryView.parse_type_string>`
+ :py:meth:`parse_types_from_source <binaryninja.platform.Platform.parse_types_from_source>`
+ :py:meth:`parse_types_from_source_file <binaryninja.platform.Platform.parse_types_from_source_file>`
+
+ """
def __init__(self, handle, platform = None, confidence = max_confidence):
self._handle = handle
self._mutable = isinstance(handle.contents, core.BNTypeBuilder)