2013-06-24 23:33:16 +04:00
|
|
|
cmd_help:
|
|
|
|
|
|
|
|
push str_help
|
|
|
|
call [con_write_asciiz]
|
|
|
|
|
2013-07-10 00:55:18 +04:00
|
|
|
jmp wait_for_usercommand
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
cmd_bye:
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
; Send BYE message to the server
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "BYE" + 13 shl 24
|
|
|
|
mov byte[buf_cmd+4], 10
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, 5, 0
|
2013-07-10 13:37:01 +04:00
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
; Close the control connection
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall close, [controlsocket]
|
2016-10-07 20:11:07 +03:00
|
|
|
ijmp eax, interface_addr, interface.server_addr
|
2013-07-10 13:37:01 +04:00
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
|
2013-07-10 01:59:02 +04:00
|
|
|
cmd_pwd:
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "PWD" + 13 shl 24
|
|
|
|
mov byte[buf_cmd+4], 10
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, 5, 0
|
2013-07-10 01:59:02 +04:00
|
|
|
|
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
|
2013-07-10 00:55:18 +04:00
|
|
|
cmd_cwd:
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "CWD "
|
2013-07-10 00:55:18 +04:00
|
|
|
|
|
|
|
mov ecx, 256
|
|
|
|
xor al, al
|
2014-05-12 03:42:10 +04:00
|
|
|
mov edi, buf_cmd
|
2013-07-10 00:55:18 +04:00
|
|
|
repne scasb
|
2014-05-12 03:42:10 +04:00
|
|
|
lea esi, [edi - buf_cmd]
|
2013-07-12 13:58:26 +04:00
|
|
|
mov word [edi - 2], 0x0a0d
|
2013-07-10 00:55:18 +04:00
|
|
|
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, , 0
|
2013-07-10 00:55:18 +04:00
|
|
|
|
2013-07-10 01:31:47 +04:00
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
cmd_dele:
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "DELE"
|
2016-10-07 20:11:07 +03:00
|
|
|
mov byte[buf_cmd+4], " "
|
2013-07-10 13:37:01 +04:00
|
|
|
|
|
|
|
mov ecx, 256
|
|
|
|
xor al, al
|
2014-05-12 03:42:10 +04:00
|
|
|
mov edi, buf_cmd
|
2013-07-10 13:37:01 +04:00
|
|
|
repne scasb
|
2014-05-12 03:42:10 +04:00
|
|
|
lea esi, [edi - buf_cmd]
|
2013-07-12 13:58:26 +04:00
|
|
|
mov word [edi - 2], 0x0a0d
|
2013-07-10 13:37:01 +04:00
|
|
|
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, , 0
|
2013-07-10 13:37:01 +04:00
|
|
|
|
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
cmd_list:
|
2013-07-10 13:37:01 +04:00
|
|
|
call open_dataconnection
|
|
|
|
|
|
|
|
mov [operation], OPERATION_LIST
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "LIST"
|
|
|
|
mov word[buf_cmd+4], 0x0a0d
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, 6, 0
|
2013-07-10 13:37:01 +04:00
|
|
|
|
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
2013-07-10 01:31:47 +04:00
|
|
|
|
|
|
|
cmd_retr:
|
|
|
|
call open_dataconnection
|
2014-05-11 00:36:33 +04:00
|
|
|
|
|
|
|
; Create/open the file
|
2016-10-07 20:11:07 +03:00
|
|
|
; TODO: check beforehand if the disk has enough free space available to store the file
|
2014-05-12 03:42:10 +04:00
|
|
|
|
|
|
|
mov esi, buf_cmd+5
|
2014-05-11 00:36:33 +04:00
|
|
|
mov ecx, 256-5
|
|
|
|
call set_filename
|
2013-07-10 13:37:01 +04:00
|
|
|
|
|
|
|
mov [filestruct.subfn], 2 ; create/rewrite file
|
|
|
|
mov [filestruct.offset], 0
|
|
|
|
mov [filestruct.offset+4], 0
|
|
|
|
mov [filestruct.size], 0
|
|
|
|
mov [filestruct.ptr], 0
|
|
|
|
|
|
|
|
mcall 70, filestruct
|
2016-10-07 20:11:07 +03:00
|
|
|
test eax, eax
|
|
|
|
jz @f
|
|
|
|
call error_fs
|
|
|
|
jmp close_datacon
|
|
|
|
@@:
|
2014-05-11 00:36:33 +04:00
|
|
|
; Prepare to write to the file
|
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
mov [filestruct.subfn], 3 ; write to file
|
2014-05-11 00:36:33 +04:00
|
|
|
mov [operation], OPERATION_RETR
|
|
|
|
|
|
|
|
; Request the file from server
|
2014-05-12 03:42:10 +04:00
|
|
|
|
|
|
|
mov dword[buf_cmd], "RETR"
|
|
|
|
mov byte[buf_cmd+4], " "
|
2013-07-10 01:31:47 +04:00
|
|
|
|
|
|
|
mov ecx, 256
|
|
|
|
xor al, al
|
2014-05-12 03:42:10 +04:00
|
|
|
mov edi, buf_cmd
|
2013-07-10 01:31:47 +04:00
|
|
|
repne scasb
|
2014-05-12 03:42:10 +04:00
|
|
|
lea esi, [edi - buf_cmd]
|
2014-05-11 00:36:33 +04:00
|
|
|
mov dword[edi - 2], 0x0a0d
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, , 0
|
2013-07-10 01:31:47 +04:00
|
|
|
|
2016-10-07 20:11:07 +03:00
|
|
|
icall eax, interface_addr, interface.print, buf_cmd
|
2013-07-10 01:31:47 +04:00
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
cmd_rdir:
|
|
|
|
|
|
|
|
mov [operation], OPERATION_RDIR
|
|
|
|
|
|
|
|
; Request filename list from the server
|
|
|
|
|
2014-07-27 00:36:31 +04:00
|
|
|
call open_dataconnection
|
|
|
|
|
|
|
|
mov [ptr_fname], 0
|
|
|
|
mov [size_fname], 0
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "NLST"
|
|
|
|
mov word[buf_cmd+4], 0x0a0d
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, 6, 0
|
2013-07-10 01:31:47 +04:00
|
|
|
|
2014-07-27 00:36:31 +04:00
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
2013-07-10 01:31:47 +04:00
|
|
|
cmd_stor:
|
|
|
|
|
|
|
|
call open_dataconnection
|
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
mov [operation], OPERATION_STOR
|
|
|
|
|
2016-10-07 20:11:07 +03:00
|
|
|
; get file size
|
|
|
|
mov [filestruct.subfn], 5
|
2013-07-10 13:37:01 +04:00
|
|
|
mov [filestruct.offset], 0
|
|
|
|
mov [filestruct.offset+4], 0
|
2016-10-07 20:11:07 +03:00
|
|
|
mov [filestruct.size], 0
|
|
|
|
mov [filestruct.ptr], folder_buf
|
2013-07-10 13:37:01 +04:00
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov esi, buf_cmd+5
|
2013-07-10 13:37:01 +04:00
|
|
|
mov ecx, 256-5
|
|
|
|
call set_filename
|
|
|
|
|
2016-10-07 20:11:07 +03:00
|
|
|
mcall 70, filestruct
|
|
|
|
|
|
|
|
mov eax, dword[folder_buf+32] ; supports file size upto 4GB
|
|
|
|
mov [file_size], eax
|
|
|
|
|
|
|
|
mov [filestruct.subfn], 0 ; read file
|
|
|
|
; mov [filestruct.offset], 0
|
|
|
|
; mov [filestruct.offset+4], 0
|
|
|
|
mov [filestruct.size], BUFFERSIZE
|
|
|
|
mov [filestruct.ptr], buf_buffer2
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "STOR"
|
|
|
|
mov byte[buf_cmd+4], " "
|
2013-07-10 01:31:47 +04:00
|
|
|
|
|
|
|
mov ecx, 256
|
|
|
|
xor al, al
|
2014-05-12 03:42:10 +04:00
|
|
|
mov edi, buf_cmd
|
2013-07-10 01:31:47 +04:00
|
|
|
repne scasb
|
2014-05-12 03:42:10 +04:00
|
|
|
lea esi, [edi - buf_cmd]
|
2013-07-12 13:58:26 +04:00
|
|
|
mov word [edi - 2], 0x0a0d
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, , 0
|
2013-07-10 01:31:47 +04:00
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
|
|
|
|
2013-07-10 14:17:07 +04:00
|
|
|
cmd_lcwd:
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov esi, buf_cmd+5
|
2014-07-27 00:36:31 +04:00
|
|
|
cmp byte[esi], 10
|
|
|
|
je .print
|
2013-07-10 14:17:07 +04:00
|
|
|
mov ecx, 256-5
|
|
|
|
.loop:
|
|
|
|
lodsb
|
|
|
|
cmp al, 10
|
2016-10-07 20:11:07 +03:00
|
|
|
je .check
|
2013-07-10 14:17:07 +04:00
|
|
|
test al, al
|
2016-10-07 20:11:07 +03:00
|
|
|
je .check
|
2013-07-10 14:17:07 +04:00
|
|
|
loop .loop
|
2016-10-07 20:11:07 +03:00
|
|
|
|
|
|
|
.check:
|
2013-07-10 14:17:07 +04:00
|
|
|
mov byte[esi-1], 0
|
2016-10-07 20:11:07 +03:00
|
|
|
|
|
|
|
; check whether entered path is valid (folder exists)
|
|
|
|
mov [filestruct2.subfn], 5
|
|
|
|
mov [filestruct2.offset], 0
|
|
|
|
mov [filestruct2.size], 0
|
|
|
|
mov [filestruct2.ptr], folder_buf
|
|
|
|
mov [filestruct2.name], buf_cmd+5
|
|
|
|
mcall 70, filestruct2
|
|
|
|
test eax, eax
|
|
|
|
jz @f
|
|
|
|
cmp eax, 2
|
|
|
|
je @f
|
|
|
|
call error_fs
|
|
|
|
jmp wait_for_usercommand
|
|
|
|
|
|
|
|
@@:
|
2014-05-12 03:42:10 +04:00
|
|
|
mcall 30, 1, buf_cmd+5 ; set working directory
|
2016-10-07 20:11:07 +03:00
|
|
|
|
2014-07-27 00:36:31 +04:00
|
|
|
.print:
|
2014-05-12 03:42:10 +04:00
|
|
|
mcall 30, 2, buf_cmd, 256 ; and read it again
|
2016-10-07 20:11:07 +03:00
|
|
|
icall eax, interface_addr, interface.print, str_lcwd, buf_cmd, str_newline
|
2013-07-10 14:17:07 +04:00
|
|
|
|
|
|
|
jmp wait_for_usercommand
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
|
2013-07-10 15:19:18 +04:00
|
|
|
cmd_cdup:
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "CDUP"
|
2016-10-07 20:11:07 +03:00
|
|
|
mov word[buf_cmd+4], 0x0a0d
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, 6, 0
|
2013-07-10 15:19:18 +04:00
|
|
|
|
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
|
2013-07-10 15:19:18 +04:00
|
|
|
cmd_rmd:
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "RMD "
|
2013-07-10 15:19:18 +04:00
|
|
|
|
|
|
|
mov ecx, 256
|
|
|
|
xor al, al
|
2014-05-12 03:42:10 +04:00
|
|
|
mov edi, buf_cmd
|
2013-07-10 15:19:18 +04:00
|
|
|
repne scasb
|
2014-05-12 03:42:10 +04:00
|
|
|
lea esi, [edi - buf_cmd]
|
2013-07-12 13:58:26 +04:00
|
|
|
mov word [edi - 2], 0x0a0d
|
2013-07-10 15:19:18 +04:00
|
|
|
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, , 0
|
2013-07-10 15:19:18 +04:00
|
|
|
|
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
|
2013-07-10 15:19:18 +04:00
|
|
|
cmd_mkd:
|
|
|
|
|
2014-05-12 03:42:10 +04:00
|
|
|
mov dword[buf_cmd], "MKD "
|
2013-07-10 15:19:18 +04:00
|
|
|
|
|
|
|
mov ecx, 256
|
|
|
|
xor al, al
|
2014-05-12 03:42:10 +04:00
|
|
|
mov edi, buf_cmd
|
2013-07-10 15:19:18 +04:00
|
|
|
repne scasb
|
2014-05-12 03:42:10 +04:00
|
|
|
lea esi, [edi - buf_cmd]
|
2013-07-12 13:58:26 +04:00
|
|
|
mov word [edi - 2], 0x0a0d
|
2013-07-10 15:19:18 +04:00
|
|
|
|
2014-07-27 00:36:31 +04:00
|
|
|
mcall send, [controlsocket], buf_cmd, , 0
|
2013-07-10 15:19:18 +04:00
|
|
|
|
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
2013-07-10 14:17:07 +04:00
|
|
|
|
2016-10-07 20:11:07 +03:00
|
|
|
cmd_abor:
|
|
|
|
|
|
|
|
mcall close, [datasocket]
|
|
|
|
jmp wait_for_servercommand
|
|
|
|
|
|
|
|
|
2013-07-10 13:37:01 +04:00
|
|
|
; esi = source ptr
|
|
|
|
; ecx = max length of source buffer
|
|
|
|
set_filename:
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
mov edi, filestruct.name
|
2013-07-10 13:37:01 +04:00
|
|
|
.loop:
|
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jz .done
|
|
|
|
cmp al, 10
|
|
|
|
je .done
|
|
|
|
stosb
|
|
|
|
loop .loop
|
|
|
|
.done:
|
|
|
|
xor al, al ; append a 0 byte
|
|
|
|
stosb
|
|
|
|
|
2014-05-11 00:36:33 +04:00
|
|
|
ret
|