2 Defines the Main Editor data type -
4 - Instances of the other objects of the editor
7 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include "HexEditor.h"
13 #include "EditStatusBar.h"
14 #include "EditInputBar.h"
16 HEFI_EDITOR_COLOR_ATTRIBUTES HOriginalColors
;
20 // the first time editor launch
25 // it's time editor should exit
29 BOOLEAN HEditorMouseAction
;
31 extern HEFI_EDITOR_BUFFER_IMAGE HBufferImage
;
32 extern HEFI_EDITOR_BUFFER_IMAGE HBufferImageBackupVar
;
34 extern BOOLEAN HBufferImageMouseNeedRefresh
;
35 extern BOOLEAN HBufferImageNeedRefresh
;
36 extern BOOLEAN HBufferImageOnlyLineNeedRefresh
;
38 HEFI_EDITOR_GLOBAL_EDITOR HMainEditor
;
39 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorBackupVar
;
42 // basic initialization for MainEditor
44 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorConst
= {
63 Help info that will be displayed.
65 EFI_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
),
95 @retval EFI_SUCCESS The operation was successful.
98 HMainCommandDisplayHelp (
104 EFI_KEY_DATA KeyData
;
111 for (CurrentLine
= 0; 0 != HexMainMenuHelpInfo
[CurrentLine
]; CurrentLine
++) {
112 InfoString
= HiiGetString (
113 gShellDebug1HiiHandle
,
114 HexMainMenuHelpInfo
[CurrentLine
]
118 ShellPrintEx (0, CurrentLine
+1, L
"%E%s%N", InfoString
);
125 Status
= gBS
->WaitForEvent (1, &HMainEditor
.TextInputEx
->WaitForKeyEx
, &EventIndex
);
126 if (EFI_ERROR (Status
) || (EventIndex
!= 0)) {
130 Status
= HMainEditor
.TextInputEx
->ReadKeyStrokeEx (HMainEditor
.TextInputEx
, &KeyData
);
131 if (EFI_ERROR (Status
)) {
135 if (((KeyData
.KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) == 0) ||
136 (KeyData
.KeyState
.KeyShiftState
== EFI_SHIFT_STATE_VALID
))
139 // For consoles that don't support/report shift state,
140 // CTRL+W is translated to L'W' - L'A' + 1.
142 if (KeyData
.Key
.UnicodeChar
== L
'W' - L
'A' + 1) {
145 } else if (((KeyData
.KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) != 0) &&
146 ((KeyData
.KeyState
.KeyShiftState
& (EFI_LEFT_CONTROL_PRESSED
| EFI_RIGHT_CONTROL_PRESSED
)) != 0) &&
147 ((KeyData
.KeyState
.KeyShiftState
& ~(EFI_SHIFT_STATE_VALID
| EFI_LEFT_CONTROL_PRESSED
| EFI_RIGHT_CONTROL_PRESSED
)) == 0))
150 // For consoles that supports/reports shift state,
151 // make sure that only CONTROL shift key is pressed.
153 if ((KeyData
.Key
.UnicodeChar
== 'w') || (KeyData
.Key
.UnicodeChar
== 'W')) {
159 // update screen with buffer's info
160 HBufferImageNeedRefresh
= TRUE
;
161 HBufferImageOnlyLineNeedRefresh
= FALSE
;
162 HBufferImageRefresh ();
168 Move cursor to specified lines.
170 @retval EFI_SUCCESS The operation was successful.
173 HMainCommandGoToOffset (
184 // variable initialization
194 Status
= InputBarSetPrompt (L
"Go To Offset: ");
195 if (EFI_ERROR (Status
)) {
199 Status
= InputBarSetStringSize (8);
200 if (EFI_ERROR (Status
)) {
205 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
210 if (Status
== EFI_NOT_READY
) {
215 // THE input string length should > 0
217 if (StrLen (InputBarGetString ()) > 0) {
218 Status
= ShellConvertStringToUint64 (InputBarGetString (), &Offset
, TRUE
, FALSE
);
219 if (EFI_ERROR (Status
)) {
220 StatusBarSetStatusString (L
"Invalid Offset");
228 Size
= HBufferImageGetTotalSize ();
229 if (Offset
>= Size
) {
230 StatusBarSetStatusString (L
"Invalid Offset");
234 FRow
= (UINTN
)DivU64x32 (Offset
, 0x10) + 1;
235 FCol
= (UINTN
)ModU64x32 (Offset
, 0x10) + 1;
237 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
239 HBufferImageNeedRefresh
= TRUE
;
240 HBufferImageOnlyLineNeedRefresh
= FALSE
;
241 HBufferImageMouseNeedRefresh
= TRUE
;
247 Save current opened buffer.
248 If is file buffer, you can save to current file name or
249 save to another file name.
251 @retval EFI_SUCCESS The operation was successful.
252 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
253 @retval EFI_LOAD_ERROR A load error occurred.
256 HMainCommandSaveBuffer (
266 SHELL_FILE_HANDLE ShellFileHandle
;
268 if (HMainEditor
.BufferImage
->BufferType
!= FileTypeFileBuffer
) {
269 if (!HMainEditor
.BufferImage
->Modified
) {
273 Status
= InputBarSetPrompt (L
"Dangerous to save disk/mem buffer. Save (Yes/No/Cancel) ? ");
274 if (EFI_ERROR (Status
)) {
279 // the answer is just one character
281 Status
= InputBarSetStringSize (1);
282 if (EFI_ERROR (Status
)) {
287 // loop for user's answer
288 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
291 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
296 if (Status
== EFI_NOT_READY
) {
300 switch (InputBarGetString ()[0]) {
304 // want to save this buffer first
306 Status
= HBufferImageSave (
308 HMainEditor
.BufferImage
->DiskImage
->Name
,
309 HMainEditor
.BufferImage
->DiskImage
->Offset
,
310 HMainEditor
.BufferImage
->DiskImage
->Size
,
311 HMainEditor
.BufferImage
->MemImage
->Offset
,
312 HMainEditor
.BufferImage
->MemImage
->Size
,
313 HMainEditor
.BufferImage
->BufferType
316 if (EFI_ERROR (Status
)) {
317 StatusBarSetStatusString (L
"BufferSave: Problems Writing");
326 // the file won't be saved
346 // ENDOF != FILEBUFFER
348 // This command will save currently opened file to disk.
349 // You can choose save to another file name or just save to
350 // current file name.
351 // Below is the scenario of Save File command: (
352 // Suppose the old file name is A )
353 // 1. An Input Bar will be prompted: "File To Save: [ old file name]"
354 // IF user press ESC, Save File command ends .
355 // IF user press Enter, input file name will be A.
356 // IF user inputs a new file name B, input file name will be B.
358 // 2. IF input file name is A, go to do Step 3.
359 // IF input file name is B, go to do Step 4.
361 // 3. IF A is read only, Status Bar will show "Access Denied"
362 // and Save File commands ends.
363 // IF A is not read only, save file buffer to disk
364 // and remove Modified flag in Title Bar , then Save File command ends.
366 // 4. IF B does not exist, create this file and save file buffer to it.
368 // IF B exits, do Step 5.
370 // 5. An Input Bar will be prompted:
371 // "File Exists. Overwrite ( Yes/No/Cancel ) ?"
372 // IF user press 'y' or 'Y', do Step 6.
373 // IF user press 'n' or 'N', Save File commands ends.
374 // IF user press 'c' or 'C' or ESC, Save File commands ends.
376 // 6. IF B is a read-only file, Status Bar will show "Access Denied"
377 // and Save File commands ends.
378 // IF B can be read and write, save file buffer to B.
380 // 7. Update File Name field in Title Bar to B
381 // and remove the Modified flag in Title Bar.
385 L
"File to Save: [%s]",
386 HMainEditor
.BufferImage
->FileImage
->FileName
389 return EFI_OUT_OF_RESOURCES
;
392 if (StrLen (Str
) >= 50) {
394 // replace the long file name with "..."
403 Status
= InputBarSetPrompt (Str
);
404 if (EFI_ERROR (Status
)) {
408 Status
= InputBarSetStringSize (100);
409 if (EFI_ERROR (Status
)) {
416 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
419 // if user pressed ESC
421 if (Status
== EFI_NOT_READY
) {
422 SHELL_FREE_NON_NULL (Str
);
426 SHELL_FREE_NON_NULL (Str
);
429 // if just enter pressed, so think save to current file name
431 if (StrLen (InputBarGetString ()) == 0) {
432 FileName
= CatSPrint (
435 HMainEditor
.BufferImage
->FileImage
->FileName
438 FileName
= CatSPrint (NULL
, L
"%s", InputBarGetString ());
441 if (FileName
== NULL
) {
442 return EFI_OUT_OF_RESOURCES
;
445 if (!IsValidFileName (FileName
)) {
446 StatusBarSetStatusString (L
"Invalid File Name");
447 SHELL_FREE_NON_NULL (FileName
);
454 // save to the old file
456 if (StringNoCaseCompare (
458 &HMainEditor
.BufferImage
->FileImage
->FileName
466 // if the file is read only, so can not write back to it.
468 if (HMainEditor
.BufferImage
->FileImage
->ReadOnly
) {
469 StatusBarSetStatusString (L
"Access Denied");
470 SHELL_FREE_NON_NULL (FileName
);
474 Status
= ShellOpenFileByName (FileName
, &ShellFileHandle
, EFI_FILE_MODE_READ
, 0);
476 if (!EFI_ERROR (Status
)) {
477 Info
= ShellGetFileInfo (ShellFileHandle
);
479 ShellCloseFile (&ShellFileHandle
);
481 // check if read only
483 if (Info
->Attribute
& EFI_FILE_READ_ONLY
) {
484 StatusBarSetStatusString (L
"Access Denied");
485 SHELL_FREE_NON_NULL (FileName
);
489 SHELL_FREE_NON_NULL (Info
);
491 // ask user whether to overwrite this file
493 Status
= InputBarSetPrompt (L
"File exists. Overwrite (Yes/No/Cancel) ? ");
494 if (EFI_ERROR (Status
)) {
495 SHELL_FREE_NON_NULL (FileName
);
499 Status
= InputBarSetStringSize (1);
500 if (EFI_ERROR (Status
)) {
501 SHELL_FREE_NON_NULL (FileName
);
507 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
509 if (Status
== EFI_NOT_READY
) {
510 SHELL_FREE_NON_NULL (FileName
);
514 switch (InputBarGetString ()[0]) {
521 SHELL_FREE_NON_NULL (FileName
);
525 SHELL_FREE_NON_NULL (FileName
);
529 } // if opened existing file
533 // save file back to disk
535 Status
= HBufferImageSave (
537 HMainEditor
.BufferImage
->DiskImage
->Name
,
538 HMainEditor
.BufferImage
->DiskImage
->Offset
,
539 HMainEditor
.BufferImage
->DiskImage
->Size
,
540 HMainEditor
.BufferImage
->MemImage
->Offset
,
541 HMainEditor
.BufferImage
->MemImage
->Size
,
544 SHELL_FREE_NON_NULL (FileName
);
546 if (EFI_ERROR (Status
)) {
547 return EFI_LOAD_ERROR
;
554 Load a disk buffer editor.
556 @retval EFI_SUCCESS The operation was successful.
557 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
558 @retval EFI_LOAD_ERROR A load error occurred.
561 HMainCommandSelectStart (
567 Start
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
572 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
573 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
574 StatusBarSetStatusString (L
"Invalid Block Start");
575 return EFI_LOAD_ERROR
;
579 if ((HMainEditor
.SelectEnd
!= 0) && (Start
> HMainEditor
.SelectEnd
)) {
580 StatusBarSetStatusString (L
"Invalid Block Start");
581 return EFI_LOAD_ERROR
;
584 HMainEditor
.SelectStart
= Start
;
586 HBufferImageNeedRefresh
= TRUE
;
592 Load a disk buffer editor.
594 @retval EFI_SUCCESS The operation was successful.
595 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
596 @retval EFI_LOAD_ERROR A load error occurred.
599 HMainCommandSelectEnd (
605 End
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
610 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
611 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
612 StatusBarSetStatusString (L
"Invalid Block End");
613 return EFI_LOAD_ERROR
;
617 if ((HMainEditor
.SelectStart
!= 0) && (End
< HMainEditor
.SelectStart
)) {
618 StatusBarSetStatusString (L
"Invalid Block End");
622 HMainEditor
.SelectEnd
= End
;
624 HBufferImageNeedRefresh
= TRUE
;
630 Cut current line to clipboard.
632 @retval EFI_SUCCESS The operation was successful.
633 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
634 @retval EFI_LOAD_ERROR A load error occurred.
647 // not select, so not allowed to cut
649 if (HMainEditor
.SelectStart
== 0) {
650 StatusBarSetStatusString (L
"No Block is Selected");
655 // not select, so not allowed to cut
657 if (HMainEditor
.SelectEnd
== 0) {
658 StatusBarSetStatusString (L
"No Block is Selected");
662 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
663 for (Index
= 0; Index
< (HMainEditor
.SelectEnd
- 1) / 0x10; Index
++) {
664 Link
= Link
->ForwardLink
;
667 Count
= HMainEditor
.SelectEnd
- HMainEditor
.SelectStart
+ 1;
668 Buffer
= AllocateZeroPool (Count
);
669 if (Buffer
== NULL
) {
670 return EFI_OUT_OF_RESOURCES
;
674 // cut the selected area
676 HBufferImageDeleteCharacterFromBuffer (
677 HMainEditor
.SelectStart
- 1,
685 HClipBoardSet (Buffer
, Count
);
687 HBufferImageNeedRefresh
= TRUE
;
688 HBufferImageOnlyLineNeedRefresh
= FALSE
;
690 if (!HMainEditor
.BufferImage
->Modified
) {
691 HMainEditor
.BufferImage
->Modified
= TRUE
;
695 // now no select area
697 HMainEditor
.SelectStart
= 0;
698 HMainEditor
.SelectEnd
= 0;
704 Paste line to file buffer.
706 @retval EFI_SUCCESS The operation was successful.
707 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
708 @retval EFI_LOAD_ERROR A load error occurred.
715 BOOLEAN OnlyLineRefresh
;
716 HEFI_EDITOR_LINE
*Line
;
721 Count
= HClipBoardGet (&Buffer
);
722 if ((Count
== 0) || (Buffer
== NULL
)) {
723 StatusBarSetStatusString (L
"Nothing to Paste");
727 Line
= HMainEditor
.BufferImage
->CurrentLine
;
729 OnlyLineRefresh
= FALSE
;
730 if ((Line
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) && (Line
->Size
+ Count
< 0x10)) {
732 // is at last line, and after paste will not exceed
733 // so only this line need to be refreshed
735 // if after add, the line is 0x10, then will append a new line
736 // so the whole page will need be refreshed
738 OnlyLineRefresh
= TRUE
;
741 FPos
= 0x10 * (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) + HMainEditor
.BufferImage
->BufferPosition
.Column
- 1;
743 HBufferImageAddCharacterToBuffer (FPos
, Count
, Buffer
);
745 if (OnlyLineRefresh
) {
746 HBufferImageNeedRefresh
= FALSE
;
747 HBufferImageOnlyLineNeedRefresh
= TRUE
;
749 HBufferImageNeedRefresh
= TRUE
;
750 HBufferImageOnlyLineNeedRefresh
= FALSE
;
753 if (!HMainEditor
.BufferImage
->Modified
) {
754 HMainEditor
.BufferImage
->Modified
= TRUE
;
763 @retval EFI_SUCCESS The operation was successful.
764 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
765 @retval EFI_LOAD_ERROR A load error occurred.
775 // Below is the scenario of Exit command:
776 // 1. IF currently opened file is not modified, exit the editor and
777 // Exit command ends.
778 // IF currently opened file is modified, do Step 2
780 // 2. An Input Bar will be prompted:
781 // "File modified. Save ( Yes/No/Cancel )?"
782 // IF user press 'y' or 'Y', currently opened file will be saved and
784 // IF user press 'n' or 'N', currently opened file will not be saved
786 // IF user press 'c' or 'C' or ESC, Exit command ends.
789 // if file has been modified, so will prompt user
790 // whether to save the changes
792 if (HMainEditor
.BufferImage
->Modified
) {
793 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
794 if (EFI_ERROR (Status
)) {
798 Status
= InputBarSetStringSize (1);
799 if (EFI_ERROR (Status
)) {
804 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
809 if (Status
== EFI_NOT_READY
) {
813 switch (InputBarGetString ()[0]) {
817 // write file back to disk
819 Status
= HBufferImageSave (
820 HMainEditor
.BufferImage
->FileImage
->FileName
,
821 HMainEditor
.BufferImage
->DiskImage
->Name
,
822 HMainEditor
.BufferImage
->DiskImage
->Offset
,
823 HMainEditor
.BufferImage
->DiskImage
->Size
,
824 HMainEditor
.BufferImage
->MemImage
->Offset
,
825 HMainEditor
.BufferImage
->MemImage
->Size
,
826 HMainEditor
.BufferImage
->BufferType
828 if (!EFI_ERROR (Status
)) {
851 Load a file from disk to editor.
853 @retval EFI_SUCCESS The operation was successful.
854 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
855 @retval EFI_LOAD_ERROR A load error occurred.
858 HMainCommandOpenFile (
864 EDIT_FILE_TYPE BufferType
;
866 BufferType
= HMainEditor
.BufferImage
->BufferType
;
869 // This command will open a file from current working directory.
870 // Read-only file can also be opened. But it can not be modified.
871 // Below is the scenario of Open File command:
872 // 1. IF currently opened file has not been modified, directly go to step .
873 // IF currently opened file has been modified, an Input Bar will be
875 // "File Modified. Save ( Yes/No/Cancel) ?"
876 // IF user press 'y' or 'Y', currently opened file will be saved.
877 // IF user press 'n' or 'N', currently opened file will
879 // IF user press 'c' or 'C' or ESC, Open File command ends and
880 // currently opened file is still opened.
882 // 2. An Input Bar will be prompted as : "File Name to Open: "
883 // IF user press ESC, Open File command ends and
884 // currently opened file is still opened.
885 // Any other inputs with a Return will cause
886 // currently opened file close.
888 // 3. IF user input file name is an existing file ,
889 // this file will be read and opened.
890 // IF user input file name is a new file, this file will be created
891 // and opened. This file's type ( UNICODE or ASCII ) is the same with
895 // if current file is modified, so you need to choose whether to
898 if (HMainEditor
.BufferImage
->Modified
) {
899 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
900 if (EFI_ERROR (Status
)) {
905 // the answer is just one character
907 Status
= InputBarSetStringSize (1);
908 if (EFI_ERROR (Status
)) {
913 // loop for user's answer
914 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
918 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
923 if (Status
== EFI_NOT_READY
) {
927 switch (InputBarGetString ()[0]) {
931 // want to save this buffer first
933 Status
= HBufferImageSave (
934 HMainEditor
.BufferImage
->FileImage
->FileName
,
935 HMainEditor
.BufferImage
->DiskImage
->Name
,
936 HMainEditor
.BufferImage
->DiskImage
->Offset
,
937 HMainEditor
.BufferImage
->DiskImage
->Size
,
938 HMainEditor
.BufferImage
->MemImage
->Offset
,
939 HMainEditor
.BufferImage
->MemImage
->Size
,
940 HMainEditor
.BufferImage
->BufferType
942 if (EFI_ERROR (Status
)) {
946 MainTitleBarRefresh (
947 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
? HMainEditor
.BufferImage
->FileImage
->FileName
: HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
? HMainEditor
.BufferImage
->DiskImage
->Name
: NULL
,
948 HMainEditor
.BufferImage
->BufferType
,
949 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
951 HMainEditor
.ScreenSize
.Column
,
952 HMainEditor
.ScreenSize
.Row
,
953 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
? HMainEditor
.BufferImage
->DiskImage
->Offset
: HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
? HMainEditor
.BufferImage
->MemImage
->Offset
: 0,
954 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
? HMainEditor
.BufferImage
->DiskImage
->Size
: HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
? HMainEditor
.BufferImage
->MemImage
->Size
: 0
962 // the file won't be saved
975 // TO get the open file name
977 Status
= InputBarSetPrompt (L
"File Name to Open: ");
978 if (EFI_ERROR (Status
)) {
980 HMainEditor
.BufferImage
->FileImage
->FileName
,
981 HMainEditor
.BufferImage
->DiskImage
->Name
,
982 HMainEditor
.BufferImage
->DiskImage
->Offset
,
983 HMainEditor
.BufferImage
->DiskImage
->Size
,
984 HMainEditor
.BufferImage
->MemImage
->Offset
,
985 HMainEditor
.BufferImage
->MemImage
->Size
,
992 Status
= InputBarSetStringSize (100);
993 if (EFI_ERROR (Status
)) {
994 Status
= HBufferImageRead (
995 HMainEditor
.BufferImage
->FileImage
->FileName
,
996 HMainEditor
.BufferImage
->DiskImage
->Name
,
997 HMainEditor
.BufferImage
->DiskImage
->Offset
,
998 HMainEditor
.BufferImage
->DiskImage
->Size
,
999 HMainEditor
.BufferImage
->MemImage
->Offset
,
1000 HMainEditor
.BufferImage
->MemImage
->Size
,
1008 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1013 if (Status
== EFI_NOT_READY
) {
1014 Status
= HBufferImageRead (
1015 HMainEditor
.BufferImage
->FileImage
->FileName
,
1016 HMainEditor
.BufferImage
->DiskImage
->Name
,
1017 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1018 HMainEditor
.BufferImage
->DiskImage
->Size
,
1019 HMainEditor
.BufferImage
->MemImage
->Offset
,
1020 HMainEditor
.BufferImage
->MemImage
->Size
,
1029 // THE input string length should > 0
1031 if (StrLen (InputBarGetString ()) > 0) {
1033 // CHECK if filename's valid
1035 if (!IsValidFileName (InputBarGetString ())) {
1037 HMainEditor
.BufferImage
->FileImage
->FileName
,
1038 HMainEditor
.BufferImage
->DiskImage
->Name
,
1039 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1040 HMainEditor
.BufferImage
->DiskImage
->Size
,
1041 HMainEditor
.BufferImage
->MemImage
->Offset
,
1042 HMainEditor
.BufferImage
->MemImage
->Size
,
1047 StatusBarSetStatusString (L
"Invalid File Name");
1058 Status
= HBufferImageRead (
1059 InputBarGetString (),
1060 HMainEditor
.BufferImage
->DiskImage
->Name
,
1061 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1062 HMainEditor
.BufferImage
->DiskImage
->Size
,
1063 HMainEditor
.BufferImage
->MemImage
->Offset
,
1064 HMainEditor
.BufferImage
->MemImage
->Size
,
1069 if (EFI_ERROR (Status
)) {
1071 HMainEditor
.BufferImage
->FileImage
->FileName
,
1072 HMainEditor
.BufferImage
->DiskImage
->Name
,
1073 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1074 HMainEditor
.BufferImage
->DiskImage
->Size
,
1075 HMainEditor
.BufferImage
->MemImage
->Offset
,
1076 HMainEditor
.BufferImage
->MemImage
->Size
,
1081 return EFI_LOAD_ERROR
;
1088 Load a disk buffer editor.
1090 @retval EFI_SUCCESS The operation was successful.
1091 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
1092 @retval EFI_LOAD_ERROR A load error occurred.
1093 @retval EFI_NOT_FOUND The disk was not found.
1096 HMainCommandOpenDisk (
1106 EDIT_FILE_TYPE BufferType
;
1109 // variable initialization
1113 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1116 // if current file is modified, so you need to choose
1117 // whether to save it first.
1119 if (HMainEditor
.BufferImage
->Modified
) {
1120 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1121 if (EFI_ERROR (Status
)) {
1126 // the answer is just one character
1128 Status
= InputBarSetStringSize (1);
1129 if (EFI_ERROR (Status
)) {
1134 // loop for user's answer
1135 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1139 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1144 if (Status
== EFI_NOT_READY
) {
1148 switch (InputBarGetString ()[0]) {
1152 // want to save this buffer first
1154 Status
= HBufferImageSave (
1155 HMainEditor
.BufferImage
->FileImage
->FileName
,
1156 HMainEditor
.BufferImage
->DiskImage
->Name
,
1157 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1158 HMainEditor
.BufferImage
->DiskImage
->Size
,
1159 HMainEditor
.BufferImage
->MemImage
->Offset
,
1160 HMainEditor
.BufferImage
->MemImage
->Size
,
1163 if (EFI_ERROR (Status
)) {
1167 MainTitleBarRefresh (
1168 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
? HMainEditor
.BufferImage
->FileImage
->FileName
: HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
? HMainEditor
.BufferImage
->DiskImage
->Name
: NULL
,
1169 HMainEditor
.BufferImage
->BufferType
,
1170 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1172 HMainEditor
.ScreenSize
.Column
,
1173 HMainEditor
.ScreenSize
.Row
,
1174 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
? HMainEditor
.BufferImage
->DiskImage
->Offset
: HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
? HMainEditor
.BufferImage
->MemImage
->Offset
: 0,
1175 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
? HMainEditor
.BufferImage
->DiskImage
->Size
: HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
? HMainEditor
.BufferImage
->MemImage
->Size
: 0
1183 // the file won't be saved
1196 // get disk block device name
1198 Status
= InputBarSetPrompt (L
"Block Device to Open: ");
1199 if (EFI_ERROR (Status
)) {
1203 Status
= InputBarSetStringSize (100);
1204 if (EFI_ERROR (Status
)) {
1209 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1214 if (Status
== EFI_NOT_READY
) {
1219 // THE input string length should > 0
1221 if (StrLen (InputBarGetString ()) > 0) {
1226 DeviceName
= CatSPrint (NULL
, L
"%s", InputBarGetString ());
1227 if (DeviceName
== NULL
) {
1228 return EFI_OUT_OF_RESOURCES
;
1232 // get starting offset
1234 Status
= InputBarSetPrompt (L
"First Block No.: ");
1235 if (EFI_ERROR (Status
)) {
1239 Status
= InputBarSetStringSize (16);
1240 if (EFI_ERROR (Status
)) {
1245 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1250 if (Status
== EFI_NOT_READY
) {
1255 // THE input string length should > 0
1257 if (StrLen (InputBarGetString ()) > 0) {
1258 Status
= ShellConvertStringToUint64 (InputBarGetString (), &Offset
, TRUE
, FALSE
);
1259 if (EFI_ERROR (Status
)) {
1268 // get Number of Blocks:
1270 Status
= InputBarSetPrompt (L
"Number of Blocks: ");
1271 if (EFI_ERROR (Status
)) {
1275 Status
= InputBarSetStringSize (8);
1276 if (EFI_ERROR (Status
)) {
1281 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1286 if (Status
== EFI_NOT_READY
) {
1291 // THE input string length should > 0
1293 if (StrLen (InputBarGetString ()) > 0) {
1294 Status
= ShellConvertStringToUint64 (InputBarGetString (), &Size
, TRUE
, FALSE
);
1295 if (EFI_ERROR (Status
)) {
1307 Status
= HBufferImageRead (
1318 if (EFI_ERROR (Status
)) {
1320 HMainEditor
.BufferImage
->FileImage
->FileName
,
1321 HMainEditor
.BufferImage
->DiskImage
->Name
,
1322 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1323 HMainEditor
.BufferImage
->DiskImage
->Size
,
1324 HMainEditor
.BufferImage
->MemImage
->Offset
,
1325 HMainEditor
.BufferImage
->MemImage
->Size
,
1329 return EFI_NOT_FOUND
;
1336 Load memory content to editor
1338 @retval EFI_SUCCESS The operation was successful.
1339 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
1340 @retval EFI_LOAD_ERROR A load error occurred.
1341 @retval EFI_NOT_FOUND The disk was not found.
1344 HMainCommandOpenMemory (
1352 EDIT_FILE_TYPE BufferType
;
1355 // variable initialization
1359 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1362 // if current buffer is modified, so you need to choose
1363 // whether to save it first.
1365 if (HMainEditor
.BufferImage
->Modified
) {
1366 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1367 if (EFI_ERROR (Status
)) {
1372 // the answer is just one character
1374 Status
= InputBarSetStringSize (1);
1375 if (EFI_ERROR (Status
)) {
1380 // loop for user's answer
1381 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1385 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1390 if (Status
== EFI_NOT_READY
) {
1394 switch (InputBarGetString ()[0]) {
1398 // want to save this buffer first
1400 Status
= HBufferImageSave (
1401 HMainEditor
.BufferImage
->FileImage
->FileName
,
1402 HMainEditor
.BufferImage
->DiskImage
->Name
,
1403 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1404 HMainEditor
.BufferImage
->DiskImage
->Size
,
1405 HMainEditor
.BufferImage
->MemImage
->Offset
,
1406 HMainEditor
.BufferImage
->MemImage
->Size
,
1409 if (EFI_ERROR (Status
)) {
1413 MainTitleBarRefresh (
1414 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
? HMainEditor
.BufferImage
->FileImage
->FileName
: HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
? HMainEditor
.BufferImage
->DiskImage
->Name
: NULL
,
1415 HMainEditor
.BufferImage
->BufferType
,
1416 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1418 HMainEditor
.ScreenSize
.Column
,
1419 HMainEditor
.ScreenSize
.Row
,
1420 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
? HMainEditor
.BufferImage
->DiskImage
->Offset
: HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
? HMainEditor
.BufferImage
->MemImage
->Offset
: 0,
1421 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
? HMainEditor
.BufferImage
->DiskImage
->Size
: HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
? HMainEditor
.BufferImage
->MemImage
->Size
: 0
1429 // the file won't be saved
1442 // get starting offset
1444 Status
= InputBarSetPrompt (L
"Starting Offset: ");
1445 if (EFI_ERROR (Status
)) {
1449 Status
= InputBarSetStringSize (8);
1450 if (EFI_ERROR (Status
)) {
1455 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1460 if (Status
== EFI_NOT_READY
) {
1465 // THE input string length should > 0
1467 if (StrLen (InputBarGetString ()) > 0) {
1468 Status
= ShellConvertStringToUint64 (InputBarGetString (), &Offset
, TRUE
, FALSE
);
1469 if (EFI_ERROR (Status
)) {
1478 // get Number of Blocks:
1480 Status
= InputBarSetPrompt (L
"Buffer Size: ");
1481 if (EFI_ERROR (Status
)) {
1485 Status
= InputBarSetStringSize (8);
1486 if (EFI_ERROR (Status
)) {
1491 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1496 if (Status
== EFI_NOT_READY
) {
1501 // THE input string length should > 0
1503 if (StrLen (InputBarGetString ()) > 0) {
1504 Status
= ShellConvertStringToUint64 (InputBarGetString (), &Size
, TRUE
, FALSE
);
1505 if (EFI_ERROR (Status
)) {
1517 if ((Offset
+ Size
- 1) > 0xffffffff) {
1518 StatusBarSetStatusString (L
"Invalid parameter");
1519 return EFI_LOAD_ERROR
;
1522 Status
= HBufferImageRead (
1533 if (EFI_ERROR (Status
)) {
1534 StatusBarSetStatusString (L
"Read Device Error!");
1536 HMainEditor
.BufferImage
->FileImage
->FileName
,
1537 HMainEditor
.BufferImage
->DiskImage
->Name
,
1538 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1539 HMainEditor
.BufferImage
->DiskImage
->Size
,
1540 HMainEditor
.BufferImage
->MemImage
->Offset
,
1541 HMainEditor
.BufferImage
->MemImage
->Size
,
1545 return EFI_NOT_FOUND
;
1551 MENU_ITEM_FUNCTION HexMainControlBasedMenuFunctions
[] = {
1553 NULL
, /* Ctrl - A */
1554 NULL
, /* Ctrl - B */
1555 NULL
, /* Ctrl - C */
1556 HMainCommandSelectEnd
, /* Ctrl - D */
1557 HMainCommandDisplayHelp
, /* Ctrl - E */
1558 NULL
, /* Ctrl - F */
1559 HMainCommandGoToOffset
, /* Ctrl - G */
1560 NULL
, /* Ctrl - H */
1561 HMainCommandOpenDisk
, /* Ctrl - I */
1562 NULL
, /* Ctrl - J */
1563 NULL
, /* Ctrl - K */
1564 NULL
, /* Ctrl - L */
1565 HMainCommandOpenMemory
, /* Ctrl - M */
1566 NULL
, /* Ctrl - N */
1567 HMainCommandOpenFile
, /* Ctrl - O */
1568 NULL
, /* Ctrl - P */
1569 HMainCommandExit
, /* Ctrl - Q */
1570 NULL
, /* Ctrl - R */
1571 HMainCommandSaveBuffer
, /* Ctrl - S */
1572 HMainCommandSelectStart
, /* Ctrl - T */
1573 NULL
, /* Ctrl - U */
1574 HMainCommandPaste
, /* Ctrl - V */
1575 NULL
, /* Ctrl - W */
1576 HMainCommandCut
, /* Ctrl - X */
1577 NULL
, /* Ctrl - Y */
1578 NULL
, /* Ctrl - Z */
1581 CONST EDITOR_MENU_ITEM HexEditorMenuItems
[] = {
1583 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_GO_TO_OFFSET
),
1584 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F1
),
1585 HMainCommandGoToOffset
1588 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_SAVE_BUFFER
),
1589 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F2
),
1590 HMainCommandSaveBuffer
1593 STRING_TOKEN (STR_EDIT_LIBMENUBAR_EXIT
),
1594 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F3
),
1599 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_SELECT_START
),
1600 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F4
),
1601 HMainCommandSelectStart
1604 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_SELECT_END
),
1605 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F5
),
1606 HMainCommandSelectEnd
1609 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_CUT
),
1610 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F6
),
1614 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_PASTE
),
1615 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F7
),
1620 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_OPEN_FILE
),
1621 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F8
),
1622 HMainCommandOpenFile
1625 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_OPEN_DISK
),
1626 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F9
),
1627 HMainCommandOpenDisk
1630 STRING_TOKEN (STR_HEXEDIT_LIBMENUBAR_OPEN_MEMORY
),
1631 STRING_TOKEN (STR_EDIT_LIBMENUBAR_F10
),
1632 HMainCommandOpenMemory
1643 Init function for MainEditor
1645 @retval EFI_SUCCESS The operation was successful.
1646 @retval EFI_LOAD_ERROR A load error occurred.
1654 EFI_HANDLE
*HandleBuffer
;
1659 // basic initialization
1661 CopyMem (&HMainEditor
, &HMainEditorConst
, sizeof (HMainEditor
));
1664 // set screen attributes
1666 HMainEditor
.ColorAttributes
.Colors
.Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x000000ff;
1668 HMainEditor
.ColorAttributes
.Colors
.Background
= (UINT8
)(gST
->ConOut
->Mode
->Attribute
>> 4);
1670 HOriginalColors
= HMainEditor
.ColorAttributes
.Colors
;
1672 HOriginalMode
= gST
->ConOut
->Mode
->Mode
;
1675 // query screen size
1677 gST
->ConOut
->QueryMode (
1679 gST
->ConOut
->Mode
->Mode
,
1680 &(HMainEditor
.ScreenSize
.Column
),
1681 &(HMainEditor
.ScreenSize
.Row
)
1685 // Find TextInEx in System Table ConsoleInHandle
1686 // Per UEFI Spec, TextInEx is required for a console capable platform.
1688 Status
= gBS
->HandleProtocol (
1689 gST
->ConsoleInHandle
,
1690 &gEfiSimpleTextInputExProtocolGuid
,
1691 (VOID
**)&HMainEditor
.TextInputEx
1693 if (EFI_ERROR (Status
)) {
1698 // Find mouse in System Table ConsoleInHandle
1700 Status
= gBS
->HandleProtocol (
1701 gST
->ConsoleInHandle
,
1702 &gEfiSimplePointerProtocolGuid
,
1703 (VOID
**)&HMainEditor
.MouseInterface
1705 if (EFI_ERROR (Status
)) {
1707 // If there is no Simple Pointer Protocol on System Table
1709 HandleBuffer
= NULL
;
1710 HMainEditor
.MouseInterface
= NULL
;
1711 Status
= gBS
->LocateHandleBuffer (
1713 &gEfiSimplePointerProtocolGuid
,
1718 if (!EFI_ERROR (Status
) && (HandleCount
> 0)) {
1720 // Try to find the first available mouse device
1722 for (Index
= 0; Index
< HandleCount
; Index
++) {
1723 Status
= gBS
->HandleProtocol (
1724 HandleBuffer
[Index
],
1725 &gEfiSimplePointerProtocolGuid
,
1726 (VOID
**)&HMainEditor
.MouseInterface
1728 if (!EFI_ERROR (Status
)) {
1734 if (HandleBuffer
!= NULL
) {
1735 FreePool (HandleBuffer
);
1739 if (!EFI_ERROR (Status
) && (HMainEditor
.MouseInterface
!= NULL
)) {
1740 HMainEditor
.MouseAccumulatorX
= 0;
1741 HMainEditor
.MouseAccumulatorY
= 0;
1742 HMainEditor
.MouseSupported
= TRUE
;
1746 // below will call the five components' init function
1748 Status
= MainTitleBarInit (L
"UEFI HEXEDIT");
1749 if (EFI_ERROR (Status
)) {
1750 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_TITLE
), gShellDebug1HiiHandle
);
1751 return EFI_LOAD_ERROR
;
1754 Status
= ControlHotKeyInit (HexMainControlBasedMenuFunctions
);
1755 if (EFI_ERROR (Status
)) {
1756 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1757 return EFI_LOAD_ERROR
;
1760 Status
= MenuBarInit (HexEditorMenuItems
);
1761 if (EFI_ERROR (Status
)) {
1762 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1763 return EFI_LOAD_ERROR
;
1766 Status
= StatusBarInit ();
1767 if (EFI_ERROR (Status
)) {
1768 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_STATUS
), gShellDebug1HiiHandle
);
1769 return EFI_LOAD_ERROR
;
1772 InputBarInit (HMainEditor
.TextInputEx
);
1774 Status
= HBufferImageInit ();
1775 if (EFI_ERROR (Status
)) {
1776 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_BUFFERIMAGE
), gShellDebug1HiiHandle
);
1777 return EFI_LOAD_ERROR
;
1780 Status
= HClipBoardInit ();
1781 if (EFI_ERROR (Status
)) {
1782 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_CLIPBOARD
), gShellDebug1HiiHandle
);
1783 return EFI_LOAD_ERROR
;
1787 // clear whole screen and enable cursor
1789 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1790 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1793 // initialize EditorFirst and EditorExit
1795 HEditorFirst
= TRUE
;
1796 HEditorExit
= FALSE
;
1797 HEditorMouseAction
= FALSE
;
1803 Cleanup function for MainEditor.
1805 @retval EFI_SUCCESS The operation was successful.
1806 @retval EFI_LOAD_ERROR A load error occurred.
1809 HMainEditorCleanup (
1816 // call the five components' cleanup function
1818 MainTitleBarCleanup ();
1822 StatusBarCleanup ();
1826 Status
= HBufferImageCleanup ();
1827 if (EFI_ERROR (Status
)) {
1828 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_BUFFERIMAGE_CLEAN
), gShellDebug1HiiHandle
);
1831 Status
= HClipBoardCleanup ();
1832 if (EFI_ERROR (Status
)) {
1833 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_CLIPBOARD_CLEAN
), gShellDebug1HiiHandle
);
1839 if (HOriginalMode
!= gST
->ConOut
->Mode
->Mode
) {
1840 gST
->ConOut
->SetMode (gST
->ConOut
, HOriginalMode
);
1843 gST
->ConOut
->SetAttribute (
1845 EFI_TEXT_ATTR (HOriginalColors
.Foreground
, HOriginalColors
.Background
)
1847 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1853 Refresh function for MainEditor.
1855 @retval EFI_SUCCESS The operation was successful.
1858 HMainEditorRefresh (
1868 if (HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
) {
1869 if ((HMainEditor
.BufferImage
->DiskImage
!= NULL
) &&
1870 (HBufferImageBackupVar
.DiskImage
!= NULL
) &&
1871 ((HMainEditor
.BufferImage
->DiskImage
->Offset
!= HBufferImageBackupVar
.DiskImage
->Offset
) ||
1872 (HMainEditor
.BufferImage
->DiskImage
->Size
!= HBufferImageBackupVar
.DiskImage
->Size
)))
1876 } else if (HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
) {
1877 if ((HMainEditor
.BufferImage
->MemImage
!= NULL
) &&
1878 (HBufferImageBackupVar
.MemImage
!= NULL
) &&
1879 ((HMainEditor
.BufferImage
->MemImage
->Offset
!= HBufferImageBackupVar
.MemImage
->Offset
) ||
1880 (HMainEditor
.BufferImage
->MemImage
->Size
!= HBufferImageBackupVar
.MemImage
->Size
)))
1884 } else if (HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
) {
1885 if ((HMainEditor
.BufferImage
->FileImage
!= NULL
) &&
1886 (HMainEditor
.BufferImage
->FileImage
->FileName
!= NULL
) &&
1887 (HBufferImageBackupVar
.FileImage
!= NULL
) &&
1888 (HBufferImageBackupVar
.FileImage
->FileName
!= NULL
) &&
1889 (StrCmp (HMainEditor
.BufferImage
->FileImage
->FileName
, HBufferImageBackupVar
.FileImage
->FileName
) != 0))
1895 if ((HMainEditor
.BufferImage
->FileImage
!= NULL
) &&
1896 (HBufferImageBackupVar
.FileImage
!= NULL
) &&
1897 (HMainEditor
.BufferImage
->FileImage
->ReadOnly
!= HBufferImageBackupVar
.FileImage
->ReadOnly
))
1903 // to aVOID screen flicker
1904 // the stall value is from experience
1909 // call the components refresh function
1913 || (HMainEditor
.BufferImage
->BufferType
!= HBufferImageBackupVar
.BufferType
)
1914 || (HBufferImageBackupVar
.Modified
!= HMainEditor
.BufferImage
->Modified
)
1917 MainTitleBarRefresh (
1918 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
,
1919 HMainEditor
.BufferImage
->BufferType
,
1920 (BOOLEAN
)(HMainEditor
.BufferImage
->FileImage
!= NULL
? HMainEditor
.BufferImage
->FileImage
->ReadOnly
: FALSE
),
1921 HMainEditor
.BufferImage
->Modified
,
1922 HMainEditor
.ScreenSize
.Column
,
1923 HMainEditor
.ScreenSize
.Row
,
1924 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,
1925 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
1927 HBufferImageRefresh ();
1931 || (HBufferImageBackupVar
.DisplayPosition
.Row
!= HMainEditor
.BufferImage
->DisplayPosition
.Row
)
1932 || (HBufferImageBackupVar
.DisplayPosition
.Column
!= HMainEditor
.BufferImage
->DisplayPosition
.Column
)
1933 || StatusBarGetRefresh ())
1937 HMainEditor
.ScreenSize
.Row
,
1938 HMainEditor
.ScreenSize
.Column
,
1943 HBufferImageRefresh ();
1947 HBufferImageRefresh ();
1951 // EditorFirst is now set to FALSE
1953 HEditorFirst
= FALSE
;
1959 Handle the mouse input.
1961 @param[in] MouseState The current mouse state.
1962 @param[out] BeforeLeftButtonDown helps with selections.
1964 @retval EFI_SUCCESS The operation was successful.
1965 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
1966 @retval EFI_LOAD_ERROR A load error occurred.
1967 @retval EFI_NOT_FOUND The disk was not found.
1970 HMainEditorHandleMouseInput (
1971 IN EFI_SIMPLE_POINTER_STATE MouseState
,
1972 OUT BOOLEAN
*BeforeLeftButtonDown
1981 HEFI_EDITOR_LINE
*Line
;
1988 // have mouse movement
1990 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
1994 TextX
= HGetTextX (MouseState
.RelativeMovementX
);
1995 TextY
= HGetTextY (MouseState
.RelativeMovementY
);
1997 HBufferImageAdjustMousePosition (TextX
, TextY
);
2002 if (MouseState
.LeftButton
) {
2003 HighBits
= HBufferImageIsAtHighBits (
2004 HMainEditor
.BufferImage
->MousePosition
.Column
,
2009 // not at an movable place
2013 // now just move mouse pointer to legal position
2016 // move mouse position to legal position
2018 HMainEditor
.BufferImage
->MousePosition
.Column
-= 10;
2019 if (HMainEditor
.BufferImage
->MousePosition
.Column
> 24) {
2020 HMainEditor
.BufferImage
->MousePosition
.Column
--;
2021 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
2023 if (HMainEditor
.BufferImage
->MousePosition
.Column
< 24) {
2024 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
2036 FRow
= HMainEditor
.BufferImage
->BufferPosition
.Row
+
2037 HMainEditor
.BufferImage
->MousePosition
.Row
-
2038 HMainEditor
.BufferImage
->DisplayPosition
.Row
;
2040 if (HMainEditor
.BufferImage
->NumLines
< FRow
) {
2045 // now just move mouse pointer to legal position
2047 FRow
= HMainEditor
.BufferImage
->NumLines
;
2051 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2052 for (Index
= 0; Index
< FRow
- 1; Index
++) {
2053 Link
= Link
->ForwardLink
;
2056 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2062 // now just move mouse pointer to legal position
2064 if (FCol
> Line
->Size
) {
2065 if (*BeforeLeftButtonDown
) {
2068 if (Line
->Size
== 0) {
2080 FCol
= Line
->Size
+ 1;
2085 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
2087 HMainEditor
.BufferImage
->MousePosition
.Row
= HMainEditor
.BufferImage
->DisplayPosition
.Row
;
2089 HMainEditor
.BufferImage
->MousePosition
.Column
= HMainEditor
.BufferImage
->DisplayPosition
.Column
;
2091 *BeforeLeftButtonDown
= TRUE
;
2096 // else of if LButton
2100 if (*BeforeLeftButtonDown
) {
2107 *BeforeLeftButtonDown
= FALSE
;
2114 return EFI_NOT_FOUND
;
2118 Handle user key input. will route it to other components handle function.
2120 @retval EFI_SUCCESS The operation was successful.
2121 @retval EFI_OUT_OF_RESOURCES A memory allocation occurred.
2122 @retval EFI_LOAD_ERROR A load error occurred.
2125 HMainEditorKeyInput (
2129 EFI_KEY_DATA KeyData
;
2131 EFI_SIMPLE_POINTER_STATE MouseState
;
2132 BOOLEAN NoShiftState
;
2133 BOOLEAN LengthChange
;
2136 BOOLEAN BeforeMouseIsDown
;
2137 BOOLEAN MouseIsDown
;
2142 UINTN SelectStartBackup
;
2143 UINTN SelectEndBackup
;
2146 // variable initialization
2151 LengthChange
= FALSE
;
2153 MouseIsDown
= FALSE
;
2158 Status
= EFI_SUCCESS
;
2160 HEditorMouseAction
= FALSE
;
2163 // backup some key elements, so that can aVOID some refresh work
2165 HMainEditorBackup ();
2168 // wait for user key input
2171 // change priority of checking mouse/keyboard activity dynamically
2172 // so prevent starvation of keyboard.
2173 // if last time, mouse moves then this time check keyboard
2175 if (HMainEditor
.MouseSupported
) {
2176 Status
= HMainEditor
.MouseInterface
->GetState (
2177 HMainEditor
.MouseInterface
,
2180 if (!EFI_ERROR (Status
)) {
2181 BeforeMouseIsDown
= MouseIsDown
;
2183 Status
= HMainEditorHandleMouseInput (MouseState
, &MouseIsDown
);
2185 if (!EFI_ERROR (Status
)) {
2186 if (!BeforeMouseIsDown
) {
2191 FRow
= HBufferImage
.BufferPosition
.Row
;
2192 FCol
= HBufferImage
.BufferPosition
.Column
;
2193 SelectStartBackup
= HMainEditor
.SelectStart
;
2194 SelectEndBackup
= HMainEditor
.SelectEnd
;
2199 SelectStartBackup
= HMainEditor
.SelectStart
;
2200 SelectEndBackup
= HMainEditor
.SelectEnd
;
2207 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
2208 HMainEditor
.SelectStart
= 0;
2209 HMainEditor
.SelectEnd
= 0;
2210 HMainEditor
.SelectStart
= (FRow
- 1) * 0x10 + FCol
;
2217 (HBufferImage
.BufferPosition
.Row
- 1) *
2219 HBufferImage
.BufferPosition
.Column
2220 ) >= HMainEditor
.SelectStart
2223 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2225 HBufferImage
.BufferPosition
.Column
;
2227 HMainEditor
.SelectEnd
= 0;
2232 // end of if RelativeX/Y
2239 if (HBufferImageGetTotalSize () == 0) {
2240 HMainEditor
.SelectStart
= 0;
2241 HMainEditor
.SelectEnd
= 0;
2247 (HBufferImage
.BufferPosition
.Row
- 1) *
2249 HBufferImage
.BufferPosition
.Column
2250 ) >= HMainEditor
.SelectStart
2253 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2255 HBufferImage
.BufferPosition
.Column
;
2257 HMainEditor
.SelectEnd
= 0;
2260 if (HMainEditor
.SelectEnd
== 0) {
2261 HMainEditor
.SelectStart
= 0;
2269 if ((SelectStartBackup
!= HMainEditor
.SelectStart
) || (SelectEndBackup
!= HMainEditor
.SelectEnd
)) {
2270 if ((SelectStartBackup
- 1) / 0x10 != (HMainEditor
.SelectStart
- 1) / 0x10) {
2271 HBufferImageNeedRefresh
= TRUE
;
2273 if ((SelectEndBackup
- 1) / 0x10 != (HMainEditor
.SelectEnd
- 1) / 0x10) {
2274 HBufferImageNeedRefresh
= TRUE
;
2276 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2282 HEditorMouseAction
= TRUE
;
2283 HBufferImageMouseNeedRefresh
= TRUE
;
2284 } else if (Status
== EFI_LOAD_ERROR
) {
2285 StatusBarSetStatusString (L
"Invalid Mouse Movement ");
2291 // CheckEvent() returns Success when non-partial key is pressed.
2293 Status
= gBS
->CheckEvent (HMainEditor
.TextInputEx
->WaitForKeyEx
);
2294 if (!EFI_ERROR (Status
)) {
2295 Status
= HMainEditor
.TextInputEx
->ReadKeyStrokeEx (HMainEditor
.TextInputEx
, &KeyData
);
2296 if (!EFI_ERROR (Status
)) {
2298 // dispatch to different components' key handling function
2299 // so not everywhere has to set this variable
2301 HBufferImageMouseNeedRefresh
= TRUE
;
2304 // clear previous status string
2306 StatusBarSetRefresh ();
2308 // NoShiftState: TRUE when no shift key is pressed.
2310 NoShiftState
= ((KeyData
.KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) == 0) || (KeyData
.KeyState
.KeyShiftState
== EFI_SHIFT_STATE_VALID
);
2312 // dispatch to different components' key handling function
2314 if (EFI_SUCCESS
== MenuBarDispatchControlHotKey (&KeyData
)) {
2315 Status
= EFI_SUCCESS
;
2316 } else if (NoShiftState
&& (KeyData
.Key
.ScanCode
== SCAN_NULL
)) {
2317 Status
= HBufferImageHandleInput (&KeyData
.Key
);
2318 } else if (NoShiftState
&& ((KeyData
.Key
.ScanCode
>= SCAN_UP
) && (KeyData
.Key
.ScanCode
<= SCAN_PAGE_DOWN
))) {
2319 Status
= HBufferImageHandleInput (&KeyData
.Key
);
2320 } else if (NoShiftState
&& ((KeyData
.Key
.ScanCode
>= SCAN_F1
) && (KeyData
.Key
.ScanCode
<= SCAN_F12
))) {
2321 Status
= MenuBarDispatchFunctionKey (&KeyData
.Key
);
2323 StatusBarSetStatusString (L
"Unknown Command");
2325 HBufferImageMouseNeedRefresh
= FALSE
;
2328 if ((Status
!= EFI_SUCCESS
) && (Status
!= EFI_OUT_OF_RESOURCES
)) {
2330 // not already has some error status
2332 if (StrCmp (L
"", StatusBarGetString ()) == 0) {
2333 StatusBarSetStatusString (L
"Disk Error. Try Again");
2339 // decide if has to set length warning
2341 if (HBufferImage
.BufferType
!= HBufferImageBackupVar
.BufferType
) {
2342 LengthChange
= FALSE
;
2345 // still the old buffer
2347 if (HBufferImage
.BufferType
!= FileTypeFileBuffer
) {
2348 Size
= HBufferImageGetTotalSize ();
2350 switch (HBufferImage
.BufferType
) {
2351 case FileTypeDiskBuffer
:
2352 OldSize
= HBufferImage
.DiskImage
->Size
* HBufferImage
.DiskImage
->BlockSize
;
2355 case FileTypeMemBuffer
:
2356 OldSize
= HBufferImage
.MemImage
->Size
;
2364 if (!LengthChange
) {
2365 if (OldSize
!= Size
) {
2366 StatusBarSetStatusString (L
"Disk/Mem Buffer Length should not be changed");
2370 if (OldSize
!= Size
) {
2371 LengthChange
= TRUE
;
2373 LengthChange
= FALSE
;
2380 // after handling, refresh editor
2382 HMainEditorRefresh ();
2383 } while (Status
!= EFI_OUT_OF_RESOURCES
&& !HEditorExit
);
2389 Backup function for MainEditor.
2396 HMainEditorBackupVar
.SelectStart
= HMainEditor
.SelectStart
;
2397 HMainEditorBackupVar
.SelectEnd
= HMainEditor
.SelectEnd
;
2398 HBufferImageBackup ();