10#pragma comment(lib,"psapi.lib")
19 if (my_name.length() == 0 || my_name.length() >
MAX_PATH) {
23 memcpy(this->
szModName, my_name.c_str(), my_name.length());
49 BOOL isRedirDisabled = FALSE;
62 if (isRedirDisabled) {
79 class CollectRelocField :
public peconv::RelocBlockCallback
82 CollectRelocField(
ModuleData &_mod, std::set<DWORD>& _fields)
83 : RelocBlockCallback(_mod.
is64bit()), mod(_mod), fields(_fields)
87 virtual bool processRelocField(ULONG_PTR relocField)
89 DWORD reloc_rva = mod.vaToRva(relocField, (ULONG_PTR)mod.original_module);
90 fields.insert(reloc_rva);
94 std::set<DWORD> &fields;
102 CollectRelocField collector(*
this, fields_rvas);
107 if (fields_rvas.size()) {
126 if (thunk_rvas.size()) {
153 if (original_base == new_base) {
160 std::cerr <<
"[!] Relocating module failed!" << std::endl;
172 std::string module_name = this->
szModName;
175 size_t mod_name_len = module_name.length();
176 if (!is_same && mod_name_len > 0) {
179 memcpy(path_copy, this->
szModName, mod_name_len);
192 BOOL isWow64 = FALSE;
206 const size_t len = path.length();
228 std::cout <<
"[-] Failed to reload: " <<
szModName <<
"\n";
231 std::cout <<
"[+] Reloaded: " <<
szModName <<
"\n";
238 IMAGE_DATA_DIRECTORY* dotNetDir = peconv::get_directory_entry(this->
original_module, IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR);
239 if (dotNetDir ==
nullptr) {
248 std::cout <<
"This is a .NET module" << std::endl;
263 if (expanded.length() == 0) {
276 if (expanded.length() == 0) {
300 this->isHdrReady =
false;
304 this->isHdrReady =
true;
313 this->
imgBuffer = peconv::alloc_pe_buffer(mod_size, PAGE_READWRITE);
348 PIMAGE_SECTION_HEADER section_hdr = peconv::get_section_hdr(
headerBuffer, peconv::MAX_HEADER_SIZE, section_num);
349 if (!section_hdr || (section_hdr->SizeOfRawData == 0)) {
352 return (ULONGLONG)
modBaseAddr + section_hdr->VirtualAddress;
364 PIMAGE_SECTION_HEADER sec_hdr = peconv::get_section_hdr(this->
headerBuffer, peconv::MAX_HEADER_SIZE, section_number);
368 if (ep_va >= sec_hdr->VirtualAddress
369 && ep_va < (sec_hdr->VirtualAddress + sec_hdr->Misc.VirtualSize))
384 MEMORY_BASIC_INFORMATION page_info = { 0 };
386 SIZE_T out = VirtualQueryEx(
processHandle, (LPCVOID) start_va, &page_info,
sizeof(page_info));
387 if (out !=
sizeof(page_info)) {
389 std::cerr <<
"Cannot retrieve remote section info" << std::endl;
394 std::cout << std::hex <<
"Sec: " << section_number <<
" VA: " << start_va <<
" t: " << page_info.Type <<
" p: " << page_info.Protect << std::endl;
407 if (allow_inaccessible) {
418 size_t sec_count = peconv::get_sections_count(this->
headerBuffer, peconv::MAX_HEADER_SIZE);
419 for (
size_t i = 0; i < sec_count ; i++) {
430 if (!isHdrReady)
return 0;
static size_t calcImgSize(HANDLE processHandle, HMODULE modBaseAddr, BYTE *headerBuffer, size_t headerBufferSize, IMAGE_SECTION_HEADER *hdr_ptr=NULL)
bool autoswichIfWow64Mapping()
ModuleData(HANDLE _processHandle, HMODULE _module, bool _isPEBConnected, bool _useCache, const char *_moduleName=nullptr)
bool relocateToBase(ULONGLONG new_base)
bool loadRelocatedFields(std::set< DWORD > &fields_rvas)
bool _loadOriginal(bool disableFSredir)
bool loadImportsList(peconv::ImportsCollection &collection)
bool switchToMappedPath()
bool loadImportThunks(std::set< DWORD > &fields_rvas)
bool isDotNetManagedCode()
bool _loadFullImage(size_t v_size)
bool loadImportsList(peconv::ImportsCollection &collection)
static std::string getModuleName(HANDLE _processHandle, HMODULE _modBaseAddr)
BYTE headerBuffer[peconv::MAX_HEADER_SIZE]
bool hasExecutableSection(bool allow_data, bool allow_inaccessible)
bool isSectionExecutable(const size_t section_number, bool allow_data, bool allow_inaccessible)
static std::string getMappedName(HANDLE _processHandle, LPVOID _modBaseAddr)
ULONGLONG getRemoteSectionVa(const size_t section_num)
bool isSectionEntry(const size_t section_number)
pesieve::ModulesCache cache
std::string expand_path(const std::string &path)
std::string to_lowercase(std::string)
BOOL wow64_disable_fs_redirection(OUT PVOID *OldValue)
BOOL is_process_wow64(IN HANDLE processHandle, OUT BOOL *isProcWow64)
bool is_readable(DWORD mapping_type, DWORD protection)
std::string convert_to_win32_path(const std::string &path)
bool is_normal_inaccessible(DWORD state, DWORD mapping_type, DWORD protection)
BOOL(CALLBACK *_MiniDumpWriteDump)(HANDLE hProcess
bool is_executable(DWORD mapping_type, DWORD protection)
DWORD(__stdcall *_PssCaptureSnapshot)(HANDLE ProcessHandle
bool convert_to_wow64_path(char *szModName)
BOOL wow64_revert_fs_redirection(IN PVOID OldValue)