verbal
August 5th, 2008, 08:22 PM
Hello,
I am writing a little network program in assembly and i have the following problem.
I am using linux x86 and i want to call the socket system call which number i found to be 102 (or 0x66). As i know the number of the system call is stored in %eax and the arguments are stored in the %ebx, %ecx and %edx registers. so i wrote the following code to call it:
movl $0x66, %eax
movl $0x2, %ebx // AF_INET = 2
movl $0x1, %ecx // SOCK_STREAM = 1
xor %edx, %edx // IPPROTO_IP = 0
int $0x80
but when i run strace i get the following output:
ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
bind(0, NULL, 0) = -1 EFAULT (Bad address)
_exit(10) // i call exit() later in the assembly code
I did some search on the net and i found the following code to call socket() which works perfectly:
xor %eax,%eax // eax = 0
mov %eax,%ebx // ebx = 0
push %eax // push eax
inc %eax // eax = 1
push %eax // push eax
inc %eax // eax = 2
push %eax // push eax
mov %esp,%ecx // ecx = esp
mov $0x66,%al // al = 102
mov %eax,%edi // edi = eax
inc %ebx // ebx = 1
int $0x80
(The comments are written by me)
I don't understand some commands here like the one moving %esp on %ecx or pushing all the arguments on the stack. Can someone explain a little better this code to tell me what have i done wrong?
Thanks in advance.
I am writing a little network program in assembly and i have the following problem.
I am using linux x86 and i want to call the socket system call which number i found to be 102 (or 0x66). As i know the number of the system call is stored in %eax and the arguments are stored in the %ebx, %ecx and %edx registers. so i wrote the following code to call it:
movl $0x66, %eax
movl $0x2, %ebx // AF_INET = 2
movl $0x1, %ecx // SOCK_STREAM = 1
xor %edx, %edx // IPPROTO_IP = 0
int $0x80
but when i run strace i get the following output:
ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
bind(0, NULL, 0) = -1 EFAULT (Bad address)
_exit(10) // i call exit() later in the assembly code
I did some search on the net and i found the following code to call socket() which works perfectly:
xor %eax,%eax // eax = 0
mov %eax,%ebx // ebx = 0
push %eax // push eax
inc %eax // eax = 1
push %eax // push eax
inc %eax // eax = 2
push %eax // push eax
mov %esp,%ecx // ecx = esp
mov $0x66,%al // al = 102
mov %eax,%edi // edi = eax
inc %ebx // ebx = 1
int $0x80
(The comments are written by me)
I don't understand some commands here like the one moving %esp on %ecx or pushing all the arguments on the stack. Can someone explain a little better this code to tell me what have i done wrong?
Thanks in advance.