LS,我没有完全运行,只是通过反汇编找到的地址……
回复 11# 的帖子
那你怎么确定这个地址 0x00404010 就是分配给这个全局变量的呢 ?
#include <stdio.h> #include <stdlib.h> int g = 10; int main(void) { int l = 20; printf("%d, %p\n", g, &g); printf("%d, %p\n", l, &l); return 0; }
10, 00402000 20, 0022FF44 Hit any key to close this window...
.file "tt.c" .globl _g .data .align 4 _g: .long 10 .def ___main; .scl 2; .type 32; .endef .section .rdata,"dr" LC0: .ascii "%d, %p\12\0" .text .p2align 4,,15 .globl _main .def _main; .scl 2; .type 32; .endef _main: pushl %ebp movl $16, %eax movl %esp, %ebp subl $24, %esp andl $-16, %esp call __alloca call ___main movl $20, -4(%ebp) movl $_g, %eax movl %eax, 8(%esp) movl _g, %eax movl $LC0, (%esp) movl %eax, 4(%esp) call _printf movl $LC0, (%esp) leal -4(%ebp), %eax movl %eax, 8(%esp) movl -4(%ebp), %eax movl %eax, 4(%esp) call _printf leave xorl %eax, %eax ret .def _printf; .scl 2; .type 32; .endef
; Listing generated by Microsoft (R) Optimizing Compiler Version 14.00.50727.762 TITLE C:\Users\StarWing\Desktop\dev\tt.c .686P .XMM include listing.inc .model flat INCLUDELIB LIBCMT INCLUDELIB OLDNAMES PUBLIC _g _DATA SEGMENT _g DD 0aH $SG3495 DB '%d, %p', 0aH, 00H $SG3496 DB '%d, %p', 0aH, 00H _DATA ENDS PUBLIC _main EXTRN _printf:PROC ; Function compile flags: /Odtp ; File c:\users\starwing\desktop\dev\tt.c _TEXT SEGMENT _l$ = -4 ; size = 4 _main PROC ; 7 : { push ebp mov ebp, esp push ecx ; 8 : int l = 20; mov DWORD PTR _l$[ebp], 20 ; 00000014H ; 9 : ; 10 : printf("%d, %p\n", g, &g); push OFFSET _g mov eax, DWORD PTR _g push eax push OFFSET $SG3495 call _printf add esp, 12 ; 0000000cH ; 11 : printf("%d, %p\n", l, &l); lea ecx, DWORD PTR _l$[ebp] push ecx mov edx, DWORD PTR _l$[ebp] push edx push OFFSET $SG3496 call _printf add esp, 12 ; 0000000cH ; 12 : ; 13 : return 0; xor eax, eax ; 14 : } mov esp, ebp pop ebp ret 0 _main ENDP _TEXT ENDS END