Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass the output of a command as argument in gdb?

Tags:

debugging

gdb

I have a C program that accepts arguments. I want to pass arguments to it while debugging through gdb but I want to specify the arguments through, say, a python command. So,

(gdb) run >>python return "a"*20 #arg1 >>python return 1+2 #arg2

How can I do this? The reason why I want to do this is because I want to pass bytecode address to the program as an argument but if I pass it as a sting it just converts everything to ASCII. i.e. if I try:

(gdb) run \xf7\xff\xba\xb5

then the address that I gave above is just converted into an ASCII string instead of being used as a memory address. I think if my first query is answered my second query might also get answered.

Thanks.

like image 489
ritratt Avatar asked Feb 15 '23 05:02

ritratt


1 Answers

I found the solution.

(gdb) run "`python -c 'print "\xff\xff\xff\xff"'`"

like image 67
ritratt Avatar answered Mar 03 '23 03:03

ritratt