我有一个可执行文件的核心转储,该可执行文件不是使用调试符号构建的。我可以恢复 argv 内容吗?
我有一个可执行文件的核心转储,该可执行文件不是使用调试符号构建的。
我可以恢复 argv 内容以查看命令行是什么吗?
如果我运行 gdb,我可以看到回溯,并且可以导航到 main() 框架。一旦到达那里,有没有办法在不知道其确切地址的情况下恢复 argv?
我在 x86_x64(Intel Xeon CPU)上运行 CEntOS Linux 发行版/内核,
我希望的原因之一是核心转储似乎显示部分 argv。
(该程序是 postgres,当我加载核心文件时,gdb 会打印一条消息,其中包括 postgres db 用户名、客户端 OP 地址和查询的前 10 个字符))
I have a core dump of an executable that was NOT built with debug symbols.
Can I recover argv contents to see what the command line was?
If I run gdb, I can see a backtrace, and I can navigate to the main() frame. Once there, is there a way to recover argv, without knowing its exact address?
I am on x86_x64 (Intel Xeon CPU) running a CEntOS Linux distro/kernel,
One reason I am hopeful is that the core dump seems to show a partial argv.
(The program is postgres, and when I load the core file, gdb prints a message that includes the postgres db-user name, client OP address, and first 10 characters of the query))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
x86_64
上,参数在%rdi
、%rsi
等寄存器中传递(调用约定)。因此,当您进入
main
框架时,您应该能够:不幸的是,GDB 通常不会在以下情况下恢复
$rdi
和$rsi
:你切换帧。所以这个例子不起作用:所以你必须做更多的工作......
你可以做的是使用Linux堆栈如何设置的知识进程启动,结合 GDB 将恢复堆栈指针的事实:
所以现在我们期望原来的
%rsp
为$rsp+8
(一次 POP,两次 PUSH),但由于在指令0x0000000000400449
处进行了对齐,因此它可能位于$rsp+16
>让我们看看那里有什么...
看起来很有希望:4 个(可疑的 argc),后面跟着 4 个非 NULL 指针,后面跟着 NULL。
让我们看看这是否成功:
确实,这就是我调用二进制文件的方式。作为最终的健全性检查,
0x00007fffbe5d6ecf
看起来像环境的一部分吗?是的,这就是环境的开始(或结束)。
这样你就得到了。
最后注意事项:如果 GDB 没有打印太多
,我们可以从第 5 帧恢复argc
和argv
。 GDB 和 GCC 双方都在努力使 GDB 打印更少的“优化”...此外,在加载核心时,我的 GDB 打印:
否定整个练习的需要。但是,这仅适用于短命令行,而上面的解决方案适用于任何命令行。
On
x86_64
the arguments are passed in%rdi
,%rsi
, etc. registers (calling convention).Therefore, when you step into the
main
frame, you should be able to:Unfortunately, GDB will not normally restore
$rdi
and$rsi
when you switch frames. So this example doesn't work:So you'll have to work some more ...
What you can do is use the knowledge of how Linux stack is set up at process startup, combined with the fact that GDB will restore stack pointer:
So now we expect the original
%rsp
to be$rsp+8
(one POP, two PUSHes), but it could be at$rsp+16
due to alignment that was done at instruction0x0000000000400449
Let's see what's there ...
That looks promising: 4 (suspected argc), followed by 4 non-NULL pointers, followed by NULL.
Let's see if that pans out:
Indeed, that's how I invoked the binary. As a final sanity check, does
0x00007fffbe5d6ecf
look like part of the enovironment?Yep, that's the beginning (or the end) of the environment.
So there you have it.
Final notes: if GDB didn't print
<optimized out>
so much, we could have recoveredargc
andargv
from frame #5. There is work on both GDB and GCC sides to make GDB print much less of "optimized out" ...Also, when loading the core, my GDB prints:
negating the need for this whole exercise. However, that only works for short command lines, while the solution above will work for any command line.