New CMemory function and vgui comments.

* CMemory::FindAllCallReferences: Get all function calls to a function from the supplied sectioBase and sectionSize, useful to mass patch calls to a function.
This commit is contained in:
PixieCore 2022-07-02 19:08:35 +02:00
parent 6f4d69a776
commit f614ed5140
3 changed files with 39 additions and 7 deletions

View File

@ -124,6 +124,7 @@ public:
CMemory FollowNearCallSelf(const ptrdiff_t opcodeOffset = 0x1, const ptrdiff_t nextInstructionOffset = 0x5);
CMemory ResolveRelativeAddress(const ptrdiff_t registerOffset = 0x0, const ptrdiff_t nextInstructionOffset = 0x4) const;
CMemory ResolveRelativeAddressSelf(const ptrdiff_t registerOffset = 0x0, const ptrdiff_t nextInstructionOffset = 0x4);
vector<CMemory> FindAllCallReferences(const uintptr_t sectionBase, const size_t sectionSize);
static void HookVirtualMethod(const uintptr_t virtualTable, const void* pHookMethod, const ptrdiff_t methodIndex, void** ppOriginalMethod);
private:

View File

@ -232,6 +232,34 @@ CMemory CMemory::ResolveRelativeAddressSelf(const ptrdiff_t registerOffset, cons
return *this;
}
//-----------------------------------------------------------------------------
// Purpose: resolve all 'call' references to ptr
// (This is very slow only use for mass patching.)
// Input : sectionBase -
// sectionSize -
// Output : vector<CMemory>
//-----------------------------------------------------------------------------
vector<CMemory> CMemory::FindAllCallReferences(const uintptr_t sectionBase, const size_t sectionSize)
{
vector <CMemory> referencesInfo = {};
uint8_t* pTextStart = reinterpret_cast<uint8_t*>(sectionBase);
for (size_t i = 0ull; i < sectionSize - 0x5; i++, _mm_prefetch(reinterpret_cast<const char*>(pTextStart + 64), _MM_HINT_NTA))
{
if (pTextStart[i] == CALL)
{
CMemory memAddr = CMemory(&pTextStart[i]);
if (!memAddr.Offset(0x1).CheckOpCodes({ 0x00, 0x00, 0x00, 0x00 })) // Check if its not a dynamic resolved call.
{
if (memAddr.FollowNearCall() == *this)
referencesInfo.push_back(memAddr);
}
}
}
return referencesInfo;
}
//-----------------------------------------------------------------------------
// Purpose: patch virtual method to point to a user set function
// Input : virtualTable -

View File

@ -19,7 +19,7 @@
#include <materialsystem/cmaterialglue.h>
//-----------------------------------------------------------------------------
// Purpose:
// Purpose: proceed a log update
//-----------------------------------------------------------------------------
void CLogSystem::Update(void)
{
@ -50,7 +50,7 @@ void CLogSystem::Update(void)
}
//-----------------------------------------------------------------------------
// Purpose:
// Purpose: add a log to the vector.
//-----------------------------------------------------------------------------
void CLogSystem::AddLog(LogType_t type, string svMessage)
{
@ -61,7 +61,7 @@ void CLogSystem::AddLog(LogType_t type, string svMessage)
}
//-----------------------------------------------------------------------------
// Purpose:
// Purpose: draw log on screen.
//-----------------------------------------------------------------------------
void CLogSystem::DrawLog(void)
{
@ -109,7 +109,7 @@ void CLogSystem::DrawLog(void)
}
//-----------------------------------------------------------------------------
// Purpose:
// Purpose: draw current host stats on screen.
//-----------------------------------------------------------------------------
void CLogSystem::DrawHostStats(void) const
{
@ -130,7 +130,7 @@ void CLogSystem::DrawHostStats(void) const
}
//-----------------------------------------------------------------------------
// Purpose:
// Purpose: draw current simulation stats on screen.
//-----------------------------------------------------------------------------
void CLogSystem::DrawSimStats(void) const
{
@ -155,7 +155,7 @@ void CLogSystem::DrawSimStats(void) const
}
//-----------------------------------------------------------------------------
// Purpose:
// Purpose: draw current gpu stats on screen.
//-----------------------------------------------------------------------------
void CLogSystem::DrawGPUStats(void) const
{
@ -179,6 +179,9 @@ void CLogSystem::DrawGPUStats(void) const
CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, 0x13, m_nFontHeight, nWidth, nHeight, c.r(), c.g(), c.b(), c.a(), (char*)szLogbuf);
}
//-----------------------------------------------------------------------------
// Purpose: draw currently traced material info on screen.
//-----------------------------------------------------------------------------
void CLogSystem::DrawCrosshairMaterial(void) const
{
CMaterialGlue* material = GetMaterialAtCrossHair();
@ -198,7 +201,7 @@ void CLogSystem::DrawCrosshairMaterial(void) const
}
//-----------------------------------------------------------------------------
// Purpose:
// Purpose: get log color for passed type.
//-----------------------------------------------------------------------------
Color CLogSystem::GetLogColorForType(LogType_t type) const
{