security/sandbox/win/src/resolver.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/win/src/resolver.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "sandbox/win/src/resolver.h"
     1.9 +
    1.10 +#include "base/win/pe_image.h"
    1.11 +#include "sandbox/win/src/sandbox_nt_util.h"
    1.12 +
    1.13 +namespace sandbox {
    1.14 +
    1.15 +NTSTATUS ResolverThunk::Init(const void* target_module,
    1.16 +                             const void* interceptor_module,
    1.17 +                             const char* target_name,
    1.18 +                             const char* interceptor_name,
    1.19 +                             const void* interceptor_entry_point,
    1.20 +                             void* thunk_storage,
    1.21 +                             size_t storage_bytes) {
    1.22 +  if (NULL == thunk_storage || 0 == storage_bytes ||
    1.23 +      NULL == target_module || NULL == target_name)
    1.24 +    return STATUS_INVALID_PARAMETER;
    1.25 +
    1.26 +  if (storage_bytes < GetThunkSize())
    1.27 +    return STATUS_BUFFER_TOO_SMALL;
    1.28 +
    1.29 +  NTSTATUS ret = STATUS_SUCCESS;
    1.30 +  if (NULL == interceptor_entry_point) {
    1.31 +    ret = ResolveInterceptor(interceptor_module, interceptor_name,
    1.32 +                             &interceptor_entry_point);
    1.33 +    if (!NT_SUCCESS(ret))
    1.34 +      return ret;
    1.35 +  }
    1.36 +
    1.37 +  ret = ResolveTarget(target_module, target_name, &target_);
    1.38 +  if (!NT_SUCCESS(ret))
    1.39 +    return ret;
    1.40 +
    1.41 +  interceptor_ = interceptor_entry_point;
    1.42 +
    1.43 +  return ret;
    1.44 +}
    1.45 +
    1.46 +NTSTATUS ResolverThunk::ResolveInterceptor(const void* interceptor_module,
    1.47 +                                           const char* interceptor_name,
    1.48 +                                           const void** address) {
    1.49 +  DCHECK_NT(address);
    1.50 +  if (!interceptor_module)
    1.51 +    return STATUS_INVALID_PARAMETER;
    1.52 +
    1.53 +  base::win::PEImage pe(interceptor_module);
    1.54 +  if (!pe.VerifyMagic())
    1.55 +    return STATUS_INVALID_IMAGE_FORMAT;
    1.56 +
    1.57 +  *address = pe.GetProcAddress(interceptor_name);
    1.58 +
    1.59 +  if (!(*address))
    1.60 +    return STATUS_PROCEDURE_NOT_FOUND;
    1.61 +
    1.62 +  return STATUS_SUCCESS;
    1.63 +}
    1.64 +
    1.65 +}  // namespace sandbox

mercurial