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
36 buffer_filename resb 4
47 ; read command line args
52 ; display error msg if no file
59 mov ebx, DWORD [ebp+_ARGV]
60 add ebx, 4 ; first user arg is filename
62 mov [buffer_filename], ebx
64 push DWORD [buffer_filename]
68 mov [buffer_lines], ecx
69 mov DWORD [cur_line], 0x00
71 push DWORD [buffer_lines]
93 ; no args - reads from globals
96 %define CMDSTR 4 ; the previous line read from user
111 ; read line from stdin
115 mov DWORD [ebp-CMDSTR], eax
117 ; commands are single char for now
119 jne _repl_invalid_cmd
122 mov eax, DWORD [ebp-CMDSTR]
125 ; q exists program =-=-=-=-=-=-=-=-=-=-=-=-=
126 mov eax, DWORD [ebp-CMDSTR]
128 jne _repl_cmd_quit_end
132 ; p prints current line =-=-=-=-=-=-=-=-=-=-=
133 mov eax, DWORD [ebp-CMDSTR]
135 jne _repl_cmd_print_end
137 mov eax, DWORD [cur_line]
147 ; n prints the current line number =-=-=-=-=-=-=-=
148 mov eax, DWORD [ebp-CMDSTR]
150 jne _repl_cmd_number_end
152 push DWORD [cur_line]
157 _repl_cmd_number_end:
159 ; - goes to prev line =-=-=-=-=-=-=-=-=-=-=-=-=
160 mov eax, DWORD [ebp-CMDSTR]
162 jne _repl_cmd_decline_end
164 ; make sure we are within bounds
165 mov eax, DWORD [cur_line]
168 jl _repl_invalid_addr
170 sub DWORD [cur_line], 1
173 _repl_cmd_decline_end:
175 ; + goes to next line =-=-=-=-=-=-=-=-=-=-=-=-=
176 mov eax, DWORD [ebp-CMDSTR]
178 jne _repl_cmd_incline_end
180 ; make sure we are within bounds
181 mov eax, DWORD [cur_line]
183 cmp eax, [buffer_lines]
184 jge _repl_invalid_addr
186 add DWORD [cur_line], 1
189 _repl_cmd_incline_end:
191 ; g goes to first line =-=-=-=-=-=-=-=-=-=-=-=-=
192 mov eax, DWORD [ebp-CMDSTR]
194 jne _repl_cmd_jumptop_end
196 mov DWORD [cur_line], 0x00
199 _repl_cmd_jumptop_end:
201 ; G goes to last line =-=-=-=-=-=-=-=-=-=-=-=-=
202 mov eax, DWORD [ebp-CMDSTR]
204 jne _repl_cmd_jumpbot_end
206 mov eax, DWORD [buffer_lines]
208 mov DWORD [cur_line], eax
211 _repl_cmd_jumpbot_end:
213 ; c changes the current line =-=-=-=-=-=-=-=-=-=
214 mov eax, DWORD [ebp-CMDSTR]
216 jne _repl_cmd_change_end
218 ; read a new line to use
236 add eax, DWORD [buffer]
240 _repl_cmd_change_end:
242 ; w writes file =-=-=-=-=-=-=-=-=-=-=-=-=
243 mov eax, DWORD [ebp-CMDSTR]
245 jne _repl_cmd_write_end
247 push DWORD [buffer_filename]
249 push DWORD [buffer_lines]
256 jmp _repl_invalid_cmd
258 ; some error messages