我的問候&向所有人致意。我有一個C程序,基本上寫測試緩衝區溢出。這條指令是做什麼的?: - mov%gs:0x14,%eax
#include<stdio.h>
void display()
{
char buff[8];
gets(buff);
puts(buff);
}
main()
{
display();
return(0);
}
現在我使用GDB反彙編它的顯示和主要部分。該代碼: - 彙編代碼的功能主要
轉儲:
0x080484ae <+0>: push %ebp # saving ebp to stack
0x080484af <+1>: mov %esp,%ebp # saving esp in ebp
0x080484b1 <+3>: call 0x8048474 <display> # calling display function
0x080484b6 <+8>: mov $0x0,%eax # move 0 into eax , but WHY ????
0x080484bb <+13>: pop %ebp # remove ebp from stack
0x080484bc <+14>: ret # return
彙編轉儲結束。
轉儲的彙編代碼功能顯示:
0x08048474 <+0>: push %ebp #saves ebp to stack
0x08048475 <+1>: mov %esp,%ebp # saves esp to ebp
0x08048477 <+3>: sub $0x10,%esp # making 16 bytes space in stack
0x0804847a <+6>: mov %gs:0x14,%eax # what does it mean ????
0x08048480 <+12>: mov %eax,-0x4(%ebp) # move eax contents to 4 bytes lower in stack
0x08048483 <+15>: xor %eax,%eax # xor eax with itself (but WHY??)
0x08048485 <+17>: lea -0xc(%ebp),%eax #Load effective address of 12 bytes
lower placed value (WHY????)
0x08048488 <+20>: mov %eax,(%esp) #make esp point to the address inside of eax
0x0804848b <+23>: call 0x8048374 <[email protected]> # calling get, what is "@plt" ????
0x08048490 <+28>: lea -0xc(%ebp),%eax # LEA of 12 bytes lower to eax
0x08048493 <+31>: mov %eax,(%esp) # make esp point to eax contained address
0x08048496 <+34>: call 0x80483a4 <[email protected]> # again what is "@plt" ????
0x0804849b <+39>: mov -0x4(%ebp),%eax # move (ebp - 4) location's contents to eax
0x0804849e <+42>: xor %gs:0x14,%eax # # again what is this ????
0x080484a5 <+49>: je 0x80484ac <display+56> # Not known to me
0x080484a7 <+51>: call 0x8048394 <[email protected]> # not known to me
0x080484ac <+56>: leave # a new instruction, not known to me
0x080484ad <+57>: ret # return to MAIN's next instruction
彙編轉儲結束。
所以人們,你應該考慮我的功課。休息所有的代碼是我知道的,除了幾行。我已經包括一個大「爲什麼????」以及每行前面的評論中的更多問題。對我來說第一個障礙是「mov%gs:0x14,%eax」指令,我不能在這個指令之後做出流程圖。有人告訴我,這幾個指令是什麼意思,並在程序中做什麼?謝謝...
主要返回0,這就是爲什麼'mov $ 0x0,%eax'。 – Qiau
''xor%eax,%eax'是一種清除%eax的高效方法,因爲xor-ing相同的值總是會產生0. – Qiau
'gs:0x14'的操作看起來像[stack canary](http:///en.wikipedia.org/wiki/Stack_buffer_overflow#Stack_canaries)。 'xor%eax,%eax'只是將'eax'設置爲'0'的一種方法。 'lea -0xc(%ebp),%eax'將'buff'的地址加載到'eax'中,所以它可以傳入'gets/puts'。 – DCoder