Linux GDB 可以更改正在运行的程序的汇编代码吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6473908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can GDB change the assembly code of a running program?
提问by jyz
I want to add some extra funcionality to /bin/ls.
So I started it on gdb and added a breakpoint at the beginning.
我想为 /bin/ls 添加一些额外的功能。
所以我在gdb上启动,在开头加了一个断点。
Now question is: how can I change the code of a running program in memory? I can see the assembly code, but I'm not able to modify. How can I do it?
现在的问题是:如何更改内存中正在运行的程序的代码?我可以看到汇编代码,但我无法修改。我该怎么做?
On Windows I can easily do this with olldbg for example. How about on Linux?
例如,在 Windows 上,我可以使用 olldbg 轻松完成此操作。在 Linux 上呢?
(I know that doing this I will only change the code of the process in memory. So then I can dump memory to a file, and then I'll have my changes saved in a binary file).
(我知道这样做我只会更改内存中进程的代码。这样我就可以将内存转储到一个文件中,然后我会将我的更改保存在一个二进制文件中)。
Thank you.
谢谢你。
采纳答案by DipSwitch
You can write binary to memory directly but GDB doesn't have an assembler build in by default you can however do something like set *(unsigned char*)0x80FFDDEE = 0x90
to change the mnemonic at that address to a NOP for example. You could however use NASM to write a shellcode and use perl or python to inject it into the program :)
您可以直接将二进制写入内存,但默认情况下 GDB 没有内置汇编程序,但是您可以执行一些操作,例如set *(unsigned char*)0x80FFDDEE = 0x90
将该地址处的助记符更改为 NOP。但是,您可以使用 NASM 编写 shellcode 并使用 perl 或 python 将其注入程序:)
You might also like this little .gdbinit file to make debugging allot easier: https://gist.github.com/985474
您可能还喜欢这个小 .gdbinit 文件,以便更轻松地进行调试:https://gist.github.com/985474
回答by Dark Falcon
回答by mohit
Here is a blog postthat explains how to change the code at runtime both for gdb and Visual Studio.
这是一篇博客文章,解释了如何在运行时更改 gdb 和 Visual Studio 的代码。
回答by husin alhaj ahmade
You can use gcc-plugin to write an extension to modify your coed and add any additional functionality in easy way during compilation process. if you work on machine level code, you should use binary instrumentation tools like Pin and Dyninst to instrument your binary file on the disk. however, if the overhead is important issue, you should work carefully with such tools.
您可以使用 gcc-plugin 编写扩展来修改您的 coed 并在编译过程中以简单的方式添加任何附加功能。如果您处理机器级代码,则应该使用 Pin 和 Dyninst 等二进制检测工具来检测磁盘上的二进制文件。但是,如果开销是重要问题,您应该谨慎使用此类工具。