1 ; sped - the stupidly pointless editor
21 banner_str db `SPED - the stupidly pointless editor\n`, 0x00
22 nofile_str db `no file provided\n`, 0x00
23 readlines_str db `opened file with %i lines\n`, 0x00
24 prompt_str db `sped > `, 0x00
25 invalidcmd_str db `invalid command\n`, 0x00
26 invalidaddr_str db `invalid address\n`, 0x00
27 charcount_str db `read %i chars\n`, 0x00
28 currentline_str db `current line: %i\n`, 0x00
29 echo_str db `%s`, 0x00 ; print strings without format exploit
44 ; read command line args
49 ; display error msg if no file
56 mov ebx, DWORD [ebp+_ARGV]
57 add ebx, 4 ; first user arg is filename
62 mov [buffer_lines], ecx
63 mov DWORD [cur_line], 0x00
65 push DWORD [buffer_lines]
83 ; no args - reads from globals
86 %define CMDSTR 4 ; the previous line read from user
101 ; read line from stdin
105 mov DWORD [ebp-CMDSTR], eax
107 ; commands are single char for now
109 jne _repl_invalid_cmd
112 mov eax, DWORD [ebp-CMDSTR]
116 mov eax, DWORD [ebp-CMDSTR]
118 jne _repl_cmd_quit_end
122 ; p prints current line
123 mov eax, DWORD [ebp-CMDSTR]
125 jne _repl_cmd_print_end
127 mov eax, DWORD [cur_line]
137 ; n prints the current line number
138 mov eax, DWORD [ebp-CMDSTR]
140 jne _repl_cmd_number_end
142 push DWORD [cur_line]
147 _repl_cmd_number_end:
149 ; - goes to prev line
150 mov eax, DWORD [ebp-CMDSTR]
152 jne _repl_cmd_decline_end
154 ; make sure we are within bounds
155 mov eax, DWORD [cur_line]
158 jl _repl_invalid_addr
160 sub DWORD [cur_line], 1
163 _repl_cmd_decline_end:
165 ; + goes to next line
166 mov eax, DWORD [ebp-CMDSTR]
168 jne _repl_cmd_incline_end
170 ; make sure we are within bounds
171 mov eax, DWORD [cur_line]
173 cmp eax, [buffer_lines]
174 jge _repl_invalid_addr
176 add DWORD [cur_line], 1
179 _repl_cmd_incline_end:
182 jmp _repl_invalid_cmd
184 ; some error messages