Skip to content

Commit 631d7d1

Browse files
committed
Kasper Brandt submitted a patch to handle "mov edi,edi" hot patch points and collapsed stack frames in SkipJumps.
1 parent 76d1f10 commit 631d7d1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

mhook-lib/mhook.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,17 @@ static VOID LeaveCritSec() {
185185
// jump tables, etc.
186186
//=========================================================================
187187
static PBYTE SkipJumps(PBYTE pbCode) {
188+
PBYTE pbOrgCode = pbCode;
188189
#ifdef _M_IX86_X64
190+
#ifdef _M_IX86
191+
//mov edi,edi: hot patch point
192+
if (pbCode[0] == 0x8b && pbCode[1] == 0xff)
193+
pbCode += 2;
194+
// push ebp; mov ebp, esp; pop ebp;
195+
// "collapsed" stackframe generated by MSVC
196+
if (pbCode[0] == 0x55 && pbCode[1] == 0x8b && pbCode[2] == 0xec && pbCode[3] == 0x5d)
197+
pbCode += 4;
198+
#endif
189199
if (pbCode[0] == 0xff && pbCode[1] == 0x25) {
190200
#ifdef _M_IX86
191201
// on x86 we have an absolute pointer...
@@ -214,7 +224,7 @@ static PBYTE SkipJumps(PBYTE pbCode) {
214224
#else
215225
#error unsupported platform
216226
#endif
217-
return pbCode;
227+
return pbOrgCode;
218228
}
219229

220230
//=========================================================================
@@ -563,7 +573,7 @@ static DWORD DisassembleAndSkip(PVOID pFunction, DWORD dwMinLen, MHOOKS_PATCHDAT
563573

564574
ODPRINTF((L"mhooks: DisassembleAndSkip: Disassembling %p", pLoc));
565575
while ( (dwRet < dwMinLen) && (pins = GetInstruction(&dis, (ULONG_PTR)pLoc, pLoc, dwFlags)) ) {
566-
ODPRINTF(("mhooks: DisassembleAndSkip: %p: %s", pLoc, pins->String));
576+
ODPRINTF(("mhooks: DisassembleAndSkip: %p:(0x%2.2x) %s", pLoc, pins->Length, pins->String));
567577
if (pins->Type == ITYPE_RET ) break;
568578
if (pins->Type == ITYPE_BRANCH ) break;
569579
if (pins->Type == ITYPE_BRANCHCC) break;

0 commit comments

Comments
 (0)