Skip to content

Commit 3e0b576

Browse files
committed
Add a workaround for shared ppOriginal
1 parent e3357f2 commit 3e0b576

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/MinHook.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,28 @@ static MH_STATUS CreateHook(ULONG_PTR hookIdent, LPVOID pTarget, LPVOID pDetour,
204204

205205
if (ppOriginal)
206206
{
207+
// Check if the ppOriginal pointer was already specified for
208+
// other hooks. If so, modify them to use pTargetOrTrampoline.
209+
// This fixes a problem with the following questionable code:
210+
//
211+
// MH_CreateHook(pTarget1, pDetour, &ppOriginal);
212+
// // ...
213+
// MH_CreateHook(pTarget2, pDetour, &ppOriginal);
214+
//
215+
// While it's unsupported to have the same ppOriginal pointer
216+
// specified more than once, it worked in MinHook, and some
217+
// Windhawk mods which call HandleLoadedExplorerPatcher rely on
218+
// it.
219+
for (UINT i = 0; i < g_hooks.size - 1; ++i)
220+
{
221+
PHOOK_ENTRY pHookIter = &g_hooks.pItems[i];
222+
if (pHookIter->ppOriginal == ppOriginal)
223+
{
224+
pHookIter->pTargetOrTrampoline = *pHookIter->ppOriginal;
225+
pHookIter->ppOriginal = &pHookIter->pTargetOrTrampoline;
226+
}
227+
}
228+
207229
pHook->pTargetOrTrampoline = NULL;
208230
pHook->ppOriginal = ppOriginal;
209231
*ppOriginal = pTarget;

0 commit comments

Comments
 (0)