13 if (r_align == 0)
return false;
16 if (sections_count < 2)
return false;
18 bool is_valid_padding =
false;
19 for (
size_t i = 1; i < sections_count; i++) {
22 if (!sec1 || !sec2)
continue;
24 if (sec1->SizeOfRawData == 0)
continue;
26 const DWORD sec1_end_offset = sec1->VirtualAddress + sec1->SizeOfRawData;
27 if (sec2->VirtualAddress == sec1_end_offset)
continue;
29 if (sec2->VirtualAddress < sec1_end_offset) {
30 LOG_ERROR(
"Invalid size of the section: 0x%llx vs 0x%llx", (
unsigned long long)sec2->VirtualAddress, (
unsigned long long)sec1_end_offset);
33 const size_t diff = sec2->VirtualAddress - sec1_end_offset;
34 if (diff < r_align)
continue;
36 BYTE* sec1_end_ptr = (BYTE*)((ULONGLONG)pe_buffer + sec1_end_offset);
38 LOG_ERROR(
"Invalid pointer to the section at offset: 0x%llx", (
unsigned long long)sec1_end_offset);
42 is_valid_padding =
true;
48 return is_valid_padding;
62 if (sections_count == 0)
return false;
63 for (
size_t i = 0; i < sections_count; i++) {
65 if (!sec || sec->PointerToRawData == 0 || sec->SizeOfRawData == 0) {
68 if (sec->PointerToRawData >= v_align)
continue;
70 size_t diff = v_align - sec->PointerToRawData;
71 BYTE* sec_raw_ptr = (BYTE*)((ULONGLONG)pe_buffer + sec->PointerToRawData);
85 for (
size_t i = 0; i < count; i++) {
89 if (hdr->PointerToRawData != 0)
return false;
92 if (hdr->VirtualAddress != 0)
return false;
101 for (
size_t i = 0; i < count; i++) {
105 if (hdr->VirtualAddress != hdr->PointerToRawData) {
116 LOG_INFO(
"Valid Import Table found.");
120 LOG_INFO(
"Valid Relocations Table found.");
124 LOG_INFO(
"Header virtual alignment OK.");
127 LOG_INFO(
"TOTAL v_score: %zu.", v_score);
144 LOG_INFO(
"Raw alignment is erased.");
156 for (
size_t i = 0; i < sections_count; i++) {
168 if (!sec)
return false;
171 size_t sec_rsize = sec->SizeOfRawData;
173 if (sec_rsize >= sec_vsize)
return false;
174 size_t diff = sec_vsize - sec_rsize;
176 BYTE* sec_raw_end_ptr = (BYTE*)((ULONGLONG)pe_buffer + sec->VirtualAddress + sec_rsize);
Parsing and filling the Import Table.
Compile-time configurable logging macros for peconv.
#define LOG_INFO(fmt,...)
#define LOG_ERROR(fmt,...)
bool has_valid_import_table(const PBYTE modulePtr, size_t moduleSize, size_t max_count=0)
bool is_section_expanded(IN const BYTE *pe_buffer, IN size_t pe_size, IN const PIMAGE_SECTION_HEADER sec)
DWORD get_virtual_sec_size(IN const BYTE *pe_hdr, IN const PIMAGE_SECTION_HEADER sec_hdr, IN bool rounded)
bool is_pe_raw(IN const BYTE *pe_buffer, IN size_t pe_size)
bool validate_ptr(IN const void *buffer_bgn, IN size_t buffer_size, IN const void *field_bgn, IN size_t field_size)
PIMAGE_SECTION_HEADER get_section_hdr(IN const BYTE *pe_buffer, IN const size_t buffer_size, IN size_t section_num)
bool is_padding(const BYTE *cave_ptr, size_t cave_size, const BYTE padding_char)
DWORD get_sec_alignment(IN const BYTE *modulePtr, IN bool is_raw)
bool is_pe_raw_eq_virtual(IN const BYTE *pe_buffer, IN size_t pe_size)
size_t get_sections_count(IN const BYTE *buffer, IN const size_t buffer_size)
bool is_pe_expanded(IN const BYTE *pe_buffer, IN size_t pe_size)
DWORD get_hdrs_size(IN const BYTE *pe_buffer)
bool has_valid_relocation_table(IN const PBYTE modulePtr, IN const size_t moduleSize)
bool is_hdr_virtual_align(const BYTE *pe_buffer, size_t pe_size)
bool is_virtual_padding(const BYTE *pe_buffer, size_t pe_size)
bool is_sec_hdrs_erased(IN const BYTE *pe_buffer, IN size_t pe_size, bool is_raw)
bool is_pe_mapped(IN const BYTE *pe_buffer, IN size_t pe_size)
Detecting in which mode is the PE in the supplied buffer (i.e. raw, virtual). Analyzes PE features ty...
Operating on PE file's relocations table.
Miscellaneous utility functions.