Home | History | Annotate | Download | only in src
      1 // Copyright (c) 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 #ifndef SANDBOX_SRC_SIDESTEP_RESOLVER_H__
      6 #define SANDBOX_SRC_SIDESTEP_RESOLVER_H__
      7 
      8 #include "base/basictypes.h"
      9 #include "sandbox/win/src/nt_internals.h"
     10 #include "sandbox/win/src/resolver.h"
     11 
     12 namespace sandbox {
     13 
     14 // This is the concrete resolver used to perform sidestep interceptions.
     15 class SidestepResolverThunk : public ResolverThunk {
     16  public:
     17   SidestepResolverThunk() {}
     18   virtual ~SidestepResolverThunk() {}
     19 
     20   // Implementation of Resolver::Setup.
     21   virtual NTSTATUS Setup(const void* target_module,
     22                          const void* interceptor_module,
     23                          const char* target_name,
     24                          const char* interceptor_name,
     25                          const void* interceptor_entry_point,
     26                          void* thunk_storage,
     27                          size_t storage_bytes,
     28                          size_t* storage_used);
     29 
     30   // Implementation of Resolver::GetThunkSize.
     31   virtual size_t GetThunkSize() const;
     32 
     33  private:
     34   DISALLOW_COPY_AND_ASSIGN(SidestepResolverThunk);
     35 };
     36 
     37 // This is the concrete resolver used to perform smart sidestep interceptions.
     38 // This means basically a sidestep interception that skips the interceptor when
     39 // the caller resides on the same dll being intercepted. It is intended as
     40 // a helper only, because that determination is not infallible.
     41 class SmartSidestepResolverThunk : public SidestepResolverThunk {
     42  public:
     43   SmartSidestepResolverThunk() {}
     44   virtual ~SmartSidestepResolverThunk() {}
     45 
     46   // Implementation of Resolver::Setup.
     47   virtual NTSTATUS Setup(const void* target_module,
     48                          const void* interceptor_module,
     49                          const char* target_name,
     50                          const char* interceptor_name,
     51                          const void* interceptor_entry_point,
     52                          void* thunk_storage,
     53                          size_t storage_bytes,
     54                          size_t* storage_used);
     55 
     56   // Implementation of Resolver::GetThunkSize.
     57   virtual size_t GetThunkSize() const;
     58 
     59  private:
     60   // Performs the actual call to the interceptor if the conditions are correct
     61   // (as determined by IsInternalCall).
     62   static void SmartStub();
     63 
     64   // Returns true if return_address is inside the module loaded at base.
     65   static bool IsInternalCall(const void* base, void* return_address);
     66 
     67   DISALLOW_COPY_AND_ASSIGN(SmartSidestepResolverThunk);
     68 };
     69 
     70 }  // namespace sandbox
     71 
     72 
     73 #endif  // SANDBOX_SRC_SIDESTEP_RESOLVER_H__
     74