format PE CONSOLE entry start include 'win32a.inc' PREFIX equ "KT315: " section '' readable writeable align 1 addr: db '127.0.0.1', 0 starts: db PREFIX, 'Server started on 127.0.0.1:80!', 0x0A, 0 errors: db PREFIX, 'Something went wrong!', 0x0A, 0 closed: db PREFIX, 'Server closed!', 0x0A, 0 conn: db PREFIX, 'Someone connected!', 0x0A, 0 s_format: db '%s', 0 server: db "HTTP/1.1 200 OK", 0x0D, 0x0A,\ "Content-Type: text/html; charset=UTF-8", 0x0D, 0x0A, 0x0D, 0x0A,\ "!!!!ASSEMBLY POWER!!!!",\ "

ASSEMBLY is a REAL POWER!

", 0x0D, 0x0A, 0 .sizeof = $ - server buf: db 1024 dup(0) align 4 svr_addr sockaddr_in AF_INET, 0x5000, 0 .sizeof = $ - svr_addr .size dd $ - svr_addr cli_addr sockaddr_in AF_INET, 0x5000 .sizeof = $ - cli_addr .size dd $ - cli_addr wsa: WSADATA section 'KT315' executable readable start: push addr call dword[inet_addr] mov dword[svr_addr.sin_addr], eax push wsa push 0202 call dword[WSAStartup] test eax, eax jnz .errors push 0 push SOCK_STREAM push AF_INET call dword[socket] test eax, eax jle .errors mov esi, eax push svr_addr.sizeof push svr_addr push esi call dword[bind] test eax, eax jnz .errors push 5 push esi call dword[listen] push starts call dword[printf] add esp, 4 @@: push cli_addr.size push cli_addr push esi call dword[accept] mov edi, eax test edi, edi jg .accepted push errors push s_format call dword[printf] add esp, 4*2 jmp .errors .accepted: push conn push s_format call dword[printf] add esp, 4*2 push 0 push 1024 push buf push edi call dword[recv] push buf push s_format call dword[printf] add esp, 4*2 push 0 push server.sizeof push server push edi call dword[send] push edi call dword[closesocket] jmp @b .errors: push errors push s_format call dword[printf] add esp, 4*2 .exit: push esi call dword[closesocket] call dword[WSACleanup] push closed push s_format call dword[printf] add esp, 4*2 ret section 'KT315' import readable writeable library kernel, 'kernel32.dll',\ msvcrt, 'msvcrt.dll',\ ws2, 'ws2_32.dll' import kernel,\ ExitProcess, 'ExitProcess' import msvcrt,\ printf, 'printf' import ws2,\ WSAStartup, 'WSAStartup',\ WSACleanup, 'WSACleanup',\ setsockopt, 'setsockopt',\ closesocket, 'closesocket',\ socket, 'socket',\ bind, 'bind',\ listen, 'listen',\ send, 'send',\ accept, 'accept',\ inet_addr, 'inet_addr',\ recv, 'recv'