14 BYTE* load_no_sec_pe(BYTE* dllRawData,
size_t r_size, OUT
size_t &v_size,
bool executable)
16 ULONG_PTR desired_base = 0;
22 DWORD protect = (executable) ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
27 memcpy(mappedPE, dllRawData, r_size);
33BYTE*
peconv::load_pe_module(BYTE* dllRawData,
size_t r_size, OUT
size_t &v_size,
bool executable,
bool relocate, ULONG_PTR desired_base)
39 return load_no_sec_pe(dllRawData, r_size, v_size, executable);
48 BYTE *mappedDLL =
pe_raw_to_virtual(dllRawData, r_size, v_size, executable, desired_base);
51 if (relocate && !
relocate_module(mappedDLL, v_size, (ULONGLONG)mappedDLL)) {
53 LOG_ERROR(
"Could not relocate the module.");
58 LOG_ERROR(
"Could not allocate memory at the desired base.");
63BYTE*
peconv::load_pe_module(LPCTSTR filename, OUT
size_t &v_size,
bool executable,
bool relocate, ULONG_PTR desired_base)
66 BYTE *dllRawData =
load_file(filename, r_size);
71 BYTE* mappedPE =
load_pe_module(dllRawData, r_size, v_size, executable, relocate, desired_base);
78 bool validate_and_load_imports(BYTE* loaded_pe,
const size_t v_size,
t_function_resolver* import_resolver)
81 LOG_WARNING(
"PE does not have a valid Import Table.");
94 BYTE* loaded_pe =
load_pe_module(dllRawData, r_size, v_size,
true,
true, desired_base);
100 if (!validate_and_load_imports(loaded_pe, v_size, import_resolver)) {
116 if (!validate_and_load_imports(loaded_pe, v_size, import_resolver)) {
Definitions of the used buffer types. Functions for their allocation and deallocation.
Searching specific functions in PE's Exports Table.
Definitions of basic Imports Resolver classes. They can be used for filling imports when the PE is lo...
Parsing and filling the Import Table.
#define LOG_DEBUG(fmt,...)
#define LOG_ERROR(fmt,...)
#define LOG_WARNING(fmt,...)
bool has_valid_import_table(const PBYTE modulePtr, size_t moduleSize, size_t max_count=0)
bool has_relocations(IN const BYTE *pe_buffer)
ULONGLONG get_image_base(IN const BYTE *pe_buffer)
ALIGNED_BUF alloc_pe_buffer(size_t buffer_size, DWORD protect, void *desired_base=nullptr)
peconv::UNALIGNED_BUF load_file(IN LPCTSTR filename, OUT size_t &r_size)
DWORD get_image_size(IN const BYTE *payload)
bool free_pe_buffer(ALIGNED_BUF buffer, size_t buffer_size=0)
BYTE * load_pe_module(BYTE *payload_raw, size_t r_size, OUT size_t &v_size, bool executable, bool relocate, ULONG_PTR desired_base=0)
BYTE * pe_raw_to_virtual(IN const BYTE *rawPeBuffer, IN size_t rawPeSize, OUT size_t &outputSize, IN OPTIONAL bool executable=true, IN OPTIONAL ULONG_PTR desired_base=0)
size_t get_sections_count(IN const BYTE *buffer, IN const size_t buffer_size)
bool relocate_module(IN BYTE *modulePtr, IN SIZE_T moduleSize, IN ULONGLONG newBase, IN ULONGLONG oldBase=0)
void free_file(IN peconv::UNALIGNED_BUF buffer)
BYTE * get_nt_hdrs(IN const BYTE *pe_buffer, IN OPTIONAL size_t buffer_size=0)
BYTE * load_pe_executable(BYTE *payload_raw, size_t r_size, OUT size_t &v_size, t_function_resolver *import_resolver=nullptr, ULONG_PTR desired_base=0)
bool load_imports(BYTE *modulePtr, t_function_resolver *func_resolver=nullptr)
Loading PE from a file with the help of the custom loader.
Operating on PE file's relocations table.