| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sandbox/win/src/service_resolver.h" | 5 #include "sandbox/win/src/service_resolver.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "sandbox/win/src/sandbox_utils.h" | |
| 9 #include "sandbox/win/src/win_utils.h" | 8 #include "sandbox/win/src/win_utils.h" |
| 10 | 9 |
| 11 namespace { | 10 namespace { |
| 12 #pragma pack(push, 1) | 11 #pragma pack(push, 1) |
| 13 | 12 |
| 14 const BYTE kMovEax = 0xB8; | 13 const BYTE kMovEax = 0xB8; |
| 15 const BYTE kMovEdx = 0xBA; | 14 const BYTE kMovEdx = 0xBA; |
| 16 const USHORT kMovEdxEsp = 0xD48B; | 15 const USHORT kMovEdxEsp = 0xD48B; |
| 17 const USHORT kCallPtrEdx = 0x12FF; | 16 const USHORT kCallPtrEdx = 0x12FF; |
| 18 const USHORT kCallEdx = 0xD2FF; | 17 const USHORT kCallEdx = 0xD2FF; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 if (!::ReadProcessMemory(process_, | 202 if (!::ReadProcessMemory(process_, |
| 204 bit_cast<const void*>(function_code.stub), | 203 bit_cast<const void*>(function_code.stub), |
| 205 &ki_system_call, sizeof(ki_system_call), &read)) | 204 &ki_system_call, sizeof(ki_system_call), &read)) |
| 206 return false; | 205 return false; |
| 207 | 206 |
| 208 if (sizeof(ki_system_call) != read) | 207 if (sizeof(ki_system_call) != read) |
| 209 return false; | 208 return false; |
| 210 | 209 |
| 211 HMODULE module_1, module_2; | 210 HMODULE module_1, module_2; |
| 212 // last check, call_stub should point to a KiXXSystemCall function on ntdll | 211 // last check, call_stub should point to a KiXXSystemCall function on ntdll |
| 213 if (!GetModuleHandleHelper(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | | 212 if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | |
| 214 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, | 213 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, |
| 215 bit_cast<const wchar_t*>(ki_system_call), | 214 bit_cast<const wchar_t*>(ki_system_call), &module_1)) |
| 216 &module_1)) | |
| 217 return false; | 215 return false; |
| 218 | 216 |
| 219 if (NULL != ntdll_base_) { | 217 if (NULL != ntdll_base_) { |
| 220 // This path is only taken when running the unit tests. We want to be | 218 // This path is only taken when running the unit tests. We want to be |
| 221 // able to patch a buffer in memory, so target_ is not inside ntdll. | 219 // able to patch a buffer in memory, so target_ is not inside ntdll. |
| 222 module_2 = ntdll_base_; | 220 module_2 = ntdll_base_; |
| 223 } else { | 221 } else { |
| 224 if (!GetModuleHandleHelper( | 222 if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | |
| 225 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | | 223 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, |
| 226 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, | 224 reinterpret_cast<const wchar_t*>(target_), |
| 227 reinterpret_cast<const wchar_t*>(target_), | 225 &module_2)) |
| 228 &module_2)) { | |
| 229 return false; | 226 return false; |
| 230 } | |
| 231 } | 227 } |
| 232 | 228 |
| 233 if (module_1 != module_2) | 229 if (module_1 != module_2) |
| 234 return false; | 230 return false; |
| 235 } | 231 } |
| 236 | 232 |
| 237 // Save the verified code | 233 // Save the verified code |
| 238 memcpy(local_thunk, &function_code, sizeof(function_code)); | 234 memcpy(local_thunk, &function_code, sizeof(function_code)); |
| 239 | 235 |
| 240 return true; | 236 return true; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 return false; | 411 return false; |
| 416 } | 412 } |
| 417 | 413 |
| 418 // Save the verified code | 414 // Save the verified code |
| 419 memcpy(local_thunk, &function_code, sizeof(function_code)); | 415 memcpy(local_thunk, &function_code, sizeof(function_code)); |
| 420 | 416 |
| 421 return true; | 417 return true; |
| 422 } | 418 } |
| 423 | 419 |
| 424 } // namespace sandbox | 420 } // namespace sandbox |
| OLD | NEW |