Rev 3967 | Rev 4920 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3701 | hidnplayr | 1 | server_parser: |
2 | |||
3 | ; Commands are always 3 numbers and followed by a space |
||
4 | ; If a server decides it needs multiline output, |
||
5 | ; first lines will have a dash instead of space after numbers, |
||
3789 | hidnplayr | 6 | ; thus they are simply ignored in this simple command parser. |
3701 | hidnplayr | 7 | |
8 | cmp dword[s], "150 " |
||
9 | je data_ok |
||
10 | |||
11 | cmp dword[s], "220 " |
||
12 | je welcome |
||
13 | |||
3790 | hidnplayr | 14 | ; cmp dword[s], "226 " |
3967 | hidnplayr | 15 | ; je transfer_ok |
3789 | hidnplayr | 16 | |
3701 | hidnplayr | 17 | cmp dword[s], "227 " |
18 | je pasv_ok |
||
19 | |||
20 | cmp dword[s], "230 " |
||
21 | je login_ok |
||
22 | |||
3790 | hidnplayr | 23 | ; cmp dword[s], "250" |
3800 | hidnplayr | 24 | ; je op_ok |
3790 | hidnplayr | 25 | |
3701 | hidnplayr | 26 | cmp dword[s], "331 " |
27 | je pass |
||
28 | |||
3790 | hidnplayr | 29 | ; cmp dword[s], "421 " |
3789 | hidnplayr | 30 | ; je timeout |
3701 | hidnplayr | 31 | |
3818 | hidnplayr | 32 | cmp dword[s], "503 " ; login first |
33 | je welcome |
||
34 | |||
3800 | hidnplayr | 35 | cmp dword[s], "530 " ; password incorrect |
3789 | hidnplayr | 36 | je welcome |
3701 | hidnplayr | 37 | |
3800 | hidnplayr | 38 | cmp dword[s], "550 " |
39 | je close_datacon |
||
40 | |||
4729 | hidnplayr | 41 | cmp byte[s+3], "-" |
42 | je wait_for_servercommand |
||
3789 | hidnplayr | 43 | jmp wait_for_usercommand |
44 | |||
45 | |||
3701 | hidnplayr | 46 | welcome: |
47 | |||
48 | mov [status], STATUS_CONNECTED |
||
3789 | hidnplayr | 49 | jmp wait_for_usercommand |
3701 | hidnplayr | 50 | |
51 | |||
52 | pass: |
||
53 | |||
54 | mov [status], STATUS_NEEDPASSWORD |
||
3789 | hidnplayr | 55 | jmp wait_for_usercommand |
3701 | hidnplayr | 56 | |
57 | |||
58 | login_ok: |
||
59 | |||
60 | mov [status], STATUS_LOGGED_IN |
||
3789 | hidnplayr | 61 | jmp wait_for_usercommand |
3701 | hidnplayr | 62 | |
63 | |||
64 | pasv_ok: |
||
65 | |||
3818 | hidnplayr | 66 | sub ecx, 4 |
3701 | hidnplayr | 67 | jb .fail |
68 | mov al, "(" |
||
3818 | hidnplayr | 69 | mov edi, s + 4 |
3701 | hidnplayr | 70 | repne scasb |
71 | |||
72 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
||
73 | cmp eax, -1 |
||
3813 | hidnplayr | 74 | je error_socket |
3701 | hidnplayr | 75 | mov [datasocket], eax |
76 | |||
77 | mov esi, edi |
||
78 | call ascii_dec |
||
79 | mov byte[sockaddr2.ip+0], bl |
||
80 | call ascii_dec |
||
81 | mov byte[sockaddr2.ip+1], bl |
||
82 | call ascii_dec |
||
83 | mov byte[sockaddr2.ip+2], bl |
||
84 | call ascii_dec |
||
85 | mov byte[sockaddr2.ip+3], bl |
||
86 | |||
87 | call ascii_dec |
||
3789 | hidnplayr | 88 | mov byte[sockaddr2.port+0], bl |
89 | call ascii_dec |
||
3701 | hidnplayr | 90 | mov byte[sockaddr2.port+1], bl |
91 | |||
3789 | hidnplayr | 92 | invoke con_write_asciiz, str_open |
3701 | hidnplayr | 93 | mcall connect, [datasocket], sockaddr2, 18 |
3818 | hidnplayr | 94 | ; cmp eax, -1 |
95 | ; je error_socket |
||
96 | jmp wait_for_servercommand |
||
3701 | hidnplayr | 97 | |
98 | .fail: |
||
3818 | hidnplayr | 99 | invoke con_write_asciiz, str_unknown |
3789 | hidnplayr | 100 | jmp wait_for_servercommand |
3701 | hidnplayr | 101 | |
102 | |||
103 | data_ok: |
||
104 | |||
3967 | hidnplayr | 105 | invoke con_write_asciiz, str2b |
106 | |||
3800 | hidnplayr | 107 | cmp [operation], OPERATION_STOR |
108 | je .stor |
||
109 | |||
110 | ; we are receiving data |
||
3792 | hidnplayr | 111 | mcall recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0 |
112 | test ebx, ebx |
||
3800 | hidnplayr | 113 | jnz .done |
3790 | hidnplayr | 114 | mov byte[buffer_ptr2 + eax], 0 |
3701 | hidnplayr | 115 | |
3800 | hidnplayr | 116 | cmp [operation], OPERATION_RETR |
117 | je .retr |
||
118 | |||
119 | ; not retreiving, just print to console |
||
3790 | hidnplayr | 120 | invoke con_write_asciiz, buffer_ptr2 |
3800 | hidnplayr | 121 | jmp data_ok |
3789 | hidnplayr | 122 | |
3800 | hidnplayr | 123 | ; retreiving, save to file |
124 | .retr: |
||
125 | mov [filestruct.ptr], buffer_ptr2 |
||
126 | mov [filestruct.size], eax |
||
127 | push eax |
||
128 | mcall 70, filestruct |
||
129 | pop eax |
||
130 | add [filestruct.offset], eax |
||
3792 | hidnplayr | 131 | jmp data_ok |
132 | |||
3800 | hidnplayr | 133 | ; storing, send all data |
134 | .stor: |
||
135 | mcall 70, filestruct |
||
136 | cmp eax, 6 ; end of file |
||
137 | je .last_call |
||
138 | test eax, eax ; error |
||
139 | ; jne .fileerror |
||
140 | add [filestruct.offset], ebx |
||
141 | mov esi, ebx |
||
142 | mcall send, [datasocket], buffer_ptr2, , 0 |
||
143 | jmp .stor |
||
144 | |||
145 | .last_call: |
||
146 | mov esi, ebx |
||
147 | mcall send, [datasocket], buffer_ptr2, , 0 |
||
148 | |||
149 | .done: |
||
3967 | hidnplayr | 150 | invoke con_write_asciiz, str_close |
3789 | hidnplayr | 151 | mcall close, [datasocket] |
152 | jmp wait_for_servercommand |
||
3701 | hidnplayr | 153 | |
154 | |||
3800 | hidnplayr | 155 | |
156 | close_datacon: |
||
3967 | hidnplayr | 157 | invoke con_write_asciiz, str_close |
3800 | hidnplayr | 158 | mcall close, [datasocket] |
159 | jmp wait_for_usercommand |
||
160 | |||
161 | |||
162 | |||
3701 | hidnplayr | 163 | ascii_dec: |
164 | |||
165 | xor ebx, ebx |
||
3789 | hidnplayr | 166 | mov cl, 4 ; max length is 3 digits + 1 separator |
3701 | hidnplayr | 167 | .loop: |
168 | lodsb |
||
169 | sub al, '0' |
||
170 | jb .done |
||
171 | cmp al, 9 |
||
172 | ja .done |
||
3789 | hidnplayr | 173 | lea ebx, [ebx*4+ebx] ; ebx *5 |
174 | shl ebx, 1 ; ebx *2 |
||
3701 | hidnplayr | 175 | add bl, al |
176 | dec cl |
||
177 | jnz .loop |
||
178 | |||
179 | .done: |
||
180 | ret |