/* Returns the machine type from the PE/COFF image specified by Pe32Data. If Pe32Data is NULL, then ASSERT(). */
UINT16 EFIAPI PeCoffLoaderGetMachineType(IN VOID *Pe32Data)
/* Returns the machine type from the PE/COFF image specified by Pe32Data. If Pe32Data is NULL, then ASSERT(). */
UINT16 EFIAPI PeCoffLoaderGetMachineType(IN VOID *Pe32Data)
{
  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;
  EFI_IMAGE_DOS_HEADER                 *DosHdr;
  ASSERT (Pe32Data != NULL);
  DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
  if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));
  } else {
    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
  }
  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
    return Hdr.Te->Machine;
  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
    return Hdr.Pe32->FileHeader.Machine;
  }
  return 0x0000;
}