MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / load

Method load

python/binaryview.py:2882–2940  ·  view source on GitHub ↗

``load`` opens, generates default load options (which are overridable), and returns the first available \ :py:class:`BinaryView`. If no :py:class:`BinaryViewType` is available, then a ``Mapped`` :py:class:`BinaryViewType` is used to load \ the :py:class:`BinaryView` with the specified load op

(source: Union[str, bytes, bytearray, 'databuffer.DataBuffer', 'os.PathLike', 'BinaryView', 'project.ProjectFile'], update_analysis: bool = True,
	    progress_func: Optional[ProgressFuncType] = None, options: Mapping[str, Any] = {})

Source from the content-addressed store, hash-verified

2880
2881 @staticmethod
2882 def load(source: Union[str, bytes, bytearray, 'databuffer.DataBuffer', 'os.PathLike', 'BinaryView', 'project.ProjectFile'], update_analysis: bool = True,
2883 progress_func: Optional[ProgressFuncType] = None, options: Mapping[str, Any] = {}) -> Optional['BinaryView']:
2884 """
2885 ``load`` opens, generates default load options (which are overridable), and returns the first available \
2886 :py:class:`BinaryView`. If no :py:class:`BinaryViewType` is available, then a ``Mapped`` :py:class:`BinaryViewType` is used to load \
2887 the :py:class:`BinaryView` with the specified load options. The ``Mapped`` view type attempts to auto-detect the architecture of the \
2888 file during initialization. If no architecture is detected or specified in the load options, then the ``Mapped`` view type fails to \
2889 initialize and returns ``None``.
2890
2891 .. note:: Although general container file support is not complete, support for Universal archives exists. It's possible to control the architecture preference \
2892 with the **'files.universal.architecturePreference'** setting. This setting is scoped to SettingsUserScope and can be modified as follows ::
2893
2894 >>> Settings().set_string_list("files.universal.architecturePreference", ["arm64"])
2895
2896 It's also possible to override the **'files.universal.architecturePreference'** user setting by specifying it directly with :py:func:`load`.
2897 This specific usage of this setting is experimental and may change in the future ::
2898
2899 >>> bv = binaryninja.load('/bin/ls', options={'files.universal.architecturePreference': ['arm64']})
2900
2901 .. warning:: The recommended code pattern for opening a BinaryView is to use the \
2902 :py:func:`~binaryninja.load` API as a context manager like ``with load('/bin/ls') as bv:`` \
2903 which will automatically clean up when done with the view. If using this API directly \
2904 you will need to call `bv.file.close()` before the BinaryView leaves scope to ensure the \
2905 reference is properly removed and prevents memory leaks.
2906
2907 :param Union[str, bytes, bytearray, 'databuffer.DataBuffer', 'os.PathLike', 'BinaryView'] source: path to file/bndb, raw bytes, or raw view to load
2908 :param bool update_analysis: whether or not to run :py:func:`~BinaryView.update_analysis_and_wait` after opening a :py:class:`BinaryView`, defaults to ``True``
2909 :param callback progress_func: optional function to be called with the current progress and total count
2910 :param dict options: a dictionary in the form {setting identifier string : object value}
2911 :return: returns a :py:class:`BinaryView` object for the given filename or ``None``
2912 :rtype: :py:class:`BinaryView` or ``None``
2913
2914 :Example:
2915
2916 >>> binaryninja.load('/bin/ls', options={'loader.imageBase': 0xfffffff0000, 'loader.macho.processFunctionStarts' : False})
2917 <BinaryView: '/bin/ls', start 0xfffffff0000, len 0xa290>
2918 >>>
2919 """
2920 binaryninja._init_plugins()
2921
2922 if progress_func is None:
2923 progress_cfunc = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_ulonglong)(lambda ctxt, cur, total: True)
2924 else:
2925 progress_cfunc = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_ulonglong)(lambda ctxt, cur, total: progress_func(cur, total))
2926
2927 if isinstance(source, os.PathLike):
2928 source = str(source)
2929 if isinstance(source, BinaryView):
2930 handle = core.BNLoadBinaryView(source.handle, update_analysis, json.dumps(options), progress_cfunc, None)
2931 elif isinstance(source, project.ProjectFile):
2932 handle = core.BNLoadProjectFile(source._handle, update_analysis, json.dumps(options), progress_cfunc, None)
2933 elif isinstance(source, str):
2934 handle = core.BNLoadFilename(source, update_analysis, json.dumps(options), progress_cfunc, None)
2935 elif isinstance(source, bytes) or isinstance(source, bytearray) or isinstance(source, databuffer.DataBuffer):
2936 raw_view = BinaryView.new(source)
2937 handle = core.BNLoadBinaryView(raw_view.handle, update_analysis, json.dumps(options), progress_cfunc, None)
2938 else:
2939 raise NotImplementedError

Callers 15

__init__Method · 0.45
loadFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
M6502Class · 0.45
load_zero_page_16Method · 0.45
indirect_loadMethod · 0.45
pe_stat.pyFile · 0.45
translate_instrFunction · 0.45
feature_map.pyFile · 0.45
guid_benchmarkFunction · 0.45

Calls 2

BinaryViewClass · 0.70
newMethod · 0.45

Tested by 4

mainFunction · 0.36
insta_signaturesFunction · 0.36
type_conversionFunction · 0.36
check_for_leaksFunction · 0.36