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

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

Issue 144333003: Revert 246313 "Use an alternate mechanism for CreateFile calls i..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | trunk/src/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;
60 DWORD error = NO_ERROR; 59 DWORD error = NO_ERROR;
61 DWORD old_page_protection = 0; 60 DWORD old_page_protection = 0;
62
63 if (!::VirtualQuery(old_code, &memory_info, sizeof(memory_info))) {
64 error = GetLastError();
65 return error;
66 }
67
68 DWORD is_executable = (PAGE_EXECUTE | PAGE_EXECUTE_READ |
69 PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) &
70 memory_info.Protect;
71
72 if (VirtualProtect(old_code, 61 if (VirtualProtect(old_code,
73 length, 62 length,
74 is_executable ? PAGE_EXECUTE_READWRITE : 63 PAGE_READWRITE,
75 PAGE_READWRITE,
76 &old_page_protection)) { 64 &old_page_protection)) {
77 65
78 // Write the data. 66 // Write the data.
79 CopyMemory(old_code, new_code, length); 67 CopyMemory(old_code, new_code, length);
80 68
81 // Restore the old page protection. 69 // Restore the old page protection.
82 error = ERROR_SUCCESS; 70 error = ERROR_SUCCESS;
83 VirtualProtect(old_code, 71 VirtualProtect(old_code,
84 length, 72 length,
85 old_page_protection, 73 old_page_protection,
86 &old_page_protection); 74 &old_page_protection);
87 } else { 75 } else {
88 error = GetLastError(); 76 error = GetLastError();
77 NOTREACHED();
89 } 78 }
90 79
91 return error; 80 return error;
92 } 81 }
93 82
94 bool InterceptEnumCallback(const base::win::PEImage& image, const char* module, 83 bool InterceptEnumCallback(const base::win::PEImage& image, const char* module,
95 DWORD ordinal, const char* name, DWORD hint, 84 DWORD ordinal, const char* name, DWORD hint,
96 IMAGE_THUNK_DATA* iat, void* cookie) { 85 IMAGE_THUNK_DATA* iat, void* cookie) {
97 InterceptFunctionInformation* intercept_information = 86 InterceptFunctionInformation* intercept_information =
98 reinterpret_cast<InterceptFunctionInformation*>(cookie); 87 reinterpret_cast<InterceptFunctionInformation*>(cookie);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 module_handle_ = NULL; 269 module_handle_ = NULL;
281 intercept_function_ = NULL; 270 intercept_function_ = NULL;
282 original_function_ = NULL; 271 original_function_ = NULL;
283 iat_thunk_ = NULL; 272 iat_thunk_ = NULL;
284 273
285 return error; 274 return error;
286 } 275 }
287 276
288 } // namespace win 277 } // namespace win
289 } // namespace base 278 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | trunk/src/build/common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698