Skip to content

Commit

Permalink
Kasper Brandt submitted a patch to handle "mov edi,edi" hot patch poi…
Browse files Browse the repository at this point in the history
…nts and collapsed stack frames in SkipJumps.
  • Loading branch information
martona committed Mar 5, 2014
1 parent 76d1f10 commit 631d7d1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mhook-lib/mhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,17 @@ static VOID LeaveCritSec() {
// jump tables, etc.
//=========================================================================
static PBYTE SkipJumps(PBYTE pbCode) {
PBYTE pbOrgCode = pbCode;
#ifdef _M_IX86_X64
#ifdef _M_IX86
//mov edi,edi: hot patch point
if (pbCode[0] == 0x8b && pbCode[1] == 0xff)
pbCode += 2;
// push ebp; mov ebp, esp; pop ebp;
// "collapsed" stackframe generated by MSVC
if (pbCode[0] == 0x55 && pbCode[1] == 0x8b && pbCode[2] == 0xec && pbCode[3] == 0x5d)
pbCode += 4;
#endif
if (pbCode[0] == 0xff && pbCode[1] == 0x25) {
#ifdef _M_IX86
// on x86 we have an absolute pointer...
Expand Down Expand Up @@ -214,7 +224,7 @@ static PBYTE SkipJumps(PBYTE pbCode) {
#else
#error unsupported platform
#endif
return pbCode;
return pbOrgCode;
}

//=========================================================================
Expand Down Expand Up @@ -563,7 +573,7 @@ static DWORD DisassembleAndSkip(PVOID pFunction, DWORD dwMinLen, MHOOKS_PATCHDAT

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

0 comments on commit 631d7d1

Please sign in to comment.