📄 ftps.asm
字号:
mov edx, [fsize] ;Adjust the amount of data to send
sf003:
sub [fsize], edx
; send the block
mov esi, text + 0x1300 + 0x4000
call outputDataStr
; any more to send?
cmp [fsize], dword 0
je sf_exit
; read a bit more of the file
inc dword [readblock]
mov eax,[readblock]
mov [fileinfoblock+4],eax
mov eax,58
mov ebx,fileinfoblock
int 0x40
jmp sf002a
sf_exit:
ret
;***************************************************************************
; Function
; getFile
;
; Description
; Receives the specified file over the open data socket
; The file to receive is named in the buff string
;
; Inputs
; None
;
; Outputs
; None
;
;***************************************************************************
getFile:
call setupFilePath
; init fileblock descriptor, for file write
xor eax, eax
mov [fsize], eax ; Start filelength at 0
mov [fileinfoblock+4], eax ; set to 0
inc eax
mov [fileinfoblock], eax ; write cmd
; Read data from the socket until the socket closes
; loop
; loop
; read byte from socket
; write byte to file buffer
; until no more bytes in socket
; sleep 100ms
; until socket no longer connected
; write file to ram
gf000:
mov eax, 53
mov ebx, 2 ; Get # of bytes in input queue
mov ecx, [DataSocket]
int 0x40
cmp eax, 0
je gf_sleep
mov eax, 53
mov ebx, 3 ; Get a byte from socket in bl
mov ecx, [DataSocket]
int 0x40 ; returned data in bl
mov esi, text + 0x1300 + 0x4000
add esi, dword [fsize]
mov [esi], bl
inc dword [fsize]
; dummy, write to screen
;call printChar
jmp gf000
gf_sleep:
; Check to see if socket closed...
mov eax,53
mov ebx,6 ; Get socket status
mov ecx,[DataSocket]
int 0x40
cmp eax, 7
jne gf001 ; still open, so just sleep a bit
; Finished, so write the file
mov eax, [fsize]
mov [fileinfoblock+8], eax
mov eax,58
mov ebx,fileinfoblock
int 0x40
ret ; Finished
gf001:
; wait a bit
mov eax,5
mov ebx,1 ; Delay for up 100ms
int 0x40
jmp gf000 ; try for more data
;***************************************************************************
; COMMAND HANDLERS FOLLOW
;
; These handlers implement the functionality of each supported FTP Command
;
;***************************************************************************
cmdPWD:
; OK, show the directory name text
mov esi, ramdir
mov edx, ramdir_end - ramdir
call outputStr
; TODO give real directory
ret
cmdCWD:
; Only / is valid for the ramdisk
cmp [buff+5], byte 0x0d
jne ccwd_000
; OK, show the directory name text
mov esi, chdir
mov edx, chdir_end - chdir
jmp ccwd_001
ccwd_000:
; Tell user there is no such directory
mov esi, noFileStr
mov edx, noFileStr_end - noFileStr
ccwd_001:
call outputStr
ret
cmdQUIT:
; The remote end will do the close; We just
; say goodbye.
mov esi, byeStr
mov edx, byeStr_end - byeStr
call outputStr
ret
cmdABOR:
; Close port
call disconnectData
mov esi, abortStr
mov edx, abortStr_end - abortStr
call outputStr
ret
cmdPORT:
; TODO
; Copy the IP and port values to DataIP and DataPort
call parsePortStr
; Indicate the command was accepted
mov esi, cmdOKStr
mov edx, cmdOKStr_end - cmdOKStr
call outputStr
ret
cmdnoop:
; Indicate the command was accepted
mov esi, cmdOKStr
mov edx, cmdOKStr_end - cmdOKStr
call outputStr
ret
cmdTYPE:
; TODO
; Note the type field selected - reject if needed.
; Indicate the command was accepted
mov esi, cmdOKStr
mov edx, cmdOKStr_end - cmdOKStr
call outputStr
ret
cmdsyst:
; Indicate the system type
mov esi, systStr
mov edx, systStr_end - systStr
call outputStr
ret
cmdDELE:
mov esi, buff + 4 ; Point to (1 before) first character of file
mov edi, fname
; Skip any trailing spaces or / character
cdd001:
inc esi
cmp [esi], byte ' '
je cdd001
cmp [esi], byte '/'
je cdd001
cdd002:
cld
movsb
cmp [esi], byte 0x0d
jne cdd002
mov [edi], byte 0
mov ebx, fname
mov eax, 32
int 0x40
cmp eax, 0
jne cmdDele_err
mov esi, delokStr
mov edx, delokStr_end - delokStr
call outputStr
jmp cmdDele_exit
cmdDele_err:
mov esi, noFileStr
mov edx, noFileStr_end - noFileStr
call outputStr
cmdDele_exit:
ret
cmdNLST:
cmdLIST:
; Indicate the command was accepted
mov esi, startStr
mov edx, startStr_end - startStr
call outputStr
call connectData
; Wait for socket to establish
cl001:
; wait a bit
mov eax,5
mov ebx,1 ; Delay for up 100ms
int 0x40
; check connection status
mov eax,53
mov ebx,6 ; Get socket status
mov ecx,[DataSocket]
int 0x40
cmp eax, 4
jne cl001
; send directory listing
call sendDir
; Close port
call disconnectData
mov esi, endStr
mov edx, endStr_end - endStr
call outputStr
ret
cmdRETR:
; Indicate the command was accepted
mov esi, startStr
mov edx, startStr_end - startStr
call outputStr
call connectData
; Wait for socket to establish
cr001:
; wait a bit
mov eax,5
mov ebx,1 ; Delay for up 100ms
int 0x40
; check connection status
mov eax,53
mov ebx,6 ; Get socket status
mov ecx,[DataSocket]
int 0x40
cmp eax, 4
jne cr001
; send data to remote user
call sendFile
; Close port
call disconnectData
mov esi, endStr
mov edx, endStr_end - endStr
call outputStr
ret
cmdSTOR:
; Indicate the command was accepted
mov esi, storStr
mov edx, storStr_end - storStr
call outputStr
call connectData
; Wait for socket to establish
cs001:
; wait a bit
mov eax,5
mov ebx,1 ; Delay for up 100ms
int 0x40
; check connection status
mov eax,53
mov ebx,6 ; Get socket status
mov ecx,[DataSocket]
int 0x40
cmp eax, 4
jne cs001
; get data file from remote user
call getFile
mov esi, endStr
mov edx, endStr_end - endStr
call outputStr
; Close port
call disconnectData
ret
; DATA AREA
; This is the list of supported commands, and the function to call
; The list end with a NULL.
CMDList:
db 'pwd',0
dd cmdPWD
db 'PWD',0
dd cmdPWD
db 'XPWD',0
dd cmdPWD
db 'xpwd',0
dd cmdPWD
db 'QUIT',0
dd cmdQUIT
db 'quit',0
dd cmdQUIT
db 'PORT',0
dd cmdPORT
db 'port',0
dd cmdPORT
db 'LIST',0
dd cmdLIST
db 'list',0
dd cmdLIST
db 'NLST',0
dd cmdNLST
db 'nlst',0
dd cmdNLST
db 'TYPE',0
dd cmdTYPE
db 'type',0
dd cmdTYPE
db 'syst',0
dd cmdsyst
db 'noop',0
dd cmdnoop
db 'CWD',0
dd cmdCWD
db 'cwd',0
dd cmdCWD
db 'RETR',0
dd cmdRETR
db 'retr',0
dd cmdRETR
db 'DELE',0
dd cmdDELE
db 'dele',0
dd cmdDELE
db 'stor',0
dd cmdSTOR
db 'STOR',0
dd cmdSTOR
db 'ABOR',0
dd cmdABOR
db 'abor',0
dd cmdABOR
db 0xff,0xf4,0xff,0xf2,'ABOR',0
dd cmdABOR
db 0
cmdPtr dd 0
CmdSocket dd 0x0
CmdSocketStatus dd 0x0
DataSocket dd 0x0
DataSocketStatus dd 0x0
DataPort dd 0x00
DataIP dd 0x00
pos dd 80 * 1
scroll dd 1
dd 24
wcolor dd 0x000000
window_label:
db 'FTP SERVER',0
contt db 'Connected'
contlen:
discontt db 'Disconnected'
discontlen:
cmdOKStr: db '200 Command OK',0x0d,0x0a
cmdOKStr_end:
loginStr0: db '220- Menuet FTP Server v0.1',0x0d,0x0a
db '220 Username and Password required',0x0d,0x0a
loginStr0_end:
loginStr1: db '331 Password now required',0x0d,0x0a
loginStr1_end:
loginStr2: db '230 You are now logged in.',0x0d,0x0a
loginStr2_end:
byeStr: db '221 Bye bye!',0x0d,0x0a
byeStr_end:
systStr: db '215 UNIX system type',0x0d,0x0a
systStr_end:
ramdir: db '257 "/"',0x0d,0x0a
ramdir_end:
chdir: db '200 directory changed to /',0x0d,0x0a
chdir_end:
unsupStr: db '500 Unsupported command',0x0d,0x0a
unsupStr_end:
noFileStr: db '550 No such file',0x0d,0x0a
noFileStr_end:
delokStr: db '250 DELE command successful',0x0d,0x0a
delokStr_end:
startStr: db '150 Here it comes...',0x0d,0x0a
startStr_end:
storStr: db '150 Connecting for STOR',0x0d,0x0a
storStr_end:
endStr: db '226 Transfer OK, Closing connection',0x0d,0x0a
endStr_end:
abortStr: db '225 Abort successful',0x0d,0x0a
abortStr_end:
; This is the buffer used for building up a directory listing line
dirStr: times 128 db 0
; These are template strings used in building up a directory listing line
tmplStr: db 'rw-rw-rw- 1 0 0 ',0
timeStr: db ' Jan 1 2000 ',0
; The following lines define data for reading a directory block
readblock: dd 0
fileinfoblock:
dd 0x00
dd 0x00
dd 0x01
dd text + 0x1300 + 0x4000 ; data area
dd text + 0x1300 ; work area
fname: times 256 db 0
fsize: dd 0
; The 'filename' for a directory listing
dirpath: db '/RD/1',0
state db 0
buffptr dd 0
buff: times 256 db 0 ; Could put this after iend
; Ram use at the end of the application:
; text : 2400 bytes for screen memory
; text + 0x1300 : 16KB work area for file access
; text + 0x1300 + 0x4000 : file data area
text:
I_END:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -