15 prompt_str db `sped > `, 0x00
16 invalidcmd_str db `invalid command\n`, 0x00
17 invalidaddr_str db `invalid address\n`, 0x00
18 oneline_str db `cannot delete line, as there is only one line\n`, 0x00
19 charcount_str db `read %i chars\n`, 0x00
20 currentline_str db `current line: %i\n`, 0x00
21 echo_str db `%s`, 0x00 ; print strings without format exploit
26 buffer_filename resb 4
32 ; args: buffer, buffer_lines, buffer_filename
36 %define _BUFFER_LINES 12
37 %define _BUFFER_FILENAME 8
38 %define CMDSTR 4 ; the previous line read from user
46 mov eax, [ebp+_BUFFER]
48 mov eax, [ebp+_BUFFER_LINES]
49 mov [buffer_lines], eax
50 mov eax, [ebp+_BUFFER_FILENAME]
51 mov [buffer_filename], eax
52 mov DWORD [cur_line], 0x00
62 ; read line from stdin
66 mov DWORD [ebp-CMDSTR], eax
68 ; commands are single char for now
73 mov eax, DWORD [ebp-CMDSTR]
76 ; q exists program =-=-=-=-=-=-=-=-=-=-=-=-=
77 mov eax, DWORD [ebp-CMDSTR]
79 jne _repl_cmd_quit_end
83 ; p prints current line =-=-=-=-=-=-=-=-=-=-=
84 mov eax, DWORD [ebp-CMDSTR]
86 jne _repl_cmd_print_end
88 mov eax, DWORD [cur_line]
98 ; n prints the current line number =-=-=-=-=-=-=-=
99 mov eax, DWORD [ebp-CMDSTR]
101 jne _repl_cmd_number_end
103 push DWORD [cur_line]
108 _repl_cmd_number_end:
110 ; - goes to prev line =-=-=-=-=-=-=-=-=-=-=-=-=
111 mov eax, DWORD [ebp-CMDSTR]
113 jne _repl_cmd_decline_end
115 ; make sure we are within bounds
116 mov eax, DWORD [cur_line]
119 jl _repl_invalid_addr
121 sub DWORD [cur_line], 1
124 _repl_cmd_decline_end:
126 ; + goes to next line =-=-=-=-=-=-=-=-=-=-=-=-=
127 mov eax, DWORD [ebp-CMDSTR]
129 jne _repl_cmd_incline_end
131 ; make sure we are within bounds
132 mov eax, DWORD [cur_line]
134 cmp eax, [buffer_lines]
135 jge _repl_invalid_addr
137 add DWORD [cur_line], 1
140 _repl_cmd_incline_end:
142 ; g goes to first line =-=-=-=-=-=-=-=-=-=-=-=-=
143 mov eax, DWORD [ebp-CMDSTR]
145 jne _repl_cmd_jumptop_end
147 mov DWORD [cur_line], 0x00
150 _repl_cmd_jumptop_end:
152 ; G goes to last line =-=-=-=-=-=-=-=-=-=-=-=-=
153 mov eax, DWORD [ebp-CMDSTR]
155 jne _repl_cmd_jumpbot_end
157 mov eax, DWORD [buffer_lines]
159 mov DWORD [cur_line], eax
162 _repl_cmd_jumpbot_end:
164 ; c changes the current line =-=-=-=-=-=-=-=-=-=
165 mov eax, DWORD [ebp-CMDSTR]
167 jne _repl_cmd_change_end
169 ; read a new line to use
187 add eax, DWORD [buffer]
191 _repl_cmd_change_end:
193 ; d delete line =-=-=-=-=-=-=-=-=-=-=-=-=
194 mov eax, DWORD [ebp-CMDSTR]
196 jne _repl_cmd_delete_end
198 ; check to make sure we don't have only one line
199 cmp DWORD [buffer_lines], 1
204 push DWORD [buffer_lines]
205 push DWORD [cur_line]
209 sub DWORD [buffer_lines], 1
211 ; if it's the last line, move one down
212 mov eax, DWORD [buffer_lines]
213 cmp DWORD [cur_line], eax
215 sub DWORD [cur_line], 1
218 _repl_cmd_delete_end:
220 ; o appends text after line =-=-=-=-=-=-=-=-=
221 mov eax, DWORD [ebp-CMDSTR]
223 jne _repl_cmd_appenddown_end
227 push DWORD [buffer_lines]
228 mov eax, DWORD [cur_line]
244 add eax, DWORD [buffer]
247 add DWORD [buffer_lines], 1
250 _repl_cmd_appenddown_end:
252 ; O oppens text before line =-=-=-=-=-=-=-=
253 mov eax, DWORD [ebp-CMDSTR]
255 jne _repl_cmd_appendup_end
259 push DWORD [buffer_lines]
260 push DWORD [cur_line]
273 add eax, DWORD [buffer]
276 ; also move cursor down one
277 add DWORD [cur_line], 1
279 add DWORD [buffer_lines], 1
282 _repl_cmd_appendup_end:
285 ; w writes file =-=-=-=-=-=-=-=-=-=-=-=-=
286 mov eax, DWORD [ebp-CMDSTR]
288 jne _repl_cmd_write_end
290 push DWORD [buffer_filename]
292 push DWORD [buffer_lines]
299 ; if no commands were matched, it's an error
300 jmp _repl_invalid_cmd
302 ; some error messages
325 %undef _BUFFER_FILENAME