12 prompt_str db `sped > `, 0x00
13 invalidcmd_str db `invalid command\n`, 0x00
14 invalidaddr_str db `invalid address\n`, 0x00
15 charcount_str db `read %i chars\n`, 0x00
16 currentline_str db `current line: %i\n`, 0x00
17 echo_str db `%s`, 0x00 ; print strings without format exploit
22 buffer_filename resb 4
28 ; args: buffer, buffer_lines, buffer_filename
32 %define _BUFFER_LINES 12
33 %define _BUFFER_FILENAME 8
34 %define CMDSTR 4 ; the previous line read from user
42 mov eax, [ebp+_BUFFER]
44 mov eax, [ebp+_BUFFER_LINES]
45 mov [buffer_lines], eax
46 mov eax, [ebp+_BUFFER_FILENAME]
47 mov [buffer_filename], eax
48 mov DWORD [cur_line], 0x00
58 ; read line from stdin
62 mov DWORD [ebp-CMDSTR], eax
64 ; commands are single char for now
69 mov eax, DWORD [ebp-CMDSTR]
72 ; q exists program =-=-=-=-=-=-=-=-=-=-=-=-=
73 mov eax, DWORD [ebp-CMDSTR]
75 jne _repl_cmd_quit_end
79 ; p prints current line =-=-=-=-=-=-=-=-=-=-=
80 mov eax, DWORD [ebp-CMDSTR]
82 jne _repl_cmd_print_end
84 mov eax, DWORD [cur_line]
94 ; n prints the current line number =-=-=-=-=-=-=-=
95 mov eax, DWORD [ebp-CMDSTR]
97 jne _repl_cmd_number_end
104 _repl_cmd_number_end:
106 ; - goes to prev line =-=-=-=-=-=-=-=-=-=-=-=-=
107 mov eax, DWORD [ebp-CMDSTR]
109 jne _repl_cmd_decline_end
111 ; make sure we are within bounds
112 mov eax, DWORD [cur_line]
115 jl _repl_invalid_addr
117 sub DWORD [cur_line], 1
120 _repl_cmd_decline_end:
122 ; + goes to next line =-=-=-=-=-=-=-=-=-=-=-=-=
123 mov eax, DWORD [ebp-CMDSTR]
125 jne _repl_cmd_incline_end
127 ; make sure we are within bounds
128 mov eax, DWORD [cur_line]
130 cmp eax, [buffer_lines]
131 jge _repl_invalid_addr
133 add DWORD [cur_line], 1
136 _repl_cmd_incline_end:
138 ; g goes to first line =-=-=-=-=-=-=-=-=-=-=-=-=
139 mov eax, DWORD [ebp-CMDSTR]
141 jne _repl_cmd_jumptop_end
143 mov DWORD [cur_line], 0x00
146 _repl_cmd_jumptop_end:
148 ; G goes to last line =-=-=-=-=-=-=-=-=-=-=-=-=
149 mov eax, DWORD [ebp-CMDSTR]
151 jne _repl_cmd_jumpbot_end
153 mov eax, DWORD [buffer_lines]
155 mov DWORD [cur_line], eax
158 _repl_cmd_jumpbot_end:
160 ; c changes the current line =-=-=-=-=-=-=-=-=-=
161 mov eax, DWORD [ebp-CMDSTR]
163 jne _repl_cmd_change_end
165 ; read a new line to use
183 add eax, DWORD [buffer]
187 _repl_cmd_change_end:
189 ; d delete line =-=-=-=-=-=-=-=-=-=-=-=-=
190 mov eax, DWORD [ebp-CMDSTR]
192 jne _repl_cmd_delete_end
197 _repl_cmd_delete_end:
199 ; w writes file =-=-=-=-=-=-=-=-=-=-=-=-=
200 mov eax, DWORD [ebp-CMDSTR]
202 jne _repl_cmd_write_end
204 push DWORD [buffer_filename]
206 push DWORD [buffer_lines]
213 ; if no commands were matched, it's an error
214 jmp _repl_invalid_cmd
216 ; some error messages
234 %undef _BUFFER_FILENAME