-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.asm
54 lines (40 loc) · 1.42 KB
/
io.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
; read_line(char* rcx, int rdx)
read_line:
push rbp
mov rbp, rsp
sub rsp, 0x30
; Store RCX and RDX in the shadow space
mov [rbp+0x10], rcx
mov [rbp+0x18], rdx
mov rcx, STD_INPUT_HANDLE ; Get handle to StdIn
call GetStdHandle
mov rcx, rax ; hFile
mov rdx, [rbp + 0x10] ; lpBuffer
mov r8, [rbp + 0x18] ; nNumberOfBytesToRead
lea r9, [rbp - 0x08] ; lpNumberOfBytesRead
mov qword [rbp - 0x08], 0 ; lpOverlapped
call ReadFile
mov rax, [rbp - 0x08] ; Put the number of bytes read in to rax
sub rax, 0x02 ; Our "bytes read" includes the carriage return and line feed - so lets skip those
mov rdx, [rbp + 0x10] ; Load the buffer back into rdx
mov byte [rdx + rax], 0x00 ; Null terminate the string after the main command (e.g, "exit\r\n" becomes "exit")
leave
ret
; write_line(char* rcx, int rdx)
write_line:
push rbp
mov rbp, rsp
sub rsp, 0x30
; Store RCX and RDX in the shadow space
mov [rbp + 0x10], rcx
mov [rbp + 0x18], rdx
mov rcx, STD_OUTPUT_HANDLE ; Get handle to StdOut
call GetStdHandle
mov rcx, rax ; hFile
mov rdx, [rbp + 0x10] ; lpBuffer
mov r8, [rbp + 0x18] ; nNumberOfBytesToRead
lea r9, [rbp - 0x08] ; lpNumberOfBytesRead
mov qword [rbp - 0x08], 0 ; lpOverlapped
call WriteFile
leave
ret