DBG: cache modules (should speed up stepping quite a bit), closed issue #566
This commit is contained in:
parent
4699d415ca
commit
b4c6c09faf
|
@ -154,7 +154,7 @@ void LinearPass::AnalysisWorker(duint Start, duint End, BBlockArray* Blocks)
|
|||
|
||||
for(duint i = Start; i < End;)
|
||||
{
|
||||
if(!disasm.Disassemble(i, TranslateAddress(i), End - i))
|
||||
if(!disasm.Disassemble(i, TranslateAddress(i), int(End - i)))
|
||||
{
|
||||
// Skip instructions that can't be determined
|
||||
i++;
|
||||
|
|
|
@ -30,29 +30,17 @@ static bool _assembleatex(duint addr, const char* instruction, char* error, bool
|
|||
|
||||
static bool _sectionfromaddr(duint addr, char* section)
|
||||
{
|
||||
HMODULE hMod = (HMODULE)ModBaseFromAddr(addr);
|
||||
if(!hMod)
|
||||
return false;
|
||||
wchar_t curModPath[MAX_PATH] = L"";
|
||||
if(!GetModuleFileNameExW(fdProcessInfo->hProcess, hMod, curModPath, MAX_PATH))
|
||||
return false;
|
||||
HANDLE FileHandle;
|
||||
DWORD LoadedSize;
|
||||
HANDLE FileMap;
|
||||
ULONG_PTR FileMapVA;
|
||||
if(StaticFileLoadW(curModPath, UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
|
||||
std::vector<MODSECTIONINFO> sections;
|
||||
if(ModSectionsFromAddr(addr, §ions))
|
||||
{
|
||||
duint rva = addr - (duint)hMod;
|
||||
int sectionNumber = GetPE32SectionNumberFromVA(FileMapVA, GetPE32DataFromMappedFile(FileMapVA, 0, UE_IMAGEBASE) + rva);
|
||||
if(sectionNumber >= 0)
|
||||
for(const auto & cur : sections)
|
||||
{
|
||||
const char* name = (const char*)GetPE32DataFromMappedFile(FileMapVA, sectionNumber, UE_SECTIONNAME);
|
||||
if(section)
|
||||
strcpy_s(section, MAX_SECTION_SIZE, name); //maxi
|
||||
StaticFileUnloadW(curModPath, false, FileHandle, LoadedSize, FileMap, FileMapVA);
|
||||
return true;
|
||||
if(addr >= cur.addr && addr < cur.addr + (cur.size + (0x1000 - 1) & ~(0x1000 - 1)))
|
||||
{
|
||||
strcpy_s(section, MAX_SECTION_SIZE, cur.name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
StaticFileUnloadW(curModPath, false, FileHandle, LoadedSize, FileMap, FileMapVA);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -100,23 +100,29 @@ bool ModLoad(duint Base, duint Size, const char* FullPath)
|
|||
strcpy_s(info.name, file);
|
||||
info.base = Base;
|
||||
info.size = Size;
|
||||
info.fileHandle = nullptr;
|
||||
info.loadedSize = 0;
|
||||
info.fileMap = nullptr;
|
||||
info.fileMapVA = 0;
|
||||
|
||||
// Load module data
|
||||
bool virtualModule = strstr(FullPath, "virtual:\\") == FullPath;
|
||||
|
||||
if(!virtualModule)
|
||||
{
|
||||
HANDLE fileHandle;
|
||||
DWORD loadedSize;
|
||||
HANDLE fileMap;
|
||||
ULONG_PTR fileMapVA;
|
||||
WString wszFullPath = StringUtils::Utf8ToUtf16(FullPath);
|
||||
auto wszFullPath = StringUtils::Utf8ToUtf16(FullPath);
|
||||
|
||||
// Load the physical module from disk
|
||||
if(StaticFileLoadW(wszFullPath.c_str(), UE_ACCESS_READ, false, &fileHandle, &loadedSize, &fileMap, &fileMapVA))
|
||||
if(StaticFileLoadW(wszFullPath.c_str(), UE_ACCESS_READ, false, &info.fileHandle, &info.loadedSize, &info.fileMap, &info.fileMapVA))
|
||||
{
|
||||
GetModuleInfo(info, fileMapVA);
|
||||
StaticFileUnloadW(wszFullPath.c_str(), false, fileHandle, loadedSize, fileMap, fileMapVA);
|
||||
GetModuleInfo(info, info.fileMapVA);
|
||||
}
|
||||
else
|
||||
{
|
||||
info.fileHandle = nullptr;
|
||||
info.loadedSize = 0;
|
||||
info.fileMap = nullptr;
|
||||
info.fileMapVA = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -160,6 +166,11 @@ bool ModUnload(duint Base)
|
|||
if(found == modinfo.end())
|
||||
return false;
|
||||
|
||||
// Unload the mapped file from memory
|
||||
const auto & info = found->second;
|
||||
if(info.fileMapVA)
|
||||
StaticFileUnloadW(StringUtils::Utf8ToUtf16(info.path).c_str(), false, info.fileHandle, info.loadedSize, info.fileMap, info.fileMapVA);
|
||||
|
||||
// Remove it from the list
|
||||
modinfo.erase(found);
|
||||
EXCLUSIVE_RELEASE();
|
||||
|
|
|
@ -30,6 +30,11 @@ struct MODINFO
|
|||
|
||||
std::vector<MODSECTIONINFO> sections;
|
||||
std::vector<MODIMPORTINFO> imports;
|
||||
|
||||
HANDLE fileHandle;
|
||||
DWORD loadedSize;
|
||||
HANDLE fileMap;
|
||||
ULONG_PTR fileMapVA;
|
||||
};
|
||||
|
||||
bool ModLoad(duint Base, duint Size, const char* FullPath);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "label.h"
|
||||
#include "expressionparser.h"
|
||||
#include "function.h"
|
||||
#include "threading.h"
|
||||
|
||||
static bool dosignedcalc = false;
|
||||
|
||||
|
@ -2235,21 +2236,14 @@ bool valtostring(const char* string, duint value, bool silent)
|
|||
*/
|
||||
duint valfileoffsettova(const char* modname, duint offset)
|
||||
{
|
||||
char modpath[MAX_PATH] = "";
|
||||
if(ModPathFromName(modname, modpath, MAX_PATH))
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
const auto modInfo = ModInfoFromAddr(ModBaseFromName(modname));
|
||||
if(modInfo && modInfo->fileMapVA)
|
||||
{
|
||||
HANDLE FileHandle;
|
||||
DWORD LoadedSize;
|
||||
HANDLE FileMap;
|
||||
ULONG_PTR FileMapVA;
|
||||
if(StaticFileLoadW(StringUtils::Utf8ToUtf16(modpath).c_str(), UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
|
||||
{
|
||||
ULONGLONG rva = ConvertFileOffsetToVA(FileMapVA, //FileMapVA
|
||||
FileMapVA + (ULONG_PTR)offset, //Offset inside FileMapVA
|
||||
false); //Return without ImageBase
|
||||
StaticFileUnloadW(StringUtils::Utf8ToUtf16(modpath).c_str(), true, FileHandle, LoadedSize, FileMap, FileMapVA);
|
||||
return offset < LoadedSize ? (duint)rva + ModBaseFromName(modname) : 0;
|
||||
}
|
||||
ULONGLONG rva = ConvertFileOffsetToVA(modInfo->fileMapVA, //FileMapVA
|
||||
modInfo->fileMapVA + (ULONG_PTR)offset, //Offset inside FileMapVA
|
||||
false); //Return without ImageBase
|
||||
return offset < modInfo->loadedSize ? (duint)rva + ModBaseFromName(modname) : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -2261,19 +2255,12 @@ duint valfileoffsettova(const char* modname, duint offset)
|
|||
*/
|
||||
duint valvatofileoffset(duint va)
|
||||
{
|
||||
char modpath[MAX_PATH] = "";
|
||||
if(ModPathFromAddr(va, modpath, MAX_PATH))
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
const auto modInfo = ModInfoFromAddr(va);
|
||||
if(modInfo && modInfo->fileMapVA)
|
||||
{
|
||||
HANDLE FileHandle;
|
||||
DWORD LoadedSize;
|
||||
HANDLE FileMap;
|
||||
ULONG_PTR FileMapVA;
|
||||
if(StaticFileLoadW(StringUtils::Utf8ToUtf16(modpath).c_str(), UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
|
||||
{
|
||||
ULONGLONG offset = ConvertVAtoFileOffsetEx(FileMapVA, LoadedSize, 0, va - ModBaseFromAddr(va), true, false);
|
||||
StaticFileUnloadW(StringUtils::Utf8ToUtf16(modpath).c_str(), true, FileHandle, LoadedSize, FileMap, FileMapVA);
|
||||
return (duint)offset;
|
||||
}
|
||||
ULONGLONG offset = ConvertVAtoFileOffsetEx(modInfo->fileMapVA, modInfo->loadedSize, 0, va - modInfo->base, true, false);
|
||||
return (duint)offset;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue