OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome_frame/module_utils.h" | 5 #include "chrome_frame/module_utils.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 const wchar_t kBeaconWindowClassName[] = | 10 const wchar_t kBeaconWindowClassName[] = |
(...skipping 29 matching lines...) Expand all Loading... |
40 atom_ = NULL; | 40 atom_ = NULL; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 HMODULE DllRedirector::GetFirstCFModule() { | 44 HMODULE DllRedirector::GetFirstCFModule() { |
45 WNDCLASSEX wnd_class = {0}; | 45 WNDCLASSEX wnd_class = {0}; |
46 HMODULE oldest_module = NULL; | 46 HMODULE oldest_module = NULL; |
47 if (GetClassInfoEx(GetModuleHandle(NULL), kBeaconWindowClassName, | 47 if (GetClassInfoEx(GetModuleHandle(NULL), kBeaconWindowClassName, |
48 &wnd_class)) { | 48 &wnd_class)) { |
49 oldest_module = reinterpret_cast<HMODULE>(wnd_class.lpfnWndProc); | 49 oldest_module = reinterpret_cast<HMODULE>(wnd_class.lpfnWndProc); |
| 50 // Handle older versions that store module pointer in a class info. |
| 51 // TODO(amit): Remove this in future versions. |
| 52 if (reinterpret_cast<HMODULE>(DefWindowProc) == oldest_module) { |
| 53 WNDCLASSEX wnd_class = {0}; |
| 54 HMODULE oldest_module = NULL; |
| 55 HWND hwnd = CreateWindow(kBeaconWindowClassName, L"temp_window", |
| 56 WS_POPUP, 0, 0, 0, 0, NULL, NULL, NULL, NULL); |
| 57 DCHECK(IsWindow(hwnd)); |
| 58 if (hwnd) { |
| 59 oldest_module = reinterpret_cast<HMODULE>(GetClassLongPtr(hwnd, 0)); |
| 60 DestroyWindow(hwnd); |
| 61 } |
| 62 } |
50 } | 63 } |
51 return oldest_module; | 64 return oldest_module; |
52 } | 65 } |
53 | 66 |
54 LPFNGETCLASSOBJECT DllRedirector::GetDllGetClassObjectPtr(HMODULE module) { | 67 LPFNGETCLASSOBJECT DllRedirector::GetDllGetClassObjectPtr(HMODULE module) { |
55 LPFNGETCLASSOBJECT proc_ptr = NULL; | 68 LPFNGETCLASSOBJECT proc_ptr = NULL; |
56 HMODULE temp_handle = 0; | 69 HMODULE temp_handle = 0; |
57 // Increment the module ref count while we have an pointer to its | 70 // Increment the module ref count while we have an pointer to its |
58 // DllGetClassObject function. | 71 // DllGetClassObject function. |
59 if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, | 72 if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, |
60 reinterpret_cast<LPCTSTR>(module), | 73 reinterpret_cast<LPCTSTR>(module), |
61 &temp_handle)) { | 74 &temp_handle)) { |
62 proc_ptr = reinterpret_cast<LPFNGETCLASSOBJECT>( | 75 proc_ptr = reinterpret_cast<LPFNGETCLASSOBJECT>( |
63 GetProcAddress(temp_handle, "DllGetClassObject")); | 76 GetProcAddress(temp_handle, "DllGetClassObject")); |
64 if (!proc_ptr) { | 77 if (!proc_ptr) { |
65 FreeLibrary(temp_handle); | 78 FreeLibrary(temp_handle); |
66 LOG(ERROR) << "Module Scan: Couldn't get address of " | 79 LOG(ERROR) << "Module Scan: Couldn't get address of " |
67 << "DllGetClassObject: " | 80 << "DllGetClassObject: " |
68 << GetLastError(); | 81 << GetLastError(); |
69 } | 82 } |
70 } else { | 83 } else { |
71 LOG(ERROR) << "Module Scan: Could not increment module count: " | 84 LOG(ERROR) << "Module Scan: Could not increment module count: " |
72 << GetLastError(); | 85 << GetLastError(); |
73 } | 86 } |
74 return proc_ptr; | 87 return proc_ptr; |
75 } | 88 } |
OLD | NEW |