security/sandbox/win/src/service_resolver.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef SANDBOX_SRC_SERVICE_RESOLVER_H__
michael@0 6 #define SANDBOX_SRC_SERVICE_RESOLVER_H__
michael@0 7
michael@0 8 #include "sandbox/win/src/nt_internals.h"
michael@0 9 #include "sandbox/win/src/resolver.h"
michael@0 10
michael@0 11 namespace sandbox {
michael@0 12
michael@0 13 // This is the concrete resolver used to perform service-call type functions
michael@0 14 // inside ntdll.dll.
michael@0 15 class ServiceResolverThunk : public ResolverThunk {
michael@0 16 public:
michael@0 17 // The service resolver needs a child process to write to.
michael@0 18 ServiceResolverThunk(HANDLE process, bool relaxed)
michael@0 19 : process_(process), ntdll_base_(NULL), win2k_(false),
michael@0 20 relaxed_(relaxed), relative_jump_(0) {}
michael@0 21 virtual ~ServiceResolverThunk() {}
michael@0 22
michael@0 23 // Implementation of Resolver::Setup.
michael@0 24 virtual NTSTATUS Setup(const void* target_module,
michael@0 25 const void* interceptor_module,
michael@0 26 const char* target_name,
michael@0 27 const char* interceptor_name,
michael@0 28 const void* interceptor_entry_point,
michael@0 29 void* thunk_storage,
michael@0 30 size_t storage_bytes,
michael@0 31 size_t* storage_used);
michael@0 32
michael@0 33 // Implementation of Resolver::ResolveInterceptor.
michael@0 34 virtual NTSTATUS ResolveInterceptor(const void* module,
michael@0 35 const char* function_name,
michael@0 36 const void** address);
michael@0 37
michael@0 38 // Implementation of Resolver::ResolveTarget.
michael@0 39 virtual NTSTATUS ResolveTarget(const void* module,
michael@0 40 const char* function_name,
michael@0 41 void** address);
michael@0 42
michael@0 43 // Implementation of Resolver::GetThunkSize.
michael@0 44 virtual size_t GetThunkSize() const;
michael@0 45
michael@0 46 protected:
michael@0 47 // The unit test will use this member to allow local patch on a buffer.
michael@0 48 HMODULE ntdll_base_;
michael@0 49
michael@0 50 // Handle of the child process.
michael@0 51 HANDLE process_;
michael@0 52
michael@0 53 protected:
michael@0 54 // Keeps track of a Windows 2000 resolver.
michael@0 55 bool win2k_;
michael@0 56
michael@0 57 private:
michael@0 58 // Returns true if the code pointer by target_ corresponds to the expected
michael@0 59 // type of function. Saves that code on the first part of the thunk pointed
michael@0 60 // by local_thunk (should be directly accessible from the parent).
michael@0 61 virtual bool IsFunctionAService(void* local_thunk) const;
michael@0 62
michael@0 63 // Performs the actual patch of target_.
michael@0 64 // local_thunk must be already fully initialized, and the first part must
michael@0 65 // contain the original code. The real type of this buffer is ServiceFullThunk
michael@0 66 // (yes, private). remote_thunk (real type ServiceFullThunk), must be
michael@0 67 // allocated on the child, and will contain the thunk data, after this call.
michael@0 68 // Returns the apropriate status code.
michael@0 69 virtual NTSTATUS PerformPatch(void* local_thunk, void* remote_thunk);
michael@0 70
michael@0 71 // Provides basically the same functionality as IsFunctionAService but it
michael@0 72 // continues even if it does not recognize the function code. remote_thunk
michael@0 73 // is the address of our memory on the child.
michael@0 74 bool SaveOriginalFunction(void* local_thunk, void* remote_thunk);
michael@0 75
michael@0 76 // true if we are allowed to patch already-patched functions.
michael@0 77 bool relaxed_;
michael@0 78 ULONG relative_jump_;
michael@0 79
michael@0 80 DISALLOW_COPY_AND_ASSIGN(ServiceResolverThunk);
michael@0 81 };
michael@0 82
michael@0 83 // This is the concrete resolver used to perform service-call type functions
michael@0 84 // inside ntdll.dll on WOW64 (32 bit ntdll on 64 bit Vista).
michael@0 85 class Wow64ResolverThunk : public ServiceResolverThunk {
michael@0 86 public:
michael@0 87 // The service resolver needs a child process to write to.
michael@0 88 Wow64ResolverThunk(HANDLE process, bool relaxed)
michael@0 89 : ServiceResolverThunk(process, relaxed) {}
michael@0 90 virtual ~Wow64ResolverThunk() {}
michael@0 91
michael@0 92 private:
michael@0 93 virtual bool IsFunctionAService(void* local_thunk) const;
michael@0 94
michael@0 95 DISALLOW_COPY_AND_ASSIGN(Wow64ResolverThunk);
michael@0 96 };
michael@0 97
michael@0 98 // This is the concrete resolver used to perform service-call type functions
michael@0 99 // inside ntdll.dll on WOW64 for Windows 8.
michael@0 100 class Wow64W8ResolverThunk : public ServiceResolverThunk {
michael@0 101 public:
michael@0 102 // The service resolver needs a child process to write to.
michael@0 103 Wow64W8ResolverThunk(HANDLE process, bool relaxed)
michael@0 104 : ServiceResolverThunk(process, relaxed) {}
michael@0 105 virtual ~Wow64W8ResolverThunk() {}
michael@0 106
michael@0 107 private:
michael@0 108 virtual bool IsFunctionAService(void* local_thunk) const;
michael@0 109
michael@0 110 DISALLOW_COPY_AND_ASSIGN(Wow64W8ResolverThunk);
michael@0 111 };
michael@0 112
michael@0 113 // This is the concrete resolver used to perform service-call type functions
michael@0 114 // inside ntdll.dll on Windows 2000 and XP pre SP2.
michael@0 115 class Win2kResolverThunk : public ServiceResolverThunk {
michael@0 116 public:
michael@0 117 // The service resolver needs a child process to write to.
michael@0 118 Win2kResolverThunk(HANDLE process, bool relaxed)
michael@0 119 : ServiceResolverThunk(process, relaxed) {
michael@0 120 win2k_ = true;
michael@0 121 }
michael@0 122 virtual ~Win2kResolverThunk() {}
michael@0 123
michael@0 124 private:
michael@0 125 virtual bool IsFunctionAService(void* local_thunk) const;
michael@0 126
michael@0 127 DISALLOW_COPY_AND_ASSIGN(Win2kResolverThunk);
michael@0 128 };
michael@0 129
michael@0 130 // This is the concrete resolver used to perform service-call type functions
michael@0 131 // inside ntdll.dll on Windows 8.
michael@0 132 class Win8ResolverThunk : public ServiceResolverThunk {
michael@0 133 public:
michael@0 134 // The service resolver needs a child process to write to.
michael@0 135 Win8ResolverThunk(HANDLE process, bool relaxed)
michael@0 136 : ServiceResolverThunk(process, relaxed) {}
michael@0 137 virtual ~Win8ResolverThunk() {}
michael@0 138
michael@0 139 private:
michael@0 140 virtual bool IsFunctionAService(void* local_thunk) const;
michael@0 141
michael@0 142 DISALLOW_COPY_AND_ASSIGN(Win8ResolverThunk);
michael@0 143 };
michael@0 144
michael@0 145 } // namespace sandbox
michael@0 146
michael@0 147
michael@0 148 #endif // SANDBOX_SRC_SERVICE_RESOLVER_H__

mercurial