]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c
ShellPkg/for: Fix potential null pointer deference
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / DmpStore.c
index 0eee944ed4296f97b808f7a5c9571b3dd5ea6589..5791da9acc8c5f0192dfa733e6f5247bb1427c25 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Main file for DmpStore shell Debug1 function.\r
    \r
-  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.\r
-  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<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
@@ -42,7 +42,6 @@ typedef struct {
   @retval The attribute string info.\r
 **/\r
 CHAR16 *\r
-EFIAPI\r
 GetAttrType (\r
   IN CONST UINT32 Atts\r
   )\r
@@ -82,6 +81,42 @@ GetAttrType (
   return RetString;\r
 }\r
 \r
+/**\r
+  Convert binary to hex format string.\r
+\r
+  @param[in]  Buffer            The binary data.\r
+  @param[in]  BufferSize        The size in bytes of the binary data.\r
+  @param[in, out] HexString     Hex format string.\r
+  @param[in]      HexStringSize The size in bytes of the string.\r
+\r
+  @return The hex format string.\r
+**/\r
+CHAR16*\r
+BinaryToHexString (\r
+  IN     VOID    *Buffer,\r
+  IN     UINTN   BufferSize,\r
+  IN OUT CHAR16  *HexString,\r
+  IN     UINTN   HexStringSize\r
+  )\r
+{\r
+  UINTN Index;\r
+  UINTN StringIndex;\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((BufferSize * 2 + 1) * sizeof (CHAR16) <= HexStringSize);\r
+\r
+  for (Index = 0, StringIndex = 0; Index < BufferSize; Index += 1) {\r
+    StringIndex +=\r
+      UnicodeSPrint (\r
+        &HexString[StringIndex],\r
+        HexStringSize - StringIndex * sizeof (CHAR16),\r
+        L"%02x",\r
+        ((UINT8 *) Buffer)[Index]\r
+        );\r
+  }\r
+  return HexString;\r
+}\r
+\r
 /**\r
   Load the variable data from file and set to variable data base.\r
 \r
@@ -206,7 +241,7 @@ LoadVariablesFromFile (
   }\r
     \r
   if ((Position != FileSize) || (ShellStatus != SHELL_SUCCESS)) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD_BAD_FILE), gShellDebug1HiiHandle);\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD_BAD_FILE), gShellDebug1HiiHandle, L"dmpstore");  \r
     if (Position != FileSize) {\r
       ShellStatus = SHELL_VOLUME_CORRUPTED;\r
     }\r
@@ -237,7 +272,7 @@ LoadVariablesFromFile (
                       Variable->Data\r
                       );\r
       if (EFI_ERROR (Status)) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD_GEN_FAIL), gShellDebug1HiiHandle, Variable->Name, Status);\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD_GEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", Variable->Name, Status);  \r
       }\r
     }\r
   }\r
@@ -329,13 +364,13 @@ AppendSingleVariableToFile (
   //\r
   // Crc32\r
   //\r
-  gBS->CalculateCrc32 (Buffer, (UINTN) (Ptr - Buffer), (UINT32 *) Ptr);\r
+  gBS->CalculateCrc32 (Buffer, (UINTN) Ptr - (UINTN) Buffer, (UINT32 *) Ptr);\r
 \r
   Status = ShellWriteFile (FileHandle, &BufferSize, Buffer);\r
   FreePool (Buffer);\r
 \r
   if (!EFI_ERROR (Status) && \r
-      (BufferSize != sizeof (NameSize) + sizeof (DataSize) + sizeof (*Guid) + sizeof (Attributes) + NameSize + DataSize)\r
+      (BufferSize != sizeof (NameSize) + sizeof (DataSize) + sizeof (*Guid) + sizeof (Attributes) + NameSize + DataSize + sizeof (UINT32))\r
     ) {\r
     Status = EFI_DEVICE_ERROR;\r
   }\r
@@ -351,14 +386,15 @@ AppendSingleVariableToFile (
 \r
   This is necessary since once a delete happens GetNextVariableName() will work.\r
 \r
-  @param[in] Name           The variable name of the EFI variable (or NULL).\r
-  @param[in] Guid           The GUID of the variable set (or NULL).\r
-  @param[in] Type           The operation type.\r
-  @param[in] FileHandle     The file to operate on (or NULL).\r
-  @param[in] PrevName       The previous variable name from GetNextVariableName. L"" to start.\r
-  @param[in] FoundVarGuid   The previous GUID from GetNextVariableName. ignored at start.\r
-  @param[in] FoundOne       If a VariableName or Guid was specified and one was printed or\r
-                            deleted, then set this to TRUE, otherwise ignored.\r
+  @param[in] Name                 The variable name of the EFI variable (or NULL).\r
+  @param[in] Guid                 The GUID of the variable set (or NULL).\r
+  @param[in] Type                 The operation type.\r
+  @param[in] FileHandle           The file to operate on (or NULL).\r
+  @param[in] PrevName             The previous variable name from GetNextVariableName. L"" to start.\r
+  @param[in] FoundVarGuid         The previous GUID from GetNextVariableName. ignored at start.\r
+  @param[in] FoundOne             If a VariableName or Guid was specified and one was printed or\r
+                                  deleted, then set this to TRUE, otherwise ignored.\r
+  @param[in] StandardFormatOutput TRUE indicates Standard-Format Output.\r
 \r
   @retval SHELL_SUCCESS           The operation was successful.\r
   @retval SHELL_OUT_OF_RESOURCES  A memorty allocation failed.\r
@@ -367,7 +403,6 @@ AppendSingleVariableToFile (
   @retval SHELL_NOT_FOUND         the Name/Guid pair could not be found.\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 CascadeProcessVariables (\r
   IN CONST CHAR16      *Name        OPTIONAL,\r
   IN CONST EFI_GUID    *Guid        OPTIONAL,\r
@@ -375,7 +410,8 @@ CascadeProcessVariables (
   IN EFI_FILE_PROTOCOL *FileHandle  OPTIONAL,\r
   IN CONST CHAR16      * CONST PrevName,\r
   IN EFI_GUID          FoundVarGuid,\r
-  IN BOOLEAN           *FoundOne\r
+  IN BOOLEAN           *FoundOne,\r
+  IN BOOLEAN           StandardFormatOutput\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -385,7 +421,10 @@ CascadeProcessVariables (
   UINT32                    Atts;\r
   SHELL_STATUS              ShellStatus;\r
   UINTN                     NameSize;\r
-  CHAR16                    *RetString;\r
+  CHAR16                    *AttrString;\r
+  CHAR16                    *HexString;\r
+  EFI_STATUS                SetStatus;\r
+  CONST CHAR16              *GuidName;\r
 \r
   if (ShellGetExecutionBreakFlag()) {\r
     return (SHELL_ABORTED);\r
@@ -398,6 +437,7 @@ CascadeProcessVariables (
     StrnCatGrow(&FoundVarName, &NameSize, PrevName, 0);\r
   } else {\r
     FoundVarName = AllocateZeroPool(sizeof(CHAR16));\r
+    NameSize = sizeof(CHAR16);\r
   }\r
 \r
   Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);\r
@@ -406,7 +446,7 @@ CascadeProcessVariables (
     FoundVarName = AllocateZeroPool (NameSize);\r
     if (FoundVarName != NULL) {\r
       if (PrevName != NULL) {\r
-        StrCpy(FoundVarName, PrevName);\r
+        StrnCpyS(FoundVarName, NameSize/sizeof(CHAR16), PrevName, NameSize/sizeof(CHAR16) - 1);\r
       }\r
 \r
       Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);\r
@@ -429,7 +469,7 @@ CascadeProcessVariables (
   //\r
   // Recurse to the next iteration.  We know "our" variable's name.\r
   //\r
-  ShellStatus = CascadeProcessVariables(Name, Guid, Type, FileHandle, FoundVarName, FoundVarGuid, FoundOne);\r
+  ShellStatus = CascadeProcessVariables (Name, Guid, Type, FileHandle, FoundVarName, FoundVarGuid, FoundOne, StandardFormatOutput);\r
 \r
   if (ShellGetExecutionBreakFlag() || (ShellStatus == SHELL_ABORTED)) {\r
     SHELL_FREE_NON_NULL(FoundVarName);\r
@@ -461,50 +501,78 @@ CascadeProcessVariables (
         Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);\r
       }\r
     }\r
-    if ((Type == DmpStoreDisplay) || (Type == DmpStoreSave)) {\r
       //\r
       // Last error check then print this variable out.\r
       //\r
+    if (Type == DmpStoreDisplay) {\r
       if (!EFI_ERROR(Status) && (DataBuffer != NULL) && (FoundVarName != NULL)) {\r
-        RetString = GetAttrType(Atts);\r
-        ShellPrintHiiEx(\r
-          -1,\r
-          -1,\r
-          NULL,\r
-          STRING_TOKEN(STR_DMPSTORE_HEADER_LINE),\r
-          gShellDebug1HiiHandle,\r
-          RetString,\r
-          &FoundVarGuid,\r
-          FoundVarName,\r
-          DataSize);\r
-        if (Type == DmpStoreDisplay) {\r
-          DumpHex(2, 0, DataSize, DataBuffer);\r
+        AttrString = GetAttrType(Atts);\r
+        if (StandardFormatOutput) {\r
+          HexString = AllocatePool ((DataSize * 2 + 1) * sizeof (CHAR16));\r
+          if (HexString != NULL) {\r
+            ShellPrintHiiEx (\r
+              -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_VAR_SFO), gShellDebug1HiiHandle,\r
+              FoundVarName, &FoundVarGuid, Atts, DataSize,\r
+              BinaryToHexString (\r
+                DataBuffer, DataSize, HexString, (DataSize * 2 + 1) * sizeof (CHAR16)\r
+                )\r
+              );\r
+            FreePool (HexString);\r
+          } else {\r
+            Status = EFI_OUT_OF_RESOURCES;\r
+          }\r
         } else {\r
-          Status = AppendSingleVariableToFile (\r
-                     FileHandle,\r
-                     FoundVarName,\r
-                     &FoundVarGuid,\r
-                     Atts,\r
-                     (UINT32) DataSize,\r
-                     DataBuffer\r
-                     );\r
+          Status = gEfiShellProtocol->GetGuidName(&FoundVarGuid, &GuidName);\r
+          if (EFI_ERROR (Status)) {\r
+            ShellPrintHiiEx (\r
+              -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,\r
+              AttrString, &FoundVarGuid, FoundVarName, DataSize\r
+              );\r
+          } else {\r
+            ShellPrintHiiEx (\r
+              -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE2), gShellDebug1HiiHandle,\r
+              AttrString, GuidName, FoundVarName, DataSize\r
+              );\r
+          }\r
+          DumpHex (2, 0, DataSize, DataBuffer);\r
         }\r
-        SHELL_FREE_NON_NULL(RetString);\r
+        SHELL_FREE_NON_NULL (AttrString);\r
+      }\r
+    } else if (Type == DmpStoreSave) {\r
+      if (!EFI_ERROR(Status) && (DataBuffer != NULL) && (FoundVarName != NULL)) {\r
+        AttrString = GetAttrType (Atts);\r
+        ShellPrintHiiEx (\r
+          -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,\r
+          AttrString, &FoundVarGuid, FoundVarName, DataSize\r
+          );\r
+        Status = AppendSingleVariableToFile (\r
+                   FileHandle,\r
+                   FoundVarName,\r
+                   &FoundVarGuid,\r
+                   Atts,\r
+                   (UINT32) DataSize,\r
+                   DataBuffer\r
+                   );\r
+        SHELL_FREE_NON_NULL (AttrString);\r
       }\r
     } else if (Type == DmpStoreDelete) {\r
       //\r
       // We only need name to delete it...\r
       //\r
-      ShellPrintHiiEx (\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        STRING_TOKEN(STR_DMPSTORE_DELETE_LINE),\r
-        gShellDebug1HiiHandle,\r
-        &FoundVarGuid,\r
-        FoundVarName,\r
-        gRT->SetVariable (FoundVarName, &FoundVarGuid, Atts, 0, NULL)\r
-        );\r
+      SetStatus = gRT->SetVariable (FoundVarName, &FoundVarGuid, Atts, 0, NULL);\r
+      if (StandardFormatOutput) {\r
+        if (SetStatus == EFI_SUCCESS) {\r
+          ShellPrintHiiEx (\r
+            -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_NG_SFO), gShellDebug1HiiHandle,\r
+            FoundVarName, &FoundVarGuid\r
+            );\r
+        }\r
+      } else {\r
+        ShellPrintHiiEx (\r
+          -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_DELETE_LINE), gShellDebug1HiiHandle,\r
+          &FoundVarGuid, FoundVarName, SetStatus\r
+          );\r
+      }\r
     }\r
     SHELL_FREE_NON_NULL(DataBuffer);\r
   }\r
@@ -525,10 +593,11 @@ CascadeProcessVariables (
 /**\r
   Function to display or delete variables.  This will set up and call into the recursive function.\r
 \r
-  @param[in] Name        The variable name of the EFI variable (or NULL).\r
-  @param[in] Guid        The GUID of the variable set (or NULL).\r
-  @param[in] Type        The operation type.\r
-  @param[in] FileHandle  The file to save or load variables.\r
+  @param[in] Name                 The variable name of the EFI variable (or NULL).\r
+  @param[in] Guid                 The GUID of the variable set (or NULL).\r
+  @param[in] Type                 The operation type.\r
+  @param[in] FileHandle           The file to save or load variables.\r
+  @param[in] StandardFormatOutput TRUE indicates Standard-Format Output.\r
 \r
   @retval SHELL_SUCCESS           The operation was successful.\r
   @retval SHELL_OUT_OF_RESOURCES  A memorty allocation failed.\r
@@ -537,12 +606,12 @@ CascadeProcessVariables (
   @retval SHELL_NOT_FOUND         the Name/Guid pair could not be found.\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 ProcessVariables (\r
   IN CONST CHAR16      *Name      OPTIONAL,\r
   IN CONST EFI_GUID    *Guid      OPTIONAL,\r
   IN DMP_STORE_TYPE    Type,\r
-  IN SHELL_FILE_HANDLE FileHandle OPTIONAL\r
+  IN SHELL_FILE_HANDLE FileHandle OPTIONAL,\r
+  IN BOOLEAN           StandardFormatOutput\r
   )\r
 {\r
   SHELL_STATUS              ShellStatus;\r
@@ -553,24 +622,40 @@ ProcessVariables (
   ShellStatus   = SHELL_SUCCESS;\r
   ZeroMem (&FoundVarGuid, sizeof(EFI_GUID));\r
 \r
+  if (StandardFormatOutput) {\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"dmpstore");\r
+  }\r
+\r
   if (Type == DmpStoreLoad) {\r
     ShellStatus = LoadVariablesFromFile (FileHandle, Name, Guid, &Found);\r
   } else {\r
-    ShellStatus = CascadeProcessVariables(Name, Guid, Type, FileHandle, NULL, FoundVarGuid, &Found);\r
+    ShellStatus = CascadeProcessVariables (Name, Guid, Type, FileHandle, NULL, FoundVarGuid, &Found, StandardFormatOutput);\r
   }\r
 \r
   if (!Found) {\r
     if (ShellStatus == SHELL_OUT_OF_RESOURCES) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"dmpstore");  \r
       return (ShellStatus);\r
     } else if (Name != NULL && Guid == NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, Name);\r
+      if (StandardFormatOutput) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N_SFO), gShellDebug1HiiHandle, Name);\r
+      } else {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, L"dmpstore", Name);  \r
+      }\r
     } else if (Name != NULL && Guid != NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN), gShellDebug1HiiHandle, Guid, Name);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN), gShellDebug1HiiHandle, L"dmpstore", Guid, Name);  \r
     } else if (Name == NULL && Guid == NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND), gShellDebug1HiiHandle);\r
+      if (StandardFormatOutput) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_SFO), gShellDebug1HiiHandle);\r
+      } else {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND), gShellDebug1HiiHandle, L"dmpstore");\r
+      }\r
     } else if (Name == NULL && Guid != NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G), gShellDebug1HiiHandle, Guid);\r
+      if (StandardFormatOutput) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G_SFO), gShellDebug1HiiHandle, Guid);\r
+      } else {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G), gShellDebug1HiiHandle, L"dmpstore", Guid);\r
+      }\r
     } \r
     return (SHELL_NOT_FOUND);\r
   }\r
@@ -583,6 +668,7 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {L"-s", TypeValue},\r
   {L"-all", TypeFlag},\r
   {L"-guid", TypeValue},\r
+  {L"-sfo", TypeFlag},\r
   {NULL, TypeMax}\r
   };\r
 \r
@@ -600,6 +686,7 @@ ShellCommandRunDmpStore (
   )\r
 {\r
   EFI_STATUS        Status;\r
+  RETURN_STATUS     RStatus;\r
   LIST_ENTRY        *Package;\r
   CHAR16            *ProblemParam;\r
   SHELL_STATUS      ShellStatus;\r
@@ -611,17 +698,19 @@ ShellCommandRunDmpStore (
   DMP_STORE_TYPE    Type;\r
   SHELL_FILE_HANDLE FileHandle;\r
   EFI_FILE_INFO     *FileInfo;\r
+  BOOLEAN           StandardFormatOutput;\r
 \r
-  ShellStatus   = SHELL_SUCCESS;\r
-  Package       = NULL;\r
-  FileHandle    = NULL;\r
-  File          = NULL;\r
-  Type          = DmpStoreDisplay;\r
+  ShellStatus          = SHELL_SUCCESS;\r
+  Package              = NULL;\r
+  FileHandle           = NULL;\r
+  File                 = NULL;\r
+  Type                 = DmpStoreDisplay;\r
+  StandardFormatOutput = FALSE;\r
 \r
   Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
   if (EFI_ERROR(Status)) {\r
     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dmpstore", ProblemParam);  \r
       FreePool(ProblemParam);\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
@@ -629,16 +718,19 @@ ShellCommandRunDmpStore (
     }\r
   } else {\r
     if (ShellCommandLineGetCount(Package) > 2) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmpstore");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else if (ShellCommandLineGetFlag(Package, L"-all") && ShellCommandLineGetFlag(Package, L"-guid")) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"-all", L"-guid");\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-all", L"-guid");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else if (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-l")) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"-l", L"-s");\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle,  L"dmpstore", L"-l", L"-s");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else if ((ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) && ShellCommandLineGetFlag(Package, L"-d")) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"-l or -s", L"-d");\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-d");  \r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+    } else if ((ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) && ShellCommandLineGetFlag(Package, L"-sfo")) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-sfo");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
       //\r
@@ -647,9 +739,9 @@ 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
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, GuidStr);\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
           Guid = &GuidData;\r
@@ -670,7 +762,7 @@ ShellCommandRunDmpStore (
           Type = DmpStoreSave;\r
           File = ShellCommandLineGetValue(Package, L"-s");\r
           if (File == NULL) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-s");\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-s");  \r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           } else {\r
             Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0);\r
@@ -680,16 +772,16 @@ ShellCommandRunDmpStore (
               //\r
               FileInfo = ShellGetFileInfo (FileHandle);\r
               if (FileInfo == NULL) {\r
-                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);\r
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);  \r
                 Status = EFI_DEVICE_ERROR;\r
               } else {\r
                 if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {\r
-                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, File);\r
+                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File);  \r
                   Status = EFI_INVALID_PARAMETER;\r
                 } else {\r
                   Status = ShellDeleteFile (&FileHandle);\r
                   if (EFI_ERROR (Status)) {\r
-                    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL), gShellDebug1HiiHandle, File);\r
+                    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);  \r
                   }\r
                 }\r
                 FreePool (FileInfo);\r
@@ -703,13 +795,13 @@ ShellCommandRunDmpStore (
               //\r
               // Otherwise it's bad.\r
               //\r
-              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);\r
+              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);  \r
             }\r
 \r
             if (!EFI_ERROR (Status)) {\r
               Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0);\r
               if (EFI_ERROR (Status)) {\r
-                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);\r
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);  \r
               }\r
             }\r
 \r
@@ -721,21 +813,21 @@ ShellCommandRunDmpStore (
           Type = DmpStoreLoad;\r
           File = ShellCommandLineGetValue(Package, L"-l");\r
           if (File == NULL) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-l");\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-l");  \r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           } else {\r
             Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_READ, 0);\r
             if (EFI_ERROR (Status)) {\r
-              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);  \r
               ShellStatus = SHELL_INVALID_PARAMETER;\r
             } else {\r
               FileInfo = ShellGetFileInfo (FileHandle);\r
               if (FileInfo == NULL) {\r
-                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);\r
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);  \r
                 ShellStatus = SHELL_DEVICE_ERROR;\r
               } else {\r
                 if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {\r
-                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, File);\r
+                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File);  \r
                   ShellStatus = SHELL_INVALID_PARAMETER;\r
                 }\r
                 FreePool (FileInfo);\r
@@ -745,6 +837,10 @@ ShellCommandRunDmpStore (
         } else if (ShellCommandLineGetFlag(Package, L"-d")) {\r
           Type = DmpStoreDelete;\r
         }\r
+\r
+        if (ShellCommandLineGetFlag (Package,L"-sfo")) {\r
+          StandardFormatOutput = TRUE;\r
+        }\r
       }\r
 \r
       if (ShellStatus == SHELL_SUCCESS) {\r
@@ -753,7 +849,7 @@ ShellCommandRunDmpStore (
         } else if (Type == DmpStoreLoad) {\r
           ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD), gShellDebug1HiiHandle, File);\r
         }\r
-        ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle);\r
+        ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle, StandardFormatOutput);\r
         if ((Type == DmpStoreLoad) || (Type == DmpStoreSave)) {\r
           ShellCloseFile (&FileHandle);\r
         }\r