Binary Ninja Python API Reference

Welcome to the Binary Ninja API documentation. The below methods are available from the root of the binaryninja package, but most of the API is organized into the modules shown in the left side-bar.

You can also scroll to the end to view a class list of all available classes.

The search bar on the side works both online and offline.

exception UIPluginInHeadlessError(*args, **kwargs)[source]

Bases: Exception

class CoreVersionInfo(major: int, minor: int, build: int, channel: str)[source]

Bases: object

Parameters
  • major (int) –

  • minor (int) –

  • build (int) –

  • channel (str) –

Return type

None

build: int
channel: str
major: int
minor: int
bundled_plugin_path() Optional[str][source]

bundled_plugin_path returns a string containing the current plugin path inside the install path

Returns

current bundled plugin path

Return type

str, or None on failure

connect_pycharm_debugger(port=5678)[source]

Connect to PyCharm (Professional Edition) for debugging.

Note

See https://docs.binary.ninja/dev/plugins.html#remote-debugging-with-intellij-pycharm for step-by-step instructions on how to set up Python debugging.

Parameters

port – Port number for connecting to the debugger.

connect_vscode_debugger(port=5678)[source]

Connect to Visual Studio Code for debugging. This function blocks until the debugger is connected! Not recommended for use in startup.py

Note

See https://docs.binary.ninja/dev/plugins.html#remote-debugging-with-vscode for step-by-step instructions on how to set up Python debugging.

Parameters

port – Port number for connecting to the debugger.

core_build_id() int[source]

core_build_id returns a integer containing the current build id

Returns

current build id

Return type

int

core_expires() struct_time[source]

License Expiration

Return type

struct_time

core_license_count() int[source]

License count from the license file

Return type

int

core_product() Optional[str][source]

Product string from the license file

Return type

Optional[str]

core_product_type() Optional[str][source]

Product type from the license file

Return type

Optional[str]

core_serial() Optional[str][source]

core_serial returns a string containing the current serial number

Returns

current serial

Return type

str, or None on failure

core_set_license(licenseData: str) None[source]

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.

Parameters

licenseData (str) – string containing the full contents of a license file

Returns

user plugin path

Return type

None

Example
>>> import os
>>> core_set_license(os.environ['BNLICENSE']) #Do this before creating any BinaryViews
>>> with open_view("/bin/ls") as bv:
...             print(len(list(bv.functions)))
128
core_ui_enabled() bool[source]

Indicates that a UI exists and the UI has invoked BNInitUI

Return type

bool

core_version() Optional[str][source]

core_version returns a string containing the current version

Returns

current version

Return type

str, or None on failure

core_version_info() CoreVersionInfo[source]

core_version_info returns a CoreVersionInfo containing the current version information

Returns

current version information

Return type

CoreVersionInfo

disable_default_log() None[source]

Disable default logging in headless mode for the current session. By default, logging in headless operation is controlled by the ‘python.log.minLevel’ settings.

Return type

None

get_install_directory()[source]

get_install_directory returns a string pointing to the installed binary currently running

Warning

ONLY for use within the Binary Ninja UI, behavior is undefined and unreliable if run headlessly

get_memory_usage_info() Mapping[str, int][source]
Return type

Mapping[str, int]

get_unique_identifier()[source]
load(*args, **kwargs) BinaryView[source]

load is a convenience wrapper for BinaryViewType.load that opens a BinaryView object.

Parameters
  • source (Union[str, bytes, bytearray, 'databuffer.DataBuffer', 'os.PathLike']) – a file or byte stream to load into a virtual memory space

  • update_analysis (bool) – whether or not to run update_analysis_and_wait after opening a BinaryView, defaults to True

  • progress_func (callback) – optional function to be called with the current progress and total count

  • options (dict) – a dictionary in the form {setting identifier string : object value}

Returns

returns a BinaryView object for the given filename

Return type

BinaryView

Raises

Exception – When a BinaryView could not be created

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
open_view(*args, **kwargs) BinaryView[source]

open_view is a convenience wrapper for get_view_of_file_with_options that opens a BinaryView object.

Note

If attempting to open a BNDB, the file MUST have the suffix .bndb, or else the file will not be loaded as a database.

Parameters
  • filename (Union[str, 'os.PathLike']) – path to filename or bndb to open

  • update_analysis (bool) – whether or not to run update_analysis_and_wait after opening a BinaryView, defaults to True

  • progress_func (callback) – optional function to be called with the current progress and total count

  • options (dict) – a dictionary in the form {setting identifier string : object value}

Returns

returns a BinaryView object for the given filename

Return type

BinaryView

Raises

Exception – When a BinaryView could not be created

Example
>>> from binaryninja import *
>>> with open_view("/bin/ls") as bv:
...     print(len(list(bv.functions)))
...
128
shutdown()[source]

shutdown cleanly shuts down the core, stopping all workers and closing all log files.

user_directory() Optional[str][source]

user_directory returns a string containing the path to the user directory

Returns

current user path

Return type

str, or None on failure

user_plugin_path() Optional[str][source]

user_plugin_path returns a string containing the current plugin path inside the user directory

Returns

current user plugin path

Return type

str, or None on failure