mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Initial working implementation of the Signature Cache Map.
Init speeds have been reduced from 1.7 seconds (average) to 0.3 seconds (average)
This commit is contained in:
parent
5513057f53
commit
783b3dbb5a
@ -46,17 +46,6 @@ CMemory CModule::FindPatternSIMD(const uint8_t* szPattern, const char* szMask, c
|
|||||||
if (!m_ExecutableCode.IsSectionValid())
|
if (!m_ExecutableCode.IsSectionValid())
|
||||||
return CMemory();
|
return CMemory();
|
||||||
|
|
||||||
|
|
||||||
//if (g_SigCache.m_bInitialized) // Get from cache instead.
|
|
||||||
//{
|
|
||||||
// auto p = g_SigCache.m_Map.find(szPattern);
|
|
||||||
// if (p != g_SigCache.m_Map.end())
|
|
||||||
// {
|
|
||||||
// return CMemory(p->second);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t nBase = static_cast<uint64_t>(m_ExecutableCode.m_pSectionBase);
|
uint64_t nBase = static_cast<uint64_t>(m_ExecutableCode.m_pSectionBase);
|
||||||
uint64_t nSize = static_cast<uint64_t>(m_ExecutableCode.m_nSectionSize);
|
uint64_t nSize = static_cast<uint64_t>(m_ExecutableCode.m_nSectionSize);
|
||||||
|
|
||||||
@ -106,7 +95,6 @@ CMemory CModule::FindPatternSIMD(const uint8_t* szPattern, const char* szMask, c
|
|||||||
{
|
{
|
||||||
if (nOccurrenceCount == nOccurrence)
|
if (nOccurrenceCount == nOccurrence)
|
||||||
{
|
{
|
||||||
g_SigCache.AddEntry(reinterpret_cast<const char*>(szPattern), nMaskLen, reinterpret_cast<uint64_t>(pData - nBase));
|
|
||||||
return static_cast<CMemory>(const_cast<uint8_t*>(pData));
|
return static_cast<CMemory>(const_cast<uint8_t*>(pData));
|
||||||
}
|
}
|
||||||
nOccurrenceCount++;
|
nOccurrenceCount++;
|
||||||
@ -119,7 +107,6 @@ CMemory CModule::FindPatternSIMD(const uint8_t* szPattern, const char* szMask, c
|
|||||||
}
|
}
|
||||||
if (nOccurrenceCount == nOccurrence)
|
if (nOccurrenceCount == nOccurrence)
|
||||||
{
|
{
|
||||||
g_SigCache.AddEntry(reinterpret_cast<const char*>(szPattern), nMaskLen, reinterpret_cast<uint64_t>(pData - nBase));
|
|
||||||
return static_cast<CMemory>((&*(const_cast<uint8_t*>(pData))));
|
return static_cast<CMemory>((&*(const_cast<uint8_t*>(pData))));
|
||||||
}
|
}
|
||||||
nOccurrenceCount++;
|
nOccurrenceCount++;
|
||||||
@ -137,8 +124,22 @@ CMemory CModule::FindPatternSIMD(const uint8_t* szPattern, const char* szMask, c
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
CMemory CModule::FindPatternSIMD(const string& svPattern, const ModuleSections_t& moduleSection) const
|
CMemory CModule::FindPatternSIMD(const string& svPattern, const ModuleSections_t& moduleSection) const
|
||||||
{
|
{
|
||||||
|
if (g_SigCache.m_bInitialized) // Get from cache instead.
|
||||||
|
{
|
||||||
|
google::protobuf::Map sMap = g_SigCache.m_Cache.smap();
|
||||||
|
|
||||||
|
auto p = sMap.find(svPattern);
|
||||||
|
if (p != sMap.end())
|
||||||
|
{
|
||||||
|
return CMemory((GetModuleBase() + p->second));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const pair patternInfo = PatternToMaskedBytes(svPattern);
|
const pair patternInfo = PatternToMaskedBytes(svPattern);
|
||||||
return FindPatternSIMD(patternInfo.first.data(), patternInfo.second.c_str(), moduleSection);
|
CMemory memory = FindPatternSIMD(patternInfo.first.data(), patternInfo.second.c_str(), moduleSection);
|
||||||
|
|
||||||
|
g_SigCache.AddEntry(svPattern, GetRVA(memory.GetPtr()));
|
||||||
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -351,3 +352,11 @@ string CModule::GetModuleName(void) const
|
|||||||
{
|
{
|
||||||
return m_svModuleName;
|
return m_svModuleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: returns the RVA of given address
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
uintptr_t CModule::GetRVA(const uintptr_t nAddress) const
|
||||||
|
{
|
||||||
|
return (nAddress - GetModuleBase());
|
||||||
|
}
|
||||||
|
@ -33,6 +33,7 @@ public:
|
|||||||
uintptr_t GetModuleBase(void) const;
|
uintptr_t GetModuleBase(void) const;
|
||||||
DWORD GetModuleSize(void) const;
|
DWORD GetModuleSize(void) const;
|
||||||
string GetModuleName(void) const;
|
string GetModuleName(void) const;
|
||||||
|
uintptr_t GetRVA(const uintptr_t nAddress) const;
|
||||||
|
|
||||||
ModuleSections_t m_ExecutableCode;
|
ModuleSections_t m_ExecutableCode;
|
||||||
ModuleSections_t m_ExceptionTable;
|
ModuleSections_t m_ExceptionTable;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user