### Get Installation Directory Source: https://api.binary.ninja/index Returns a string that points to the installed Binary Ninja executable currently running. This is useful for locating program files. ```python get_install_directory() ``` -------------------------------- ### Initialize Binary Ninja with License Data Source: https://api.binary.ninja/index This example shows how to initialize the Binary Ninja core with license data provided as a string, rather than loading from a file. This is particularly useful in headless environments for enhanced security. ```python import os from binaryninja import core_set_license, load core_set_license(os.environ['BNLICENSE']) #Do this before creating any BinaryViews with load("/bin/ls") as bv: print(len(list(bv.functions))) ``` -------------------------------- ### Get User Directory Source: https://api.binary.ninja/index Returns a string containing the path to the user directory for Binary Ninja. Returns None if the directory cannot be determined. ```python user_directory() ``` -------------------------------- ### Get User Plugin Path Source: https://api.binary.ninja/index Returns a string containing the path to the current plugins within the user directory. Returns None if the path cannot be determined. ```python user_plugin_path() ``` -------------------------------- ### Get Core Version Information Source: https://api.binary.ninja/index Retrieves the current version information of the Binary Ninja core. This function returns an object containing details about the running version. ```python core_version_info() ``` -------------------------------- ### Generate Unique Identifier Source: https://api.binary.ninja/index Generates a globally unique identifier (GUID). This function returns a string representation of the generated GUID. ```python get_unique_identifier() ``` -------------------------------- ### Get System Cache Directory Source: https://api.binary.ninja/index Returns the path to Binary Ninja’s system cache directory. The location varies by operating system (macOS, Linux, Windows). Returns None if the directory cannot be determined. ```python get_system_cache_directory() ``` -------------------------------- ### Get Memory Usage Information Source: https://api.binary.ninja/index Retrieves counts of various Binary Ninja objects currently held in memory. The function returns a dictionary where keys are class names and values are their respective counts. ```python get_memory_usage_info() ``` -------------------------------- ### Load Binary View Source: https://api.binary.ninja/index Opens and loads a BinaryView object from a given source, such as a file path or a byte stream. It can optionally run analysis after loading and accepts configuration options. Raises an exception if a BinaryView cannot be created. ```python with load("/bin/ls") as bv: print(len(list(bv.functions))) ``` ```python with load(bytes.fromhex('5054ebfe'), options={'loader.platform' : 'x86'}) as bv: print(len(list(bv.functions))) ``` -------------------------------- ### Connect to VS Code Debugger Source: https://api.binary.ninja/index Initiates a connection to a Visual Studio Code debugger. This function will block execution until the debugger is connected, so it's not recommended for use in startup scripts. Ensure VS Code is set up for Python debugging. ```python from binaryninja import connect_vscode_debugger # Connect to VS Code debugger on the default port 5678 # This call will block until the debugger is connected. # connect_vscode_debugger() # Connect to VS Code debugger on a custom port # connect_vscode_debugger(port=12345) ``` -------------------------------- ### Compare Binary Ninja Versions Source: https://api.binary.ninja/index This snippet demonstrates how to compare the current Binary Ninja version against a specified version. It uses the CoreVersionInfo class to parse and compare version strings or components, useful for ensuring compatibility with specific features. ```python from binaryninja import core_version_info, CoreVersionInfo # Check if the current version meets minimum requirements for a plugin if core_version_info() >= CoreVersionInfo(5, 1, 8104): print("Using new API available in 5.1.8104 and later") # Parse and compare against a version string if core_version_info() >= CoreVersionInfo("4.2.0"): print("Version 4.2.0 or later detected") # Get individual version components version = core_version_info() print(f"Running Binary Ninja {version.major}.{version.minor}.{version.build}") ``` -------------------------------- ### Connect to PyCharm Debugger Source: https://api.binary.ninja/index Establishes a connection to a PyCharm debugger instance. This function allows for remote debugging of Binary Ninja Python scripts. Ensure PyCharm is configured for Python debugging and the specified port matches. ```python from binaryninja import connect_pycharm_debugger # Connect to PyCharm debugger on the default port 5678 connect_pycharm_debugger() # Connect to PyCharm debugger on a custom port # connect_pycharm_debugger(port=12345) ``` -------------------------------- ### Fuzzy String Matching Source: https://api.binary.ninja/index Performs a fuzzy match between a query string and a target string. It returns an integer score representing the confidence of the match, with higher scores indicating a more confident match. Returns None if the query does not match the target string. ```python fuzzy_match_single(_target_, _query_) ``` -------------------------------- ### Disable Default Logging Source: https://api.binary.ninja/index Disables default logging behavior in headless mode for the current session. By default, logging in headless operation is controlled by the ‘python.log.minLevel’ settings. This function returns None. ```python disable_default_log() ``` -------------------------------- ### Shutdown Binary Ninja Core Source: https://api.binary.ninja/index Cleanly shuts down the Binary Ninja core, stopping all worker threads and closing log files. This function is typically called automatically upon script exit when the binaryninja module is imported. ```python shutdown() ```