17 std::cerr <<
"[-] Invalid payload: " << std::hex << (
ULONGLONG)
payload << std::endl;
40 std::cout <<
"Coping sections:" << std::endl;
59 std::cerr <<
"[!] Virtual section size is out ouf bounds: " << std::hex <<
sec_size << std::endl;
63 std::cerr <<
"[!] Truncated to maximal size: " << std::hex <<
sec_size <<
", buffer size: " <<
payload_size << std::endl;
68 std::cerr <<
"[-] VirtualAddress of section is out ouf bounds: " << std::hex <<
next_sec->VirtualAddress << std::endl;
74 std::cerr <<
"[-] Raw section size is out ouf bounds: " << std::hex <<
sec_size << std::endl;
84 std::cerr <<
"[-] Section " <<
i <<
": out ouf bounds, skipping... " << std::endl;
91 std::cerr <<
"[-] Section " <<
i <<
": out ouf bounds, skipping... " << std::endl;
109 std::cout <<
"[!] hdrsSize not filled, using calculated size: " << std::hex <<
hdrsSize <<
"\n";
146 std::cerr <<
"[-] Failed relocating the module!" << std::endl;
150 std::cerr <<
"[!] WARNING: The module could not be relocated, so the ImageBase has been changed instead!" << std::endl;
194 std::cerr <<
"[-] Failed relocating the module!" << std::endl;
198 std::cerr <<
"[!] WARNING: The module could not be relocated, so the ImageBase has been changed instead!" << std::endl;
215 sec->SizeOfRawData =
sec->Misc.VirtualSize;
216 sec->PointerToRawData =
sec->VirtualAddress;
bool parse_delayed_desc(BYTE *modulePtr, const size_t moduleSize, const ULONGLONG img_base, LPSTR lib_name, const T_FIELD ordinal_flag, IMAGE_DELAYLOAD_DESCRIPTOR *desc, peconv::t_function_resolver *func_resolver)
bool set_sec_alignment(IN OUT BYTE *pe_buffer, IN bool is_raw, IN DWORD new_alignment)
DWORD get_virtual_sec_size(IN const BYTE *pe_hdr, IN const PIMAGE_SECTION_HEADER sec_hdr, IN bool rounded)
bool update_image_base(IN OUT BYTE *payload, IN ULONGLONG destImageBase)
ULONGLONG get_image_base(IN const BYTE *pe_buffer)
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)
BYTE * pe_virtual_to_raw(IN BYTE *payload, IN size_t in_size, IN ULONGLONG loadBase, OUT size_t &outputSize, IN OPTIONAL bool rebuffer=true)
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)
DWORD get_sec_alignment(IN const BYTE *modulePtr, IN bool is_raw)
bool is64bit(IN const BYTE *pe_buffer)
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)
BYTE * pe_realign_raw_to_virtual(IN const BYTE *payload, IN size_t in_size, IN ULONGLONG loadBase, OUT size_t &outputSize)
BYTE * get_nt_hdrs(IN const BYTE *pe_buffer, IN OPTIONAL size_t buffer_size=0)
Wrappers over various fields in the PE header. Read, write, parse PE headers.
bool sections_virtual_to_raw(BYTE *payload, SIZE_T payload_size, OUT BYTE *destAddress, OUT SIZE_T *raw_size_ptr)
Converting PE from virtual to raw format.
Operating on PE file's relocations table.
Miscellaneous utility functions.