### IDAX Wrapper Usage Examples Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Demonstrates realistic usage patterns for the IDAX wrapper. These examples serve as practical guides for integrating and utilizing the IDAX library in various scenarios. ```comment # Example sources demonstrate realistic idax wrapper usage patterns, ``` -------------------------------- ### Build Addon Binaries: CMake configuration for IDAX examples Source: https://github.com/19h/idax/blob/master/examples/README.md This bash script demonstrates the CMake commands required to build addon binaries for IDAX examples. It enables building all examples and addons, or specific tool ports and plugins like idapcode. ```bash # Build all addon binaries cake -S . -B build -DIDAX_BUILD_EXAMPLES=ON -DIDAX_BUILD_EXAMPLE_ADDONS=ON cake --build build # Build specific tool ports cake -S . -B build -DIDAX_BUILD_EXAMPLES=ON -DIDAX_BUILD_EXAMPLE_TOOLS=ON cake --build build --target idax_idalib_dump_port idax_idalib_lumina_port idax_ida2py_port # Build idapcode port addon cake -S . -B build \ -DIDAX_BUILD_EXAMPLES=ON \ -DIDAX_BUILD_EXAMPLE_ADDONS=ON \ -DIDAX_BUILD_EXAMPLE_IDAPCODE_PORT=ON \ -DIDAX_IDAPCODE_BUILD_SPECS=ON cake --build build --target idax_idapcode_port_plugin ``` -------------------------------- ### Optional Build Examples Source: https://github.com/19h/idax/blob/master/CMakeLists.txt This enables an option to build the example addons for idax. If the IDAX_BUILD_EXAMPLES option is set to ON, it includes the 'examples' subdirectory, which presumably contains build configurations for the examples. ```cmake # ── Examples (optional) ────────────────────────────────────────────────── option(IDAX_BUILD_EXAMPLES "Build idax example addons" OFF) if(IDAX_BUILD_EXAMPLES) add_subdirectory(examples) endif() ``` -------------------------------- ### Install idax Project Source: https://github.com/19h/idax/blob/master/README.md This command installs the idax project to a specified prefix using CMake. Ensure you replace '/path/to/install' with your desired installation directory. ```bash cmake --install build --prefix /path/to/install ``` -------------------------------- ### Handle Load Request Flags (C++) Source: https://github.com/19h/idax/blob/master/docs/quickstart/loader.md Demonstrates how to use typed request models for advanced load, reload, or archive semantics in IDAX. It shows setting up a `LoadRequest` and decoding/encoding load flags. ```cpp ida::loader::LoadRequest request; request.format_name = "My Format"; request.flags.reload = true; request.archive_name = "libfoo.a"; request.archive_member_name = "foo.o"; ida::loader::LoadFlags flags = ida::loader::decode_load_flags(0x0200); // NEF_RELOAD auto raw = ida::loader::encode_load_flags(flags); ``` -------------------------------- ### Output Instruction and Operand with Context (C++) Source: https://github.com/19h/idax/blob/master/docs/quickstart/processor.md Demonstrates how to use `ida::processor::OutputContext` to render instructions and operands in an SDK-opaque manner. This allows for richer formatting while maintaining compatibility across different SDK versions. ```cpp ida::processor::OutputInstructionResult output_instruction_with_context(ida::Address address, ida::processor::OutputContext& out) override { out.mnemonic("mov").space().register_name("r0").comma().space().immediate(1); return ida::processor::OutputInstructionResult::Success; } ida::processor::OutputInstructionResult output_mnemonic_with_context(ida::Address address, ida::processor::OutputContext& out) override { out.mnemonic("mov"); return ida::processor::OutputInstructionResult::Success; } ida::processor::OutputOperandResult output_operand_with_context(ida::Address address, int operand_index, ida::processor::OutputContext& out) override { if (operand_index == 0) { out.register_name("r0"); return ida::processor::OutputOperandResult::Success; } return ida::processor::OutputOperandResult::Hidden; } ``` -------------------------------- ### Implement Custom Loader Skeleton (C++) Source: https://github.com/19h/idax/blob/master/docs/quickstart/loader.md Defines the basic structure for a custom IDAX loader by subclassing `ida::loader::Loader`. It includes the necessary `accept` and `load` methods, along with the `IDAX_LOADER` macro. ```cpp class MyLoader : public ida::loader::Loader { public: ida::Result> accept(ida::loader::InputFile &file) override; ida::Status load(ida::loader::InputFile &file, std::string_view format_name) override; }; IDAX_LOADER(MyLoader) ``` -------------------------------- ### Build IDAX Example Tools Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Builds example tools for IDAX that utilize IDA Pro libraries. It checks for the presence of IDA Pro runtime or the `ida_add_idalib` command before proceeding. If IDA Pro is found, it prints the runtime directory. Otherwise, it informs about using SDK stubs or warns if `ida_add_idalib` is unavailable. ```cmake if(IDAX_BUILD_EXAMPLE_TOOLS) if(IDAX_EXAMPLE_IDA_RUNTIME_DIR) message(STATUS "idax tool examples use IDA runtime: ${IDAX_EXAMPLE_IDA_RUNTIME_DIR}") elseif(COMMAND ida_add_idalib) message(STATUS "idax tool examples use SDK idalib stubs (set IDADIR for runtime-linked binaries)") else() message(WARNING "ida_add_idalib() is unavailable; skipping idalib tool examples") endif() if(COMMAND ida_add_idalib OR IDAX_EXAMPLE_IDA_RUNTIME_DIR) idax_add_idalib_tool(idax_idalib_dump_port tools/idalib_dump_port.cpp) idax_add_idalib_tool(idax_idalib_lumina_port tools/idalib_lumina_port.cpp) idax_add_idalib_tool(idax_ida2py_port tools/ida2py_port.cpp) endif() endif() ``` -------------------------------- ### Add Minimal IDA Plugin Example Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Uses the `ida_add_plugin` CMake function to create a basic IDA Pro plugin example named `idax_example_plugin`. It compiles `plugin/action_plugin.cpp` and links against the `idax::idax` library. ```cmake ida_add_plugin(idax_example_plugin SOURCES plugin/action_plugin.cpp LIBRARIES idax::idax ) ``` -------------------------------- ### Register and Attach IDA Action Source: https://github.com/19h/idax/blob/master/docs/quickstart/plugin.md Registers a defined IDA action and attaches it to a menu item. This makes the action available to the user within the IDA interface. It uses functions from the 'ida::plugin' namespace. ```cpp auto r1 = ida::plugin::register_action(action); auto r2 = ida::plugin::attach_to_menu("Edit/Plugins/", action.id); ``` -------------------------------- ### Define IDAX Example Source Files Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Lists the source files for various IDAX examples, categorized into minimal quick-start skeletons, advanced analysis tools, full parity examples, and idalib tool ports. This variable is used to build the `idax_examples` custom target. ```cmake set(IDAX_EXAMPLE_SOURCES # Minimal examples (quick-start reference). plugin/action_plugin.cpp loader/minimal_loader.cpp procmod/minimal_procmod.cpp # Advanced examples (realistic analysis tools). plugin/deep_analysis_plugin.cpp plugin/decompiler_plugin.cpp plugin/event_monitor_plugin.cpp plugin/storage_metadata_plugin.cpp plugin/lifter_port_plugin.cpp plugin/qtform_renderer_plugin.cpp plugin/qtform_renderer_widget.hpp plugin/qtform_renderer_widget.cpp plugin/drawida_port_plugin.cpp plugin/drawida_port_widget.hpp plugin/drawida_port_widget.cpp plugin/abyss_port_plugin.cpp plugin/driverbuddy_port_plugin.cpp plugin/idapcode_port_plugin.cpp plugin/driverbuddy_wdf_slots.inc loader/advanced_loader.cpp procmod/advanced_procmod.cpp # Full parity example (real-world port pattern). full/jbc_common.hpp loader/jbc_full_loader.cpp procmod/jbc_full_procmod.cpp # idalib tool port examples. tools/idalib_dump_port.cpp tools/idalib_lumina_port.cpp tools/ida2py_port.cpp ) ``` -------------------------------- ### Add IDA Pro Example Tool Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Defines a function to add an example tool that links against IDA Pro libraries. It handles linking the necessary IDA libraries and setting runtime paths for macOS. If IDA Pro runtime is not found, it falls back to using SDK stubs if available. ```cmake function(idax_add_idalib_tool TARGET_NAME SOURCE_FILE) if(IDAX_EXAMPLE_IDA_RUNTIME_DIR) add_executable(${TARGET_NAME} ${SOURCE_FILE}) target_link_libraries(${TARGET_NAME} PRIVATE idax "${IDAX_EXAMPLE_IDA_RUNTIME_DIR}/${IDAX_IDALIB_LIB_NAME}" "${IDAX_EXAMPLE_IDA_RUNTIME_DIR}/${IDAX_IDA_LIB_NAME}" ) if(APPLE) set_target_properties(${TARGET_NAME} PROPERTIES BUILD_RPATH "${IDAX_EXAMPLE_IDA_RUNTIME_DIR}" INSTALL_RPATH "${IDAX_EXAMPLE_IDA_RUNTIME_DIR}" ) endif() elseif(COMMAND ida_add_idalib) ida_add_idalib(${TARGET_NAME} TYPE EXECUTABLE SOURCES ${SOURCE_FILE} LIBRARIES idax::idax ) endif() endfunction() ``` -------------------------------- ### Define IDA Action with Callbacks Source: https://github.com/19h/idax/blob/master/docs/quickstart/plugin.md Defines an IDA action, including its ID, label, hotkey, tooltip, and handler functions. It demonstrates both basic and context-aware handlers, as well as advanced host access for decompiler integration. Dependencies include the 'ida::plugin' and 'ida::ui' namespaces. ```cpp ida::plugin::Action action; action.id = "idax:quickstart:hello"; action.label = "Hello from idax"; action.hotkey = "Ctrl-Alt-H"; action.tooltip = "Quickstart action"; action.handler = []() -> ida::Status { ida::ui::message("hello from idax plugin action\n"); return ida::ok(); }; action.enabled = []() { return true; }; // Optional context-aware callbacks. action.handler_with_context = [](const ida::plugin::ActionContext& ctx) -> ida::Status { if (ctx.current_address != ida::BadAddress) { ida::ui::message("action invoked with a valid cursor address\n"); } return ida::ok(); }; action.enabled_with_context = [](const ida::plugin::ActionContext& ctx) { return ctx.current_address != ida::BadAddress; }; // Optional advanced host access for plugin interop paths. action.handler_with_context = [](const ida::plugin::ActionContext& ctx) -> ida::Status { auto host_status = ida::plugin::with_decompiler_view_host( ctx, [](void* view_host) -> ida::Status { // view_host is an opaque handle (vdui_t* cast to void*) when available. // Keep usage scoped inside this callback. (void)view_host; return ida::ok(); }); if (!host_status && host_status.error().category != ida::ErrorCategory::NotFound) { return std::unexpected(host_status.error()); } return ida::ok(); }; ``` -------------------------------- ### Create Processor Module Skeleton (C++) Source: https://github.com/19h/idax/blob/master/docs/quickstart/processor.md Defines the basic structure of a processor module by subclassing `ida::processor::Processor` and overriding essential methods. It also includes the `IDAX_PROCESSOR` macro to register the custom processor. ```cpp class MyProcessor : public ida::processor::Processor { public: ida::processor::ProcessorInfo info() const override; ida::Result analyze(ida::Address address) override; ida::processor::EmulateResult emulate(ida::Address address) override; void output_instruction(ida::Address address) override; ida::processor::OutputOperandResult output_operand(ida::Address address, int operand) override; }; IDAX_PROCESSOR(MyProcessor) ``` -------------------------------- ### Create IDAX Examples Custom Target Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Defines a custom CMake target named `idax_examples` that compiles all the source files listed in the `IDAX_EXAMPLE_SOURCES` variable. This target allows for building all example components of the IDAX project. ```cmake add_custom_target(idax_examples SOURCES ${IDAX_EXAMPLE_SOURCES}) ``` -------------------------------- ### Install idax Targets and Headers (CMake) Source: https://github.com/19h/idax/blob/master/CMakeLists.txt Installs the idax library targets, headers, and optional documentation files to their designated locations. It also sets up export files for CMake to find the installed targets. ```cmake include(GNUInstallDirs) install(TARGETS idax EXPORT idaxTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) install(FILES docs/api_reference.md docs/tutorial/first_contact.md DESTINATION ${CMAKE_INSTALL_DATADIR}/idax/docs OPTIONAL ) install(EXPORT idaxTargets FILE idaxTargets.cmake NAMESPACE idax:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/idax ) ``` -------------------------------- ### Rust Quick Start: Initialize, Open, Analyze, and Close IDA Database Source: https://github.com/19h/idax/blob/master/bindings/rust/idax/README.md This snippet demonstrates the basic workflow of the idax crate: initializing the IDA library, opening a binary for analysis, querying metadata like file path and MD5 hash, iterating through functions and segments, and finally closing the database. It showcases essential functions from the database, function, and segment modules. ```rust use idax::{database, function, segment}; fn main() -> idax::Result<()> { // Initialize the IDA library database::init()?; // Open a binary for analysis database::open("/path/to/binary", true)?; // Query metadata let path = database::input_file_path()?; let md5 = database::input_md5()?; println!("Analyzing: {path} (MD5: {md5})"); // Iterate functions let count = function::count()?; for i in 0..count { let func = function::by_index(i)?; println!(" {:#x}: {}", func.start, func.name); } // Iterate segments let seg_count = segment::count()?; for i in 0..seg_count { let seg = segment::by_index(i)?; println!(" {}: {:#x}..{:#x}", seg.name, seg.start, seg.end); } database::close(false)?; Ok(()) } ``` -------------------------------- ### Set Segment-Register Defaults (C++) Source: https://github.com/19h/idax/blob/master/docs/quickstart/processor.md Shows how to set default values for segment registers across all segments using `ida::segment::set_default_segment_register_for_all`. This is useful for processors that require per-segment default register configurations. ```cpp ida::segment::set_default_segment_register_for_all(kRegisterCs, 0); ida::segment::set_default_segment_register_for_all(kRegisterDs, 0); ``` -------------------------------- ### Add Minimal IDA Processor Module Example Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Uses the `ida_add_procmod` CMake function to create an IDA Pro processor module example named `idax_example_procmod`. It compiles `procmod/minimal_procmod.cpp` and links against the `idax::idax` library. ```cmake ida_add_procmod(idax_example_procmod SOURCES procmod/minimal_procmod.cpp LIBRARIES idax::idax ) ``` -------------------------------- ### Build idax Project with CMake Source: https://github.com/19h/idax/blob/master/README.md This snippet shows how to set up the IDA SDK environment variable and then use CMake to configure and build the idax project. It includes options to enable tests and examples. ```bash export IDASDK=/path/to/ida-sdk cmake -B build -DIDAX_BUILD_TESTS=ON -DIDAX_BUILD_EXAMPLES=ON cmake --build build ``` -------------------------------- ### Add Minimal IDA Loader Example Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Uses the `ida_add_loader` CMake function to create an IDA Pro loader plugin named `idax_example_loader`. It compiles `loader/minimal_loader.cpp` and links against the `idax::idax` library. ```cmake ida_add_loader(idax_example_loader SOURCES loader/minimal_loader.cpp LIBRARIES idax::idax ) ``` -------------------------------- ### Configure IDAX Build Options Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Sets CMake options to control the building of example addons, tools, and specific IDA Pro plugin ports within the IDAX project. These options allow users to selectively compile different example components. ```cmake option(IDAX_BUILD_EXAMPLE_ADDONS "Build sample IDA addon modules" OFF) option(IDAX_BUILD_EXAMPLE_TOOLS "Build sample idalib-based tools" OFF) option(IDAX_BUILD_EXAMPLE_IDAPCODE_PORT "Build idapcode-to-idax Sleigh port plugin example" OFF) option(IDAX_IDAPCODE_BUILD_SPECS "Build Sleigh spec files for idapcode port runtime" OFF) ``` -------------------------------- ### Event Subscriptions with RAII in C++ Source: https://github.com/19h/idax/blob/master/README.md This C++ example shows how to subscribe to IDA events, specifically the `on_renamed` event, using a lambda function. It utilizes `ida::event::ScopedSubscription` for RAII (Resource Acquisition Is Initialization), ensuring that the subscription is automatically managed and unsubscribed when the scope is exited. ```cpp // Subscribe to rename events -- automatically unsubscribes when guard goes out of scope auto token = ida::event::on_renamed( [](ida::Address addr, std::string new_name, std::string old_name) { ida::ui::message("renamed: " + old_name + " -> " + new_name + "\n"); }); ida::event::ScopedSubscription guard(*token); // RAII: unsubscribes in destructor ``` -------------------------------- ### Navigate Program Segments and Functions in IDA Pro Source: https://github.com/19h/idax/blob/master/docs/tutorial/first_contact.md Iterates through all segments and functions within the IDA database to inspect their properties like name, start, and end addresses. This helps in understanding the program's layout. ```cpp for (auto seg : ida::segment::all()) { // inspect seg.name(), seg.start(), seg.end() } for (auto fn : ida::function::all()) { // inspect fn.name(), fn.start(), fn.end() } ``` -------------------------------- ### Generate Text Snapshots for Regression Testing (C++) Source: https://github.com/19h/idax/blob/master/docs/cookbook/disassembly_workflows.md Provides an example of generating text-based snapshots of instructions for regression testing. It captures the instruction text, mnemonic, operand count, and normalized operand renderings. ```cpp // For snapshot-style tests, capture: // ida::instruction::text(ea) // mnemonic + operand count // normalized operand renderings // Compare against a known fixture binary in CI. ``` -------------------------------- ### Initialize and Manage IDA Database Lifecycle Source: https://context7.com/19h/idax/llms.txt Demonstrates the essential steps for initializing the IDA library, opening a database, waiting for analysis, querying metadata, and saving/closing the database using idax. It emphasizes the importance of calling `ida::database::init()` first and shows how to handle potential errors using `ida::Result`. ```cpp #include int main() { // Initialize the IDA library (required before any other calls) auto status = ida::database::init(); if (!status) { std::cerr << "Init failed: " << status.error().message << "\n"; return 1; } // Open a database with auto-analysis status = ida::database::open("firmware.i64", /*auto_analysis=*/true); if (!status) { std::cerr << "Open failed: " << status.error().message << "\n"; return 1; } // Wait for auto-analysis to complete ida::analysis::wait(); // Query database metadata auto path = ida::database::input_file_path(); // -> "firmware.bin" auto base = ida::database::image_base(); // -> 0x400000 auto min_addr = ida::database::min_address(); // -> 0x400000 auto max_addr = ida::database::max_address(); // -> 0x4FFFFF auto md5 = ida::database::input_md5(); // -> "a1b2c3..." auto proc = ida::database::processor_name(); // -> "metapc" auto bitness = ida::database::address_bitness(); // -> 64 // Save and close ida::database::save(); ida::database::close(); return 0; } ``` -------------------------------- ### Configure IDA Pro Library Paths Source: https://github.com/19h/idax/blob/master/examples/CMakeLists.txt Configures the library names for IDA Pro based on the operating system (Windows, macOS, Linux). It also attempts to find the IDA Pro installation directory to link against the necessary libraries for example tools. ```cmake if(WIN32) set(IDAX_IDALIB_LIB_NAME "idalib.lib") set(IDAX_IDA_LIB_NAME "ida.lib") elseif(APPLE) set(IDAX_IDALIB_LIB_NAME "libidalib.dylib") set(IDAX_IDA_LIB_NAME "libida.dylib") else() set(IDAX_IDALIB_LIB_NAME "libidalib.so") set(IDAX_IDA_LIB_NAME "libida.so") endif() set(IDAX_EXAMPLE_IDA_RUNTIME_DIR "") if(DEFINED ENV{IDADIR}) set(_ida_dir "$ENV{IDADIR}") if(EXISTS "${_ida_dir}/${IDAX_IDALIB_LIB_NAME}" AND EXISTS "${_ida_dir}/${IDAX_IDA_LIB_NAME}") set(IDAX_EXAMPLE_IDA_RUNTIME_DIR "${_ida_dir}") endif() endif() if(NOT IDAX_EXAMPLE_IDA_RUNTIME_DIR AND APPLE) foreach(_ver 9.3 9.2) set(_try "/Applications/IDA Professional ${_ver}.app/Contents/MacOS") if(EXISTS "${_try}/${IDAX_IDALIB_LIB_NAME}" AND EXISTS "${_try}/${IDAX_IDA_LIB_NAME}") set(IDAX_EXAMPLE_IDA_RUNTIME_DIR "${_try}") break() endif() endforeach() endif() ``` -------------------------------- ### Locate IDA Installation (CMake) Source: https://github.com/19h/idax/blob/master/tests/integration/CMakeLists.txt This CMake code snippet locates the IDA Pro installation directory. It first checks for the IDADIR environment variable and, if not found, attempts to find common macOS installation paths. If the installation is not found, it issues a warning and exits. ```cmake if(DEFINED ENV{IDADIR}) set(IDA_INSTALL_DIR "$ENV{IDADIR}") elseif(APPLE) # Try common macOS locations. foreach(_ver 9.3 9.2) set(_try "/Applications/IDA Professional ${_ver}.app/Contents/MacOS") if(EXISTS "${_try}/libidalib.dylib") set(IDA_INSTALL_DIR "${_try}") break() endif() endforeach() endif() if(NOT IDA_INSTALL_DIR) message(WARNING "IDA installation not found — integration tests cannot be built.\n" "Set IDADIR environment variable to your IDA installation directory.") return() endif() message(STATUS "IDA installation: ${IDA_INSTALL_DIR}") ``` -------------------------------- ### Configure and Install Package Configuration Files (CMake) Source: https://github.com/19h/idax/blob/master/CMakeLists.txt Generates and installs the CMake package configuration files (`idaxConfig.cmake` and `idaxConfigVersion.cmake`) required for other projects to find and use the installed idax library. This involves using CMake's helper functions for configuration and versioning. ```cmake include(CMakePackageConfigHelpers) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/idaxConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/idaxConfig.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/idax ) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/idaxConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/idaxConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/idaxConfigVersion.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/idax ) ``` -------------------------------- ### Initialize and Open Database in IDA Pro Source: https://github.com/19h/idax/blob/master/docs/tutorial/first_contact.md Initializes the IDA database with command-line arguments, opens the specified input file, and waits for the analysis to complete. This is the first step in interacting with a program's structure. ```cpp ida::database::init(argc, argv); ada::database::open(input_path, true); ada::analysis::wait(); ``` -------------------------------- ### Create and Register IDA Plugin with Actions (C++) Source: https://context7.com/19h/idax/llms.txt Demonstrates how to create a basic IDA plugin by inheriting from ida::plugin::Plugin. It includes registering custom actions, attaching them to menus, and handling plugin initialization, termination, and execution. Dependencies include the 'ida/idax.hpp' header. ```cpp #include class MyPlugin final : public ida::plugin::Plugin { public: ida::plugin::Info info() const override { return { .name = "My Analysis Plugin", .hotkey = "Ctrl-Alt-M", .comment = "Performs custom analysis", .help = "Select a function and press the hotkey" }; } bool init() override { // Register a custom action ida::plugin::register_action({ .id = "myplugin:analyze", .label = "Run Analysis", .hotkey = "Ctrl-Shift-A", .handler = []() { auto addr = ida::ui::screen_address(); if (addr) { ida::ui::message("Analyzing at " + std::to_string(*addr) + "\n"); } return ida::ok(); }, .enabled = []() { return true; } }); // Attach to menu ida::plugin::attach_to_menu("Edit/Plugins/", "myplugin:analyze"); return true; } void term() override { ida::plugin::unregister_action("myplugin:analyze"); } ida::Status run(std::size_t arg) override { ida::ui::message("Plugin executed with arg=" + std::to_string(arg) + "\n"); // Get current address auto addr = ida::ui::screen_address(); if (!addr) { return ida::fail("No address selected"); } // Analyze function at cursor auto fn = ida::function::at(*addr); if (fn) { ida::ui::info("Function: " + fn->name()); } return ida::ok(); } }; IDAX_PLUGIN(MyPlugin) ``` -------------------------------- ### Iterating Entry Points: Legacy SDK vs. IDAX Source: https://github.com/19h/idax/blob/master/docs/migration/legacy_to_wrapper.md Demonstrates how to iterate through program entry points. The Legacy SDK uses a quantity and index-based approach, while IDAX provides a more direct count and by-index access to entry point objects. ```cpp // Legacy: iterating entry points // for (size_t i = 0; i < get_entry_qty(); i++) { // ea_t ea = get_entry(get_entry_ordinal(i)); // qstring name; get_entry_name(&name, get_entry_ordinal(i)); // } // idax: auto cnt = ida::entry::count(); if (cnt) { for (std::size_t i = 0; i < *cnt; ++i) { auto ep = ida::entry::by_index(i); if (ep) { // ep->address, ep->name, ep->ordinal } } } ``` -------------------------------- ### Unregister IDA Action During Teardown Source: https://github.com/19h/idax/blob/master/docs/quickstart/plugin.md Detaches an IDA action from its menu and unregisters it. This is typically performed during plugin teardown to clean up IDA's state. It utilizes functions from the 'ida::plugin' namespace. ```cpp auto r3 = ida::plugin::detach_from_menu("Edit/Plugins/", action.id); auto r4 = ida::plugin::unregister_action(action.id); ``` -------------------------------- ### Open and Create Netnodes with IDAX Storage Source: https://github.com/19h/idax/blob/master/docs/migration/legacy_to_wrapper.md Explains how to open existing netnodes or create new ones using the `ida::storage::Node` class in IDAX. Error handling for failed node opening is also shown. ```cpp // Legacy: // netnode n("my_plugin_data", 0, true); // create // idax: auto node = ida::storage::Node::open("my_plugin_data", true); if (!node) { /* handle error */ } ``` -------------------------------- ### Initializing and Opening an IDA Database with idax Source: https://github.com/19h/idax/blob/master/bindings/node/agents.md Demonstrates the basic lifecycle management for an IDA Pro database using the `idax.database` namespace. This includes initializing the IDA kernel and opening a database file with various options for analysis. ```javascript const idax = require('idax'); // Initialize IDA kernel (required before opening) idax.database.init({ quiet: false }); // Open a database, triggering default auto-analysis idax.database.open("path/to/my_database.idb"); // Open a database and skip analysis idax.database.open("path/to/another_db.idb", false); // Open specifying analysis mode idax.database.open("path/to/third_db.idb", 'skipAnalysis'); // Open specifying intent and mode idax.database.open("path/to/fourth_db.idb", 'binary', 'analyze'); // Open as a binary file idax.database.openBinary("path/to/binary_file.bin"); // Open as a non-binary file idax.database.openNonBinary("path/to/non_binary_file.dat"); ``` -------------------------------- ### Set, Get, and Remove Alt Values with IDAX Source: https://github.com/19h/idax/blob/master/docs/migration/legacy_to_wrapper.md Illustrates the usage of `set_alt`, `alt`, and `remove_alt` methods for managing integer values associated with address indices in IDAX storage nodes. ```cpp // Legacy: // n.altset(100, 42); // uval_t v = n.altval(100); // idax: node->set_alt(100, 42); auto v = node->alt(100); // -> Result node->remove_alt(100); ``` -------------------------------- ### Utilize Persistent Storage with Netnodes (C++) Source: https://context7.com/19h/idax/llms.txt Demonstrates how to use IDA's netnode system for persistent key-value storage within a plugin. It covers opening/creating nodes, storing and retrieving integers (alt), binary data (sup, blob), and string key-value pairs (hash). Dependencies include the 'ida/idax.hpp' header. ```cpp #include void use_storage() { // Open or create a node auto node = ida::storage::Node::open("$my_plugin_data", /*create=*/true); if (!node) { std::cerr << "Failed to open node\n"; return; } // Store integer values (alt) node->set_alt(100, 42); auto val = node->alt(100); if (val) { std::cout << "Alt value: " << *val << "\n"; } // Store binary data (sup) std::vector data = {0x01, 0x02, 0x03, 0x04}; node->set_sup(200, data); auto read_data = node->sup(200); // Store string key-value pairs (hash) node->set_hash("version", "1.0.0"); node->set_hash("author", "MyPlugin"); auto version = node->hash("version"); // Store large binary blobs std::vector blob(1024, 0xFF); node->set_blob(100, blob); // Use index >= 100 to avoid crashes auto blob_sz = node->blob_size(100); auto read_blob = node->blob(100); // Remove values node->remove_alt(100); node->remove_blob(100); } ``` -------------------------------- ### Error Handling Example in Rust Source: https://github.com/19h/idax/blob/master/bindings/rust/idax/README.md Demonstrates how to handle errors returned by IDAX operations using `idax::Result`. It shows matching on `Ok` and specific `Err` categories like `NotFound`. ```rust use idax::{function, Error}; use idax::error::ErrorCategory; match function::at(0xDEAD) { Ok(func) => println!("Found: {}", func.name), Err(e) if e.category == ErrorCategory::NotFound => { println!("No function at that address"); } Err(e) => return Err(e), } ``` -------------------------------- ### Manage Node Identity with IDAX Storage Source: https://github.com/19h/idax/blob/master/docs/migration/legacy_to_wrapper.md Demonstrates how to retrieve the unique ID of a netnode and how to open a node using its ID with the IDAX storage API. It also shows how to get the name of a node. ```cpp auto node = ida::storage::Node::open("$my_plugin_data", true); if (!node) return; auto id = node->id(); // -> Result auto reopened = ida::storage::Node::open_by_id(*id); auto name = reopened->name(); // -> Result ``` -------------------------------- ### IDA Database Operations and Analysis with idax (C++) Source: https://github.com/19h/idax/blob/master/README.md Demonstrates common idax operations including initializing and opening an IDA database, waiting for analysis to complete, iterating through functions, setting comments, resolving symbols, decompiling code, and saving/closing the database. This snippet showcases idax's C++23 interface, replacing raw SDK calls with a more intuitive, object-oriented approach. ```cpp #include // Open a database, iterate functions, decode instructions, decompile. // No flags. No sentinel values. No manual locking. No raw structs. ida::database::init();ida::database::open("firmware.i64", /*auto_analysis=*/true);ida::analysis::wait(); for (auto fn : ida::function::all()) { if (ida::instruction::is_call(fn.start())) ida::comment::set(fn.start(), "entry is a call instruction"); } auto main_address = ida::name::resolve("main"); if (main_address) { auto df = ida::decompiler::decompile(*main_address); if (df) { auto lines = df->lines(); if (lines) { for (const auto& line : *lines) std::cout << line << "\n"; } } } ida::database::save();ida::database::close(); ``` -------------------------------- ### Test idax Project with ctest Source: https://github.com/19h/idax/blob/master/README.md This command runs the idax test suite from the build directory. It's recommended to set the IDADIR environment variable to your IDA installation path for full integration coverage. ```bash ctest --test-dir build --output-on-failure ``` -------------------------------- ### Set up Build Environment for idax-sys Source: https://github.com/19h/idax/blob/master/bindings/rust/idax-sys/README.md These shell commands demonstrate how to configure the build environment for the idax-sys crate. It involves setting the IDASDK environment variable to point to the IDA SDK directory and building the libidax.a C++ library before running `cargo build`. ```sh # Point to your IDA SDK export IDASDK=/path/to/idasdk # Build idax C++ library first (from the idax repo root) cmake -B build -DCMAKE_BUILD_TYPE=Release cmake --build build # Now cargo build will find libidax.a and the SDK cargo build ``` -------------------------------- ### Binary Search and Patching in C++ Source: https://github.com/19h/idax/blob/master/README.md This C++ snippet demonstrates how to perform a binary search for a specific byte pattern (e.g., an ELF signature) within a given address range in the IDA database. If the pattern is found, it shows how to patch a byte at the found address and then read it back to confirm the change using an assertion. ```cpp auto lo = *ida::database::min_address(); auto hi = *ida::database::max_address(); // Find an ELF signature auto hit = ida::data::find_binary_pattern(lo, hi, "7F 45 4C 46"); if (hit) { // Patch it ida::data::patch_byte(*hit, 0x00); // Read it back to confirm auto val = ida::data::read_byte(*hit); assert(val && *val == 0x00); } ``` -------------------------------- ### Set, Get, and Remove Hash Values with IDAX Source: https://github.com/19h/idax/blob/master/docs/migration/legacy_to_wrapper.md Demonstrates the use of `set_hash` and `hash` methods for managing string key-value pairs within IDAX storage nodes, replacing legacy hash operations. ```cpp // Legacy: // n.hashset("version", "1.0"); // ssize_t sz = n.hashval("version", buf, bufsize); // idax: node->set_hash("version", "1.0"); auto val = node->hash("version"); // -> Result ```