1
0
Fork 0

Merge pull request #3300 from torusrxxx/patch000000fe

Save module party
This commit is contained in:
Duncan Ogilvie 2024-01-05 22:25:17 +01:00 committed by GitHub
commit ec9a2a2af1
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 94 additions and 14 deletions

View File

@ -71,6 +71,7 @@ void DbSave(DbLoadSaveType saveType, const char* dbfile, bool disablecompression
EncodeMapCacheSave(root);
TraceRecord.saveToDb(root);
BpCacheSave(root);
ModCacheSave(root);
WatchCacheSave(root);
//save notes
@ -283,6 +284,7 @@ void DbLoad(DbLoadSaveType loadType, const char* dbfile)
EncodeMapCacheLoad(root);
TraceRecord.loadFromDb(root);
BpCacheLoad(root, migrateBreakpoints);
ModCacheLoad(root);
WatchCacheLoad(root);
// Load notes
@ -340,6 +342,7 @@ void DbClear(bool terminating)
EncodeMapClear();
TraceRecord.clear();
BpClear();
ModCacheClear();
WatchClear();
GuiSetDebuggeeNotes("");

View File

@ -701,6 +701,59 @@ static bool GetUnsafeModuleInfoImpl(MODINFO & Info, ULONG_PTR FileMapVA, void(*f
return true;
}
// Determine user/system module based on path, the default method
static MODULEPARTY GetDefaultParty(const MODINFO & Info)
{
if(Info.isVirtual)
return mod_user;
// Determine whether the module is located in system
wchar_t szWindowsDir[MAX_PATH];
GetWindowsDirectoryW(szWindowsDir, _countof(szWindowsDir));
String Utf8Sysdir = StringUtils::Utf16ToUtf8(szWindowsDir);
Utf8Sysdir.append("\\");
if(_memicmp(Utf8Sysdir.c_str(), Info.path, Utf8Sysdir.size()) == 0)
{
return mod_system;
}
else
{
return mod_user;
}
}
// These are used to store party in DB
struct MODULEPARTYINFO : AddrInfo
{
MODULEPARTY party;
};
struct ModuleSerializer : AddrInfoSerializer<MODULEPARTYINFO>
{
bool Save(const MODULEPARTYINFO & value) override
{
setHex("hash", value.modhash);
setInt("party", value.party);
return true;
}
bool Load(MODULEPARTYINFO & value) override
{
value.addr = 0;
value.manual = true;
return getHex("hash", value.modhash) && getInt("party", value.party);
}
};
struct ModulePartyInfo : AddrInfoHashMap<LockModuleHashes, MODULEPARTYINFO, ModuleSerializer>
{
const char* jsonKey() const override
{
return "modules";
}
};
static ModulePartyInfo modulePartyInfo;
void GetModuleInfo(MODINFO & Info, ULONG_PTR FileMapVA)
{
// Get the PE headers
@ -840,23 +893,15 @@ bool ModLoad(duint Base, duint Size, const char* FullPath, bool loadSymbols)
info.fileMap = nullptr;
info.fileMapVA = 0;
// Determine whether the module is located in system
wchar_t szWindowsDir[MAX_PATH];
GetWindowsDirectoryW(szWindowsDir, _countof(szWindowsDir));
String Utf8Sysdir = StringUtils::Utf16ToUtf8(szWindowsDir);
Utf8Sysdir.append("\\");
if(_memicmp(Utf8Sysdir.c_str(), FullPath, Utf8Sysdir.size()) == 0)
{
info.party = mod_system;
}
else
{
info.party = mod_user;
}
// Load module data
info.isVirtual = strstr(FullPath, "virtual:\\") == FullPath;
MODULEPARTYINFO modParty;
if(modulePartyInfo.Get(info.hash, modParty))
info.party = modParty.party;
else
info.party = GetDefaultParty(info);
if(!info.isVirtual)
{
auto wszFullPath = StringUtils::Utf8ToUtf16(FullPath);
@ -1188,6 +1233,34 @@ void ModSetParty(duint Address, MODULEPARTY Party)
return;
module->party = Party;
// DB
MODULEPARTYINFO DBEntry;
if(Party != GetDefaultParty(module[0])) // Save non-default party settings
{
DBEntry.addr = 0;
DBEntry.modhash = module->hash;
DBEntry.party = Party;
DBEntry.manual = true;
modulePartyInfo.Add(DBEntry);
}
else
modulePartyInfo.Delete(module->hash); // Don't need to save the default party
}
void ModCacheSave(JSON root)
{
modulePartyInfo.CacheSave(root);
}
void ModCacheLoad(JSON root)
{
modulePartyInfo.CacheLoad(root);
}
void ModCacheClear()
{
modulePartyInfo.Clear();
}
bool ModRelocationsFromAddr(duint Address, std::vector<MODRELOCATIONINFO> & Relocations)

View File

@ -2,6 +2,7 @@
#define _MODULE_H
#include "_global.h"
#include "jansson/jansson_x64dbg.h" // addrinfo.h and serializablemap.h use functions defined here so can't be included
#include <functional>
#include "symbolsourcebase.h"
@ -173,6 +174,9 @@ void ModEnum(const std::function<void(const MODINFO &)> & cbEnum);
MODULEPARTY ModGetParty(duint Address);
void ModSetParty(duint Address, MODULEPARTY Party);
void ModCacheSave(JSON root);
void ModCacheLoad(JSON root);
void ModCacheClear();
bool ModRelocationsFromAddr(duint Address, std::vector<MODRELOCATIONINFO> & Relocations);
bool ModRelocationAtAddr(duint Address, MODRELOCATIONINFO* Relocation);
bool ModRelocationsInRange(duint Address, duint Size, std::vector<MODRELOCATIONINFO> & Relocations);