|
HyperDbg Debugger
|
Bounded in-memory Portable Executable reader. More...
Go to the source code of this file.
Classes | |
| struct | _IMAGE_DOS_HEADER |
| struct | _IMAGE_FILE_HEADER |
| struct | _IMAGE_SECTION_HEADER |
| struct | _PE_IMAGE_READER |
Macros | |
| #define | IMAGE_SIZEOF_SHORT_NAME 8 |
Typedefs | |
| typedef struct _IMAGE_DOS_HEADER | IMAGE_DOS_HEADER |
| typedef struct _IMAGE_DOS_HEADER * | PIMAGE_DOS_HEADER |
| typedef struct _IMAGE_FILE_HEADER | IMAGE_FILE_HEADER |
| typedef struct _IMAGE_FILE_HEADER * | PIMAGE_FILE_HEADER |
| typedef struct _IMAGE_SECTION_HEADER | IMAGE_SECTION_HEADER |
| typedef struct _IMAGE_SECTION_HEADER * | PIMAGE_SECTION_HEADER |
| typedef struct _PE_IMAGE_READER | PE_IMAGE_READER |
| typedef struct _PE_IMAGE_READER * | PPE_IMAGE_READER |
Functions | |
| BOOLEAN | PeImageReaderInitialize (const BYTE *ImageBase, SIZE_T ImageSize, PPE_IMAGE_READER Reader) |
| Parses and validates all PE headers in an in-memory image buffer. | |
| BOOLEAN | PeImageReaderIs32Bit (PPE_IMAGE_READER Reader) |
| Returns whether the PE image is a 32-bit (PE32) image. | |
| BOOLEAN | PeImageReaderGetPointerAtOffset (PPE_IMAGE_READER Reader, SIZE_T Offset, SIZE_T Length, const BYTE **Pointer) |
| Returns a validated pointer into the image at a raw file offset. | |
| BOOLEAN | PeImageReaderGetSectionName (const IMAGE_SECTION_HEADER *SectionHeader, CHAR *NameBuffer, SIZE_T NameBufferSize) |
| Copies the section name from a section header into a null-terminated buffer. | |
| BOOLEAN | PeImageReaderRvaToFileOffset (PPE_IMAGE_READER Reader, DWORD Rva, DWORD Length, PSIZE_T FileOffset) |
| Translates a relative virtual address (RVA) to a raw file offset. | |
Bounded in-memory Portable Executable reader.
| #define IMAGE_SIZEOF_SHORT_NAME 8 |
| typedef struct _IMAGE_DOS_HEADER IMAGE_DOS_HEADER |
| typedef struct _IMAGE_FILE_HEADER IMAGE_FILE_HEADER |
| typedef struct _IMAGE_SECTION_HEADER IMAGE_SECTION_HEADER |
| typedef struct _PE_IMAGE_READER PE_IMAGE_READER |
| typedef struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER |
| typedef struct _IMAGE_FILE_HEADER * PIMAGE_FILE_HEADER |
| typedef struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER |
| typedef struct _PE_IMAGE_READER * PPE_IMAGE_READER |
| BOOLEAN PeImageReaderGetPointerAtOffset | ( | PPE_IMAGE_READER | Reader, |
| SIZE_T | Offset, | ||
| SIZE_T | Length, | ||
| const BYTE ** | Pointer ) |
Returns a validated pointer into the image at a raw file offset.
Verifies that the range [Offset, Offset + Length) lies within the image buffer before setting *Pointer. Use this function when working with raw file offsets rather than virtual addresses.
| Reader | Pointer to an initialized PE_IMAGE_READER; must not be NULL |
| Offset | Raw file offset from the start of the image |
| Length | Number of bytes that must be accessible at the offset |
| Pointer | Output pointer set to ImageBase + Offset on success; must not be NULL |
| BOOLEAN PeImageReaderGetSectionName | ( | const IMAGE_SECTION_HEADER * | SectionHeader, |
| CHAR * | NameBuffer, | ||
| SIZE_T | NameBufferSize ) |
Copies the section name from a section header into a null-terminated buffer.
The PE section name field (IMAGE_SIZEOF_SHORT_NAME bytes) is not required to be null-terminated when it uses all 8 bytes. This function always appends a null terminator and truncates to NameBufferSize - 1 characters if necessary.
| SectionHeader | Pointer to the section header to read; must not be NULL |
| NameBuffer | Destination buffer for the null-terminated name; must not be NULL |
| NameBufferSize | Size of NameBuffer in bytes; must be at least 1 |
| BOOLEAN PeImageReaderInitialize | ( | const BYTE * | ImageBase, |
| SIZE_T | ImageSize, | ||
| PPE_IMAGE_READER | Reader ) |
Parses and validates all PE headers in an in-memory image buffer.
Verifies the DOS signature, the NT signature, the optional header magic, and ensures all headers and the section table fit within the supplied buffer. On success the Reader structure is populated with pointers into ImageBase.
| ImageBase | Pointer to the start of the image buffer; must not be NULL |
| ImageSize | Size of the buffer in bytes |
| Reader | Output structure to populate on success; must not be NULL |
| BOOLEAN PeImageReaderIs32Bit | ( | PPE_IMAGE_READER | Reader | ) |
Returns whether the PE image is a 32-bit (PE32) image.
Examines the Is32Bit flag populated by PeImageReaderInitialize. A return value of FALSE means either the reader is NULL or the image is PE32+.
| Reader | Pointer to an initialized PE_IMAGE_READER |
| BOOLEAN PeImageReaderRvaToFileOffset | ( | PPE_IMAGE_READER | Reader, |
| DWORD | Rva, | ||
| DWORD | Length, | ||
| PSIZE_T | FileOffset ) |
Translates a relative virtual address (RVA) to a raw file offset.
First checks whether the RVA falls within the PE headers (before any section), in which case the file offset equals the RVA. Otherwise iterates the section table to find the section that contains the range [Rva, Rva + Length) and computes the corresponding raw offset via PointerToRawData. Returns FALSE if no section contains the range, if the raw data mapping is out of bounds, or if any arithmetic overflows.
| Reader | Pointer to an initialized PE_IMAGE_READER; must not be NULL |
| Rva | Relative virtual address to translate |
| Length | Number of bytes that must be accessible at the translated offset |
| FileOffset | Output pointer that receives the raw file offset on success; must not be NULL |