EFI_STATUS\r
EFIAPI\r
Tcg2DxeImageRead (\r
- IN VOID *FileHandle,\r
- IN UINTN FileOffset,\r
- IN OUT UINTN *ReadSize,\r
- OUT VOID *Buffer\r
+ IN VOID *FileHandle,\r
+ IN UINTN FileOffset,\r
+ IN OUT UINTN *ReadSize,\r
+ OUT VOID *Buffer\r
)\r
{\r
- UINTN EndPosition;\r
+ UINTN EndPosition;\r
\r
- if (FileHandle == NULL || ReadSize == NULL || Buffer == NULL) {\r
+ if ((FileHandle == NULL) || (ReadSize == NULL) || (Buffer == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
*ReadSize = 0;\r
}\r
\r
- CopyMem (Buffer, (UINT8 *)((UINTN) FileHandle + FileOffset), *ReadSize);\r
+ CopyMem (Buffer, (UINT8 *)((UINTN)FileHandle + FileOffset), *ReadSize);\r
\r
return EFI_SUCCESS;\r
}\r
**/\r
EFI_STATUS\r
MeasurePeImageAndExtend (\r
- IN UINT32 PCRIndex,\r
- IN EFI_PHYSICAL_ADDRESS ImageAddress,\r
- IN UINTN ImageSize,\r
- OUT TPML_DIGEST_VALUES *DigestList\r
+ IN UINT32 PCRIndex,\r
+ IN EFI_PHYSICAL_ADDRESS ImageAddress,\r
+ IN UINTN ImageSize,\r
+ OUT TPML_DIGEST_VALUES *DigestList\r
)\r
{\r
EFI_STATUS Status;\r
// Check PE/COFF image\r
//\r
ZeroMem (&ImageContext, sizeof (ImageContext));\r
- ImageContext.Handle = (VOID *) (UINTN) ImageAddress;\r
+ ImageContext.Handle = (VOID *)(UINTN)ImageAddress;\r
mTcg2DxeImageSize = ImageSize;\r
- ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) Tcg2DxeImageRead;\r
+ ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE)Tcg2DxeImageRead;\r
\r
//\r
// Get information about the image being loaded\r
goto Finish;\r
}\r
\r
- DosHdr = (EFI_IMAGE_DOS_HEADER *) (UINTN) ImageAddress;\r
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageAddress;\r
PeCoffHeaderOffset = 0;\r
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
PeCoffHeaderOffset = DosHdr->e_lfanew;\r
}\r
\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *) (UINTN) ImageAddress + PeCoffHeaderOffset);\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *)(UINTN)ImageAddress + PeCoffHeaderOffset);\r
if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
Status = EFI_UNSUPPORTED;\r
goto Finish;\r
// 3. Calculate the distance from the base of the image header to the image checksum address.\r
// 4. Hash the image header from its base to beginning of the image checksum.\r
//\r
- HashBase = (UINT8 *) (UINTN) ImageAddress;\r
+ HashBase = (UINT8 *)(UINTN)ImageAddress;\r
if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
//\r
// Use PE32 offset\r
//\r
NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
- HashSize = (UINTN) (&Hdr.Pe32->OptionalHeader.CheckSum) - (UINTN) HashBase;\r
+ HashSize = (UINTN)(&Hdr.Pe32->OptionalHeader.CheckSum) - (UINTN)HashBase;\r
} else {\r
//\r
// Use PE32+ offset\r
//\r
NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
- HashSize = (UINTN) (&Hdr.Pe32Plus->OptionalHeader.CheckSum) - (UINTN) HashBase;\r
+ HashSize = (UINTN)(&Hdr.Pe32Plus->OptionalHeader.CheckSum) - (UINTN)HashBase;\r
}\r
\r
Status = HashUpdate (HashHandle, HashBase, HashSize);\r
//\r
// Use PE32 offset.\r
//\r
- HashBase = (UINT8 *) &Hdr.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);\r
- HashSize = Hdr.Pe32->OptionalHeader.SizeOfHeaders - (UINTN) (HashBase - ImageAddress);\r
+ HashBase = (UINT8 *)&Hdr.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);\r
+ HashSize = Hdr.Pe32->OptionalHeader.SizeOfHeaders - (UINTN)(HashBase - ImageAddress);\r
} else {\r
//\r
// Use PE32+ offset.\r
//\r
- HashBase = (UINT8 *) &Hdr.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);\r
- HashSize = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - (UINTN) (HashBase - ImageAddress);\r
+ HashBase = (UINT8 *)&Hdr.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);\r
+ HashSize = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - (UINTN)(HashBase - ImageAddress);\r
}\r
\r
if (HashSize != 0) {\r
- Status = HashUpdate (HashHandle, HashBase, HashSize);\r
+ Status = HashUpdate (HashHandle, HashBase, HashSize);\r
if (EFI_ERROR (Status)) {\r
goto Finish;\r
}\r
//\r
// Use PE32 offset\r
//\r
- HashBase = (UINT8 *) &Hdr.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);\r
- HashSize = (UINTN) (&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (UINTN) HashBase;\r
+ HashBase = (UINT8 *)&Hdr.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);\r
+ HashSize = (UINTN)(&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (UINTN)HashBase;\r
} else {\r
//\r
// Use PE32+ offset\r
//\r
- HashBase = (UINT8 *) &Hdr.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);\r
- HashSize = (UINTN) (&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (UINTN) HashBase;\r
+ HashBase = (UINT8 *)&Hdr.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);\r
+ HashSize = (UINTN)(&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (UINTN)HashBase;\r
}\r
\r
if (HashSize != 0) {\r
- Status = HashUpdate (HashHandle, HashBase, HashSize);\r
+ Status = HashUpdate (HashHandle, HashBase, HashSize);\r
if (EFI_ERROR (Status)) {\r
goto Finish;\r
}\r
//\r
// Use PE32 offset\r
//\r
- HashBase = (UINT8 *) &Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];\r
- HashSize = Hdr.Pe32->OptionalHeader.SizeOfHeaders - (UINTN) (HashBase - ImageAddress);\r
+ HashBase = (UINT8 *)&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];\r
+ HashSize = Hdr.Pe32->OptionalHeader.SizeOfHeaders - (UINTN)(HashBase - ImageAddress);\r
} else {\r
//\r
// Use PE32+ offset\r
//\r
- HashBase = (UINT8 *) &Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];\r
- HashSize = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - (UINTN) (HashBase - ImageAddress);\r
+ HashBase = (UINT8 *)&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];\r
+ HashSize = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - (UINTN)(HashBase - ImageAddress);\r
}\r
\r
if (HashSize != 0) {\r
- Status = HashUpdate (HashHandle, HashBase, HashSize);\r
+ Status = HashUpdate (HashHandle, HashBase, HashSize);\r
if (EFI_ERROR (Status)) {\r
goto Finish;\r
}\r
// header indicates how big the table should be. Do not include any\r
// IMAGE_SECTION_HEADERs in the table whose 'SizeOfRawData' field is zero.\r
//\r
- SectionHeader = (EFI_IMAGE_SECTION_HEADER *) AllocateZeroPool (sizeof (EFI_IMAGE_SECTION_HEADER) * Hdr.Pe32->FileHeader.NumberOfSections);\r
+ SectionHeader = (EFI_IMAGE_SECTION_HEADER *)AllocateZeroPool (sizeof (EFI_IMAGE_SECTION_HEADER) * Hdr.Pe32->FileHeader.NumberOfSections);\r
if (SectionHeader == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
goto Finish;\r
// words, sort the section headers according to the disk-file offset of\r
// the section.\r
//\r
- Section = (EFI_IMAGE_SECTION_HEADER *) (\r
- (UINT8 *) (UINTN) ImageAddress +\r
- PeCoffHeaderOffset +\r
- sizeof(UINT32) +\r
- sizeof(EFI_IMAGE_FILE_HEADER) +\r
- Hdr.Pe32->FileHeader.SizeOfOptionalHeader\r
- );\r
+ Section = (EFI_IMAGE_SECTION_HEADER *)(\r
+ (UINT8 *)(UINTN)ImageAddress +\r
+ PeCoffHeaderOffset +\r
+ sizeof (UINT32) +\r
+ sizeof (EFI_IMAGE_FILE_HEADER) +\r
+ Hdr.Pe32->FileHeader.SizeOfOptionalHeader\r
+ );\r
for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {\r
Pos = Index;\r
while ((Pos > 0) && (Section->PointerToRawData < SectionHeader[Pos - 1].PointerToRawData)) {\r
- CopyMem (&SectionHeader[Pos], &SectionHeader[Pos - 1], sizeof(EFI_IMAGE_SECTION_HEADER));\r
+ CopyMem (&SectionHeader[Pos], &SectionHeader[Pos - 1], sizeof (EFI_IMAGE_SECTION_HEADER));\r
Pos--;\r
}\r
- CopyMem (&SectionHeader[Pos], Section, sizeof(EFI_IMAGE_SECTION_HEADER));\r
+\r
+ CopyMem (&SectionHeader[Pos], Section, sizeof (EFI_IMAGE_SECTION_HEADER));\r
Section += 1;\r
}\r
\r
// 15. Repeat steps 13 and 14 for all the sections in the sorted table.\r
//\r
for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {\r
- Section = (EFI_IMAGE_SECTION_HEADER *) &SectionHeader[Index];\r
+ Section = (EFI_IMAGE_SECTION_HEADER *)&SectionHeader[Index];\r
if (Section->SizeOfRawData == 0) {\r
continue;\r
}\r
- HashBase = (UINT8 *) (UINTN) ImageAddress + Section->PointerToRawData;\r
- HashSize = (UINTN) Section->SizeOfRawData;\r
+\r
+ HashBase = (UINT8 *)(UINTN)ImageAddress + Section->PointerToRawData;\r
+ HashSize = (UINTN)Section->SizeOfRawData;\r
\r
Status = HashUpdate (HashHandle, HashBase, HashSize);\r
if (EFI_ERROR (Status)) {\r
// FileSize - (CertDirectory->Size)\r
//\r
if (ImageSize > SumOfBytesHashed) {\r
- HashBase = (UINT8 *) (UINTN) ImageAddress + SumOfBytesHashed;\r
+ HashBase = (UINT8 *)(UINTN)ImageAddress + SumOfBytesHashed;\r
\r
if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) {\r
CertSize = 0;\r
}\r
\r
if (ImageSize > CertSize + SumOfBytesHashed) {\r
- HashSize = (UINTN) (ImageSize - CertSize - SumOfBytesHashed);\r
+ HashSize = (UINTN)(ImageSize - CertSize - SumOfBytesHashed);\r
\r
Status = HashUpdate (HashHandle, HashBase, HashSize);\r
if (EFI_ERROR (Status)) {\r