如何解决在 x86 程序集中偏移指针
先编码,后问题。
filename
file_pointer
openas
然后,在 generateFile
中,我们有 -20(%ebp)
,它是指向数据块中第一个元素的指针,或 -8(%ebp)
。
我们在 main
内部调用这个函数并偏移指针以便能够打印出 filename
和 openas
。
.section .data
strLOCK0:
.asciz "r"
strLOCK1:
.asciz "hello.txt"
strLOCK2:
.asciz "%s\n"
strLOCK3:
.asciz "%d\n"
.section .text
.globl _start
_start:
call main
movl %eax,%ebx
movl $1,%eax
int $0x80
.type generateFile,@function
generateFile:
pushl %ebp
movl %esp,%ebp
subl $20,%esp
movl 12(%ebp),%ecx
pushl %ecx
movl 8(%ebp),%ecx
pushl %ecx
call fopen
movl %eax,%ecx
movl %ecx,-4(%ebp)
movl 8(%ebp),-8(%ebp)
movl -4(%ebp),-12(%ebp)
movl 12(%ebp),-16(%ebp)
leal -8(%ebp),-20(%ebp)
movl -20(%ebp),%eax
leave
ret
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
subl $4,%esp
movl $strLOCK0,%ecx
pushl %ecx
movl $strLOCK1,%ecx
pushl %ecx
call generateFile
movl %eax,-4(%ebp)
movl -4(%ebp),%ebx
movl (%ebx),%ecx
pushl %ecx
movl $strLOCK2,%ecx
pushl %ecx
call printf
popl %ebx
movl -4(%ebp),%ebx
movl -8(%ebx),%ecx
pushl %ecx
movl $strLOCK3,%ecx
pushl %ecx
call printf
popl %ebx
movl $0,%eax
leave
ret
问题不是预期的输出:
hello.txt
r
相反,我得到:
hello.txt
-852052
我尝试了不同的东西,例如
4(%ebx)
当我得到一个值,但它不起作用时。
我该如何解决这个问题?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。