Skip to content

Commit

Permalink
Merge pull request #134 from FransBouma/master
Browse files Browse the repository at this point in the history
Mitigates #132
  • Loading branch information
m417z authored Aug 8, 2024
2 parents 91cc946 + df15207 commit c1a7c38
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,23 @@ static MH_STATUS Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
for (i = 0; i < pThreads->size; ++i)
{
HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
BOOL suspended = FALSE;
if (hThread != NULL)
{
SuspendThread(hThread);
ProcessThreadIPs(hThread, pos, action);
DWORD result = SuspendThread(hThread);
if (result != 0xFFFFFFFF)
{
suspended = TRUE;
ProcessThreadIPs(hThread, pos, action);
}
CloseHandle(hThread);
}

if (!suspended)
{
// Mark thread as not suspended, so it's not resumed later on.
pThreads->pItems[i] = 0;
}
}
}

Expand All @@ -362,11 +373,15 @@ static VOID Unfreeze(PFROZEN_THREADS pThreads)
UINT i;
for (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 c1a7c38

Please sign in to comment.