summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py27
-rw-r--r--python/datarender.py13
-rw-r--r--python/enterprise.py6
-rw-r--r--python/flowgraph.py8
-rw-r--r--python/interaction.py76
-rw-r--r--python/mediumlevelil.py2
-rw-r--r--python/plugin.py2
-rw-r--r--python/types.py2
8 files changed, 69 insertions, 67 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 619d7592..5f93e5d1 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -80,14 +80,12 @@ from . import platform as _platform
from . import deprecation
from . import typecontainer
from . import externallibrary
-from . import project
from . import undo
from . import stringrecognizer
PathType = Union[str, os.PathLike]
InstructionsType = Generator[Tuple[List['_function.InstructionTextToken'], int], None, None]
-NotificationType = Mapping['BinaryDataNotification', 'BinaryDataNotificationCallbacks']
ProgressFuncType = Callable[[int, int], bool]
DataMatchCallbackType = Callable[[int, 'databuffer.DataBuffer'], bool]
LineMatchCallbackType = Callable[[int, 'lineardisassembly.LinearDisassemblyLine'], bool]
@@ -127,10 +125,10 @@ class ReferenceSource:
return self.function.get_low_level_il_at(self.address, self.arch)
@property
- def llils(self) -> Iterator[lowlevelil.LowLevelILInstruction]:
+ def llils(self) -> List[lowlevelil.LowLevelILInstruction]:
"""Returns the low level il instructions at the current location if any exists"""
if self.function is None or self.arch is None:
- return
+ return []
return self.function.get_low_level_ils_at(self.address, self.arch)
@property
@@ -306,7 +304,7 @@ class BinaryDataNotification:
>>>
"""
- def __init__(self, notifications: NotificationType = None):
+ def __init__(self, notifications: Optional[NotificationType] = None):
self.notifications = notifications
def notification_barrier(self, view: 'BinaryView') -> int:
@@ -826,7 +824,7 @@ class BinaryDataNotificationCallbacks:
self._notify = notify
self._cb = core.BNBinaryDataNotification()
self._cb.context = 0
- if (not hasattr(notify, 'notifications')) or (hasattr(notify, 'notifications') and notify.notifications is None):
+ if (not hasattr(notify, 'notifications')) or (notify.notifications is None):
self._cb.notificationBarrier = self._cb.notificationBarrier
self._cb.dataWritten = self._cb.dataWritten.__class__(self._data_written)
self._cb.dataInserted = self._cb.dataInserted.__class__(self._data_inserted)
@@ -9369,7 +9367,7 @@ to a the type "tagRECT" found in the typelibrary "winX64common"
return result.value
class QueueGenerator:
- def __init__(self, t, results):
+ def __init__(self, t: threading.Thread, results: queue.Queue):
self.thread = t
self.results = results
t.start()
@@ -9388,7 +9386,7 @@ to a the type "tagRECT" found in the typelibrary "winX64common"
def find_all_data(
self, start: int, end: int, data: bytes, flags: FindFlag = FindFlag.FindCaseSensitive,
progress_func: Optional[ProgressFuncType] = None, match_callback: Optional[DataMatchCallbackType] = None
- ) -> QueueGenerator:
+ ) -> Union[QueueGenerator, bool]:
"""
``find_all_data`` searches for the bytes ``data`` starting at the virtual address ``start``
until the virtual address ``end``. Once a match is found, the ``match_callback`` is called.
@@ -9464,7 +9462,7 @@ to a the type "tagRECT" found in the typelibrary "winX64common"
self, start: int, end: int, text: str, settings: Optional[_function.DisassemblySettings] = None,
flags=FindFlag.FindCaseSensitive, graph_type: _function.FunctionViewTypeOrName = FunctionGraphType.NormalFunctionGraph, progress_func=None,
match_callback=None
- ) -> QueueGenerator:
+ ) -> Union[QueueGenerator, bool]:
"""
``find_all_text`` searches for string ``text`` occurring in the linear view output starting
at the virtual address ``start`` until the virtual address ``end``. Once a match is found,
@@ -9559,7 +9557,7 @@ to a the type "tagRECT" found in the typelibrary "winX64common"
self, start: int, end: int, constant: int, settings: Optional[_function.DisassemblySettings] = None,
graph_type: _function.FunctionViewTypeOrName = FunctionGraphType.NormalFunctionGraph, progress_func: Optional[ProgressFuncType] = None,
match_callback: Optional[LineMatchCallbackType] = None
- ) -> QueueGenerator:
+ ) -> Union[QueueGenerator, bool]:
"""
``find_all_constant`` searches for the integer constant ``constant`` starting at the
virtual address ``start`` until the virtual address ``end``. Once a match is found,
@@ -9632,8 +9630,8 @@ to a the type "tagRECT" found in the typelibrary "winX64common"
return self.QueueGenerator(t, results)
- def search(self, pattern: str, start: int = None, end: int = None, raw: bool = False, ignore_case: bool = False, overlap: bool = False, align: int = 1,
- limit: int = None, progress_callback: Optional[ProgressFuncType] = None, match_callback: Optional[DataMatchCallbackType] = None) -> QueueGenerator:
+ def search(self, pattern: str, start: Optional[int] = None, end: Optional[int] = None, raw: bool = False, ignore_case: bool = False, overlap: bool = False, align: int = 1,
+ limit: Optional[int] = None, progress_callback: Optional[ProgressFuncType] = None, match_callback: Optional[DataMatchCallbackType] = None) -> QueueGenerator:
r"""
Searches for matches of the specified ``pattern`` within this BinaryView with an optionally provided address range specified by ``start`` and ``end``.
This is the API used by the advanced binary search UI option. The search pattern can be interpreted in various ways:
@@ -11355,7 +11353,10 @@ class TypedDataAccessor:
if isinstance(self.type, (_types.IntegerType, _types.IntegerBuilder)):
signed = bool(self.type.signed)
to_write = data.to_bytes(len(self), TypedDataAccessor.byte_order(self.endian), signed=signed) # type: ignore
- elif isinstance(data, float) and isinstance(self.type, (_types.FloatType, _types.FloatBuilder)):
+ elif isinstance(data, float):
+ if not isinstance(self.type, (_types.FloatType, _types.FloatBuilder)):
+ raise TypeError(f"Can't set the value of type {type(self.type)} to float value")
+
endian = "<" if self.endian == Endianness.LittleEndian else ">"
if self.type.width == 2:
code = "e"
diff --git a/python/datarender.py b/python/datarender.py
index d516f26e..152477ae 100644
--- a/python/datarender.py
+++ b/python/datarender.py
@@ -20,6 +20,7 @@
import traceback
import ctypes
+from typing import List, Optional
import binaryninja
from . import _binaryninjacore as core
@@ -34,7 +35,7 @@ from . import types
class TypeContext:
- def __init__(self, _type, _offset):
+ def __init__(self, _type: types.Type, _offset: int):
self._type = _type
self._offset = _offset
@@ -85,7 +86,7 @@ class DataRenderer:
"""
_registered_renderers = []
- def __init__(self, context=None):
+ def __init__(self, context: Optional[TypeContext] = None):
self._cb = core.BNCustomDataRenderer()
self._cb.context = context
self._cb.freeObject = self._cb.freeObject.__class__(self._free_object)
@@ -137,7 +138,7 @@ class DataRenderer:
type = types.Type.create(handle=core.BNNewTypeReference(type))
prefixTokens = function.InstructionTextToken._from_core_struct(prefix, prefixCount)
- pycontext = []
+ pycontext: List[TypeContext] = []
for i in range(ctxCount):
pycontext.append(
TypeContext(types.Type.create(core.BNNewTypeReference(typeCtx[i].type)), typeCtx[i].offset)
@@ -184,13 +185,13 @@ class DataRenderer:
def perform_free_object(self, ctxt):
pass
- def perform_is_valid_for_data(self, ctxt, view, addr, type, context):
+ def perform_is_valid_for_data(self, ctxt, view: binaryview.BinaryView, addr: int, type: types.Type, context: List[TypeContext]) -> bool:
return False
- def perform_get_lines_for_data(self, ctxt, view, addr, type, prefix, width, context):
+ def perform_get_lines_for_data(self, ctxt, view: binaryview.BinaryView, addr: int, type: types.Type, prefix: List[function.InstructionTextToken], width: int, context: List[TypeContext]) -> List['function.DisassemblyTextLine']:
return []
- def perform_get_lines_for_data_with_language(self, ctxt, view, addr, type, prefix, width, context, language):
+ def perform_get_lines_for_data_with_language(self, ctxt, view: binaryview.BinaryView, addr: int, type: types.Type, prefix: List[function.InstructionTextToken], width: int, context: List[TypeContext], language: str) -> List['function.DisassemblyTextLine']:
return self.perform_get_lines_for_data(ctxt, view, addr, type, prefix, width, context)
def __del__(self):
diff --git a/python/enterprise.py b/python/enterprise.py
index 1ab04fdd..83a95c27 100644
--- a/python/enterprise.py
+++ b/python/enterprise.py
@@ -320,7 +320,7 @@ class LicenseCheckout:
"""
Helper class for scripts to make use of a license checkout in a scope.
- :param duration: Duration between refreshes
+ :param duration: Duration in seconds between refreshes
:param _cache: Deprecated but left in for compatibility
:param release: If the license should be released at the end of scope. If `False`, you
can either manually release it later or it will expire after `duration`.
@@ -334,11 +334,11 @@ class LicenseCheckout:
... print(hex(bv.start))
# License is released at end of scope
"""
- def __init__(self, duration=900, _cache=True, release=True):
+ def __init__(self, duration: int = 900, _cache: bool = True, release: bool = True):
"""
Get a new license checkout
- :param duration: Duration between refreshes
+ :param duration: Duration in seconds between refreshes
:param _cache: Deprecated but left in for compatibility
:param release: If the license should be released at the end of scope. If `False`, you
can either manually release it later or it will expire after `duration`.
diff --git a/python/flowgraph.py b/python/flowgraph.py
index 4cbb40d8..527ddd8b 100644
--- a/python/flowgraph.py
+++ b/python/flowgraph.py
@@ -21,7 +21,7 @@
import ctypes
import threading
import traceback
-from typing import List, Optional, Tuple
+from typing import List, Optional, Tuple, Union
# Binary Ninja components
import binaryninja
@@ -41,7 +41,7 @@ from . import interaction
class FlowGraphEdge:
- def __init__(self, branch_type, source, target, points, back_edge, style):
+ def __init__(self, branch_type: Union[BranchType, int], source: 'FlowGraphNode', target: 'FlowGraphNode', points: List[Tuple[float, float]], back_edge: bool, style: 'EdgeStyle'):
self.type = BranchType(branch_type)
self.source = source
self.target = target
@@ -85,7 +85,7 @@ class EdgeStyle:
class FlowGraphNode:
- def __init__(self, graph=None, handle=None):
+ def __init__(self, graph: Optional['FlowGraph'] = None, handle=None):
_handle = handle
if _handle is None:
if graph is None:
@@ -343,7 +343,7 @@ class FlowGraphNode:
class FlowGraphLayoutRequest:
- def __init__(self, graph, callback=None):
+ def __init__(self, graph: 'FlowGraph', callback=None):
self.on_complete = callback
self._cb = ctypes.CFUNCTYPE(None, ctypes.c_void_p)(self._complete)
self.handle = core.BNStartFlowGraphLayout(graph.handle, None, self._cb)
diff --git a/python/interaction.py b/python/interaction.py
index 27648e12..d94fdb87 100644
--- a/python/interaction.py
+++ b/python/interaction.py
@@ -381,12 +381,12 @@ class SaveFileNameField:
"""
``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="", default=None):
+ def __init__(self, prompt: str, ext: str = "", default_name: str = "", default: Optional[str] = None):
self._prompt = prompt
self._ext = ext
self._default_name = default_name
self._default = default
- self._result = None
+ self._result: Optional[str] = None
def _fill_core_struct(self, value):
value.type = FormInputFieldType.SaveFileNameFormField
@@ -408,7 +408,7 @@ class SaveFileNameField:
return self._prompt
@prompt.setter
- def prompt(self, value):
+ def prompt(self, value: str):
self._prompt = value
@property
@@ -416,7 +416,7 @@ class SaveFileNameField:
return self._ext
@ext.setter
- def ext(self, value):
+ def ext(self, value: str):
self._ext = value
@property
@@ -424,7 +424,7 @@ class SaveFileNameField:
return self._default_name
@default_name.setter
- def default_name(self, value):
+ def default_name(self, value: str):
self._default_name = value
@property
@@ -432,7 +432,7 @@ class SaveFileNameField:
return self._result
@result.setter
- def result(self, value):
+ def result(self, value: Optional[str]):
self._result = value
@@ -441,7 +441,7 @@ class DirectoryNameField:
``DirectoryNameField`` prompts the user to specify a directory name to open. Result is stored in self.result as
a string.
"""
- def __init__(self, prompt, default_name="", default=None):
+ def __init__(self, prompt: str, default_name: str = "", default: Optional[str] = None):
self._prompt = prompt
self._default_name = default_name
self._default = default
@@ -466,7 +466,7 @@ class DirectoryNameField:
return self._prompt
@prompt.setter
- def prompt(self, value):
+ def prompt(self, value: str):
self._prompt = value
@property
@@ -474,7 +474,7 @@ class DirectoryNameField:
return self._default_name
@default_name.setter
- def default_name(self, value):
+ def default_name(self, value: str):
self._default_name = value
@property
@@ -482,7 +482,7 @@ class DirectoryNameField:
return self._result
@result.setter
- def result(self, value):
+ def result(self, value: Optional[str]):
self._result = value
@@ -494,7 +494,7 @@ class CheckboxField:
:param str prompt: Prompt to be presented to the user
:param bool default: Default state of the checkbox (False == unchecked, True == checked)
"""
- def __init__(self, prompt, default):
+ def __init__(self, prompt: str, default: Optional[bool]):
self._prompt = prompt
self._result = None
self._default = default
@@ -516,7 +516,7 @@ class CheckboxField:
return self._prompt
@prompt.setter
- def prompt(self, value):
+ def prompt(self, value: str):
self._prompt = value
@property
@@ -524,7 +524,7 @@ class CheckboxField:
return self._result
@result.setter
- def result(self, value):
+ def result(self, value: bool):
self._result = value
@property
@@ -532,7 +532,7 @@ class CheckboxField:
return self._default
@default.setter
- def default(self, value):
+ def default(self, value: Optional[bool]):
self._default = value
@@ -882,7 +882,7 @@ class InteractionHandler:
class PlainTextReport:
- def __init__(self, title, contents, view=None):
+ def __init__(self, title: str, contents: str, view: Optional['binaryview.BinaryView'] = None):
self._view = view
self._title = title
self._contents = contents
@@ -898,7 +898,7 @@ class PlainTextReport:
return self._view
@view.setter
- def view(self, value):
+ def view(self, value: Optional['binaryview.BinaryView']):
self._view = value
@property
@@ -906,7 +906,7 @@ class PlainTextReport:
return self._title
@title.setter
- def title(self, value):
+ def title(self, value: str):
self._title = value
@property
@@ -914,12 +914,12 @@ class PlainTextReport:
return self._contents
@contents.setter
- def contents(self, value):
+ def contents(self, value: str):
self._contents = value
class MarkdownReport:
- def __init__(self, title, contents, plaintext="", view=None):
+ def __init__(self, title: str, contents: str, plaintext: str = "", view: Optional['binaryview.BinaryView'] = None):
self._view = view
self._title = title
self._contents = contents
@@ -936,7 +936,7 @@ class MarkdownReport:
return self._view
@view.setter
- def view(self, value):
+ def view(self, value: Optional['binaryview.BinaryView']):
self._view = value
@property
@@ -944,7 +944,7 @@ class MarkdownReport:
return self._title
@title.setter
- def title(self, value):
+ def title(self, value: str):
self._title = value
@property
@@ -952,7 +952,7 @@ class MarkdownReport:
return self._contents
@contents.setter
- def contents(self, value):
+ def contents(self, value: str):
self._contents = value
@property
@@ -960,12 +960,12 @@ class MarkdownReport:
return self._plaintext
@plaintext.setter
- def plaintext(self, value):
+ def plaintext(self, value: str):
self._plaintext = value
class HTMLReport:
- def __init__(self, title, contents, plaintext="", view=None):
+ def __init__(self, title: str, contents: str, plaintext: str = "", view: Optional['binaryview.BinaryView'] = None):
self._view = view
self._title = title
self._contents = contents
@@ -982,7 +982,7 @@ class HTMLReport:
return self._view
@view.setter
- def view(self, value):
+ def view(self, value: Optional['binaryview.BinaryView']):
self._view = value
@property
@@ -990,7 +990,7 @@ class HTMLReport:
return self._title
@title.setter
- def title(self, value):
+ def title(self, value: str):
self._title = value
@property
@@ -998,7 +998,7 @@ class HTMLReport:
return self._contents
@contents.setter
- def contents(self, value):
+ def contents(self, value: str):
self._contents = value
@property
@@ -1006,12 +1006,12 @@ class HTMLReport:
return self._plaintext
@plaintext.setter
- def plaintext(self, value):
+ def plaintext(self, value: str):
self._plaintext = value
class FlowGraphReport:
- def __init__(self, title, graph, view=None):
+ def __init__(self, title: str, graph: 'flowgraph.FlowGraph', view: Optional['binaryview.BinaryView'] = None):
self._view = view
self._title = title
self._graph = graph
@@ -1024,7 +1024,7 @@ class FlowGraphReport:
return self._view
@view.setter
- def view(self, value):
+ def view(self, value: Optional['binaryview.BinaryView']):
self._view = value
@property
@@ -1032,7 +1032,7 @@ class FlowGraphReport:
return self._title
@title.setter
- def title(self, value):
+ def title(self, value: str):
self._title = value
@property
@@ -1040,7 +1040,7 @@ class FlowGraphReport:
return self._graph
@graph.setter
- def graph(self, value):
+ def graph(self, value: 'flowgraph.FlowGraph'):
self._graph = value
@@ -1056,22 +1056,22 @@ class ReportCollection:
def _report_from_index(self, i):
report_type = core.BNGetReportType(self.handle, i)
- title = core.BNGetReportTitle(self.handle, i)
+ title: str = core.BNGetReportTitle(self.handle, i) # type: ignore
view = core.BNGetReportView(self.handle, i)
if view:
view = binaryview.BinaryView(handle=view)
else:
view = None
if report_type == ReportType.PlainTextReportType:
- contents = core.BNGetReportContents(self.handle, i)
+ contents: str = core.BNGetReportContents(self.handle, i) # type: ignore
return PlainTextReport(title, contents, view)
elif report_type == ReportType.MarkdownReportType:
- contents = core.BNGetReportContents(self.handle, i)
- plaintext = core.BNGetReportPlainText(self.handle, i)
+ contents: str = core.BNGetReportContents(self.handle, i) # type: ignore
+ plaintext: str = core.BNGetReportPlainText(self.handle, i) # type: ignore
return MarkdownReport(title, contents, plaintext, view)
elif report_type == ReportType.HTMLReportType:
- contents = core.BNGetReportContents(self.handle, i)
- plaintext = core.BNGetReportPlainText(self.handle, i)
+ contents: str = core.BNGetReportContents(self.handle, i) # type: ignore
+ plaintext: str = core.BNGetReportPlainText(self.handle, i) # type: ignore
return HTMLReport(title, contents, plaintext, view)
elif report_type == ReportType.FlowGraphReportType:
graph = flowgraph.CoreFlowGraph(core.BNGetReportFlowGraph(self.handle, i))
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index e710d5c2..61c0bf1b 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -3273,7 +3273,7 @@ class MediumLevelILExpr:
.. note:: Deprecated. Use ExpressionIndex instead
"""
- def __init__(self, index):
+ def __init__(self, index: int):
self._index = index
def __int__(self):
diff --git a/python/plugin.py b/python/plugin.py
index c2d25948..d8206bb8 100644
--- a/python/plugin.py
+++ b/python/plugin.py
@@ -1073,7 +1073,7 @@ class BackgroundTask(metaclass=_BackgroundTaskMetaclass):
:param initial_progress_text: text description of the task to display in the status bar in the UI, defaults to `""`
:param can_cancel: whether to enable cancellation of the task, defaults to `False`
"""
- def __init__(self, initial_progress_text="", can_cancel=False, handle=None):
+ def __init__(self, initial_progress_text: str = "", can_cancel: bool = False, handle=None):
if handle is None:
self.handle = core.BNBeginBackgroundTask(initial_progress_text, can_cancel)
else:
diff --git a/python/types.py b/python/types.py
index 5b3de7c9..7ad75603 100644
--- a/python/types.py
+++ b/python/types.py
@@ -552,7 +552,7 @@ class MutableTypeBuilder(Generic[TB]):
class TypeBuilderAttributes(dict):
- def __init__(self, builder, *args):
+ def __init__(self, builder: 'TypeBuilder', *args):
super(TypeBuilderAttributes, self).__init__(*args)
self._builder = builder