add Edit and HexEdit commands.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11436 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jcarsey 2011-03-25 21:15:07 +00:00
parent 5a0fe66eda
commit 632820d1cf
28 changed files with 14014 additions and 0 deletions

View File

@ -0,0 +1,158 @@
/** @file
Main file for Edit shell Debug1 function.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "UefiShellDebug1CommandsLib.h"
#include "TextEditor.h"
/**
Function for 'edit' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunEdit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
CHAR16 *Buffer;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
LIST_ENTRY *Package;
CONST CHAR16 *Cwd;
CHAR16 *Nfs;
CHAR16 *Spot;
// SHELL_FILE_HANDLE TempHandle;
Buffer = NULL;
ShellStatus = SHELL_SUCCESS;
Nfs = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
if (ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Cwd = gEfiShellProtocol->GetCurDir(NULL);
if (Cwd == NULL) {
Cwd = ShellGetEnvironmentVariable(L"path");
if (Cwd != NULL) {
Nfs = StrnCatGrow(&Nfs, NULL, Cwd+3, 0);
if (Nfs != NULL) {
Spot = StrStr(Nfs, L";");
if (Spot != NULL) {
*Spot = CHAR_NULL;
}
Spot = StrStr(Nfs, L"\\");
if (Spot != NULL) {
Spot[1] = CHAR_NULL;
}
gEfiShellProtocol->SetCurDir(NULL, Nfs);
FreePool(Nfs);
}
}
}
Status = MainEditorInit ();
if (EFI_ERROR (Status)) {
gST->ConOut->ClearScreen (gST->ConOut);
gST->ConOut->EnableCursor (gST->ConOut, TRUE);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_INIT_FAILED), gShellDebug1HiiHandle);
} else {
MainEditorBackup ();
//
// if editor launched with file named
//
if (ShellCommandLineGetCount(Package) == 2) {
FileBufferSetFileName (ShellCommandLineGetRawValue(Package, 1));
// if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
// Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
// if (!EFI_ERROR(Status)) {
// ShellCloseFile(&TempHandle);
// }
// }
}
Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE);
if (!EFI_ERROR (Status)) {
MainEditorRefresh ();
Status = MainEditorKeyInput ();
}
if (Status != EFI_OUT_OF_RESOURCES) {
//
// back up the status string
//
Buffer = CatSPrint (NULL, L"%s", StatusBarGetString());
}
MainEditorCleanup ();
//
// print editor exit code on screen
//
if (Status == EFI_SUCCESS) {
} else if (Status == EFI_OUT_OF_RESOURCES) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_OUT_MEM), gShellDebug1HiiHandle);
} else {
if (Buffer != NULL) {
if (StrCmp (Buffer, L"") != 0) {
//
// print out the status string
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);
}
}
if (Status != EFI_OUT_OF_RESOURCES) {
SHELL_FREE_NON_NULL (Buffer);
}
}
}
ShellCommandLineFreeVarList (Package);
}
return ShellStatus;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,263 @@
/** @file
Declares filebuffer interface functions.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_FILE_BUFFER_H_
#define _LIB_FILE_BUFFER_H_
#include "TextEditorTypes.h"
/**
Initialization function for FileBuffer.
@param EFI_SUCCESS The initialization was successful.
@param EFI_LOAD_ERROR A default name could not be created.
@param EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferInit (
VOID
);
/**
Cleanup function for FileBuffer.
@retval EFI_SUCCESS The cleanup was successful.
**/
EFI_STATUS
EFIAPI
FileBufferCleanup (
VOID
);
/**
Refresh the screen with whats in the buffer.
@retval EFI_SUCCESS The refresh was successful.
@retval EFI_LOAD_ERROR There was an error finding what to write.
**/
EFI_STATUS
EFIAPI
FileBufferRefresh (
VOID
);
/**
Dispatch input to different handler
@param[in] Key The input key. One of:
ASCII KEY
Backspace/Delete
Return
Direction key: up/down/left/right/pgup/pgdn
Home/End
INS
@retval EFI_SUCCESS The dispatch was done successfully.
@retval EFI_LOAD_ERROR The dispatch was not successful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferHandleInput (
IN CONST EFI_INPUT_KEY * Key
);
/**
Backup function for FileBuffer. Only backup the following items:
Mouse/Cursor position
File Name, Type, ReadOnly, Modified
Insert Mode
This is for making the file buffer refresh as few as possible.
@retval EFI_SUCCESS The backup operation was successful.
**/
EFI_STATUS
EFIAPI
FileBufferBackup (
VOID
);
/**
Set the cursor position according to FileBuffer.DisplayPosition.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
FileBufferRestorePosition (
VOID
);
/**
Set FileName field in FileBuffer.
@param Str The file name to set.
@retval EFI_SUCCESS The filename was successfully set.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@retval EFI_INVALID_PARAMETER Str is not a valid filename.
**/
EFI_STATUS
EFIAPI
FileBufferSetFileName (
IN CONST CHAR16 *Str
);
/**
Read a file from disk into the FileBuffer.
@param[in] FileName The filename to read.
@param[in] Recover TRUE if is for recover mode, no information printouts.
@retval EFI_SUCCESS The load was successful.
@retval EFI_LOAD_ERROR The load failed.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@retval EFI_INVALID_PARAMETER FileName is a directory.
**/
EFI_STATUS
EFIAPI
FileBufferRead (
IN CONST CHAR16 *FileName,
IN CONST BOOLEAN Recover
);
/**
Save lines in FileBuffer to disk
@param[in] FileName The file name for writing.
@retval EFI_SUCCESS Data was written.
@retval EFI_LOAD_ERROR
@retval EFI_OUT_OF_RESOURCES There were not enough resources to write the file.
**/
EFI_STATUS
EFIAPI
FileBufferSave (
CONST CHAR16 *FileName
);
/**
According to cursor's file position, adjust screen display
@param[in] NewFilePosRow The row of file position ( start from 1 ).
@param[in] NewFilePosCol The column of file position ( start from 1 ).
**/
VOID
EFIAPI
FileBufferMovePosition (
IN CONST UINTN NewFilePosRow,
IN CONST UINTN NewFilePosCol
);
/**
Cut current line out and return a pointer to it.
@param[out] CutLine Upon a successful return pointer to the pointer to
the allocated cut line.
@retval EFI_SUCCESS The cut was successful.
@retval EFI_NOT_FOUND There was no selection to cut.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferCutLine (
OUT EFI_EDITOR_LINE **CutLine
);
/**
Paste a line into line list.
@retval EFI_SUCCESS The paste was successful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferPasteLine (
VOID
);
/**
Search string from current position on in file
@param[in] Str The search string.
@param[in] Offset The offset from current position.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_NOT_FOUND The string Str was not found.
**/
EFI_STATUS
EFIAPI
FileBufferSearch (
IN CONST CHAR16 *Str,
IN CONST UINTN Offset
);
/**
Replace SearchLen characters from current position on with Replace.
This will modify the current buffer at the current position.
@param[in] Replace The string to replace.
@param[in] SearchLen Search string's length.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferReplace (
IN CONST CHAR16 *Replace,
IN CONST UINTN SearchLen
);
/**
Search and replace operation.
@param[in] SearchStr The string to search for.
@param[in] ReplaceStr The string to replace with.
@param[in] Offset The column to start at.
**/
EFI_STATUS
EFIAPI
FileBufferReplaceAll (
IN CHAR16 *SearchStr,
IN CHAR16 *ReplaceStr,
IN UINTN Offset
);
/**
Move the mouse cursor position.
@param[in] TextX The new x-coordinate.
@param[in] TextY The new y-coordinate.
**/
VOID
EFIAPI
FileBufferAdjustMousePosition (
IN CONST INT32 TextX,
IN CONST INT32 TextY
);
/**
Set the modified state to TRUE.
**/
VOID
EFIAPI
FileBufferSetModified (
VOID
);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,77 @@
/** @file
Declares editor interface functions.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_EDITOR_H_
#define _LIB_EDITOR_H_
#include "TextEditorTypes.h"
/**
The initialization function for MainEditor.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occured.
**/
EFI_STATUS
EFIAPI
MainEditorInit (
VOID
);
/**
The cleanup function for MainEditor.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occured.
**/
EFI_STATUS
EFIAPI
MainEditorCleanup (
VOID
);
/**
Refresh the main editor component.
**/
VOID
EFIAPI
MainEditorRefresh (
VOID
);
/**
Handle user key input. This routes to other functions for the actions.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occured.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
MainEditorKeyInput (
VOID
);
/**
Backup function for MainEditor
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
MainEditorBackup (
VOID
);
#endif

View File

@ -0,0 +1,92 @@
/** @file
Implementation of various string and line routines.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "TextEditor.h"
#include "Misc.h"
/**
Duplicate a EFI_EDITOR_LINE structure.
@param Src The line structure to copy from.
@retval NULL A memory allocation failed.
@return a pointer to the newly allcoated line.
**/
EFI_EDITOR_LINE *
EFIAPI
LineDup (
IN EFI_EDITOR_LINE *Src
)
{
EFI_EDITOR_LINE *Dest;
//
// allocate for the line structure
//
Dest = AllocateZeroPool (sizeof (EFI_EDITOR_LINE));
if (Dest == NULL) {
return NULL;
}
//
// allocate and set the line buffer
//
Dest->Buffer = CatSPrint (NULL, L"%s", Src->Buffer);
if (Dest->Buffer == NULL) {
FreePool (Dest);
return NULL;
}
//
// set the other structure members
//
Dest->Signature = LINE_LIST_SIGNATURE;
Dest->Size = Src->Size;
Dest->TotalSize = Dest->Size;
Dest->Type = Src->Type;
Dest->Link = Src->Link;
return Dest;
}
/**
Free a EFI_EDITOR_LINE structure.
@param Src The line structure to free.
**/
VOID
EFIAPI
LineFree (
IN EFI_EDITOR_LINE *Src
)
{
if (Src == NULL) {
return ;
}
//
// free the line buffer and then the line structure itself
//
SHELL_FREE_NON_NULL (Src->Buffer);
SHELL_FREE_NON_NULL (Src);
}

View File

@ -0,0 +1,52 @@
/** @file
Declares generic editor helper functions.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_MISC_H_
#define _LIB_MISC_H_
#include "TextEditorTypes.h"
/**
Free a EFI_EDITOR_LINE structure.
@param Src The line structure to free.
**/
VOID
EFIAPI
LineFree (
IN EFI_EDITOR_LINE *Src
);
/**
Duplicate a EFI_EDITOR_LINE structure.
@param Src The line structure to copy from.
@retval NULL A memory allocation failed.
@return a pointer to the newly allcoated line.
**/
EFI_EDITOR_LINE *
EFIAPI
LineDup (
IN EFI_EDITOR_LINE *Src
);
#endif

View File

@ -0,0 +1,32 @@
/** @file
Main include file for Edit shell Debug1 function.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _EFI_EDIT_H_
#define _EFI_EDIT_H_
#include "TextEditorTypes.h"
#include "MainTextEditor.h"
#include "FileBuffer.h"
#include "EditTitleBar.h"
#include "EditStatusBar.h"
#include "EditInputBar.h"
#include "EditMenuBar.h"
#include "Misc.h"
extern EFI_EDITOR_GLOBAL_EDITOR MainEditor;
extern BOOLEAN EditorFirst;
extern BOOLEAN EditorExit;
#endif // _EFI_EDIT_H_

View File

@ -0,0 +1,102 @@
/** @file
Declares editor types.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _EDITOR_TYPE_H_
#define _EDITOR_TYPE_H_
#include "UefiShellDebug1CommandsLib.h"
#include "EditTitleBar.h"
#include "EditMenuBar.h"
#define MIN_POOL_SIZE 125
#define MAX_STRING_LENGTH 127
typedef struct {
UINTN Row;
UINTN Column;
} EFI_EDITOR_POSITION;
typedef
EFI_STATUS
(*EFI_MENU_ITEM_FUNCTION) (
VOID
);
typedef enum {
NewLineTypeDefault,
NewLineTypeLineFeed,
NewLineTypeCarriageReturn,
NewLineTypeCarriageReturnLineFeed,
NewLineTypeLineFeedCarriageReturn,
NewLineTypeUnknown
} EE_NEWLINE_TYPE;
#define LINE_LIST_SIGNATURE 'eell'
typedef struct _EFI_EDITOR_LINE {
UINTN Signature;
CHAR16 *Buffer;
UINTN Size; // unit is Unicode
UINTN TotalSize; // unit is Unicode, exclude CHAR_NULL
EE_NEWLINE_TYPE Type;
LIST_ENTRY Link;
} EFI_EDITOR_LINE;
typedef struct {
UINT32 Foreground : 4;
UINT32 Background : 4;
} EFI_EDITOR_COLOR_ATTRIBUTES;
typedef union {
EFI_EDITOR_COLOR_ATTRIBUTES Colors;
UINTN Data;
} EFI_EDITOR_COLOR_UNION;
typedef struct {
UINTN Columns;
UINTN Rows;
} EFI_EDITOR_TEXT_MODE;
typedef struct {
CHAR16 *FileName; // file name current edited in editor
EDIT_FILE_TYPE FileType; // Unicode file or ASCII file
LIST_ENTRY *ListHead; // list head of lines
EFI_EDITOR_LINE *Lines; // lines of current file
UINTN NumLines; // total line numbers
EFI_EDITOR_POSITION DisplayPosition; // cursor position in screen
EFI_EDITOR_POSITION FilePosition; // cursor position in file
EFI_EDITOR_POSITION MousePosition; // mouse position in screen
// file position of first byte displayed on screen
//
EFI_EDITOR_POSITION LowVisibleRange;
BOOLEAN FileModified; // file is modified or not
BOOLEAN ModeInsert; // input mode INS or OVR
BOOLEAN ReadOnly; // file is read-only or not
EFI_EDITOR_LINE *CurrentLine; // current line cursor is at
} EFI_EDITOR_FILE_BUFFER;
typedef struct {
EFI_EDITOR_FILE_BUFFER *FileBuffer;
EFI_EDITOR_COLOR_UNION ColorAttributes;
EFI_EDITOR_POSITION ScreenSize; // row number and column number
EFI_EDITOR_LINE *CutLine; // clip board
BOOLEAN MouseSupported;
EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface;
INT32 MouseAccumulatorX;
INT32 MouseAccumulatorY;
} EFI_EDITOR_GLOBAL_EDITOR;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,250 @@
/** @file
Defines BufferImage - the view of the file that is visible at any point,
as well as the event handlers for editing the file
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_BUFFER_IMAGE_H_
#define _LIB_BUFFER_IMAGE_H_
#include "HexEditor.h"
EFI_STATUS
HBufferImageInit (
VOID
);
EFI_STATUS
HBufferImageCleanup (
VOID
);
EFI_STATUS
HBufferImageRefresh (
VOID
);
EFI_STATUS
HBufferImageHide (
VOID
);
EFI_STATUS
HBufferImageHandleInput (
EFI_INPUT_KEY *
);
EFI_STATUS
HBufferImageBackup (
VOID
);
EFI_STATUS
HBufferImageRead (
IN CONST CHAR16 *,
IN CONST CHAR16 *,
IN UINTN,
IN UINTN,
IN UINTN,
IN UINTN,
IN EDIT_FILE_TYPE,
IN BOOLEAN
);
EFI_STATUS
HBufferImageSave (
IN CHAR16 *,
IN CHAR16 *,
IN UINTN,
IN UINTN,
IN UINTN,
IN UINTN,
IN EDIT_FILE_TYPE
);
INTN
HBufferImageCharToHex (
IN CHAR16
);
EFI_STATUS
HBufferImageRestoreMousePosition (
VOID
);
EFI_STATUS
HBufferImageRestorePosition (
VOID
);
VOID
HBufferImageMovePosition (
IN UINTN,
IN UINTN,
IN BOOLEAN
);
EFI_STATUS
HBufferImageHandleInput (
EFI_INPUT_KEY *
);
HEFI_EDITOR_LINE *
HBufferImageCreateLine (
VOID
);
EFI_STATUS
HBufferImageDoCharInput (
CHAR16
);
EFI_STATUS
HBufferImageAddChar (
CHAR16
);
BOOLEAN
HInCurrentScreen (
UINTN
);
BOOLEAN
HAboveCurrentScreen (
UINTN
);
BOOLEAN
HUnderCurrentScreen (
UINTN
);
EFI_STATUS
HBufferImageScrollRight (
VOID
);
EFI_STATUS
HBufferImageScrollLeft (
VOID
);
EFI_STATUS
HBufferImageScrollDown (
VOID
);
EFI_STATUS
HBufferImageScrollUp (
VOID
);
EFI_STATUS
HBufferImagePageUp (
VOID
);
EFI_STATUS
HBufferImagePageDown (
VOID
);
EFI_STATUS
HBufferImageHome (
VOID
);
EFI_STATUS
HBufferImageEnd (
VOID
);
EFI_STATUS
HBufferImageDoBackspace (
VOID
);
EFI_STATUS
HBufferImageDoDelete (
VOID
);
EFI_STATUS
HBufferImageCutLine (
HEFI_EDITOR_LINE **
);
EFI_STATUS
HBufferImagePasteLine (
VOID
);
EFI_STATUS
HBufferImageGetFileInfo (
EFI_FILE_HANDLE,
CHAR16 *,
EFI_FILE_INFO **
);
EFI_STATUS
HBufferImageSearch (
CHAR16 *,
UINTN
);
EFI_STATUS
HBufferImageReplace (
CHAR16 *,
UINTN
);
EFI_STATUS
HBufferImageFree (
VOID
) ;
EFI_STATUS
HBufferImageDeleteCharacterFromBuffer (
IN UINTN,
IN UINTN,
UINT8 *
);
EFI_STATUS
HBufferImageAddCharacterToBuffer (
IN UINTN,
IN UINTN,
UINT8 *
);
EFI_STATUS
HBufferImageBufferToList (
IN VOID *,
IN UINTN
);
EFI_STATUS
HBufferImageListToBuffer (
IN VOID *,
IN UINTN
);
VOID
HBufferImageAdjustMousePosition (
INT32,
INT32
);
BOOLEAN
HBufferImageIsAtHighBits (
UINTN,
UINTN *
) ;
EFI_STATUS
HBufferImageCutLine (
HEFI_EDITOR_LINE **
);
UINTN
HBufferImageGetTotalSize (
VOID
);
BOOLEAN
HBufferImageIsInSelectedArea (
UINTN,
UINTN
);
#endif

View File

@ -0,0 +1,112 @@
/** @file
Functions to deal with Clip Board
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "HexEditor.h"
HEFI_EDITOR_CLIPBOARD HClipBoard;
//
// for basic initialization of HClipBoard
//
HEFI_EDITOR_CLIPBOARD HClipBoardConst = {
NULL,
0
};
EFI_STATUS
HClipBoardInit (
VOID
)
/*++
Routine Description:
Initialization function for HDiskImage
Arguments:
None
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
--*/
{
//
// basiclly initialize the HDiskImage
//
CopyMem (&HClipBoard, &HClipBoardConst, sizeof (HClipBoard));
return EFI_SUCCESS;
}
EFI_STATUS
HClipBoardCleanup (
VOID
)
/*++
Routine Description:
Initialization function for HDiskImage
Arguments:
None
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
--*/
{
SHELL_FREE_NON_NULL (HClipBoard.Buffer);
return EFI_SUCCESS;
}
EFI_STATUS
HClipBoardSet (
IN UINT8 *Buffer,
IN UINTN Size
)
{
//
// free the old clipboard buffer
// and set new clipboard buffer
//
SHELL_FREE_NON_NULL (HClipBoard.Buffer);
HClipBoard.Buffer = Buffer;
HClipBoard.Size = Size;
return EFI_SUCCESS;
}
UINTN
HClipBoardGet (
OUT UINT8 **Buffer
)
{
//
// return the clipboard buffer
//
*Buffer = HClipBoard.Buffer;
return HClipBoard.Size;
}

View File

@ -0,0 +1,40 @@
/** @file
Defines DiskImage - the view of the file that is visible at any point,
as well as the event handlers for editing the file
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_CLIP_BOARD_H_
#define _LIB_CLIP_BOARD_H_
#include "HexEditor.h"
EFI_STATUS
HClipBoardInit (
VOID
);
EFI_STATUS
HClipBoardCleanup (
VOID
);
EFI_STATUS
HClipBoardSet (
UINT8 *,
UINTN
);
UINTN
HClipBoardGet (
UINT8 **
);
#endif

View File

@ -0,0 +1,487 @@
/** @file
Functions to deal with Disk buffer.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "HexEditor.h"
#include <Protocol/BlockIo.h>
extern EFI_HANDLE HImageHandleBackup;
extern HEFI_EDITOR_BUFFER_IMAGE HBufferImage;
extern BOOLEAN HBufferImageNeedRefresh;
extern BOOLEAN HBufferImageOnlyLineNeedRefresh;
extern BOOLEAN HBufferImageMouseNeedRefresh;
extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditor;
HEFI_EDITOR_DISK_IMAGE HDiskImage;
HEFI_EDITOR_DISK_IMAGE HDiskImageBackupVar;
//
// for basic initialization of HDiskImage
//
HEFI_EDITOR_DISK_IMAGE HDiskImageConst = {
NULL,
0,
0,
0
};
EFI_STATUS
HDiskImageInit (
VOID
)
/*++
Routine Description:
Initialization function for HDiskImage
Arguments:
None
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
--*/
{
//
// basically initialize the HDiskImage
//
CopyMem (&HDiskImage, &HDiskImageConst, sizeof (HDiskImage));
CopyMem (&HDiskImageBackupVar, &HDiskImageConst, sizeof (HDiskImageBackupVar));
return EFI_SUCCESS;
}
EFI_STATUS
HDiskImageBackup (
VOID
)
/*++
Routine Description:
Backup function for HDiskImage
Only a few fields need to be backup.
This is for making the Disk buffer refresh
as few as possible.
Arguments:
None
Returns:
EFI_SUCCESS - Success
EFI_OUT_OF_RESOURCES - gST->ConOut of resources
--*/
{
//
// backup the disk name, offset and size
//
//
SHELL_FREE_NON_NULL (HDiskImageBackupVar.Name);
HDiskImageBackupVar.Name = CatSPrint(NULL, L"%s", HDiskImage.Name);
if (HDiskImageBackupVar.Name == NULL) {
return EFI_OUT_OF_RESOURCES;
}
HDiskImageBackupVar.Offset = HDiskImage.Offset;
HDiskImageBackupVar.Size = HDiskImage.Size;
return EFI_SUCCESS;
}
EFI_STATUS
HDiskImageCleanup (
VOID
)
/*++
Routine Description:
Cleanup function for HDiskImage
Arguments:
None
Returns:
EFI_SUCCESS
--*/
{
SHELL_FREE_NON_NULL (HDiskImage.Name);
SHELL_FREE_NON_NULL (HDiskImageBackupVar.Name);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
HDiskImageSetDiskNameOffsetSize (
IN CONST CHAR16 *Str,
IN UINTN Offset,
IN UINTN Size
)
/*++
Routine Description:
Set FileName field in HFileImage
Arguments:
Str - File name to set
Offset - The offset
Size - The size
Returns:
EFI_SUCCESS
EFI_OUT_OF_RESOURCES
--*/
{
UINTN Len;
UINTN Index;
//
// free the old file name
//
SHELL_FREE_NON_NULL (HDiskImage.Name);
Len = StrLen (Str);
HDiskImage.Name = AllocateZeroPool (2 * (Len + 1));
if (HDiskImage.Name == NULL) {
return EFI_OUT_OF_RESOURCES;
}
for (Index = 0; Index < Len; Index++) {
HDiskImage.Name[Index] = Str[Index];
}
HDiskImage.Name[Len] = L'\0';
HDiskImage.Offset = Offset;
HDiskImage.Size = Size;
return EFI_SUCCESS;
}
EFI_STATUS
HDiskImageRead (
IN CONST CHAR16 *DeviceName,
IN UINTN Offset,
IN UINTN Size,
IN BOOLEAN Recover
)
/*++
Routine Description:
Read a disk from disk into HBufferImage
Arguments:
DeviceName - filename to read
Offset - The offset
Size - The size
Recover - if is for recover, no information print
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
EFI_OUT_OF_RESOURCES
EFI_INVALID_PARAMETER
--*/
{
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_DEVICE_PATH_PROTOCOL *DupDevicePath;
EFI_HANDLE Handle;
EFI_BLOCK_IO_PROTOCOL *BlkIo;
EFI_STATUS Status;
VOID *Buffer;
CHAR16 *Str;
UINTN Bytes;
HEFI_EDITOR_LINE *Line;
UINT64 ByteOffset;
EDIT_FILE_TYPE BufferTypeBackup;
BufferTypeBackup = HBufferImage.BufferType;
HBufferImage.BufferType = FileTypeDiskBuffer;
DevicePath = gEfiShellProtocol->GetDevicePathFromMap(DeviceName);
if (DevicePath == NULL) {
StatusBarSetStatusString (L"Cannot Find Device");
return EFI_INVALID_PARAMETER;
}
DupDevicePath = DuplicateDevicePath(DevicePath);
//
// get blkio interface
//
Status = gBS->LocateDevicePath(&gEfiBlockIoProtocolGuid,&DupDevicePath,&Handle);
FreePool(DupDevicePath);
if (EFI_ERROR (Status)) {
StatusBarSetStatusString (L"Read Disk Failed");
return Status;
}
Status = gBS->OpenProtocol(Handle, &gEfiBlockIoProtocolGuid, (VOID**)&BlkIo, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR (Status)) {
StatusBarSetStatusString (L"Read Disk Failed");
return Status;
}
//
// if Offset exceeds LastBlock,
// return error
//
if (Offset > BlkIo->Media->LastBlock || Offset + Size > BlkIo->Media->LastBlock) {
StatusBarSetStatusString (L"Invalid Offset + Size");
return EFI_LOAD_ERROR;
}
Bytes = BlkIo->Media->BlockSize * Size;
Buffer = AllocateZeroPool (Bytes);
if (Buffer == NULL) {
StatusBarSetStatusString (L"Read Disk Failed");
return EFI_OUT_OF_RESOURCES;
}
ByteOffset = MultU64x32 (Offset, BlkIo->Media->BlockSize);
//
// read from disk
//
Status = BlkIo->ReadBlocks (
BlkIo,
BlkIo->Media->MediaId,
Offset,
Bytes,
Buffer
);
if (EFI_ERROR (Status)) {
FreePool (Buffer);
StatusBarSetStatusString (L"Read Disk Failed");
return EFI_LOAD_ERROR;
}
HBufferImageFree ();
//
// convert buffer to line list
//
Status = HBufferImageBufferToList (Buffer, Bytes);
FreePool (Buffer);
if (EFI_ERROR (Status)) {
StatusBarSetStatusString (L"Read Disk Failed");
return Status;
}
Status = HDiskImageSetDiskNameOffsetSize (DeviceName, Offset, Size);
if (EFI_ERROR (Status)) {
StatusBarSetStatusString (L"Read Disk Failed");
return EFI_OUT_OF_RESOURCES;
}
//
// initialize some variables
//
HDiskImage.BlockSize = BlkIo->Media->BlockSize;
HBufferImage.DisplayPosition.Row = 2;
HBufferImage.DisplayPosition.Column = 10;
HBufferImage.MousePosition.Row = 2;
HBufferImage.MousePosition.Column = 10;
HBufferImage.LowVisibleRow = 1;
HBufferImage.HighBits = TRUE;
HBufferImage.BufferPosition.Row = 1;
HBufferImage.BufferPosition.Column = 1;
if (!Recover) {
Str = CatSPrint(NULL, L"%d Lines Read", HBufferImage.NumLines);
if (Str == NULL) {
StatusBarSetStatusString (L"Read Disk Failed");
return EFI_OUT_OF_RESOURCES;
}
StatusBarSetStatusString (Str);
SHELL_FREE_NON_NULL (Str);
HMainEditor.SelectStart = 0;
HMainEditor.SelectEnd = 0;
}
//
// has line
//
if (HBufferImage.Lines != NULL) {
HBufferImage.CurrentLine = CR (
HBufferImage.ListHead->ForwardLink,
HEFI_EDITOR_LINE,
Link,
EFI_EDITOR_LINE_LIST
);
} else {
//
// create a dummy line
//
Line = HBufferImageCreateLine ();
if (Line == NULL) {
StatusBarSetStatusString (L"Read Disk Failed");
return EFI_OUT_OF_RESOURCES;
}
HBufferImage.CurrentLine = Line;
}
HBufferImage.Modified = FALSE;
HBufferImageNeedRefresh = TRUE;
HBufferImageOnlyLineNeedRefresh = FALSE;
HBufferImageMouseNeedRefresh = TRUE;
return EFI_SUCCESS;
}
EFI_STATUS
HDiskImageSave (
IN CHAR16 *DeviceName,
IN UINTN Offset,
IN UINTN Size
)
/*++
Routine Description:
Save lines in HBufferImage to disk
NOT ALLOW TO WRITE TO ANOTHER DISK!!!!!!!!!
Arguments:
DeviceName - The device name
Offset - The offset
Size - The size
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
EFI_OUT_OF_RESOURCES
EFI_INVALID_PARAMETER
--*/
{
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_DEVICE_PATH_PROTOCOL *DupDevicePath;
EFI_BLOCK_IO_PROTOCOL *BlkIo;
EFI_STATUS Status;
EFI_HANDLE Handle;
VOID *Buffer;
UINTN Bytes;
UINT64 ByteOffset;
EDIT_FILE_TYPE BufferTypeBackup;
//
// if not modified, directly return
//
if (HBufferImage.Modified == FALSE) {
return EFI_SUCCESS;
}
BufferTypeBackup = HBufferImage.BufferType;
HBufferImage.BufferType = FileTypeDiskBuffer;
DevicePath = gEfiShellProtocol->GetDevicePathFromMap(DeviceName);
if (DevicePath == NULL) {
// StatusBarSetStatusString (L"Cannot Find Device");
return EFI_INVALID_PARAMETER;
}
DupDevicePath = DuplicateDevicePath(DevicePath);
//
// get blkio interface
//
Status = gBS->LocateDevicePath(&gEfiBlockIoProtocolGuid,&DupDevicePath,&Handle);
FreePool(DupDevicePath);
if (EFI_ERROR (Status)) {
// StatusBarSetStatusString (L"Read Disk Failed");
return Status;
}
Status = gBS->OpenProtocol(Handle, &gEfiBlockIoProtocolGuid, (VOID**)&BlkIo, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR (Status)) {
// StatusBarSetStatusString (L"Read Disk Failed");
return Status;
}
Bytes = BlkIo->Media->BlockSize * Size;
Buffer = AllocateZeroPool (Bytes);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// concatenate the line list to a buffer
//
Status = HBufferImageListToBuffer (Buffer, Bytes);
if (EFI_ERROR (Status)) {
FreePool (Buffer);
return Status;
}
ByteOffset = MultU64x32 (Offset, BlkIo->Media->BlockSize);
//
// write the buffer to disk
//
Status = BlkIo->WriteBlocks (
BlkIo,
BlkIo->Media->MediaId,
Offset,
Bytes,
Buffer
);
FreePool (Buffer);
if (EFI_ERROR (Status)) {
return EFI_LOAD_ERROR;
}
//
// now not modified
//
HBufferImage.Modified = FALSE;
return EFI_SUCCESS;
}

View File

@ -0,0 +1,48 @@
/** @file
Defines DiskImage - the view of the file that is visible at any point,
as well as the event handlers for editing the file
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_DISK_IMAGE_H_
#define _LIB_DISK_IMAGE_H_
#include "HexEditor.h"
EFI_STATUS
HDiskImageInit (
VOID
);
EFI_STATUS
HDiskImageCleanup (
VOID
);
EFI_STATUS
HDiskImageBackup (
VOID
);
EFI_STATUS
HDiskImageRead (
IN CONST CHAR16 *,
IN UINTN,
IN UINTN,
IN BOOLEAN
);
EFI_STATUS
HDiskImageSave (
IN CHAR16 *,
IN UINTN,
IN UINTN
);
#endif

View File

@ -0,0 +1,504 @@
/** @file
Functions to deal with file buffer.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "HexEditor.h"
extern EFI_HANDLE HImageHandleBackup;
extern HEFI_EDITOR_BUFFER_IMAGE HBufferImage;
extern BOOLEAN HBufferImageNeedRefresh;
extern BOOLEAN HBufferImageOnlyLineNeedRefresh;
extern BOOLEAN HBufferImageMouseNeedRefresh;
extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditor;
HEFI_EDITOR_FILE_IMAGE HFileImage;
HEFI_EDITOR_FILE_IMAGE HFileImageBackupVar;
//
// for basic initialization of HFileImage
//
HEFI_EDITOR_BUFFER_IMAGE HFileImageConst = {
NULL,
0,
FALSE
};
EFI_STATUS
HFileImageInit (
VOID
)
/*++
Routine Description:
Initialization function for HFileImage
Arguments:
None
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
--*/
{
//
// basically initialize the HFileImage
//
CopyMem (&HFileImage, &HFileImageConst, sizeof (HFileImage));
CopyMem (
&HFileImageBackupVar,
&HFileImageConst,
sizeof (HFileImageBackupVar)
);
return EFI_SUCCESS;
}
EFI_STATUS
HFileImageBackup (
VOID
)
/*++
Routine Description:
Backup function for HFileImage
Only a few fields need to be backup.
This is for making the file buffer refresh
as few as possible.
Arguments:
None
Returns:
EFI_SUCCESS
EFI_OUT_OF_RESOURCES
--*/
{
SHELL_FREE_NON_NULL (HFileImageBackupVar.FileName);
HFileImageBackupVar.FileName = CatSPrint(NULL, L"%s", HFileImage.FileName);
if (HFileImageBackupVar.FileName == NULL) {
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
EFI_STATUS
HFileImageCleanup (
VOID
)
/*++
Routine Description:
Cleanup function for HFileImage
Arguments:
None
Returns:
EFI_SUCCESS
--*/
{
SHELL_FREE_NON_NULL (HFileImage.FileName);
SHELL_FREE_NON_NULL (HFileImageBackupVar.FileName);
return EFI_SUCCESS;
}
EFI_STATUS
HFileImageSetFileName (
IN CONST CHAR16 *Str
)
/*++
Routine Description:
Set FileName field in HFileImage
Arguments:
Str -- File name to set
Returns:
EFI_SUCCESS
EFI_OUT_OF_RESOURCES
--*/
{
UINTN Size;
UINTN Index;
//
// free the old file name
//
SHELL_FREE_NON_NULL (HFileImage.FileName);
Size = StrLen (Str);
HFileImage.FileName = AllocateZeroPool (2 * (Size + 1));
if (HFileImage.FileName == NULL) {
return EFI_OUT_OF_RESOURCES;
}
for (Index = 0; Index < Size; Index++) {
HFileImage.FileName[Index] = Str[Index];
}
HFileImage.FileName[Size] = L'\0';
return EFI_SUCCESS;
}
EFI_STATUS
HFileImageGetFileInfo (
IN EFI_FILE_HANDLE Handle,
IN CHAR16 *FileName,
OUT EFI_FILE_INFO **InfoOut
)
/*++
Routine Description:
Get this file's information
Arguments:
Handle - in NT32 mode Directory handle, in other mode File Handle
FileName - The file name
InfoOut - parameter to pass file information out
Returns:
EFI_SUCCESS
EFI_OUT_OF_RESOURCES
EFI_LOAD_ERROR
--*/
{
VOID *Info;
UINTN Size;
EFI_STATUS Status;
Size = SIZE_OF_EFI_FILE_INFO + 1024;
Info = AllocateZeroPool (Size);
if (!Info) {
return EFI_OUT_OF_RESOURCES;
}
//
// get file information
//
Status = Handle->GetInfo (Handle, &gEfiFileInfoGuid, &Size, Info);
if (EFI_ERROR (Status)) {
return EFI_LOAD_ERROR;
}
*InfoOut = (EFI_FILE_INFO *) Info;
return EFI_SUCCESS;
}
EFI_STATUS
HFileImageRead (
IN CONST CHAR16 *FileName,
IN BOOLEAN Recover
)
/*++
Routine Description:
Read a file from disk into HBufferImage
Arguments:
FileName -- filename to read
Recover -- if is for recover, no information print
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
EFI_OUT_OF_RESOURCES
--*/
{
HEFI_EDITOR_LINE *Line;
UINT8 *Buffer;
CHAR16 *UnicodeBuffer;
EFI_STATUS Status;
//
// variable initialization
//
Line = NULL;
//
// in this function, when you return error ( except EFI_OUT_OF_RESOURCES )
// you should set status string
// since this function maybe called before the editorhandleinput loop
// so any error will cause editor return
// so if you want to print the error status
// you should set the status string
//
Status = ReadFileIntoBuffer (FileName, (VOID**)&Buffer, &HFileImage.Size, &HFileImage.ReadOnly);
if (EFI_ERROR(Status)) {
UnicodeBuffer = CatSPrint(NULL, L"Read error on file &s: %r", FileName, Status);
if (UnicodeBuffer == NULL) {
SHELL_FREE_NON_NULL(Buffer);
return EFI_OUT_OF_RESOURCES;
}
StatusBarSetStatusString (UnicodeBuffer);
FreePool (UnicodeBuffer);
}
HFileImageSetFileName (FileName);
//
// free the old lines
//
HBufferImageFree ();
Status = HBufferImageBufferToList (Buffer, HFileImage.Size);
SHELL_FREE_NON_NULL (Buffer);
if (EFI_ERROR (Status)) {
StatusBarSetStatusString (L"Error parsing file.");
return Status;
}
HBufferImage.DisplayPosition.Row = 2;
HBufferImage.DisplayPosition.Column = 10;
HBufferImage.MousePosition.Row = 2;
HBufferImage.MousePosition.Column = 10;
HBufferImage.LowVisibleRow = 1;
HBufferImage.HighBits = TRUE;
HBufferImage.BufferPosition.Row = 1;
HBufferImage.BufferPosition.Column = 1;
if (!Recover) {
UnicodeBuffer = CatSPrint(NULL, L"%d Lines Read", HBufferImage.NumLines);
if (UnicodeBuffer == NULL) {
SHELL_FREE_NON_NULL(Buffer);
return EFI_OUT_OF_RESOURCES;
}
StatusBarSetStatusString (UnicodeBuffer);
FreePool (UnicodeBuffer);
HMainEditor.SelectStart = 0;
HMainEditor.SelectEnd = 0;
}
//
// has line
//
if (HBufferImage.Lines != 0) {
HBufferImage.CurrentLine = CR (HBufferImage.ListHead->ForwardLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
} else {
//
// create a dummy line
//
Line = HBufferImageCreateLine ();
if (Line == NULL) {
SHELL_FREE_NON_NULL(Buffer);
return EFI_OUT_OF_RESOURCES;
}
HBufferImage.CurrentLine = Line;
}
HBufferImage.Modified = FALSE;
HBufferImageNeedRefresh = TRUE;
HBufferImageOnlyLineNeedRefresh = FALSE;
HBufferImageMouseNeedRefresh = TRUE;
return EFI_SUCCESS;
}
EFI_STATUS
HFileImageSave (
IN CHAR16 *FileName
)
/*++
Routine Description:
Save lines in HBufferImage to disk
Arguments:
FileName - The file name
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
EFI_OUT_OF_RESOURCES
--*/
{
LIST_ENTRY *Link;
HEFI_EDITOR_LINE *Line;
CHAR16 *Str;
EFI_STATUS Status;
UINTN NumLines;
SHELL_FILE_HANDLE FileHandle;
UINTN TotalSize;
UINT8 *Buffer;
UINT8 *Ptr;
EDIT_FILE_TYPE BufferTypeBackup;
BufferTypeBackup = HBufferImage.BufferType;
HBufferImage.BufferType = FileTypeFileBuffer;
//
// if is the old file
//
if (StrCmp (FileName, HFileImage.FileName) == 0) {
//
// check whether file exists on disk
//
if (ShellIsFile(FileName) == EFI_SUCCESS) {
//
// current file exists on disk
// so if not modified, then not save
//
if (HBufferImage.Modified == FALSE) {
return EFI_SUCCESS;
}
//
// if file is read-only, set error
//
if (HFileImage.ReadOnly == TRUE) {
StatusBarSetStatusString (L"Read Only File Can Not Be Saved");
return EFI_SUCCESS;
}
}
}
if (ShellIsDirectory(FileName) == EFI_SUCCESS) {
StatusBarSetStatusString (L"Directory Can Not Be Saved");
return EFI_LOAD_ERROR;
}
Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
if (!EFI_ERROR (Status)) {
//
// the file exits, delete it
//
Status = ShellDeleteFile (&FileHandle);
if (EFI_ERROR (Status) || Status == EFI_WARN_DELETE_FAILURE) {
StatusBarSetStatusString (L"Write File Failed");
return EFI_LOAD_ERROR;
}
}
//
// write all the lines back to disk
//
NumLines = 0;
TotalSize = 0;
for (Link = HBufferImage.ListHead->ForwardLink; Link != HBufferImage.ListHead; Link = Link->ForwardLink) {
Line = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
if (Line->Size != 0) {
TotalSize += Line->Size;
}
//
// end of if Line -> Size != 0
//
NumLines++;
}
//
// end of for Link
//
Buffer = AllocateZeroPool (TotalSize);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Ptr = Buffer;
for (Link = HBufferImage.ListHead->ForwardLink; Link != HBufferImage.ListHead; Link = Link->ForwardLink) {
Line = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
if (Line->Size != 0) {
CopyMem (Ptr, Line->Buffer, Line->Size);
Ptr += Line->Size;
}
//
// end of if Line -> Size != 0
//
}
Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
if (EFI_ERROR (Status)) {
StatusBarSetStatusString (L"Create File Failed");
return EFI_LOAD_ERROR;
}
Status = ShellWriteFile (FileHandle, &TotalSize, Buffer);
FreePool (Buffer);
if (EFI_ERROR (Status)) {
ShellDeleteFile (&FileHandle);
return EFI_LOAD_ERROR;
}
ShellCloseFile(&FileHandle);
HBufferImage.Modified = FALSE;
//
// set status string
//
Str = CatSPrint(NULL, L"%d Lines Wrote", NumLines);
StatusBarSetStatusString (Str);
FreePool (Str);
//
// now everything is ready , you can set the new file name to filebuffer
//
if (BufferTypeBackup != FileTypeFileBuffer || StringNoCaseCompare (&FileName, &HFileImage.FileName) != 0) {
//
// not the same
//
HFileImageSetFileName (FileName);
if (HFileImage.FileName == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
HFileImage.ReadOnly = FALSE;
return EFI_SUCCESS;
}

View File

@ -0,0 +1,56 @@
/** @file
Defines FileImage - the view of the file that is visible at any point,
as well as the event handlers for editing the file
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_FILE_IMAGE_H_
#define _LIB_FILE_IMAGE_H_
#include "HexEditor.h"
EFI_STATUS
HFileImageInit (
VOID
);
EFI_STATUS
HFileImageCleanup (
VOID
);
EFI_STATUS
HFileImageBackup (
VOID
);
EFI_STATUS
HFileImageSetFileName (
IN CONST CHAR16 *
);
EFI_STATUS
HFileImageGetFileInfo (
EFI_FILE_HANDLE,
CHAR16 *,
EFI_FILE_INFO **
);
EFI_STATUS
HFileImageRead (
IN CONST CHAR16 *,
IN BOOLEAN
);
EFI_STATUS
HFileImageSave (
IN CHAR16 *
);
#endif

View File

@ -0,0 +1,247 @@
/** @file
Main entry point of editor
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "UefiShellDebug1CommandsLib.h"
#include "HexEditor.h"
//
// Global Variables
//
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-f", TypeFlag},
{L"-d", TypeFlag},
{L"-m", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'hexedit' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunHexEdit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
CHAR16 *Buffer;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
LIST_ENTRY *Package;
CONST CHAR16 *Cwd;
CHAR16 *NFS;
CHAR16 *Spot;
CONST CHAR16 *Name;
UINTN Offset;
UINTN Size;
UINT64 LastOffset;
EDIT_FILE_TYPE WhatToDo;
Buffer = NULL;
ShellStatus = SHELL_SUCCESS;
NFS = NULL;
Cwd = NULL;
Buffer = NULL;
Name = NULL;
Spot = NULL;
Offset = 0;
Size = 0;
LastOffset = 0;
WhatToDo = FileTypeNone;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// Check for -d
//
if (ShellCommandLineGetFlag(Package, L"-d")){
if (ShellCommandLineGetCount(Package) < 4) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetCount(Package) > 4) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
WhatToDo = FileTypeDiskBuffer;
Name = ShellCommandLineGetRawValue(Package, 1);
Offset = ShellStrToUintn(ShellCommandLineGetRawValue(Package, 2));
Size = ShellStrToUintn(ShellCommandLineGetRawValue(Package, 3));
}
}
//
// check for -f
//
if (ShellCommandLineGetFlag(Package, L"-f") && (WhatToDo == FileTypeNone)){
if (ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Name = ShellCommandLineGetRawValue(Package, 1);
if (!IsValidFileName(Name)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Name);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
WhatToDo = FileTypeFileBuffer;
}
}
}
//
// check for -m
//
if (ShellCommandLineGetFlag(Package, L"-m") && (WhatToDo == FileTypeNone)){
if (ShellCommandLineGetCount(Package) < 3) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetCount(Package) > 3) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
WhatToDo = FileTypeMemBuffer;
Offset = ShellStrToUintn(ShellCommandLineGetRawValue(Package, 1));
Size = ShellStrToUintn(ShellCommandLineGetRawValue(Package, 2));
}
}
ShellCommandLineFreeVarList (Package);
if (ShellStatus == SHELL_SUCCESS && WhatToDo == FileTypeNone) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
}
if (ShellStatus == SHELL_SUCCESS) {
//
// Do the editor
//
Status = HMainEditorInit ();
if (EFI_ERROR (Status)) {
gST->ConOut->ClearScreen (gST->ConOut);
gST->ConOut->EnableCursor (gST->ConOut, TRUE);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_INIT_FAILED), gShellDebug1HiiHandle);
} else {
HMainEditorBackup ();
switch (WhatToDo) {
case FileTypeFileBuffer:
Status = HBufferImageRead (
Name,
NULL,
0,
0,
0,
0,
FileTypeFileBuffer,
FALSE
);
break;
case FileTypeDiskBuffer:
Status = HBufferImageRead (
NULL,
Name,
Offset,
Size,
0,
0,
FileTypeDiskBuffer,
FALSE
);
break;
case FileTypeMemBuffer:
Status = HBufferImageRead (
NULL,
NULL,
0,
0,
(UINT32) Offset,
Size,
FileTypeMemBuffer,
FALSE
);
break;
}
if (!EFI_ERROR (Status)) {
HMainEditorRefresh ();
Status = HMainEditorKeyInput ();
}
if (Status != EFI_OUT_OF_RESOURCES) {
//
// back up the status string
//
Buffer = CatSPrint (NULL, L"%s", StatusBarGetString());
}
}
//
// cleanup
//
HMainEditorCleanup ();
if (!EFI_ERROR (Status)) {
if (ShellStatus == SHELL_SUCCESS) {
ShellStatus = SHELL_UNSUPPORTED;
}
}
//
// print editor exit code on screen
//
if (Status == EFI_OUT_OF_RESOURCES) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle);
} else if (EFI_ERROR(Status)){
if (Buffer != NULL) {
if (StrCmp (Buffer, L"") != 0) {
//
// print out the status string
//
ShellPrintEx(-1, -1, L"%s", gShellDebug1HiiHandle, Buffer);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_UNKNOWN_EDITOR), gShellDebug1HiiHandle);
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_UNKNOWN_EDITOR), gShellDebug1HiiHandle);
}
}
}
}
SHELL_FREE_NON_NULL (Buffer);
return ShellStatus;
}

View File

@ -0,0 +1,41 @@
/** @file
Main include file for hex editor
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _EFI_SHELL_HEXEDIT_H_
#define _EFI_SHELL_HEXEDIT_H_
#include "UefiShellDebug1CommandsLib.h"
#include "HexEditorTypes.h"
#include "MainHexEditor.h"
#include "BufferImage.h"
#include "FileImage.h"
#include "DiskImage.h"
#include "MemImage.h"
#include "EditTitleBar.h"
#include "EditStatusBar.h"
#include "EditInputBar.h"
#include "EditMenuBar.h"
#include "Misc.h"
#include "Clipboard.h"
extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditor;
extern BOOLEAN HEditorFirst;
extern BOOLEAN HEditorExit;
#endif // _HEDITOR_H

View File

@ -0,0 +1,132 @@
/** @file
data types that are used by editor
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _HEDITOR_TYPE_H_
#define _HEDITOR_TYPE_H_
#include "UefiShellDebug1CommandsLib.h"
#include "EditTitleBar.h"
#define EFI_EDITOR_LINE_LIST 'eell'
#define ASCII_POSITION ((0x10 * 3) + 12)
typedef struct {
UINTN Row;
UINTN Column;
} HEFI_EDITOR_POSITION;
typedef
EFI_STATUS
(*HEFI_MENU_ITEM_FUNCTION) (
VOID
);
typedef struct {
CHAR16 Name[50];
CHAR16 Key[3];
HEFI_MENU_ITEM_FUNCTION Function;
} HMENU_ITEMS;
typedef struct _HEFI_EDITOR_LINE {
UINTN Signature;
UINT8 Buffer[0x10];
UINTN Size; // unit is Unicode
LIST_ENTRY Link;
} HEFI_EDITOR_LINE;
typedef struct _HEFI_EDITOR_MENU_ITEM {
CHAR16 NameToken;
CHAR16 FunctionKeyToken;
HEFI_MENU_ITEM_FUNCTION Function;
} HEFI_EDITOR_MENU_ITEM;
typedef struct {
UINT32 Foreground : 4;
UINT32 Background : 4;
} HEFI_EDITOR_COLOR_ATTRIBUTES;
typedef union {
HEFI_EDITOR_COLOR_ATTRIBUTES Colors;
UINT8 Data;
} HEFI_EDITOR_COLOR_UNION;
typedef struct {
UINTN Columns;
UINTN Rows;
} HEFI_EDITOR_TEXT_MODE;
typedef struct {
CHAR16 *Name;
UINTN BlockSize;
UINTN Size;
UINTN Offset;
} HEFI_EDITOR_DISK_IMAGE;
typedef struct {
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoFncs;
UINTN Offset;
UINTN Size;
} HEFI_EDITOR_MEM_IMAGE;
typedef struct {
CHAR16 *FileName;
UINTN Size; // file size
BOOLEAN ReadOnly; // file is read-only or not
} HEFI_EDITOR_FILE_IMAGE;
typedef struct {
LIST_ENTRY *ListHead; // list head of lines
HEFI_EDITOR_LINE *Lines; // lines of current file
UINTN NumLines; // number of lines
HEFI_EDITOR_LINE *CurrentLine; // current line cursor is at
HEFI_EDITOR_POSITION DisplayPosition; // cursor position in screen
HEFI_EDITOR_POSITION MousePosition; // mouse position in screen
HEFI_EDITOR_POSITION BufferPosition; // cursor position in buffer
UINTN LowVisibleRow; // the lowest visible row of file position
BOOLEAN HighBits; // cursor is at the high4 bits or low4 bits
BOOLEAN Modified; // BUFFER is modified or not
EDIT_FILE_TYPE BufferType;
HEFI_EDITOR_FILE_IMAGE *FileImage;
HEFI_EDITOR_DISK_IMAGE *DiskImage;
HEFI_EDITOR_MEM_IMAGE *MemImage;
} HEFI_EDITOR_BUFFER_IMAGE;
typedef struct {
UINT8 *Buffer;
UINTN Size;
} HEFI_EDITOR_CLIPBOARD;
typedef struct {
HEFI_EDITOR_BUFFER_IMAGE *BufferImage;
HEFI_EDITOR_CLIPBOARD *Clipboard;
HEFI_EDITOR_COLOR_UNION ColorAttributes;
HEFI_EDITOR_POSITION ScreenSize; // row number and column number
BOOLEAN MouseSupported;
EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface;
INT32 MouseAccumulatorX;
INT32 MouseAccumulatorY;
UINTN SelectStart; // starting from 1
UINTN SelectEnd; // starting from 1
} HEFI_EDITOR_GLOBAL_EDITOR;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,48 @@
/** @file
Defines the Main Editor data type -
- Global variables
- Instances of the other objects of the editor
- Main Interfaces
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_EDITOR_H_
#define _LIB_EDITOR_H_
#include "HexEditor.h"
EFI_STATUS
HMainEditorInit (
VOID
);
EFI_STATUS
HMainEditorCleanup (
VOID
);
EFI_STATUS
HMainEditorRefresh (
VOID
);
EFI_STATUS
HMainEditorKeyInput (
VOID
);
/**
Backup function for MainEditor.
**/
VOID
EFIAPI
HMainEditorBackup (
VOID
);
#endif

View File

@ -0,0 +1,412 @@
/** @file
Functions to deal with Mem buffer
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "HexEditor.h"
extern EFI_HANDLE HImageHandleBackup;
extern HEFI_EDITOR_BUFFER_IMAGE HBufferImage;
extern BOOLEAN HBufferImageNeedRefresh;
extern BOOLEAN HBufferImageOnlyLineNeedRefresh;
extern BOOLEAN HBufferImageMouseNeedRefresh;
extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditor;
HEFI_EDITOR_MEM_IMAGE HMemImage;
HEFI_EDITOR_MEM_IMAGE HMemImageBackupVar;
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL DummyPciRootBridgeIo;
//
// for basic initialization of HDiskImage
//
HEFI_EDITOR_MEM_IMAGE HMemImageConst = {
NULL,
0,
0
};
EFI_STATUS
DummyMemRead (
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL * This,
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
);
EFI_STATUS
DummyMemWrite (
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL * This,
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
);
EFI_STATUS
HMemImageInit (
VOID
)
/*++
Routine Description:
Initialization function for HDiskImage
Arguments:
None
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
--*/
{
EFI_STATUS Status;
//
// basically initialize the HMemImage
//
CopyMem (&HMemImage, &HMemImageConst, sizeof (HMemImage));
Status = gBS->LocateProtocol (
&gEfiPciRootBridgeIoProtocolGuid,
NULL,
(VOID**)&HMemImage.IoFncs
);
if (Status == EFI_NOT_FOUND) {
//
// For NT32, no EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL is available
// Use Dummy PciRootBridgeIo for memory access
//
ZeroMem (&DummyPciRootBridgeIo, sizeof (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL));
DummyPciRootBridgeIo.Mem.Read = DummyMemRead;
DummyPciRootBridgeIo.Mem.Write = DummyMemWrite;
HMemImage.IoFncs = &DummyPciRootBridgeIo;
Status = EFI_SUCCESS;
}
if (!EFI_ERROR (Status)) {
return EFI_SUCCESS;
} else {
return EFI_LOAD_ERROR;
}
}
EFI_STATUS
HMemImageBackup (
VOID
)
/*++
Routine Description:
Backup function for HDiskImage
Only a few fields need to be backup.
This is for making the Disk buffer refresh
as few as possible.
Arguments:
None
Returns:
EFI_SUCCESS
--*/
{
HMemImageBackupVar.Offset = HMemImage.Offset;
HMemImageBackupVar.Size = HMemImage.Size;
return EFI_SUCCESS;
}
EFI_STATUS
HMemImageCleanup (
VOID
)
/*++
Routine Description:
Cleanup function for HDiskImage
Arguments:
None
Returns:
EFI_SUCCESS
--*/
{
return EFI_SUCCESS;
}
EFI_STATUS
HMemImageSetMemOffsetSize (
IN UINTN Offset,
IN UINTN Size
)
/*++
Routine Description:
Set FileName field in HFileImage
Arguments:
Offset - The offset
Size - The size
Returns:
EFI_SUCCESS
EFI_OUT_OF_RESOURCES
--*/
{
HMemImage.Offset = Offset;
HMemImage.Size = Size;
return EFI_SUCCESS;
}
EFI_STATUS
HMemImageRead (
IN UINTN Offset,
IN UINTN Size,
BOOLEAN Recover
)
/*++
Routine Description:
Read a disk from disk into HBufferImage
Arguments:
Offset - The offset
Size - The size
Recover - if is for recover, no information print
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
EFI_OUT_OF_RESOURCES
--*/
{
EFI_STATUS Status;
void *Buffer;
CHAR16 *Str;
HEFI_EDITOR_LINE *Line;
EDIT_FILE_TYPE BufferTypeBackup;
BufferTypeBackup = HBufferImage.BufferType;
HBufferImage.BufferType = FileTypeMemBuffer;
Buffer = AllocateZeroPool (Size);
if (Buffer == NULL) {
StatusBarSetStatusString (L"Read Memory Failed");
return EFI_OUT_OF_RESOURCES;
}
Status = HMemImage.IoFncs->Mem.Read (
HMemImage.IoFncs,
EfiPciWidthUint8,
Offset,
Size,
Buffer
);
if (EFI_ERROR (Status)) {
FreePool (Buffer);
StatusBarSetStatusString (L"Memory Specified Not Accessible");
return EFI_LOAD_ERROR;
}
HBufferImageFree ();
Status = HBufferImageBufferToList (Buffer, Size);
FreePool (Buffer);
if (EFI_ERROR (Status)) {
StatusBarSetStatusString (L"Read Memory Failed");
return Status;
}
Status = HMemImageSetMemOffsetSize (Offset, Size);
HBufferImage.DisplayPosition.Row = 2;
HBufferImage.DisplayPosition.Column = 10;
HBufferImage.MousePosition.Row = 2;
HBufferImage.MousePosition.Column = 10;
HBufferImage.LowVisibleRow = 1;
HBufferImage.HighBits = TRUE;
HBufferImage.BufferPosition.Row = 1;
HBufferImage.BufferPosition.Column = 1;
if (!Recover) {
Str = CatSPrint(NULL, L"%d Lines Read", HBufferImage.NumLines);
if (Str == NULL) {
StatusBarSetStatusString (L"Read Memory Failed");
return EFI_OUT_OF_RESOURCES;
}
StatusBarSetStatusString (Str);
SHELL_FREE_NON_NULL (Str);
HMainEditor.SelectStart = 0;
HMainEditor.SelectEnd = 0;
}
//
// has line
//
if (HBufferImage.Lines != NULL) {
HBufferImage.CurrentLine = CR (HBufferImage.ListHead->ForwardLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
} else {
//
// create a dummy line
//
Line = HBufferImageCreateLine ();
if (Line == NULL) {
StatusBarSetStatusString (L"Read Memory Failed");
return EFI_OUT_OF_RESOURCES;
}
HBufferImage.CurrentLine = Line;
}
HBufferImage.Modified = FALSE;
HBufferImageNeedRefresh = TRUE;
HBufferImageOnlyLineNeedRefresh = FALSE;
HBufferImageMouseNeedRefresh = TRUE;
return EFI_SUCCESS;
}
EFI_STATUS
HMemImageSave (
IN UINTN Offset,
IN UINTN Size
)
/*++
Routine Description:
Save lines in HBufferImage to disk
Arguments:
Offset - The offset
Size - The size
Returns:
EFI_SUCCESS
EFI_LOAD_ERROR
EFI_OUT_OF_RESOURCES
--*/
{
EFI_STATUS Status;
VOID *Buffer;
EDIT_FILE_TYPE BufferTypeBackup;
//
// not modified, so directly return
//
if (HBufferImage.Modified == FALSE) {
return EFI_SUCCESS;
}
BufferTypeBackup = HBufferImage.BufferType;
HBufferImage.BufferType = FileTypeMemBuffer;
Buffer = AllocateZeroPool (Size);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = HBufferImageListToBuffer (Buffer, Size);
if (EFI_ERROR (Status)) {
FreePool (Buffer);
return Status;
}
//
// write back to memory
//
Status = HMemImage.IoFncs->Mem.Write (
HMemImage.IoFncs,
EfiPciWidthUint8,
Offset,
Size,
Buffer
);
FreePool (Buffer);
if (EFI_ERROR (Status)) {
return EFI_LOAD_ERROR;
}
//
// now not modified
//
HBufferImage.Modified = FALSE;
return EFI_SUCCESS;
}
EFI_STATUS
DummyMemRead (
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL * This,
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
DummyMemWrite (
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL * This,
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
{
return EFI_UNSUPPORTED;
}

View File

@ -0,0 +1,52 @@
/** @file
Defines MemImage - the view of the file that is visible at any point,
as well as the event handlers for editing the file
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_MEM_IMAGE_H_
#define _LIB_MEM_IMAGE_H_
#include "HexEditor.h"
EFI_STATUS
HMemImageInit (
VOID
);
EFI_STATUS
HMemImageCleanup (
VOID
);
EFI_STATUS
HMemImageBackup (
VOID
);
EFI_STATUS
HMemImageSetMemOffsetSize (
IN UINTN,
IN UINTN
);
EFI_STATUS
HMemImageRead (
IN UINTN,
IN UINTN,
IN BOOLEAN
);
EFI_STATUS
HMemImageSave (
IN UINTN,
IN UINTN
);
#endif

View File

@ -0,0 +1,541 @@
/** @file
Implementation of various string and line routines
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "HexEditor.h"
extern BOOLEAN HEditorMouseAction;
VOID
HEditorClearLine (
IN UINTN Row
)
/*++
Routine Description:
Clear line at Row
Arguments:
Row -- row number to be cleared ( start from 1 )
Returns:
EFI_SUCCESS
--*/
{
CHAR16 Line[200];
UINTN Index;
UINTN Limit;
UINTN StartCol;
if (HEditorMouseAction) {
Limit = 3 * 0x10;
StartCol = 10;
} else {
Limit = HMainEditor.ScreenSize.Column;
StartCol = 1;
}
//
// prepare a blank line
//
for (Index = 0; Index < Limit; Index++) {
Line[Index] = ' ';
}
if (Row == HMainEditor.ScreenSize.Row && Limit == HMainEditor.ScreenSize.Column) {
//
// if '\0' is still at position 80, it will cause first line error
//
Line[Limit - 1] = '\0';
} else {
Line[Limit] = '\0';
}
//
// print out the blank line
//
ShellPrintEx ((INT32)StartCol - 1, (INT32)Row - 1, Line);
}
HEFI_EDITOR_LINE *
HLineDup (
IN HEFI_EDITOR_LINE *Src
)
/*++
Routine Description:
Duplicate a line
Arguments:
Src -- line to be duplicated
Returns:
NULL -- wrong
Not NULL -- line created
--*/
{
HEFI_EDITOR_LINE *Dest;
//
// allocate for the line structure
//
Dest = AllocateZeroPool (sizeof (HEFI_EDITOR_LINE));
if (Dest == NULL) {
return NULL;
}
Dest->Signature = EFI_EDITOR_LINE_LIST;
Dest->Size = Src->Size;
CopyMem (Dest->Buffer, Src->Buffer, 0x10);
Dest->Link = Src->Link;
return Dest;
}
VOID
HLineFree (
IN HEFI_EDITOR_LINE *Src
)
/*++
Routine Description:
Free a line and it's internal buffer
Arguments:
Src -- line to be freed
Returns:
None
--*/
{
if (Src == NULL) {
return ;
}
SHELL_FREE_NON_NULL (Src);
}
HEFI_EDITOR_LINE *
_HLineAdvance (
IN UINTN Count
)
/*++
Routine Description:
Advance to the next Count lines
Arguments:
Count -- line number to advance
Returns:
NULL -- wrong
Not NULL -- line after advance
--*/
{
UINTN Index;
HEFI_EDITOR_LINE *Line;
Line = HMainEditor.BufferImage->CurrentLine;
if (Line == NULL) {
return NULL;
}
for (Index = 0; Index < Count; Index++) {
//
// if already last line
//
if (Line->Link.ForwardLink == HMainEditor.BufferImage->ListHead) {
return NULL;
}
Line = CR (Line->Link.ForwardLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
}
return Line;
}
HEFI_EDITOR_LINE *
_HLineRetreat (
IN UINTN Count
)
/*++
Routine Description:
Retreat to the previous Count lines
Arguments:
Count -- line number to retreat
Returns:
NULL -- wrong
Not NULL -- line after retreat
--*/
{
UINTN Index;
HEFI_EDITOR_LINE *Line;
Line = HMainEditor.BufferImage->CurrentLine;
if (Line == NULL) {
return NULL;
}
for (Index = 0; Index < Count; Index++) {
//
// already the first line
//
if (Line->Link.BackLink == HMainEditor.BufferImage->ListHead) {
return NULL;
}
Line = CR (Line->Link.BackLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
}
return Line;
}
HEFI_EDITOR_LINE *
HMoveLine (
IN INTN Count
)
/*++
Routine Description:
Advance/Retreat lines
Arguments:
Count -- line number to advance/retreat
>0 : advance
<0: retreat
Returns:
NULL -- wrong
Not NULL -- line after advance
--*/
{
HEFI_EDITOR_LINE *Line;
UINTN AbsCount;
//
// difference with MoveCurrentLine
// just return Line
// do not set currentline to Line
//
if (Count <= 0) {
AbsCount = -Count;
Line = _HLineRetreat (AbsCount);
} else {
Line = _HLineAdvance (Count);
}
return Line;
}
HEFI_EDITOR_LINE *
HMoveCurrentLine (
IN INTN Count
)
/*++
Routine Description:
Advance/Retreat lines and set CurrentLine in BufferImage to it
Arguments:
Count -- line number to advance/retreat
>0 : advance
<0: retreat
Returns:
NULL -- wrong
Not NULL -- line after advance
--*/
{
HEFI_EDITOR_LINE *Line;
UINTN AbsCount;
//
// <0: retreat
// >0: advance
//
if (Count <= 0) {
AbsCount = -Count;
Line = _HLineRetreat (AbsCount);
} else {
Line = _HLineAdvance (Count);
}
if (Line == NULL) {
return NULL;
}
HMainEditor.BufferImage->CurrentLine = Line;
return Line;
}
EFI_STATUS
HFreeLines (
IN LIST_ENTRY *ListHead,
IN HEFI_EDITOR_LINE *Lines
)
/*++
Routine Description:
Free all the lines in HBufferImage
Fields affected:
Lines
CurrentLine
NumLines
ListHead
Arguments:
ListHead - The list head
Lines - The lines
Returns:
EFI_SUCCESS
--*/
{
LIST_ENTRY *Link;
HEFI_EDITOR_LINE *Line;
//
// release all the lines
//
if (Lines != NULL) {
Line = Lines;
Link = &(Line->Link);
do {
Line = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
Link = Link->ForwardLink;
HLineFree (Line);
} while (Link != ListHead);
}
ListHead->ForwardLink = ListHead;
ListHead->BackLink = ListHead;
return EFI_SUCCESS;
}
UINTN
HStrStr (
IN CHAR16 *Str,
IN CHAR16 *Pat
)
/*++
Routine Description:
Search Pat in Str
Arguments:
Str -- mother string
Pat -- search pattern
Returns:
0 : not found
>= 1 : found position + 1
--*/
{
INTN *Failure;
INTN i;
INTN j;
INTN Lenp;
INTN Lens;
//
// this function copies from some lib
//
Lenp = StrLen (Pat);
Lens = StrLen (Str);
Failure = AllocateZeroPool (Lenp * sizeof (INTN));
Failure[0] = -1;
for (j = 1; j < Lenp; j++) {
i = Failure[j - 1];
while ((Pat[j] != Pat[i + 1]) && (i >= 0)) {
i = Failure[i];
}
if (Pat[j] == Pat[i + 1]) {
Failure[j] = i + 1;
} else {
Failure[j] = -1;
}
}
i = 0;
j = 0;
while (i < Lens && j < Lenp) {
if (Str[i] == Pat[j]) {
i++;
j++;
} else if (j == 0) {
i++;
} else {
j = Failure[j - 1] + 1;
}
}
FreePool (Failure);
//
// 0: not found
// >=1 : found position + 1
//
return ((j == Lenp) ? (i - Lenp) : -1) + 1;
}
INT32
HGetTextX (
IN INT32 GuidX
)
{
INT32 Gap;
HMainEditor.MouseAccumulatorX += GuidX;
Gap = (HMainEditor.MouseAccumulatorX * (INT32) HMainEditor.ScreenSize.Column) / (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionX);
HMainEditor.MouseAccumulatorX = (HMainEditor.MouseAccumulatorX * (INT32) HMainEditor.ScreenSize.Column) % (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionX);
HMainEditor.MouseAccumulatorX = HMainEditor.MouseAccumulatorX / (INT32) HMainEditor.ScreenSize.Column;
return Gap;
}
INT32
HGetTextY (
IN INT32 GuidY
)
{
INT32 Gap;
HMainEditor.MouseAccumulatorY += GuidY;
Gap = (HMainEditor.MouseAccumulatorY * (INT32) HMainEditor.ScreenSize.Row) / (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionY);
HMainEditor.MouseAccumulatorY = (HMainEditor.MouseAccumulatorY * (INT32) HMainEditor.ScreenSize.Row) % (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionY);
HMainEditor.MouseAccumulatorY = HMainEditor.MouseAccumulatorY / (INT32) HMainEditor.ScreenSize.Row;
return Gap;
}
EFI_STATUS
HXtoi (
IN CHAR16 *Str,
OUT UINTN *Value
)
/*++
Routine Description:
convert hex string to uint
Arguments:
Str - The string
Value - The value
Returns:
--*/
{
UINT64 u;
CHAR16 c;
UINTN Size;
Size = sizeof (UINTN);
//
// skip leading white space
//
while (*Str && *Str == ' ') {
Str += 1;
}
if (StrLen (Str) > Size * 2) {
return EFI_LOAD_ERROR;
}
//
// convert hex digits
//
u = 0;
c = *Str;
while (c) {
c = *Str;
Str++;
if (c == 0) {
break;
}
//
// not valid char
//
if (!((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || (c >= '0' && c <= '9') || (c == '\0'))) {
return EFI_LOAD_ERROR;
}
if (c >= 'a' && c <= 'f') {
c -= 'a' - 'A';
}
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
u = LShiftU64 (u, 4) + (c - (c >= 'A' ? 'A' - 10 : '0'));
} else {
//
// '\0'
//
break;
}
}
*Value = (UINTN) u;
return EFI_SUCCESS;
}

View File

@ -0,0 +1,96 @@
/** @file
Definitions for various line and string routines
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_MISC_H_
#define _LIB_MISC_H_
#include "HexEditor.h"
VOID
HEditorClearLine (
UINTN
);
HEFI_EDITOR_LINE *
HLineDup (
HEFI_EDITOR_LINE *
);
VOID
HLineFree (
HEFI_EDITOR_LINE *
);
HEFI_EDITOR_LINE *
HMoveLine (
INTN
);
HEFI_EDITOR_LINE *
HMoveCurrentLine (
INTN
);
UINTN
HLineStrInsert (
HEFI_EDITOR_LINE *,
CHAR16,
UINTN,
UINTN
);
VOID
HLineCat (
HEFI_EDITOR_LINE *,
HEFI_EDITOR_LINE *
);
VOID
HLineDeleteAt (
HEFI_EDITOR_LINE *,
UINTN
);
UINTN
HUnicodeToAscii (
CHAR16 *,
UINTN,
CHAR8 *
);
UINTN
HStrStr (
CHAR16 *,
CHAR16 *
);
EFI_STATUS
HFreeLines (
LIST_ENTRY *,
HEFI_EDITOR_LINE *
);
INT32
HGetTextX (
INT32
) ;
INT32
HGetTextY (
INT32
) ;
EFI_STATUS
HXtoi (
CHAR16 *,
UINTN *
);
#endif