18#define PE_COFF_IMAGE_ALIGN_SIZE 4
47 ASSERT (Pe32Data !=
NULL);
48 ASSERT (EntryPoint !=
NULL);
51 if (DosHdr->
e_magic == EFI_IMAGE_DOS_SIGNATURE) {
67 if (Hdr.Te->
Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
70 }
else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
71 *EntryPoint = (VOID *)((
UINTN)Pe32Data + (
UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
99 ASSERT (Pe32Data !=
NULL);
102 if (DosHdr->
e_magic == EFI_IMAGE_DOS_SIGNATURE) {
114 if (Hdr.Te->
Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
116 }
else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
117 return Hdr.Pe32->FileHeader.Machine;
153 VOID *CodeViewEntryPointer;
155 UINT32 NumberOfRvaAndSizes;
158 ASSERT (Pe32Data !=
NULL);
161 DirectoryEntry =
NULL;
163 NumberOfRvaAndSizes = 0;
166 if (DosHdr->
e_magic == EFI_IMAGE_DOS_SIGNATURE) {
178 if (Hdr.Te->
Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
179 if (Hdr.Te->
DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {
180 DirectoryEntry = &Hdr.Te->
DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];
183 Hdr.Te->
DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +
186 }
else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
192 switch (Hdr.Pe32->FileHeader.Machine) {
193 case IMAGE_FILE_MACHINE_I386:
199 case IMAGE_FILE_MACHINE_X64:
200 case IMAGE_FILE_MACHINE_IA64:
210 Magic = Hdr.Pe32->OptionalHeader.
Magic;
217 NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;
218 DirectoryEntry = (
EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
224 NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
225 DirectoryEntry = (
EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
229 if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
230 DirectoryEntry =
NULL;
237 if ((DebugEntry ==
NULL) || (DirectoryEntry ==
NULL)) {
246 if (DebugEntry->SizeOfData > 0) {
247 CodeViewEntryPointer = (VOID *)((
UINTN)DebugEntry->
RVA + ((
UINTN)Pe32Data) + (
UINTN)TEImageAdjust);
248 switch (*(UINT32 *)CodeViewEntryPointer) {
287 ASSERT (Pe32Data !=
NULL);
290 if (DosHdr->
e_magic == EFI_IMAGE_DOS_SIGNATURE) {
302 if (Hdr.Te->
Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
304 }
else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
305 SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders;
310 return (UINT32)SizeOfHeaders;
342 Pe32Data = Address & ~(PE_COFF_IMAGE_ALIGN_SIZE - 1);
343 while (Pe32Data != 0) {
345 if (DosHdr->
e_magic == EFI_IMAGE_DOS_SIGNATURE) {
353 if (((
UINTN)Hdr.Pe32 > Pe32Data) && ((
UINTN)Hdr.Pe32 < Address)) {
354 if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
363 if ((Hdr.Te->
Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) &&
364 ((Hdr.Te->
Machine == IMAGE_FILE_MACHINE_I386) || (Hdr.Te->
Machine == IMAGE_FILE_MACHINE_IA64) ||
365 (Hdr.Te->
Machine == IMAGE_FILE_MACHINE_EBC) || (Hdr.Te->
Machine == IMAGE_FILE_MACHINE_X64) ||
366 (Hdr.Te->
Machine == IMAGE_FILE_MACHINE_ARM64) || (Hdr.Te->
Machine == IMAGE_FILE_MACHINE_ARMTHUMB_MIXED))
376 Pe32Data -= PE_COFF_IMAGE_ALIGN_SIZE;
#define RETURN_UNSUPPORTED
#define DEBUG_CODE_BEGIN()
UINT32 EFIAPI PeCoffGetSizeOfHeaders(IN VOID *Pe32Data)
RETURN_STATUS EFIAPI PeCoffLoaderGetEntryPoint(IN VOID *Pe32Data, OUT VOID **EntryPoint)
UINT16 EFIAPI PeCoffLoaderGetMachineType(IN VOID *Pe32Data)
VOID *EFIAPI PeCoffLoaderGetPdbPointer(IN VOID *Pe32Data)
UINTN EFIAPI PeCoffSearchImageBase(IN UINTN Address)
#define CODEVIEW_SIGNATURE_NB10
#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW
The Visual C++ debug information.
#define CODEVIEW_SIGNATURE_RSDS
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define CODEVIEW_SIGNATURE_MTOC
UINT32 RVA
The address of the debug data when loaded, relative to the image base.
UINT32 e_lfanew
File address of new exe header.
UINT16 e_magic
Magic number.
UINT32 AddressOfEntryPoint
Offset to entry point – from original optional header.
UINT16 Signature
The signature for TE format = "VZ".
UINT32 BaseOfCode
From original image – required for ITP debug.
EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]
Only base relocation and debug directory.
UINT16 StrippedSize
Number of bytes we removed from the header.
UINT16 Machine
From the original file header.