From c7ffb77e1fdc2e9bc7a2de27c2feddf15e8b54ea Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 11 Mar 2022 15:37:46 -0500 Subject: Add simple load API for creating a BinaryView from various input types. --- python/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'python/__init__.py') diff --git a/python/__init__.py b/python/__init__.py index b973118a..e0cd31ad 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -278,6 +278,32 @@ def get_memory_usage_info() -> Mapping[str, int]: return result +def load(*args, **kwargs) -> Optional[BinaryView]: + """ + `load` is a convenience wrapper for :py:class:`BinaryViewType.load` that opens a BinaryView object. + + :param Union[str, bytes, bytearray, 'databuffer.DataBuffer'] source: a file or byte stream for which load load into a virtual memory space + :param bool update_analysis: whether or not to run :func:`update_analysis_and_wait` after opening a :py:class:`BinaryView`, defaults to ``True`` + :param callback progress_func: optional function to be called with the current progress and total count + :param dict options: a dictionary in the form {setting identifier string : object value} + :return: returns a :py:class:`BinaryView` object for the given filename or ``None`` + :rtype: :py:class:`BinaryView` or ``None`` + + :Example: + >>> from binaryninja import * + >>> with load("/bin/ls") as bv: + ... print(len(list(bv.functions))) + ... + 134 + + >>> with load(bytes.fromhex('5054ebfe'), options={'loader.architecture' : 'x86'}) as bv: + ... print(len(list(bv.functions))) + ... + 1 + """ + return BinaryViewType.load(*args, **kwargs) + + def open_view(*args, **kwargs) -> Optional[BinaryView]: """ `open_view` is a convenience wrapper for :py:class:`get_view_of_file_with_options` that opens a BinaryView object. -- cgit v1.3.1