libPeConv
A library to load, manipulate, dump PE files.
Loading...
Searching...
No Matches
load_config_util.cpp
Go to the documentation of this file.
3
4BYTE* peconv::get_load_config_ptr(BYTE* buffer, size_t buf_size)
5{
6 if (!buffer || !buf_size) return nullptr;
7 IMAGE_DATA_DIRECTORY* dir = peconv::get_directory_entry(buffer, IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG);
8 if (!dir) {
9 return 0;
10 }
11 DWORD entry_rva = dir->VirtualAddress;
12 DWORD entry_size = dir->Size;
13 if (!peconv::validate_ptr(buffer, buf_size, buffer + entry_rva, entry_size)) {
14 return 0;
15 }
16 IMAGE_LOAD_CONFIG_DIRECTORY32* ldc = reinterpret_cast<IMAGE_LOAD_CONFIG_DIRECTORY32*>((ULONG_PTR)buffer + entry_rva);
17 return reinterpret_cast<BYTE*>(ldc);
18}
19
20peconv::t_load_config_ver peconv::get_load_config_version(BYTE* buffer, size_t buf_size, BYTE* ld_config_ptr)
21{
22 if (!buffer || !buf_size || !ld_config_ptr) {
24 }
25 bool is64b = peconv::is64bit(buffer);
26
27 if (!peconv::validate_ptr(buffer, buf_size, ld_config_ptr, sizeof(peconv::IMAGE_LOAD_CONFIG_DIR32_W7))) {
29 }
30
32 const size_t curr_size = smallest->Size;
33
34 if (is64b) {
35 switch (curr_size) {
42 default:
44 }
45 }
46 else {
47 switch (curr_size) {
54 default:
56 }
57 }
59}
Fetching Load Config Directory and recognizing its version.
struct peconv::_IMAGE_LOAD_CONFIG_DIR64_W10 IMAGE_LOAD_CONFIG_DIR64_W10
BYTE * get_load_config_ptr(BYTE *buffer, size_t buf_size)
t_load_config_ver get_load_config_version(BYTE *buffer, size_t buf_size, BYTE *ld_config_ptr)
struct peconv::_IMAGE_LOAD_CONFIG_DIR32_W8 IMAGE_LOAD_CONFIG_DIR32_W8
struct peconv::_IMAGE_LOAD_CONFIG_DIR32_W10 IMAGE_LOAD_CONFIG_DIR32_W10
bool validate_ptr(IN const void *buffer_bgn, IN size_t buffer_size, IN const void *field_bgn, IN size_t field_size)
struct peconv::_IMAGE_LOAD_CONFIG_DIR64_W8 IMAGE_LOAD_CONFIG_DIR64_W8
struct peconv::_IMAGE_LOAD_CONFIG_DIR64_W7 IMAGE_LOAD_CONFIG_DIR64_W7
bool is64bit(IN const BYTE *pe_buffer)
IMAGE_DATA_DIRECTORY * get_directory_entry(IN const BYTE *pe_buffer, IN DWORD dir_id, IN bool allow_empty=false)
struct peconv::_IMAGE_LOAD_CONFIG_DIR32_W7 IMAGE_LOAD_CONFIG_DIR32_W7
@ LOAD_CONFIG_UNK_VER
@ LOAD_CONFIG_W10_VER
Wrappers over various fields in the PE header. Read, write, parse PE headers.