17 if (sections_count < 2)
return false;
19 bool is_valid_padding =
false;
20 for (
size_t i = 1; i < sections_count; i += 2) {
23 if (!sec1 || !sec2)
continue;
25 if (sec1->SizeOfRawData == 0)
continue;
27 const DWORD sec1_end_offset = sec1->VirtualAddress + sec1->SizeOfRawData;
28 if (sec2->VirtualAddress == sec1_end_offset)
continue;
30 if (sec2->VirtualAddress < sec1_end_offset) {
34 const size_t diff = sec2->VirtualAddress - sec1_end_offset;
35 if (diff < r_align)
continue;
37 BYTE* sec1_end_ptr = (BYTE*)((ULONGLONG)pe_buffer + sec1_end_offset);
43 is_valid_padding =
true;
49 return is_valid_padding;
63 if (sections_count == 0)
return false;
64 for (
size_t i = 0; i < sections_count; i++) {
66 if (!sec || sec->PointerToRawData == 0 || sec->SizeOfRawData == 0) {
69 if (sec->PointerToRawData >= v_align)
continue;
71 size_t diff = v_align - sec->PointerToRawData;
72 BYTE* sec_raw_ptr = (BYTE*)((ULONGLONG)pe_buffer + sec->PointerToRawData);
86 for (
size_t i = 0; i < count; i++) {
90 if (hdr->PointerToRawData != 0)
return false;
93 if (hdr->VirtualAddress != 0)
return false;
102 for (
size_t i = 0; i < count; i++) {
106 if (hdr->VirtualAddress != hdr->PointerToRawData) {
118 std::cout <<
"Valid Import Table found" << std::endl;
124 std::cout <<
"Valid Relocations Table found" << std::endl;
130 std::cout <<
"Header virtual align OK" << std::endl;
135 std::cout <<
"TOTAL v_score: " << std::dec << v_score << std::endl;
154 std::cout <<
"Raw alignment is erased\n";
167 for (
size_t i = 0; i < sections_count; i++) {
179 if (!sec)
return false;
182 size_t sec_rsize = sec->SizeOfRawData;
184 if (sec_rsize >= sec_vsize)
return false;
185 size_t diff = sec_vsize - sec_rsize;
187 BYTE* sec_raw_end_ptr = (BYTE*)((ULONGLONG)pe_buffer + sec->VirtualAddress + sec_rsize);
Parsing and filling the Import Table.
bool has_valid_import_table(const PBYTE modulePtr, size_t moduleSize)
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_pe_mapped(IN const BYTE *pe_buffer, IN size_t pe_size)
bool sec_hdrs_erased(IN const BYTE *pe_buffer, IN size_t pe_size, bool is_raw)
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.