X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FC%2FGenSec%2FGenSec.c;h=46149762586ef0d7b849b3fa7333f462d5d40a3f;hb=9a8d7aa7f796ce68ece2815d268889ac4e2ac318;hp=9a1d0ca48a831522b4596ac93851760bcf765d73;hpb=a709adfaf0bebbaf3d989f56b500e3985687d0e3;p=mirror_edk2.git diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec/GenSec.c index 9a1d0ca48a..4614976258 100644 --- a/BaseTools/Source/C/GenSec/GenSec.c +++ b/BaseTools/Source/C/GenSec/GenSec.c @@ -1,7 +1,8 @@ /** @file +Creates output file that is a properly formed section per the PI spec. -Copyright (c) 2004 - 2008, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
+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 @@ -9,15 +10,13 @@ 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. -Module Name: - - GenSection.c - -Abstract: - - Creates output file that is a properly formed section per the PI spec. - **/ +#ifndef __GNUC__ +#include +#include +#include +#include +#endif #include #include @@ -27,12 +26,15 @@ Abstract: #include #include #include +#include #include "CommonLib.h" #include "Compress.h" #include "Crc32.h" #include "EfiUtilityMsgs.h" #include "ParseInf.h" +#include "FvLib.h" +#include "PeCoffLib.h" // // GenSec Tool Information @@ -41,8 +43,6 @@ Abstract: #define UTILITY_MAJOR_VERSION 0 #define UTILITY_MINOR_VERSION 1 -#define MAX_SECTION_SIZE 0x1000000 - STATIC CHAR8 *mSectionTypeName[] = { NULL, // 0x00 - reserved "EFI_SECTION_COMPRESSION", // 0x01 @@ -80,6 +80,12 @@ STATIC CHAR8 *mCompressionTypeName[] = { "PI_NONE", "PI_STD" }; #define EFI_GUIDED_SECTION_NONE 0x80 STATIC CHAR8 *mGUIDedSectionAttribue[] = { "NONE", "PROCESSING_REQUIRED", "AUTH_STATUS_VALID"}; +STATIC CHAR8 *mAlignName[] = { + "1", "2", "4", "8", "16", "32", "64", "128", "256", "512", + "1K", "2K", "4K", "8K", "16K", "32K", "64K", "128K", "256K", + "512K", "1M", "2M", "4M", "8M", "16M" +}; + // // Crc32 GUID section related definitions. // @@ -88,6 +94,11 @@ typedef struct { UINT32 CRC32Checksum; } CRC32_SECTION_HEADER; +typedef struct { + EFI_GUID_DEFINED_SECTION2 GuidSectionHeader; + UINT32 CRC32Checksum; +} CRC32_SECTION_HEADER2; + STATIC EFI_GUID mZeroGuid = {0x0, 0x0, 0x0, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; STATIC EFI_GUID mEfiCrc32SectionGuid = EFI_CRC32_GUIDED_SECTION_EXTRACTION_PROTOCOL_GUID; @@ -112,7 +123,7 @@ Returns: --*/ { - fprintf (stdout, "%s Version %d.%d\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION); + fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION); } STATIC @@ -144,7 +155,7 @@ Returns: // // Copyright declaration // - fprintf (stdout, "Copyright (c) 2007, Intel Corporation. All rights reserved.\n\n"); + fprintf (stdout, "Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.\n\n"); // // Details Option @@ -178,8 +189,16 @@ Returns: fprintf (stdout, " -n String, --name String\n\ String is a NULL terminated string used in Ui section.\n"); fprintf (stdout, " -j Number, --buildnumber Number\n\ - Number is an integer value between 0000 and 9999\n\ + Number is an integer value between 0 and 65535\n\ used in Ver section.\n"); + fprintf (stdout, " --sectionalign SectionAlign\n\ + SectionAlign points to section alignment, which support\n\ + the alignment scope 0~16M. If SectionAlign is specified\n\ + as 0, tool get alignment value from SectionFile. It is\n\ + specified in same order that the section file is input.\n"); + fprintf (stdout, " --dummy dummyfile\n\ + compare dummpyfile with input_file to decide whether\n\ + need to set PROCESSING_REQUIRED attribute.\n"); fprintf (stdout, " -v, --verbose Turn on verbose output with informational messages.\n"); fprintf (stdout, " -q, --quiet Disable all messages except key message and fatal error\n"); fprintf (stdout, " -d, --debug level Enable debug messages, at input debug level.\n"); @@ -256,20 +275,21 @@ Returns: FILE *InFile; UINT8 *Buffer; UINT32 TotalLength; + UINT32 HeaderLength; EFI_COMMON_SECTION_HEADER *CommonSect; STATUS Status; if (InputFileNum > 1) { - Error (NULL, 0, 2000, "Invalid paramter", "more than one input file specified"); + Error (NULL, 0, 2000, "Invalid parameter", "more than one input file specified"); return STATUS_ERROR; } else if (InputFileNum < 1) { - Error (NULL, 0, 2000, "Invalid paramter", "no input file specified"); + Error (NULL, 0, 2000, "Invalid parameter", "no input file specified"); return STATUS_ERROR; } // // Open the input file // - InFile = fopen (InputFileName[0], "rb"); + InFile = fopen (LongFilePath (InputFileName[0]), "rb"); if (InFile == NULL) { Error (NULL, 0, 0001, "Error opening file", InputFileName[0]); return STATUS_ERROR; @@ -288,9 +308,14 @@ Returns: // // Size must fit in 3 bytes // + //if (TotalLength >= MAX_SECTION_SIZE) { + // Error (NULL, 0, 2000, "Invalid parameter", "%s file size (0x%X) exceeds section size limit(%uM).", InputFileName[0], (unsigned) TotalLength, MAX_SECTION_SIZE>>20); + // goto Done; + //} + HeaderLength = sizeof (EFI_COMMON_SECTION_HEADER); if (TotalLength >= MAX_SECTION_SIZE) { - Error (NULL, 0, 2000, "Invalid paramter", "%s file size (0x%X) exceeds section size limit(%uM).", InputFileName[0], (unsigned) TotalLength, MAX_SECTION_SIZE>>20); - goto Done; + TotalLength = sizeof (EFI_COMMON_SECTION_HEADER2) + InputFileLength; + HeaderLength = sizeof (EFI_COMMON_SECTION_HEADER2); } VerboseMsg ("the size of the created section file is %u bytes", (unsigned) TotalLength); // @@ -303,15 +328,20 @@ Returns: } CommonSect = (EFI_COMMON_SECTION_HEADER *) Buffer; CommonSect->Type = SectionType; - CommonSect->Size[0] = (UINT8) (TotalLength & 0xff); - CommonSect->Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8); - CommonSect->Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16); + if (TotalLength < MAX_SECTION_SIZE) { + CommonSect->Size[0] = (UINT8) (TotalLength & 0xff); + CommonSect->Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8); + CommonSect->Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16); + } else { + memset(CommonSect->Size, 0xff, sizeof(UINT8) * 3); + ((EFI_COMMON_SECTION_HEADER2 *)CommonSect)->ExtendedSize = TotalLength; + } // // read data from the input file. // if (InputFileLength != 0) { - if (fread (Buffer + sizeof (EFI_COMMON_SECTION_HEADER), (size_t) InputFileLength, 1, InFile) != 1) { + if (fread (Buffer + HeaderLength, (size_t) InputFileLength, 1, InFile) != 1) { Error (NULL, 0, 0004, "Error reading file", InputFileName[0]); goto Done; } @@ -329,9 +359,50 @@ Done: return Status; } +STATIC +EFI_STATUS +StringtoAlignment ( + IN CHAR8 *AlignBuffer, + OUT UINT32 *AlignNumber + ) +/*++ + +Routine Description: + + Converts Align String to align value (1~16M). + +Arguments: + + AlignBuffer - Pointer to Align string. + AlignNumber - Pointer to Align value. + +Returns: + + EFI_SUCCESS Successfully convert align string to align value. + EFI_INVALID_PARAMETER Align string is invalid or align value is not in scope. + +--*/ +{ + UINT32 Index = 0; + // + // Check AlignBuffer + // + if (AlignBuffer == NULL) { + return EFI_INVALID_PARAMETER; + } + for (Index = 0; Index < sizeof (mAlignName) / sizeof (CHAR8 *); Index ++) { + if (stricmp (AlignBuffer, mAlignName [Index]) == 0) { + *AlignNumber = 1 << Index; + return EFI_SUCCESS; + } + } + return EFI_INVALID_PARAMETER; +} + EFI_STATUS GetSectionContents ( CHAR8 **InputFileName, + UINT32 *InputFileAlign, UINT32 InputFileNum, UINT8 *FileBuffer, UINT32 *BufferLength @@ -346,7 +417,9 @@ Routine Description: Arguments: InputFileName - Name of the input file. - + + InputFileAlign - Alignment required by the input file data. + InputFileNum - Number of input files. Should be at least 1. FileBuffer - Output buffer to contain data @@ -362,22 +435,32 @@ Returns: EFI_BUFFER_TOO_SMALL FileBuffer is not enough to contain all file data. --*/ { - UINT32 Size; - UINT32 FileSize; - UINT32 Index; - FILE *InFile; + UINT32 Size; + UINT32 Offset; + UINT32 FileSize; + UINT32 Index; + FILE *InFile; + EFI_COMMON_SECTION_HEADER *SectHeader; + EFI_COMMON_SECTION_HEADER2 TempSectHeader; + EFI_TE_IMAGE_HEADER TeHeader; + UINT32 TeOffset; + EFI_GUID_DEFINED_SECTION GuidSectHeader; + EFI_GUID_DEFINED_SECTION2 GuidSectHeader2; + UINT32 HeaderSize; if (InputFileNum < 1) { - Error (NULL, 0, 2000, "Invalid paramter", "must specify at least one input file"); + Error (NULL, 0, 2000, "Invalid parameter", "must specify at least one input file"); return EFI_INVALID_PARAMETER; } if (BufferLength == NULL) { - Error (NULL, 0, 2000, "Invalid paramter", "BufferLength can't be NULL"); + Error (NULL, 0, 2000, "Invalid parameter", "BufferLength can't be NULL"); return EFI_INVALID_PARAMETER; } - Size = 0; + Size = 0; + Offset = 0; + TeOffset = 0; // // Go through our array of file names and copy their contents // to the output buffer. @@ -396,7 +479,7 @@ Returns: // // Open file and read contents // - InFile = fopen (InputFileName[Index], "rb"); + InFile = fopen (LongFilePath (InputFileName[Index]), "rb"); if (InFile == NULL) { Error (NULL, 0, 0001, "Error opening file", InputFileName[Index]); return EFI_ABORTED; @@ -406,11 +489,84 @@ Returns: FileSize = ftell (InFile); fseek (InFile, 0, SEEK_SET); DebugMsg (NULL, 0, 9, "Input files", "the input file name is %s and the size is %u bytes", InputFileName[Index], (unsigned) FileSize); + // + // Adjust section buffer when section alignment is required. + // + if (InputFileAlign != NULL) { + // + // Check this section is Te/Pe section, and Calculate the numbers of Te/Pe section. + // + TeOffset = 0; + // + // The section might be EFI_COMMON_SECTION_HEADER2 + // But only Type needs to be checked + // + if (FileSize >= MAX_SECTION_SIZE) { + HeaderSize = sizeof (EFI_COMMON_SECTION_HEADER2); + } else { + HeaderSize = sizeof (EFI_COMMON_SECTION_HEADER); + } + fread (&TempSectHeader, 1, HeaderSize, InFile); + if (TempSectHeader.Type == EFI_SECTION_TE) { + fread (&TeHeader, 1, sizeof (TeHeader), InFile); + if (TeHeader.Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) { + TeOffset = TeHeader.StrippedSize - sizeof (TeHeader); + } + } else if (TempSectHeader.Type == EFI_SECTION_GUID_DEFINED) { + fseek (InFile, 0, SEEK_SET); + if (FileSize >= MAX_SECTION_SIZE) { + fread (&GuidSectHeader2, 1, sizeof (GuidSectHeader2), InFile); + if ((GuidSectHeader2.Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) == 0) { + HeaderSize = GuidSectHeader2.DataOffset; + } + } else { + fread (&GuidSectHeader, 1, sizeof (GuidSectHeader), InFile); + if ((GuidSectHeader.Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) == 0) { + HeaderSize = GuidSectHeader.DataOffset; + } + } + } + + fseek (InFile, 0, SEEK_SET); + + // + // Revert TeOffset to the converse value relative to Alignment + // This is to assure the original PeImage Header at Alignment. + // + if (TeOffset != 0) { + TeOffset = InputFileAlign [Index] - (TeOffset % InputFileAlign [Index]); + TeOffset = TeOffset % InputFileAlign [Index]; + } + + // + // make sure section data meet its alignment requirement by adding one raw pad section. + // + if ((InputFileAlign [Index] != 0) && (((Size + HeaderSize + TeOffset) % InputFileAlign [Index]) != 0)) { + Offset = (Size + sizeof (EFI_COMMON_SECTION_HEADER) + HeaderSize + TeOffset + InputFileAlign [Index] - 1) & ~(InputFileAlign [Index] - 1); + Offset = Offset - Size - HeaderSize - TeOffset; + + if (FileBuffer != NULL && ((Size + Offset) < *BufferLength)) { + // + // The maximal alignment is 64K, the raw section size must be less than 0xffffff + // + memset (FileBuffer + Size, 0, Offset); + SectHeader = (EFI_COMMON_SECTION_HEADER *) (FileBuffer + Size); + SectHeader->Type = EFI_SECTION_RAW; + SectHeader->Size[0] = (UINT8) (Offset & 0xff); + SectHeader->Size[1] = (UINT8) ((Offset & 0xff00) >> 8); + SectHeader->Size[2] = (UINT8) ((Offset & 0xff0000) >> 16); + } + DebugMsg (NULL, 0, 9, "Pad raw section for section data alignment", "Pad Raw section size is %u", (unsigned) Offset); + + Size = Size + Offset; + } + } + // // Now read the contents of the file into the buffer // Buffer must be enough to contain the file content. // - if (FileSize > 0 && FileBuffer != NULL && (Size + FileSize) <= *BufferLength) { + if ((FileSize > 0) && (FileBuffer != NULL) && ((Size + FileSize) <= *BufferLength)) { if (fread (FileBuffer + Size, (size_t) FileSize, 1, InFile) != 1) { Error (NULL, 0, 0004, "Error reading file", InputFileName[Index]); fclose (InFile); @@ -437,6 +593,7 @@ Returns: EFI_STATUS GenSectionCompressionSection ( CHAR8 **InputFileName, + UINT32 *InputFileAlign, UINT32 InputFileNum, UINT8 SectCompSubType, UINT8 **OutFileBuffer @@ -453,7 +610,9 @@ Routine Description: Arguments: InputFileName - Name of the input file. - + + InputFileAlign - Alignment required by the input file data. + InputFileNum - Number of input files. Should be at least 1. SectCompSubType - Specify the compression algorithm requested. @@ -471,22 +630,26 @@ Returns: UINT32 TotalLength; UINT32 InputLength; UINT32 CompressedLength; + UINT32 HeaderLength; UINT8 *FileBuffer; UINT8 *OutputBuffer; EFI_STATUS Status; EFI_COMPRESSION_SECTION *CompressionSect; + EFI_COMPRESSION_SECTION2 *CompressionSect2; COMPRESS_FUNCTION CompressFunction; InputLength = 0; FileBuffer = NULL; OutputBuffer = NULL; CompressedLength = 0; + TotalLength = 0; // // read all input file contents into a buffer // first get the size of all file contents // Status = GetSectionContents ( InputFileName, + InputFileAlign, InputFileNum, FileBuffer, &InputLength @@ -503,6 +666,7 @@ Returns: // Status = GetSectionContents ( InputFileName, + InputFileAlign, InputFileNum, FileBuffer, &InputLength @@ -516,6 +680,10 @@ Returns: return Status; } + if (FileBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + CompressFunction = NULL; // @@ -524,6 +692,22 @@ Returns: switch (SectCompSubType) { case EFI_NOT_COMPRESSED: CompressedLength = InputLength; + HeaderLength = sizeof (EFI_COMPRESSION_SECTION); + if (CompressedLength + HeaderLength >= MAX_SECTION_SIZE) { + HeaderLength = sizeof (EFI_COMPRESSION_SECTION2); + } + TotalLength = CompressedLength + HeaderLength; + // + // Copy file buffer to the none compressed data. + // + OutputBuffer = malloc (TotalLength); + if (OutputBuffer == NULL) { + free (FileBuffer); + return EFI_OUT_OF_RESOURCES; + } + memcpy (OutputBuffer + HeaderLength, FileBuffer, CompressedLength); + free (FileBuffer); + FileBuffer = OutputBuffer; break; case EFI_STANDARD_COMPRESSION: @@ -531,7 +715,7 @@ Returns: break; default: - Error (NULL, 0, 2000, "Invalid paramter", "unknown compression type"); + Error (NULL, 0, 2000, "Invalid parameter", "unknown compression type"); free (FileBuffer); return EFI_ABORTED; } @@ -540,13 +724,18 @@ Returns: Status = CompressFunction (FileBuffer, InputLength, OutputBuffer, &CompressedLength); if (Status == EFI_BUFFER_TOO_SMALL) { - OutputBuffer = malloc (CompressedLength + sizeof (EFI_COMPRESSION_SECTION)); + HeaderLength = sizeof (EFI_COMPRESSION_SECTION); + if (CompressedLength + HeaderLength >= MAX_SECTION_SIZE) { + HeaderLength = sizeof (EFI_COMPRESSION_SECTION2); + } + TotalLength = CompressedLength + HeaderLength; + OutputBuffer = malloc (TotalLength); if (!OutputBuffer) { free (FileBuffer); return EFI_OUT_OF_RESOURCES; } - Status = CompressFunction (FileBuffer, InputLength, OutputBuffer + sizeof (EFI_COMPRESSION_SECTION), &CompressedLength); + Status = CompressFunction (FileBuffer, InputLength, OutputBuffer + HeaderLength, &CompressedLength); } free (FileBuffer); @@ -559,34 +748,48 @@ Returns: return Status; } + + if (FileBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } } DebugMsg (NULL, 0, 9, "comprss file size", "the original section size is %d bytes and the compressed section size is %u bytes", (unsigned) InputLength, (unsigned) CompressedLength); - TotalLength = CompressedLength + sizeof (EFI_COMPRESSION_SECTION); - if (TotalLength >= MAX_SECTION_SIZE) { - Error (NULL, 0, 2000, "Invalid paramter", "The size of all files exceeds section size limit(%uM).", MAX_SECTION_SIZE>>20); - if (FileBuffer != NULL) { - free (FileBuffer); - } - if (OutputBuffer != NULL) { - free (OutputBuffer); - } - return STATUS_ERROR; - } + + //if (TotalLength >= MAX_SECTION_SIZE) { + // Error (NULL, 0, 2000, "Invalid parameter", "The size of all files exceeds section size limit(%uM).", MAX_SECTION_SIZE>>20); + // if (FileBuffer != NULL) { + // free (FileBuffer); + // } + // if (OutputBuffer != NULL) { + // free (OutputBuffer); + // } + // return STATUS_ERROR; + //} VerboseMsg ("the size of the created section file is %u bytes", (unsigned) TotalLength); // // Add the section header for the compressed data // - CompressionSect = (EFI_COMPRESSION_SECTION *) FileBuffer; - - CompressionSect->CommonHeader.Type = EFI_SECTION_COMPRESSION; - CompressionSect->CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff); - CompressionSect->CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8); - CompressionSect->CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16); - CompressionSect->CompressionType = SectCompSubType; - CompressionSect->UncompressedLength = InputLength; + if (TotalLength >= MAX_SECTION_SIZE) { + CompressionSect2 = (EFI_COMPRESSION_SECTION2 *)FileBuffer; + + memset(CompressionSect2->CommonHeader.Size, 0xff, sizeof(UINT8) * 3); + CompressionSect2->CommonHeader.Type = EFI_SECTION_COMPRESSION; + CompressionSect2->CommonHeader.ExtendedSize = TotalLength; + CompressionSect2->CompressionType = SectCompSubType; + CompressionSect2->UncompressedLength = InputLength; + } else { + CompressionSect = (EFI_COMPRESSION_SECTION *) FileBuffer; + + CompressionSect->CommonHeader.Type = EFI_SECTION_COMPRESSION; + CompressionSect->CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff); + CompressionSect->CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8); + CompressionSect->CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16); + CompressionSect->CompressionType = SectCompSubType; + CompressionSect->UncompressedLength = InputLength; + } // // Set OutFileBuffer @@ -599,6 +802,7 @@ Returns: EFI_STATUS GenSectionGuidDefinedSection ( CHAR8 **InputFileName, + UINT32 *InputFileAlign, UINT32 InputFileNum, EFI_GUID *VendorGuid, UINT16 DataAttribute, @@ -618,6 +822,8 @@ Arguments: InputFileName - Name of the input file. + InputFileAlign - Alignment required by the input file data. + InputFileNum - Number of input files. Should be at least 1. VendorGuid - Specify vendor guid value. @@ -644,17 +850,14 @@ Returns: UINT32 Crc32Checksum; EFI_STATUS Status; CRC32_SECTION_HEADER *Crc32GuidSect; + CRC32_SECTION_HEADER2 *Crc32GuidSect2; EFI_GUID_DEFINED_SECTION *VendorGuidSect; + EFI_GUID_DEFINED_SECTION2 *VendorGuidSect2; InputLength = 0; Offset = 0; FileBuffer = NULL; - - if (CompareGuid (VendorGuid, &mEfiCrc32SectionGuid) == 0) { - Offset = sizeof (CRC32_SECTION_HEADER); - } else { - Offset = sizeof (EFI_GUID_DEFINED_SECTION); - } + TotalLength = 0; // // read all input file contents into a buffer @@ -662,12 +865,26 @@ Returns: // Status = GetSectionContents ( InputFileName, + InputFileAlign, InputFileNum, FileBuffer, &InputLength ); if (Status == EFI_BUFFER_TOO_SMALL) { + if (CompareGuid (VendorGuid, &mZeroGuid) == 0) { + Offset = sizeof (CRC32_SECTION_HEADER); + if (InputLength + Offset >= MAX_SECTION_SIZE) { + Offset = sizeof (CRC32_SECTION_HEADER2); + } + } else { + Offset = sizeof (EFI_GUID_DEFINED_SECTION); + if (InputLength + Offset >= MAX_SECTION_SIZE) { + Offset = sizeof (EFI_GUID_DEFINED_SECTION2); + } + } + TotalLength = InputLength + Offset; + FileBuffer = (UINT8 *) malloc (InputLength + Offset); if (FileBuffer == NULL) { Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); @@ -678,6 +895,7 @@ Returns: // Status = GetSectionContents ( InputFileName, + InputFileAlign, InputFileNum, FileBuffer + Offset, &InputLength @@ -693,55 +911,78 @@ Returns: } if (InputLength == 0) { + if (FileBuffer != NULL) { + free (FileBuffer); + } Error (NULL, 0, 2000, "Invalid parameter", "the size of input file %s can't be zero", InputFileName); return EFI_NOT_FOUND; } + // + // InputLength != 0, but FileBuffer == NULL means out of resources. + // + if (FileBuffer == NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); + return EFI_OUT_OF_RESOURCES; + } + // // Now data is in FileBuffer + Offset // - if (CompareGuid (VendorGuid, &mEfiCrc32SectionGuid) == 0) { + if (CompareGuid (VendorGuid, &mZeroGuid) == 0) { // // Default Guid section is CRC32. // Crc32Checksum = 0; CalculateCrc32 (FileBuffer + Offset, InputLength, &Crc32Checksum); - - TotalLength = InputLength + sizeof (CRC32_SECTION_HEADER); + if (TotalLength >= MAX_SECTION_SIZE) { - Error (NULL, 0, 2000, "Invalid paramter", "The size of all files exceeds section size limit(%uM).", MAX_SECTION_SIZE>>20); - free (FileBuffer); - return STATUS_ERROR; + Crc32GuidSect2 = (CRC32_SECTION_HEADER2 *) FileBuffer; + Crc32GuidSect2->GuidSectionHeader.CommonHeader.Type = EFI_SECTION_GUID_DEFINED; + Crc32GuidSect2->GuidSectionHeader.CommonHeader.Size[0] = (UINT8) 0xff; + Crc32GuidSect2->GuidSectionHeader.CommonHeader.Size[1] = (UINT8) 0xff; + Crc32GuidSect2->GuidSectionHeader.CommonHeader.Size[2] = (UINT8) 0xff; + Crc32GuidSect2->GuidSectionHeader.CommonHeader.ExtendedSize = TotalLength; + memcpy (&(Crc32GuidSect2->GuidSectionHeader.SectionDefinitionGuid), &mEfiCrc32SectionGuid, sizeof (EFI_GUID)); + Crc32GuidSect2->GuidSectionHeader.Attributes = EFI_GUIDED_SECTION_AUTH_STATUS_VALID; + Crc32GuidSect2->GuidSectionHeader.DataOffset = sizeof (CRC32_SECTION_HEADER2); + Crc32GuidSect2->CRC32Checksum = Crc32Checksum; + DebugMsg (NULL, 0, 9, "Guided section", "Data offset is %u", Crc32GuidSect2->GuidSectionHeader.DataOffset); + } else { + Crc32GuidSect = (CRC32_SECTION_HEADER *) FileBuffer; + Crc32GuidSect->GuidSectionHeader.CommonHeader.Type = EFI_SECTION_GUID_DEFINED; + Crc32GuidSect->GuidSectionHeader.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff); + Crc32GuidSect->GuidSectionHeader.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8); + Crc32GuidSect->GuidSectionHeader.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16); + memcpy (&(Crc32GuidSect->GuidSectionHeader.SectionDefinitionGuid), &mEfiCrc32SectionGuid, sizeof (EFI_GUID)); + Crc32GuidSect->GuidSectionHeader.Attributes = EFI_GUIDED_SECTION_AUTH_STATUS_VALID; + Crc32GuidSect->GuidSectionHeader.DataOffset = sizeof (CRC32_SECTION_HEADER); + Crc32GuidSect->CRC32Checksum = Crc32Checksum; + DebugMsg (NULL, 0, 9, "Guided section", "Data offset is %u", Crc32GuidSect->GuidSectionHeader.DataOffset); } - - Crc32GuidSect = (CRC32_SECTION_HEADER *) FileBuffer; - Crc32GuidSect->GuidSectionHeader.CommonHeader.Type = EFI_SECTION_GUID_DEFINED; - Crc32GuidSect->GuidSectionHeader.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff); - Crc32GuidSect->GuidSectionHeader.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8); - Crc32GuidSect->GuidSectionHeader.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16); - memcpy (&(Crc32GuidSect->GuidSectionHeader.SectionDefinitionGuid), &mEfiCrc32SectionGuid, sizeof (EFI_GUID)); - Crc32GuidSect->GuidSectionHeader.Attributes = EFI_GUIDED_SECTION_AUTH_STATUS_VALID; - Crc32GuidSect->GuidSectionHeader.DataOffset = sizeof (CRC32_SECTION_HEADER); - Crc32GuidSect->CRC32Checksum = Crc32Checksum; - DebugMsg (NULL, 0, 9, "Guided section", "Data offset is %u", Crc32GuidSect->GuidSectionHeader.DataOffset); - } else { - TotalLength = InputLength + sizeof (EFI_GUID_DEFINED_SECTION); if (TotalLength >= MAX_SECTION_SIZE) { - Error (NULL, 0, 2000, "Invalid paramter", "The size of all files exceeds section size limit(%uM).", MAX_SECTION_SIZE>>20); - free (FileBuffer); - return STATUS_ERROR; + VendorGuidSect2 = (EFI_GUID_DEFINED_SECTION2 *) FileBuffer; + VendorGuidSect2->CommonHeader.Type = EFI_SECTION_GUID_DEFINED; + VendorGuidSect2->CommonHeader.Size[0] = (UINT8) 0xff; + VendorGuidSect2->CommonHeader.Size[1] = (UINT8) 0xff; + VendorGuidSect2->CommonHeader.Size[2] = (UINT8) 0xff; + VendorGuidSect2->CommonHeader.ExtendedSize = InputLength + sizeof (EFI_GUID_DEFINED_SECTION2); + memcpy (&(VendorGuidSect2->SectionDefinitionGuid), VendorGuid, sizeof (EFI_GUID)); + VendorGuidSect2->Attributes = DataAttribute; + VendorGuidSect2->DataOffset = (UINT16) (sizeof (EFI_GUID_DEFINED_SECTION2) + DataHeaderSize); + DebugMsg (NULL, 0, 9, "Guided section", "Data offset is %u", VendorGuidSect2->DataOffset); + } else { + VendorGuidSect = (EFI_GUID_DEFINED_SECTION *) FileBuffer; + VendorGuidSect->CommonHeader.Type = EFI_SECTION_GUID_DEFINED; + VendorGuidSect->CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff); + VendorGuidSect->CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8); + VendorGuidSect->CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16); + memcpy (&(VendorGuidSect->SectionDefinitionGuid), VendorGuid, sizeof (EFI_GUID)); + VendorGuidSect->Attributes = DataAttribute; + VendorGuidSect->DataOffset = (UINT16) (sizeof (EFI_GUID_DEFINED_SECTION) + DataHeaderSize); + DebugMsg (NULL, 0, 9, "Guided section", "Data offset is %u", VendorGuidSect->DataOffset); } - - VendorGuidSect = (EFI_GUID_DEFINED_SECTION *) FileBuffer; - VendorGuidSect->CommonHeader.Type = EFI_SECTION_GUID_DEFINED; - VendorGuidSect->CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff); - VendorGuidSect->CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8); - VendorGuidSect->CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16); - memcpy (&(VendorGuidSect->SectionDefinitionGuid), VendorGuid, sizeof (EFI_GUID)); - VendorGuidSect->Attributes = DataAttribute; - VendorGuidSect->DataOffset = (UINT16) (sizeof (EFI_GUID_DEFINED_SECTION) + DataHeaderSize); - DebugMsg (NULL, 0, 9, "Guided section", "Data offset is %u", VendorGuidSect->DataOffset); } VerboseMsg ("the size of the created section file is %u bytes", (unsigned) TotalLength); @@ -753,6 +994,103 @@ Returns: return EFI_SUCCESS; } +EFI_STATUS +FfsRebaseImageRead ( + IN VOID *FileHandle, + IN UINTN FileOffset, + IN OUT UINT32 *ReadSize, + OUT VOID *Buffer + ) + /*++ + + Routine Description: + + Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file + + Arguments: + + FileHandle - The handle to the PE/COFF file + + FileOffset - The offset, in bytes, into the file to read + + ReadSize - The number of bytes to read from the file starting at FileOffset + + Buffer - A pointer to the buffer to read the data into. + + Returns: + + EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset + + --*/ +{ + CHAR8 *Destination8; + CHAR8 *Source8; + UINT32 Length; + + Destination8 = Buffer; + Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset); + Length = *ReadSize; + while (Length--) { + *(Destination8++) = *(Source8++); + } + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +GetAlignmentFromFile(char *InFile, UINT32 *Alignment) + /* + InFile is input file for getting alignment + return the alignment + */ +{ + FILE *InFileHandle; + UINT8 *PeFileBuffer; + UINTN PeFileSize; + UINT32 CurSecHdrSize; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + EFI_COMMON_SECTION_HEADER *CommonHeader; + EFI_STATUS Status; + + InFileHandle = NULL; + PeFileBuffer = NULL; + *Alignment = 0; + + memset (&ImageContext, 0, sizeof (ImageContext)); + + InFileHandle = fopen(LongFilePath(InFile), "rb"); + if (InFileHandle == NULL){ + Error (NULL, 0, 0001, "Error opening file", InFile); + return EFI_ABORTED; + } + PeFileSize = _filelength (fileno(InFileHandle)); + PeFileBuffer = (UINT8 *) malloc (PeFileSize); + if (PeFileBuffer == NULL) { + fclose (InFileHandle); + Error(NULL, 0, 4001, "Resource", "memory cannot be allocated of %s", InFileHandle); + return EFI_OUT_OF_RESOURCES; + } + fread (PeFileBuffer, sizeof (UINT8), PeFileSize, InFileHandle); + fclose (InFileHandle); + CommonHeader = (EFI_COMMON_SECTION_HEADER *) PeFileBuffer; + CurSecHdrSize = GetSectionHeaderLength(CommonHeader); + ImageContext.Handle = (VOID *) ((UINTN)PeFileBuffer + CurSecHdrSize); + ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE)FfsRebaseImageRead; + Status = PeCoffLoaderGetImageInfo(&ImageContext); + if (EFI_ERROR (Status)) { + Error (NULL, 0, 3000, "Invalid PeImage", "The input file is %s and return status is %x", InFile, (int) Status); + return Status; + } + *Alignment = ImageContext.SectionAlignment; + // Free the allocated memory resource + if (PeFileBuffer != NULL) { + free (PeFileBuffer); + PeFileBuffer = NULL; + } + return EFI_SUCCESS; +} + int main ( int argc, @@ -778,7 +1116,6 @@ Returns: { UINT32 Index; UINT32 InputFileNum; - FILE *InFile; FILE *OutFile; CHAR8 **InputFileName; CHAR8 *OutputFileName; @@ -797,19 +1134,30 @@ Returns: UINT8 *OutFileBuffer; EFI_STATUS Status; UINT64 LogLevel; - + UINT32 *InputFileAlign; + UINT32 InputFileAlignNum; + EFI_COMMON_SECTION_HEADER *SectionHeader; + CHAR8 *DummyFileName; + FILE *DummyFile; + UINTN DummyFileSize; + UINT8 *DummyFileBuffer; + FILE *InFile; + UINT8 *InFileBuffer; + UINTN InFileSize; + + InputFileAlign = NULL; + InputFileAlignNum = 0; InputFileName = NULL; OutputFileName = NULL; SectionName = NULL; CompressionName = NULL; StringBuffer = ""; - InFile = NULL; OutFile = NULL; VersionNumber = 0; InputFileNum = 0; SectType = EFI_SECTION_ALL; SectCompSubType = 0; - SectGuidAttribute = 0; + SectGuidAttribute = EFI_GUIDED_SECTION_NONE; OutFileBuffer = NULL; InputLength = 0; Status = STATUS_SUCCESS; @@ -817,6 +1165,13 @@ Returns: SectGuidHeaderLength = 0; VersionSect = NULL; UiSect = NULL; + DummyFileSize = 0; + DummyFileName = NULL; + DummyFile = NULL; + DummyFileBuffer = NULL; + InFile = NULL; + InFileSize = 0; + InFileBuffer = NULL; SetUtilityName (UTILITY_NAME); @@ -887,8 +1242,22 @@ Returns: argv += 2; continue; } + if (stricmp (argv[0], "--dummy") == 0) { + DummyFileName = argv[1]; + if (DummyFileName == NULL) { + Error (NULL, 0, 1003, "Invalid option value", "Dummy file can't be NULL"); + goto Finish; + } + argc -= 2; + argv += 2; + continue; + } if ((stricmp (argv[0], "-r") == 0) || (stricmp (argv[0], "--attributes") == 0)) { + if (argv[1] == NULL) { + Error (NULL, 0, 1003, "Invalid option value", "Guid section attributes can't be NULL"); + goto Finish; + } if (stricmp (argv[1], mGUIDedSectionAttribue[EFI_GUIDED_SECTION_PROCESSING_REQUIRED]) == 0) { SectGuidAttribute |= EFI_GUIDED_SECTION_PROCESSING_REQUIRED; } else if (stricmp (argv[1], mGUIDedSectionAttribue[EFI_GUIDED_SECTION_AUTH_STATUS_VALID]) == 0) { @@ -983,6 +1352,44 @@ Returns: continue; } + // + // Section File alignment requirement + // + if (stricmp (argv[0], "--sectionalign") == 0) { + if (InputFileAlignNum == 0) { + InputFileAlign = (UINT32 *) malloc (MAXIMUM_INPUT_FILE_NUM * sizeof (UINT32)); + if (InputFileAlign == NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!"); + goto Finish; + } + memset (InputFileAlign, 1, MAXIMUM_INPUT_FILE_NUM * sizeof (UINT32)); + } else if (InputFileAlignNum % MAXIMUM_INPUT_FILE_NUM == 0) { + InputFileAlign = (UINT32 *) realloc ( + InputFileAlign, + (InputFileNum + MAXIMUM_INPUT_FILE_NUM) * sizeof (UINT32) + ); + + if (InputFileAlign == NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!"); + goto Finish; + } + memset (&(InputFileAlign[InputFileNum]), 1, (MAXIMUM_INPUT_FILE_NUM * sizeof (UINT32))); + } + if (stricmp(argv[1], "0") == 0) { + InputFileAlign[InputFileAlignNum] = 0; + } else { + Status = StringtoAlignment (argv[1], &(InputFileAlign[InputFileAlignNum])); + if (EFI_ERROR (Status)) { + Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]); + goto Finish; + } + } + argc -= 2; + argv += 2; + InputFileAlignNum ++; + continue; + } + // // Get Input file name // @@ -990,9 +1397,8 @@ Returns: InputFileName = (CHAR8 **) malloc (MAXIMUM_INPUT_FILE_NUM * sizeof (CHAR8 *)); if (InputFileName == NULL) { Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); - return 1; + goto Finish; } - memset (InputFileName, 0, (MAXIMUM_INPUT_FILE_NUM * sizeof (CHAR8 *))); } else if (InputFileNum % MAXIMUM_INPUT_FILE_NUM == 0) { // @@ -1005,9 +1411,8 @@ Returns: if (InputFileName == NULL) { Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); - return 1; + goto Finish; } - memset (&(InputFileName[InputFileNum]), 0, (MAXIMUM_INPUT_FILE_NUM * sizeof (CHAR8 *))); } @@ -1016,8 +1421,87 @@ Returns: argv ++; } + if (InputFileAlignNum > 0 && InputFileAlignNum != InputFileNum) { + Error (NULL, 0, 1003, "Invalid option", "section alignment must be set for each section"); + goto Finish; + } + for (Index = 0; Index < InputFileAlignNum; Index++) + { + if (InputFileAlign[Index] == 0) { + Status = GetAlignmentFromFile(InputFileName[Index], &(InputFileAlign[Index])); + if (EFI_ERROR(Status)) { + Error (NULL, 0, 1003, "Fail to get Alignment from %s", InputFileName[InputFileNum]); + goto Finish; + } + } + } + VerboseMsg ("%s tool start.", UTILITY_NAME); + if (DummyFileName != NULL) { + // + // Open file and read contents + // + DummyFile = fopen (LongFilePath (DummyFileName), "rb"); + if (DummyFile == NULL) { + Error (NULL, 0, 0001, "Error opening file", DummyFileName); + goto Finish; + } + + fseek (DummyFile, 0, SEEK_END); + DummyFileSize = ftell (DummyFile); + fseek (DummyFile, 0, SEEK_SET); + DummyFileBuffer = (UINT8 *) malloc (DummyFileSize); + if (DummyFileBuffer == NULL) { + fclose(DummyFile); + Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); + goto Finish; + } + + fread(DummyFileBuffer, 1, DummyFileSize, DummyFile); + fclose(DummyFile); + DebugMsg (NULL, 0, 9, "Dummy files", "the dummy file name is %s and the size is %u bytes", DummyFileName, (unsigned) DummyFileSize); + + if (InputFileName == NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); + goto Finish; + } + InFile = fopen(LongFilePath(InputFileName[0]), "rb"); + if (InFile == NULL) { + Error (NULL, 0, 0001, "Error opening file", InputFileName[0]); + goto Finish; + } + + fseek (InFile, 0, SEEK_END); + InFileSize = ftell (InFile); + fseek (InFile, 0, SEEK_SET); + InFileBuffer = (UINT8 *) malloc (InFileSize); + if (InFileBuffer == NULL) { + fclose(InFile); + Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); + goto Finish; + } + + fread(InFileBuffer, 1, InFileSize, InFile); + fclose(InFile); + DebugMsg (NULL, 0, 9, "Input files", "the input file name is %s and the size is %u bytes", InputFileName[0], (unsigned) InFileSize); + if (InFileSize > DummyFileSize){ + if (stricmp((CHAR8 *)DummyFileBuffer, (CHAR8 *)(InFileBuffer + (InFileSize - DummyFileSize))) == 0){ + SectGuidHeaderLength = InFileSize - DummyFileSize; + } + } + if (SectGuidHeaderLength == 0) { + SectGuidAttribute |= EFI_GUIDED_SECTION_PROCESSING_REQUIRED; + } + if (DummyFileBuffer != NULL) { + free (DummyFileBuffer); + DummyFileBuffer = NULL; + } + if (InFileBuffer != NULL) { + free (InFileBuffer); + } + } + // // Parse all command line parameters to get the corresponding section type. // @@ -1045,19 +1529,12 @@ Returns: VerboseMsg ("Compress method is %s", mCompressionTypeName [SectCompSubType]); } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_GUID_DEFINED]) == 0) { SectType = EFI_SECTION_GUID_DEFINED; - - if (CompareGuid (&VendorGuid, &mZeroGuid) == 0) { - memcpy (&VendorGuid, &mEfiCrc32SectionGuid, sizeof (EFI_GUID)); - } - if (SectGuidAttribute == 0) { - SectGuidAttribute = EFI_GUIDED_SECTION_PROCESSING_REQUIRED; - } if ((SectGuidAttribute & EFI_GUIDED_SECTION_NONE) != 0) { // // NONE attribute, clear attribute value. // - SectGuidAttribute = 0; + SectGuidAttribute = SectGuidAttribute & ~EFI_GUIDED_SECTION_NONE; } VerboseMsg ("Vendor Guid is %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", (unsigned) VendorGuid.Data1, @@ -1092,8 +1569,8 @@ Returns: SectType = EFI_SECTION_SMM_DEPEX; } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_VERSION]) == 0) { SectType = EFI_SECTION_VERSION; - if (VersionNumber < 0 || VersionNumber > 9999) { - Error (NULL, 0, 1003, "Invalid option value", "%d is not in 0~9999", VersionNumber); + if (VersionNumber < 0 || VersionNumber > 65535) { + Error (NULL, 0, 1003, "Invalid option value", "%d is not in 0~65535", VersionNumber); goto Finish; } VerboseMsg ("Version section number is %d", VersionNumber); @@ -1122,7 +1599,9 @@ Returns: // // GuidValue is only required by Guided section. // - if ((SectType != EFI_SECTION_GUID_DEFINED) && (CompareGuid (&VendorGuid, &mZeroGuid) != 0)) { + if ((SectType != EFI_SECTION_GUID_DEFINED) && + (SectionName != NULL) && + (CompareGuid (&VendorGuid, &mZeroGuid) != 0)) { fprintf (stdout, "Warning: the input guid value is not required for this section type %s\n", SectionName); } @@ -1161,8 +1640,13 @@ Returns: // switch (SectType) { case EFI_SECTION_COMPRESSION: + if (InputFileAlign != NULL) { + free (InputFileAlign); + InputFileAlign = NULL; + } Status = GenSectionCompressionSection ( InputFileName, + InputFileAlign, InputFileNum, SectCompSubType, &OutFileBuffer @@ -1170,8 +1654,17 @@ Returns: break; case EFI_SECTION_GUID_DEFINED: + if (InputFileAlign != NULL && (CompareGuid (&VendorGuid, &mZeroGuid) != 0)) { + // + // Only process alignment for the default known CRC32 guided section. + // For the unknown guided section, the alignment is processed when the dummy all section (EFI_SECTION_ALL) is generated. + // + free (InputFileAlign); + InputFileAlign = NULL; + } Status = GenSectionGuidDefinedSection ( InputFileName, + InputFileAlign, InputFileNum, &VendorGuid, SectGuidAttribute, @@ -1232,6 +1725,7 @@ Returns: // Status = GetSectionContents ( InputFileName, + InputFileAlign, InputFileNum, OutFileBuffer, &InputLength @@ -1248,6 +1742,7 @@ Returns: // Status = GetSectionContents ( InputFileName, + InputFileAlign, InputFileNum, OutFileBuffer, &InputLength @@ -1277,13 +1772,17 @@ Returns: // Get output file length // if (SectType != EFI_SECTION_ALL) { - InputLength = SECTION_SIZE (OutFileBuffer); + SectionHeader = (EFI_COMMON_SECTION_HEADER *)OutFileBuffer; + InputLength = *(UINT32 *)SectionHeader->Size & 0x00ffffff; + if (InputLength == 0xffffff) { + InputLength = ((EFI_COMMON_SECTION_HEADER2 *)SectionHeader)->ExtendedSize; + } } // // Write the output file // - OutFile = fopen (OutputFileName, "wb"); + OutFile = fopen (LongFilePath (OutputFileName), "wb"); if (OutFile == NULL) { Error (NULL, 0, 0001, "Error opening file for writing", OutputFileName); goto Finish; @@ -1296,6 +1795,10 @@ Finish: free (InputFileName); } + if (InputFileAlign != NULL) { + free (InputFileAlign); + } + if (OutFileBuffer != NULL) { free (OutFileBuffer); } @@ -1303,7 +1806,11 @@ Finish: if (OutFile != NULL) { fclose (OutFile); } - + + if (DummyFileBuffer != NULL) { + free (DummyFileBuffer); + } + VerboseMsg ("%s tool done with return code is 0x%x.", UTILITY_NAME, GetUtilityStatus ()); return GetUtilityStatus ();