pointers - 偏移 x86 程序集中的指针
问题描述
先编码,后问题。
这段代码有一个我正在调用file
的数据块,数据块是这样的:
filename
file_pointer
openas
然后,generateFile
我们有-20(%ebp)
which 是指向数据块中第一个元素的指针,或者-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), %ecx
movl %ecx, -8(%ebp)
movl -4(%ebp), %ecx
movl %ecx, -12(%ebp)
movl 12(%ebp), %ecx
movl %ecx, -16(%ebp)
leal -8(%ebp), %ecx
movl %ecx, -20(%ebp)
movl -20(%ebp), %ecx
movl %ecx, %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, %ecx
movl %ecx, -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, %ecx
movl %ecx, %eax
leave
ret
问题不是预期的输出:
hello.txt
r
相反,我得到:
hello.txt
-852052
我尝试了不同的东西,例如
4(%ebx)
当我得到一个价值,但它不起作用。
我怎样才能解决这个问题?
解决方案
推荐阅读
- javascript - 我想将两个 Javascript 数组与 Lodash(不是 concat)结合起来
- debugging - 您如何运行预先编写的 lldb 命令?
- elasticsearch - Kibana DataTable Visualization 在有模板时不显示 message.keyword
- python - python - 使用字符串读取列表并将其转换为 int() 但保持特定格式
- linq - LINQ 在 Lambda ex 中加入多表
- css - 用于 chrome 但不适用于 safari 的按钮的 CSS
- html - 如何在 XPath 中跳过他的一些父母来选择子元素
- laravel - 是否可以使用 Eloquent 和两个 hasMany 关系计算一个查询中的平均值
- c# - C# 许多长时间运行的任务并行
- javascript - 如何通过使用时刻减去两个日期来获得总小时数?