汇编系统调用无效 [英] assembly system call non-effective
问题描述
我想用以下内容打印 AAAA:
I want to print AAAA with the following:
BITS 32;
;write;
push 0x41414141;
pop ecx ;
mov eax, 4 ; write is syscall 4 for Ubuntu 32-bit
mov ebx, 1 ; stdout
mov edx, 4 ;
int 0x80 ;
;exit;
mov eax, 1 ;
mov ebx, 0 ;
int 0x80 ;
然而,一旦组装和链接此代码只退出,没有错误,有什么问题?
Yet, once assembled and linked this code only exits, no errors, what is wrong ?
推荐答案
快速修复您的代码:
push 0x41414141 ; put 'AAAA' into stack memory
mov ecx,esp ; pointer to the 'AAAA'
mov eax, 4 ; write is syscall 4 for 32-bit Linux
mov ebx, 1 ; stdout
mov edx, 4
int 0x80
add esp,4 ; restore stack
没有解释,因为你应该首先检查我在评论中提出的问题,然后修复将是显而易见的,或者你将不得不询问一些你不理解的特定问题......
No explanation, as you should first check what I did ask in comment, then the fix will be either obvious, or you will have to ask about something particular you don't understand...
如果您使用 strace ./my_program
运行原始代码,您会看到 write()
返回 -EFAULT,因为您传递了一个错误地址.始终使用 strace
来调试进行系统调用且行为不符合预期的程序.
If you run your original code with strace ./my_program
, you'd see write()
return -EFAULT because you passed a bad address. Always use strace
to debug programs that make syscalls and don't behave the way you expected.
这篇关于汇编系统调用无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!