bind
是套接字系统调用之一。有一种特殊的方法可以在gdb中加入系统调用断点 - catch syscall <syscall name>
。在这种类型的断点之后,您可以根据kernel calling conventions来查看寄存器中的系统调用参数。对于x86_64,通过%rdi,%rsi,%rdx,%r10,%r8和%r9寄存器传递参数。对于x86-32 - 通过%ebx,%ecx,%edx,%esi,%edi,%ebp寄存器。
(gdb) catch syscall bind
Catchpoint 3 (syscall 'bind' [49])
(gdb) r
Starting program: /usr/bin/nmap google.com
Starting Nmap 5.00 (http://nmap.org) at 2012-03-16 01:09 PDT
Warning: Hostname google.com resolves to 6 IPs. Using 173.194.69.100.
Catchpoint 3 (call to syscall 'bind'), 0x00007ffff6520307 in bind()
from /lib/libc.so.6
(gdb) info registers
rax 0xffffffffffffffda -38
rbx 0xb35870 11753584
rcx 0xffffffffffffffff -1
rdx 0x14 20
rsi 0x7fffffff7d90 140737488321936
rdi 0x8 8
rbp 0x8 0x8
rsp 0x7fffffff7d58 0x7fffffff7d58
r8 0xb 11
r9 0x8000 32768
r10 0x7fffffff7b00 140737488321280
r11 0x202 514
r12 0xb09630 11572784
r13 0xb359f0 11753968
r14 0x2 2
r15 0xc8 200
rip 0x7ffff6520307 0x7ffff6520307 <bind+7>
eflags 0x202 [ IF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
---Type <return> to continue, or q <return> to quit---
gs 0x0 0
(gdb)
例如这里%rdi包含第一个bind
调用参数 - 套接字文件描述符。
对于x86-32,由于套接字系统调用通过socketcall
系统调用实现,所以事情更加复杂。这就是为什么不可能直接将0123点拨入bind
。你可以找到更多关于它的信息here。
你在使用什么操作系统? x64还是x86?答案取决于建筑。 – ks1322 2012-03-14 07:18:39
x86_64,但我也对x86感兴趣。 – Lekensteyn 2012-03-14 11:30:30