/** @file\r
The tool dumps the contents of a firmware volume\r
\r
-Copyright (c) 1999 - 2016, 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
VOID\r
);\r
\r
+UINT32\r
+UnicodeStrLen (\r
+ IN CHAR16 *String\r
+ )\r
+ /*++\r
+\r
+ Routine Description:\r
+\r
+ Returns the length of a null-terminated unicode string.\r
+\r
+ Arguments:\r
+\r
+ String - The pointer to a null-terminated unicode string.\r
+\r
+ Returns:\r
+\r
+ N/A\r
+\r
+ --*/\r
+{\r
+ UINT32 Length;\r
+\r
+ for (Length = 0; *String != L'\0'; String++, Length++) {\r
+ ;\r
+ }\r
+ return Length;\r
+}\r
+\r
+VOID\r
+Unicode2AsciiString (\r
+ IN CHAR16 *Source,\r
+ OUT CHAR8 *Destination\r
+ )\r
+ /*++\r
+\r
+ Routine Description:\r
+\r
+ Convert a null-terminated unicode string to a null-terminated ascii string.\r
+\r
+ Arguments:\r
+\r
+ Source - The pointer to the null-terminated input unicode string.\r
+ Destination - The pointer to the null-terminated output ascii string.\r
+\r
+ Returns:\r
+\r
+ N/A\r
+\r
+ --*/\r
+{\r
+ while (*Source != '\0') {\r
+ *(Destination++) = (CHAR8) *(Source++);\r
+ }\r
+ //\r
+ // End the ascii with a NULL.\r
+ //\r
+ *Destination = '\0';\r
+}\r
+\r
int\r
main (\r
int argc,\r
continue;\r
}\r
if ((stricmp (argv[0], "--hash") == 0)) {\r
+ if (EnableHash == TRUE) {\r
+ //\r
+ // --hash already given in the option, ignore this one\r
+ //\r
+ argc --;\r
+ argv ++;\r
+ continue;\r
+ }\r
EnableHash = TRUE;\r
OpenSslCommand = "openssl";\r
OpenSslEnv = getenv("OPENSSL_PATH");\r
if (OpenSslEnv == NULL) {\r
OpenSslPath = OpenSslCommand;\r
} else {\r
- OpenSslPath = malloc(strlen(OpenSslEnv)+strlen(OpenSslCommand)+1);\r
+ //\r
+ // We add quotes to the Openssl Path in case it has space characters\r
+ //\r
+ OpenSslPath = malloc(2+strlen(OpenSslEnv)+strlen(OpenSslCommand)+1);\r
if (OpenSslPath == NULL) {\r
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
return GetUtilityStatus ();\r
\r
Routine Description:\r
\r
- This function returns the next larger size that meets the alignment \r
+ This function returns the next larger size that meets the alignment\r
requirement specified.\r
\r
Arguments:\r
\r
ActualSize The size.\r
Alignment The desired alignment.\r
- \r
+\r
Returns:\r
- \r
+\r
EFI_SUCCESS Function completed successfully.\r
EFI_ABORTED The function encountered an error.\r
\r
//\r
// 0x02\r
//\r
- "EFI_SECTION_GUID_DEFINED", \r
+ "EFI_SECTION_GUID_DEFINED",\r
//\r
// 0x03\r
//\r
//\r
// 0x12\r
//\r
- "EFI_SECTION_TE", \r
+ "EFI_SECTION_TE",\r
//\r
// 0x13\r
//\r
- "EFI_SECTION_DXE_DEPEX", \r
+ "EFI_SECTION_DXE_DEPEX",\r
//\r
// 0x14\r
//\r
\r
Routine Description:\r
\r
- This function determines the size of the FV and the erase polarity. The \r
+ This function determines the size of the FV and the erase polarity. The\r
erase polarity is the FALSE value for file state.\r
\r
Arguments:\r
InputFile The file that contains the FV image.\r
FvSize The size of the FV.\r
ErasePolarity The FV erase polarity.\r
- \r
+\r
Returns:\r
- \r
+\r
EFI_SUCCESS Function completed successfully.\r
EFI_INVALID_PARAMETER A required parameter was NULL or is out of range.\r
EFI_ABORTED The function encountered an error.\r
if (VolumeHeader.Attributes & EFI_FVB2_ALIGNMENT_64K) {\r
printf (" EFI_FVB2_ALIGNMENT_64K\n");\r
}\r
- \r
+\r
#else\r
\r
if (VolumeHeader.Attributes & EFI_FVB2_READ_LOCK_CAP) {\r
EFI_STATUS Status;\r
UINT8 GuidBuffer[PRINTED_GUID_BUFFER_SIZE];\r
UINT32 HeaderSize;\r
-#if (PI_SPECIFICATION_VERSION < 0x00010000) \r
+#if (PI_SPECIFICATION_VERSION < 0x00010000)\r
UINT16 *Tail;\r
#endif\r
//\r
return EFI_ABORTED;\r
}\r
}\r
-#if (PI_SPECIFICATION_VERSION < 0x00010000) \r
+#if (PI_SPECIFICATION_VERSION < 0x00010000)\r
//\r
// Verify tail if present\r
//\r
return EFI_ABORTED;\r
}\r
}\r
- #endif \r
+ #endif\r
break;\r
\r
default:\r
printf ("EFI_FV_FILETYPE_SMM_CORE\n");\r
break;\r
\r
+ case EFI_FV_FILETYPE_MM_STANDALONE:\r
+ printf ("EFI_FV_FILETYPE_MM_STANDALONE\n");\r
+ break;\r
+\r
+ case EFI_FV_FILETYPE_MM_CORE_STANDALONE:\r
+ printf ("EFI_FV_FILETYPE_MM_CORE_STANDALONE\n");\r
+ break;\r
+\r
case EFI_FV_FILETYPE_FFS_PAD:\r
printf ("EFI_FV_FILETYPE_FFS_PAD\n");\r
break;\r
//\r
// Update Image Base Address\r
//\r
- if ((ImgHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (ImgHdr->Pe32.FileHeader.Machine != IMAGE_FILE_MACHINE_IA64)) {\r
+ if (ImgHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
ImgHdr->Pe32.OptionalHeader.ImageBase = (UINT32) NewPe32BaseAddress;\r
} else if (ImgHdr->Pe32Plus.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
ImgHdr->Pe32Plus.OptionalHeader.ImageBase = NewPe32BaseAddress;\r
)\r
{\r
UINT32 DefaultPathLen;\r
+ UINT64 Index;\r
+ CHAR8 QuotesStr[] = "\"";\r
+ strcpy(NewPath, QuotesStr);\r
DefaultPathLen = strlen(DefaultPath);\r
- strcpy(NewPath, DefaultPath);\r
- UINT64 Index = 0;\r
- for (; Index < DefaultPathLen; Index ++) {\r
+ strcat(NewPath, DefaultPath);\r
+ Index = 0;\r
+ for (; Index < DefaultPathLen + 1; Index ++) {\r
if (NewPath[Index] == '\\' || NewPath[Index] == '/') {\r
if (NewPath[Index + 1] != '\0') {\r
NewPath[Index] = '/';\r
NewPath[Index + 1] = '\0';\r
}\r
strcat(NewPath, AppendPath);\r
+ strcat(NewPath, QuotesStr);\r
return EFI_SUCCESS;\r
}\r
\r
\r
EFI_SECTION_ERROR - Problem with section parsing.\r
(a) compression errors\r
- (b) unrecognized section \r
+ (b) unrecognized section\r
EFI_UNSUPPORTED - Do not know how to parse the section.\r
EFI_SUCCESS - Section successfully parsed.\r
EFI_OUT_OF_RESOURCES - Memory allocation failed.\r
CHAR8 *ExtractionTool;\r
CHAR8 *ToolInputFile;\r
CHAR8 *ToolOutputFile;\r
- CHAR8 *SystemCommandFormatString;\r
CHAR8 *SystemCommand;\r
EFI_GUID *EfiGuid;\r
UINT16 DataOffset;\r
UINT32 RealHdrLen;\r
CHAR8 *ToolInputFileName;\r
CHAR8 *ToolOutputFileName;\r
+ CHAR8 *UIFileName;\r
\r
ParsedLength = 0;\r
ToolInputFileName = NULL;\r
SectionLength - SectionHeaderLen\r
);\r
\r
- SystemCommandFormatString = "%s sha1 -out %s %s";\r
SystemCommand = malloc (\r
- strlen (SystemCommandFormatString) +\r
+ strlen (OPENSSL_COMMAND_FORMAT_STRING) +\r
strlen (OpenSslPath) +\r
strlen (ToolInputFileName) +\r
strlen (ToolOutputFileName) +\r
}\r
sprintf (\r
SystemCommand,\r
- SystemCommandFormatString,\r
+ OPENSSL_COMMAND_FORMAT_STRING,\r
OpenSslPath,\r
ToolOutputFileName,\r
ToolInputFileName\r
break;\r
\r
case EFI_SECTION_USER_INTERFACE:\r
- printf (" String: %ls\n", (CHAR16 *) &((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString);\r
+ UIFileName = (CHAR8 *) malloc (UnicodeStrLen (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString) + 1);\r
+ if (UIFileName == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ Unicode2AsciiString (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString, UIFileName);\r
+ printf (" String: %s\n", UIFileName);\r
+ free (UIFileName);\r
break;\r
\r
case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:\r
}\r
\r
ScratchBuffer = malloc (ScratchSize);\r
+ if (ScratchBuffer == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
UncompressedBuffer = malloc (UncompressedLength);\r
- if ((ScratchBuffer == NULL) || (UncompressedBuffer == NULL)) {\r
+ if (UncompressedBuffer == NULL) {\r
+ free (ScratchBuffer);\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
return EFI_OUT_OF_RESOURCES;\r
}\r
Status = DecompressFunction (\r
//\r
// Construction 'system' command string\r
//\r
- SystemCommandFormatString = "%s -d -o %s %s";\r
SystemCommand = malloc (\r
- strlen (SystemCommandFormatString) +\r
+ strlen (EXTRACT_COMMAND_FORMAT_STRING) +\r
strlen (ExtractionTool) +\r
strlen (ToolInputFile) +\r
strlen (ToolOutputFile) +\r
}\r
sprintf (\r
SystemCommand,\r
- SystemCommandFormatString,\r
+ EXTRACT_COMMAND_FORMAT_STRING,\r
ExtractionTool,\r
ToolOutputFile,\r
ToolInputFile\r
{\r
FILE *Fptr;\r
CHAR8 Line[MAX_LINE_LEN];\r
+ CHAR8 FormatString[MAX_LINE_LEN];\r
GUID_TO_BASENAME *GPtr;\r
\r
if ((Fptr = fopen (LongFilePath (FileName), "r")) == NULL) {\r
return EFI_DEVICE_ERROR;\r
}\r
\r
+ //\r
+ // Generate the format string for fscanf\r
+ //\r
+ sprintf (\r
+ FormatString,\r
+ "%%%us %%%us",\r
+ (unsigned) sizeof (GPtr->Guid) - 1,\r
+ (unsigned) sizeof (GPtr->BaseName) - 1\r
+ );\r
+\r
while (fgets (Line, sizeof (Line), Fptr) != NULL) {\r
//\r
// Allocate space for another guid/basename element\r
//\r
GPtr = malloc (sizeof (GUID_TO_BASENAME));\r
if (GPtr == NULL) {\r
+ fclose (Fptr);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
memset ((char *) GPtr, 0, sizeof (GUID_TO_BASENAME));\r
- if (sscanf (Line, "%s %s", GPtr->Guid, GPtr->BaseName) == 2) {\r
+ if (sscanf (Line, FormatString, GPtr->Guid, GPtr->BaseName) == 2) {\r
GPtr->Next = mGuidBaseNameList;\r
mGuidBaseNameList = GPtr;\r
} else {\r
\r
//\r
// Copyright declaration\r
- // \r
- fprintf (stdout, "Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.\n\n");\r
+ //\r
+ fprintf (stdout, "Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.\n\n");\r
fprintf (stdout, " Display Tiano Firmware Volume FFS image information\n\n");\r
\r
//\r