1

In CTFs when I'm given some ELF file, it usually wasn't compiled with the -g flag. Is there a way to to somehow edit the file to make it be as if the ELF file was originally compiled with the -g flag? (I guess part of my issue is that I also don't understand exactly what the -g flag adds for gdb, so I'm not sure if its possible to add whatever it adds)

3
  • Is there a way to insert the debug symbols into the given ELF file? Do you have the debug symbols?
    – tkausl
    Commented Aug 14, 2023 at 3:19
  • Debug symbols are produced during compilation; if your ELF binary has been stripped there's nothing to 'insert' - the symbols are tied to a single build, even if you had a separate file with DWARF symbols from a different source their offsets wouldn't match up with the binary
    – mimak
    Commented Aug 14, 2023 at 14:09
  • @tkausl I have changed the question somewhat, I see what I misunderstood Commented Aug 15, 2023 at 1:38

2 Answers 2

1

You could try ghidra2dwarf:

Ghidra2Dwarf is a ghidra plugin that allows to exports informations (such as functions, decompiled code, types) from ghidra to dwarf sections inside ELF binaries.

People have been using it to help with CTF challenges since 2020:

https://github.com/cesena/ghidra2dwarf/issues/5

0

Hellf python library can help you modify your elf file to add symbols to the symbol section table.

See an example here

Not the answer you're looking for? Browse other questions tagged or ask your own question.