1 ; sped - the stupidly pointless editor
23 banner_str db `SPED - the stupidly pointless editor\n`, 0x00
24 nofile_str db `no file provided\n`, 0x00
25 readlines_str db `opened file with %i lines\n`, 0x00
26 prompt_str db `sped > `, 0x00
27 invalidcmd_str db `invalid command\n`, 0x00
28 invalidaddr_str db `invalid address\n`, 0x00
29 charcount_str db `read %i chars\n`, 0x00
30 currentline_str db `current line: %i\n`, 0x00
31 echo_str db `%s`, 0x00 ; print strings without format exploit
46 ; read command line args
51 ; display error msg if no file
58 mov ebx, DWORD [ebp+_ARGV]
59 add ebx, 4 ; first user arg is filename
64 mov [buffer_lines], ecx
65 mov DWORD [cur_line], 0x00
67 push DWORD [buffer_lines]
89 ; no args - reads from globals
92 %define CMDSTR 4 ; the previous line read from user
107 ; read line from stdin
111 mov DWORD [ebp-CMDSTR], eax
113 ; commands are single char for now
115 jne _repl_invalid_cmd
118 mov eax, DWORD [ebp-CMDSTR]
121 ; q exists program =-=-=-=-=-=-=-=-=-=-=-=-=
122 mov eax, DWORD [ebp-CMDSTR]
124 jne _repl_cmd_quit_end
128 ; p prints current line =-=-=-=-=-=-=-=-=-=-=
129 mov eax, DWORD [ebp-CMDSTR]
131 jne _repl_cmd_print_end
133 mov eax, DWORD [cur_line]
143 ; n prints the current line number =-=-=-=-=-=-=-=
144 mov eax, DWORD [ebp-CMDSTR]
146 jne _repl_cmd_number_end
148 push DWORD [cur_line]
153 _repl_cmd_number_end:
155 ; - goes to prev line =-=-=-=-=-=-=-=-=-=-=-=-=
156 mov eax, DWORD [ebp-CMDSTR]
158 jne _repl_cmd_decline_end
160 ; make sure we are within bounds
161 mov eax, DWORD [cur_line]
164 jl _repl_invalid_addr
166 sub DWORD [cur_line], 1
169 _repl_cmd_decline_end:
171 ; + goes to next line =-=-=-=-=-=-=-=-=-=-=-=-=
172 mov eax, DWORD [ebp-CMDSTR]
174 jne _repl_cmd_incline_end
176 ; make sure we are within bounds
177 mov eax, DWORD [cur_line]
179 cmp eax, [buffer_lines]
180 jge _repl_invalid_addr
182 add DWORD [cur_line], 1
185 _repl_cmd_incline_end:
187 ; g goes to first line =-=-=-=-=-=-=-=-=-=-=-=-=
188 mov eax, DWORD [ebp-CMDSTR]
190 jne _repl_cmd_jumptop_end
192 mov DWORD [cur_line], 0x00
195 _repl_cmd_jumptop_end:
197 ; G goes to last line =-=-=-=-=-=-=-=-=-=-=-=-=
198 mov eax, DWORD [ebp-CMDSTR]
200 jne _repl_cmd_jumpbot_end
202 mov eax, DWORD [buffer_lines]
204 mov DWORD [cur_line], eax
207 _repl_cmd_jumpbot_end:
209 ; c changes the current line =-=-=-=-=-=-=-=-=-=
210 mov eax, DWORD [ebp-CMDSTR]
212 jne _repl_cmd_change_end
214 ; read a new line to use
232 add eax, DWORD [buffer]
236 _repl_cmd_change_end:
239 jmp _repl_invalid_cmd
241 ; some error messages