“粉碎堆栈中的乐趣和利润”中的内存地址计算

时间:2012-04-15 07:40:30

标签: c memory assembly stack-overflow

我正在阅读“Smashing The Stack For Fun And Profit

在“缓冲区溢出”一节中,我看到了:

    0x8000490 <main>:       pushl  %ebp
    0x8000491 <main+1>:     movl   %esp,%ebp
    0x8000493 <main+3>:     subl   $0x4,%esp
    0x8000496 <main+6>:     movl   $0x0,0xfffffffc(%ebp)
    0x800049d <main+13>:    pushl  $0x3
    0x800049f <main+15>:    pushl  $0x2
    0x80004a1 <main+17>:    pushl  $0x1
    0x80004a3 <main+19>:    call   0x8000470 <function>
    0x80004a8 <main+24>:    addl   $0xc,%esp
    0x80004ab <main+27>:    movl   $0x1,0xfffffffc(%ebp)
    0x80004b2 <main+34>:    movl   0xfffffffc(%ebp),%eax
    0x80004b5 <main+37>:    pushl  %eax
    0x80004b6 <main+38>:    pushl  $0x80004f8
    0x80004bb <main+43>:    call   0x8000378 <printf>
    0x80004c0 <main+48>:    addl   $0x8,%esp
    0x80004c3 <main+51>:    movl   %ebp,%esp
    0x80004c5 <main+53>:    popl   %ebp
    0x80004c6 <main+54>:    ret
    0x80004c7 <main+55>:    nop

“我们可以看到,当调用function()时,RET将是0x8004a8,而我们 想跳过0x80004ab的任务。我们想要的下一条指令 执行是在0x8004b2。一个小数学告诉我们距离是8 字节“。

我在这里得不到答案。 0x80004b2 - 0x80004ab = 7,对吗?为什么作者说它是8? 我在这里错过任何一点吗?

1 个答案:

答案 0 :(得分:5)

我也想知道这一点。我只能认为aleph1从未真正测试过该代码,因为我确定偏移应该是10(0x80004b2 - 0x80004a8)。我还发现这篇文章的版本将原始值更正为10。

http://www.cs.wright.edu/~tkprasad/courses/cs781/alephOne.html