OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/debug/close_handle_hook_win.h" | 5 #include "base/debug/close_handle_hook_win.h" |
6 | 6 |
7 #include <Windows.h> | 7 #include <Windows.h> |
8 #include <psapi.h> | 8 #include <psapi.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <memory> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/win/iat_patch_function.h" | 17 #include "base/win/iat_patch_function.h" |
18 #include "base/win/pe_image.h" | 18 #include "base/win/pe_image.h" |
19 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 typedef BOOL (WINAPI* CloseHandleType) (HANDLE handle); | 24 typedef BOOL (WINAPI* CloseHandleType) (HANDLE handle); |
25 | 25 |
26 typedef BOOL (WINAPI* DuplicateHandleType)(HANDLE source_process, | 26 typedef BOOL (WINAPI* DuplicateHandleType)(HANDLE source_process, |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 for (std::vector<base::win::IATPatchFunction*>::iterator it = hooks_.begin(); | 236 for (std::vector<base::win::IATPatchFunction*>::iterator it = hooks_.begin(); |
237 it != hooks_.end(); ++it) { | 237 it != hooks_.end(); ++it) { |
238 (*it)->Unpatch(); | 238 (*it)->Unpatch(); |
239 delete *it; | 239 delete *it; |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 void PatchLoadedModules(HandleHooks* hooks) { | 243 void PatchLoadedModules(HandleHooks* hooks) { |
244 const DWORD kSize = 256; | 244 const DWORD kSize = 256; |
245 DWORD returned; | 245 DWORD returned; |
246 scoped_ptr<HMODULE[]> modules(new HMODULE[kSize]); | 246 std::unique_ptr<HMODULE[]> modules(new HMODULE[kSize]); |
247 if (!EnumProcessModules(GetCurrentProcess(), modules.get(), | 247 if (!EnumProcessModules(GetCurrentProcess(), modules.get(), |
248 kSize * sizeof(HMODULE), &returned)) { | 248 kSize * sizeof(HMODULE), &returned)) { |
249 return; | 249 return; |
250 } | 250 } |
251 returned /= sizeof(HMODULE); | 251 returned /= sizeof(HMODULE); |
252 returned = std::min(kSize, returned); | 252 returned = std::min(kSize, returned); |
253 | 253 |
254 for (DWORD current = 0; current < returned; current++) { | 254 for (DWORD current = 0; current < returned; current++) { |
255 hooks->AddIATPatch(modules[current]); | 255 hooks->AddIATPatch(modules[current]); |
256 } | 256 } |
(...skipping 10 matching lines...) Expand all Loading... |
267 PatchLoadedModules(hooks); | 267 PatchLoadedModules(hooks); |
268 } | 268 } |
269 | 269 |
270 void RemoveHandleHooks() { | 270 void RemoveHandleHooks() { |
271 // We are partching all loaded modules without forcing them to stay in memory, | 271 // We are partching all loaded modules without forcing them to stay in memory, |
272 // removing patches is not safe. | 272 // removing patches is not safe. |
273 } | 273 } |
274 | 274 |
275 } // namespace debug | 275 } // namespace debug |
276 } // namespace base | 276 } // namespace base |
OLD | NEW |