MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / DebugInfoParser

Class DebugInfoParser

python/debuginfo.py:152–248  ·  view source on GitHub ↗

:py:class:`DebugInfoParser` represents the registered parsers and providers of debug information for 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 otherw

Source from the content-addressed store, hash-verified

150
151
152class DebugInfoParser(object, metaclass=_DebugInfoParserMetaClass):
153 """
154 :py:class:`DebugInfoParser` represents the registered parsers and providers of debug information for Binary Ninja.
155
156 The debug information is used by Binary Ninja as ground-truth information about the attributes of functions,
157 types, and variables that Binary Ninja's analysis pipeline would otherwise work to deduce. By providing
158 debug info, Binary Ninja's output can be generated quicker, more accurately, and more completely.
159
160 A DebugInfoParser consists of:
161
162 1. A name
163 2. An ``is_valid`` function which takes a :py:class:`binaryview.BinaryView` and returns a bool.
164 3. A ``parse`` function which takes a :py:class:`DebugInfo` object and uses the member functions :py:meth:`DebugInfo.add_type`, :py:meth:`DebugInfo.add_function`, and :py:meth:`DebugInfo.add_data_variable` to populate all the info it can.
165
166 And finally calling :py:meth:`DebugInfoParser.register` to register it with the core.
167
168 A working example::
169
170 import binaryninja as bn
171
172 def is_valid(bv: bn.binaryview.BinaryView) -> bool:
173 return bv.view_type == "Raw"
174
175 def parse_info(debug_info: bn.debuginfo.DebugInfo, bv: bn.binaryview.BinaryView, debug_file: bn.binaryview.BinaryView, progress: Callable[[int, int], bool]) -> None:
176 debug_info.add_type("name", bn.types.Type.int(4, True))
177 debug_info.add_data_variable(0x1234, bn.types.Type.int(4, True), "name")
178 function_info = bn.debuginfo.DebugFunctionInfo(0xadd6355, "short_name", "full_name", "raw_name", bn.types.Type.function(bn.types.Type.int(4, False), None), components=["some", "namespaces"])
179 debug_info.add_function(function_info)
180
181 bn.debuginfo.DebugInfoParser.register("debug info parser", is_valid, parse_info)
182
183 :py:class:`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::
184
185 valid_parsers = bn.debuginfo.DebugInfoParser.get_parsers_for_view(bv)
186 parser = valid_parsers[0]
187 debug_info = parser.parse_debug_info(bv, bv) # See docs for why BV is here twice
188 bv.apply_debug_info(debug_info)
189
190 Multiple debug-info parsers can manually contribute debug info for a binary view by simply calling ``parse_debug_info`` with the
191 ``DebugInfo`` object just returned. This is automatic when opening a binary view with multiple valid debug info parsers. If you
192 wish to set the debug info for a binary view without applying it as well, you can call ``'binaryview.BinaryView'.set_debug_info``.
193 """
194 def __init__(self, handle: core.BNDebugInfoParser) -> None:
195 self.handle = core.handle_of_type(handle, core.BNDebugInfoParser)
196
197 def __del__(self) -> None:
198 core.BNFreeDebugInfoParserReference(self.handle)
199
200 def __repr__(self) -> str:
201 return f"<debug-info parser: '{self.name}'>"
202
203 def __eq__(self, other: "DebugInfoParser") -> bool:
204 if not isinstance(other, self.__class__):
205 return NotImplemented
206 return ctypes.addressof(self.handle.contents) == ctypes.addressof(other.handle.contents)
207
208 def __ne__(self, other: "DebugInfoParser") -> bool:
209 if not isinstance(other, self.__class__):

Callers 5

listMethod · 0.70
__iter__Method · 0.70
__getitem__Method · 0.70
get_parsers_for_viewMethod · 0.70
registerMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected