如何从文本文件传递参数以在gdb下运行程序?

时间:2017-01-28 10:46:21

标签: linux gdb xargs shellcode

我想使用像gdb下的命令这样的函数。

$ cat arg.txt | xargs ./binary

有没有办法实现呢?

2 个答案:

答案 0 :(得分:1)

当通过xargs调用gdb时,默认情况下,stdin会从/dev/null重定向。显然gdb需要stdin来读取和执行用户输入,但它不能,因为stdin是/dev/null

解决此问题的一种方法是将xargs--arg-file

一起使用
xargs --arg-file arg.txt gdb --args ./binary

请参阅man xargs

   -a file, --arg-file=file
          Read items from file instead of standard input.  If you use
          this option, stdin remains unchanged when commands are run.
          Otherwise, stdin is redirected from /dev/null.

答案 1 :(得分:0)

谢谢,我得到了一个简单的解决方案。

(gdb) run $( cat arg.txt )

也可以将命令的输出作为参数传递。

(gdb) run $( ruby -e 'print( "text as arguments" )' )
相关问题