| 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 | |
| 208 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const { | 182 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const { |
| 209 ServiceEntry function_code; | 183 ServiceEntry function_code; |
| 210 SIZE_T read; | 184 SIZE_T read; |
| 211 if (!::ReadProcessMemory(process_, target_, &function_code, | 185 if (!::ReadProcessMemory(process_, target_, &function_code, |
| 212 sizeof(function_code), &read)) | 186 sizeof(function_code), &read)) |
| 213 return false; | 187 return false; |
| 214 | 188 |
| 215 if (sizeof(function_code) != read) | 189 if (sizeof(function_code) != read) |
| 216 return false; | 190 return false; |
| 217 | 191 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 return false; | 411 return false; |
| 438 } | 412 } |
| 439 | 413 |
| 440 // Save the verified code | 414 // Save the verified code |
| 441 memcpy(local_thunk, &function_code, sizeof(function_code)); | 415 memcpy(local_thunk, &function_code, sizeof(function_code)); |
| 442 | 416 |
| 443 return true; | 417 return true; |
| 444 } | 418 } |
| 445 | 419 |
| 446 } // namespace sandbox | 420 } // namespace sandbox |
| OLD | NEW |