Not sure if this is the right place to post, sorry if it isn't. Im going through a couple of ethical hacking books before i start my CEH ethical hacking course in a few months and one of the things i need to do is examine the registers. Im using a small piece of code in GDB to do so:
Code:
#include <stdio.h>
#include <string.h>
int main() {
char str_a[20];
strcpy(str_a, "Hello, world!\n");
printf(str_a);
}
When i compile it using GCC i get the error message - warning: format not a string literal and no format arguments
And when i set a breakpoint on the strcpy line i get a message :
Function "strcpy" not defined. Make breakpoint pending on future shared library load? (y or [n]) y
Which i assumed would happen as its strcpy is part of a shared library, i also assumed that when i ran it using GDB it would resolve the issue, but it didnt it just skipped that breakpoint altogether and continued onto the next breakpoint.
Code:
(gdb) list
1 #include <stdio.h>
2 #include <string.h>
3
4 int main() {
5 char str_a[20];
6
7 strcpy(str_a, "Hello, world!\n");
8 printf(str_a);
9 }(gdb) break 6
Breakpoint 1 at 0x4005fb: file char_array2.c, line 6.
(gdb) break strcpy
Function "strcpy" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (strcpy) pending.
(gdb) break 8
Breakpoint 3 at 0x400614: file char_array2.c, line 8.
(gdb) run
Starting program: /root/Documents/Programming/char_array2
Breakpoint 1, main () at char_array2.c:7
7 strcpy(str_a, "Hello, world!\n");
(gdb) i r rip
rip 0x4005fb 0x4005fb <main+23>
(gdb) x/5i $rip
=> 0x4005fb <main+23>: mov ecx,0x40072c
0x400600 <main+28>: lea rax,[rbp-0x20]
0x400604 <main+32>: mov edx,0xf
0x400609 <main+37>: mov rsi,rcx
0x40060c <main+40>: mov rdi,rax
(gdb) continue
Continuing.
Breakpoint 3, main () at char_array2.c:8
8 printf(str_a);
(gdb) i r rip
rip 0x400614 0x400614 <main+48>
(gdb) x/5i $rip
=> 0x400614 <main+48>: lea rax,[rbp-0x20]
0x400618 <main+52>: mov rdi,rax
0x40061b <main+55>: mov eax,0x0
0x400620 <main+60>: call 0x4004b8 <printf@plt>
0x400625 <main+65>: mov rdx,QWORD PTR [rbp-0x8]
(gdb) continue
Continuing.
Hello, world!
Anyone know what i did wrong?
Bookmarks