Bug 1446499: Use static nsWindowsDllInterceptor in plugin's HookProtectedMode r=aklotz

HookProtectedMode requires its nsWindowsDllInterceptor to last as long as the functions need to be overridden.  This uses a static object instead of a local one.

--HG--
extra : rebase_source : 7ba3f2fc1e19f89936b7f7fa490554e9cf9b885c
This commit is contained in:
David Parks 2018-04-03 17:09:36 -07:00
Родитель 679c14a9c4
Коммит a9fd0592af
1 изменённых файлов: 14 добавлений и 7 удалений

Просмотреть файл

@ -296,16 +296,23 @@ CreateFileWHookFn(LPCWSTR aFname, DWORD aAccess, DWORD aShare,
void FunctionHook::HookProtectedMode() void FunctionHook::HookProtectedMode()
{ {
// Make sure we only do this once.
static bool sRunOnce = false;
if (sRunOnce) {
return;
}
sRunOnce = true;
// Legacy code. Uses the nsWindowsDLLInterceptor directly instead of // Legacy code. Uses the nsWindowsDLLInterceptor directly instead of
// using the FunctionHook // using the FunctionHook
sKernel32Intercept.Init("kernel32.dll");
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Plugin); MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Plugin);
WindowsDllInterceptor k32Intercept("kernel32.dll"); sKernel32Intercept.AddHook("CreateFileW",
k32Intercept.AddHook("CreateFileW", reinterpret_cast<intptr_t>(CreateFileWHookFn),
reinterpret_cast<intptr_t>(CreateFileWHookFn), (void**) &sCreateFileWStub);
(void**) &sCreateFileWStub); sKernel32Intercept.AddHook("CreateFileA",
k32Intercept.AddHook("CreateFileA", reinterpret_cast<intptr_t>(CreateFileAHookFn),
reinterpret_cast<intptr_t>(CreateFileAHookFn), (void**) &sCreateFileAStub);
(void**) &sCreateFileAStub);
} }
#endif // defined(XP_WIN) #endif // defined(XP_WIN)