-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.asm
96 lines (80 loc) · 1.04 KB
/
server.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
format ELF64
public _start
socket = 41
bind = 49
listen = 50
accept = 43
read = 0
write = 1
open = 2
exit = 60
close = 3
af_inet = 2
sock_stream = 1
o_rdonly = 0
section '.text' executable
_start:
mov rdi, af_inet
mov rsi, sock_stream
mov rdx, 0
mov rax, socket
syscall
mov r12, rax ; socket fd
mov rdi, r12
mov rsi, address
mov rdx, 16
mov rax, bind
syscall
mov rdi, r12
mov rsi, 10
mov rax, listen
syscall
accept_loop:
mov rdi, r12
mov rsi, 0
mov rdx, 0
mov rax, accept
syscall
mov r13, rax ; client socket fd
mov rdi, r13
mov rsi, buffer
mov rdx, 256
mov rax, read
syscall
mov rdi, path
mov rsi, o_rdonly
mov rax, open
syscall
mov r14, rax ; save index.html fd
mov rdi, rax
mov rsi, buffer2
mov rdx, 256
mov rax, read
syscall
mov rdi, r13
mov rsi, buffer2
mov rdx, 256
mov rax, write
syscall
mov rdi, r13
mov rax, close
syscall
mov rdi, r14
mov rax, close
syscall
jmp accept_loop
mov rdi, 0
mov rax, exit
syscall
section '.data' writeable
address:
dw af_inet
dw 0x901f
dd 0
dq 0
buffer:
db 256 dup 0
buffer2:
db 256 dup 0
path:
db 'index.html', 0