TianoCore EDK2 master
Loading...
Searching...
No Matches
MainHexEditor.c
Go to the documentation of this file.
1
12#include "HexEditor.h"
13#include "EditStatusBar.h"
14#include "EditInputBar.h"
15
16HEFI_EDITOR_COLOR_ATTRIBUTES HOriginalColors;
17INTN HOriginalMode;
18
19//
20// the first time editor launch
21//
22BOOLEAN HEditorFirst;
23
24//
25// it's time editor should exit
26//
27BOOLEAN HEditorExit;
28
29BOOLEAN HEditorMouseAction;
30
31extern HEFI_EDITOR_BUFFER_IMAGE HBufferImage;
32extern HEFI_EDITOR_BUFFER_IMAGE HBufferImageBackupVar;
33
34extern BOOLEAN HBufferImageMouseNeedRefresh;
35extern BOOLEAN HBufferImageNeedRefresh;
36extern BOOLEAN HBufferImageOnlyLineNeedRefresh;
37
39HEFI_EDITOR_GLOBAL_EDITOR HMainEditorBackupVar;
40
41//
42// basic initialization for MainEditor
43//
44HEFI_EDITOR_GLOBAL_EDITOR HMainEditorConst = {
45 &HBufferImage,
46 {
47 { 0, 0}
48 },
49 {
50 0,
51 0
52 },
53 NULL,
54 FALSE,
55 NULL,
56 0,
57 0,
58 1,
59 1
60};
61
65EFI_STRING_ID HexMainMenuHelpInfo[] = {
66 STRING_TOKEN (STR_HEXEDIT_HELP_TITLE),
67 STRING_TOKEN (STR_HEXEDIT_HELP_BLANK),
68 STRING_TOKEN (STR_HEXEDIT_HELP_LIST_TITLE),
69 STRING_TOKEN (STR_HEXEDIT_HELP_DIV),
70 STRING_TOKEN (STR_HEXEDIT_HELP_GO_TO_OFFSET),
71 STRING_TOKEN (STR_HEXEDIT_HELP_SAVE_BUFFER),
72 STRING_TOKEN (STR_HEXEDIT_HELP_EXIT),
73 STRING_TOKEN (STR_HEXEDIT_HELP_SELECT_START),
74 STRING_TOKEN (STR_HEXEDIT_HELP_SELECT_END),
75 STRING_TOKEN (STR_HEXEDIT_HELP_CUT),
76 STRING_TOKEN (STR_HEXEDIT_HELP_PASTE),
77 STRING_TOKEN (STR_HEXEDIT_HELP_OPEN_FILE),
78 STRING_TOKEN (STR_HEXEDIT_HELP_OPEN_DISK),
79 STRING_TOKEN (STR_HEXEDIT_HELP_OPEN_MEMORY),
80 STRING_TOKEN (STR_HEXEDIT_HELP_BLANK),
81 STRING_TOKEN (STR_HEXEDIT_HELP_EXIT_HELP),
82 STRING_TOKEN (STR_HEXEDIT_HELP_BLANK),
83 STRING_TOKEN (STR_HEXEDIT_HELP_BLANK),
84 STRING_TOKEN (STR_HEXEDIT_HELP_BLANK),
85 STRING_TOKEN (STR_HEXEDIT_HELP_BLANK),
86 STRING_TOKEN (STR_HEXEDIT_HELP_BLANK),
87 STRING_TOKEN (STR_HEXEDIT_HELP_BLANK),
88 STRING_TOKEN (STR_HEXEDIT_HELP_DIV),
89 0
90};
91
99 VOID
100 )
101{
102 INT32 CurrentLine;
103 CHAR16 *InfoString;
104 EFI_KEY_DATA KeyData;
105 EFI_STATUS Status;
106 UINTN EventIndex;
107
108 //
109 // print helpInfo
110 //
111 for (CurrentLine = 0; 0 != HexMainMenuHelpInfo[CurrentLine]; CurrentLine++) {
112 InfoString = HiiGetString (
113 gShellDebug1HiiHandle,
114 HexMainMenuHelpInfo[CurrentLine]
115 ,
116 NULL
117 );
118 if (InfoString != NULL) {
119 ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString);
120 } else {
121 ASSERT (FALSE);
122 }
123 }
124
125 //
126 // scan for ctrl+w
127 //
128 while (TRUE) {
129 Status = gBS->WaitForEvent (1, &HMainEditor.TextInputEx->WaitForKeyEx, &EventIndex);
130 if (EFI_ERROR (Status) || (EventIndex != 0)) {
131 continue;
132 }
133
134 Status = HMainEditor.TextInputEx->ReadKeyStrokeEx (HMainEditor.TextInputEx, &KeyData);
135 if (EFI_ERROR (Status)) {
136 continue;
137 }
138
139 if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) ||
140 (KeyData.KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID))
141 {
142 //
143 // For consoles that don't support/report shift state,
144 // CTRL+W is translated to L'W' - L'A' + 1.
145 //
146 if (KeyData.Key.UnicodeChar == L'W' - L'A' + 1) {
147 break;
148 }
149 } else if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) &&
150 ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) &&
151 ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID | EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) == 0))
152 {
153 //
154 // For consoles that supports/reports shift state,
155 // make sure that only CONTROL shift key is pressed.
156 //
157 if ((KeyData.Key.UnicodeChar == 'w') || (KeyData.Key.UnicodeChar == 'W')) {
158 break;
159 }
160 }
161 }
162
163 // update screen with buffer's info
164 HBufferImageNeedRefresh = TRUE;
165 HBufferImageOnlyLineNeedRefresh = FALSE;
167
168 return EFI_SUCCESS;
169}
170
178 VOID
179 )
180{
181 UINTN Size;
182 UINT64 Offset;
183 EFI_STATUS Status;
184 UINTN FRow;
185 UINTN FCol;
186
187 //
188 // variable initialization
189 //
190 Size = 0;
191 Offset = 0;
192 FRow = 0;
193 FCol = 0;
194
195 //
196 // get offset
197 //
198 Status = InputBarSetPrompt (L"Go To Offset: ");
199 if (EFI_ERROR (Status)) {
200 return Status;
201 }
202
203 Status = InputBarSetStringSize (8);
204 if (EFI_ERROR (Status)) {
205 return Status;
206 }
207
208 while (1) {
209 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
210
211 //
212 // ESC pressed
213 //
214 if (Status == EFI_NOT_READY) {
215 return EFI_SUCCESS;
216 }
217
218 //
219 // THE input string length should > 0
220 //
221 if (StrLen (InputBarGetString ()) > 0) {
223 if (EFI_ERROR (Status)) {
224 StatusBarSetStatusString (L"Invalid Offset");
225 return EFI_SUCCESS;
226 }
227
228 break;
229 }
230 }
231
232 Size = HBufferImageGetTotalSize ();
233 if (Offset >= Size) {
234 StatusBarSetStatusString (L"Invalid Offset");
235 return EFI_SUCCESS;
236 }
237
238 FRow = (UINTN)DivU64x32 (Offset, 0x10) + 1;
239 FCol = (UINTN)ModU64x32 (Offset, 0x10) + 1;
240
241 HBufferImageMovePosition (FRow, FCol, TRUE);
242
243 HBufferImageNeedRefresh = TRUE;
244 HBufferImageOnlyLineNeedRefresh = FALSE;
245 HBufferImageMouseNeedRefresh = TRUE;
246
247 return EFI_SUCCESS;
248}
249
261 VOID
262 )
263{
264 EFI_STATUS Status;
265 BOOLEAN Done;
266 CHAR16 *FileName;
267 BOOLEAN OldFile;
268 CHAR16 *Str;
269 EFI_FILE_INFO *Info;
270 SHELL_FILE_HANDLE ShellFileHandle;
271
272 if (HMainEditor.BufferImage->BufferType != FileTypeFileBuffer) {
273 if (!HMainEditor.BufferImage->Modified) {
274 return EFI_SUCCESS;
275 }
276
277 Status = InputBarSetPrompt (L"Dangerous to save disk/mem buffer. Save (Yes/No/Cancel) ? ");
278 if (EFI_ERROR (Status)) {
279 return Status;
280 }
281
282 //
283 // the answer is just one character
284 //
285 Status = InputBarSetStringSize (1);
286 if (EFI_ERROR (Status)) {
287 return Status;
288 }
289
290 //
291 // loop for user's answer
292 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
293 //
294 while (1) {
295 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
296
297 //
298 // ESC pressed
299 //
300 if (Status == EFI_NOT_READY) {
301 return EFI_SUCCESS;
302 }
303
304 switch (InputBarGetString ()[0]) {
305 case L'y':
306 case L'Y':
307 //
308 // want to save this buffer first
309 //
310 Status = HBufferImageSave (
311 NULL,
312 HMainEditor.BufferImage->DiskImage->Name,
313 HMainEditor.BufferImage->DiskImage->Offset,
314 HMainEditor.BufferImage->DiskImage->Size,
315 HMainEditor.BufferImage->MemImage->Offset,
316 HMainEditor.BufferImage->MemImage->Size,
317 HMainEditor.BufferImage->BufferType
318 );
319
320 if (EFI_ERROR (Status)) {
321 StatusBarSetStatusString (L"BufferSave: Problems Writing");
322 return Status;
323 }
324
325 return EFI_SUCCESS;
326
327 case L'n':
328 case L'N':
329 //
330 // the file won't be saved
331 //
332 return EFI_SUCCESS;
333
334 case L'c':
335 case L'C':
336 return EFI_SUCCESS;
337 }
338
339 //
340 // end of switch
341 //
342 }
343
344 //
345 // ENDOF WHILE
346 //
347 }
348
349 //
350 // ENDOF != FILEBUFFER
351 //
352 // This command will save currently opened file to disk.
353 // You can choose save to another file name or just save to
354 // current file name.
355 // Below is the scenario of Save File command: (
356 // Suppose the old file name is A )
357 // 1. An Input Bar will be prompted: "File To Save: [ old file name]"
358 // IF user press ESC, Save File command ends .
359 // IF user press Enter, input file name will be A.
360 // IF user inputs a new file name B, input file name will be B.
361 //
362 // 2. IF input file name is A, go to do Step 3.
363 // IF input file name is B, go to do Step 4.
364 //
365 // 3. IF A is read only, Status Bar will show "Access Denied"
366 // and Save File commands ends.
367 // IF A is not read only, save file buffer to disk
368 // and remove Modified flag in Title Bar , then Save File command ends.
369 //
370 // 4. IF B does not exist, create this file and save file buffer to it.
371 // Go to do Step 7.
372 // IF B exits, do Step 5.
373 //
374 // 5. An Input Bar will be prompted:
375 // "File Exists. Overwrite ( Yes/No/Cancel ) ?"
376 // IF user press 'y' or 'Y', do Step 6.
377 // IF user press 'n' or 'N', Save File commands ends.
378 // IF user press 'c' or 'C' or ESC, Save File commands ends.
379 //
380 // 6. IF B is a read-only file, Status Bar will show "Access Denied"
381 // and Save File commands ends.
382 // IF B can be read and write, save file buffer to B.
383 //
384 // 7. Update File Name field in Title Bar to B
385 // and remove the Modified flag in Title Bar.
386 //
387 Str = CatSPrint (
388 NULL,
389 L"File to Save: [%s]",
390 HMainEditor.BufferImage->FileImage->FileName
391 );
392 if (Str == NULL) {
393 return EFI_OUT_OF_RESOURCES;
394 }
395
396 if (StrLen (Str) >= 50) {
397 //
398 // replace the long file name with "..."
399 //
400 Str[46] = L'.';
401 Str[47] = L'.';
402 Str[48] = L'.';
403 Str[49] = L']';
404 Str[50] = L'\0';
405 }
406
407 Status = InputBarSetPrompt (Str);
408 if (EFI_ERROR (Status)) {
409 return Status;
410 }
411
412 Status = InputBarSetStringSize (100);
413 if (EFI_ERROR (Status)) {
414 return Status;
415 }
416
417 //
418 // get new file name
419 //
420 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
421
422 //
423 // if user pressed ESC
424 //
425 if (Status == EFI_NOT_READY) {
426 SHELL_FREE_NON_NULL (Str);
427 return EFI_SUCCESS;
428 }
429
430 SHELL_FREE_NON_NULL (Str);
431
432 //
433 // if just enter pressed, so think save to current file name
434 //
435 if (StrLen (InputBarGetString ()) == 0) {
436 FileName = CatSPrint (
437 NULL,
438 L"%s",
439 HMainEditor.BufferImage->FileImage->FileName
440 );
441 } else {
442 FileName = CatSPrint (NULL, L"%s", InputBarGetString ());
443 }
444
445 if (FileName == NULL) {
446 return EFI_OUT_OF_RESOURCES;
447 }
448
449 if (!IsValidFileName (FileName)) {
450 StatusBarSetStatusString (L"Invalid File Name");
451 SHELL_FREE_NON_NULL (FileName);
452 return EFI_SUCCESS;
453 }
454
455 OldFile = FALSE;
456
457 //
458 // save to the old file
459 //
461 &FileName,
462 &HMainEditor.BufferImage->FileImage->FileName
463 ) == 0)
464 {
465 OldFile = TRUE;
466 }
467
468 if (OldFile) {
469 //
470 // if the file is read only, so can not write back to it.
471 //
472 if (HMainEditor.BufferImage->FileImage->ReadOnly) {
473 StatusBarSetStatusString (L"Access Denied");
474 SHELL_FREE_NON_NULL (FileName);
475 return EFI_SUCCESS;
476 }
477 } else {
478 Status = ShellOpenFileByName (FileName, &ShellFileHandle, EFI_FILE_MODE_READ, 0);
479
480 if (!EFI_ERROR (Status)) {
481 Info = ShellGetFileInfo (ShellFileHandle);
482
483 ShellCloseFile (&ShellFileHandle);
484 //
485 // check if read only
486 //
487 if (Info->Attribute & EFI_FILE_READ_ONLY) {
488 StatusBarSetStatusString (L"Access Denied");
489 SHELL_FREE_NON_NULL (FileName);
490 return EFI_SUCCESS;
491 }
492
493 SHELL_FREE_NON_NULL (Info);
494 //
495 // ask user whether to overwrite this file
496 //
497 Status = InputBarSetPrompt (L"File exists. Overwrite (Yes/No/Cancel) ? ");
498 if (EFI_ERROR (Status)) {
499 SHELL_FREE_NON_NULL (FileName);
500 return Status;
501 }
502
503 Status = InputBarSetStringSize (1);
504 if (EFI_ERROR (Status)) {
505 SHELL_FREE_NON_NULL (FileName);
506 return Status;
507 }
508
509 Done = FALSE;
510 while (!Done) {
511 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
512
513 if (Status == EFI_NOT_READY) {
514 SHELL_FREE_NON_NULL (FileName);
515 return EFI_SUCCESS;
516 }
517
518 switch (InputBarGetString ()[0]) {
519 case L'y':
520 case L'Y':
521 Done = TRUE;
522 break;
523 case L'n':
524 case L'N':
525 SHELL_FREE_NON_NULL (FileName);
526 return EFI_SUCCESS;
527 case L'c':
528 case L'C':
529 SHELL_FREE_NON_NULL (FileName);
530 return EFI_SUCCESS;
531 } // switch
532 } // while
533 } // if opened existing file
534 } // if OldFile
535
536 //
537 // save file back to disk
538 //
539 Status = HBufferImageSave (
540 FileName,
541 HMainEditor.BufferImage->DiskImage->Name,
542 HMainEditor.BufferImage->DiskImage->Offset,
543 HMainEditor.BufferImage->DiskImage->Size,
544 HMainEditor.BufferImage->MemImage->Offset,
545 HMainEditor.BufferImage->MemImage->Size,
546 FileTypeFileBuffer
547 );
548 SHELL_FREE_NON_NULL (FileName);
549
550 if (EFI_ERROR (Status)) {
551 return EFI_LOAD_ERROR;
552 }
553
554 return EFI_SUCCESS;
555}
556
566 VOID
567 )
568{
569 UINTN Start;
570
571 Start = (HMainEditor.BufferImage->BufferPosition.Row - 1) * 0x10 + HMainEditor.BufferImage->BufferPosition.Column;
572
573 //
574 // last line
575 //
576 if (HMainEditor.BufferImage->CurrentLine->Link.ForwardLink == HMainEditor.BufferImage->ListHead) {
577 if (HMainEditor.BufferImage->BufferPosition.Column > HMainEditor.BufferImage->CurrentLine->Size) {
578 StatusBarSetStatusString (L"Invalid Block Start");
579 return EFI_LOAD_ERROR;
580 }
581 }
582
583 if ((HMainEditor.SelectEnd != 0) && (Start > HMainEditor.SelectEnd)) {
584 StatusBarSetStatusString (L"Invalid Block Start");
585 return EFI_LOAD_ERROR;
586 }
587
588 HMainEditor.SelectStart = Start;
589
590 HBufferImageNeedRefresh = TRUE;
591
592 return EFI_SUCCESS;
593}
594
604 VOID
605 )
606{
607 UINTN End;
608
609 End = (HMainEditor.BufferImage->BufferPosition.Row - 1) * 0x10 + HMainEditor.BufferImage->BufferPosition.Column;
610
611 //
612 // last line
613 //
614 if (HMainEditor.BufferImage->CurrentLine->Link.ForwardLink == HMainEditor.BufferImage->ListHead) {
615 if (HMainEditor.BufferImage->BufferPosition.Column > HMainEditor.BufferImage->CurrentLine->Size) {
616 StatusBarSetStatusString (L"Invalid Block End");
617 return EFI_LOAD_ERROR;
618 }
619 }
620
621 if ((HMainEditor.SelectStart != 0) && (End < HMainEditor.SelectStart)) {
622 StatusBarSetStatusString (L"Invalid Block End");
623 return EFI_SUCCESS;
624 }
625
626 HMainEditor.SelectEnd = End;
627
628 HBufferImageNeedRefresh = TRUE;
629
630 return EFI_SUCCESS;
631}
632
642 VOID
643 )
644{
645 UINTN Index;
646 LIST_ENTRY *Link;
647 UINT8 *Buffer;
648 UINTN Count;
649
650 //
651 // not select, so not allowed to cut
652 //
653 if (HMainEditor.SelectStart == 0) {
654 StatusBarSetStatusString (L"No Block is Selected");
655 return EFI_SUCCESS;
656 }
657
658 //
659 // not select, so not allowed to cut
660 //
661 if (HMainEditor.SelectEnd == 0) {
662 StatusBarSetStatusString (L"No Block is Selected");
663 return EFI_SUCCESS;
664 }
665
666 Link = HMainEditor.BufferImage->ListHead->ForwardLink;
667 for (Index = 0; Index < (HMainEditor.SelectEnd - 1) / 0x10; Index++) {
668 Link = Link->ForwardLink;
669 }
670
671 Count = HMainEditor.SelectEnd - HMainEditor.SelectStart + 1;
672 Buffer = AllocateZeroPool (Count);
673 if (Buffer == NULL) {
674 return EFI_OUT_OF_RESOURCES;
675 }
676
677 //
678 // cut the selected area
679 //
681 HMainEditor.SelectStart - 1,
682 Count,
683 Buffer
684 );
685
686 //
687 // put to clipboard
688 //
689 HClipBoardSet (Buffer, Count);
690
691 HBufferImageNeedRefresh = TRUE;
692 HBufferImageOnlyLineNeedRefresh = FALSE;
693
694 if (!HMainEditor.BufferImage->Modified) {
695 HMainEditor.BufferImage->Modified = TRUE;
696 }
697
698 //
699 // now no select area
700 //
701 HMainEditor.SelectStart = 0;
702 HMainEditor.SelectEnd = 0;
703
704 return EFI_SUCCESS;
705}
706
716 VOID
717 )
718{
719 BOOLEAN OnlyLineRefresh;
720 HEFI_EDITOR_LINE *Line;
721 UINT8 *Buffer;
722 UINTN Count;
723 UINTN FPos;
724
725 Count = HClipBoardGet (&Buffer);
726 if ((Count == 0) || (Buffer == NULL)) {
727 StatusBarSetStatusString (L"Nothing to Paste");
728 return EFI_SUCCESS;
729 }
730
731 Line = HMainEditor.BufferImage->CurrentLine;
732
733 OnlyLineRefresh = FALSE;
734 if ((Line->Link.ForwardLink == HMainEditor.BufferImage->ListHead) && (Line->Size + Count < 0x10)) {
735 //
736 // is at last line, and after paste will not exceed
737 // so only this line need to be refreshed
738 //
739 // if after add, the line is 0x10, then will append a new line
740 // so the whole page will need be refreshed
741 //
742 OnlyLineRefresh = TRUE;
743 }
744
745 FPos = 0x10 * (HMainEditor.BufferImage->BufferPosition.Row - 1) + HMainEditor.BufferImage->BufferPosition.Column - 1;
746
747 HBufferImageAddCharacterToBuffer (FPos, Count, Buffer);
748
749 if (OnlyLineRefresh) {
750 HBufferImageNeedRefresh = FALSE;
751 HBufferImageOnlyLineNeedRefresh = TRUE;
752 } else {
753 HBufferImageNeedRefresh = TRUE;
754 HBufferImageOnlyLineNeedRefresh = FALSE;
755 }
756
757 if (!HMainEditor.BufferImage->Modified) {
758 HMainEditor.BufferImage->Modified = TRUE;
759 }
760
761 return EFI_SUCCESS;
762}
763
773 VOID
774 )
775{
776 EFI_STATUS Status;
777
778 //
779 // Below is the scenario of Exit command:
780 // 1. IF currently opened file is not modified, exit the editor and
781 // Exit command ends.
782 // IF currently opened file is modified, do Step 2
783 //
784 // 2. An Input Bar will be prompted:
785 // "File modified. Save ( Yes/No/Cancel )?"
786 // IF user press 'y' or 'Y', currently opened file will be saved and
787 // Editor exits
788 // IF user press 'n' or 'N', currently opened file will not be saved
789 // and Editor exits.
790 // IF user press 'c' or 'C' or ESC, Exit command ends.
791 //
792 //
793 // if file has been modified, so will prompt user
794 // whether to save the changes
795 //
796 if (HMainEditor.BufferImage->Modified) {
797 Status = InputBarSetPrompt (L"Buffer modified. Save (Yes/No/Cancel) ? ");
798 if (EFI_ERROR (Status)) {
799 return Status;
800 }
801
802 Status = InputBarSetStringSize (1);
803 if (EFI_ERROR (Status)) {
804 return Status;
805 }
806
807 while (1) {
808 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
809
810 //
811 // ESC pressed
812 //
813 if (Status == EFI_NOT_READY) {
814 return EFI_SUCCESS;
815 }
816
817 switch (InputBarGetString ()[0]) {
818 case L'y':
819 case L'Y':
820 //
821 // write file back to disk
822 //
823 Status = HBufferImageSave (
824 HMainEditor.BufferImage->FileImage->FileName,
825 HMainEditor.BufferImage->DiskImage->Name,
826 HMainEditor.BufferImage->DiskImage->Offset,
827 HMainEditor.BufferImage->DiskImage->Size,
828 HMainEditor.BufferImage->MemImage->Offset,
829 HMainEditor.BufferImage->MemImage->Size,
830 HMainEditor.BufferImage->BufferType
831 );
832 if (!EFI_ERROR (Status)) {
833 HEditorExit = TRUE;
834 }
835
836 return Status;
837
838 case L'n':
839 case L'N':
840 HEditorExit = TRUE;
841 return EFI_SUCCESS;
842
843 case L'c':
844 case L'C':
845 return EFI_SUCCESS;
846 }
847 }
848 }
849
850 HEditorExit = TRUE;
851 return EFI_SUCCESS;
852}
853
863 VOID
864 )
865{
866 BOOLEAN Done;
867 EFI_STATUS Status;
868 EDIT_FILE_TYPE BufferType;
869
870 BufferType = HMainEditor.BufferImage->BufferType;
871
872 //
873 // This command will open a file from current working directory.
874 // Read-only file can also be opened. But it can not be modified.
875 // Below is the scenario of Open File command:
876 // 1. IF currently opened file has not been modified, directly go to step .
877 // IF currently opened file has been modified, an Input Bar will be
878 // prompted as :
879 // "File Modified. Save ( Yes/No/Cancel) ?"
880 // IF user press 'y' or 'Y', currently opened file will be saved.
881 // IF user press 'n' or 'N', currently opened file will
882 // not be saved.
883 // IF user press 'c' or 'C' or ESC, Open File command ends and
884 // currently opened file is still opened.
885 //
886 // 2. An Input Bar will be prompted as : "File Name to Open: "
887 // IF user press ESC, Open File command ends and
888 // currently opened file is still opened.
889 // Any other inputs with a Return will cause
890 // currently opened file close.
891 //
892 // 3. IF user input file name is an existing file ,
893 // this file will be read and opened.
894 // IF user input file name is a new file, this file will be created
895 // and opened. This file's type ( UNICODE or ASCII ) is the same with
896 // the old file.
897 //
898 //
899 // if current file is modified, so you need to choose whether to
900 // save it first.
901 //
902 if (HMainEditor.BufferImage->Modified) {
903 Status = InputBarSetPrompt (L"Buffer modified. Save (Yes/No/Cancel) ? ");
904 if (EFI_ERROR (Status)) {
905 return Status;
906 }
907
908 //
909 // the answer is just one character
910 //
911 Status = InputBarSetStringSize (1);
912 if (EFI_ERROR (Status)) {
913 return Status;
914 }
915
916 //
917 // loop for user's answer
918 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
919 //
920 Done = FALSE;
921 while (!Done) {
922 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
923
924 //
925 // ESC pressed
926 //
927 if (Status == EFI_NOT_READY) {
928 return EFI_SUCCESS;
929 }
930
931 switch (InputBarGetString ()[0]) {
932 case L'y':
933 case L'Y':
934 //
935 // want to save this buffer first
936 //
937 Status = HBufferImageSave (
938 HMainEditor.BufferImage->FileImage->FileName,
939 HMainEditor.BufferImage->DiskImage->Name,
940 HMainEditor.BufferImage->DiskImage->Offset,
941 HMainEditor.BufferImage->DiskImage->Size,
942 HMainEditor.BufferImage->MemImage->Offset,
943 HMainEditor.BufferImage->MemImage->Size,
944 HMainEditor.BufferImage->BufferType
945 );
946 if (EFI_ERROR (Status)) {
947 return Status;
948 }
949
951 HMainEditor.BufferImage->BufferType == FileTypeFileBuffer ? HMainEditor.BufferImage->FileImage->FileName : HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer ? HMainEditor.BufferImage->DiskImage->Name : NULL,
952 HMainEditor.BufferImage->BufferType,
953 HMainEditor.BufferImage->FileImage->ReadOnly,
954 FALSE,
955 HMainEditor.ScreenSize.Column,
956 HMainEditor.ScreenSize.Row,
957 HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer ? HMainEditor.BufferImage->DiskImage->Offset : HMainEditor.BufferImage->BufferType == FileTypeMemBuffer ? HMainEditor.BufferImage->MemImage->Offset : 0,
958 HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer ? HMainEditor.BufferImage->DiskImage->Size : HMainEditor.BufferImage->BufferType == FileTypeMemBuffer ? HMainEditor.BufferImage->MemImage->Size : 0
959 );
960 Done = TRUE;
961 break;
962
963 case L'n':
964 case L'N':
965 //
966 // the file won't be saved
967 //
968 Done = TRUE;
969 break;
970
971 case L'c':
972 case L'C':
973 return EFI_SUCCESS;
974 }
975 }
976 }
977
978 //
979 // TO get the open file name
980 //
981 Status = InputBarSetPrompt (L"File Name to Open: ");
982 if (EFI_ERROR (Status)) {
984 HMainEditor.BufferImage->FileImage->FileName,
985 HMainEditor.BufferImage->DiskImage->Name,
986 HMainEditor.BufferImage->DiskImage->Offset,
987 HMainEditor.BufferImage->DiskImage->Size,
988 HMainEditor.BufferImage->MemImage->Offset,
989 HMainEditor.BufferImage->MemImage->Size,
990 BufferType,
991 TRUE
992 );
993 return Status;
994 }
995
996 Status = InputBarSetStringSize (100);
997 if (EFI_ERROR (Status)) {
998 Status = HBufferImageRead (
999 HMainEditor.BufferImage->FileImage->FileName,
1000 HMainEditor.BufferImage->DiskImage->Name,
1001 HMainEditor.BufferImage->DiskImage->Offset,
1002 HMainEditor.BufferImage->DiskImage->Size,
1003 HMainEditor.BufferImage->MemImage->Offset,
1004 HMainEditor.BufferImage->MemImage->Size,
1005 BufferType,
1006 TRUE
1007 );
1008 return Status;
1009 }
1010
1011 while (1) {
1012 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
1013
1014 //
1015 // ESC pressed
1016 //
1017 if (Status == EFI_NOT_READY) {
1018 Status = HBufferImageRead (
1019 HMainEditor.BufferImage->FileImage->FileName,
1020 HMainEditor.BufferImage->DiskImage->Name,
1021 HMainEditor.BufferImage->DiskImage->Offset,
1022 HMainEditor.BufferImage->DiskImage->Size,
1023 HMainEditor.BufferImage->MemImage->Offset,
1024 HMainEditor.BufferImage->MemImage->Size,
1025 BufferType,
1026 TRUE
1027 );
1028
1029 return Status;
1030 }
1031
1032 //
1033 // THE input string length should > 0
1034 //
1035 if (StrLen (InputBarGetString ()) > 0) {
1036 //
1037 // CHECK if filename's valid
1038 //
1041 HMainEditor.BufferImage->FileImage->FileName,
1042 HMainEditor.BufferImage->DiskImage->Name,
1043 HMainEditor.BufferImage->DiskImage->Offset,
1044 HMainEditor.BufferImage->DiskImage->Size,
1045 HMainEditor.BufferImage->MemImage->Offset,
1046 HMainEditor.BufferImage->MemImage->Size,
1047 BufferType,
1048 TRUE
1049 );
1050
1051 StatusBarSetStatusString (L"Invalid File Name");
1052 return EFI_SUCCESS;
1053 }
1054
1055 break;
1056 }
1057 }
1058
1059 //
1060 // read from disk
1061 //
1062 Status = HBufferImageRead (
1064 HMainEditor.BufferImage->DiskImage->Name,
1065 HMainEditor.BufferImage->DiskImage->Offset,
1066 HMainEditor.BufferImage->DiskImage->Size,
1067 HMainEditor.BufferImage->MemImage->Offset,
1068 HMainEditor.BufferImage->MemImage->Size,
1069 FileTypeFileBuffer,
1070 FALSE
1071 );
1072
1073 if (EFI_ERROR (Status)) {
1075 HMainEditor.BufferImage->FileImage->FileName,
1076 HMainEditor.BufferImage->DiskImage->Name,
1077 HMainEditor.BufferImage->DiskImage->Offset,
1078 HMainEditor.BufferImage->DiskImage->Size,
1079 HMainEditor.BufferImage->MemImage->Offset,
1080 HMainEditor.BufferImage->MemImage->Size,
1081 BufferType,
1082 TRUE
1083 );
1084
1085 return EFI_LOAD_ERROR;
1086 }
1087
1088 return EFI_SUCCESS;
1089}
1090
1101 VOID
1102 )
1103{
1104 UINT64 Size;
1105 UINT64 Offset;
1106 CHAR16 *DeviceName;
1107 EFI_STATUS Status;
1108 BOOLEAN Done;
1109
1110 EDIT_FILE_TYPE BufferType;
1111
1112 //
1113 // variable initialization
1114 //
1115 Size = 0;
1116 Offset = 0;
1117 BufferType = HMainEditor.BufferImage->BufferType;
1118
1119 //
1120 // if current file is modified, so you need to choose
1121 // whether to save it first.
1122 //
1123 if (HMainEditor.BufferImage->Modified) {
1124 Status = InputBarSetPrompt (L"Buffer modified. Save (Yes/No/Cancel) ? ");
1125 if (EFI_ERROR (Status)) {
1126 return Status;
1127 }
1128
1129 //
1130 // the answer is just one character
1131 //
1132 Status = InputBarSetStringSize (1);
1133 if (EFI_ERROR (Status)) {
1134 return Status;
1135 }
1136
1137 //
1138 // loop for user's answer
1139 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1140 //
1141 Done = FALSE;
1142 while (!Done) {
1143 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
1144
1145 //
1146 // ESC pressed
1147 //
1148 if (Status == EFI_NOT_READY) {
1149 return EFI_SUCCESS;
1150 }
1151
1152 switch (InputBarGetString ()[0]) {
1153 case L'y':
1154 case L'Y':
1155 //
1156 // want to save this buffer first
1157 //
1158 Status = HBufferImageSave (
1159 HMainEditor.BufferImage->FileImage->FileName,
1160 HMainEditor.BufferImage->DiskImage->Name,
1161 HMainEditor.BufferImage->DiskImage->Offset,
1162 HMainEditor.BufferImage->DiskImage->Size,
1163 HMainEditor.BufferImage->MemImage->Offset,
1164 HMainEditor.BufferImage->MemImage->Size,
1165 BufferType
1166 );
1167 if (EFI_ERROR (Status)) {
1168 return Status;
1169 }
1170
1172 HMainEditor.BufferImage->BufferType == FileTypeFileBuffer ? HMainEditor.BufferImage->FileImage->FileName : HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer ? HMainEditor.BufferImage->DiskImage->Name : NULL,
1173 HMainEditor.BufferImage->BufferType,
1174 HMainEditor.BufferImage->FileImage->ReadOnly,
1175 FALSE,
1176 HMainEditor.ScreenSize.Column,
1177 HMainEditor.ScreenSize.Row,
1178 HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer ? HMainEditor.BufferImage->DiskImage->Offset : HMainEditor.BufferImage->BufferType == FileTypeMemBuffer ? HMainEditor.BufferImage->MemImage->Offset : 0,
1179 HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer ? HMainEditor.BufferImage->DiskImage->Size : HMainEditor.BufferImage->BufferType == FileTypeMemBuffer ? HMainEditor.BufferImage->MemImage->Size : 0
1180 );
1181 Done = TRUE;
1182 break;
1183
1184 case L'n':
1185 case L'N':
1186 //
1187 // the file won't be saved
1188 //
1189 Done = TRUE;
1190 break;
1191
1192 case L'c':
1193 case L'C':
1194 return EFI_SUCCESS;
1195 }
1196 }
1197 }
1198
1199 //
1200 // get disk block device name
1201 //
1202 Status = InputBarSetPrompt (L"Block Device to Open: ");
1203 if (EFI_ERROR (Status)) {
1204 return Status;
1205 }
1206
1207 Status = InputBarSetStringSize (100);
1208 if (EFI_ERROR (Status)) {
1209 return Status;
1210 }
1211
1212 while (1) {
1213 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
1214
1215 //
1216 // ESC pressed
1217 //
1218 if (Status == EFI_NOT_READY) {
1219 return EFI_SUCCESS;
1220 }
1221
1222 //
1223 // THE input string length should > 0
1224 //
1225 if (StrLen (InputBarGetString ()) > 0) {
1226 break;
1227 }
1228 }
1229
1230 DeviceName = CatSPrint (NULL, L"%s", InputBarGetString ());
1231 if (DeviceName == NULL) {
1232 return EFI_OUT_OF_RESOURCES;
1233 }
1234
1235 //
1236 // get starting offset
1237 //
1238 Status = InputBarSetPrompt (L"First Block No.: ");
1239 if (EFI_ERROR (Status)) {
1240 return Status;
1241 }
1242
1243 Status = InputBarSetStringSize (16);
1244 if (EFI_ERROR (Status)) {
1245 return Status;
1246 }
1247
1248 while (1) {
1249 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
1250
1251 //
1252 // ESC pressed
1253 //
1254 if (Status == EFI_NOT_READY) {
1255 return EFI_SUCCESS;
1256 }
1257
1258 //
1259 // THE input string length should > 0
1260 //
1261 if (StrLen (InputBarGetString ()) > 0) {
1262 Status = ShellConvertStringToUint64 (InputBarGetString (), &Offset, TRUE, FALSE);
1263 if (EFI_ERROR (Status)) {
1264 continue;
1265 }
1266
1267 break;
1268 }
1269 }
1270
1271 //
1272 // get Number of Blocks:
1273 //
1274 Status = InputBarSetPrompt (L"Number of Blocks: ");
1275 if (EFI_ERROR (Status)) {
1276 return Status;
1277 }
1278
1279 Status = InputBarSetStringSize (8);
1280 if (EFI_ERROR (Status)) {
1281 return Status;
1282 }
1283
1284 while (1) {
1285 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
1286
1287 //
1288 // ESC pressed
1289 //
1290 if (Status == EFI_NOT_READY) {
1291 return EFI_SUCCESS;
1292 }
1293
1294 //
1295 // THE input string length should > 0
1296 //
1297 if (StrLen (InputBarGetString ()) > 0) {
1299 if (EFI_ERROR (Status)) {
1300 continue;
1301 }
1302
1303 if (Size == 0) {
1304 continue;
1305 }
1306
1307 break;
1308 }
1309 }
1310
1311 Status = HBufferImageRead (
1312 NULL,
1313 DeviceName,
1314 (UINTN)Offset,
1315 (UINTN)Size,
1316 0,
1317 0,
1318 FileTypeDiskBuffer,
1319 FALSE
1320 );
1321
1322 if (EFI_ERROR (Status)) {
1324 HMainEditor.BufferImage->FileImage->FileName,
1325 HMainEditor.BufferImage->DiskImage->Name,
1326 HMainEditor.BufferImage->DiskImage->Offset,
1327 HMainEditor.BufferImage->DiskImage->Size,
1328 HMainEditor.BufferImage->MemImage->Offset,
1329 HMainEditor.BufferImage->MemImage->Size,
1330 BufferType,
1331 TRUE
1332 );
1333 return EFI_NOT_FOUND;
1334 }
1335
1336 return EFI_SUCCESS;
1337}
1338
1349 VOID
1350 )
1351{
1352 UINT64 Size;
1353 UINT64 Offset;
1354 EFI_STATUS Status;
1355 BOOLEAN Done;
1356 EDIT_FILE_TYPE BufferType;
1357
1358 //
1359 // variable initialization
1360 //
1361 Size = 0;
1362 Offset = 0;
1363 BufferType = HMainEditor.BufferImage->BufferType;
1364
1365 //
1366 // if current buffer is modified, so you need to choose
1367 // whether to save it first.
1368 //
1369 if (HMainEditor.BufferImage->Modified) {
1370 Status = InputBarSetPrompt (L"Buffer modified. Save (Yes/No/Cancel) ? ");
1371 if (EFI_ERROR (Status)) {
1372 return Status;
1373 }
1374
1375 //
1376 // the answer is just one character
1377 //
1378 Status = InputBarSetStringSize (1);
1379 if (EFI_ERROR (Status)) {
1380 return Status;
1381 }
1382
1383 //
1384 // loop for user's answer
1385 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1386 //
1387 Done = FALSE;
1388 while (!Done) {
1389 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
1390
1391 //
1392 // ESC pressed
1393 //
1394 if (Status == EFI_NOT_READY) {
1395 return EFI_SUCCESS;
1396 }
1397
1398 switch (InputBarGetString ()[0]) {
1399 case L'y':
1400 case L'Y':
1401 //
1402 // want to save this buffer first
1403 //
1404 Status = HBufferImageSave (
1405 HMainEditor.BufferImage->FileImage->FileName,
1406 HMainEditor.BufferImage->DiskImage->Name,
1407 HMainEditor.BufferImage->DiskImage->Offset,
1408 HMainEditor.BufferImage->DiskImage->Size,
1409 HMainEditor.BufferImage->MemImage->Offset,
1410 HMainEditor.BufferImage->MemImage->Size,
1411 BufferType
1412 );
1413 if (EFI_ERROR (Status)) {
1414 return Status;
1415 }
1416
1418 HMainEditor.BufferImage->BufferType == FileTypeFileBuffer ? HMainEditor.BufferImage->FileImage->FileName : HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer ? HMainEditor.BufferImage->DiskImage->Name : NULL,
1419 HMainEditor.BufferImage->BufferType,
1420 HMainEditor.BufferImage->FileImage->ReadOnly,
1421 FALSE,
1422 HMainEditor.ScreenSize.Column,
1423 HMainEditor.ScreenSize.Row,
1424 HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer ? HMainEditor.BufferImage->DiskImage->Offset : HMainEditor.BufferImage->BufferType == FileTypeMemBuffer ? HMainEditor.BufferImage->MemImage->Offset : 0,
1425 HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer ? HMainEditor.BufferImage->DiskImage->Size : HMainEditor.BufferImage->BufferType == FileTypeMemBuffer ? HMainEditor.BufferImage->MemImage->Size : 0
1426 );
1427 Done = TRUE;
1428 break;
1429
1430 case L'n':
1431 case L'N':
1432 //
1433 // the file won't be saved
1434 //
1435 Done = TRUE;
1436 break;
1437
1438 case L'c':
1439 case L'C':
1440 return EFI_SUCCESS;
1441 }
1442 }
1443 }
1444
1445 //
1446 // get starting offset
1447 //
1448 Status = InputBarSetPrompt (L"Starting Offset: ");
1449 if (EFI_ERROR (Status)) {
1450 return Status;
1451 }
1452
1453 Status = InputBarSetStringSize (8);
1454 if (EFI_ERROR (Status)) {
1455 return Status;
1456 }
1457
1458 while (1) {
1459 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
1460
1461 //
1462 // ESC pressed
1463 //
1464 if (Status == EFI_NOT_READY) {
1465 return EFI_SUCCESS;
1466 }
1467
1468 //
1469 // THE input string length should > 0
1470 //
1471 if (StrLen (InputBarGetString ()) > 0) {
1472 Status = ShellConvertStringToUint64 (InputBarGetString (), &Offset, TRUE, FALSE);
1473 if (EFI_ERROR (Status)) {
1474 continue;
1475 }
1476
1477 break;
1478 }
1479 }
1480
1481 //
1482 // get Number of Blocks:
1483 //
1484 Status = InputBarSetPrompt (L"Buffer Size: ");
1485 if (EFI_ERROR (Status)) {
1486 return Status;
1487 }
1488
1489 Status = InputBarSetStringSize (8);
1490 if (EFI_ERROR (Status)) {
1491 return Status;
1492 }
1493
1494 while (1) {
1495 Status = InputBarRefresh (HMainEditor.ScreenSize.Row, HMainEditor.ScreenSize.Column);
1496
1497 //
1498 // ESC pressed
1499 //
1500 if (Status == EFI_NOT_READY) {
1501 return EFI_SUCCESS;
1502 }
1503
1504 //
1505 // THE input string length should > 0
1506 //
1507 if (StrLen (InputBarGetString ()) > 0) {
1509 if (EFI_ERROR (Status)) {
1510 continue;
1511 }
1512
1513 if (Size == 0) {
1514 continue;
1515 }
1516
1517 break;
1518 }
1519 }
1520
1521 if ((Offset + Size - 1) > 0xffffffff) {
1522 StatusBarSetStatusString (L"Invalid parameter");
1523 return EFI_LOAD_ERROR;
1524 }
1525
1526 Status = HBufferImageRead (
1527 NULL,
1528 NULL,
1529 0,
1530 0,
1531 (UINTN)Offset,
1532 (UINTN)Size,
1533 FileTypeMemBuffer,
1534 FALSE
1535 );
1536
1537 if (EFI_ERROR (Status)) {
1538 StatusBarSetStatusString (L"Read Device Error!");
1540 HMainEditor.BufferImage->FileImage->FileName,
1541 HMainEditor.BufferImage->DiskImage->Name,
1542 HMainEditor.BufferImage->DiskImage->Offset,
1543 HMainEditor.BufferImage->DiskImage->Size,
1544 HMainEditor.BufferImage->MemImage->Offset,
1545 HMainEditor.BufferImage->MemImage->Size,
1546 BufferType,
1547 TRUE
1548 );
1549 return EFI_NOT_FOUND;
1550 }
1551
1552 return EFI_SUCCESS;
1553}
1554
1555MENU_ITEM_FUNCTION HexMainControlBasedMenuFunctions[] = {
1556 NULL,
1557 NULL, /* Ctrl - A */
1558 NULL, /* Ctrl - B */
1559 NULL, /* Ctrl - C */
1560 HMainCommandSelectEnd, /* Ctrl - D */
1561 HMainCommandDisplayHelp, /* Ctrl - E */
1562 NULL, /* Ctrl - F */
1563 HMainCommandGoToOffset, /* Ctrl - G */
1564 NULL, /* Ctrl - H */
1565 HMainCommandOpenDisk, /* Ctrl - I */
1566 NULL, /* Ctrl - J */
1567 NULL, /* Ctrl - K */
1568 NULL, /* Ctrl - L */
1569 HMainCommandOpenMemory, /* Ctrl - M */
1570 NULL, /* Ctrl - N */
1571 HMainCommandOpenFile, /* Ctrl - O */
1572 NULL, /* Ctrl - P */
1573 HMainCommandExit, /* Ctrl - Q */
1574 NULL, /* Ctrl - R */
1575 HMainCommandSaveBuffer, /* Ctrl - S */
1576 HMainCommandSelectStart, /* Ctrl - T */
1577 NULL, /* Ctrl - U */
1578 HMainCommandPaste, /* Ctrl - V */
1579 NULL, /* Ctrl - W */
1580 HMainCommandCut, /* Ctrl - X */
1581 NULL, /* Ctrl - Y */
1582 NULL, /* Ctrl - Z */
1583};
1584
1585CONST EDITOR_MENU_ITEM HexEditorMenuItems[] = {
1586 {
1587 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_GO_TO_OFFSET),
1588 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F1),
1590 },
1591 {
1592 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_SAVE_BUFFER),
1593 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F2),
1595 },
1596 {
1597 STRING_TOKEN (STR_EDIT_LIBMENUBAR_EXIT),
1598 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F3),
1600 },
1601
1602 {
1603 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_SELECT_START),
1604 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F4),
1606 },
1607 {
1608 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_SELECT_END),
1609 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F5),
1611 },
1612 {
1613 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_CUT),
1614 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F6),
1616 },
1617 {
1618 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_PASTE),
1619 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F7),
1621 },
1622
1623 {
1624 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_OPEN_FILE),
1625 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F8),
1627 },
1628 {
1629 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_OPEN_DISK),
1630 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F9),
1632 },
1633 {
1634 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_OPEN_MEMORY),
1635 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F10),
1637 },
1638
1639 {
1640 0,
1641 0,
1642 NULL
1643 }
1644};
1645
1654 VOID
1655 )
1656{
1657 EFI_STATUS Status;
1658 EFI_HANDLE *HandleBuffer;
1659 UINTN HandleCount;
1660 UINTN Index;
1661
1662 //
1663 // basic initialization
1664 //
1665 CopyMem (&HMainEditor, &HMainEditorConst, sizeof (HMainEditor));
1666
1667 //
1668 // set screen attributes
1669 //
1670 HMainEditor.ColorAttributes.Colors.Foreground = gST->ConOut->Mode->Attribute & 0x000000ff;
1671
1672 HMainEditor.ColorAttributes.Colors.Background = (UINT8)(gST->ConOut->Mode->Attribute >> 4);
1673
1674 HOriginalColors = HMainEditor.ColorAttributes.Colors;
1675
1676 HOriginalMode = gST->ConOut->Mode->Mode;
1677
1678 //
1679 // query screen size
1680 //
1681 gST->ConOut->QueryMode (
1682 gST->ConOut,
1683 gST->ConOut->Mode->Mode,
1684 &(HMainEditor.ScreenSize.Column),
1685 &(HMainEditor.ScreenSize.Row)
1686 );
1687
1688 //
1689 // Find TextInEx in System Table ConsoleInHandle
1690 // Per UEFI Spec, TextInEx is required for a console capable platform.
1691 //
1692 Status = gBS->HandleProtocol (
1694 &gEfiSimpleTextInputExProtocolGuid,
1695 (VOID **)&HMainEditor.TextInputEx
1696 );
1697 if (EFI_ERROR (Status)) {
1698 return Status;
1699 }
1700
1701 //
1702 // Find mouse in System Table ConsoleInHandle
1703 //
1704 Status = gBS->HandleProtocol (
1706 &gEfiSimplePointerProtocolGuid,
1707 (VOID **)&HMainEditor.MouseInterface
1708 );
1709 if (EFI_ERROR (Status)) {
1710 //
1711 // If there is no Simple Pointer Protocol on System Table
1712 //
1713 HandleBuffer = NULL;
1714 HMainEditor.MouseInterface = NULL;
1715 Status = gBS->LocateHandleBuffer (
1716 ByProtocol,
1717 &gEfiSimplePointerProtocolGuid,
1718 NULL,
1719 &HandleCount,
1720 &HandleBuffer
1721 );
1722 if (!EFI_ERROR (Status) && (HandleCount > 0)) {
1723 //
1724 // Try to find the first available mouse device
1725 //
1726 for (Index = 0; Index < HandleCount; Index++) {
1727 Status = gBS->HandleProtocol (
1728 HandleBuffer[Index],
1729 &gEfiSimplePointerProtocolGuid,
1730 (VOID **)&HMainEditor.MouseInterface
1731 );
1732 if (!EFI_ERROR (Status)) {
1733 break;
1734 }
1735 }
1736 }
1737
1738 if (HandleBuffer != NULL) {
1739 FreePool (HandleBuffer);
1740 }
1741 }
1742
1743 if (!EFI_ERROR (Status) && (HMainEditor.MouseInterface != NULL)) {
1744 HMainEditor.MouseAccumulatorX = 0;
1745 HMainEditor.MouseAccumulatorY = 0;
1746 HMainEditor.MouseSupported = TRUE;
1747 }
1748
1749 //
1750 // below will call the five components' init function
1751 //
1752 Status = MainTitleBarInit (L"UEFI HEXEDIT");
1753 if (EFI_ERROR (Status)) {
1754 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_TITLE), gShellDebug1HiiHandle);
1755 return EFI_LOAD_ERROR;
1756 }
1757
1758 Status = ControlHotKeyInit (HexMainControlBasedMenuFunctions);
1759 if (EFI_ERROR (Status)) {
1760 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU), gShellDebug1HiiHandle);
1761 return EFI_LOAD_ERROR;
1762 }
1763
1764 Status = MenuBarInit (HexEditorMenuItems);
1765 if (EFI_ERROR (Status)) {
1766 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU), gShellDebug1HiiHandle);
1767 return EFI_LOAD_ERROR;
1768 }
1769
1770 Status = StatusBarInit ();
1771 if (EFI_ERROR (Status)) {
1772 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_STATUS), gShellDebug1HiiHandle);
1773 return EFI_LOAD_ERROR;
1774 }
1775
1776 InputBarInit (HMainEditor.TextInputEx);
1777
1778 Status = HBufferImageInit ();
1779 if (EFI_ERROR (Status)) {
1780 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_BUFFERIMAGE), gShellDebug1HiiHandle);
1781 return EFI_LOAD_ERROR;
1782 }
1783
1784 Status = HClipBoardInit ();
1785 if (EFI_ERROR (Status)) {
1786 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_CLIPBOARD), gShellDebug1HiiHandle);
1787 return EFI_LOAD_ERROR;
1788 }
1789
1790 //
1791 // clear whole screen and enable cursor
1792 //
1793 gST->ConOut->ClearScreen (gST->ConOut);
1794 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
1795
1796 //
1797 // initialize EditorFirst and EditorExit
1798 //
1799 HEditorFirst = TRUE;
1800 HEditorExit = FALSE;
1801 HEditorMouseAction = FALSE;
1802
1803 return EFI_SUCCESS;
1804}
1805
1814 VOID
1815 )
1816{
1817 EFI_STATUS Status;
1818
1819 //
1820 // call the five components' cleanup function
1821 //
1823
1824 MenuBarCleanup ();
1825
1827
1828 InputBarCleanup ();
1829
1830 Status = HBufferImageCleanup ();
1831 if (EFI_ERROR (Status)) {
1832 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_BUFFERIMAGE_CLEAN), gShellDebug1HiiHandle);
1833 }
1834
1835 Status = HClipBoardCleanup ();
1836 if (EFI_ERROR (Status)) {
1837 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_CLIPBOARD_CLEAN), gShellDebug1HiiHandle);
1838 }
1839
1840 //
1841 // restore old mode
1842 //
1843 if (HOriginalMode != gST->ConOut->Mode->Mode) {
1844 gST->ConOut->SetMode (gST->ConOut, HOriginalMode);
1845 }
1846
1847 gST->ConOut->SetAttribute (
1848 gST->ConOut,
1849 EFI_TEXT_ATTR (HOriginalColors.Foreground, HOriginalColors.Background)
1850 );
1851 gST->ConOut->ClearScreen (gST->ConOut);
1852
1853 return EFI_SUCCESS;
1854}
1855
1863 VOID
1864 )
1865{
1866 BOOLEAN NameChange;
1867 BOOLEAN ReadChange;
1868
1869 NameChange = FALSE;
1870 ReadChange = FALSE;
1871
1872 if (HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer) {
1873 if ((HMainEditor.BufferImage->DiskImage != NULL) &&
1874 (HBufferImageBackupVar.DiskImage != NULL) &&
1875 ((HMainEditor.BufferImage->DiskImage->Offset != HBufferImageBackupVar.DiskImage->Offset) ||
1876 (HMainEditor.BufferImage->DiskImage->Size != HBufferImageBackupVar.DiskImage->Size)))
1877 {
1878 NameChange = TRUE;
1879 }
1880 } else if (HMainEditor.BufferImage->BufferType == FileTypeMemBuffer) {
1881 if ((HMainEditor.BufferImage->MemImage != NULL) &&
1882 (HBufferImageBackupVar.MemImage != NULL) &&
1883 ((HMainEditor.BufferImage->MemImage->Offset != HBufferImageBackupVar.MemImage->Offset) ||
1884 (HMainEditor.BufferImage->MemImage->Size != HBufferImageBackupVar.MemImage->Size)))
1885 {
1886 NameChange = TRUE;
1887 }
1888 } else if (HMainEditor.BufferImage->BufferType == FileTypeFileBuffer) {
1889 if ((HMainEditor.BufferImage->FileImage != NULL) &&
1890 (HMainEditor.BufferImage->FileImage->FileName != NULL) &&
1891 (HBufferImageBackupVar.FileImage != NULL) &&
1892 (HBufferImageBackupVar.FileImage->FileName != NULL) &&
1893 (StrCmp (HMainEditor.BufferImage->FileImage->FileName, HBufferImageBackupVar.FileImage->FileName) != 0))
1894 {
1895 NameChange = TRUE;
1896 }
1897 }
1898
1899 if ((HMainEditor.BufferImage->FileImage != NULL) &&
1900 (HBufferImageBackupVar.FileImage != NULL) &&
1901 (HMainEditor.BufferImage->FileImage->ReadOnly != HBufferImageBackupVar.FileImage->ReadOnly))
1902 {
1903 ReadChange = TRUE;
1904 }
1905
1906 //
1907 // to aVOID screen flicker
1908 // the stall value is from experience
1909 //
1910 gBS->Stall (50);
1911
1912 //
1913 // call the components refresh function
1914 //
1915 if ( HEditorFirst
1916 || NameChange
1917 || (HMainEditor.BufferImage->BufferType != HBufferImageBackupVar.BufferType)
1918 || (HBufferImageBackupVar.Modified != HMainEditor.BufferImage->Modified)
1919 || ReadChange )
1920 {
1922 HMainEditor.BufferImage->BufferType == FileTypeFileBuffer && HMainEditor.BufferImage->FileImage != NULL ? HMainEditor.BufferImage->FileImage->FileName : HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer && HMainEditor.BufferImage->DiskImage != NULL ? HMainEditor.BufferImage->DiskImage->Name : NULL,
1923 HMainEditor.BufferImage->BufferType,
1924 (BOOLEAN)(HMainEditor.BufferImage->FileImage != NULL ? HMainEditor.BufferImage->FileImage->ReadOnly : FALSE),
1925 HMainEditor.BufferImage->Modified,
1926 HMainEditor.ScreenSize.Column,
1927 HMainEditor.ScreenSize.Row,
1928 HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer && HMainEditor.BufferImage->DiskImage != NULL ? HMainEditor.BufferImage->DiskImage->Offset : HMainEditor.BufferImage->BufferType == FileTypeMemBuffer && HMainEditor.BufferImage->MemImage != NULL ? HMainEditor.BufferImage->MemImage->Offset : 0,
1929 HMainEditor.BufferImage->BufferType == FileTypeDiskBuffer && HMainEditor.BufferImage->DiskImage != NULL ? HMainEditor.BufferImage->DiskImage->Size : HMainEditor.BufferImage->BufferType == FileTypeMemBuffer && HMainEditor.BufferImage->MemImage != NULL ? HMainEditor.BufferImage->MemImage->Size : 0
1930 );
1932 }
1933
1934 if ( HEditorFirst
1935 || (HBufferImageBackupVar.DisplayPosition.Row != HMainEditor.BufferImage->DisplayPosition.Row)
1936 || (HBufferImageBackupVar.DisplayPosition.Column != HMainEditor.BufferImage->DisplayPosition.Column)
1937 || StatusBarGetRefresh ())
1938 {
1940 HEditorFirst,
1941 HMainEditor.ScreenSize.Row,
1942 HMainEditor.ScreenSize.Column,
1943 (UINTN)(-1),
1944 (UINTN)(-1),
1945 FALSE
1946 );
1948 }
1949
1950 if (HEditorFirst) {
1952 }
1953
1954 //
1955 // EditorFirst is now set to FALSE
1956 //
1957 HEditorFirst = FALSE;
1958
1959 return EFI_SUCCESS;
1960}
1961
1975 IN EFI_SIMPLE_POINTER_STATE MouseState,
1976 OUT BOOLEAN *BeforeLeftButtonDown
1977 )
1978{
1979 INT32 TextX;
1980 INT32 TextY;
1981 UINTN FRow;
1982 UINTN FCol;
1983 BOOLEAN HighBits;
1984 LIST_ENTRY *Link;
1985 HEFI_EDITOR_LINE *Line;
1986 UINTN Index;
1987 BOOLEAN Action;
1988
1989 Action = FALSE;
1990
1991 //
1992 // have mouse movement
1993 //
1994 if (MouseState.RelativeMovementX || MouseState.RelativeMovementY) {
1995 //
1996 // handle
1997 //
1998 TextX = HGetTextX (MouseState.RelativeMovementX);
1999 TextY = HGetTextY (MouseState.RelativeMovementY);
2000
2001 HBufferImageAdjustMousePosition (TextX, TextY);
2002
2003 Action = TRUE;
2004 }
2005
2006 if (MouseState.LeftButton) {
2007 HighBits = HBufferImageIsAtHighBits (
2008 HMainEditor.BufferImage->MousePosition.Column,
2009 &FCol
2010 );
2011
2012 //
2013 // not at an movable place
2014 //
2015 if (FCol == 0) {
2016 //
2017 // now just move mouse pointer to legal position
2018 //
2019 //
2020 // move mouse position to legal position
2021 //
2022 HMainEditor.BufferImage->MousePosition.Column -= 10;
2023 if (HMainEditor.BufferImage->MousePosition.Column > 24) {
2024 HMainEditor.BufferImage->MousePosition.Column--;
2025 FCol = HMainEditor.BufferImage->MousePosition.Column / 3 + 1 + 1;
2026 } else {
2027 if (HMainEditor.BufferImage->MousePosition.Column < 24) {
2028 FCol = HMainEditor.BufferImage->MousePosition.Column / 3 + 1 + 1;
2029 } else {
2030 //
2031 // == 24
2032 //
2033 FCol = 9;
2034 }
2035 }
2036
2037 HighBits = TRUE;
2038 }
2039
2040 FRow = HMainEditor.BufferImage->BufferPosition.Row +
2041 HMainEditor.BufferImage->MousePosition.Row -
2042 HMainEditor.BufferImage->DisplayPosition.Row;
2043
2044 if (HMainEditor.BufferImage->NumLines < FRow) {
2045 //
2046 // dragging
2047 //
2048 //
2049 // now just move mouse pointer to legal position
2050 //
2051 FRow = HMainEditor.BufferImage->NumLines;
2052 HighBits = TRUE;
2053 }
2054
2055 Link = HMainEditor.BufferImage->ListHead->ForwardLink;
2056 for (Index = 0; Index < FRow - 1; Index++) {
2057 Link = Link->ForwardLink;
2058 }
2059
2060 Line = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
2061
2062 //
2063 // dragging
2064 //
2065 //
2066 // now just move mouse pointer to legal position
2067 //
2068 if (FCol > Line->Size) {
2069 if (*BeforeLeftButtonDown) {
2070 HighBits = FALSE;
2071
2072 if (Line->Size == 0) {
2073 if (FRow > 1) {
2074 FRow--;
2075 FCol = 16;
2076 } else {
2077 FRow = 1;
2078 FCol = 1;
2079 }
2080 } else {
2081 FCol = Line->Size;
2082 }
2083 } else {
2084 FCol = Line->Size + 1;
2085 HighBits = TRUE;
2086 }
2087 }
2088
2089 HBufferImageMovePosition (FRow, FCol, HighBits);
2090
2091 HMainEditor.BufferImage->MousePosition.Row = HMainEditor.BufferImage->DisplayPosition.Row;
2092
2093 HMainEditor.BufferImage->MousePosition.Column = HMainEditor.BufferImage->DisplayPosition.Column;
2094
2095 *BeforeLeftButtonDown = TRUE;
2096
2097 Action = TRUE;
2098 } else {
2099 //
2100 // else of if LButton
2101 //
2102 // release LButton
2103 //
2104 if (*BeforeLeftButtonDown) {
2105 Action = TRUE;
2106 }
2107
2108 //
2109 // mouse up
2110 //
2111 *BeforeLeftButtonDown = FALSE;
2112 }
2113
2114 if (Action) {
2115 return EFI_SUCCESS;
2116 }
2117
2118 return EFI_NOT_FOUND;
2119}
2120
2130 VOID
2131 )
2132{
2133 EFI_KEY_DATA KeyData;
2134 EFI_STATUS Status;
2135 EFI_SIMPLE_POINTER_STATE MouseState;
2136 BOOLEAN NoShiftState;
2137 BOOLEAN LengthChange;
2138 UINTN Size;
2139 UINTN OldSize;
2140 BOOLEAN BeforeMouseIsDown;
2141 BOOLEAN MouseIsDown;
2142 BOOLEAN FirstDown;
2143 BOOLEAN MouseDrag;
2144 UINTN FRow;
2145 UINTN FCol;
2146 UINTN SelectStartBackup;
2147 UINTN SelectEndBackup;
2148
2149 //
2150 // variable initialization
2151 //
2152 OldSize = 0;
2153 FRow = 0;
2154 FCol = 0;
2155 LengthChange = FALSE;
2156
2157 MouseIsDown = FALSE;
2158 FirstDown = FALSE;
2159 MouseDrag = FALSE;
2160
2161 do {
2162 Status = EFI_SUCCESS;
2163
2164 HEditorMouseAction = FALSE;
2165
2166 //
2167 // backup some key elements, so that can aVOID some refresh work
2168 //
2170
2171 //
2172 // wait for user key input
2173 //
2174 //
2175 // change priority of checking mouse/keyboard activity dynamically
2176 // so prevent starvation of keyboard.
2177 // if last time, mouse moves then this time check keyboard
2178 //
2179 if (HMainEditor.MouseSupported) {
2180 Status = HMainEditor.MouseInterface->GetState (
2181 HMainEditor.MouseInterface,
2182 &MouseState
2183 );
2184 if (!EFI_ERROR (Status)) {
2185 BeforeMouseIsDown = MouseIsDown;
2186
2187 Status = HMainEditorHandleMouseInput (MouseState, &MouseIsDown);
2188
2189 if (!EFI_ERROR (Status)) {
2190 if (!BeforeMouseIsDown) {
2191 //
2192 // mouse down
2193 //
2194 if (MouseIsDown) {
2195 FRow = HBufferImage.BufferPosition.Row;
2196 FCol = HBufferImage.BufferPosition.Column;
2197 SelectStartBackup = HMainEditor.SelectStart;
2198 SelectEndBackup = HMainEditor.SelectEnd;
2199
2200 FirstDown = TRUE;
2201 }
2202 } else {
2203 SelectStartBackup = HMainEditor.SelectStart;
2204 SelectEndBackup = HMainEditor.SelectEnd;
2205
2206 //
2207 // begin to drag
2208 //
2209 if (MouseIsDown) {
2210 if (FirstDown) {
2211 if (MouseState.RelativeMovementX || MouseState.RelativeMovementY) {
2212 HMainEditor.SelectStart = 0;
2213 HMainEditor.SelectEnd = 0;
2214 HMainEditor.SelectStart = (FRow - 1) * 0x10 + FCol;
2215
2216 MouseDrag = TRUE;
2217 FirstDown = FALSE;
2218 }
2219 } else {
2220 if ((
2221 (HBufferImage.BufferPosition.Row - 1) *
2222 0x10 +
2223 HBufferImage.BufferPosition.Column
2224 ) >= HMainEditor.SelectStart
2225 )
2226 {
2227 HMainEditor.SelectEnd = (HBufferImage.BufferPosition.Row - 1) *
2228 0x10 +
2229 HBufferImage.BufferPosition.Column;
2230 } else {
2231 HMainEditor.SelectEnd = 0;
2232 }
2233 }
2234
2235 //
2236 // end of if RelativeX/Y
2237 //
2238 } else {
2239 //
2240 // mouse is up
2241 //
2242 if (MouseDrag) {
2243 if (HBufferImageGetTotalSize () == 0) {
2244 HMainEditor.SelectStart = 0;
2245 HMainEditor.SelectEnd = 0;
2246 FirstDown = FALSE;
2247 MouseDrag = FALSE;
2248 }
2249
2250 if ((
2251 (HBufferImage.BufferPosition.Row - 1) *
2252 0x10 +
2253 HBufferImage.BufferPosition.Column
2254 ) >= HMainEditor.SelectStart
2255 )
2256 {
2257 HMainEditor.SelectEnd = (HBufferImage.BufferPosition.Row - 1) *
2258 0x10 +
2259 HBufferImage.BufferPosition.Column;
2260 } else {
2261 HMainEditor.SelectEnd = 0;
2262 }
2263
2264 if (HMainEditor.SelectEnd == 0) {
2265 HMainEditor.SelectStart = 0;
2266 }
2267 }
2268
2269 FirstDown = FALSE;
2270 MouseDrag = FALSE;
2271 }
2272
2273 if ((SelectStartBackup != HMainEditor.SelectStart) || (SelectEndBackup != HMainEditor.SelectEnd)) {
2274 if ((SelectStartBackup - 1) / 0x10 != (HMainEditor.SelectStart - 1) / 0x10) {
2275 HBufferImageNeedRefresh = TRUE;
2276 } else {
2277 if ((SelectEndBackup - 1) / 0x10 != (HMainEditor.SelectEnd - 1) / 0x10) {
2278 HBufferImageNeedRefresh = TRUE;
2279 } else {
2280 HBufferImageOnlyLineNeedRefresh = TRUE;
2281 }
2282 }
2283 }
2284 }
2285
2286 HEditorMouseAction = TRUE;
2287 HBufferImageMouseNeedRefresh = TRUE;
2288 } else if (Status == EFI_LOAD_ERROR) {
2289 StatusBarSetStatusString (L"Invalid Mouse Movement ");
2290 }
2291 }
2292 }
2293
2294 //
2295 // CheckEvent() returns Success when non-partial key is pressed.
2296 //
2297 Status = gBS->CheckEvent (HMainEditor.TextInputEx->WaitForKeyEx);
2298 if (!EFI_ERROR (Status)) {
2299 Status = HMainEditor.TextInputEx->ReadKeyStrokeEx (HMainEditor.TextInputEx, &KeyData);
2300 if (!EFI_ERROR (Status)) {
2301 //
2302 // dispatch to different components' key handling function
2303 // so not everywhere has to set this variable
2304 //
2305 HBufferImageMouseNeedRefresh = TRUE;
2306
2307 //
2308 // clear previous status string
2309 //
2311 //
2312 // NoShiftState: TRUE when no shift key is pressed.
2313 //
2314 NoShiftState = ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) || (KeyData.KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID);
2315 //
2316 // dispatch to different components' key handling function
2317 //
2318 if (EFI_SUCCESS == MenuBarDispatchControlHotKey (&KeyData)) {
2319 Status = EFI_SUCCESS;
2320 } else if (NoShiftState && (KeyData.Key.ScanCode == SCAN_NULL)) {
2321 Status = HBufferImageHandleInput (&KeyData.Key);
2322 } else if (NoShiftState && ((KeyData.Key.ScanCode >= SCAN_UP) && (KeyData.Key.ScanCode <= SCAN_PAGE_DOWN))) {
2323 Status = HBufferImageHandleInput (&KeyData.Key);
2324 } else if (NoShiftState && ((KeyData.Key.ScanCode >= SCAN_F1) && (KeyData.Key.ScanCode <= SCAN_F12))) {
2325 Status = MenuBarDispatchFunctionKey (&KeyData.Key);
2326 } else {
2327 StatusBarSetStatusString (L"Unknown Command");
2328
2329 HBufferImageMouseNeedRefresh = FALSE;
2330 }
2331
2332 if ((Status != EFI_SUCCESS) && (Status != EFI_OUT_OF_RESOURCES)) {
2333 //
2334 // not already has some error status
2335 //
2336 if (StrCmp (L"", StatusBarGetString ()) == 0) {
2337 StatusBarSetStatusString (L"Disk Error. Try Again");
2338 }
2339 }
2340 }
2341
2342 //
2343 // decide if has to set length warning
2344 //
2345 if (HBufferImage.BufferType != HBufferImageBackupVar.BufferType) {
2346 LengthChange = FALSE;
2347 } else {
2348 //
2349 // still the old buffer
2350 //
2351 if (HBufferImage.BufferType != FileTypeFileBuffer) {
2352 Size = HBufferImageGetTotalSize ();
2353
2354 switch (HBufferImage.BufferType) {
2355 case FileTypeDiskBuffer:
2356 OldSize = HBufferImage.DiskImage->Size * HBufferImage.DiskImage->BlockSize;
2357 break;
2358
2359 case FileTypeMemBuffer:
2360 OldSize = HBufferImage.MemImage->Size;
2361 break;
2362
2363 default:
2364 OldSize = 0;
2365 break;
2366 }
2367
2368 if (!LengthChange) {
2369 if (OldSize != Size) {
2370 StatusBarSetStatusString (L"Disk/Mem Buffer Length should not be changed");
2371 }
2372 }
2373
2374 if (OldSize != Size) {
2375 LengthChange = TRUE;
2376 } else {
2377 LengthChange = FALSE;
2378 }
2379 }
2380 }
2381 }
2382
2383 //
2384 // after handling, refresh editor
2385 //
2387 } while (Status != EFI_OUT_OF_RESOURCES && !HEditorExit);
2388
2389 return Status;
2390}
2391
2395VOID
2397 VOID
2398 )
2399{
2400 HMainEditorBackupVar.SelectStart = HMainEditor.SelectStart;
2401 HMainEditorBackupVar.SelectEnd = HMainEditor.SelectEnd;
2403}
UINT64 UINTN
INT64 INTN
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
UINT32 EFIAPI ModU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: ModU64x32.c:29
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS HBufferImageHandleInput(IN EFI_INPUT_KEY *Key)
Definition: BufferImage.c:2387
VOID HBufferImageAdjustMousePosition(IN INT32 TextX, IN INT32 TextY)
Definition: BufferImage.c:2291
EFI_STATUS HBufferImageRefresh(VOID)
Definition: BufferImage.c:740
EFI_STATUS HBufferImageAddCharacterToBuffer(IN UINTN Pos, IN UINTN Count, IN UINT8 *AddBuffer)
Definition: BufferImage.c:2018
EFI_STATUS HBufferImageRead(IN CONST CHAR16 *FileName, IN CONST CHAR16 *DiskName, IN UINTN DiskOffset, IN UINTN DiskSize, IN UINTN MemOffset, IN UINTN MemSize, IN EDIT_FILE_TYPE BufferType, IN BOOLEAN Recover)
Definition: BufferImage.c:909
UINTN HBufferImageGetTotalSize(VOID)
Definition: BufferImage.c:1850
EFI_STATUS HBufferImageSave(IN CHAR16 *FileName, IN CHAR16 *DiskName, IN UINTN DiskOffset, IN UINTN DiskSize, IN UINTN MemOffset, IN UINTN MemSize, IN EDIT_FILE_TYPE BufferType)
Definition: BufferImage.c:976
EFI_STATUS HBufferImageBackup(VOID)
Definition: BufferImage.c:141
BOOLEAN HBufferImageIsAtHighBits(IN UINTN Column, OUT UINTN *FCol)
Definition: BufferImage.c:425
VOID HBufferImageMovePosition(IN UINTN NewFilePosRow, IN UINTN NewFilePosCol, IN BOOLEAN HighBits)
Definition: BufferImage.c:1419
EFI_STATUS HBufferImageDeleteCharacterFromBuffer(IN UINTN Pos, IN UINTN Count, OUT UINT8 *DeleteBuffer)
Definition: BufferImage.c:1889
EFI_STATUS HBufferImageInit(VOID)
Definition: BufferImage.c:78
EFI_STATUS HBufferImageCleanup(VOID)
Definition: BufferImage.c:211
UINTN HClipBoardGet(OUT UINT8 **Buffer)
Definition: Clipboard.c:95
EFI_STATUS HClipBoardInit(VOID)
Definition: Clipboard.c:33
EFI_STATUS HClipBoardSet(IN UINT8 *Buffer, IN UINTN Size)
Definition: Clipboard.c:70
EFI_STATUS HClipBoardCleanup(VOID)
Definition: Clipboard.c:52
VOID InputBarCleanup(VOID)
Definition: EditInputBar.c:37
EFI_STATUS InputBarSetPrompt(IN CONST CHAR16 *Str)
Definition: EditInputBar.c:267
EFI_STATUS InputBarSetStringSize(UINTN Size)
Definition: EditInputBar.c:293
EFI_STATUS InputBarRefresh(UINTN LastRow, UINTN LastColumn)
Definition: EditInputBar.c:118
CONST CHAR16 * InputBarGetString(VOID)
Definition: EditInputBar.c:318
VOID InputBarInit(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx)
Definition: EditInputBar.c:23
EFI_STATUS MenuBarDispatchFunctionKey(IN CONST EFI_INPUT_KEY *Key)
Definition: EditMenuBar.c:146
EFI_STATUS MenuBarDispatchControlHotKey(IN CONST EFI_KEY_DATA *KeyData)
Definition: EditMenuBar.c:175
VOID MenuBarCleanup(VOID)
Definition: EditMenuBar.c:21
EFI_STATUS MenuBarInit(IN CONST EDITOR_MENU_ITEM *Items)
Definition: EditMenuBar.c:37
EFI_STATUS ControlHotKeyInit(IN MENU_ITEM_FUNCTION *Items)
Definition: EditMenuBar.c:63
VOID StatusBarSetRefresh(VOID)
EFI_STATUS StatusBarRefresh(IN BOOLEAN EditorFirst, IN UINTN LastRow, IN UINTN LastCol, IN UINTN FileRow, IN UINTN FileCol, IN BOOLEAN InsertMode)
Definition: EditStatusBar.c:79
EFI_STATUS StatusBarSetStatusString(IN CHAR16 *Str)
CONST CHAR16 * StatusBarGetString(VOID)
BOOLEAN StatusBarGetRefresh(VOID)
EFI_STATUS StatusBarInit(VOID)
Definition: EditStatusBar.c:24
VOID StatusBarCleanup(VOID)
Definition: EditStatusBar.c:45
EFI_STATUS MainTitleBarInit(CONST CHAR16 *Prompt)
Definition: EditTitleBar.c:24
EFI_STATUS MainTitleBarRefresh(IN CONST CHAR16 *FileName OPTIONAL, IN CONST EDIT_FILE_TYPE FileType, IN CONST BOOLEAN ReadOnly, IN CONST BOOLEAN Modified, IN CONST UINTN LastCol, IN CONST UINTN LastRow, IN CONST UINTN Offset, IN CONST UINTN Size)
Definition: EditTitleBar.c:82
VOID MainTitleBarCleanup(VOID)
Definition: EditTitleBar.c:49
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STRING EFIAPI HiiGetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:211
EFI_STATUS HMainCommandCut(VOID)
EFI_STATUS HMainCommandDisplayHelp(VOID)
Definition: MainHexEditor.c:98
EFI_STATUS HMainCommandGoToOffset(VOID)
EFI_STATUS HMainEditorKeyInput(VOID)
VOID HMainEditorBackup(VOID)
EFI_STATUS HMainEditorRefresh(VOID)
EFI_STATUS HMainCommandOpenDisk(VOID)
EFI_STATUS HMainCommandExit(VOID)
EFI_STATUS HMainCommandOpenFile(VOID)
EFI_STATUS HMainEditorCleanup(VOID)
EFI_STATUS HMainCommandSaveBuffer(VOID)
EFI_STATUS HMainEditorHandleMouseInput(IN EFI_SIMPLE_POINTER_STATE MouseState, OUT BOOLEAN *BeforeLeftButtonDown)
EFI_STATUS HMainEditorInit(VOID)
EFI_STATUS HMainCommandSelectEnd(VOID)
EFI_STRING_ID HexMainMenuHelpInfo[]
Definition: MainHexEditor.c:65
EFI_STATUS HMainCommandOpenMemory(VOID)
EFI_STATUS HMainCommandSelectStart(VOID)
EFI_STATUS HMainCommandPaste(VOID)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define CR(Record, TYPE, Field, TestSignature)
Definition: DebugLib.h:659
EFI_FILE_INFO *EFIAPI ShellGetFileInfo(IN SHELL_FILE_HANDLE FileHandle)
Definition: UefiShellLib.c:573
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
EFI_STATUS EFIAPI ShellOpenFileByName(IN CONST CHAR16 *FileName, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
Definition: UefiShellLib.c:720
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
EFI_STATUS EFIAPI ShellConvertStringToUint64(IN CONST CHAR16 *String, OUT UINT64 *Value, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
EFI_STATUS EFIAPI ShellCloseFile(IN SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:969
INT32 HGetTextY(IN INT32 GuidY)
Definition: Misc.c:241
INT32 HGetTextX(IN INT32 GuidX)
Definition: Misc.c:220
INTN EFIAPI StringNoCaseCompare(IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
Definition: BaseSortLib.c:92
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
CHAR16 *EFIAPI CatSPrint(IN CHAR16 *String OPTIONAL, IN CONST CHAR16 *FormatString,...)
Definition: UefiLibPrint.c:827
BOOLEAN IsValidFileName(IN CONST CHAR16 *Name)
@ ByProtocol
Definition: UefiSpec.h:1518
UINT32 KeyShiftState
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode
UINT64 Attribute
Definition: FileInfo.h:47
EFI_INPUT_KEY Key
EFI_KEY_STATE KeyState
EFI_HANDLE ConsoleInHandle
Definition: UefiSpec.h:2048
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064