Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: base/win/iat_patch_function.cc

Issue 138593004: Use an alternate mechanism for CreateFile calls in Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: IAT patch clean up Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | build/common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/win/iat_patch_function.h" 5 #include "base/win/iat_patch_function.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/win/pe_image.h" 8 #include "base/win/pe_image.h"
9 9
10 namespace base { 10 namespace base {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // length Number of bytes to copy 49 // length Number of bytes to copy
50 // 50 //
51 // Returns: Windows error code (winerror.h). NO_ERROR if successful 51 // Returns: Windows error code (winerror.h). NO_ERROR if successful
52 DWORD ModifyCode(void* old_code, void* new_code, int length) { 52 DWORD ModifyCode(void* old_code, void* new_code, int length) {
53 if ((NULL == old_code) || (NULL == new_code) || (0 == length)) { 53 if ((NULL == old_code) || (NULL == new_code) || (0 == length)) {
54 NOTREACHED(); 54 NOTREACHED();
55 return ERROR_INVALID_PARAMETER; 55 return ERROR_INVALID_PARAMETER;
56 } 56 }
57 57
58 // Change the page protection so that we can write. 58 // Change the page protection so that we can write.
59 MEMORY_BASIC_INFORMATION memory_info;
59 DWORD error = NO_ERROR; 60 DWORD error = NO_ERROR;
60 DWORD old_page_protection = 0; 61 DWORD old_page_protection = 0;
62
63 if (!::VirtualQuery(old_code, &memory_info, sizeof(memory_info))) {
64 error = GetLastError();
65 NOTREACHED();
rvargas (doing something else) 2014/01/21 21:19:49 On second thoughts, we should probably just remove
Cait (Slow) 2014/01/21 21:47:19 Done.
66 return error;
67 }
68
69 DWORD is_executable = (PAGE_EXECUTE | PAGE_EXECUTE_READ |
70 PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) &
71 memory_info.Protect;
rvargas (doing something else) 2014/01/21 20:03:26 tiny nit: one less space here.
Cait (Slow) 2014/01/21 21:47:19 Done.
72
61 if (VirtualProtect(old_code, 73 if (VirtualProtect(old_code,
62 length, 74 length,
63 PAGE_READWRITE, 75 is_executable ? PAGE_EXECUTE_READWRITE :
76 PAGE_READWRITE,
64 &old_page_protection)) { 77 &old_page_protection)) {
65 78
66 // Write the data. 79 // Write the data.
67 CopyMemory(old_code, new_code, length); 80 CopyMemory(old_code, new_code, length);
68 81
69 // Restore the old page protection. 82 // Restore the old page protection.
70 error = ERROR_SUCCESS; 83 error = ERROR_SUCCESS;
71 VirtualProtect(old_code, 84 VirtualProtect(old_code,
72 length, 85 length,
73 old_page_protection, 86 old_page_protection,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 module_handle_ = NULL; 282 module_handle_ = NULL;
270 intercept_function_ = NULL; 283 intercept_function_ = NULL;
271 original_function_ = NULL; 284 original_function_ = NULL;
272 iat_thunk_ = NULL; 285 iat_thunk_ = NULL;
273 286
274 return error; 287 return error;
275 } 288 }
276 289
277 } // namespace win 290 } // namespace win
278 } // namespace base 291 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | build/common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698