| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sandbox/win/src/resolver.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "base/win/pe_image.h" | |
| 10 #include "sandbox/win/src/sandbox_nt_util.h" | |
| 11 | |
| 12 namespace sandbox { | |
| 13 | |
| 14 NTSTATUS ResolverThunk::Init(const void* target_module, | |
| 15 const void* interceptor_module, | |
| 16 const char* target_name, | |
| 17 const char* interceptor_name, | |
| 18 const void* interceptor_entry_point, | |
| 19 void* thunk_storage, | |
| 20 size_t storage_bytes) { | |
| 21 if (NULL == thunk_storage || 0 == storage_bytes || | |
| 22 NULL == target_module || NULL == target_name) | |
| 23 return STATUS_INVALID_PARAMETER; | |
| 24 | |
| 25 if (storage_bytes < GetThunkSize()) | |
| 26 return STATUS_BUFFER_TOO_SMALL; | |
| 27 | |
| 28 NTSTATUS ret = STATUS_SUCCESS; | |
| 29 if (NULL == interceptor_entry_point) { | |
| 30 ret = ResolveInterceptor(interceptor_module, interceptor_name, | |
| 31 &interceptor_entry_point); | |
| 32 if (!NT_SUCCESS(ret)) | |
| 33 return ret; | |
| 34 } | |
| 35 | |
| 36 ret = ResolveTarget(target_module, target_name, &target_); | |
| 37 if (!NT_SUCCESS(ret)) | |
| 38 return ret; | |
| 39 | |
| 40 interceptor_ = interceptor_entry_point; | |
| 41 | |
| 42 return ret; | |
| 43 } | |
| 44 | |
| 45 NTSTATUS ResolverThunk::ResolveInterceptor(const void* interceptor_module, | |
| 46 const char* interceptor_name, | |
| 47 const void** address) { | |
| 48 DCHECK_NT(address); | |
| 49 if (!interceptor_module) | |
| 50 return STATUS_INVALID_PARAMETER; | |
| 51 | |
| 52 base::win::PEImage pe(interceptor_module); | |
| 53 if (!pe.VerifyMagic()) | |
| 54 return STATUS_INVALID_IMAGE_FORMAT; | |
| 55 | |
| 56 *address = pe.GetProcAddress(interceptor_name); | |
| 57 | |
| 58 if (!(*address)) | |
| 59 return STATUS_PROCEDURE_NOT_FOUND; | |
| 60 | |
| 61 return STATUS_SUCCESS; | |
| 62 } | |
| 63 | |
| 64 } // namespace sandbox | |
| OLD | NEW |