Intro x86 Part 3: Linux Tools & Analysis: Xeno Kovah - 2009/2010 Xkovah at Gmail
Intro x86 Part 3: Linux Tools & Analysis: Xeno Kovah - 2009/2010 Xkovah at Gmail
Examples:
call DWORD PTR [ebx+esi*4-0xe8]
call *-0xe8(%ebx,%esi,4)
mov
mov
lea
lea
Book p. 53
Book p. 63
objdump -d hello
hello:
08048374 <main>:
8048374:
8d 4c 24 04
8048378:
83 e4 f0
804837b:
ff 71 fc
804837e:
55
804837f:
89 e5
8048381:
51
push %ebp
mov %esp,%ebp
push %ebx
sub $0x4,%esp
call 8048280 <_init+0xc>
lea 0x4(%esp),%ecx
and $0xfffffff0,%esp
pushl -0x4(%ecx)
push %ebp
mov %esp,%ebp
push %ecx
08048374 <main>:
8048374:
8d 4c 24 04
8048378:
83 e4 f0
804837b:
ff 71 fc
804837e:
55
804837f:
89 e5
8048381:
51
push ebp
mov ebp,esp
push ebx
sub esp,0x4
call 8048280 <_init+0xc>
lea ecx,[esp+0x4]
and esp,0xfffffff0
push DWORD PTR [ecx-0x4]
push ebp
mov ebp,esp
push ecx
10
Book p. 57
12
GDB commands
help - internal navigation of available
commands
run or r - run the program
r <argv> - run the program passing
the arguments in <argv>
I.e. for Example 2 r 1 2 would be what
we used in windows
14
GDB commands 2
help display
display prints out a statement every time the debugger stops
display/FMT EXP
FMT can be a combination of the following:
i - display as asm instruction
x or d - display as hex or decimal
b or h or w - display as byte, halfword (2 bytes), word (4 bytes - as
opposed to intel calling that a double word. Confusing!)
s - character string (will just keep reading till it hits a null character)
<number> - display <number> worth of things (instructions, bytes,
words, strings, etc)
GDB commands 3
GDB commands 4
For all breakpoint-related commands see help
breakpoints
break or b - set a breakpoint
With debugging symbols you can do things like b
main . Without them you can do things like
b *<address> to break at a given memory address.
Note: gdb s interpretation of where a function begins
may exclude the function prolog like push ebp
GDB 7 commands
New for GDB 7, released Sept 2009
Thanks to Dave Keppler for notifying me of the availability of
these new commands
reverse-step ('rs') -- Step program backward until it reaches
the beginning of a previous source line
reverse-stepi -- Step backward exactly one instruction
reverse-continue ('rc') -- Continue program being
debugged but run it in reverse
reverse-finish -- Execute backward until just before the
selected stack frame is called
18
GDB 7 commands 2
reverse-next ('rn') -- Step program backward, proceeding
through subroutine calls.
reverse-nexti ('rni') -- Step backward one instruction, but
proceed through called subroutines.
set exec-direction (forward/reverse) -- Set direction of
execution. All subsequent execution commands (continue,
step, until etc.) will run the program being debugged in the
selected direction.
The "disassemble" command now supports an optional /
m modifier to print mixed source+assembly.
"disassemble" command with a /r modifier, print the raw
instructions in hex as well as in symbolic form.
See help disassemble for full syntax
19
display/10i $eip
display/x $eax
display/x $ebx
display/x $ecx
display/x $edx
display/x $edi
display/x $esi
display/x $ebp
display/32xw $esp
break main
20
(gdb) r
Starting program: /home/user/hello
0xb7df2450
0xb7df2450
21
Stepping
22
Lab time:
Running examples with GDB
24