OLD | NEW |
---|---|
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 Loading... | |
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 ::VirtualQuery(old_code, &memory_info, sizeof(memory_info)); | |
rvargas (doing something else)
2014/01/21 18:48:50
Validate the return value.
Cait (Slow)
2014/01/21 19:53:41
Done.
| |
64 | |
65 DWORD is_executable = (PAGE_EXECUTE | PAGE_EXECUTE_READ | | |
66 PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) & | |
rvargas (doing something else)
2014/01/21 18:48:50
nit: either indent under PAGE_EXECUTE or drop the
Cait (Slow)
2014/01/21 19:53:41
Done.
| |
67 memory_info.Protect; | |
68 | |
61 if (VirtualProtect(old_code, | 69 if (VirtualProtect(old_code, |
62 length, | 70 length, |
63 PAGE_READWRITE, | 71 is_executable ? PAGE_EXECUTE_READWRITE : |
72 PAGE_READWRITE, | |
64 &old_page_protection)) { | 73 &old_page_protection)) { |
65 | 74 |
66 // Write the data. | 75 // Write the data. |
67 CopyMemory(old_code, new_code, length); | 76 CopyMemory(old_code, new_code, length); |
68 | 77 |
69 // Restore the old page protection. | 78 // Restore the old page protection. |
70 error = ERROR_SUCCESS; | 79 error = ERROR_SUCCESS; |
71 VirtualProtect(old_code, | 80 VirtualProtect(old_code, |
72 length, | 81 length, |
73 old_page_protection, | 82 old_page_protection, |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 module_handle_ = NULL; | 278 module_handle_ = NULL; |
270 intercept_function_ = NULL; | 279 intercept_function_ = NULL; |
271 original_function_ = NULL; | 280 original_function_ = NULL; |
272 iat_thunk_ = NULL; | 281 iat_thunk_ = NULL; |
273 | 282 |
274 return error; | 283 return error; |
275 } | 284 } |
276 | 285 |
277 } // namespace win | 286 } // namespace win |
278 } // namespace base | 287 } // namespace base |
OLD | NEW |