gdb 的反汇编对应列出源码

gdb 的反汇编命令原来可以列出源码对应的行数和二进制字节了啊

之前都是用info line 来看函数汇编对应的源码行数,偶尔还用二进制编辑工具看字节码(gdb也有 x命令)

原来不知道上面时候有了这两个选项都不知道啊!  看看下面的初始化局部字符串数组原来是这样做的阿^_^

(gdb) help disassemble 
Disassemble a specified section of memory.
Default is the function surrounding the pc of the selected frame.
With a /m modifier, source lines are included (if available).
With a /r modifier, raw instructions in hex are included.
With a single argument, the function surrounding that address is dumped.
Two arguments (separated by a comma) are taken as a range of memory to dump,
  in the form of "start,end", or "start,+length".



(gdb) disassemble /m  main
Dump of assembler code for function main:
119    {
   0x08048799 <+0>:    push   %ebp
   0x0804879a <+1>:    mov    %esp,%ebp
   0x0804879c <+3>:    and    $0xfffffff0,%esp
   0x0804879f <+6>:    push   %ebx
   0x080487a0 <+7>:    sub    $0x5c,%esp
   0x080487a3 <+10>:    mov    0xc(%ebp),%eax
   0x080487a6 <+13>:    mov    %eax,0x1c(%esp)
   0x080487aa <+17>:    mov    %gs:0x14,%eax
   0x080487b0 <+23>:    mov    %eax,0x4c(%esp)
   0x080487b4 <+27>:    xor    %eax,%eax

120       char a[] =  "abadbabcefgabababacefababa";
   0x080487b6 <+29>:    movl   $0x64616261,0x2a(%esp)
   0x080487be <+37>:    movl   $0x63626162,0x2e(%esp)
   0x080487c6 <+45>:    movl   $0x61676665,0x32(%esp)
   0x080487ce <+53>:    movl   $0x61626162,0x36(%esp)
   0x080487d6 <+61>:    movl   $0x65636162,0x3a(%esp)
   0x080487de <+69>:    movl   $0x61626166,0x3e(%esp)
   0x080487e6 <+77>:    movw   $0x6162,0x42(%esp)
---Type <return> to continue, or q <return> to quit---
   0x080487ed <+84>:    movb   $0x0,0x44(%esp)

121       char b[] =  "ababac";   
   0x080487f2 <+89>:    movl   $0x62616261,0x45(%esp)
   0x080487fa <+97>:    movw   $0x6361,0x49(%esp)
   0x08048801 <+104>:    movb   $0x0,0x4b(%esp)

122       int i  = naive_match(a,b,strlen(a),strlen(b));     
   0x08048806 <+109>:    lea    0x45(%esp),%eax
   0x0804880a <+113>:    mov    %eax,(%esp)
   0x0804880d <+116>:    call   0x8048358 <strlen@plt>
   0x08048812 <+121>:    mov    %eax,%ebx
   0x08048814 <+123>:    lea    0x2a(%esp),%eax
   0x08048818 <+127>:    mov    %eax,(%esp)
   0x0804881b <+130>:    call   0x8048358 <strlen@plt>
   0x08048820 <+135>:    mov    %ebx,0xc(%esp)
   0x08048824 <+139>:    mov    %eax,0x8(%esp)
   0x08048828 <+143>:    lea    0x45(%esp),%eax
   0x0804882c <+147>:    mov    %eax,0x4(%esp)
   0x08048830 <+151>:    lea    0x2a(%esp),%eax
   0x08048834 <+155>:    mov    %eax,(%esp)
---Type <return> to continue, or q <return> to quit---
   0x08048837 <+158>:    call   0x8048444 <naive_match>
   0x0804883c <+163>:    mov    %eax,0x24(%esp)

123       printf ("i=%d\n" , i);
   0x08048840 <+167>:    mov    $0x8048aaf,%eax
   0x08048845 <+172>:    mov    0x24(%esp),%edx
   0x08048849 <+176>:    mov    %edx,0x4(%esp)
   0x0804884d <+180>:    mov    %eax,(%esp)
   0x08048850 <+183>:    call   0x8048368 <printf@plt>

124       
125       caculate_jump(b,strlen(b));
   0x08048855 <+188>:    lea    0x45(%esp),%eax
   0x08048859 <+192>:    mov    %eax,(%esp)
   0x0804885c <+195>:    call   0x8048358 <strlen@plt>
   0x08048861 <+200>:    mov    %eax,0x4(%esp)
   0x08048865 <+204>:    lea    0x45(%esp),%eax
   0x08048869 <+208>:    mov    %eax,(%esp)
   0x0804886c <+211>:    call   0x8048504 <caculate_jump>

126       for (i =0;i< 7;i++)
---Type <return> to continue, or q <return> to quit---
   0x08048871 <+216>:    movl   $0x0,0x24(%esp)
   0x08048879 <+224>:    jmp    0x80488a4 <main+267>
   0x0804889f <+262>:    addl   $0x1,0x24(%esp)
   0x080488a4 <+267>:    cmpl   $0x6,0x24(%esp)
   0x080488a9 <+272>:    jle    0x804887b <main+226>

127       {
128          printf ("F[%d] =%d\n" , i,F[i]);
   0x0804887b <+226>:    mov    0x24(%esp),%eax
   0x0804887f <+230>:    mov    0x804a040(,%eax,4),%edx
   0x08048886 <+237>:    mov    $0x8048ab5,%eax
   0x0804888b <+242>:    mov    %edx,0x8(%esp)
   0x0804888f <+246>:    mov    0x24(%esp),%edx
   0x08048893 <+250>:    mov    %edx,0x4(%esp)
   0x08048897 <+254>:    mov    %eax,(%esp)
   0x0804889a <+257>:    call   0x8048368 <printf@plt>

129       }
130       i  = kmp(a,b,strlen(a),strlen(b));     
   0x080488ab <+274>:    lea    0x45(%esp),%eax
   0x080488af <+278>:    mov    %eax,(%esp)
---Type <return> to continue, or q <return> to quit---
   0x080488b2 <+281>:    call   0x8048358 <strlen@plt>
   0x080488b7 <+286>:    mov    %eax,%ebx
   0x080488b9 <+288>:    lea    0x2a(%esp),%eax
   0x080488bd <+292>:    mov    %eax,(%esp)
   0x080488c0 <+295>:    call   0x8048358 <strlen@plt>
   0x080488c5 <+300>:    mov    %ebx,0xc(%esp)
   0x080488c9 <+304>:    mov    %eax,0x8(%esp)
   0x080488cd <+308>:    lea    0x45(%esp),%eax
   0x080488d1 <+312>:    mov    %eax,0x4(%esp)
   0x080488d5 <+316>:    lea    0x2a(%esp),%eax
   0x080488d9 <+320>:    mov    %eax,(%esp)
   0x080488dc <+323>:    call   0x80486c8 <kmp>
   0x080488e1 <+328>:    mov    %eax,0x24(%esp)

131       printf ("i=%d\n" , i);
   0x080488e5 <+332>:    mov    $0x8048aaf,%eax
   0x080488ea <+337>:    mov    0x24(%esp),%edx
   0x080488ee <+341>:    mov    %edx,0x4(%esp)
   0x080488f2 <+345>:    mov    %eax,(%esp)
   0x080488f5 <+348>:    call   0x8048368 <printf@plt>

---Type <return> to continue, or q <return> to quit---
132          
133       caculate_jump_enhance(b,strlen(b));
   0x080488fa <+353>:    lea    0x45(%esp),%eax
   0x080488fe <+357>:    mov    %eax,(%esp)
   0x08048901 <+360>:    call   0x8048358 <strlen@plt>
   0x08048906 <+365>:    mov    %eax,0x4(%esp)
   0x0804890a <+369>:    lea    0x45(%esp),%eax
   0x0804890e <+373>:    mov    %eax,(%esp)
   0x08048911 <+376>:    call   0x80485ae <caculate_jump_enhance>

134      
135       for (i =0;i< 7;i++)
   0x08048916 <+381>:    movl   $0x0,0x24(%esp)
   0x0804891e <+389>:    jmp    0x8048949 <main+432>
   0x08048944 <+427>:    addl   $0x1,0x24(%esp)
   0x08048949 <+432>:    cmpl   $0x6,0x24(%esp)
   0x0804894e <+437>:    jle    0x8048920 <main+391>

136       {
137          printf ("F[%d] =%d\n" , i,F[i]);
   0x08048920 <+391>:    mov    0x24(%esp),%eax
---Type <return> to continue, or q <return> to quit---
   0x08048924 <+395>:    mov    0x804a040(,%eax,4),%edx
   0x0804892b <+402>:    mov    $0x8048ab5,%eax
   0x08048930 <+407>:    mov    %edx,0x8(%esp)
   0x08048934 <+411>:    mov    0x24(%esp),%edx
   0x08048938 <+415>:    mov    %edx,0x4(%esp)
   0x0804893c <+419>:    mov    %eax,(%esp)
   0x0804893f <+422>:    call   0x8048368 <printf@plt>

138       }
139       i  = kmp(a,b,strlen(a),strlen(b));     
   0x08048950 <+439>:    lea    0x45(%esp),%eax
   0x08048954 <+443>:    mov    %eax,(%esp)
   0x08048957 <+446>:    call   0x8048358 <strlen@plt>
   0x0804895c <+451>:    mov    %eax,%ebx
   0x0804895e <+453>:    lea    0x2a(%esp),%eax
   0x08048962 <+457>:    mov    %eax,(%esp)
   0x08048965 <+460>:    call   0x8048358 <strlen@plt>
   0x0804896a <+465>:    mov    %ebx,0xc(%esp)
   0x0804896e <+469>:    mov    %eax,0x8(%esp)
   0x08048972 <+473>:    lea    0x45(%esp),%eax
   0x08048976 <+477>:    mov    %eax,0x4(%esp)
---Type <return> to continue, or q <return> to quit---
   0x0804897a <+481>:    lea    0x2a(%esp),%eax
   0x0804897e <+485>:    mov    %eax,(%esp)
   0x08048981 <+488>:    call   0x80486c8 <kmp>
   0x08048986 <+493>:    mov    %eax,0x24(%esp)

140        printf ("i=%d\n" , i);
   0x0804898a <+497>:    mov    $0x8048aaf,%eax
   0x0804898f <+502>:    mov    0x24(%esp),%edx
   0x08048993 <+506>:    mov    %edx,0x4(%esp)
   0x08048997 <+510>:    mov    %eax,(%esp)
   0x0804899a <+513>:    call   0x8048368 <printf@plt>

141       return 0;
   0x0804899f <+518>:    mov    $0x0,%eax

142    }
   0x080489a4 <+523>:    mov    0x4c(%esp),%edx
   0x080489a8 <+527>:    xor    %gs:0x14,%edx
   0x080489af <+534>:    je     0x80489b6 <main+541>
   0x080489b1 <+536>:    call   0x8048378 <__stack_chk_fail@plt>
   0x080489b6 <+541>:    add    $0x5c,%esp
---Type <return> to continue, or q <return> to quit---
   0x080489b9 <+544>:    pop    %ebx
   0x080489ba <+545>:    mov    %ebp,%esp
   0x080489bc <+547>:    pop    %ebp
   0x080489bd <+548>:    ret    

End of assembler dump.







(gdb) disassemble /r main
Dump of assembler code for function main:
   0x08048799 <+0>:     55    push   %ebp
   0x0804879a <+1>:     89 e5    mov    %esp,%ebp
   0x0804879c <+3>:     83 e4 f0    and    $0xfffffff0,%esp
   0x0804879f <+6>:     53    push   %ebx
   0x080487a0 <+7>:     83 ec 5c    sub    $0x5c,%esp
   0x080487a3 <+10>:     8b 45 0c    mov    0xc(%ebp),%eax
   0x080487a6 <+13>:     89 44 24 1c    mov    %eax,0x1c(%esp)
   0x080487aa <+17>:     65 a1 14 00 00 00    mov    %gs:0x14,%eax
   0x080487b0 <+23>:     89 44 24 4c    mov    %eax,0x4c(%esp)
   0x080487b4 <+27>:     31 c0    xor    %eax,%eax
   0x080487b6 <+29>:     c7 44 24 2a 61 62 61 64    movl   $0x64616261,0x2a(%esp)
   0x080487be <+37>:     c7 44 24 2e 62 61 62 63    movl   $0x63626162,0x2e(%esp)
   0x080487c6 <+45>:     c7 44 24 32 65 66 67 61    movl   $0x61676665,0x32(%esp)
   0x080487ce <+53>:     c7 44 24 36 62 61 62 61    movl   $0x61626162,0x36(%esp)
   0x080487d6 <+61>:     c7 44 24 3a 62 61 63 65    movl   $0x65636162,0x3a(%esp)
   0x080487de <+69>:     c7 44 24 3e 66 61 62 61    movl   $0x61626166,0x3e(%esp)
   0x080487e6 <+77>:     66 c7 44 24 42 62 61    movw   $0x6162,0x42(%esp)
   0x080487ed <+84>:     c6 44 24 44 00    movb   $0x0,0x44(%esp)
   0x080487f2 <+89>:     c7 44 24 45 61 62 61 62    movl   $0x62616261,0x45(%esp)
   0x080487fa <+97>:     66 c7 44 24 49 61 63    movw   $0x6361,0x49(%esp)
---Type <return> to continue, or q <return> to quit---
   0x08048801 <+104>:     c6 44 24 4b 00    movb   $0x0,0x4b(%esp)
   0x08048806 <+109>:     8d 44 24 45    lea    0x45(%esp),%eax
   0x0804880a <+113>:     89 04 24    mov    %eax,(%esp)
   0x0804880d <+116>:     e8 46 fb ff ff    call   0x8048358 <strlen@plt>
   0x08048812 <+121>:     89 c3    mov    %eax,%ebx
   0x08048814 <+123>:     8d 44 24 2a    lea    0x2a(%esp),%eax
   0x08048818 <+127>:     89 04 24    mov    %eax,(%esp)
   0x0804881b <+130>:     e8 38 fb ff ff    call   0x8048358 <strlen@plt>
   0x08048820 <+135>:     89 5c 24 0c    mov    %ebx,0xc(%esp)
   0x08048824 <+139>:     89 44 24 08    mov    %eax,0x8(%esp)
   0x08048828 <+143>:     8d 44 24 45    lea    0x45(%esp),%eax
   0x0804882c <+147>:     89 44 24 04    mov    %eax,0x4(%esp)
   0x08048830 <+151>:     8d 44 24 2a    lea    0x2a(%esp),%eax
   0x08048834 <+155>:     89 04 24    mov    %eax,(%esp)
   0x08048837 <+158>:     e8 08 fc ff ff    call   0x8048444 <naive_match>
   0x0804883c <+163>:     89 44 24 24    mov    %eax,0x24(%esp)
   0x08048840 <+167>:     b8 af 8a 04 08    mov    $0x8048aaf,%eax
   0x08048845 <+172>:     8b 54 24 24    mov    0x24(%esp),%edx
   0x08048849 <+176>:     89 54 24 04    mov    %edx,0x4(%esp)
   0x0804884d <+180>:     89 04 24    mov    %eax,(%esp)
   0x08048850 <+183>:     e8 13 fb ff ff    call   0x8048368 <printf@plt>
---Type <return> to continue, or q <return> to quit---
   0x08048855 <+188>:     8d 44 24 45    lea    0x45(%esp),%eax
   0x08048859 <+192>:     89 04 24    mov    %eax,(%esp)
   0x0804885c <+195>:     e8 f7 fa ff ff    call   0x8048358 <strlen@plt>
   0x08048861 <+200>:     89 44 24 04    mov    %eax,0x4(%esp)
   0x08048865 <+204>:     8d 44 24 45    lea    0x45(%esp),%eax
   0x08048869 <+208>:     89 04 24    mov    %eax,(%esp)
   0x0804886c <+211>:     e8 93 fc ff ff    call   0x8048504 <caculate_jump>
   0x08048871 <+216>:     c7 44 24 24 00 00 00 00    movl   $0x0,0x24(%esp)
   0x08048879 <+224>:     eb 29    jmp    0x80488a4 <main+267>
   0x0804887b <+226>:     8b 44 24 24    mov    0x24(%esp),%eax
   0x0804887f <+230>:     8b 14 85 40 a0 04 08    mov    0x804a040(,%eax,4),%edx
   0x08048886 <+237>:     b8 b5 8a 04 08    mov    $0x8048ab5,%eax
   0x0804888b <+242>:     89 54 24 08    mov    %edx,0x8(%esp)
   0x0804888f <+246>:     8b 54 24 24    mov    0x24(%esp),%edx
   0x08048893 <+250>:     89 54 24 04    mov    %edx,0x4(%esp)
   0x08048897 <+254>:     89 04 24    mov    %eax,(%esp)
   0x0804889a <+257>:     e8 c9 fa ff ff    call   0x8048368 <printf@plt>
   0x0804889f <+262>:     83 44 24 24 01    addl   $0x1,0x24(%esp)
   0x080488a4 <+267>:     83 7c 24 24 06    cmpl   $0x6,0x24(%esp)
   0x080488a9 <+272>:     7e d0    jle    0x804887b <main+226>
   0x080488ab <+274>:     8d 44 24 45    lea    0x45(%esp),%eax
---Type <return> to continue, or q <return> to quit---
   0x080488af <+278>:     89 04 24    mov    %eax,(%esp)
   0x080488b2 <+281>:     e8 a1 fa ff ff    call   0x8048358 <strlen@plt>
   0x080488b7 <+286>:     89 c3    mov    %eax,%ebx
   0x080488b9 <+288>:     8d 44 24 2a    lea    0x2a(%esp),%eax
   0x080488bd <+292>:     89 04 24    mov    %eax,(%esp)
   0x080488c0 <+295>:     e8 93 fa ff ff    call   0x8048358 <strlen@plt>
   0x080488c5 <+300>:     89 5c 24 0c    mov    %ebx,0xc(%esp)
   0x080488c9 <+304>:     89 44 24 08    mov    %eax,0x8(%esp)
   0x080488cd <+308>:     8d 44 24 45    lea    0x45(%esp),%eax
   0x080488d1 <+312>:     89 44 24 04    mov    %eax,0x4(%esp)
   0x080488d5 <+316>:     8d 44 24 2a    lea    0x2a(%esp),%eax
   0x080488d9 <+320>:     89 04 24    mov    %eax,(%esp)
   0x080488dc <+323>:     e8 e7 fd ff ff    call   0x80486c8 <kmp>
   0x080488e1 <+328>:     89 44 24 24    mov    %eax,0x24(%esp)
   0x080488e5 <+332>:     b8 af 8a 04 08    mov    $0x8048aaf,%eax
   0x080488ea <+337>:     8b 54 24 24    mov    0x24(%esp),%edx
   0x080488ee <+341>:     89 54 24 04    mov    %edx,0x4(%esp)
   0x080488f2 <+345>:     89 04 24    mov    %eax,(%esp)
   0x080488f5 <+348>:     e8 6e fa ff ff    call   0x8048368 <printf@plt>
   0x080488fa <+353>:     8d 44 24 45    lea    0x45(%esp),%eax
   0x080488fe <+357>:     89 04 24    mov    %eax,(%esp)
---Type <return> to continue, or q <return> to quit---
   0x08048901 <+360>:     e8 52 fa ff ff    call   0x8048358 <strlen@plt>
   0x08048906 <+365>:     89 44 24 04    mov    %eax,0x4(%esp)
   0x0804890a <+369>:     8d 44 24 45    lea    0x45(%esp),%eax
   0x0804890e <+373>:     89 04 24    mov    %eax,(%esp)
   0x08048911 <+376>:     e8 98 fc ff ff    call   0x80485ae <caculate_jump_enhance>
   0x08048916 <+381>:     c7 44 24 24 00 00 00 00    movl   $0x0,0x24(%esp)
   0x0804891e <+389>:     eb 29    jmp    0x8048949 <main+432>
   0x08048920 <+391>:     8b 44 24 24    mov    0x24(%esp),%eax
   0x08048924 <+395>:     8b 14 85 40 a0 04 08    mov    0x804a040(,%eax,4),%edx
   0x0804892b <+402>:     b8 b5 8a 04 08    mov    $0x8048ab5,%eax
   0x08048930 <+407>:     89 54 24 08    mov    %edx,0x8(%esp)
   0x08048934 <+411>:     8b 54 24 24    mov    0x24(%esp),%edx
   0x08048938 <+415>:     89 54 24 04    mov    %edx,0x4(%esp)
   0x0804893c <+419>:     89 04 24    mov    %eax,(%esp)
   0x0804893f <+422>:     e8 24 fa ff ff    call   0x8048368 <printf@plt>
   0x08048944 <+427>:     83 44 24 24 01    addl   $0x1,0x24(%esp)
   0x08048949 <+432>:     83 7c 24 24 06    cmpl   $0x6,0x24(%esp)
   0x0804894e <+437>:     7e d0    jle    0x8048920 <main+391>
   0x08048950 <+439>:     8d 44 24 45    lea    0x45(%esp),%eax
   0x08048954 <+443>:     89 04 24    mov    %eax,(%esp)
   0x08048957 <+446>:     e8 fc f9 ff ff    call   0x8048358 <strlen@plt>
---Type <return> to continue, or q <return> to quit---
   0x0804895c <+451>:     89 c3    mov    %eax,%ebx
   0x0804895e <+453>:     8d 44 24 2a    lea    0x2a(%esp),%eax
   0x08048962 <+457>:     89 04 24    mov    %eax,(%esp)
   0x08048965 <+460>:     e8 ee f9 ff ff    call   0x8048358 <strlen@plt>
   0x0804896a <+465>:     89 5c 24 0c    mov    %ebx,0xc(%esp)
   0x0804896e <+469>:     89 44 24 08    mov    %eax,0x8(%esp)
   0x08048972 <+473>:     8d 44 24 45    lea    0x45(%esp),%eax
   0x08048976 <+477>:     89 44 24 04    mov    %eax,0x4(%esp)
   0x0804897a <+481>:     8d 44 24 2a    lea    0x2a(%esp),%eax
   0x0804897e <+485>:     89 04 24    mov    %eax,(%esp)
   0x08048981 <+488>:     e8 42 fd ff ff    call   0x80486c8 <kmp>
   0x08048986 <+493>:     89 44 24 24    mov    %eax,0x24(%esp)
   0x0804898a <+497>:     b8 af 8a 04 08    mov    $0x8048aaf,%eax
   0x0804898f <+502>:     8b 54 24 24    mov    0x24(%esp),%edx
   0x08048993 <+506>:     89 54 24 04    mov    %edx,0x4(%esp)
   0x08048997 <+510>:     89 04 24    mov    %eax,(%esp)
   0x0804899a <+513>:     e8 c9 f9 ff ff    call   0x8048368 <printf@plt>
   0x0804899f <+518>:     b8 00 00 00 00    mov    $0x0,%eax
   0x080489a4 <+523>:     8b 54 24 4c    mov    0x4c(%esp),%edx
   0x080489a8 <+527>:     65 33 15 14 00 00 00    xor    %gs:0x14,%edx
   0x080489af <+534>:     74 05    je     0x80489b6 <main+541>
---Type <return> to continue, or q <return> to quit---
   0x080489b1 <+536>:     e8 c2 f9 ff ff    call   0x8048378 <__stack_chk_fail@plt>
   0x080489b6 <+541>:     83 c4 5c    add    $0x5c,%esp
   0x080489b9 <+544>:     5b    pop    %ebx
   0x080489ba <+545>:     89 ec    mov    %ebp,%esp
   0x080489bc <+547>:     5d    pop    %ebp
   0x080489bd <+548>:     c3    ret    
End of assembler dump.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值