Actually, I was learning about the buffer overflow attack. So, can we figure out buffer address (I am using buffer variable in my program so that while writing in the buffer, I will make changes in the stack)?
1 Answer
Yes, as long as your variable isn’t optimised away.
For example, using ls with debug symbols:
gdb ls
>>> break main
>>> run
>>> print argv
$1 = (char **) 0x7fffffffdd78
In this case, argv is a pointer itself. If you want the address of a non-pointer variable, or the address of a pointer, use & as you would in C; gdb will give you the address, as above, or tell you if the variable isn’t stored in memory:
>>> printf &argc
Address requested for identifier "argc" which is in register $rdi
On x86, the contents of SP will tell you where the stack is:
>>> i r sp
sp 0x7fffffffdc98 0x7fffffffdc98