Vector35 / binaryninja-api

Public API, examples, documentation and issues for Binary Ninja
https://binary.ninja/
MIT License
893 stars 199 forks source link

add support for .gnu_debugdata #5779

Open psifertex opened 1 month ago

psifertex commented 1 month ago

Fedora (and apparently android based on a sample file we received) may use https://fedoraproject.org/wiki/Features/MiniDebugInfo to include additional debug information.

See also: https://sourceware.org/gdb/current/onlinedocs/gdb.html/MiniDebugInfo.html https://archive.fosdem.org/2020/schedule/event/debugging_mini/attachments/slides/4059/export/events/attachments/debugging_mini/slides/4059/fosdem2020_minidebuginfo_kkleine.pdf

psifertex commented 1 month ago

Until this is added as a first-class feature, install the snippet plugin from the plugin manager and add the following code to it:

# work-around until https://github.com/Vector35/binaryninja-api/issues/5779 is resolved
# script assumes it's being run on an ELF with the .gnu_debugdata section
import lzma
rawview = bv.parent_view

if ".gnu_debugdata" in rawview.sections:
    section = rawview.sections[".gnu_debugdata"]
    buf = lzma.decompress(rawview.read(section.start, section.length))
    with load(buf) as symview:
        with bv.bulk_modify_symbols():
            for s in symview.get_symbols():
                print(s)
                bv.define_user_symbol(s)
else:
    log_error("No debugdata found")

Then you can trigger it with an action or bind it to a hotkey