File tree Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change 23
23
.P5 dq ? ; fifth parameter
24
24
25
25
; some local space on the stack for temporary data:
26
+ .hStdIn dq ?
26
27
.hStdOut dq ?
27
28
.dwTemp dd ?
29
+ .mode dd ?
28
30
29
31
align .assume rsp , 16
30
32
align 16 | 8
@@ -33,17 +35,49 @@ main:
33
35
end virtual
34
36
sub rsp , .stack_offset
35
37
38
+ mov rcx , - 10 ; STD_INPUT_HANDLE
39
+ call [ GetStdHandle ]
40
+ mov [ .hStdIn ], rax
41
+
36
42
mov rcx , - 11 ; STD_OUTPUT_HANDLE
37
43
call [ GetStdHandle ]
38
44
mov [ .hStdOut ], rax
39
45
46
+ ; https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
47
+
48
+ lea rdx , [ .mode ]
49
+ mov rcx , [ .hStdIn ]
50
+ call [ GetConsoleMode ]
51
+ xchg ecx , eax ; BOOL
52
+ jrcxz .fail
53
+
54
+ mov edx , [ .mode ]
55
+ or edx , 0x0200 ; ENABLE_VIRTUAL_TERMINAL_INPUT
56
+ mov rcx , [ .hStdIn ]
57
+ call [ SetConsoleMode ]
58
+ xchg ecx , eax ; BOOL
59
+ jrcxz .fail
60
+
61
+ lea rdx , [ .mode ]
62
+ mov rcx , [ .hStdOut ]
63
+ call [ GetConsoleMode ]
64
+ xchg ecx , eax ; BOOL
65
+ jrcxz .fail
66
+
67
+ mov edx , [ .mode ]
68
+ or edx , 0x000C ; ENABLE_VIRTUAL_TERMINAL_PROCESSING or DISABLE_NEWLINE_AUTO_RETURN
69
+ mov rcx , [ .hStdOut ]
70
+ call [ SetConsoleMode ]
71
+ xchg ecx , eax ; BOOL
72
+ jrcxz .fail
73
+
40
74
mov [ .P5 ], 0
41
75
lea r9 , [ .dwTemp ]
42
76
mov r8d , _clear_screen.characters
43
77
lea rdx , [ _clear_screen ]
44
78
mov rcx , [ .hStdOut ]
45
79
call [ WriteConsoleA ]
46
-
80
+ .fail:
47
81
mov ecx , 0
48
82
call [ ExitProcess ]
49
83
int3
@@ -54,5 +88,7 @@ library kernel32, 'kernel32.dll'
54
88
55
89
import kernel32 , \
56
90
ExitProcess , 'ExitProcess' , \
91
+ GetConsoleMode , 'GetConsoleMode' , \
57
92
GetStdHandle , 'GetStdHandle' , \
93
+ SetConsoleMode , 'SetConsoleMode' , \
58
94
WriteConsoleA , 'WriteConsoleA'
You can’t perform that action at this time.
0 commit comments