Skip to content

Instantly share code, notes, and snippets.

@polymorf
Created November 15, 2019 00:42
Show Gist options
  • Save polymorf/4e33d7f91b5da7c5bf5504b90ce2d01d to your computer and use it in GitHub Desktop.
Save polymorf/4e33d7f91b5da7c5bf5504b90ce2d01d to your computer and use it in GitHub Desktop.
load_gnu_debugdata_symbols.py usefull for android binaries / libs
#!/usr/bin/env python2
# coding: utf8
import lief
import lzma
def get_debugdata(elf_file):
binary = lief.parse(elf_file)
debugdata=""
try:
gnu_debug_data = binary.get_section(".gnu_debugdata")
debugdata = "".join(map(chr, gnu_debug_data.content))
except lief.not_found:
return None
return lzma.decompress(debugdata)
def get_symbols(input_file):
symbols={}
debug_elf = get_debugdata(input_file)
if debug_elf != None:
debug_binary = lief.parse(raw=map(ord,debug_elf), name="toto")
for symbol in debug_binary.static_symbols:
name = str(symbol.name)
if name == "":
continue
suffix=0
uniq_name=name
while uniq_name in symbols.keys():
uniq_name="%s_%d" % (name, suffix)
suffix+=1
symbols[uniq_name] = symbol.value
return symbols
def set_symbols(symbols):
for symbol in symbols.keys():
set_name(symbols[symbol], symbol, SN_CHECK)
print "0x%08x => %s" % (symbols[symbol], symbol)
symbols = get_symbols(get_input_file_path())
set_symbols(symbols)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment