raiseRuntimeError("License is not valid. Please supply a valid license.")
_destruct_callbacks=_DestructionCallbackHandler()
defdisable_default_log() ->None:
'''Disable default logging in headless mode for the current session. By default, logging in headless operation is controlled by the 'python.log.minLevel' settings.'''
global_enable_default_log
_enable_default_log=False
close_logs()
defbundled_plugin_path() ->Optional[str]:
"""
``bundled_plugin_path`` returns a string containing the current plugin path inside the `install path <https://docs.binary.ninja/guide/#binary-path>`_
:return: current bundled plugin path
:rtype: str, or None on failure
"""
returncore.BNGetBundledPluginDirectory()
defuser_plugin_path() ->Optional[str]:
"""
``user_plugin_path`` returns a string containing the current plugin path inside the `user directory <https://docs.binary.ninja/guide/#user-folder>`_
:return: current user plugin path
:rtype: str, or None on failure
"""
returncore.BNGetUserPluginDirectory()
defuser_directory() ->Optional[str]:
"""
``user_directory`` returns a string containing the path to the `user directory <https://docs.binary.ninja/guide/#user-folder>`_
:return: current user path
:rtype: str, or None on failure
"""
returncore.BNGetUserDirectory()
defcore_version() ->Optional[str]:
"""
``core_version`` returns a string containing the current version
:return: current version
:rtype: str, or None on failure
"""
returncore.BNGetVersionString()
defcore_version_info() ->CoreVersionInfo:
"""
``core_version_info`` returns a CoreVersionInfo containing the current version information
'''Indicates that a UI exists and the UI has invoked BNInitUI'''
returncore.BNIsUIEnabled()
defcore_set_license(licenseData: str) ->None:
'''
``core_set_license`` is used to initialize the core with a license file that doesn't necessarily reside on a file system. This is especially useful for headless environments such as docker where loading the license file via an environment variable allows for greater security of the license file itself.
:param str licenseData: string containing the full contents of a license file
:rtype: None
:Example:
>>> import os
>>> core_set_license(os.environ['BNLICENSE']) #Do this before creating any BinaryViews
>>> with load("/bin/ls") as bv:
... print(len(list(bv.functions)))
128
'''
core.BNSetLicense(licenseData)
defget_memory_usage_info() ->Mapping[str, int]:
"""
Get counts of various Binary Ninja objects in memory.
:return: Dictionary of {class name: count} for objects in memory
"""
count=ctypes.c_ulonglong()
info=core.BNGetMemoryUsageInfo(count)
assertinfoisnotNone, "core.BNGetMemoryUsageInfo returned None"
result= {}
foriinrange(0, count.value):
result[info[i].name] =info[i].value
core.BNFreeMemoryUsageInfo(info, count.value)
returnresult
defget_stat_histograms() ->Mapping[str, dict]:
"""
Get per-tag bit-length histograms gathered by StatCollector instrumentation.
Each entry maps a tag name to ``{"total": int, "buckets": [int; 65]}`` where
``buckets[k]`` counts samples whose value has ``bit_width == k`` (k in 0..64) and
``total`` is the sum of the sampled values. Empty unless a ``StatCollector`` was
instantiated somewhere in the core during analysis.
:return: Dictionary of {tag name: {"total": int, "buckets": list[int]}}
"""
count=ctypes.c_ulonglong()
info=core.BNGetStatHistograms(count)
assertinfoisnotNone, "core.BNGetStatHistograms returned None"
result= {}
foriinrange(0, count.value):
result[info[i].name] = {
"total": info[i].total,
"buckets": list(info[i].buckets),
}
core.BNFreeStatHistograms(info, count.value)
returnresult
defload(*args, **kwargs) ->BinaryView:
"""
Opens a BinaryView object.
:param Union[str, bytes, bytearray, 'databuffer.DataBuffer', 'os.PathLike', 'project.ProjectFile'] source: a file or byte stream to 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 for BNDB files only
:param dict options: a dictionary in the form {setting identifier string : object value}
:return: returns a :py:class:`BinaryView` object for the given filename
:rtype: :py:class:`BinaryView`
:raises Exception: When a BinaryView could not be created
.. note:: The progress_func callback **must** return True to continue the load operation, False will abort the load operation.
.. warning:: The progress_func will **only** be called for BNDB files, not for any other file format due to a `design limitation <https://github.com/Vector35/binaryninja-api/issues/4116#issuecomment-1479496712>`_.
:Example:
>>> from binaryninja import *
>>> with load("/bin/ls") as bv:
... print(len(list(bv.functions)))
...
134
>>> with load(bytes.fromhex('5054ebfe'), options={'loader.platform' : 'x86'}) as bv:
... print(len(list(bv.functions)))
...
1
"""
bv=BinaryView.load(*args, **kwargs)
ifbvisNone:
raiseException("Unable to create new BinaryView")
returnbv
defconnect_pycharm_debugger(port=5678):
"""
Connect to PyCharm (Professional Edition) for debugging.
.. note:: See the user documentation `pycharm note <https://docs.binary.ninja/dev/plugins.html#remote-debugging-with-intellij-pycharm>`_ for step-by-step instructions on how to set up Python debugging.
:param port: Port number for connecting to the debugger.
"""
# Get pip install string from PyCharm's Python Debug Server Configuration
Connect to Visual Studio Code for debugging. This function blocks until the debugger
is connected! Not recommended for use in startup.py
.. note:: See the user documentation `vscode note <https://docs.binary.ninja/dev/plugins.html#remote-debugging-with-vscode>`_ for step-by-step instructions on how to set up Python debugging.
:param port: Port number for connecting to the debugger.