Fix crash when accessing invalid argument index

Just return null if a user tries to access an invalid argument that wasn't defined when detouring the function.
This commit is contained in:
Peace-Maker 2018-04-18 00:57:58 +02:00
parent 9bbca712b6
commit b16d1f9f3f
3 changed files with 15 additions and 3 deletions

View File

@ -129,6 +129,9 @@ int x86MsCdecl::GetArgRegisterSize()
void* x86MsCdecl::GetArgumentPtr(int iIndex, CRegisters* pRegisters)
{
if (iIndex < 0 || iIndex >= m_vecArgTypes.length())
return NULL;
// Check if this argument was passed in a register.
if (m_vecArgTypes[iIndex].custom_register != None)
{

View File

@ -137,6 +137,9 @@ int x86MsStdcall::GetArgRegisterSize()
void* x86MsStdcall::GetArgumentPtr(int iIndex, CRegisters* pRegisters)
{
if (iIndex < 0 || iIndex >= m_vecArgTypes.length())
return NULL;
// Check if this argument was passed in a register.
if (m_vecArgTypes[iIndex].custom_register != None)
{

View File

@ -150,11 +150,17 @@ void* x86MsThiscall::GetArgumentPtr(int iIndex, CRegisters* pRegisters)
// TODO: Allow custom this register.
return pRegisters->m_ecx->m_pAddress;
}
// The this pointer isn't explicitly defined as an argument.
iIndex--;
if (iIndex < 0 || iIndex >= m_vecArgTypes.length())
return NULL;
// Check if this argument was passed in a register.
if (m_vecArgTypes[iIndex-1].custom_register != None)
if (m_vecArgTypes[iIndex].custom_register != None)
{
CRegister *pRegister = pRegisters->GetRegister(m_vecArgTypes[iIndex-1].custom_register);
CRegister *pRegister = pRegisters->GetRegister(m_vecArgTypes[iIndex].custom_register);
if (!pRegister)
return NULL;
@ -162,7 +168,7 @@ void* x86MsThiscall::GetArgumentPtr(int iIndex, CRegisters* pRegisters)
}
int iOffset = 4;
for(int i=0; i < iIndex-1; i++)
for(int i=0; i < iIndex; i++)
{
if (m_vecArgTypes[i].custom_register == None)
iOffset += m_vecArgTypes[i].size;