9bool peconv::validate_ptr(IN
const void* buffer_bgn, IN
size_t buffer_size, IN
const void* field_bgn, IN
size_t field_size)
11 if (buffer_bgn ==
nullptr || field_bgn ==
nullptr) {
14 BYTE* _start = (BYTE*)buffer_bgn;
15 BYTE* _field_start = (BYTE*)field_bgn;
16 if (_field_start < _start) {
19 size_t start_delta = (ULONG_PTR)_field_start - (ULONG_PTR)_start;
20 size_t area_size = start_delta + field_size;
21 if (area_size > buffer_size) {
24 if (area_size < field_size || area_size < start_delta) {
26 std::cout <<
"Integer Overflow, limit exceeded! start_delta: " << start_delta <<
" field_size: " << field_size <<
" area_size: " << area_size <<
"\n";
41 if (!buf_size)
return NULL;
58 if (!buffer_size)
return NULL;
60 ALIGNED_BUF buf = (
ALIGNED_BUF) VirtualAlloc((LPVOID) desired_base, buffer_size, MEM_COMMIT | MEM_RESERVE, protect);
66 if (buffer ==
nullptr)
return true;
67 if (!VirtualFree(buffer, 0, MEM_RELEASE)) {
69 std::cerr <<
"Releasing failed" << std::endl;
Definitions of the used buffer types. Functions for their allocation and deallocation.
bool free_aligned(ALIGNED_BUF buffer, size_t buffer_size=0)
ALIGNED_BUF alloc_aligned(size_t buffer_size, DWORD protect, ULONGLONG desired_base=NULL)
UNALIGNED_BUF alloc_unaligned(size_t buf_size)
bool validate_ptr(IN const void *buffer_bgn, IN size_t buffer_size, IN const void *field_bgn, IN size_t field_size)
bool free_pe_buffer(ALIGNED_BUF buffer, size_t buffer_size=0)
ALIGNED_BUF alloc_pe_buffer(size_t buffer_size, DWORD protect, ULONGLONG desired_base=NULL)
void free_unaligned(UNALIGNED_BUF section_buffer)