Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/win/delay_load_hook.h" | |
| 6 | |
| 7 #if defined(_WIN32_WINNT_WIN8) && _MSC_VER < 1700 | |
| 8 // The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h, and in | |
| 9 // delayimp.h previous to VS2012. | |
| 10 #undef FACILITY_VISUALCPP | |
| 11 #endif | |
| 12 #include <DelayIMP.h> | |
| 13 | |
| 14 #include "base/logging.h" | |
| 15 #include "base/string_util.h" | |
| 16 | |
| 17 // So long as these symbols are supplied to the final binary through an | |
| 18 // object file (as opposed to indirectly thruogh a library), these pointers | |
| 19 // will override the CRT's symbols and direct the notifications to our hook. | |
| 20 PfnDliHook __pfnDliNotifyHook2 = base::win::ChromeDelayLoadHook; | |
| 21 PfnDliHook __pfnDliFailureHook2 = base::win::ChromeDelayLoadHook; | |
| 22 | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 FARPROC OnPreLoadLibrary(DelayLoadInfo* info) { | |
| 27 // If the DLL name ends with "-delay.dll", this call is about one of our | |
| 28 // custom import libraries. In this case we need to snip the suffix off, | |
| 29 // and bind to the real DLL. | |
| 30 std::string dll_name(info->szDll); | |
| 31 const char kDelaySuffix[] = "-delay.dll"; | |
| 32 if (EndsWith(dll_name, kDelaySuffix, false)) { | |
| 33 // Trim the "-delay.dll" suffix from the string. | |
| 34 dll_name.resize(dll_name.length() - (sizeof(kDelaySuffix) - 1)); | |
| 35 dll_name.append(".dll"); | |
| 36 | |
| 37 HMODULE dll = ::LoadLibraryA(dll_name.c_str()); | |
| 38 | |
| 39 return reinterpret_cast<FARPROC>(dll); | |
| 40 } | |
| 41 | |
| 42 return NULL; | |
| 43 } | |
| 44 | |
| 45 FARPROC OnFailLoadLib(DelayLoadInfo* info) { | |
| 46 LOG(FATAL) << "Failed to delay load DLL: " << info->szDll; | |
| 47 return NULL; | |
| 48 } | |
| 49 | |
| 50 FARPROC OnFailGetProc(DelayLoadInfo* info) { | |
| 51 if (info->dlp.fImportByName) { | |
| 52 LOG(FATAL) << "Failed to delay load function: '" << info->dlp.szProcName | |
| 53 << "' from DLL: " << info->szDll; | |
| 54 } else { | |
| 55 LOG(FATAL) << "Failed to delay load ordinal: '" << info->dlp.dwOrdinal | |
| 56 << "' from DLL: " << info->szDll; | |
| 57 } | |
|
cpu_(ooo_6.6-7.5)
2013/02/20 21:52:55
not sure we want this here, the current handling v
Sigurður Ásgeirsson
2013/02/26 18:56:19
Moved this to chrome/app. However, the intent here
| |
| 58 | |
| 59 return NULL; | |
| 60 } | |
| 61 | |
| 62 } // namespace | |
| 63 | |
| 64 namespace base { | |
| 65 namespace win { | |
| 66 | |
| 67 FARPROC WINAPI ChromeDelayLoadHook(unsigned reason, DelayLoadInfo* info) { | |
| 68 switch (reason) { | |
| 69 case dliNoteStartProcessing: | |
| 70 LOG(INFO) << "Delay load dliNoteStartProcessing notification."; | |
| 71 break; | |
| 72 case dliNotePreLoadLibrary: | |
| 73 return OnPreLoadLibrary(info); | |
| 74 | |
| 75 break; | |
| 76 case dliNotePreGetProcAddress: | |
| 77 LOG(INFO) << "Delay load dliNotePreGetProcAddress notification."; | |
| 78 break; | |
| 79 | |
| 80 case dliFailLoadLib: | |
| 81 return OnFailLoadLib(info); | |
| 82 break; | |
| 83 | |
| 84 case dliFailGetProc: | |
| 85 return OnFailGetProc(info); | |
| 86 break; | |
| 87 | |
| 88 case dliNoteEndProcessing: | |
| 89 LOG(INFO) << "Delay load dliNoteEndProcessing notification."; | |
| 90 break; | |
| 91 default: | |
| 92 NOTREACHED() << "Impossible delay load notification."; | |
| 93 break; | |
| 94 } | |
| 95 | |
| 96 return NULL; | |
| 97 } | |
| 98 | |
| 99 } // namespace win | |
| 100 } // namespace base | |
| OLD | NEW |