### CMake: Project Setup and Options Source: https://github.com/vector35/binaryninja-api/blob/dev/CMakeLists.txt Initializes the CMake project, sets the module path, and defines build options such as enabling examples, allowing stubs, and enabling reference counting debugging. These options control various aspects of the build process. ```cmake cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(binaryninjaapi CXX C) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") option(BN_API_BUILD_EXAMPLES "Builds example plugins" OFF) option(BN_ALLOW_STUBS "Allow generating and linking against stubs if a Binary Ninja installation was not found" OFF) option(BN_REF_COUNT_DEBUG "Add extra debugging checks for RefCountObject leaks" OFF) mark_as_advanced(BN_REF_COUNT_DEBUG) ``` -------------------------------- ### Rust Example: Load Binary and Get File Info Source: https://github.com/vector35/binaryninja-api/blob/dev/rust/README.md This example demonstrates how to initialize a headless Binary Ninja session, load an executable file, and retrieve basic information such as filename, file size, and function count. It iterates through the functions to print their names. Requires Binary Ninja with a headless license. ```rust use binaryninja::headless::Session; use binaryninja::binary_view::{BinaryViewBase, BinaryViewExt}; fn main() { let headless_session = Session::new().expect("Failed to initialize session"); let bv = headless_session .load("/bin/cat") .expect("Couldn't open `/bin/cat`"); println!("Filename: `{}`", bv.file().filename()); println!("File size: `{:#x}`", bv.len()); println!("Function count: {}", bv.functions().len()); for func in &bv.functions() { println!("{}:", func.symbol().full_name()); } } ``` -------------------------------- ### Managing Plugins with RepositoryManager API Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/guide/plugins.md Demonstrates how to use the RepositoryManager API in Python to list, install, and enable/disable plugins. It shows accessing plugin lists, checking installation status, and modifying installed and enabled states. ```python >>> mgr = RepositoryManager() >>> dir(mgr) ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'add_repository', 'check_for_updates', 'default_repository', 'handle', 'plugins', 'repositories'] >>> mgr.plugins {'community': [, , , , , , , , , , , <0x1F9F1_binjamsvc not-installed/disabled>, , , , , , , , <404d_peutils not-installed/disabled>, , , , , ], 'official': [, ]} >>> mgr.plugins['community'][0].installed False >>> mgr.plugins['community'][0].installed = True >>> mgr.plugins['community'][0].installed True >>> mgr.plugins['community'][0].enabled False >>> mgr.plugins['community'][0].enabled = True >>> mgr.plugins['community'][0].enabled True >>> mgr.plugins['community'][0].enabled True ``` -------------------------------- ### Plugin Installation Paths for Binary Ninja Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/guide/index.md Plugins can be installed manually by placing .py files or folders with __init__.py modules in platform-specific directories. Binary Ninja supports installation on macOS, Linux, and Windows with different application support paths. ```bash # macOS plugin directory ~/Library/Application\ Support/Binary\ Ninja/plugins/ # Linux plugin directory ~/.binaryninja/plugins/ # Windows plugin directory %APPDATA%\Binary Ninja\plugins ``` -------------------------------- ### Install Binary Ninja API Script Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/batch.md This command executes the `install_api.py` script provided by Binary Ninja. This script is crucial for setting up your Python environment to find and use the Binary Ninja libraries. Ensure you use the correct Python interpreter, especially if multiple versions are installed. ```shell python3 ~/binaryninja/scripts/install_api.py ``` -------------------------------- ### Plugin Installation or RPATH Configuration (CMake) Source: https://github.com/vector35/binaryninja-api/blob/dev/arch/arm64/CMakeLists.txt Manages plugin installation based on the `BN_INTERNAL_BUILD` flag. If it's an internal build, it applies `plugin_rpath` and sets output directories for the library. Otherwise, it uses `bn_install_plugin` for standard plugin installation. ```cmake if(BN_INTERNAL_BUILD) plugin_rpath(${PROJECT_NAME}) set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR} RUNTIME_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR}) else() bn_install_plugin(${PROJECT_NAME}) endif() ``` -------------------------------- ### Install GUI Dependencies for Headless Ubuntu (Bash) Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/guide/troubleshooting.md This command installs a set of essential graphical libraries on a headless Ubuntu server. These packages are required for running Binary Ninja's GUI, potentially with X-Forwarding to a remote machine. ```bash apt-get install libgl1-mesa-glx libfontconfig1 libxrender1 libegl1-mesa libxi6 libnspr4 libsm6 ``` -------------------------------- ### NixOS Derivation for Binary Ninja Demo Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/guide/troubleshooting.md A customer-provided Nix derivation file for installing the Binary Ninja demo on NixOS. This configuration utilizes `autoPatchelfHook` and `makeWrapper` to set up the Binary Ninja environment and its dependencies. ```js { stdenv, autoPatchelfHook, makeWrapper, fetchurl, unzip, libGL, glib, fontconfig, xlibs, dbus, xkeyboard_config }: stdenv.mkDerivation rec { name = "binary-ninja-demo"; buildInputs = [ autoPatchelfHook makeWrapper unzip libGL stdenv.cc.cc.lib glib fontconfig xlibs.libXi xlibs.libXrender dbus ]; src = fetchurl { url = "https://cdn.binary.ninja/installers/BinaryNinja-demo.zip"; sha256 = "1yq2kgrhrwdi7f66jm1w5sc6r49hdhqnff9b0ysr5k65w9kxhl1k"; }; buildPhase = ":"; installPhase = '' mkdir -p $out/bin mkdir -p $out/opt cp -r * $out/opt chmod +x $out/opt/binaryninja makeWrapper $out/opt/binaryninja \ $out/bin/binaryninja \ --prefix "QT_XKB_CONFIG_ROOT" ":" "${xkeyboard_config}/share/X11/xkb" ''; } ``` -------------------------------- ### Creating and Linking Binary Ninja C++ Plugin Library Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/plugins.md Defines the main shared library for your Binary Ninja plugin and links it against the Binary Ninja API. The `bn_install_plugin` function is used to ensure the plugin is correctly installed into the Binary Ninja plugins directory when using `cmake --install`. ```cmake # Use whichever sources and plugin name you want add_library(TestPlugin SHARED TestPlugin.cpp) # Link with Binary Ninja target_link_libraries(TestPlugin PUBLIC binaryninjaapi) # Tell `cmake --install` to copy your plugin to the plugins directory bn_install_plugin(TestPlugin) ``` -------------------------------- ### Start Workflow Machine CLI (Python) Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/workflows.md Initiates the command-line interface for interacting with the Binary Ninja Workflow Machine. This is primarily used for debugging and managing the workflow programmatically. ```python bv.workflow.machine.cli() ``` -------------------------------- ### Conditional Plugin Installation and Output Directory Setup Source: https://github.com/vector35/binaryninja-api/blob/dev/plugins/warp/ui/CMakeLists.txt Manages plugin installation based on build context. For internal builds, configures RPATH settings and output directories for the plugin, with Unix-specific handling for dynamic library resolution. For out-of-tree builds, uses standard plugin installation. ```cmake if (BN_INTERNAL_BUILD) ui_plugin_rpath(${PROJECT_NAME}) if (UNIX) # A hack to get the ui plugin to find the warp core plugin. set_target_properties(${PROJECT_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE INSTALL_RPATH "$ORIGIN") endif() set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR} RUNTIME_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR}) else () # TODO: There is a possibility that linux will fail to load the correct core warp. bn_install_plugin(${PROJECT_NAME}) endif () ``` -------------------------------- ### Configuring Startup Scripts in Binary Ninja Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/guide/index.md The `startup.py` file in the user's configuration directory allows users to execute custom Python code automatically when Binary Ninja starts. This is useful for setting up custom environments, loading plugins, or defining frequently used functions. ```python # Commands in this file will be run in the interactive python console on startup from binaryninja import * # Example: Define a custom function to be available on startup def my_custom_command(): print("Hello from startup.py!") # You can also import and call other modules or functions # from some_plugin import initialize_plugin # initialize_plugin() ``` -------------------------------- ### C Function to Z80 Single-Byte Addition Example Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/flags.md Example C function demonstrating single-byte addition. Compiles to Z80 ADD instruction that produces the carry flag, but Binary Ninja omits the flag-setting IL because no consumer of the carry flag is detected. ```c unsigned char add(unsigned char a, unsigned char b) { return a + b; } ``` -------------------------------- ### Initialize CMake Project and Binary Ninja API Setup Source: https://github.com/vector35/binaryninja-api/blob/dev/plugins/dwarf/dwarf_import/CMakeLists.txt Sets up the CMake project minimum version, defines the dwarf_import project, and configures the Binary Ninja API path discovery. If not building as part of the main API build, it searches for the API in predefined locations and adds it as a subdirectory. ```cmake cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(dwarf_import) if(NOT BN_API_BUILD_EXAMPLES AND NOT BN_INTERNAL_BUILD) if(NOT BN_API_PATH) find_path( BN_API_PATH NAMES binaryninjaapi.h HINTS ../../.. ../../binaryninja/api/ binaryninjaapi binaryninja-api $ENV{BN_API_PATH} REQUIRED ) endif() set(CARGO_STABLE_VERSION 1.83.0) add_subdirectory(${BN_API_PATH} binaryninjaapi) endif() ``` -------------------------------- ### C Function to Z80 Multi-Byte Addition Example Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/flags.md Example C function demonstrating multi-byte (2-byte integer) addition. Compiles to Z80 instructions using ADD followed by ADC, where the carry flag is both produced and consumed between instructions, resulting in explicit flag-setting IL. ```c unsigned int add(unsigned int a, unsigned int b) { return a + b; } ``` -------------------------------- ### Binary Ninja C++ Plugin Core ABI and Initialization Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/plugins.md Exports essential C functions required by Binary Ninja to load your C++ plugin. Includes `BN_DECLARE_CORE_ABI_VERSION` for API version compatibility and `CorePluginInit` for plugin startup logic. Optionally, `CorePluginDependencies` can specify plugin load order dependencies. ```cpp #include "binaryninjaapi.h" extern "C" { // Tells Binary Ninja which version of the API you compiled against BN_DECLARE_CORE_ABI_VERSION // Function run on plugin startup, do simple initialization here (Settings, BinaryViewTypes, etc) BINARYNINJAPLUGIN bool CorePluginInit() { return true; } // (Optional) Function to add other plugin dependencies in case your plugin requires them BINARYNINJAPLUGIN void CorePluginDependencies() { // For example, if you require the x86 to be loaded before your plugin AddRequiredPluginDependency("arch_x86"); } } ``` -------------------------------- ### Build EFI Resolver Plugin Source: https://github.com/vector35/binaryninja-api/blob/dev/plugins/efi_resolver/README.md Instructions for cloning the repository, setting the Binary Ninja API path, and building the EFI Resolver plugin using CMake and Ninja. ```bash git clone https://github.com/Vector35/binaryninja-api.git && cd binaryninja-api/plugins/efi_resolver export BN_API_PATH=../binaryninja-api # Or specifying the path to api repo cmake -S . -B build -GNinja cmake --build build -t install ``` -------------------------------- ### Example of Carry Flag Role in Binary Ninja LLIL Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/flags.md This snippet demonstrates how Binary Ninja automatically generates LLIL for a carry flag during an addition operation when the 'c' flag is declared with CarryFlagRole. This saves architecture authors from manually implementing this common behavior. ```assembly 5 @ 0000021b temp0.b = A 6 @ 0000021b temp1.b = [HL {arg3}].b 7 @ 0000021b A = A + [HL {arg3}].b 8 @ 0000021b flag:c = temp0.b + temp1.b u< temp0.b <-- HERE ``` -------------------------------- ### CMake Project Setup and Linking Source: https://github.com/vector35/binaryninja-api/blob/dev/examples/llil_parser/CMakeLists.txt Configures the CMake project, adds the main source file, finds the Binary Ninja API path, and links the necessary libraries for the LLIL parser executable. It handles Windows and non-Windows specific linking. ```cmake cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(llil_parser CXX C) add_executable(${PROJECT_NAME} src/llil_parser.cpp) if(NOT BN_API_BUILD_EXAMPLES AND NOT BN_INTERNAL_BUILD) # Out-of-tree build find_path( BN_API_PATH NAMES binaryninjaapi.h HINTS ../.. binaryninjaapi $ENV{BN_API_PATH} REQUIRED ) add_subdirectory(${BN_API_PATH} api) endif() target_link_libraries(${PROJECT_NAME} binaryninjaapi) if (NOT WIN32) target_link_libraries(${PROJECT_NAME} dl) endif() set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20 CXX_VISIBILITY_PRESET hidden CXX_STANDARD_REQUIRED ON VISIBILITY_INLINES_HIDDEN ON POSITION_INDEPENDENT_CODE ON RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/bin) ``` -------------------------------- ### Handling Unimplemented Flag Operations in Binary Ninja LLIL Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/flags.md This example shows the Low-Level Intermediate Language (LLIL) generated when a flag is marked for an operation that Binary Ninja does not have a built-in implementation for. Flags like 'pv' mapped to OverflowFlagRole result in `LLIL_UNIMPLEMENTED` if no default or custom handler exists. ```assembly 12 @ 0000029e A = sbb.b(temp1.b, D, flag:c) 13 @ 0000029e flag:s = sbb.b(temp1.b, D, flag:c) s< 0 14 @ 0000029e flag:pv = unimplemented ``` -------------------------------- ### CMake Conditional Output Directory Setup for Internal and External Builds Source: https://github.com/vector35/binaryninja-api/blob/dev/view/sharedcache/api/python/CMakeLists.txt Configures the Python output directory path based on build context, using internal resource directories for BN_INTERNAL_BUILD or external plugin directories otherwise. Provides different installation paths for distributed vs. internal builds. ```cmake if(BN_INTERNAL_BUILD) set(PYTHON_OUTPUT_DIRECTORY ${BN_RESOURCE_DIR}/python/binaryninja/sharedcache/) else() set(PYTHON_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/plugins/sharedcache/) endif() ``` -------------------------------- ### C++ Binary Analysis with Core API Source: https://context7.com/vector35/binaryninja-api/llms.txt Demonstrates headless binary analysis using the C++ Binary Ninja Core API. It initializes the core, loads a binary file, displays basic information like type, start address, entry point, and platform, and iterates through entry functions and strings. ```cpp #include "binaryninjacore.h" #include "binaryninjaapi.h" #include using namespace BinaryNinja; int main(int argc, char* argv[]) { // Initialize Binary Ninja core SetBundledPluginDirectory(GetBundledPluginDirectory()); InitPlugins(); // Load binary file Ref bv = BinaryNinja::Load(argv[1]); if (!bv || bv->GetTypeName() == "Raw") { fprintf(stderr, "Failed to load executable\n"); return -1; } // Display binary information std::cout << "TYPE: " << bv->GetTypeName() << std::endl; std::cout << "START: 0x" << std::hex << bv->GetStart() << std::endl; std::cout << "ENTRY: 0x" << bv->GetEntryPoint() << std::endl; std::cout << "PLATFORM: " << bv->GetDefaultPlatform()->GetName() << std::endl; // Iterate through entry functions for (auto func : bv->GetAllEntryFunctions()) { std::cout << "Entry: 0x" << std::hex << func->GetStart() << " " << func->GetSymbol()->GetFullName() << std::endl; } // Iterate through strings for (auto str_ref : bv->GetStrings()) { char* str = (char*)malloc(str_ref.length + 1); bv->Read(str, str_ref.start, str_ref.length); str[str_ref.length] = 0; std::cout << "String at 0x" << std::hex << str_ref.start << ": " << str << std::endl; free(str); } // Clean shutdown bv->GetFile()->Close(); BNShutdown(); return 0; } ``` -------------------------------- ### CMake Project Setup and Dependency Handling Source: https://github.com/vector35/binaryninja-api/blob/dev/view/sharedcache/CMakeLists.txt Initializes the CMake project, sets the minimum version, and finds necessary paths for the Binary Ninja API. It conditionally adds subdirectories for core, API, and workflow components based on build configurations. ```cmake cmake_minimum_required(VERSION 3.13 FATAL_ERROR) project(sharedcache) if(NOT BN_INTERNAL_BUILD) find_path( BN_API_PATH NAMES binaryninjaapi.h HINTS ../.. binaryninjaapi $ENV{BN_API_PATH} REQUIRED ) add_subdirectory(${BN_API_PATH} binaryninjaapi) endif() if (NOT BN_INTERNAL_BUILD) if(WIN32) set(MSVC_VERSION msvc2022_64 CACHE STRING "Version of MSVC Qt is built with" ) endif() set(QT_VERSION 6.8.2 CACHE STRING "Version of Qt to use") if(NOT CMAKE_PREFIX_PATH) if(APPLE) set(CMAKE_PREFIX_PATH $ENV{HOME}/Qt/${QT_VERSION}/clang_64/lib/cmake) elseif(WIN32) set(CMAKE_PREFIX_PATH $ENV{HOMEDRIVE}$ENV{HOMEPATH}/Qt/${QT_VERSION}/${MSVC_VERSION}/lib/cmake) else() set(CMAKE_PREFIX_PATH $ENV{HOME}/Qt/${QT_VERSION}/gcc_64/lib/cmake) endif() endif() message("CMAKE_PREFIX_PATH is: ${CMAKE_PREFIX_PATH}") endif() add_subdirectory(core) add_subdirectory(api) add_subdirectory(workflow) ``` -------------------------------- ### VSCode tasks.json for Binary Ninja Plugin Installation (JSON) Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/plugins.md This task configuration for VSCode's tasks.json file sets up a CMake install task to build and install your Binary Ninja plugin. It allows specifying environment variables like BN_INSTALL_DIR and PATH for custom Binary Ninja installations or UI plugin development. ```json { "version": "2.0.0", "tasks": [ { "type": "cmake", "label": "CMake: install", "command": "install", "problemMatcher": [], "detail": "CMake template install task", "options": { "environment": { "BN_INSTALL_DIR": "C:\\Users\\User\\AppData\\Local\\Vector35\\BinaryNinja", "PATH": "C:\\Users\\User\\Qt\\6.8.2\\msvc2019_64\\bin" } } } ] } ``` -------------------------------- ### Project Setup and Dependency Finding (CMake) Source: https://github.com/vector35/binaryninja-api/blob/dev/view/kernelcache/CMakeLists.txt Initializes the CMake project and searches for the Binary Ninja API and Qt. It sets up paths for these dependencies, essential for building the kernelcache library. This includes platform-specific path configurations for Qt. ```cmake cmake_minimum_required(VERSION 3.13 FATAL_ERROR) project(kernelcache) if(NOT BN_INTERNAL_BUILD) find_path( BN_API_PATH NAMES binaryninjaapi.h HINTS ../.. binaryninjaapi $ENV{BN_API_PATH} REQUIRED ) add_subdirectory(${BN_API_PATH} binaryninjaapi) endif() if (NOT BN_INTERNAL_BUILD) if(WIN32) set(MSVC_VERSION msvc2022_64 CACHE STRING "Version of MSVC Qt is built with" ) endif() set(QT_VERSION 6.7.2 CACHE STRING "Version of Qt to use") if(NOT CMAKE_PREFIX_PATH) if(APPLE) set(CMAKE_PREFIX_PATH $ENV{HOME}/Qt/${QT_VERSION}/clang_64/lib/cmake) elseif(WIN32) set(CMAKE_PREFIX_PATH $ENV{HOMEDRIVE}$ENV{HOMEPATH}/Qt/${QT_VERSION}/${MSVC_VERSION}/lib/cmake) else() set(CMAKE_PREFIX_PATH $ENV{HOME}/Qt/${QT_VERSION}/gcc_64/lib/cmake) endif() endif() message("CMAKE_PREFIX_PATH is: ${CMAKE_PREFIX_PATH}") endif() ``` -------------------------------- ### Configure Plugin Installation Source: https://github.com/vector35/binaryninja-api/blob/dev/demangler/gnu3/CMakeLists.txt Manages the installation of the plugin based on whether it's an internal build. For internal builds, it sets output directories. For external builds, it uses a custom command to install the plugin correctly. ```cmake if(BN_INTERNAL_BUILD) plugin_rpath(${PROJECT_NAME}) set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR} RUNTIME_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR}) else() bn_install_plugin(${PROJECT_NAME}) endif() ``` -------------------------------- ### Define Custom EFI GUID (JSON) Source: https://github.com/vector35/binaryninja-api/blob/dev/plugins/efi_resolver/README.md Associates a GUID with a custom EFI protocol name. This JSON configuration maps the GUID to the custom protocol, enabling Binary Ninja's EFI Resolver to recognize it. ```json { "EFI_EXAMPLE_CUSTOM_PROTOCOL_GUID": [ 19088743, 35243, 52719, 1, 35, 69, 103, 137, 171, 205, 239 ] } ``` -------------------------------- ### User-supplied EFI GUIDs JSON Format Source: https://github.com/vector35/binaryninja-api/blob/dev/plugins/efi_resolver/README.md Defines the JSON structure for associating custom EFI GUIDs with type names for the EFI Resolver plugin. This allows the plugin to recognize and correctly type proprietary protocol GUIDs. ```json { "EFI_EXAMPLE_CUSTOM_PROTOCOL_GUID": [ 19088743, 35243, 52719, 1, 35, 69, 103, 137, 171, 205, 239 ] } ``` -------------------------------- ### Open new tab with BinaryView from scratch Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/cookbook.md Creates a new binary view from raw bytes and opens it in a new UI tab using FileContext. Demonstrates creating in-memory binary representations and integrating them with the Binary Ninja UI. ```python from binaryninja.binaryview import BinaryView from binaryninjaui import FileContext, UIContext data = BinaryView.new(b'\x00\x00\x01') context = FileContext(data.file, data, '') execute_on_main_thread(lambda: UIContext.activeContext().openFileContext(context)) ``` -------------------------------- ### Build Windows Binary Source: https://github.com/vector35/binaryninja-api/blob/dev/arch/msp430/CMakeLists.txt Custom CMake command to build the Binary Ninja API for Windows. This includes cleaning previous builds, compiling the Rust code, and copying the resulting executable and PDB file. ```cmake add_custom_command( OUTPUT ${OUTPUT_FILE_PATH} COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BINJA_LIB_DIR} ${RUSTUP_COMMAND} clean ${CARGO_OPTS} COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BINJA_LIB_DIR} ${RUSTUP_COMMAND} build ${CARGO_OPTS} ${CARGO_FEATURES} COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_FILE_NAME} ${OUTPUT_FILE_PATH} COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_PDB_NAME} ${OUTPUT_PDB_PATH} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES} ) ``` -------------------------------- ### CMake Plugin Output and Installation Configuration Source: https://github.com/vector35/binaryninja-api/blob/dev/plugins/efi_resolver/CMakeLists.txt Conditionally configures the plugin output directory and installation based on the build type. For internal builds, sets the library and runtime output directories to the Binary Ninja core plugin directory. For public builds, uses the bn_install_plugin helper function to properly install the plugin with appropriate destination and metadata. ```CMake if(BN_INTERNAL_BUILD) set_target_properties(efi_resolver PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR} RUNTIME_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR}) else() bn_install_plugin(${PROJECT_NAME}) endif() ``` -------------------------------- ### Install Noto Color Emoji Font on Debian (Bash) Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/guide/troubleshooting.md This command installs the 'fonts-noto-color-emoji' package on Debian-based Linux distributions. This is required for Binary Ninja to correctly display emoji icons used in its tagging system. ```bash apt install fonts-noto-color-emoji ``` -------------------------------- ### Troubleshooting: Launching Binary Ninja with Debug Logging Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/guide/plugins.md Provides a command-line instruction for launching Binary Ninja with debug logging enabled and directing the output to a specified file. This is useful for diagnosing issues. ```text /Applications/Binary\ Ninja.app/Contents/macOS/binaryninja -d -l /tmp/bnlog.txt ``` -------------------------------- ### Opening Signature Explorer GUI with Sigkit Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/annotation.md Shows how to launch the Signature Explorer graphical interface programmatically using the sigkit API. This tool aids in debugging and optimizing signature libraries. ```python sigkit.signature_explorer() ``` -------------------------------- ### Define Custom EFI Protocol GUID Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/guide/efiresolver.md Specifies how to define a custom EFI GUID and associate it with a protocol name for use in EFI Resolver. This allows for extending analysis to proprietary EFI interfaces. ```json { "EFI_EXAMPLE_CUSTOM_PROTOCOL_GUID": [ 19088743, 35243, 52719, 1, 35, 69, 103, 137, 171, 205, 239 ] } ``` -------------------------------- ### Install Plugin Function (CMake) Source: https://github.com/vector35/binaryninja-api/blob/dev/CMakeLists.txt A CMake function `bn_install_plugin` that installs a target executable or library to the user's plugin directory. It determines the correct directory based on the OS and handles PDB files on Windows. ```cmake function(bn_install_plugin target) if(WIN32) set(BN_USER_PLUGINS_DIR "$ENV{APPDATA}\Binary Ninja\plugins") elseif(APPLE) set(BN_USER_PLUGINS_DIR "$ENV{HOME}/Library/Application Support/Binary Ninja/plugins") else() set(BN_USER_PLUGINS_DIR "$ENV{HOME}/.binaryninja/plugins") endif() if(NOT BN_INTERNAL_BUILD) if(WIN32) install(TARGETS ${target} RUNTIME DESTINATION ${BN_USER_PLUGINS_DIR}) install(FILES $ DESTINATION ${BN_USER_PLUGINS_DIR} OPTIONAL) else() install(TARGETS ${target} LIBRARY DESTINATION ${BN_USER_PLUGINS_DIR}) endif() endif() endfunction() ``` -------------------------------- ### CMake Project Setup and Source Collection Source: https://github.com/vector35/binaryninja-api/blob/dev/platform/windows-kernel/CMakeLists.txt Initializes the CMake project with minimum version 3.15 and optionally includes the Binary Ninja API subdirectory. Collects all C++ and header source files from the current directory using glob pattern matching with configure dependency tracking. ```cmake cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(platform_windows_kernel) if(NOT BN_INTERNAL_BUILD) add_subdirectory(${PROJECT_SOURCE_DIR}/../.. ${PROJECT_BINARY_DIR}/api) endif() file(GLOB SOURCES CONFIGURE_DEPENDS *.cpp *.h) ``` -------------------------------- ### CMake Project Initialization and Plugin Sources Source: https://github.com/vector35/binaryninja-api/blob/dev/arch/msp430/CMakeLists.txt Initializes the CMake project for the MSP430 architecture plugin and defines the glob pattern for source files including Rust files and core headers. This establishes the minimum CMake version requirement and collects all relevant project sources that need to be tracked for dependency purposes. ```cmake cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(arch_msp430) file(GLOB PLUGIN_SOURCES CONFIGURE_DEPENDS ../../binaryninjacore.h ${PROJECT_SOURCE_DIR}/Cargo.toml ${PROJECT_SOURCE_DIR}/src/*.rs ${PROJECT_SOURCE_DIR}/disasm/src/*.rs) ``` -------------------------------- ### Set Variable Types to Guide Outlining in Python API Source: https://github.com/vector35/binaryninja-api/blob/dev/docs/dev/outlining.md Python code demonstrating how to set variable types in Binary Ninja to guide the outlining process. Proper type annotations (arrays, character types, structures) help the outliner make better decisions about which semantic builtins to use. ```python # Set variable types to guide outlining decisions var.type = types.Type.array(types.Type.char(), 16) # Define structures for better field initialization recognition struct_type = types.Type.structure([ types.StructureMember(types.Type.char(), "name", 0), types.StructureMember(types.Type.int(4), "value", 16) ]) ```