Cleanup PE/COFF related structures

This commit is contained in:
Rafal Kupiec 2024-01-10 16:05:36 +01:00
parent e3376c181f
commit 53cd4e0052
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
3 changed files with 104 additions and 103 deletions

View File

@ -238,116 +238,117 @@ typedef struct _PECOFF_IMAGE_FILE_HEADER
/* DOS PE image header */ /* DOS PE image header */
typedef struct _PECOFF_IMAGE_DOS_HEADER typedef struct _PECOFF_IMAGE_DOS_HEADER
{ {
USHORT e_magic; USHORT Magic;
USHORT e_cblp; USHORT LastPageBytes;
USHORT e_cp; USHORT ImagePages;
USHORT e_crlc; USHORT Relocations;
USHORT e_cparhdr; USHORT HeaderParagraphs;
USHORT e_minalloc; USHORT MinExtraParagraphs;
USHORT e_maxalloc; USHORT MaxExtraParagraphs;
USHORT e_ss; USHORT InitialSS;
USHORT e_sp; USHORT InitialSP;
USHORT e_csum; USHORT Checksum;
USHORT e_ip; USHORT InitialIP;
USHORT e_cs; USHORT InitialCS;
USHORT e_lfarlc; USHORT RelocationTableOffset;
USHORT e_ovno; USHORT OverlayNumber;
USHORT e_res[4]; USHORT Reserved1[4];
USHORT e_oemid; USHORT OemIdentification;
USHORT e_oeminfo; USHORT OemInformation;
USHORT e_res2[10]; USHORT Reserved2[10];
LONG e_lfanew; LONG PeHeaderOffset;
} PECOFF_IMAGE_DOS_HEADER, *PPECOFF_IMAGE_DOS_HEADER; } PECOFF_IMAGE_DOS_HEADER, *PPECOFF_IMAGE_DOS_HEADER;
/* OS/2 PE image header */ /* OS/2 PE image header */
typedef struct _PECOFF_IMAGE_OS2_HEADER typedef struct _PECOFF_IMAGE_OS2_HEADER
{ {
USHORT ne_magic; USHORT Magic;
CHAR ne_ver; CHAR MajorVersion;
CHAR ne_rev; CHAR MinorVersion;
USHORT ne_enttab; USHORT EntryTableOffset;
USHORT ne_cbenttab; USHORT EntryTableLength;
LONG ne_crc; LONG FileLoadCRC;
USHORT ne_flags; UCHAR ProgFlags;
USHORT ne_autodata; UCHAR ApplFlags;
USHORT ne_heap; USHORT AutoDataSegIndex;
USHORT ne_stack; USHORT InitHeapSize;
LONG ne_csip; USHORT InitStackSize;
LONG ne_sssp; LONG EntryPoint;
USHORT ne_cseg; LONG InitStack;
USHORT ne_cmod; USHORT SegCount;
USHORT ne_cbnrestab; USHORT ModRefs;
USHORT ne_segtab; USHORT NoResNamesTabSiz;
USHORT ne_rsrctab; USHORT SegTableOffset;
USHORT ne_restab; USHORT ResTableOffset;
USHORT ne_modtab; USHORT ResidNamTable;
USHORT ne_imptab; USHORT ModRefTable;
LONG ne_nrestab; USHORT ImportNameTable;
USHORT ne_cmovent; LONG NonResTabableOffset;
USHORT ne_align; USHORT MovEntryCount;
USHORT ne_cres; USHORT ImageAlignment;
UCHAR ne_exetyp; USHORT ResTableEntries;
UCHAR ne_flagsothers; UCHAR ImageType;
USHORT ne_pretthunks; UCHAR ImageFlags;
USHORT ne_psegrefbytes; USHORT ReturnThunkOffset;
USHORT ne_swaparea; USHORT ReferenceThunksOffset;
USHORT ne_expver; USHORT SwapArea;
USHORT WindowsVersion;
} PECOFF_IMAGE_OS2_HEADER, *PPECOFF_IMAGE_OS2_HEADER; } PECOFF_IMAGE_OS2_HEADER, *PPECOFF_IMAGE_OS2_HEADER;
/* Windows VXD PE image header */ /* Windows VXD PE image header */
typedef struct _PECOFF_IMAGE_VXD_HEADER typedef struct _PECOFF_IMAGE_VXD_HEADER
{ {
USHORT e32_magic; USHORT Magic;
UCHAR e32_border; UCHAR BytesOrder;
UCHAR e32_worder; UCHAR WordsOrder;
ULONG e32_level; ULONG FormatLevel;
USHORT e32_cpu; USHORT CpuType;
USHORT e32_os; USHORT OSType;
ULONG e32_ver; ULONG ModuleVersion;
ULONG e32_mflags; ULONG ModuleFlags;
ULONG e32_mpages; ULONG ModulePages;
ULONG e32_startobj; ULONG EntryPoint;
ULONG e32_eip; ULONG Eip;
ULONG e32_stackobj; ULONG Stack;
ULONG e32_esp; ULONG Esp;
ULONG e32_pagesize; ULONG PageSize;
ULONG e32_lastpagesize; ULONG LastPageSize;
ULONG e32_fixupsize; ULONG FixupSectionSize;
ULONG e32_fixupsum; ULONG FixupSectionChecksum;
ULONG e32_ldrsize; ULONG LoaderSectionSize;
ULONG e32_ldrsum; ULONG LoaderSectionChecksum;
ULONG e32_objtab; ULONG ObjectTableOffset;
ULONG e32_objcnt; ULONG NumberOfObjects;
ULONG e32_objmap; ULONG ObjectPageMapOffset;
ULONG e32_itermap; ULONG ObjectIterMapOffset;
ULONG e32_rsrctab; ULONG ResTableOffset;
ULONG e32_rsrccnt; ULONG NumberOfResources;
ULONG e32_restab; ULONG ResidentTableOffset;
ULONG e32_enttab; ULONG EntryTableOffset;
ULONG e32_dirtab; ULONG DirectiveTableOffset;
ULONG e32_dircnt; ULONG NumberOfDirectives;
ULONG e32_fpagetab; ULONG FixupPageTableOffset;
ULONG e32_frectab; ULONG FixupRecordTableOffset;
ULONG e32_impmod; ULONG ImportTableOffset;
ULONG e32_impmodcnt; ULONG NumberOfImports;
ULONG e32_impproc; ULONG ImportProcTableOffset;
ULONG e32_pagesum; ULONG PageChecksumTableOffset;
ULONG e32_datapage; ULONG DataPagesOffset;
ULONG e32_preload; ULONG NumberOfPreloadPages;
ULONG e32_nrestab; ULONG NonResidentTableOffset;
ULONG e32_cbnrestab; ULONG NonResidentTableSize;
ULONG e32_nressum; ULONG NonResidentTableChecksum;
ULONG e32_autodata; ULONG AutoDataObject;
ULONG e32_debuginfo; ULONG DebugInfoOffset;
ULONG e32_debuglen; ULONG DebugInfoLength;
ULONG e32_instpreload; ULONG PreLoadSectionPages;
ULONG e32_instdemand; ULONG DemandLoadSectionPages;
ULONG e32_heapsize; ULONG HeapSize;
UCHAR e32_res3[12]; UCHAR Reserved[12];
ULONG e32_winresoff; ULONG WinResOffset;
ULONG e32_winreslen; ULONG WinResLength;
USHORT e32_devid; USHORT DeviceId;
USHORT e32_ddkver; USHORT DDKVersion;
} PECOFF_IMAGE_VXD_HEADER, *PPECOFF_IMAGE_VXD_HEADER; } PECOFF_IMAGE_VXD_HEADER, *PPECOFF_IMAGE_VXD_HEADER;
/* PE/COFF section header */ /* PE/COFF section header */

View File

@ -231,7 +231,7 @@ PeLoadImage(IN PEFI_FILE_HANDLE FileHandle,
/* Extract DOS and PE headers */ /* Extract DOS and PE headers */
ImageData->DosHeader = (PPECOFF_IMAGE_DOS_HEADER)Data; ImageData->DosHeader = (PPECOFF_IMAGE_DOS_HEADER)Data;
ImageData->PeHeader = (PPECOFF_IMAGE_PE_HEADER)((PUINT8)Data + ImageData->DosHeader->e_lfanew); ImageData->PeHeader = (PPECOFF_IMAGE_PE_HEADER)((PUINT8)Data + ImageData->DosHeader->PeHeaderOffset);
/* Validate headers */ /* Validate headers */
Status = PepValidateImageHeaders(ImageData->DosHeader, ImageData->PeHeader, ImageData->FileSize); Status = PepValidateImageHeaders(ImageData->DosHeader, ImageData->PeHeader, ImageData->FileSize);
@ -541,7 +541,7 @@ PepValidateImageHeaders(IN PPECOFF_IMAGE_DOS_HEADER DosHeader,
} }
/* Validate DOS header */ /* Validate DOS header */
if(DosHeader->e_magic != PECOFF_IMAGE_DOS_SIGNATURE) if(DosHeader->Magic != PECOFF_IMAGE_DOS_SIGNATURE)
{ {
XtLdrProtocol->Debug.Print(L"WARNING: Invalid DOS signature found\n"); XtLdrProtocol->Debug.Print(L"WARNING: Invalid DOS signature found\n");
return STATUS_EFI_INCOMPATIBLE_VERSION; return STATUS_EFI_INCOMPATIBLE_VERSION;

View File

@ -223,7 +223,7 @@ BlLoadModule(IN PWCHAR ModuleName)
/* Setup PE/COFF EFI image headers */ /* Setup PE/COFF EFI image headers */
DosHeader = (PPECOFF_IMAGE_DOS_HEADER)ModuleData; DosHeader = (PPECOFF_IMAGE_DOS_HEADER)ModuleData;
PeHeader = (PPECOFF_IMAGE_PE_HEADER)(ModuleData + DosHeader->e_lfanew); PeHeader = (PPECOFF_IMAGE_PE_HEADER)(ModuleData + DosHeader->PeHeaderOffset);
SectionHeader = (PPECOFF_IMAGE_SECTION_HEADER)((PUCHAR)&PeHeader->OptionalHeader + SectionHeader = (PPECOFF_IMAGE_SECTION_HEADER)((PUCHAR)&PeHeader->OptionalHeader +
PeHeader->FileHeader.SizeOfOptionalHeader); PeHeader->FileHeader.SizeOfOptionalHeader);