1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/win/src/sidestep_resolver.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +// Copyright (c) 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 +#ifndef SANDBOX_SRC_SIDESTEP_RESOLVER_H__ 1.9 +#define SANDBOX_SRC_SIDESTEP_RESOLVER_H__ 1.10 + 1.11 +#include "base/basictypes.h" 1.12 +#include "sandbox/win/src/nt_internals.h" 1.13 +#include "sandbox/win/src/resolver.h" 1.14 + 1.15 +namespace sandbox { 1.16 + 1.17 +// This is the concrete resolver used to perform sidestep interceptions. 1.18 +class SidestepResolverThunk : public ResolverThunk { 1.19 + public: 1.20 + SidestepResolverThunk() {} 1.21 + virtual ~SidestepResolverThunk() {} 1.22 + 1.23 + // Implementation of Resolver::Setup. 1.24 + virtual NTSTATUS Setup(const void* target_module, 1.25 + const void* interceptor_module, 1.26 + const char* target_name, 1.27 + const char* interceptor_name, 1.28 + const void* interceptor_entry_point, 1.29 + void* thunk_storage, 1.30 + size_t storage_bytes, 1.31 + size_t* storage_used); 1.32 + 1.33 + // Implementation of Resolver::GetThunkSize. 1.34 + virtual size_t GetThunkSize() const; 1.35 + 1.36 + private: 1.37 + DISALLOW_COPY_AND_ASSIGN(SidestepResolverThunk); 1.38 +}; 1.39 + 1.40 +// This is the concrete resolver used to perform smart sidestep interceptions. 1.41 +// This means basically a sidestep interception that skips the interceptor when 1.42 +// the caller resides on the same dll being intercepted. It is intended as 1.43 +// a helper only, because that determination is not infallible. 1.44 +class SmartSidestepResolverThunk : public SidestepResolverThunk { 1.45 + public: 1.46 + SmartSidestepResolverThunk() {} 1.47 + virtual ~SmartSidestepResolverThunk() {} 1.48 + 1.49 + // Implementation of Resolver::Setup. 1.50 + virtual NTSTATUS Setup(const void* target_module, 1.51 + const void* interceptor_module, 1.52 + const char* target_name, 1.53 + const char* interceptor_name, 1.54 + const void* interceptor_entry_point, 1.55 + void* thunk_storage, 1.56 + size_t storage_bytes, 1.57 + size_t* storage_used); 1.58 + 1.59 + // Implementation of Resolver::GetThunkSize. 1.60 + virtual size_t GetThunkSize() const; 1.61 + 1.62 + private: 1.63 + // Performs the actual call to the interceptor if the conditions are correct 1.64 + // (as determined by IsInternalCall). 1.65 + static void SmartStub(); 1.66 + 1.67 + // Returns true if return_address is inside the module loaded at base. 1.68 + static bool IsInternalCall(const void* base, void* return_address); 1.69 + 1.70 + DISALLOW_COPY_AND_ASSIGN(SmartSidestepResolverThunk); 1.71 +}; 1.72 + 1.73 +} // namespace sandbox 1.74 + 1.75 + 1.76 +#endif // SANDBOX_SRC_SIDESTEP_RESOLVER_H__