我正在查看我的一個類的練習考試,我只是不明白問題的某些方面,所以也許你會幫助我(可能真的很容易,如果你知道x86 )。在x86彙編代碼中追蹤堆棧
所以它在這裏的問題8: http://www.coe.utah.edu/~cs4400/schedule/exam3.F10.pdf
而解決的辦法是在這裏: http://www.coe.utah.edu/~cs4400/schedule/exam3_solns.F10.pdf \
我只是不明白的值是如何在溶液中獲得。讓我跑通過I如何解讀爲此堆棧:
08048510 <callfoo>:
08048510: 55 pushl %ebp # old frame pointer is pushed to the stack
08048511: 89 e5 movl %esp,%ebp # frame pointer = stack pointer
08048513: 83 ec 08 subl $0x8,%esp # allocates 8 bytes for stack
08048516: 83 c4 f4 addl $0xfffffff4,%esp # this I believe allocates 4 bytes to the stack??
08048519: 68 9c 85 04 08 pushl $0x804859c # push string address
0804851e: e8 d1 ff ff ff call 80484f4 <foo> # call foo, which takes the string address as param1
08048523: 89 ec movl %ebp,%esp # (after foo) does similar to return out of function
08048525: 5d popl %ebp
08048526: c3 ret
080484f4 <foo>:
080484f4: 55 pushl %ebp # push old frame pointer
080484f5: 89 e5 movl %esp,%ebp # frame pointer = stack pointer
080484f7: 83 ec 18 subl $0x18,%esp # allocate 24 bytes
080484fa: 8b 45 08 movl 0x8(%ebp),%eax # moves the param1 (string pointer) into eax
080484fd: 83 c4 f8 addl $0xfffffff8,%esp # allocates 8 more bytes (?)
08048500: 50 pushl %eax # push x # pushes param1 to stack
08048501: 8d 45 fc leal 0xfffffffc(%ebp),%eax # adds 12 to the frame pointer, puts it in eax(?)
08048504: 50 pushl %eax # push buf (which apparently is located in eax and 0xc(%ebp)
08048505: e8 ba fe ff ff call 80483c4 <strcpy> # copies the string from param1 into buf
0804850a: 89 ec movl %ebp,%esp # puts stack pointer into ebp
0804850c: 5d popl %ebp # pops ebp (returns back to other function)
0804850d: c3 ret
(一),所以這樣做之後,我想我可以有點看如何BUF [0] = 0x64636261
。 char是一個字節,並且是小端,也可以這樣讀取:buf [0] = 0x61626364
(儘管我不知道我的教授是否會接受該答案)。 但是,我不明白buf [2]如何等於0x08040069
或0x69000408
。它有最後一個字符,然後是空字符,但04
和08
是什麼? (b)我不知道如何獲得(b)或(c)。我甚至可以在哪裏獲得esp
的值是要找出在foo
的開始處放入ebp
的值?總的來說,我只是困惑於最後兩個......幫助? :(
提示:Ctrl-F 0804;) – Diadistis
對,我得到了那個連接,我不認爲我會假設buf會100%包含地址的開始部分的內存。因此我不會在測試中做這件事。 (b)(c)就此而言更令人困惑,我只是不知道他們在哪裏得到這些地址。 :/ – fvertk
當foo在0804851e被調用時,下一條指令(返回地址)被壓入堆棧(08048523)。 Foo將8個字節分配給堆棧,然後寫入10個字節,從而部分覆蓋堆棧上的返回地址。 – Diadistis