debuginfo module

binaryninja.debuginfo.DebugFunctionInfo([...])

DebugFunctionInfo collates ground-truth function-external attributes for use in BinaryNinja's internal analysis.

binaryninja.debuginfo.DebugInfo(handle)

class DebugInfo provides an interface to both provide and query debug info.

binaryninja.debuginfo.DebugInfoParser(handle)

DebugInfoParser represents the registered parsers and providers of debug information to Binary Ninja.

class DebugFunctionInfo(short_name: Optional[str] = None, full_name: Optional[str] = None, raw_name: Optional[str] = None, address: Optional[int] = None, return_type: Optional[Type] = None, parameters: Optional[List[Tuple[str, Type]]] = None, variable_parameters: Optional[bool] = None, calling_convention: Optional[CallingConvention] = None, platform: Optional[Platform] = None)[source]

Bases: object

DebugFunctionInfo collates ground-truth function-external attributes for use in BinaryNinja’s internal analysis.

When contributing function info, provide only what you know - BinaryNinja will figure out everything else that it can, as it usually does.

Functions will not be created if an address is not provided, but will be able to be queried from debug info for later user analysis.

Parameters
Return type

None

address: Optional[int] = None
calling_convention: Optional[CallingConvention] = None
full_name: Optional[str] = None
parameters: Optional[List[Tuple[str, Type]]] = None
platform: Optional[Platform] = None
raw_name: Optional[str] = None
return_type: Optional[Type] = None
short_name: Optional[str] = None
variable_parameters: Optional[bool] = None
class DebugInfo(handle: binaryninja._binaryninjacore.BNDebugInfo)[source]

Bases: object

class DebugInfo 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.

DebugInfo objects themselves are independent of binary views; their data can be sourced from any arbitrary binary views and be applied to any other arbitrary binary view. A DebugInfo object can also contain debug info from multiple DebugInfoParsers. This makes it possible to gather debug info that may be distributed across several different formats and files.

DebugInfo cannot be instantiated by the user, instead get it from either the binary view (see 'binaryview.BinaryView'.debug_info) or a debug-info parser (see debuginfo.DebugInfoParser.parse_debug_info).

Note

Please note that calling one of add_* functions will not work outside of a debuginfo plugin.

Parameters

handle (binaryninja._binaryninjacore.BNDebugInfo) –

Return type

None

add_data_variable(address: int, new_type: Type, name: Optional[str] = None) bool[source]

Adds a data variable scoped under the current parser’s name to the debug info

Parameters
Return type

bool

add_function(new_func: DebugFunctionInfo) bool[source]

Adds a function scoped under the current parser’s name to the debug info

Parameters

new_func (DebugFunctionInfo) –

Return type

bool

add_type(name: str, new_type: Type) bool[source]

Adds a type scoped under the current parser’s name to the debug info

Parameters
  • name (str) –

  • new_type (Type) –

Return type

bool

data_variables_from_parser(name: Optional[str] = None) Iterator[DataVariableAndName][source]

Returns a generator of all data variables provided by a named DebugInfoParser

Parameters

name (Optional[str]) –

Return type

Iterator[DataVariableAndName]

functions_from_parser(name: Optional[str] = None) Iterator[DebugFunctionInfo][source]

Returns a generator of all functions provided by a named DebugInfoParser

Parameters

name (Optional[str]) –

Return type

Iterator[DebugFunctionInfo]

get_data_variable_by_address(parser_name: str, address: int) Optional[Tuple[str, Type]][source]
Parameters
  • parser_name (str) –

  • address (int) –

Return type

Optional[Tuple[str, Type]]

get_data_variable_by_name(parser_name: str, name: str) Optional[Tuple[int, Type]][source]
Parameters
  • parser_name (str) –

  • name (str) –

Return type

Optional[Tuple[int, Type]]

get_data_variables_by_address(address: int) List[Tuple[str, Type]][source]

The values in the tuples returned in the list is (DebugInfoParserName, TypeName, type)

Parameters

address (int) –

Return type

List[Tuple[str, Type]]

get_data_variables_by_name(name: str) List[Tuple[str, Type]][source]

The values in the tuples returned in the list is (DebugInfoParserName, address, type)

Parameters

name (str) –

Return type

List[Tuple[str, Type]]

get_parsers()[source]
get_type_by_name(parser_name: str, name: str) Optional[Type][source]
Parameters
  • parser_name (str) –

  • name (str) –

Return type

Optional[Type]

get_types_by_name(name: str) List[Tuple[str, Type]][source]

The first element in the Tuple returned in the list is the name of the debug info parser the type came from

Parameters

name (str) –

Return type

List[Tuple[str, Type]]

remove_data_variable_by_address(parser_name: str, address: int)[source]
Parameters
  • parser_name (str) –

  • address (int) –

remove_function_by_index(parser_name: str, index: int)[source]
Parameters
  • parser_name (str) –

  • index (int) –

remove_parser_data_variables(parser_name: str)[source]
Parameters

parser_name (str) –

remove_parser_functions(parser_name: str)[source]
Parameters

parser_name (str) –

remove_parser_info(parser_name: str)[source]
Parameters

parser_name (str) –

remove_parser_types(parser_name: str)[source]
Parameters

parser_name (str) –

remove_type_by_name(parser_name: str, name: str)[source]
Parameters
  • parser_name (str) –

  • name (str) –

types_from_parser(name: Optional[str] = None) Iterator[Tuple[str, Type]][source]

Returns a generator of all types provided by a named DebugInfoParser

Parameters

name (Optional[str]) –

Return type

Iterator[Tuple[str, Type]]

property data_variables: Iterator[DataVariableAndName]

A generator of all data variables provided by DebugInfoParsers

property functions: Iterator[DebugFunctionInfo]

A generator of all functions provided by DebugInfoParsers

property types: Iterator[Tuple[str, Type]]

A generator of all types provided by DebugInfoParsers

class DebugInfoParser(handle: binaryninja._binaryninjacore.BNDebugInfoParser)[source]

Bases: object

DebugInfoParser represents the registered 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 DebugInfo.add_type, DebugInfo.add_function, and DebugInfo.add_data_variable to populate all the info it can.

And finally calling DebugInfoParser.register to register it with the core.

A working example:

import binaryninja as bn

def is_valid(bv: bn.binaryview.BinaryView) -> bool:
        return bv.view_type == "Raw"

def parse_info(debug_info: bn.debuginfo.DebugInfo, bv: bn.binaryview.BinaryView) -> None:
        debug_info.add_type("name", bn.types.Type.int(4, True))
        debug_info.add_data_variable(0x1234, bn.types.Type.int(4, True), "name")
        function_info = bn.debuginfo.DebugFunctionInfo(0xdead1337, "short_name", "full_name", "raw_name", bn.types.Type.int(4, False), [])
        debug_info.add_function(function_info)

bn.debuginfo.DebugInfoParser.register("debug info parser", is_valid, parse_info)

DebugInfo can then be automatically applied to valid binary views (via the “Parse and Apply Debug Info” setting), or manually fetched/applied as bellow:

valid_parsers = bn.debuginfo.DebugInfoParser.get_parsers_for_view(bv)
parser = valid_parsers[0]
debug_info = parser.parse_debug_info(bv)
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 'binaryview.BinaryView'.set_debug_info.

Parameters

handle (binaryninja._binaryninjacore.BNDebugInfoParser) –

Return type

None

is_valid_for_view(view: BinaryView) bool[source]

Returns whether this debug-info parser is valid for the provided binary view

Parameters

view (BinaryView) –

Return type

bool

parse_debug_info(view: BinaryView, debug_info: Optional[DebugInfo] = None) DebugInfo[source]

Returns a DebugInfo object populated with debug info by this debug-info parser. Only provide a DebugInfo object if you wish to append to the existing debug info

Parameters
Return type

DebugInfo

property name: str

Debug-info parser’s name (read-only)