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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "base/bit_cast.h" | 11 #include "base/bit_cast.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "sandbox/win/src/win_utils.h" | 12 #include "sandbox/win/src/win_utils.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 #pragma pack(push, 1) | 15 #pragma pack(push, 1) |
15 | 16 |
16 const BYTE kMovEax = 0xB8; | 17 const BYTE kMovEax = 0xB8; |
17 const BYTE kMovEdx = 0xBA; | 18 const BYTE kMovEdx = 0xBA; |
18 const USHORT kMovEdxEsp = 0xD48B; | 19 const USHORT kMovEdxEsp = 0xD48B; |
19 const USHORT kCallPtrEdx = 0x12FF; | 20 const USHORT kCallPtrEdx = 0x12FF; |
20 const USHORT kCallEdx = 0xD2FF; | 21 const USHORT kCallEdx = 0xD2FF; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 size_t storage_bytes, | 169 size_t storage_bytes, |
169 size_t* storage_used) { | 170 size_t* storage_used) { |
170 NTSTATUS ret = Init(target_module, interceptor_module, target_name, | 171 NTSTATUS ret = Init(target_module, interceptor_module, target_name, |
171 interceptor_name, interceptor_entry_point, | 172 interceptor_name, interceptor_entry_point, |
172 thunk_storage, storage_bytes); | 173 thunk_storage, storage_bytes); |
173 if (!NT_SUCCESS(ret)) | 174 if (!NT_SUCCESS(ret)) |
174 return ret; | 175 return ret; |
175 | 176 |
176 relative_jump_ = 0; | 177 relative_jump_ = 0; |
177 size_t thunk_bytes = GetThunkSize(); | 178 size_t thunk_bytes = GetThunkSize(); |
178 scoped_ptr<char[]> thunk_buffer(new char[thunk_bytes]); | 179 std::unique_ptr<char[]> thunk_buffer(new char[thunk_bytes]); |
179 ServiceFullThunk* thunk = reinterpret_cast<ServiceFullThunk*>( | 180 ServiceFullThunk* thunk = reinterpret_cast<ServiceFullThunk*>( |
180 thunk_buffer.get()); | 181 thunk_buffer.get()); |
181 | 182 |
182 if (!IsFunctionAService(&thunk->original) && | 183 if (!IsFunctionAService(&thunk->original) && |
183 (!relaxed_ || !SaveOriginalFunction(&thunk->original, thunk_storage))) { | 184 (!relaxed_ || !SaveOriginalFunction(&thunk->original, thunk_storage))) { |
184 return STATUS_UNSUCCESSFUL; | 185 return STATUS_UNSUCCESSFUL; |
185 } | 186 } |
186 | 187 |
187 ret = PerformPatch(thunk, thunk_storage); | 188 ret = PerformPatch(thunk, thunk_storage); |
188 | 189 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 kRet != function_code.ret) { | 470 kRet != function_code.ret) { |
470 return false; | 471 return false; |
471 } | 472 } |
472 | 473 |
473 // Save the verified code | 474 // Save the verified code |
474 memcpy(local_thunk, &function_code, sizeof(function_code)); | 475 memcpy(local_thunk, &function_code, sizeof(function_code)); |
475 return true; | 476 return true; |
476 } | 477 } |
477 | 478 |
478 } // namespace sandbox | 479 } // namespace sandbox |
OLD | NEW |