]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
IntelFrameworkModulePkg: Fix MSFT C4255 warning
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / LzmaCustomDecompressLib / GuidedSectionExtraction.c
index ff91600afd991008b18892359023a80adb199e36..7ef9fbbfc6bf9b3fac7238f6b20a723733c48bff 100644 (file)
@@ -3,8 +3,8 @@
   It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces\r
   and registers them into GUIDed handler table.\r
 \r
-  Copyright (c) 2009, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2009 - 2011, 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
@@ -63,20 +63,37 @@ LzmaGuidedSectionGetInfo (
   ASSERT (ScratchBufferSize != NULL);\r
   ASSERT (SectionAttribute != NULL);\r
 \r
-  if (!CompareGuid (\r
-        &gLzmaCustomDecompressGuid, \r
+  if (IS_SECTION2 (InputSection)) {\r
+    if (!CompareGuid (\r
+        &gLzmaCustomDecompressGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
+\r
+    *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;\r
+\r
+    return LzmaUefiDecompressGetInfo (\r
+             (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
+             SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
+             OutputBufferSize,\r
+             ScratchBufferSize\r
+             );\r
+  } else {\r
+    if (!CompareGuid (\r
+        &gLzmaCustomDecompressGuid,\r
         &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
 \r
-  *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
+    *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
 \r
-  return LzmaUefiDecompressGetInfo (\r
-          (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
-          (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
-          OutputBufferSize,\r
-          ScratchBufferSize\r
-          );\r
+    return LzmaUefiDecompressGetInfo (\r
+             (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+             SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+             OutputBufferSize,\r
+             ScratchBufferSize\r
+             );\r
+  }\r
 }\r
 \r
 /**\r
@@ -124,22 +141,43 @@ LzmaGuidedSectionExtraction (
   ASSERT (OutputBuffer != NULL);\r
   ASSERT (InputSection != NULL);\r
 \r
-  if (!CompareGuid (\r
-        &gLzmaCustomDecompressGuid, \r
+  if (IS_SECTION2 (InputSection)) {\r
+    if (!CompareGuid (\r
+        &gLzmaCustomDecompressGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
+\r
+    //\r
+    // Authentication is set to Zero, which may be ignored.\r
+    //\r
+    *AuthenticationStatus = 0;\r
+\r
+    return LzmaUefiDecompress (\r
+             (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
+             SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
+             *OutputBuffer,\r
+             ScratchBuffer\r
+             );\r
+  } else {\r
+    if (!CompareGuid (\r
+        &gLzmaCustomDecompressGuid,\r
         &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // Authentication is set to Zero, which may be ignored.\r
-  //\r
-  *AuthenticationStatus = 0;\r
-\r
-  return LzmaUefiDecompress (\r
-    (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
-    *OutputBuffer,\r
-    ScratchBuffer\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
+\r
+    //\r
+    // Authentication is set to Zero, which may be ignored.\r
+    //\r
+    *AuthenticationStatus = 0;\r
+\r
+    return LzmaUefiDecompress (\r
+             (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+             SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+             *OutputBuffer,\r
+             ScratchBuffer\r
     );\r
+  }\r
 }\r
 \r
 \r
@@ -152,6 +190,7 @@ LzmaGuidedSectionExtraction (
 EFI_STATUS\r
 EFIAPI\r
 LzmaDecompressLibConstructor (\r
+  VOID\r
   )\r
 {\r
   return ExtractGuidedSectionRegisterHandlers (\r