10 BYTE hdr_buffer[hdr_buffer_size] = { 0 };
13 PIMAGE_SECTION_HEADER hdr_ptr = NULL;
14 if (peconv::read_remote_pe_header(this->
processHndl, (BYTE*)modBaseAddr, hdr_buffer, hdr_buffer_size)) {
15 hdr_ptr = peconv::get_section_hdr(hdr_buffer, hdr_buffer_size, 0);
18 pe_vsize = peconv::fetch_region_size(this->
processHndl, (PBYTE)modBaseAddr);
31 pe_vsize = peconv::get_remote_image_size(processHndl, (BYTE*)module_base);
33 if (_readRemote(module_base, pe_vsize)) {
37 pe_vsize = calcRemoteImgSize(module_base);
39 std::cout <<
"[!] Image size at: " << std::hex << module_base <<
" undetermined, using calculated size: " << pe_vsize << std::endl;
41 return _readRemote(module_base, pe_vsize);
65 if (!allocBuffer(pe_vsize)) {
70 this->moduleBase = module_base;
71 this->relocBase = module_base;
73 const bool can_force_access = this->isRefl ? true :
false;
74 size_t read_size = peconv::read_remote_area(processHndl, (BYTE*)this->moduleBase, vBuf, pe_vsize, can_force_access);
75 if (read_size != pe_vsize) {
77 std::cout <<
"[!] Failed reading Image at: " << std::hex << this->moduleBase <<
" img size: " << pe_vsize << std::endl;
87 if (!vBuf)
return false;
89 BYTE *new_buf = peconv::alloc_aligned(new_size, PAGE_READWRITE);
94 size_t smaller_size = (vBufSize < new_size) ? vBufSize : new_size;
95 memcpy(new_buf, this->vBuf, smaller_size);
99 this->vBufSize = new_size;
105 if (!vBuf)
return false;
107 PIMAGE_SECTION_HEADER last_sec = peconv::get_last_section(vBuf, vBufSize,
false);
112 if (new_img_size < last_sec->VirtualAddress) {
116 const size_t new_sec_vsize = new_img_size - last_sec->VirtualAddress;
117 const size_t new_sec_rsize = new_sec_vsize;
119 if (last_sec->VirtualAddress + new_sec_vsize > this->vBufSize) {
124 if (!peconv::update_image_size(vBuf,
MASK_TO_DWORD(new_img_size))) {
134 IN std::string dumpFileName,
135 IN OUT peconv::t_pe_dump_mode &dumpMode,
136 IN OPTIONAL
const peconv::ExportsMapper* exportsMap,
137 OUT OPTIONAL peconv::ImpsNotCovered *notCovered
140 if (!vBuf || !isValidPe())
return false;
142 std::cout <<
"Dumping using relocBase: " << std::hex << relocBase <<
"\n";
144 if (exportsMap !=
nullptr) {
145 const bool fixed = peconv::fix_imports(this->vBuf, this->vBufSize, *exportsMap, notCovered);
148 std::cerr <<
"[-] Unable to fix imports!" << std::endl;
152 if (dumpMode == peconv::PE_DUMP_AUTO) {
153 bool is_raw_alignment_valid = peconv::is_valid_sectons_alignment(vBuf, vBufSize,
true);
154 bool is_virtual_alignment_valid = peconv::is_valid_sectons_alignment(vBuf, vBufSize,
false);
156 std::cout <<
"Is raw alignment valid: " << is_raw_alignment_valid << std::endl;
157 std::cout <<
"Is virtual alignment valid: " << is_virtual_alignment_valid << std::endl;
159 if (!is_raw_alignment_valid && is_virtual_alignment_valid) {
161 dumpMode = peconv::PE_DUMP_REALIGN;
162 bool is_dumped = peconv::dump_pe(dumpFileName.c_str(), this->vBuf, this->vBufSize, this->relocBase, dumpMode);
166 dumpMode = peconv::PE_DUMP_AUTO;
170 return peconv::dump_pe(dumpFileName.c_str(), this->vBuf, this->vBufSize, this->relocBase, dumpMode);