(gdb) set write on (gdb) show write Writing into executable and core files is on. (gdb) file main Reading symbols from main...(no debugging symbols found)...done.
2、结合C码和汇编代码,定位出需修改的汇编指令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
(gdb) disassemble /mr main Dump of assembler code for function main: 0x0000000000001135 <+0>: 55 push %rbp 0x0000000000001136 <+1>: 48 89 e5 mov %rsp,%rbp 0x0000000000001139 <+4>: 48 83 ec 10 sub $0x10,%rsp 0x000000000000113d <+8>: c7 45 fc 41 00 00 00 movl $0x41,-0x4(%rbp) 0x0000000000001144 <+15>: 83 7d fc 3c cmpl $0x3c,-0x4(%rbp) # 0x3c = 60, 对应C码:grade <= 60 0x0000000000001148 <+19>: 7f 0e jg 0x1158 <main+35> 0x000000000000114a <+21>: 48 8d 3d b3 0e 00 00 lea 0xeb3(%rip),%rdi # 0x2004 0x0000000000001151 <+28>: e8 da fe ff ff callq 0x1030 <puts@plt> 0x0000000000001156 <+33>: eb 0c jmp 0x1164 <main+47> 0x0000000000001158 <+35>: 48 8d 3d aa 0e 00 00 lea 0xeaa(%rip),%rdi # 0x2009 0x000000000000115f <+42>: e8 cc fe ff ff callq 0x1030 <puts@plt> 0x0000000000001164 <+47>: b8 00 00 00 00 mov $0x0,%eax 0x0000000000001169 <+52>: c9 leaveq 0x000000000000116a <+53>: c3 retq
(gdb) disassemble /mr main Dump of assembler code for function main: ... 0x0000000000001148 <+19>: 7f 0e jg 0x1158 <main+35> ... (gdb) set *(short *)0x1148 = 0xe7e (指令长度为2个字节,这里是小端序) (gdb) disassemble /mr main Dump of assembler code for function main: ... 0x0000000000001148 <+19>: 7e 0e jle 0x1158 <main+35> ... End of assembler dump.