Skip to content

Fix dhooks x64 crash in UpdateRegisterArgumentSizes() for #2282 #2290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions extensions/dhooks/dynhooks_sourcepawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,17 @@ ICallingConvention *ConstructCallingConvention(HookSetup *setup)
returnType.custom_register = None;

#ifdef DYNAMICHOOKS_x86_64
#ifdef WIN32
if (setup->callConv == CallConv_THISCALL) {
DataTypeSized_t type;
type.type = DATA_TYPE_POINTER;
type.size = GetDataTypeSize(type, sizeof(void*));
#ifdef PLATFORM_WINDOWS
type.custom_register = RCX;
#else
type.custom_register = RDI;
#endif
vecArgTypes.insert(vecArgTypes.begin(), type);
}
#endif
#endif

ICallingConvention *pCallConv = nullptr;
Expand Down Expand Up @@ -308,19 +310,27 @@ bool UpdateRegisterArgumentSizes(CHook* pDetour, HookSetup *setup)
ICallingConvention* callingConvention = pDetour->m_pCallingConvention;
std::vector<DataTypeSized_t> &argTypes = callingConvention->m_vecArgTypes;
int numArgs = argTypes.size();
int argTypesOffset = 0;

#ifdef DYNAMICHOOKS_x86_64
if (setup->callConv == CallConv_THISCALL) {
argTypesOffset = 1;
--numArgs;
}
#endif

for (int i = 0; i < numArgs; i++)
{
// Ignore regular arguments on the stack.
if (argTypes[i].custom_register == None)
if (argTypes[argTypesOffset+i].custom_register == None)
continue;

CRegister *reg = pDetour->m_pRegisters->GetRegister(argTypes[i].custom_register);
CRegister *reg = pDetour->m_pRegisters->GetRegister(argTypes[argTypesOffset+i].custom_register);
// That register can't be handled yet.
if (!reg)
return false;

argTypes[i].size = reg->m_iSize;
argTypes[argTypesOffset+i].size = reg->m_iSize;
setup->params[i].size = reg->m_iSize;
}

Expand Down
Loading