1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/update/updater/loaddlls.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include <windows.h> 1.10 + 1.11 +// Delayed load libraries are loaded when the first symbol is used. 1.12 +// The following ensures that we load the delayed loaded libraries from the 1.13 +// system directory. 1.14 +struct AutoLoadSystemDependencies 1.15 +{ 1.16 + AutoLoadSystemDependencies() 1.17 + { 1.18 + // Remove the current directory from the search path for dynamically loaded 1.19 + // DLLs as a precaution. This call has no effect for delay load DLLs. 1.20 + SetDllDirectory(L""); 1.21 + 1.22 + // The order that these are loaded matter, for example if we load something 1.23 + // that tries to load profapi.dll first, then profapi.dll would be loaded 1.24 + // wrongly from the current directory. 1.25 + static LPCWSTR delayDLLs[] = { L"profapi.dll", L"wsock32.dll", 1.26 + L"crypt32.dll", L"cryptsp.dll", 1.27 + L"cryptbase.dll", L"msasn1.dll", 1.28 + L"userenv.dll", L"secur32.dll", 1.29 + L"ws2_32.dll", L"ws2help.dll", 1.30 + L"apphelp.dll", L"bcryptprimitives.dll" }; 1.31 + 1.32 + WCHAR systemDirectory[MAX_PATH + 1] = { L'\0' }; 1.33 + // If GetSystemDirectory fails we accept that we'll load the DLLs from the 1.34 + // normal search path. 1.35 + GetSystemDirectory(systemDirectory, MAX_PATH + 1); 1.36 + size_t systemDirLen = wcslen(systemDirectory); 1.37 + 1.38 + // Make the system directory path terminate with a slash 1.39 + if (systemDirectory[systemDirLen - 1] != L'\\' && systemDirLen) { 1.40 + systemDirectory[systemDirLen] = L'\\'; 1.41 + ++systemDirLen; 1.42 + // No need to re-null terminate 1.43 + } 1.44 + 1.45 + // For each known DLL ensure it is loaded from the system32 directory 1.46 + for (size_t i = 0; i < sizeof(delayDLLs) / sizeof(delayDLLs[0]); ++i) { 1.47 + size_t fileLen = wcslen(delayDLLs[i]); 1.48 + wcsncpy(systemDirectory + systemDirLen, delayDLLs[i], 1.49 + MAX_PATH - systemDirLen); 1.50 + if (systemDirLen + fileLen <= MAX_PATH) { 1.51 + systemDirectory[systemDirLen + fileLen] = L'\0'; 1.52 + } else { 1.53 + systemDirectory[MAX_PATH] = L'\0'; 1.54 + } 1.55 + LPCWSTR fullModulePath = systemDirectory; // just for code readability 1.56 + LoadLibraryW(fullModulePath); 1.57 + } 1.58 + } 1.59 +} loadDLLs;