how can i get the source code path && file names from an ELF file(compired with -g)?

本秂侑毒 提交于 2019-12-12 21:23:43

问题


I want to get the source code path && source names just through the ELF file, the .debug_str section contains what i need, but how can i filter them out?


回答1:


I suggest to use this command and tools like sed or grep.

$ readelf --string-dump=.debug_str YOUR_PROGRAM

this show path and source file name:

$ readelf --string-dump=.debug_str YOUR_PROGRAM | sed -n '/\/\|\.c/{s/.*\]  //p}'



回答2:


$ readelf --string-dump=.debug_str YOUR_PROGRAM

works fine.

However, make sure your_program is not stripped by using command

file YOUR_PROGRAM



回答3:


There is another way:

readelf --syms YOUR-PROGGRAM |tee /tmp/log

vim /tmp/log
:vim "FILE" %

You will get all file names, however without path.




回答4:


readelf holds the key, but you don't want to dump strings willy-nilly. Use the -wi option to properly format the info.
For example, create a shell script thus:

readelf -wi $1 | grep -B1 DW_AT_comp_dir | \
    awk '/DW_AT_name/{name = $NF; getline; print $NF"/"name}'

which further summarizes the output of readelf -wi.



来源:https://stackoverflow.com/questions/31333337/how-can-i-get-the-source-code-path-file-names-from-an-elf-filecompired-with

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!