16 #define IMAGE_DOS_SIGNATURE 0x5A4D // MZ signature. 17 #define IMAGE_NT_SIGNATURE 0x00004550 // PE00 signature. 20 #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory 21 #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory 22 #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory 23 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory 24 #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory 25 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table 26 #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory 28 #define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 // Architecture Specific Data 29 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // RVA of GP 30 #define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory 31 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory 32 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers 33 #define IMAGE_DIRECTORY_ENTRY_IAT 12 // Import Address Table 34 #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 // Delay Load Import Descriptors 35 #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 // COM Runtime descriptor 74 #define IMAGE_SIZEOF_SHORT_NAME 8u 103 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16 301 #define IMAGE_FIRST_SECTION( ntheader ) ((IMAGE_SECTION_HEADER) \ 302 ((size_t *)(ntheader) + \ 303 FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + \ 304 ((ntheader))->FileHeader.SizeOfOptionalHeader \ 310 #define IMAGE_REL_BASED_ABSOLUTE 0 311 #define IMAGE_REL_BASED_HIGH 1 312 #define IMAGE_REL_BASED_LOW 2 313 #define IMAGE_REL_BASED_HIGHLOW 3 314 #define IMAGE_REL_BASED_HIGHADJ 4 315 #define IMAGE_REL_BASED_MIPS_JMPADDR 5 317 #define IMAGE_REL_BASED_SECTION 6 318 #define IMAGE_REL_BASED_REL32 7 321 #define IMAGE_REL_BASED_MIPS_JMPADDR16 9 322 #define IMAGE_REL_BASED_IA64_IMM64 9 323 #define IMAGE_REL_BASED_DIR64 10 379 #ifdef INT_COMPILER_MSVC 381 #pragma warning(push) 382 #pragma warning(disable:4214) 399 #ifdef INT_COMPILER_MSVC 409 #define UNW_FLAG_NHANDLER 0x00000000 410 #define UNW_FLAG_EHANDLER 0x00000001 411 #define UNW_FLAG_UHANDLER 0x00000002 412 #define UNW_FLAG_FHANDLER 0x00000003 // unofficial 413 #define UNW_FLAG_CHAININFO 0x00000004 422 #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved. 425 #define IMAGE_SCN_CNT_CODE 0x00000020 // Section contains code. 426 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 // Section contains initialized data. 427 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 // Section contains uninitialized data. 429 #define IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved. 430 #define IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information. 432 #define IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image. 433 #define IMAGE_SCN_LNK_COMDAT 0x00001000 // Section contents comdat. 438 #define IMAGE_SCN_NO_DEFER_SPEC_EXC 0x00004000 441 #define IMAGE_SCN_GPREL 0x00008000 443 #define IMAGE_SCN_MEM_FARDATA 0x00008000 445 #define IMAGE_SCN_MEM_PURGEABLE 0x00020000 446 #define IMAGE_SCN_MEM_16BIT 0x00020000 447 #define IMAGE_SCN_MEM_LOCKED 0x00040000 448 #define IMAGE_SCN_MEM_PRELOAD 0x00080000 450 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 // 451 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 // 452 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 // 453 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 // 454 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 // Default alignment if no others are specified. 455 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 // 456 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 // 457 #define IMAGE_SCN_ALIGN_128BYTES 0x00800000 // 458 #define IMAGE_SCN_ALIGN_256BYTES 0x00900000 // 459 #define IMAGE_SCN_ALIGN_512BYTES 0x00A00000 // 460 #define IMAGE_SCN_ALIGN_1024BYTES 0x00B00000 // 461 #define IMAGE_SCN_ALIGN_2048BYTES 0x00C00000 // 462 #define IMAGE_SCN_ALIGN_4096BYTES 0x00D00000 // 463 #define IMAGE_SCN_ALIGN_8192BYTES 0x00E00000 // 465 #define IMAGE_SCN_ALIGN_MASK 0x00F00000 467 #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 // Section contains extended relocations. 468 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 // Section can be discarded. 469 #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 // Section is not cachable. 470 #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 // Section is not pageable. 471 #define IMAGE_SCN_MEM_SHARED 0x10000000 // Section is shareable. 472 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 // Section is executable. 473 #define IMAGE_SCN_MEM_READ 0x40000000 // Section is readable. 474 #define IMAGE_SCN_MEM_WRITE 0x80000000 // Section is writeable. 479 #define IMAGE_FILE_MACHINE_UNKNOWN 0 480 #define IMAGE_FILE_MACHINE_I386 0x014c // Intel 386. 481 #define IMAGE_FILE_MACHINE_R3000 0x0162 // MIPS little-endian, 0x160 big-endian 482 #define IMAGE_FILE_MACHINE_R4000 0x0166 // MIPS little-endian 483 #define IMAGE_FILE_MACHINE_R10000 0x0168 // MIPS little-endian 484 #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 // MIPS little-endian WCE v2 485 #define IMAGE_FILE_MACHINE_ALPHA 0x0184 // Alpha_AXP 486 #define IMAGE_FILE_MACHINE_SH3 0x01a2 // SH3 little-endian 487 #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 488 #define IMAGE_FILE_MACHINE_SH3E 0x01a4 // SH3E little-endian 489 #define IMAGE_FILE_MACHINE_SH4 0x01a6 // SH4 little-endian 490 #define IMAGE_FILE_MACHINE_SH5 0x01a8 // SH5 491 #define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian 492 #define IMAGE_FILE_MACHINE_THUMB 0x01c2 493 #define IMAGE_FILE_MACHINE_AM33 0x01d3 494 #define IMAGE_FILE_MACHINE_POWERPC 0x01F0 // IBM PowerPC Little-Endian 495 #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 496 #define IMAGE_FILE_MACHINE_IA64 0x0200 // Intel 64 497 #define IMAGE_FILE_MACHINE_MIPS16 0x0266 // MIPS 498 #define IMAGE_FILE_MACHINE_ALPHA64 0x0284 // ALPHA64 499 #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 // MIPS 500 #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 // MIPS 501 #define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64 502 #define IMAGE_FILE_MACHINE_TRICORE 0x0520 // Infineon 503 #define IMAGE_FILE_MACHINE_CEF 0x0CEF 504 #define IMAGE_FILE_MACHINE_EBC 0x0EBC // EFI Byte Code 505 #define IMAGE_FILE_MACHINE_AMD64 0x8664 // AMD64 (K8) 506 #define IMAGE_FILE_MACHINE_M32R 0x9041 // M32R little-endian 507 #define IMAGE_FILE_MACHINE_CEE 0xC0EE 512 #define IMAGE_SUBSYSTEM_UNKNOWN 0 // Unknown subsystem. 513 #define IMAGE_SUBSYSTEM_NATIVE 1 // Image doesn't require a subsystem. 514 #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 // Image runs in the Windows GUI subsystem. 515 #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 // Image runs in the Windows character subsystem. 516 #define IMAGE_SUBSYSTEM_OS2_CUI 5 // image runs in the OS/2 character subsystem. 517 #define IMAGE_SUBSYSTEM_POSIX_CUI 7 // image runs in the Posix character subsystem. 518 #define IMAGE_SUBSYSTEM_NATIVE_WINDOWS 8 // image is a native Win9x driver. 519 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 // Image runs in the Windows CE subsystem. 520 #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 // 521 #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 // 522 #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 // 523 #define IMAGE_SUBSYSTEM_EFI_ROM 13 524 #define IMAGE_SUBSYSTEM_XBOX 14 525 #define IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION 16 535 #define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040 // DLL can move. 536 #define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY 0x0080 // Code Integrity Image 537 #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100 // Image is NX compatible 538 #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200 // Image understands isolation and doesn't want it 541 #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 543 #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 // Do not bind this image. 545 #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 // Driver uses WDM model 547 #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000 550 #define IMAGE_OPTIONAL_HEADER_PE32 0x010b 551 #define IMAGE_OPTIONAL_HEADER_PE64 0x020b 579 #define MAX_PATH 260u 582 #define MAX_FUNC_LENGTH 0xa00 584 #define MAX_FILE_ALIGNMENT 0x10000 585 #define MIN_FILE_ALIGNMENT 0x200 589 #define MAX_NUMBER_SECTIONS 96 759 _In_ DWORD NumberOfSectionHeadersAllocated,
765 #define IntPeGetSectionHeaderByName(Base, Buff, Name, Cr3, Sec) \ 766 IntPeGetSectionHeadersByName((Base), (Buff), (Name), 1, (Cr3), (Sec), NULL)
struct _IMAGE_NT_HEADERS64 * PIMAGE_NT_HEADERS64
INTSTATUS IntPeParseUnwindDataInBuffer(QWORD ImageBase, BYTE *Buffer, DWORD BufferSize, RUNTIME_FUNCTION *RuntimeFunction, DWORD RipOffset, DWORD *ReservedStack, DWORD *BeginAddress, BOOLEAN *InterruptFunction, BOOLEAN *ExceptionFunction, BOOLEAN *HasFramePointer)
Parse the unwind data for the indicated function and return the prologue size.
struct _IMAGE_NT_HEADERS IMAGE_NT_HEADERS32
UINT16 NumberOfRelocations
UINT32 PointerToSymbolTable
INTSTATUS IntPeGetSectionHeaderByRva(QWORD ImageBase, BYTE *ImageBaseBuffer, DWORD GuestRva, IMAGE_SECTION_HEADER *SectionHeader)
Given a relative virtual address, return the section header which describes the section the RVA lies ...
INTSTATUS IntPeFindFunctionStart(QWORD ImageBase, BYTE *ImageBaseBuffer, DWORD Rva, DWORD *BeginAddress)
Find the start address of a function, given a Rva pointing inside of it.
struct _IMAGE_FILE_HEADER IMAGE_FILE_HEADER
INTSTATUS IntPeGetRuntimeFunctionInBuffer(QWORD ImageBase, BYTE *Buffer, DWORD BufferSize, DWORD Rva, RUNTIME_FUNCTION *RuntimeFunction)
Parses the exception directory and gets the runtime function corresponding to the Rva...
struct _INTRO_UNWIND_INFO * PINTRO_UNWIND_INFO
struct _IMAGE_THUNK_DATA64 * PIMAGE_THUNK_DATA64
IMAGE_OPTIONAL_HEADER64 OptionalHeader
UINT32 SizeOfUninitializedData
INTSTATUS IntPeGetDirectory(QWORD ImageBase, BYTE *ImageBaseBuffer, DWORD DirectoryEntry, IMAGE_DATA_DIRECTORY *Directory)
Validate & return the indicated image data directory.
INTSTATUS IntPeFindKernelExport(const char *Name, QWORD *ExportGva)
Find an export inside the NT kernel image.
struct _IMAGE_DATA_DIRECTORY IMAGE_DATA_DIRECTORY
INTSTATUS IntPeFindFunctionByPattern(QWORD ImageBase, WIN_UNEXPORTED_FUNCTION_PATTERN *Pattern, BOOLEAN IgnoreSectionHint, DWORD *Rva)
Find a function using a pattern.
INTSTATUS IntPeFindExportByName(QWORD ImageBase, BYTE *ImageBaseBuffer, CHAR *Name, DWORD *ExportRva)
Find the export name a Rva lies in.
UINT32 NumberOfRvaAndSizes
IMAGE_OPTIONAL_HEADER32 OptionalHeader
INTSTATUS IntPeGetSectionHeaderByIndex(QWORD ImageBase, BYTE *ImageBaseBuffer, DWORD Index, IMAGE_SECTION_HEADER *SectionHeader)
Return the section header located on position Index (0 based).
UINT32 PointerToRelocations
struct _INTRO_PE_INFO INTRO_PE_INFO
DWORD TimeDateStamp
Time/date stamp.
QWORD SectionOffset
Offset of the first section header.
IMAGE_FILE_HEADER FileHeader
struct _IMAGE_BOUND_IMPORT_DESCRIPTOR * PIMAGE_BOUND_IMPORT_DESCRIPTOR
#define _In_bytecount_(expr)
struct _RUNTIME_FUNCTION RUNTIME_FUNCTION
struct _IMAGE_RESOURCE_DATA_ENTRY IMAGE_RESOURCE_DATA_ENTRY
INTSTATUS IntPeFindExportByNameInBuffer(QWORD ImageBase, BYTE *Buffer, DWORD BufferSize, const char *Name, DWORD *ExportRva)
Find the export name a Rva lies in.
struct _IMAGE_RESOURCE_DIRECTORY_ENTRY IMAGE_RESOURCE_DIRECTORY_ENTRY
UINT16 MajorSubsystemVersion
INTSTATUS IntPeFindFunctionByPatternInBuffer(BYTE *Buffer, DWORD BufferSize, WIN_UNEXPORTED_FUNCTION_PATTERN *Pattern, BOOLEAN IgnoreSectionHint, DWORD *Rva)
Find a function using a pattern.
INTSTATUS IntPeFindExportByRvaInBuffer(QWORD ImageBase, BYTE *Buffer, DWORD BufferSize, DWORD Rva)
Check if the indicated Rva belongs to an exported function.
INTSTATUS IntPeGetSectionHeadersByName(QWORD ImageBase, BYTE *ImageBaseBuffer, PCHAR Name, DWORD NumberOfSectionHeadersAllocated, QWORD Cr3, IMAGE_SECTION_HEADER *SectionHeaders, DWORD *NumberOfSectionHeadersFilled)
Return all the section headers matching the indicated Name.
UINT32 SizeOfStackReserve
int INTSTATUS
The status data type.
UINT32 AddressOfEntryPoint
UINT32 AddressOfNameOrdinals
UINT16 NumberOfModuleForwarderRefs
struct _RUNTIME_FUNCTION * PRUNTIME_FUNCTION
struct _IMAGE_IMPORT_DESCRIPTOR IMAGE_IMPORT_DESCRIPTOR
struct _INTRO_UNWIND_INFO INTRO_UNWIND_INFO
UINT16 DllCharacteristics
DWORD SectionAlignment
Sections alignment.
INTSTATUS IntPeParseUnwindData(QWORD ImageBase, BYTE *ImageBaseBuffer, RUNTIME_FUNCTION *RuntimeFunction, DWORD RipOffset, DWORD *ReservedStack, DWORD *BeginAddress, BOOLEAN *InterruptFunction, BOOLEAN *ExceptionFunction, BOOLEAN *HasFramePointer)
Parse the unwind data for the indicated function and return the prologue size.
struct _IMAGE_IMPORT_BY_NAME * PIMAGE_IMPORT_BY_NAME
Describes a pattern for a kernel function that is not exported.
#define IMAGE_SIZEOF_SHORT_NAME
struct _IMAGE_OPTIONAL_HEADER IMAGE_OPTIONAL_HEADER32
struct _IMAGE_DATA_DIRECTORY * PIMAGE_DATA_DIRECTORY
UINT32 AddressOfEntryPoint
UINT32 SizeOfInitializedData
UINT16 MinorOperatingSystemVersion
struct _IMAGE_THUNK_DATA64 IMAGE_THUNK_DATA64
struct _IMAGE_RESOURCE_DIRECTORY IMAGE_RESOURCE_DIRECTORY
UINT16 MajorOperatingSystemVersion
UINT32 SizeOfInitializedData
UINT16 DllCharacteristics
struct _IMAGE_RESOURCE_DIRECTORY * PIMAGE_RESOURCE_DIRECTORY
struct _IMAGE_OPTIONAL_HEADER64 * PIMAGE_OPTIONAL_HEADER64
INTSTATUS IntPeGetExportNameByRva(QWORD ImageBase, BYTE *ImageBaseBuffer, DWORD Rva, DWORD ExportNameSize, CHAR *ExportName)
Find the export name a Rva lies in.
INTSTATUS IntPeFindExportByOrdinal(QWORD ImageBase, BYTE *ImageBaseBuffer, DWORD Ordinal, DWORD *ExportRva)
Find an exported function using its ordinal.
WORD Machine
Machine type.
INTSTATUS IntPeListSectionsHeaders(QWORD ImageBase, BYTE *ImageBuffer, DWORD ImageBufferSize, DWORD *FirstSectionOffset, DWORD *SectionCount)
Will get the offset to the first section header and the number of sections from the given module...
struct _IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER64
struct _IMAGE_EXPORT_DIRECTORY * PIMAGE_EXPORT_DIRECTORY
struct _IMAGE_FILE_HEADER * PIMAGE_FILE_HEADER
IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
INTSTATUS IntPeGetExportNameByRvaInBuffer(QWORD ImageBase, BYTE *Buffer, DWORD BufferSize, DWORD Rva, DWORD ExportNameSize, CHAR *ExportName)
Find the export name a Rva lies in.
QWORD NumberOfSections
Number of sections.
UINT32 NumberOfRvaAndSizes
struct _IMAGE_OPTIONAL_HEADER * PIMAGE_OPTIONAL_HEADER32
#define _In_reads_or_z_(expr)
struct _IMAGE_NT_HEADERS * PIMAGE_NT_HEADERS32
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES
struct _IMAGE_BOUND_IMPORT_DESCRIPTOR IMAGE_BOUND_IMPORT_DESCRIPTOR
struct _IMAGE_DOS_HEADER IMAGE_DOS_HEADER
struct _UNWIND_INFO * PUNWIND_INFO
struct _IMAGE_THUNK_DATA32 IMAGE_THUNK_DATA32
unsigned long long UINT64
Describes a function that is not exported.
UINT16 MinorOperatingSystemVersion
struct _IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS64
DWORD EntryPoint
Entry point (RVA).
INTSTATUS IntPeValidateHeader(QWORD ImageBase, BYTE *ImageBaseBuffer, DWORD ImageBaseBufferSize, INTRO_PE_INFO *PeInfo, QWORD Cr3)
Validates a PE header.
struct _IMAGE_EXPORT_DIRECTORY IMAGE_EXPORT_DIRECTORY
UINT16 MinorSubsystemVersion
struct _IMAGE_RESOURCE_DATA_ENTRY * PIMAGE_RESOURCE_DATA_ENTRY
struct _IMAGE_BASE_RELOCATION IMAGE_BASE_RELOCATION
QWORD ImageBase
Image base.
UINT16 MajorOperatingSystemVersion
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
IMAGE_BASE_RELOCATION * PIMAGE_BASE_RELOCATION
UINT16 MinorSubsystemVersion
struct _IMAGE_IMPORT_BY_NAME IMAGE_IMPORT_BY_NAME
INTSTATUS IntPeFindExportByRva(QWORD ImageBase, BYTE *ImageBaseBuffer, DWORD Rva)
Check if a RVA lies inside an exported function.
IMAGE_FILE_HEADER FileHeader
#define _Out_writes_z_(expr)
UINT32 PointerToLinenumbers
UINT32 AddressOfFunctions
INTSTATUS IntPeFindFunctionStartInBuffer(QWORD ImageBase, BYTE *Buffer, DWORD BufferSize, DWORD Rva, DWORD *BeginAddress)
Find the start address of a function, given a Rva pointing inside of it.
UINT16 NumberOfNamedEntries
DWORD SizeOfImage
Size of the image.
BOOLEAN Image64Bit
True if the image is 64 bit.
struct _UNWIND_INFO UNWIND_INFO
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
struct _IMAGE_RESOURCE_DIRECTORY_ENTRY * PIMAGE_RESOURCE_DIRECTORY_ENTRY
struct _IMAGE_SECTION_HEADER IMAGE_SECTION_HEADER
INTSTATUS IntPeGetRuntimeFunction(QWORD ImageBase, BYTE *ImageBaseBuffer, DWORD Rva, RUNTIME_FUNCTION *RuntimeFunction)
Parses the exception directory and gets the runtime function corresponding to the Rva...
UINT64 SizeOfStackReserve
UINT16 NumberOfLinenumbers
struct _INTRO_PE_INFO * PINTRO_PE_INFO
UINT16 SizeOfOptionalHeader
UINT16 MajorSubsystemVersion
UINT32 SizeOfUninitializedData
struct _IMAGE_THUNK_DATA32 * PIMAGE_THUNK_DATA32