X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=repl.asm;h=750e430becf71190c68fb18fb4c37f725951b3dc;hb=HEAD;hp=738da942ffcbbcf086f17118d0abda22af7b0165;hpb=6cf67300c03d92a9cc0c5888b33cdb21a852eb69;p=sped.git diff --git a/repl.asm b/repl.asm index 738da94..750e430 100644 --- a/repl.asm +++ b/repl.asm @@ -1,3 +1,6 @@ +; sped - the stupidly pointless editor +; written by pinosaur +; repl.asm: user interactions extern printf extern fflush @@ -13,9 +16,9 @@ global repl section .data prompt_str db `sped > `, 0x00 - invalidcmd_str db `invalid command\n`, 0x00 - invalidaddr_str db `invalid address\n`, 0x00 - charcount_str db `read %i chars\n`, 0x00 + invalidcmd_str db `invalid command.\n`, 0x00 + invalidaddr_str db `invalid address.\n`, 0x00 + oneline_str db `cannot delete line, as there is only one line.\n`, 0x00 currentline_str db `current line: %i\n`, 0x00 echo_str db `%s`, 0x00 ; print strings without format exploit @@ -195,18 +198,92 @@ repl: jne _repl_cmd_delete_end ; check to make sure we don't have only one line + cmp DWORD [buffer_lines], 1 + jle _repl_oneline ; delete the line push DWORD [buffer] push DWORD [buffer_lines] push DWORD [cur_line] call shiftLeft + mov [buffer], eax sub DWORD [buffer_lines], 1 + ; if it's the last line, move one down + mov eax, DWORD [buffer_lines] + cmp DWORD [cur_line], eax + jl _repl_continue + sub DWORD [cur_line], 1 + jmp _repl_continue _repl_cmd_delete_end: + ; o appends text after line =-=-=-=-=-=-=-=-= + mov eax, DWORD [ebp-CMDSTR] + cmp BYTE [eax], 'o' + jne _repl_cmd_appenddown_end + + ; make room first + push DWORD [buffer] + push DWORD [buffer_lines] + mov eax, DWORD [cur_line] + add eax, 1 + push eax + call shiftRight + mov [buffer], eax + + ; input text + push 0 + call readLine + mov esi, eax + + ; insert new string + mov eax, [cur_line] + add eax, 1 + mov ecx, 4 + mul ecx + add eax, DWORD [buffer] + mov [eax], esi + + add DWORD [buffer_lines], 1 + + jmp _repl_continue + _repl_cmd_appenddown_end: + + ; O oppens text before line =-=-=-=-=-=-=-= + mov eax, DWORD [ebp-CMDSTR] + cmp BYTE [eax], 'O' + jne _repl_cmd_appendup_end + + ; make room first + push DWORD [buffer] + push DWORD [buffer_lines] + push DWORD [cur_line] + call shiftRight + mov [buffer], eax + + ; input text + push 0 + call readLine + mov esi, eax + + ; insert new string + mov eax, [cur_line] + mov ecx, 4 + mul ecx + add eax, DWORD [buffer] + mov [eax], esi + + ; also move cursor down one + add DWORD [cur_line], 1 + + add DWORD [buffer_lines], 1 + + jmp _repl_continue + _repl_cmd_appendup_end: + + ; w writes file =-=-=-=-=-=-=-=-=-=-=-=-= mov eax, DWORD [ebp-CMDSTR] cmp BYTE [eax], 'w' @@ -235,6 +312,11 @@ repl: call printf jmp _repl_continue + _repl_oneline: + push oneline_str + call printf + jmp _repl_continue + _repl_continue: jmp _repl_loop