Bug 1121829 - Support redirection of kernel32.dll for hooking function. r=dmajor

This commit is contained in:
Makoto Kato 2015-01-16 23:07:09 +09:00
parent 1247e9d923
commit e9788e3d05

View File

@ -136,6 +136,8 @@ public:
return false;
}
fn = ResolveRedirectedAddress(fn);
// Ensure we can read and write starting at fn - 5 (for the long jmp we're
// going to write) and ending at fn + 2 (for the short jmp up to the long
// jmp).
@ -202,6 +204,18 @@ public:
return true;
}
private:
static byteptr_t ResolveRedirectedAddress(const byteptr_t aOriginalFunction)
{
// If function entry is jmp [disp32] such as used by kernel32,
// we resolve redirected address from import table.
if (aOriginalFunction[0] == 0xff && aOriginalFunction[1] == 0x25) {
return (byteptr_t)(**((uint32_t**) (aOriginalFunction + 2)));
}
return aOriginalFunction;
}
#else
bool AddHook(const char* aName, intptr_t aHookDest, void** aOrigFunc)
{
@ -312,6 +326,8 @@ public:
return false;
}
pAddr = ResolveRedirectedAddress((byteptr_t)pAddr);
CreateTrampoline(pAddr, aHookDest, aOrigFunc);
if (!*aOrigFunc) {
//printf ("CreateTrampoline failed\n");
@ -653,6 +669,19 @@ protected:
return p;
}
static void* ResolveRedirectedAddress(const byteptr_t aOriginalFunction)
{
#if defined(_M_IX86)
// If function entry is jmp [disp32] such as used by kernel32,
// we resolve redirected address from import table.
if (aOriginalFunction[0] == 0xff && aOriginalFunction[1] == 0x25) {
return (void*)(**((uint32_t**) (aOriginalFunction + 2)));
}
#endif
return aOriginalFunction;
}
};
} // namespace internal