OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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/eat_resolver.h" | 5 #include "sandbox/win/src/eat_resolver.h" |
6 | 6 |
7 #include "base/win/pe_image.h" | 7 #include "base/win/pe_image.h" |
8 #include "sandbox/win/src/sandbox_nt_util.h" | 8 #include "sandbox/win/src/sandbox_nt_util.h" |
9 | 9 |
10 namespace sandbox { | 10 namespace sandbox { |
11 | 11 |
12 NTSTATUS EatResolverThunk::Setup(const void* target_module, | 12 NTSTATUS EatResolverThunk::Setup(const void* target_module, |
13 const void* interceptor_module, | 13 const void* interceptor_module, |
14 const char* target_name, | 14 const char* target_name, |
15 const char* interceptor_name, | 15 const char* interceptor_name, |
16 const void* interceptor_entry_point, | 16 const void* interceptor_entry_point, |
17 void* thunk_storage, | 17 void* thunk_storage, |
18 size_t storage_bytes, | 18 size_t storage_bytes, |
19 size_t* storage_used) { | 19 size_t* storage_used) { |
20 NTSTATUS ret = Init(target_module, interceptor_module, target_name, | 20 NTSTATUS ret = Init(target_module, interceptor_module, target_name, |
21 interceptor_name, interceptor_entry_point, | 21 interceptor_name, interceptor_entry_point, |
22 thunk_storage, storage_bytes); | 22 thunk_storage, storage_bytes); |
23 if (!NT_SUCCESS(ret)) | 23 if (!NT_SUCCESS(ret)) |
24 return ret; | 24 return ret; |
25 | 25 |
26 if (!eat_entry_) | 26 if (!eat_entry_) |
27 return STATUS_INVALID_PARAMETER; | 27 return STATUS_INVALID_PARAMETER; |
28 | 28 |
29 size_t thunk_bytes = GetInternalThunkSize(); | |
30 | |
31 #if defined(_WIN64) | 29 #if defined(_WIN64) |
32 // We have two thunks, in order: the return path and the forward path. | 30 // We have two thunks, in order: the return path and the forward path. |
33 if (!SetInternalThunk(thunk_storage, storage_bytes, NULL, target_)) | 31 if (!SetInternalThunk(thunk_storage, storage_bytes, NULL, target_)) |
34 return STATUS_BUFFER_TOO_SMALL; | 32 return STATUS_BUFFER_TOO_SMALL; |
35 | 33 |
| 34 size_t thunk_bytes = GetInternalThunkSize(); |
36 storage_bytes -= thunk_bytes; | 35 storage_bytes -= thunk_bytes; |
37 thunk_storage = reinterpret_cast<char*>(thunk_storage) + thunk_bytes; | 36 thunk_storage = reinterpret_cast<char*>(thunk_storage) + thunk_bytes; |
38 #endif | 37 #endif |
39 | 38 |
40 if (!SetInternalThunk(thunk_storage, storage_bytes, target_, interceptor_)) | 39 if (!SetInternalThunk(thunk_storage, storage_bytes, target_, interceptor_)) |
41 return STATUS_BUFFER_TOO_SMALL; | 40 return STATUS_BUFFER_TOO_SMALL; |
42 | 41 |
43 AutoProtectMemory memory; | 42 AutoProtectMemory memory; |
44 ret = memory.ChangeProtection(eat_entry_, sizeof(DWORD), PAGE_READWRITE); | 43 ret = memory.ChangeProtection(eat_entry_, sizeof(DWORD), PAGE_READWRITE); |
45 if (!NT_SUCCESS(ret)) | 44 if (!NT_SUCCESS(ret)) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 81 |
83 size_t EatResolverThunk::GetThunkSize() const { | 82 size_t EatResolverThunk::GetThunkSize() const { |
84 #if defined(_WIN64) | 83 #if defined(_WIN64) |
85 return GetInternalThunkSize() * 2; | 84 return GetInternalThunkSize() * 2; |
86 #else | 85 #else |
87 return GetInternalThunkSize(); | 86 return GetInternalThunkSize(); |
88 #endif | 87 #endif |
89 } | 88 } |
90 | 89 |
91 } // namespace sandbox | 90 } // namespace sandbox |
OLD | NEW |