- 论坛徽章:
- 0
|
回复 #6 cjaizss 的帖子
- [root@localhost muyin]# gcc -S testesp.c -o testesp.S
- testesp.c: 在函数 ‘main’ 中:
- testesp.c:10: 警告:隐式声明与内建函数 ‘printf’ 不兼容
- [root@localhost muyin]# cat testesp.S
- .file "testesp.c"
- .text
- .globl get_esp
- .type get_esp, @function
- get_esp:
- pushl %ebp
- movl %esp, %ebp
- #APP
- movl %esp,%eax
- #NO_APP
- popl %ebp
- ret
- .size get_esp, .-get_esp
- .section .rodata
- .LC0:
- .string "%x\n"
- .text
- .globl main
- .type main, @function
- main:
- leal 4(%esp), %ecx
- andl $-16, %esp
- pushl -4(%ecx)
- pushl %ebp
- movl %esp, %ebp
- pushl %ecx
- subl $36, %esp
- call get_esp
- movl %eax, -8(%ebp)
- movl -8(%ebp), %eax
- movl %eax, 4(%esp)
- movl $.LC0, (%esp)
- call printf
- addl $36, %esp
- popl %ecx
- popl %ebp
- leal -4(%ecx), %esp
- ret
- .size main, .-main
- .ident "GCC: (GNU) 4.1.2 20070925 (Red Hat 4.1.2-27)"
- .section .note.GNU-stack,"",@progbits
复制代码
我查了一下#APP和#NOAPP啥意思,看样子是没有多大关系的:
The “#APP” and “#NO_APP” parts are instructions to the assembler that briefly put it into
normal operating mode, as opposed to the special high-speed “compiler output” mode that
turns off every feature that the compiler doesn’t use as well as a lot of error-checking. For
our purposes, it’s convenient becuase it highlights the part of the code we’re interested in.
版主的意思是这样获取的ESP指针应该是实际想要获得的减少了4?因为get_sp()是在将EBP压栈后的结果,因此少了4个数?但是我用gdb调试的结果确和单独执行差了0x50啊?
[ 本帖最后由 ruger 于 2008-8-23 16:36 编辑 ] |
|