组装系统调用无效 [英] 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屋!