15 prompt_str db `sped > `, 0x00
16 invalidcmd_str db `invalid command\n`, 0x00
17 invalidaddr_str db `invalid address\n`, 0x00
18 charcount_str db `read %i chars\n`, 0x00
19 currentline_str db `current line: %i\n`, 0x00
20 echo_str db `%s`, 0x00 ; print strings without format exploit
25 buffer_filename resb 4
31 ; args: buffer, buffer_lines, buffer_filename
35 %define _BUFFER_LINES 12
36 %define _BUFFER_FILENAME 8
37 %define CMDSTR 4 ; the previous line read from user
45 mov eax, [ebp+_BUFFER]
47 mov eax, [ebp+_BUFFER_LINES]
48 mov [buffer_lines], eax
49 mov eax, [ebp+_BUFFER_FILENAME]
50 mov [buffer_filename], eax
51 mov DWORD [cur_line], 0x00
61 ; read line from stdin
65 mov DWORD [ebp-CMDSTR], eax
67 ; commands are single char for now
72 mov eax, DWORD [ebp-CMDSTR]
75 ; q exists program =-=-=-=-=-=-=-=-=-=-=-=-=
76 mov eax, DWORD [ebp-CMDSTR]
78 jne _repl_cmd_quit_end
82 ; p prints current line =-=-=-=-=-=-=-=-=-=-=
83 mov eax, DWORD [ebp-CMDSTR]
85 jne _repl_cmd_print_end
87 mov eax, DWORD [cur_line]
97 ; n prints the current line number =-=-=-=-=-=-=-=
98 mov eax, DWORD [ebp-CMDSTR]
100 jne _repl_cmd_number_end
102 push DWORD [cur_line]
107 _repl_cmd_number_end:
109 ; - goes to prev line =-=-=-=-=-=-=-=-=-=-=-=-=
110 mov eax, DWORD [ebp-CMDSTR]
112 jne _repl_cmd_decline_end
114 ; make sure we are within bounds
115 mov eax, DWORD [cur_line]
118 jl _repl_invalid_addr
120 sub DWORD [cur_line], 1
123 _repl_cmd_decline_end:
125 ; + goes to next line =-=-=-=-=-=-=-=-=-=-=-=-=
126 mov eax, DWORD [ebp-CMDSTR]
128 jne _repl_cmd_incline_end
130 ; make sure we are within bounds
131 mov eax, DWORD [cur_line]
133 cmp eax, [buffer_lines]
134 jge _repl_invalid_addr
136 add DWORD [cur_line], 1
139 _repl_cmd_incline_end:
141 ; g goes to first line =-=-=-=-=-=-=-=-=-=-=-=-=
142 mov eax, DWORD [ebp-CMDSTR]
144 jne _repl_cmd_jumptop_end
146 mov DWORD [cur_line], 0x00
149 _repl_cmd_jumptop_end:
151 ; G goes to last line =-=-=-=-=-=-=-=-=-=-=-=-=
152 mov eax, DWORD [ebp-CMDSTR]
154 jne _repl_cmd_jumpbot_end
156 mov eax, DWORD [buffer_lines]
158 mov DWORD [cur_line], eax
161 _repl_cmd_jumpbot_end:
163 ; c changes the current line =-=-=-=-=-=-=-=-=-=
164 mov eax, DWORD [ebp-CMDSTR]
166 jne _repl_cmd_change_end
168 ; read a new line to use
186 add eax, DWORD [buffer]
190 _repl_cmd_change_end:
192 ; d delete line =-=-=-=-=-=-=-=-=-=-=-=-=
193 mov eax, DWORD [ebp-CMDSTR]
195 jne _repl_cmd_delete_end
197 ; check to make sure we don't have only one line
201 push DWORD [buffer_lines]
202 push DWORD [cur_line]
206 sub DWORD [buffer_lines], 1
209 _repl_cmd_delete_end:
211 ; o appends text after line =-=-=-=-=-=-=-=-=
212 mov eax, DWORD [ebp-CMDSTR]
214 jne _repl_cmd_appendup_end
218 push DWORD [buffer_lines]
219 push DWORD [cur_line]
232 add eax, DWORD [buffer]
235 add DWORD [buffer_lines], 1
238 _repl_cmd_appendup_end:
240 ; w writes file =-=-=-=-=-=-=-=-=-=-=-=-=
241 mov eax, DWORD [ebp-CMDSTR]
243 jne _repl_cmd_write_end
245 push DWORD [buffer_filename]
247 push DWORD [buffer_lines]
254 ; if no commands were matched, it's an error
255 jmp _repl_invalid_cmd
257 ; some error messages
275 %undef _BUFFER_FILENAME