15 BYTE*
load_no_sec_pe(BYTE* dllRawData,
size_t r_size, OUT
size_t &v_size,
bool executable)
17 ULONG_PTR desired_base = 0;
23 DWORD protect = (executable) ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
28 memcpy(mappedPE, dllRawData, r_size);
15 BYTE*
load_no_sec_pe(BYTE* dllRawData,
size_t r_size, OUT
size_t &v_size,
bool executable) {
…}
34BYTE*
peconv::load_pe_module(BYTE* dllRawData,
size_t r_size, OUT
size_t &v_size,
bool executable,
bool relocate, ULONG_PTR desired_base)
49 BYTE *mappedDLL =
pe_raw_to_virtual(dllRawData, r_size, v_size, executable, desired_base);
52 if (relocate && !
relocate_module(mappedDLL, v_size, (ULONGLONG)mappedDLL)) {
54 std::cerr <<
"[!] Could not relocate the module!\n";
59 std::cerr <<
"[!] Could not allocate memory at the desired base!\n";
34BYTE*
peconv::load_pe_module(BYTE* dllRawData,
size_t r_size, OUT
size_t &v_size,
bool executable,
bool relocate, ULONG_PTR desired_base) {
…}
64BYTE*
peconv::load_pe_module(LPCTSTR filename, OUT
size_t &v_size,
bool executable,
bool relocate, ULONG_PTR desired_base)
67 BYTE *dllRawData =
load_file(filename, r_size);
70 std::cerr <<
"Cannot load the file: " << filename << std::endl;
74 BYTE* mappedPE =
load_pe_module(dllRawData, r_size, v_size, executable, relocate, desired_base);
64BYTE*
peconv::load_pe_module(LPCTSTR filename, OUT
size_t &v_size,
bool executable,
bool relocate, ULONG_PTR desired_base) {
…}
81 BYTE* loaded_pe =
load_pe_module(dllRawData, r_size, v_size,
true,
true, desired_base);
83 std::cerr <<
"[-] Loading failed!\n";
87 printf(
"Loaded at: %p\n", loaded_pe);
91 printf(
"[-] Loading imports failed!");
97 printf(
"[-] PE doesn't have a valid Import Table!\n");
106 _tprintf(TEXT(
"Module: %s\n"), my_path);
110 printf(
"[-] Loading failed!\n");
114 printf(
"Loaded at: %p\n", loaded_pe);
117 printf(
"[-] Loading imports failed!");
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.
bool has_relocations(IN const BYTE *pe_buffer)
bool has_valid_import_table(const PBYTE modulePtr, size_t moduleSize)
peconv::UNALIGNED_BUF load_file(IN LPCTSTR filename, OUT size_t &r_size)
BYTE * load_no_sec_pe(BYTE *dllRawData, size_t r_size, OUT size_t &v_size, bool executable)
ULONGLONG get_image_base(IN const BYTE *pe_buffer)
ALIGNED_BUF alloc_pe_buffer(size_t buffer_size, DWORD protect, void *desired_base=nullptr)
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.