Skip to content

Commit

Permalink
Mitigates TsudaKageyu#132
Browse files Browse the repository at this point in the history
Changes to mitigate the issue where SuspendThread() returns -1 (error occurred) which would then crash the host because the ResumeThread() call in Unfreeze would crash.
  • Loading branch information
FransBouma committed Aug 6, 2024
1 parent 91cc946 commit 96c2309
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,21 @@ static MH_STATUS Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
}
else if (pThreads->pItems != NULL)
{
UINT i;
for (i = 0; i < pThreads->size; ++i)
for (UINT i = 0; i < pThreads->size; ++i)
{
HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
if (hThread != NULL)
{
SuspendThread(hThread);
ProcessThreadIPs(hThread, pos, action);
DWORD result = SuspendThread(hThread);
if(result == 0xFFFFFFFF)
{
// mark thread as not suspended, so it's not resumed later on.
pThreads->pItems[i] = 0;
}
else
{
ProcessThreadIPs(hThread, pos, action);
}
CloseHandle(hThread);
}
}
Expand All @@ -359,14 +366,17 @@ static VOID Unfreeze(PFROZEN_THREADS pThreads)
{
if (pThreads->pItems != NULL)
{
UINT i;
for (i = 0; i < pThreads->size; ++i)
for (UINT i = 0; i < pThreads->size; ++i)
{
HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
if (hThread != NULL)
DWORD threadId = pThreads->pItems[i];
if(threadId > 0)
{
ResumeThread(hThread);
CloseHandle(hThread);
HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, threadId);
if(hThread != NULL)
{
ResumeThread(hThread);
CloseHandle(hThread);
}
}
}

Expand Down

0 comments on commit 96c2309

Please sign in to comment.