# ******************************************************************************** # server.s (Server (daemon)) # by Broken Sword [HI-TECH] # (for Linux based on Intel x86 only) # brokensword@mail.ru # http://subscribe.ru/catalog/comp.soft.prog.intelpm # rusfaq.ru # wasm.ru # Compile Instructions: # -------------------------------------------------------------------------------- # as lab6S.s # ld --strip-all -o lab6S a.out # ******************************************************************************** # ******************************************************************************** .include "syscalls.inc" .include "def.inc" .text .globl _start _start: movl $SYS_fork,%EAX int $0x80 # create 1st child process test %EAX,%EAX jz _cont1 xorl %EBX,%EBX # EBX=status code xorl %EAX,%EAX # incl %EAX # SYS_exit int $0x80 # exit parent _cont1: movl $SYS_setsid,%EAX int $0x80 movl $1,%EBX # SIGHUP movl $1,%ECX # SIG_IGN movl $SYS_signal,%EAX int $0x80 # ignore SIGHUP movl $SYS_fork,%EAX int $0x80 # create 2nd child process test %EAX,%EAX jz _cont2 xorl %EBX,%EBX # EBX=status code xorl %EAX,%EAX # incl %EAX # SYS_exit int $0x80 # exit 1st child _cont2: pushl $0 # protocol pushl $SOCK_STREAM # type pushl $AF_INET # domain movl %ESP,%ECX movl $SYS_SOCKET,%EBX movl $SYS_socketcall,%EAX int $0x80 addl $0xC,%ESP movl %EAX,(sockfd) pushl $0x10 pushl $sockaddr_in pushl %EAX # sockfd movl %ESP,%ECX movl $SYS_BIND,%EBX movl $SYS_socketcall,%EAX int $0x80 addl $0xC,%ESP pushl $0 # backlog movl (sockfd),%EAX pushl %EAX movl %ESP,%ECX movl $SYS_LISTEN,%EBX movl $SYS_socketcall,%EAX int $0x80 addl $0x8,%ESP _wait_next_client: pushl $0 # addrlen pushl $0 # cliaddr movl (sockfd),%EAX pushl %EAX # sockfd movl %ESP,%ECX movl $SYS_ACCEPT,%EBX movl $SYS_socketcall,%EAX int $0x80 addl $0xC,%ESP movl %EAX,(connfd) movl $SYS_fork,%EAX int $0x80 # create child process test %EAX,%EAX jnz _wait_next_client _next_plain_text: movl (connfd),%EBX movl $buf,%ECX # ECX->buf movl $1024,%EDX # 1024 bytes movl $SYS_read,%EAX int $0x80 # wait plain_text movl $buf,%ESI movl %ESI,%EDI movl %EAX,%ECX movl %EAX,%EDX _encrypt: lodsb cmp $0x41,%AL # A jb _next cmp $0x5A,%AL # Z ja _maybe_small incb %AL incb %AL # encryption ;) cmp $0x5A,%AL jle _next sub $26,%AL _maybe_small: cmp $0x61,%AL # a jb _next cmp $0x7A,%AL # z ja _next incb %AL incb %AL # encryption ;) cmp $0x7A,%AL jle _next sub $26,%AL _next: stosb loop _encrypt movl (connfd),%EBX movl $buf,%ECX # ECX->chiper_text movl $SYS_write,%EAX int $0x80 # send plain_text jmp _next_plain_text # ******************************************************************************** .data sockfd: .long 0 connfd: .long 0 sockaddr_in: sin_family: .word AF_INET sin_port: .word 0x3930 # port:12345 sin_addr: .long 0 # INADDR_ANY buf: # ********************************************************************************