您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在64位Linux上使用中断0x80

在64位Linux上使用中断0x80

显然,您编写了64位程序,并使用了“ int 0x80”指令。但是,“ int 0x80”仅在32位程序中正常工作。

堆栈的地址处于32位程序无法访问的范围内。因此,很有可能“ int 0x80”风格的系统调用不允许访问该存储区。

解决此问题,有两种可能性:

32位代码

mov eax,4    ; In "int 0x80" style 4 means: write
mov ebx,1    ; ... and the first arg. is stored in ebx
mov ecx,esp  ; ... and the second arg. is stored in ecx
mov edx,1    ; ... and the third arg. is stored in edx
int 0x80

64位代码

mov rax,1    ; In "syscall" style 1 means: write
mov rdi,1    ; ... and the first arg. is stored in rdi (not rbx)
mov rsi,rsp  ; ... and the second arg. is stored in rsi (not rcx)
mov rdx,1    ; ... and the third arg. is stored in rdx
syscall

背景资料:

“ int 0x80”适用于32位程序。从64位程序调用时,其行为与从32位程序中调用(使用32位调用约定)时的行为相同。

这也意味着“ int 0x80”的参数将在 传递,而64位寄存器的高32位将被忽略。

(我刚刚在64位Ubuntu 16.10上进行了测试。)

但是,这意味着您在使用“ int 0x80”时只能访问2 ^ 32以下(甚至低于2 ^ 31)的内存,因为您不能在32位寄存器中传递2 ^ 32以上的地址。

如果要写入的数据位于2 ^ 31以下的地址,则可以使用“ int 0x80”来写入数据。如果它位于2 ^ 32以上,则不能。堆栈(RSP)很可能位于2 ^ 32以上,因此您不能使用“ int 0x80”将数据写入堆栈。

因为您的程序很可能会使用2 ^ 32以上的内存,所以我写道:“ int 0x80不适用于64位程序。”

其他 2022/1/1 18:14:46 有651人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶