1
0
Fork 0

Update ModHashFromName to always lowercase first

This commit is contained in:
Duncan Ogilvie 2024-10-07 22:35:09 +02:00
parent 6e976ab67b
commit dc120752c8
4 changed files with 23 additions and 14 deletions

View File

@ -259,11 +259,7 @@ void LoopCacheLoad(JSON Root)
// Module name
const char* mod = json_string_value(json_object_get(value, "module"));
if(mod && strlen(mod) < MAX_MODULE_SIZE)
loopInfo.modhash = ModHashFromName(mod);
else
loopInfo.modhash = 0;
loopInfo.modhash = ModHashFromName(mod);
// All other variables
loopInfo.start = (duint)json_hex_value(json_object_get(value, "start"));

View File

@ -886,7 +886,7 @@ bool ModLoad(duint Base, duint Size, const char* FullPath, bool loadSymbols)
}
// Calculate module hash from full file name
info.hash = ModHashFromName(file);
info.hash = ModHashFromName(file, false);
// Copy the extension into the module struct
{
@ -1100,14 +1100,27 @@ duint ModContentHashFromAddr(duint Address)
return 0;
}
duint ModHashFromName(const char* Module)
duint ModHashFromName(const char* Module, bool tolower)
{
// return MODINFO.hash (based on the name)
ASSERT_NONNULL(Module);
auto len = int(strlen(Module));
auto len = strlen(Module);
if(!len)
return 0;
auto hash = murmurhash(Module, len);
duint hash = 0;
if(tolower)
{
auto & moduleLower = TLSData::get()->moduleHashLower;
moduleLower.clear();
for(size_t i = 0; i < len; i++)
moduleLower.push_back(StringUtils::ToLower(Module[i]));
hash = murmurhash(moduleLower.c_str(), moduleLower.size());
}
else
{
hash = murmurhash(Module, len);
}
//update the hash cache
SHARED_ACQUIRE(LockModuleHashes);

View File

@ -156,7 +156,7 @@ duint ModBaseFromAddr(duint Address);
// Get a unique hash for an address in the module.
// IMPORTANT: If you want to get a hash for the module base, pass the base
duint ModHashFromAddr(duint Address);
duint ModHashFromName(const char* Module);
duint ModHashFromName(const char* Module, bool tolower = true);
duint ModContentHashFromAddr(duint Address);
duint ModBaseFromName(const char* Module);
duint ModSizeFromAddr(duint Address);

View File

@ -36,16 +36,16 @@ void MurmurHash3_x64_128(const void* key, int len, uint32_t seed, void* out);
#ifdef _WIN64
static inline
unsigned long long murmurhash(const void* data, int len)
unsigned long long murmurhash(const void* data, size_t len)
{
unsigned long long hash[2];
MurmurHash3_x64_128(data, len, 0x1337, hash);
MurmurHash3_x64_128(data, (int)len, 0x1337, hash);
#else //x86
static inline
unsigned long murmurhash(const void* data, int len)
unsigned long murmurhash(const void* data, size_t len)
{
unsigned int hash[1];
MurmurHash3_x86_32(data, len, 0x1337, hash);
MurmurHash3_x86_32(data, (int)len, 0x1337, hash);
#endif //_WIN64
return hash[0];
}