Note that there are some explanatory texts on larger screens.

plurals
  1. PODissassembling a C function in GDB. Clarification on GAS Assembly instructions
    primarykey
    data
    text
    <p>I have a C function written here ( It does have a buffer overflow vulnerability )</p> <pre><code>void func(char *str) { char buffer[12]; int a=9; strcpy(buffer,str); } </code></pre> <p>Its assembly in gdb translates to</p> <pre><code>|0x4005b4 &lt;func&gt; push %rbp |0x4005b5 &lt;func+1&gt; mov %rsp,%rbp |0x4005b8 &lt;func+4&gt; sub $0x40,%rsp |0x4005bc &lt;func+8&gt; mov %rdi,-0x38(%rbp) |0x4005c0 &lt;func+12&gt; mov %fs:0x28,%rax |0x4005c9 &lt;func+21&gt; mov %rax,-0x8(%rbp) |0x4005cd &lt;func+25&gt; xor %eax,%eax |0x4005cf &lt;func+27&gt; movl $0x9,-0x24(%rbp) |0x4005d6 &lt;func+34&gt; mov -0x38(%rbp),%rdx |0x4005da &lt;func+38&gt; lea -0x20(%rbp),%rax |0x4005de &lt;func+42&gt; mov %rdx,%rsi |0x4005e1 &lt;func+45&gt; mov %rax,%rdi |0x4005e4 &lt;func+48&gt; callq 0x400490 &lt;strcpy@plt&gt; |0x4005e9 &lt;func+53&gt; mov -0x8(%rbp),%rax |0x4005ed &lt;func+57&gt; xor %fs:0x28,%rax |0x4005f6 &lt;func+66&gt; je 0x4005fd &lt;func+73&gt; |0x4005f8 &lt;func+68&gt; callq 0x4004a0 &lt;__stack_chk_fail@plt&gt; |0x4005fd &lt;func+73&gt; leaveq |0x4005fe &lt;func+74&gt; retq </code></pre> <p><code>rdi</code> contains the address of the original character array passed to the function.</p> <p>1.In <code>func+8</code>, is moving this rdi value to -0x38(rbp) to save the value in local variable str of the function or does it have any other implications?</p> <p>2.What does the instruction at <code>func+8</code> accomplish? Is there anyway in gdb or in linux to view the contents of the <code>fs segment</code>?</p> <p>3.What do the instructions <code>func+12</code> to <code>func+25</code> do? </p> <p>EDIT: I compiled this in gcc 4.6.3 with -O0 </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload