2013-06-24 23:33:16 +04:00
|
|
|
server_parser:
|
|
|
|
|
|
|
|
; Commands are always 3 numbers and followed by a space
|
|
|
|
; If a server decides it needs multiline output,
|
|
|
|
; first lines will have a dash instead of space after numbers,
|
2013-07-10 00:19:08 +04:00
|
|
|
; thus they are simply ignored in this simple command parser.
|
2013-06-24 23:33:16 +04:00
|
|
|
|
|
|
|
cmp dword[s], "150 "
|
|
|
|
je data_ok
|
|
|
|
|
|
|
|
cmp dword[s], "220 "
|
|
|
|
je welcome
|
|
|
|
|
2013-07-10 00:55:18 +04:00
|
|
|
; cmp dword[s], "226 "
|
2013-10-03 22:43:25 +04:00
|
|
|
; je transfer_ok
|
2013-07-10 00:19:08 +04:00
|
|
|
|
2013-06-24 23:33:16 +04:00
|
|
|
cmp dword[s], "227 "
|
|
|
|
je pasv_ok
|
|
|
|
|
|
|
|
cmp dword[s], "230 "
|
|
|
|
je login_ok
|
|
|
|
|
2013-07-10 00:55:18 +04:00
|
|
|
; cmp dword[s], "250"
|
2013-07-10 13:37:01 +04:00
|
|
|
; je op_ok
|
2013-07-10 00:55:18 +04:00
|
|
|
|
2013-06-24 23:33:16 +04:00
|
|
|
cmp dword[s], "331 "
|
|
|
|
je pass
|
|
|
|
|
2013-07-10 00:55:18 +04:00
|
|
|
; cmp dword[s], "421 "
|
2013-07-10 00:19:08 +04:00
|
|
|
; je timeout
|
|
|
|
|
2013-07-13 00:35:53 +04:00
|
|
|
cmp dword[s], "503 " ; login first
|
|
|
|
je welcome
|
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
cmp dword[s], "530 " ; password incorrect
|
2013-07-10 00:19:08 +04:00
|
|
|
je welcome
|
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
cmp dword[s], "550 "
|
|
|
|
je close_datacon
|
|
|
|
|
2014-04-01 11:20:52 +04:00
|
|
|
cmp byte[s+3], "-"
|
|
|
|
je wait_for_servercommand
|
2013-07-10 00:19:08 +04:00
|
|
|
jmp wait_for_usercommand
|
2013-06-24 23:33:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
welcome:
|
|
|
|
|
|
|
|
mov [status], STATUS_CONNECTED
|
2013-07-10 00:19:08 +04:00
|
|
|
jmp wait_for_usercommand
|
2013-06-24 23:33:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
pass:
|
|
|
|
|
|
|
|
mov [status], STATUS_NEEDPASSWORD
|
2013-07-10 00:19:08 +04:00
|
|
|
jmp wait_for_usercommand
|
2013-06-24 23:33:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
login_ok:
|
|
|
|
|
|
|
|
mov [status], STATUS_LOGGED_IN
|
2013-07-10 00:19:08 +04:00
|
|
|
jmp wait_for_usercommand
|
2013-06-24 23:33:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
pasv_ok:
|
|
|
|
|
2013-07-13 00:35:53 +04:00
|
|
|
sub ecx, 4
|
2013-06-24 23:33:16 +04:00
|
|
|
jb .fail
|
|
|
|
mov al, "("
|
2013-07-13 00:35:53 +04:00
|
|
|
mov edi, s + 4
|
2013-06-24 23:33:16 +04:00
|
|
|
repne scasb
|
|
|
|
|
|
|
|
mcall socket, AF_INET4, SOCK_STREAM, 0
|
|
|
|
cmp eax, -1
|
2013-07-12 12:59:34 +04:00
|
|
|
je error_socket
|
2013-06-24 23:33:16 +04:00
|
|
|
mov [datasocket], eax
|
|
|
|
|
|
|
|
mov esi, edi
|
|
|
|
call ascii_dec
|
|
|
|
mov byte[sockaddr2.ip+0], bl
|
|
|
|
call ascii_dec
|
|
|
|
mov byte[sockaddr2.ip+1], bl
|
|
|
|
call ascii_dec
|
|
|
|
mov byte[sockaddr2.ip+2], bl
|
|
|
|
call ascii_dec
|
|
|
|
mov byte[sockaddr2.ip+3], bl
|
|
|
|
|
|
|
|
call ascii_dec
|
|
|
|
mov byte[sockaddr2.port+0], bl
|
2013-07-10 00:19:08 +04:00
|
|
|
call ascii_dec
|
|
|
|
mov byte[sockaddr2.port+1], bl
|
2013-06-24 23:33:16 +04:00
|
|
|
|
2013-07-10 00:19:08 +04:00
|
|
|
invoke con_write_asciiz, str_open
|
2013-06-24 23:33:16 +04:00
|
|
|
mcall connect, [datasocket], sockaddr2, 18
|
2013-07-13 00:35:53 +04:00
|
|
|
; cmp eax, -1
|
|
|
|
; je error_socket
|
|
|
|
jmp wait_for_servercommand
|
2013-06-24 23:33:16 +04:00
|
|
|
|
|
|
|
.fail:
|
2013-07-13 00:35:53 +04:00
|
|
|
invoke con_write_asciiz, str_unknown
|
2013-07-10 00:19:08 +04:00
|
|
|
jmp wait_for_servercommand
|
2013-06-24 23:33:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
data_ok:
|
|
|
|
|
2013-10-03 22:43:25 +04:00
|
|
|
invoke con_write_asciiz, str2b
|
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
cmp [operation], OPERATION_STOR
|
|
|
|
je .stor
|
|
|
|
|
|
|
|
; we are receiving data
|
2013-07-10 01:14:47 +04:00
|
|
|
mcall recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0
|
|
|
|
test ebx, ebx
|
2013-07-10 13:37:01 +04:00
|
|
|
jnz .done
|
2013-07-10 00:55:18 +04:00
|
|
|
mov byte[buffer_ptr2 + eax], 0
|
2013-07-10 00:19:08 +04:00
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
cmp [operation], OPERATION_RETR
|
|
|
|
je .retr
|
|
|
|
|
|
|
|
; not retreiving, just print to console
|
2013-07-10 00:55:18 +04:00
|
|
|
invoke con_write_asciiz, buffer_ptr2
|
2013-07-10 13:37:01 +04:00
|
|
|
jmp data_ok
|
2013-06-24 23:33:16 +04:00
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
; retreiving, save to file
|
|
|
|
.retr:
|
|
|
|
mov [filestruct.ptr], buffer_ptr2
|
|
|
|
mov [filestruct.size], eax
|
|
|
|
push eax
|
|
|
|
mcall 70, filestruct
|
|
|
|
pop eax
|
|
|
|
add [filestruct.offset], eax
|
2013-07-10 01:14:47 +04:00
|
|
|
jmp data_ok
|
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
; storing, send all data
|
|
|
|
.stor:
|
|
|
|
mcall 70, filestruct
|
|
|
|
cmp eax, 6 ; end of file
|
|
|
|
je .last_call
|
|
|
|
test eax, eax ; error
|
|
|
|
; jne .fileerror
|
|
|
|
add [filestruct.offset], ebx
|
|
|
|
mov esi, ebx
|
|
|
|
mcall send, [datasocket], buffer_ptr2, , 0
|
|
|
|
jmp .stor
|
|
|
|
|
|
|
|
.last_call:
|
|
|
|
mov esi, ebx
|
|
|
|
mcall send, [datasocket], buffer_ptr2, , 0
|
|
|
|
|
|
|
|
.done:
|
2013-10-03 22:43:25 +04:00
|
|
|
invoke con_write_asciiz, str_close
|
2013-07-10 00:19:08 +04:00
|
|
|
mcall close, [datasocket]
|
|
|
|
jmp wait_for_servercommand
|
2013-06-24 23:33:16 +04:00
|
|
|
|
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
|
|
|
|
close_datacon:
|
2013-10-03 22:43:25 +04:00
|
|
|
invoke con_write_asciiz, str_close
|
2013-07-10 13:37:01 +04:00
|
|
|
mcall close, [datasocket]
|
|
|
|
jmp wait_for_usercommand
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-24 23:33:16 +04:00
|
|
|
ascii_dec:
|
|
|
|
|
|
|
|
xor ebx, ebx
|
2013-07-10 00:19:08 +04:00
|
|
|
mov cl, 4 ; max length is 3 digits + 1 separator
|
2013-06-24 23:33:16 +04:00
|
|
|
.loop:
|
|
|
|
lodsb
|
|
|
|
sub al, '0'
|
|
|
|
jb .done
|
|
|
|
cmp al, 9
|
|
|
|
ja .done
|
2013-07-10 00:19:08 +04:00
|
|
|
lea ebx, [ebx*4+ebx] ; ebx *5
|
|
|
|
shl ebx, 1 ; ebx *2
|
2013-06-24 23:33:16 +04:00
|
|
|
add bl, al
|
|
|
|
dec cl
|
|
|
|
jnz .loop
|
|
|
|
|
|
|
|
.done:
|
|
|
|
ret
|