Skip to content

Instantly share code, notes, and snippets.

@trufae
Created April 7, 2021 20:23
Show Gist options
  • Select an option

  • Save trufae/748b2f36a3075a9707befb8a4a6ca93f to your computer and use it in GitHub Desktop.

Select an option

Save trufae/748b2f36a3075a9707befb8a4a6ca93f to your computer and use it in GitHub Desktop.
script to load symbols from .gnu_debugdata section into r2
#!/usr/bin/env python
#
# Script to parse the .gnu_debugdata section of ELF binaries
# Usage:
# $ r2 -i debugdata.py bd64
# The script can be also executed from the r2 shell
# $ . debugdata.py
#
import r2pipe
r2 = r2pipe.open();
def parse_debugdata(pa, sz):
r2.cmd("wtf .dd.dump.xz %s @e:io.va=0@ %s"%(sz, pa))
r2.syscmd("xz -d .dd.dump.xz")
r2.cmd(".!rabin2 -rs .dd.dump")
pa = 0
sz = 0
sections = r2.cmdj("iSj")
for s in sections:
if s["name"] == ".gnu_debugdata":
pa = s["paddr"]
sz = s["size"]
if pa > 0 and sz > 0:
parse_debugdata(pa, sz)
else:
print("No debugdata section found in this binary")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment