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/win_utils.h" | 8 #include "sandbox/win/src/win_utils.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 if (NULL != storage_used) | 172 if (NULL != storage_used) |
173 *storage_used = thunk_bytes; | 173 *storage_used = thunk_bytes; |
174 | 174 |
175 return ret; | 175 return ret; |
176 } | 176 } |
177 | 177 |
178 size_t ServiceResolverThunk::GetThunkSize() const { | 178 size_t ServiceResolverThunk::GetThunkSize() const { |
179 return offsetof(ServiceFullThunk, internal_thunk) + GetInternalThunkSize(); | 179 return offsetof(ServiceFullThunk, internal_thunk) + GetInternalThunkSize(); |
180 } | 180 } |
181 | 181 |
| 182 NTSTATUS ServiceResolverThunk::CopyThunk(const void* target_module, |
| 183 const char* target_name, |
| 184 BYTE* thunk_storage, |
| 185 size_t storage_bytes, |
| 186 size_t* storage_used) { |
| 187 NTSTATUS ret = ResolveTarget(target_module, target_name, &target_); |
| 188 if (!NT_SUCCESS(ret)) |
| 189 return ret; |
| 190 |
| 191 size_t thunk_bytes = GetThunkSize(); |
| 192 if (storage_bytes < thunk_bytes) |
| 193 return STATUS_UNSUCCESSFUL; |
| 194 |
| 195 ServiceFullThunk* thunk = reinterpret_cast<ServiceFullThunk*>(thunk_storage); |
| 196 |
| 197 if (!IsFunctionAService(&thunk->original) && |
| 198 (!relaxed_ || !SaveOriginalFunction(&thunk->original, thunk_storage))) { |
| 199 return STATUS_UNSUCCESSFUL; |
| 200 } |
| 201 |
| 202 if (NULL != storage_used) |
| 203 *storage_used = thunk_bytes; |
| 204 |
| 205 return ret; |
| 206 } |
| 207 |
182 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const { | 208 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const { |
183 ServiceEntry function_code; | 209 ServiceEntry function_code; |
184 SIZE_T read; | 210 SIZE_T read; |
185 if (!::ReadProcessMemory(process_, target_, &function_code, | 211 if (!::ReadProcessMemory(process_, target_, &function_code, |
186 sizeof(function_code), &read)) | 212 sizeof(function_code), &read)) |
187 return false; | 213 return false; |
188 | 214 |
189 if (sizeof(function_code) != read) | 215 if (sizeof(function_code) != read) |
190 return false; | 216 return false; |
191 | 217 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 return false; | 437 return false; |
412 } | 438 } |
413 | 439 |
414 // Save the verified code | 440 // Save the verified code |
415 memcpy(local_thunk, &function_code, sizeof(function_code)); | 441 memcpy(local_thunk, &function_code, sizeof(function_code)); |
416 | 442 |
417 return true; | 443 return true; |
418 } | 444 } |
419 | 445 |
420 } // namespace sandbox | 446 } // namespace sandbox |
OLD | NEW |