]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/Debug1CommandLib: Use StrToGuid/StrHexToBytes in BaseLib
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 21 Feb 2017 09:20:54 +0000 (17:20 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Wed, 1 Mar 2017 05:39:46 +0000 (13:39 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c
ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c
ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h

index bb2c0b98ec6fdceccb383ad1734ef0649240fdac..701ff7505f2158f3d59923c2127fe20639270c08 100644 (file)
@@ -2,7 +2,7 @@
   Main file for DmpStore shell Debug1 function.\r
    \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -676,6 +676,7 @@ ShellCommandRunDmpStore (
   )\r
 {\r
   EFI_STATUS        Status;\r
+  RETURN_STATUS     RStatus;\r
   LIST_ENTRY        *Package;\r
   CHAR16            *ProblemParam;\r
   SHELL_STATUS      ShellStatus;\r
@@ -728,8 +729,8 @@ ShellCommandRunDmpStore (
       if (!ShellCommandLineGetFlag(Package, L"-all")) {\r
         GuidStr = ShellCommandLineGetValue(Package, L"-guid");\r
         if (GuidStr != NULL) {\r
-          Status = ConvertStringToGuid(GuidStr, &GuidData);\r
-          if (EFI_ERROR(Status)) {\r
+          RStatus = StrToGuid (GuidStr, &GuidData);\r
+          if (RETURN_ERROR (RStatus) || (GuidStr[GUID_STRING_LENGTH] != L'\0')) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmpstore", GuidStr);  \r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           }\r
index d98a3469a31ddf2d951c403d99ef8c110f1baeb6..c59032a81162ea4c523da28ab1fe4763b2760eaa 100644 (file)
@@ -2,7 +2,7 @@
   Main file for SetVar shell Debug1 function.\r
 \r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -65,6 +65,7 @@ ShellCommandRunSetVar (
   )\r
 {\r
   EFI_STATUS          Status;\r
+  RETURN_STATUS       RStatus;\r
   LIST_ENTRY          *Package;\r
   CHAR16              *ProblemParam;\r
   SHELL_STATUS        ShellStatus;\r
@@ -120,8 +121,8 @@ ShellCommandRunSetVar (
         CopyGuid(&Guid, &gEfiGlobalVariableGuid);\r
       } else {\r
         StringGuid = ShellCommandLineGetValue(Package, L"-guid");\r
-        Status = ConvertStringToGuid(StringGuid, &Guid);\r
-        if (EFI_ERROR(Status)) {\r
+        RStatus = StrToGuid (StringGuid, &Guid);\r
+        if (RETURN_ERROR (RStatus) || (StringGuid[GUID_STRING_LENGTH] != L'\0')) {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid);  \r
           ShellStatus = SHELL_INVALID_PARAMETER;\r
         }\r
@@ -207,10 +208,7 @@ ShellCommandRunSetVar (
             if (Buffer == NULL) {\r
               Status = EFI_OUT_OF_RESOURCES;\r
             } else {\r
-              for (LoopVar = 0 ; LoopVar < (StrLen(Data) / 2) ; LoopVar++) {\r
-                ((UINT8*)Buffer)[LoopVar] = (UINT8)(HexCharToUintn(Data[LoopVar*2]) * 16);\r
-                ((UINT8*)Buffer)[LoopVar] = (UINT8)(((UINT8*)Buffer)[LoopVar] + HexCharToUintn(Data[LoopVar*2+1]));\r
-              }\r
+              StrHexToBytes (Data, StrLen (Data), Buffer, StrLen (Data) / 2);\r
               Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrLen(Data) / 2, Buffer);\r
             }\r
             if (EFI_ERROR(Status)) {\r
index 6ebf0024c6134c0e8b6408ced465f021deb242f2..8e2141bf4350c920a0318692a0f3203eccab03b2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for NULL named library for debug1 profile shell command functions.\r
 \r
-  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -171,123 +171,6 @@ GetSystemConfigurationTable (
   return EFI_NOT_FOUND;\r
 }\r
 \r
-/**\r
-  Convert a Unicode character to numerical value.\r
-\r
-  This internal function only deal with Unicode character\r
-  which maps to a valid hexadecimal ASII character, i.e.\r
-  L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r
-  Unicode character, the value returned does not make sense.\r
-\r
-  @param  Char  The character to convert.\r
-\r
-  @return The numerical value converted.\r
-\r
-**/\r
-UINTN\r
-HexCharToUintn (\r
-  IN      CHAR16                    Char\r
-  )\r
-{\r
-  if (Char >= L'0' && Char <= L'9') {\r
-    return Char - L'0';\r
-  }\r
-\r
-  return (UINTN) (10 + CharToUpper (Char) - L'A');\r
-}\r
-\r
-/**\r
-  Convert a string representation of a guid to a Guid value.\r
-\r
-  @param[in] StringGuid    The pointer to the string of a guid.\r
-  @param[in, out] Guid     The pointer to the GUID structure to populate.\r
-\r
-  @retval EFI_INVALID_PARAMETER   A parameter was invalid.\r
-  @retval EFI_SUCCESS             The conversion was successful.\r
-**/\r
-EFI_STATUS\r
-ConvertStringToGuid (\r
-  IN CONST CHAR16 *StringGuid,\r
-  IN OUT EFI_GUID *Guid\r
-  )\r
-{\r
-  CHAR16  *TempCopy;\r
-  CHAR16  *TempSpot;\r
-  CHAR16  *Walker;\r
-  UINT64  TempVal;\r
-  EFI_STATUS Status;\r
-\r
-  if (StringGuid == NULL) {\r
-    return (EFI_INVALID_PARAMETER);\r
-  } else if (StrLen(StringGuid) != 36) {\r
-    return (EFI_INVALID_PARAMETER);\r
-  } \r
-  TempCopy = NULL;\r
-  TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);\r
-  if (TempCopy == NULL) {\r
-    return (EFI_OUT_OF_RESOURCES);\r
-  }\r
-  Walker   = TempCopy;\r
-  TempSpot = StrStr(Walker, L"-");\r
-  if (TempSpot != NULL) {\r
-    *TempSpot = CHAR_NULL;\r
-  }\r
-  Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool(TempCopy);\r
-    return (Status);\r
-  }\r
-  Guid->Data1 = (UINT32)TempVal;\r
-  Walker += 9;\r
-  TempSpot = StrStr(Walker, L"-");\r
-  if (TempSpot != NULL) {\r
-    *TempSpot = CHAR_NULL;\r
-  }\r
-  Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool(TempCopy);\r
-    return (Status);\r
-  }\r
-  Guid->Data2 = (UINT16)TempVal;\r
-  Walker += 5;\r
-  TempSpot = StrStr(Walker, L"-");\r
-  if (TempSpot != NULL) {\r
-    *TempSpot = CHAR_NULL;\r
-  }\r
-  Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool(TempCopy);\r
-    return (Status);\r
-  }\r
-  Guid->Data3 = (UINT16)TempVal;\r
-  Walker += 5;\r
-  Guid->Data4[0] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[1] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 3;\r
-  Guid->Data4[2] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[3] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[4] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[5] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[6] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[7] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[7] = (UINT8)(Guid->Data4[7] + (UINT8)HexCharToUintn(Walker[1]));\r
-  FreePool(TempCopy);\r
-  return (EFI_SUCCESS);\r
-}\r
-\r
 /**\r
   Clear the line at the specified Row.\r
   \r
index 52ea56aebb81d52ba2c41f86a9a592bdbeeec10b..80a8476a5ef54cacdc6566185cfcef7ecfc1d150 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for NULL named library for Profile1 shell command functions.\r
 \r
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -76,36 +76,6 @@ GetSystemConfigurationTable (
   IN OUT VOID **Table\r
   );\r
 \r
-/**\r
-  Convert a string representation of a GUID to the GUID value.\r
-\r
-  @param[in]  StringGuid   The pointer to the string containing a GUID printed.\r
-  @param[in, out] Guid     The pointer to the buffer to get the GUID value.\r
-**/\r
-EFI_STATUS\r
-ConvertStringToGuid (\r
-  IN CONST CHAR16 *StringGuid,\r
-  IN OUT EFI_GUID *Guid\r
-  );\r
-\r
-/**\r
-  Convert a Unicode character to numerical value.\r
-\r
-  This internal function only deal with Unicode character\r
-  which maps to a valid hexadecimal ASII character, i.e.\r
-  L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r
-  Unicode character, the value returned does not make sense.\r
-\r
-  @param  Char  The character to convert.\r
-\r
-  @return The numerical value converted.\r
-\r
-**/\r
-UINTN\r
-HexCharToUintn (\r
-  IN      CHAR16                    Char\r
-  );\r
-\r
 /**\r
   Function for 'setsize' command.\r
 \r