debuginfo module¶
|
|
|
|
|
- class DebugFunctionInfo(address: Optional[int] = None, short_name: Optional[str] = None, full_name: Optional[str] = None, raw_name: Optional[str] = None, function_type: Optional[Type] = 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:
- class DebugInfo(handle: 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 (seedebuginfo.DebugInfoParser.parse_debug_info
).Note
Please note that calling one of
add_*
functions will not work outside of a debuginfo plugin.- Parameters:
handle (BNDebugInfo) –
- 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
- 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:
- add_type(name: str, new_type: Type) bool [source]¶
Adds a type scoped under the current parser’s name to the debug info
- data_variables_from_parser(name: Optional[str] = None) Iterator[DataVariableAndName] [source]¶
Returns a generator of all data variables provided by a named DebugInfoParser
- Parameters:
- Return type:
- functions_from_parser(name: Optional[str] = None) Iterator[DebugFunctionInfo] [source]¶
Returns a generator of all functions provided by a named DebugInfoParser
- Parameters:
- Return 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)
- 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)
- 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
- types_from_parser(name: Optional[str] = None) Iterator[Tuple[str, Type]] [source]¶
Returns a generator of all types provided by a named DebugInfoParser
- 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
- class DebugInfoParser(handle: 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:
A name
An
is_valid
function which takes a BV and returns a boolA
parse
function which takes aDebugInfo
object and uses the member functionsDebugInfo.add_type
,DebugInfo.add_function
, andDebugInfo.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
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: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 theDebugInfo
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 (BNDebugInfoParser) –
- 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:
- parse_debug_info(view: BinaryView, debug_info: Optional[DebugInfo] = None, progress: Optional[Callable[[int, int], bool]] = None) Optional[DebugInfo] [source]¶
Returns a
DebugInfo
object populated with debug info by this debug-info parser. Only provide aDebugInfo
object if you wish to append to the existing debug info