强行修改 ELF 文件后使用 GDB 进行源码级调试的方法
- 使用
patchelf命令修改目标文件ld、libc。
patchelf --set-interpreter /mnt/hgfs/Share/ld.so --replace-needed libc.so.6 /mnt/hgfs/Share/libc.so pwn.elf
GDB直接载入文件。
gdb pwn.elf
- 在
GDB中设置debug-file-directory及directories,其中debug-file-directory为.build-id文件夹所在的文件夹,directories为想要调试的函数源码文件所在的文件夹。 - 注意,程序所使用的
ld、libc必须要与GDB中指定的debug-file-directory、directories是同一版本,否则无法进行源码级调试。 - 可在网站:
https://codebrowser.dev/glibc/中查找想要调试的函数的源码的具体位置。