Bug 1348747 - Part 2: Support stub functions starting with jmp rel8 in WindowsDllDetourPatcher. r=handyman

MozReview-Commit-ID: 5hPBmxtBCnu

--HG--
extra : rebase_source : 52a1d43c9f57c9c8b70ded93cbcb76218922ea8b
extra : amend_source : 6377d7eb2246b38e69b95b2a7f507a0f86e300b1
extra : histedit_source : 5cc91dfb4613431466ccde12610a36578361bf53
This commit is contained in:
Cervantes Yu 2017-05-19 15:53:54 +08:00
parent cd7a0759ce
commit 2dc8565a99

View File

@ -332,6 +332,26 @@ public:
private:
static byteptr_t ResolveRedirectedAddress(const byteptr_t aOriginalFunction)
{
// If function entry is jmp rel8 stub to the internal implementation, we
// resolve redirected address from the jump target.
if (aOriginalFunction[0] == 0xeb) {
int8_t offset = (int8_t)(aOriginalFunction[1]);
if (offset <= 0) {
// Bail out for negative offset: probably already patched by some
// third-party code.
return aOriginalFunction;
}
for (int8_t i = 0; i < offset; i++) {
if (aOriginalFunction[2 + i] != 0x90) {
// Bail out on insufficient nop space.
return aOriginalFunction;
}
}
return aOriginalFunction + 2 + offset;
}
// 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) {
@ -1224,6 +1244,26 @@ protected:
static void* ResolveRedirectedAddress(const byteptr_t aOriginalFunction)
{
// If function entry is jmp rel8 stub to the internal implementation, we
// resolve redirected address from the jump target.
if (aOriginalFunction[0] == 0xeb) {
int8_t offset = (int8_t)(aOriginalFunction[1]);
if (offset <= 0) {
// Bail out for negative offset: probably already patched by some
// third-party code.
return aOriginalFunction;
}
for (int8_t i = 0; i < offset; i++) {
if (aOriginalFunction[2 + i] != 0x90) {
// Bail out on insufficient nop space.
return aOriginalFunction;
}
}
return aOriginalFunction + 2 + offset;
}
#if defined(_M_IX86)
// If function entry is jmp [disp32] such as used by kernel32,
// we resolve redirected address from import table.