-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdisplay.c
139 lines (120 loc) · 3.01 KB
/
display.c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* PROJECT: Native Shell
* COPYRIGHT: LGPL; See LICENSE in the top level directory
* FILE: display.c
* DESCRIPTION: This module handles displaying output to screen.
* DEVELOPERS: See CONTRIBUTORS.md in the top level directory
*/
#include "precomp.h"
WCHAR DisplayBuffer[1024];
USHORT LinePos = 0;
WCHAR PutChar[2] = L" ";
UNICODE_STRING CharString = {2, 2, PutChar};
/*++
* @name RtlCliPrintString
*
* The RtlCliPrintString routine display a unicode string on the display device
*
* @param Message
* Pointer to a unicode string containing the message to print.
*
* @return STATUS_SUCCESS or failure code.
*
* @remarks None.
*
*--*/
NTSTATUS
RtlCliPrintString(IN PUNICODE_STRING Message)
{
ULONG i;
NTSTATUS Status;
for (i = 0; i < (Message->Length / sizeof(WCHAR)); i++)
{
Status = RtlCliPutChar(Message->Buffer[i]);
}
return Status;
}
/*++
* @name RtlCliPutChar
*
* The RtlCliPutChar routine displays a character.
*
* @param Char
* Character to print out.
*
* @return STATUS_SUCCESS or failure code.
*
* @remarks None.
*
*--*/
NTSTATUS
RtlCliPutChar(IN WCHAR Char)
{
// Initialize the string
CharString.Buffer[0] = Char;
// Make sure that this isn't backspace
if (Char != '\r')
{
// Check if it's a new line
if (Char == '\n')
{
// Reset the display buffer
LinePos = 0;
DisplayBuffer[LinePos] = UNICODE_NULL;
}
else
{
// Add the character in our buffer
DisplayBuffer[LinePos] = Char;
LinePos++;
}
}
// Print the character
return NtDisplayString(&CharString);
}
/*++
* @name RtlClipBackspace
*
* The RtlClipBackspace routine handles a backspace command.
*
* @param None.
*
* @return STATUS_SUCCESS or failure code if printing failed.
*
* @remarks Backspace is handled by printing the previous string minus the last
* two characters.
*
*--*/
NTSTATUS
RtlClipBackspace(VOID)
{
UNICODE_STRING BackString;
// Update the line position
LinePos--;
// Finalize this buffer and make it unicode
DisplayBuffer[LinePos] = ANSI_NULL;
RtlInitUnicodeString(&BackString, DisplayBuffer);
// Display the buffer
return NtDisplayString(&BackString);
}
NTSTATUS
__cdecl RtlCliDisplayString(IN PCH Message, ...)
{
va_list MessageList;
PCHAR MessageBuffer;
UNICODE_STRING MessageString;
NTSTATUS Status;
MessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, 512);
// First, combine the message
va_start(MessageList, Message);
_vsnprintf(MessageBuffer, 512, Message, MessageList);
va_end(MessageList);
// Now make it a unicode string
RtlCreateUnicodeStringFromAsciiz(&MessageString, MessageBuffer);
// Display it on screen
Status = RtlCliPrintString(&MessageString);
// Free Memory
RtlFreeHeap(RtlGetProcessHeap(), 0, MessageBuffer);
RtlFreeUnicodeString(&MessageString);
return Status;
}