MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / CheckPE32File

Function CheckPE32File

BaseTools/Source/C/EfiRom/EfiRom.c:806–896  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

804}
805
806static
807int
808CheckPE32File (
809 FILE *Fptr,
810 UINT16 *MachineType,
811 UINT16 *SubSystem
812 )
813/*++
814
815Routine Description:
816
817 Given a file pointer to a supposed PE32 image file, verify that it is indeed a
818 PE32 image file, and then return the machine type in the supplied pointer.
819
820Arguments:
821
822 Fptr File pointer to the already-opened PE32 file
823 MachineType Location to stuff the machine type of the PE32 file. This is needed
824 because the image may be Itanium-based, IA32, or EBC.
825
826Returns:
827
828 0 success
829 non-zero otherwise
830
831--*/
832{
833 EFI_IMAGE_DOS_HEADER DosHeader;
834 EFI_IMAGE_OPTIONAL_HEADER_UNION PeHdr;
835
836 //
837 // Position to the start of the file
838 //
839 fseek (Fptr, 0, SEEK_SET);
840
841 //
842 // Read the DOS header
843 //
844 if (fread (&DosHeader, sizeof (DosHeader), 1, Fptr) != 1) {
845 Error (NULL, 0, 0004, "Failed to read the DOS stub from the input file!", NULL);
846 return STATUS_ERROR;
847 }
848 //
849 // Check the magic number (0x5A4D)
850 //
851 if (DosHeader.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
852 Error (NULL, 0, 2000, "Invalid parameter", "Input file does not appear to be a PE32 image (magic number)!");
853 return STATUS_ERROR;
854 }
855 //
856 // Position into the file and check the PE signature
857 //
858 fseek (Fptr, (long) DosHeader.e_lfanew, SEEK_SET);
859
860 //
861 // Read PE headers
862 //
863 if (fread (&PeHdr, sizeof (PeHdr), 1, Fptr) != 1) {

Callers 1

ProcessEfiFileFunction · 0.85

Calls 4

freadFunction · 0.85
VerboseMsgFunction · 0.85
ErrorFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected