/* Extract the System Firmware image from an authenticated image. */
BOOLEAN EFIAPI ExtractSystemFirmwareImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **SystemFirmwareImage, OUT UINTN *SystemFirmwareImageSize)
/* Extract the System Firmware image from an authenticated image. */
BOOLEAN EFIAPI ExtractSystemFirmwareImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **SystemFirmwareImage, OUT UINTN *SystemFirmwareImageSize)
{
  BOOLEAN  Result;
  UINT32   FileHeaderSize;
  *SystemFirmwareImage     = NULL;
  *SystemFirmwareImageSize = 0;
  Result = GetFfsByName (AuthenticatedImage, AuthenticatedImageSize, &mEdkiiSystemFirmwareFileGuid, EFI_FV_FILETYPE_RAW, SystemFirmwareImage, SystemFirmwareImageSize);
  if (!Result) {
    *SystemFirmwareImage     = AuthenticatedImage;
    *SystemFirmwareImageSize = AuthenticatedImageSize;
    return TRUE;
  }
  if (IS_FFS_FILE2 (*SystemFirmwareImage)) {
    FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
  } else {
    FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
  }
  *SystemFirmwareImage     = (UINT8 *)*SystemFirmwareImage + FileHeaderSize;
  *SystemFirmwareImageSize = *SystemFirmwareImageSize - FileHeaderSize;
  return Result;
}