【问题标题】:Can't open file in Linux via 0x80无法通过 0x80 在 Linux 中打开文件
【发布时间】:2016-02-03 23:15:07
【问题描述】:

我正在尝试在 GAS 中实现一个简单的测试程序,该程序打开一个文件,向其中写入一些文本并退出。但是,“打开”的系统调用不断返回“-14”(“EFAULT - 错误地址”,如果我理解正确的话)。程序代码如下:

.intel_syntax noprefix
.section .data

textoutput:
    .asciz  "Hello world!"
pstr_end:
    .set lentext, pstr_end - textoutput
filetoopen:
    .asciz  "/tmp/tsttxt"

.section .text
.globl main

.func main
main:

mov eax, 5          #  open
mov ebx, filetoopen   # filname
mov ecx, 2            # flags: read and write
mov edx, 0700    # mode
int 0x80

mov ebx, eax      # <<< !!! eax here contains -14
mov eax, 4
mov ecx, textoutput
mov edx, lentext
int 0x80

mov eax, 1
mov ebx, 0
int 0x80

问题似乎出在filetoopen 字符串上(open 的联机帮助页说 EFAULT 表示pathname points outside your accessible address space。)filetoopen 是否在程序代码中正确声明?此错误的原因可能是什么?

谢谢。

【问题讨论】:

  • 如果您打算使用英特尔语法进行纯汇编编程,我会考虑使用 YASM 或 NASM。他们的英特尔语法“更好”。
  • @Jonathon 我喜欢 GAS,可以使用 Eclipse 来处理汇编程序(语法高亮、调试等)

标签: linux assembly x86 gnu-assembler


【解决方案1】:

在 intel 语法中,您需要使用 mov ebx, offset filetoopen。 如果您查看组装后的实际指令,您会发现这是一个内存负载:

80483e1:       8b 1d 2d 96 04 08       mov    ebx,DWORD PTR ds:0x804962d

那当然是错误的,你需要这里的地址。这也适用于该模式的其他两次出现。

【讨论】:

  • 谢谢。在这种情况下,“lea”似乎是正确的指令。
猜你喜欢
  • 2014-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-10
  • 1970-01-01
  • 1970-01-01
  • 2014-05-27
相关资源
最近更新 更多