X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellCommandLib%2FUefiShellCommandLib.c;h=a2ebc8f8206118852b7d17540504de8d79321139;hb=17c3dc19395121486c6f1614dbc564f39763720a;hp=b6d5d991a6786eee271023e9f8967449b5356eac;hpb=421fbf99f82f6925c395cbd25821ccec09582b6b;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index b6d5d991a6..a2ebc8f820 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1,8 +1,10 @@ /** @file Provides interface to shell internal functions for shell commands. + Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+ 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 @@ -29,6 +31,25 @@ STATIC UINTN mFsMaxCount = 0; STATIC UINTN mBlkMaxCount = 0; STATIC BUFFER_LIST mFileHandleList; +STATIC CONST CHAR8 Hex[] = { + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F' +}; + // global variables required by library class. EFI_UNICODE_COLLATION_PROTOCOL *gUnicodeCollation = NULL; SHELL_MAP_LIST gShellMapList; @@ -107,7 +128,6 @@ ShellCommandLibConstructor ( @param[in] List The list to free. **/ VOID -EFIAPI FreeFileHandleList ( IN BUFFER_LIST *List ) @@ -223,7 +243,6 @@ ShellCommandLibDestructor ( @retval NULL no dynamic command protocol instance found for name **/ CONST EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL * -EFIAPI ShellCommandFindDynamicCommand ( IN CONST CHAR16 *CommandString ) @@ -272,7 +291,6 @@ ShellCommandFindDynamicCommand ( @param[in] CommandString The command string to check for on the list. **/ BOOLEAN -EFIAPI ShellCommandDynamicCommandExists ( IN CONST CHAR16 *CommandString ) @@ -286,7 +304,6 @@ ShellCommandDynamicCommandExists ( @param[in] CommandString The command string to check for on the list. **/ BOOLEAN -EFIAPI ShellCommandIsCommandOnInternalList( IN CONST CHAR16 *CommandString ) @@ -344,7 +361,6 @@ ShellCommandIsCommandOnList( @return String of help text. Caller required to free. **/ CHAR16* -EFIAPI ShellCommandGetDynamicCommandHelp( IN CONST CHAR16 *CommandString ) @@ -371,7 +387,6 @@ ShellCommandGetDynamicCommandHelp( @return String of help text. Caller reuiqred to free. **/ CHAR16* -EFIAPI ShellCommandGetInternalCommandHelp( IN CONST CHAR16 *CommandString ) @@ -525,9 +540,14 @@ ShellCommandRegisterCommandName ( // allocate memory for new struct // Node = AllocateZeroPool(sizeof(SHELL_COMMAND_INTERNAL_LIST_ENTRY)); - ASSERT(Node != NULL); + if (Node == NULL) { + return RETURN_OUT_OF_RESOURCES; + } Node->CommandString = AllocateCopyPool(StrSize(CommandString), CommandString); - ASSERT(Node->CommandString != NULL); + if (Node->CommandString == NULL) { + FreePool (Node); + return RETURN_OUT_OF_RESOURCES; + } Node->GetManFileName = GetManFileName; Node->CommandHandler = CommandHandler; @@ -786,11 +806,20 @@ ShellCommandRegisterAlias ( // allocate memory for new struct // Node = AllocateZeroPool(sizeof(ALIAS_LIST)); - ASSERT(Node != NULL); + if (Node == NULL) { + return RETURN_OUT_OF_RESOURCES; + } Node->CommandString = AllocateCopyPool(StrSize(Command), Command); + if (Node->CommandString == NULL) { + FreePool (Node); + return RETURN_OUT_OF_RESOURCES; + } Node->Alias = AllocateCopyPool(StrSize(Alias), Alias); - ASSERT(Node->CommandString != NULL); - ASSERT(Node->Alias != NULL); + if (Node->Alias == NULL) { + FreePool (Node->CommandString); + FreePool (Node); + return RETURN_OUT_OF_RESOURCES; + } InsertHeadList (&mAliasList.Link, &Node->Link); @@ -892,7 +921,7 @@ ShellCommandIsOnAliasList( } /** - Function to determine current state of ECHO. Echo determins if lines from scripts + Function to determine current state of ECHO. Echo determines if lines from scripts and ECHO commands are enabled. @retval TRUE Echo is currently enabled @@ -908,7 +937,7 @@ ShellCommandGetEchoState( } /** - Function to set current state of ECHO. Echo determins if lines from scripts + Function to set current state of ECHO. Echo determines if lines from scripts and ECHO commands are enabled. If State is TRUE, Echo will be enabled. @@ -1192,10 +1221,8 @@ ShellCommandAddMapItemAndUpdatePath( ASSERT((NewPath == NULL && NewPathSize == 0) || (NewPath != NULL)); if (OriginalPath != NULL) { StrnCatGrow(&NewPath, &NewPathSize, OriginalPath, 0); - } else { - StrnCatGrow(&NewPath, &NewPathSize, L".\\", 0); + StrnCatGrow(&NewPath, &NewPathSize, L";", 0); } - StrnCatGrow(&NewPath, &NewPathSize, L";", 0); StrnCatGrow(&NewPath, &NewPathSize, Name, 0); StrnCatGrow(&NewPath, &NewPathSize, L"\\efi\\tools\\;", 0); StrnCatGrow(&NewPath, &NewPathSize, Name, 0); @@ -1261,6 +1288,9 @@ ShellCommandCreateInitialMappingsAndPaths( ; MapListNode = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link) ){ RemoveEntryList(&MapListNode->Link); + SHELL_FREE_NON_NULL(MapListNode->DevicePath); + SHELL_FREE_NON_NULL(MapListNode->MapName); + SHELL_FREE_NON_NULL(MapListNode->CurrentDirectoryPath); FreePool(MapListNode); } // for loop } @@ -1279,7 +1309,10 @@ ShellCommandCreateInitialMappingsAndPaths( // Get all Device Paths // DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count); - ASSERT(DevicePathList != NULL); + if (DevicePathList == NULL) { + SHELL_FREE_NON_NULL (HandleList); + return EFI_OUT_OF_RESOURCES; + } for (Count = 0 ; HandleList[Count] != NULL ; Count++) { DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]); @@ -1336,7 +1369,10 @@ ShellCommandCreateInitialMappingsAndPaths( // Get all Device Paths // DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count); - ASSERT(DevicePathList != NULL); + if (DevicePathList == NULL) { + SHELL_FREE_NON_NULL (HandleList); + return EFI_OUT_OF_RESOURCES; + } for (Count = 0 ; HandleList[Count] != NULL ; Count++) { DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]); @@ -1670,3 +1706,112 @@ FreeBufferList ( } } +/** + Dump some hexadecimal data to the screen. + + @param[in] Indent How many spaces to indent the output. + @param[in] Offset The offset of the printing. + @param[in] DataSize The size in bytes of UserData. + @param[in] UserData The data to print out. +**/ +VOID +EFIAPI +DumpHex ( + IN UINTN Indent, + IN UINTN Offset, + IN UINTN DataSize, + IN VOID *UserData + ) +{ + UINT8 *Data; + + CHAR8 Val[50]; + + CHAR8 Str[20]; + + UINT8 TempByte; + UINTN Size; + UINTN Index; + + Data = UserData; + while (DataSize != 0) { + Size = 16; + if (Size > DataSize) { + Size = DataSize; + } + + for (Index = 0; Index < Size; Index += 1) { + TempByte = Data[Index]; + Val[Index * 3 + 0] = Hex[TempByte >> 4]; + Val[Index * 3 + 1] = Hex[TempByte & 0xF]; + Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' '); + Str[Index] = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte); + } + + Val[Index * 3] = 0; + Str[Index] = 0; + ShellPrintEx(-1, -1, L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str); + + Data += Size; + Offset += Size; + DataSize -= Size; + } +} + +/** + Dump HEX data into buffer. + + @param[in] Buffer HEX data to be dumped in Buffer. + @param[in] Indent How many spaces to indent the output. + @param[in] Offset The offset of the printing. + @param[in] DataSize The size in bytes of UserData. + @param[in] UserData The data to print out. +**/ +CHAR16* +EFIAPI +CatSDumpHex ( + IN CHAR16 *Buffer, + IN UINTN Indent, + IN UINTN Offset, + IN UINTN DataSize, + IN VOID *UserData + ) +{ + UINT8 *Data; + UINT8 TempByte; + UINTN Size; + UINTN Index; + CHAR8 Val[50]; + CHAR8 Str[20]; + CHAR16 *RetVal; + CHAR16 *TempRetVal; + + Data = UserData; + RetVal = Buffer; + while (DataSize != 0) { + Size = 16; + if (Size > DataSize) { + Size = DataSize; + } + + for (Index = 0; Index < Size; Index += 1) { + TempByte = Data[Index]; + Val[Index * 3 + 0] = Hex[TempByte >> 4]; + Val[Index * 3 + 1] = Hex[TempByte & 0xF]; + Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' '); + Str[Index] = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte); + } + + Val[Index * 3] = 0; + Str[Index] = 0; + TempRetVal = CatSPrint (RetVal, L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + + Data += Size; + Offset += Size; + DataSize -= Size; + } + + return RetVal; +}