assembly system call non-effective

倖福魔咒の 提交于 2019-12-20 07:47:09

问题


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 ?


回答1:


A quick fix of your code:

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...

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.



来源:https://stackoverflow.com/questions/40041445/assembly-system-call-non-effective

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!