Module binaryninja::debuginfo

source ·
Expand description

Parsers and providers of debug information to Binary Ninja.

The debug information is used by Binary Ninja as ground-truth information about the attributes of functions, types, and variables that Binary Ninja’s analysis pipeline would otherwise work to deduce. By providing debug info, Binary Ninja’s output can be generated quicker, more accurately, and more completely.

A DebugInfoParser consists of: 1. A name 2. An is_valid function which takes a BV and returns a bool 3. A parse function which takes a DebugInfo object and uses the member functions add_type, add_function, and add_data_variable to populate all the info it can. And finally calling binaryninja::debuginfo::DebugInfoParser::register to register it with the core.

Here’s a minimal, complete example boilerplate-plugin:

use binaryninja::{
    binaryview::BinaryView,
    debuginfo::{CustomDebugInfoParser, DebugInfo, DebugInfoParser},
};

struct ExampleDebugInfoParser;

impl CustomDebugInfoParser for ExampleDebugInfoParser {
    fn is_valid(&self, _view: &BinaryView) -> bool {
        true
    }

    fn parse_info(&self, _debug_info: &mut DebugInfo, _view: &BinaryView, _debug_file: &BinaryView, _progress: Box<dyn Fn(usize, usize) -> Result<(), ()>>) -> bool {
        println!("Parsing info");
        true
    }
}

#[no_mangle]
pub extern "C" fn CorePluginInit() -> bool {
    DebugInfoParser::register("example debug info parser", ExampleDebugInfoParser {});
    true
}

DebugInfo will then be automatically applied to binary views that contain debug information (via the setting analysis.debugInfo.internal), binary views that provide valid external debug info files (analysis.debugInfo.external), or manually fetched/applied as below:

let bv = binaryninja::load("example").unwrap();
let valid_parsers = DebugInfoParser::parsers_for_view(&bv);
let parser = valid_parsers.get(0);
let debug_info = parser.parse_debug_info(&bv, &bv, None, None).unwrap();
bv.apply_debug_info(&debug_info);

Multiple debug-info parsers can manually contribute debug info for a binary view by simply calling parse_debug_info with the DebugInfo object just returned. This is automatic when opening a binary view with multiple valid debug info parsers. If you wish to set the debug info for a binary view without applying it as well, you can call binaryninja::binaryview::BinaryView::set_debug_info.

Structs§

  • Collates ground-truth function-external attributes for use in BinaryNinja’s internal analysis.
  • Provides an interface to both provide and query debug info. The DebugInfo object is used internally by the binary view to which it is applied to determine the attributes of functions, types, and variables that would otherwise be costly to deduce.
  • Represents the registered parsers and providers of debug information to Binary Ninja. See binaryninja::debuginfo for more information

Traits§

  • Implement this trait to implement a debug info parser. See DebugInfoParser for more details.