返回介绍

9.2 Local variables example

发布于 2025-02-22 14:00:43 字数 1760 浏览 0 评论 0 收藏 0

让我们修改一下例子:

Listing 9.2: 局部变量

#!bash
void main()
{
    int sum, product; // now variables are here

    f1(123, 456, &sum, &product);
    printf ("sum=%d, product=%d
", sum, product);
};

f1() 函数代码没有改变。仅仅 main() 代码作了修改。

Listing 9.3: Optimizing MSVC 2010 (/Ox /Ob0)

#!bash
_product$ = -8              ; size = 4
_sum$ = -4                  ; size = 4
_main   PROC
; Line 10
        sub     esp, 8
; Line 13
        lea     eax, DWORD PTR _product$[esp+8]
        push    eax
        lea     ecx, DWORD PTR _sum$[esp+12]
        push    ecx
        push    456         ; 000001c8H
        push    123         ; 0000007bH
        call    _f1
; Line 14
        mov     edx, DWORD PTR _product$[esp+24]
        mov     eax, DWORD PTR _sum$[esp+24]
        push    edx
        push    eax
        push    OFFSET $SG2803
        call    DWORD PTR __imp__printf
; Line 15
        xor     eax, eax
        add     esp, 36     ; 00000024H
        ret     0

我们在 OD 中查看,局部变量地址在堆栈中是 0x35FCF4 和 0x35FCF8。我们可以看到是如何圧栈的 fig. 9.6.

f1() 开始的时候,随机栈地址为 0x35FCF4 和 0x35FCF8 fig. 9.7.

f1() 完成时结果 0xDB18 和 0x243 存放在地址 0x35FCF4 和 0x35FCF8。

enter image description here

Figure 9.6: OllyDbg: 局部变量地址被圧栈

enter image description here

Figure 9.7: OllyDbg: f1()starting

enter image description here

Figure 9.8: OllyDbg: f1()finished

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文