DBG: use section vector for the memory map, now updating the memory map is close to instant
This commit is contained in:
parent
888cde708a
commit
031dadc319
|
@ -97,7 +97,7 @@ bool modload(uint base, uint size, const char* fullpath)
|
|||
while(name[len]!='.' and len)
|
||||
len--;
|
||||
MODINFO info;
|
||||
memset(&info, 0, sizeof(MODINFO));
|
||||
info.sections.clear();
|
||||
info.hash=modhashfromname(name);
|
||||
if(len)
|
||||
{
|
||||
|
@ -107,6 +107,30 @@ bool modload(uint base, uint size, const char* fullpath)
|
|||
info.base=base;
|
||||
info.size=size;
|
||||
strcpy(info.name, name);
|
||||
|
||||
//process module sections
|
||||
HANDLE FileHandle;
|
||||
DWORD LoadedSize;
|
||||
HANDLE FileMap;
|
||||
ULONG_PTR FileMapVA;
|
||||
if(StaticFileLoad((char*)fullpath, UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
|
||||
{
|
||||
int SectionCount=(int)GetPE32DataFromMappedFile(FileMapVA, 0, UE_SECTIONNUMBER);
|
||||
if(SectionCount > 0)
|
||||
{
|
||||
for(int i=0; i<SectionCount; i++)
|
||||
{
|
||||
MODSECTIONINFO curSection;
|
||||
curSection.addr=GetPE32DataFromMappedFile(FileMapVA, i, UE_SECTIONVIRTUALOFFSET)+base;
|
||||
curSection.size=GetPE32DataFromMappedFile(FileMapVA, i, UE_SECTIONVIRTUALSIZE);
|
||||
strcpy_s(curSection.name, (const char*)GetPE32DataFromMappedFile(FileMapVA, i, UE_SECTIONNAME));
|
||||
info.sections.push_back(curSection);
|
||||
}
|
||||
}
|
||||
StaticFileUnload((char*)fullpath, false, FileHandle, LoadedSize, FileMap, FileMapVA);
|
||||
}
|
||||
|
||||
//add module to list
|
||||
modinfo.insert(std::make_pair(Range(base, base+size-1), info));
|
||||
symupdatemodulelist();
|
||||
return true;
|
||||
|
@ -191,6 +215,15 @@ uint modsizefromaddr(uint addr)
|
|||
return found->second.size;
|
||||
}
|
||||
|
||||
bool modsectionsfromaddr(uint addr, std::vector<MODSECTIONINFO>* sections)
|
||||
{
|
||||
const ModulesInfo::iterator found=modinfo.find(Range(addr, addr));
|
||||
if(found==modinfo.end()) //not found
|
||||
return false;
|
||||
*sections=found->second.sections;
|
||||
return true;
|
||||
}
|
||||
|
||||
///api functions
|
||||
bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum)
|
||||
{
|
||||
|
|
|
@ -53,6 +53,13 @@ struct DepthModuleRangeCompare
|
|||
};
|
||||
|
||||
//structures
|
||||
struct MODSECTIONINFO
|
||||
{
|
||||
uint addr; //va
|
||||
uint size; //virtual size
|
||||
char name[10];
|
||||
};
|
||||
|
||||
struct MODINFO
|
||||
{
|
||||
uint base; //module base
|
||||
|
@ -60,6 +67,7 @@ struct MODINFO
|
|||
uint hash; //full module name hash
|
||||
char name[MAX_MODULE_SIZE]; //module name (without extension)
|
||||
char extension[MAX_MODULE_SIZE]; //file extension
|
||||
std::vector<MODSECTIONINFO> sections;
|
||||
};
|
||||
typedef std::map<Range, MODINFO, RangeCompare> ModulesInfo;
|
||||
|
||||
|
@ -125,6 +133,7 @@ uint modhashfromva(uint va);
|
|||
uint modhashfromname(const char* mod);
|
||||
uint modbasefromname(const char* modname);
|
||||
uint modsizefromaddr(uint addr);
|
||||
bool modsectionsfromaddr(uint addr, std::vector<MODSECTIONINFO>* sections);
|
||||
|
||||
bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum);
|
||||
|
||||
|
|
|
@ -180,11 +180,10 @@ bool dbgcmddel(const char* name)
|
|||
|
||||
void DebugUpdateGui(uint disasm_addr, bool stack)
|
||||
{
|
||||
if(!memisvalidreadptr(fdProcessInfo->hProcess, disasm_addr))
|
||||
return;
|
||||
memupdatemap(fdProcessInfo->hProcess); //update memory map
|
||||
uint cip=GetContextData(UE_CIP);
|
||||
GuiDisasmAt(disasm_addr, cip);
|
||||
if(memisvalidreadptr(fdProcessInfo->hProcess, disasm_addr))
|
||||
GuiDisasmAt(disasm_addr, cip);
|
||||
if(stack)
|
||||
{
|
||||
uint csp=GetContextData(UE_CSP);
|
||||
|
@ -1610,6 +1609,8 @@ CMDRESULT cbDebugDisasm(int argc, char* argv[])
|
|||
if(argget(*argv, arg1, 0, true))
|
||||
if(!valfromstring(arg1, &addr))
|
||||
addr=GetContextData(UE_CIP);
|
||||
if(!memisvalidreadptr(fdProcessInfo->hProcess, addr))
|
||||
return STATUS_CONTINUE;
|
||||
DebugUpdateGui(addr, false);
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ MemoryMap memoryPages;
|
|||
|
||||
void memupdatemap(HANDLE hProcess)
|
||||
{
|
||||
DWORD ticks=GetTickCount();
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
SIZE_T numBytes;
|
||||
uint MyAddress=0, newAddress=0;
|
||||
|
@ -41,12 +40,8 @@ void memupdatemap(HANDLE hProcess)
|
|||
}
|
||||
while(numBytes);
|
||||
|
||||
dprintf("memupdatemap[1], %ums\n", GetTickCount()-ticks);
|
||||
ticks=GetTickCount();
|
||||
|
||||
//list all pages when needed
|
||||
int pagecount;
|
||||
|
||||
//filter executable sections
|
||||
if(bListAllPages)
|
||||
{
|
||||
pagecount=(int)pageVector.size();
|
||||
|
@ -70,9 +65,6 @@ void memupdatemap(HANDLE hProcess)
|
|||
}
|
||||
}
|
||||
|
||||
dprintf("memupdatemap[2], %ums\n", GetTickCount()-ticks);
|
||||
ticks=GetTickCount();
|
||||
|
||||
//process file sections
|
||||
pagecount=(int)pageVector.size();
|
||||
char curMod[MAX_MODULE_SIZE]="";
|
||||
|
@ -82,28 +74,26 @@ void memupdatemap(HANDLE hProcess)
|
|||
{
|
||||
if(!scmp(curMod, pageVector.at(i).info)) //mod is not the current mod
|
||||
{
|
||||
strcpy(curMod, pageVector.at(i).info);
|
||||
HMODULE hMod=(HMODULE)modbasefromname(curMod);
|
||||
if(!hMod)
|
||||
uint base=modbasefromname(pageVector.at(i).info);
|
||||
if(!base)
|
||||
continue;
|
||||
char curModPath[MAX_PATH]="";
|
||||
if(!GetModuleFileNameExA(hProcess, hMod, curModPath, MAX_PATH))
|
||||
std::vector<MODSECTIONINFO> sections;
|
||||
if(!modsectionsfromaddr(base, §ions))
|
||||
continue;
|
||||
int SectionNumber=(int)GetPE32Data(curModPath, 0, UE_SECTIONNUMBER);
|
||||
int SectionNumber=(int)sections.size();
|
||||
MEMPAGE newPage;
|
||||
pageVector.erase(pageVector.begin()+i); //remove the SizeOfImage page
|
||||
for(int j=SectionNumber-1; j>-1; j--)
|
||||
{
|
||||
memset(&newPage, 0, sizeof(MEMPAGE));
|
||||
VirtualQueryEx(hProcess, (LPCVOID)((uint)hMod+GetPE32Data(curModPath, j, UE_SECTIONVIRTUALOFFSET)), &newPage.mbi, sizeof(MEMORY_BASIC_INFORMATION));
|
||||
uint SectionSize=GetPE32Data(curModPath, j, UE_SECTIONVIRTUALSIZE);
|
||||
|
||||
VirtualQueryEx(hProcess, (LPCVOID)sections.at(j).addr, &newPage.mbi, sizeof(MEMORY_BASIC_INFORMATION));
|
||||
uint SectionSize=sections.at(j).size;
|
||||
if(SectionSize%PAGE_SIZE) //unaligned page size
|
||||
SectionSize+=PAGE_SIZE-(SectionSize%PAGE_SIZE); //fix this
|
||||
if(SectionSize)
|
||||
newPage.mbi.RegionSize=SectionSize;
|
||||
const char* SectionName=(const char*)GetPE32Data(curModPath, j, UE_SECTIONNAME);
|
||||
if(!SectionName)
|
||||
SectionName="";
|
||||
const char* SectionName=§ions.at(j).name[0];
|
||||
int len=(int)strlen(SectionName);
|
||||
int escape_count=0;
|
||||
for(int k=0; k<len; k++)
|
||||
|
@ -149,16 +139,14 @@ void memupdatemap(HANDLE hProcess)
|
|||
pageVector.insert(pageVector.begin()+i, newPage);
|
||||
}
|
||||
memset(&newPage, 0, sizeof(MEMPAGE));
|
||||
VirtualQueryEx(hProcess, (LPCVOID)hMod, &newPage.mbi, sizeof(MEMORY_BASIC_INFORMATION));
|
||||
VirtualQueryEx(hProcess, (LPCVOID)base, &newPage.mbi, sizeof(MEMORY_BASIC_INFORMATION));
|
||||
strcpy(newPage.info, curMod);
|
||||
pageVector.insert(pageVector.begin()+i, newPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dprintf("memupdatemap[3], %ums\n", GetTickCount()-ticks);
|
||||
ticks=GetTickCount();
|
||||
|
||||
//convert to memoryPages map
|
||||
pagecount=(int)pageVector.size();
|
||||
memoryPages.clear();
|
||||
for(int i=0; i<pagecount; i++)
|
||||
|
@ -168,8 +156,6 @@ void memupdatemap(HANDLE hProcess)
|
|||
uint size=curPage.mbi.RegionSize;
|
||||
memoryPages.insert(std::make_pair(std::make_pair(start, start+size-1), curPage));
|
||||
}
|
||||
|
||||
dprintf("memupdatemap[4], %ums\n", GetTickCount()-ticks);
|
||||
}
|
||||
|
||||
uint memfindbaseaddr(uint addr, uint* size)
|
||||
|
|
Loading…
Reference in New Issue