OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
ControlMsrE2UI.c
Go to the documentation of this file.
1
15#include "ControlMsrE2.h"
16
18
19/*
20 Read up to Length -1 Characters from keyboard.
21 CR will exit
22 LF will exit
23 Del key is supported
24 Esc any input will be cleared. If there isn't any ReadLine will exít
25 When length - 1 characters are entered Readline will exit automatically.
26*/
27UINT32
29 OUT CHAR16 *Buffer,
30 IN UINT32 Length
31 )
32{
33 EFI_STATUS Status;
34 UINTN EventIndex;
35 EFI_INPUT_KEY Key;
36 UINT32 Index;
37 UINT32 Pos;
38 INT32 StartRow;
39 INT32 StartColumn;
40
41 Pos = 0;
42
43 STATIC CHAR16 Output[] = L"A";
44
45 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
46
47 StartRow = gST->ConOut->Mode->CursorRow;
48 StartColumn = gST->ConOut->Mode->CursorColumn;
49
50 do {
51 //
52 // Read a key
53 //
54 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
55 ZeroMem (&Key, sizeof (Key));
56 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
57
58 if (EFI_ERROR (Status)) {
59 if (Status == EFI_NOT_READY) {
60 continue;
61 }
62
63 break;
64 }
65
66 switch (Key.UnicodeChar) {
67 case CHAR_BACKSPACE:
68 if (Pos > 0) {
69 --Pos;
70 gST->ConOut->SetCursorPosition (gST->ConOut, StartColumn + Pos, StartRow);
71 gST->ConOut->OutputString (gST->ConOut, L" ");
72 gST->ConOut->SetCursorPosition (gST->ConOut, StartColumn + Pos, StartRow);
73 }
74
75 break;
76
77 case CHAR_ESC:
78 if (Pos > 0) {
79 Pos = 0;
80 gST->ConOut->SetCursorPosition (gST->ConOut, StartColumn + Pos, StartRow);
81 for (Index = 1; Index < Length; ++Index) {
82 gST->ConOut->OutputString (gST->ConOut, L" ");
83 }
84
85 gST->ConOut->SetCursorPosition (gST->ConOut, StartColumn + Pos, StartRow);
86 } else {
87 Buffer[Pos] = 0;
88 return Pos;
89 }
90
91 break;
92
93 case CHAR_CARRIAGE_RETURN:
94 case CHAR_LINEFEED:
95 Buffer[Pos] = 0;
96 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
97 return Pos;
98
99 default:
100 Buffer[Pos] = Key.UnicodeChar;
101 ++Pos;
102 Output[0] = Key.UnicodeChar;
103 gST->ConOut->OutputString (gST->ConOut, Output);
104
105 if (Pos == Length - 1) {
106 Buffer[Pos] = 0;
107 return Pos;
108 }
109
110 break;
111 }
112 } while (TRUE);
113
114 return 0;
115}
116
117CHAR16
119 VOID
120 )
121{
122 CHAR16 Keys[2];
123
124 ReadLine (Keys, 2);
125 return Keys[0];
126}
127
128BOOLEAN
130 VOID
131 )
132{
133 CHAR16 Key;
134
135 do {
136 Key = ReadAnyKey ();
137 } while (Key != 'y' && Key != 'Y' && Key != 'n' && Key != 'N');
138
139 return Key == 'y' || Key == 'Y';
140}
141
142#define TOKENLENGTH 32
143
144EFI_STATUS
146 VOID
147 )
148{
149 UINTN Argc;
150 CHAR16 **Argv;
151 CHAR16 *Parameter;
152 UINTN ParameterCount;
153 CHAR16 *Token;
154 UINT16 TokenIndex;
155 UINT32 Index;
156 EFI_STATUS Status;
157
159
160 Status = GetArguments (&Argc, &Argv);
161 if (EFI_ERROR (Status)) {
162 Print (L"Unable to get arguments - %r\n", Status);
163 return Status;
164 }
165
166 ParameterCount = 0;
167
168 for (Index = 1; Index < Argc; ++Index) {
169 Token = AllocateCopyPool (StrSize (Argv[Index]), Argv[Index]);
170 if (Token == NULL) {
171 Print (L"Could not allocate memory for Token.\n");
172 return EFI_OUT_OF_RESOURCES;
173 }
174
175 TokenIndex = 0;
176
177 while (Token[TokenIndex] != '\0') {
178 if (Token[TokenIndex] == ' ') {
179 ++TokenIndex;
180 continue;
181 }
182
183 Parameter = &Token[TokenIndex];
184
185 do {
186 ++TokenIndex;
187 } while (Token[TokenIndex] != '\0' && Token[TokenIndex] != ' ');
188
189 Token[TokenIndex] = '\0';
190
191 if (OcStriCmp (Parameter, L"lock") == 0) {
193 } else if (OcStriCmp (Parameter, L"unlock") == 0) {
195 } else if (OcStriCmp (Parameter, L"interactive") == 0) {
197 } else {
198 Print (L"Unknown command line argument: %s\n", Parameter);
199 Status = EFI_INVALID_PARAMETER;
200 break;
201 }
202
203 ++ParameterCount;
204 }
205
206 FreePool (Token);
207 }
208
209 if (ParameterCount > 1) {
210 Print (L"interactive, unlock, lock are exclusive options. Use only one of them.\n\n");
211 Status = EFI_INVALID_PARAMETER;
212 }
213
214 if (ParameterCount == 0) {
215 Print (L"No option selected, verify only.\n");
216 Print (L"Usage: ControlMsrE2 <unlock | lock | interactive>\n\n");
217 }
218
219 return Status;
220}
221
222VOID
224 IN OUT EFI_STRING *SearchString
225 )
226{
227 BOOLEAN Result;
228
229 do {
230 Print (L"\nCurrent search string: %s\n", *SearchString);
231 Print (L"Do you want to change it ? ");
232 Result = ReadYN ();
233 Print (L"\n");
234 if (Result) {
235 Print (L"Enter search string:\n");
236
237 CHAR16 *Buffer = AllocatePool (BUFFER_LENGTH * sizeof (CHAR16));
238
239 if (Buffer != NULL) {
240 if (ReadLine (Buffer, BUFFER_LENGTH) == 0) {
241 Print (L"\nNo Input. Search string not changed.\n");
242 FreePool (Buffer);
243 } else {
244 Print (L"\n");
245 FreePool (*SearchString);
246 *SearchString = Buffer;
247 }
248 } else {
249 Print (L"Could not allocate memory. Search string can not be changed.\n");
250 }
251 }
252 } while (Result);
253}
UINT64 Length
@ ARG_UNLOCK
@ ARG_LOCK
@ ARG_VERIFY
@ ARG_INTERACTIVE
#define CHAR_ESC
#define BUFFER_LENGTH
CHAR16 ReadAnyKey(VOID)
EFI_STATUS InterpretArguments(VOID)
BOOLEAN ReadYN(VOID)
UINT32 ReadLine(OUT CHAR16 *Buffer, IN UINT32 Length)
VOID ModifySearchString(IN OUT EFI_STRING *SearchString)
UINTN mArgumentFlags
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
EFI_STATUS GetArguments(OUT UINTN *Argc, OUT CHAR16 ***Argv)
INTN EFIAPI OcStriCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
Definition OcTypingLib.h:42
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
ush Pos
Definition deflate.h:92