Wed, 31 Dec 2014 06:09:35 +0100
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) 2006-2008 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 | // Defines InterceptionAgent, the class in charge of setting up interceptions |
michael@0 | 6 | // from the inside of the sandboxed process. For more details see |
michael@0 | 7 | // http://dev.chromium.org/developers/design-documents/sandbox . |
michael@0 | 8 | |
michael@0 | 9 | #ifndef SANDBOX_SRC_INTERCEPTION_AGENT_H__ |
michael@0 | 10 | #define SANDBOX_SRC_INTERCEPTION_AGENT_H__ |
michael@0 | 11 | |
michael@0 | 12 | #include "base/basictypes.h" |
michael@0 | 13 | #include "sandbox/win/src/nt_internals.h" |
michael@0 | 14 | #include "sandbox/win/src/sandbox_types.h" |
michael@0 | 15 | |
michael@0 | 16 | namespace sandbox { |
michael@0 | 17 | |
michael@0 | 18 | // Internal structures used for communication between the broker and the target. |
michael@0 | 19 | struct DllInterceptionData; |
michael@0 | 20 | struct SharedMemory; |
michael@0 | 21 | struct DllPatchInfo; |
michael@0 | 22 | |
michael@0 | 23 | class ResolverThunk; |
michael@0 | 24 | |
michael@0 | 25 | // The InterceptionAgent executes on the target application, and it is in charge |
michael@0 | 26 | // of setting up the desired interceptions or indicating what module needs to |
michael@0 | 27 | // be unloaded. |
michael@0 | 28 | // |
michael@0 | 29 | // The exposed API consists of three methods: GetInterceptionAgent to retrieve |
michael@0 | 30 | // the single class instance, OnDllLoad and OnDllUnload to process a dll being |
michael@0 | 31 | // loaded and unloaded respectively. |
michael@0 | 32 | // |
michael@0 | 33 | // This class assumes that it will get called for every dll being loaded, |
michael@0 | 34 | // starting with kernel32, so the singleton will be instantiated from within the |
michael@0 | 35 | // loader lock. |
michael@0 | 36 | class InterceptionAgent { |
michael@0 | 37 | public: |
michael@0 | 38 | // Returns the single InterceptionAgent object for this process. |
michael@0 | 39 | static InterceptionAgent* GetInterceptionAgent(); |
michael@0 | 40 | |
michael@0 | 41 | // This method should be invoked whenever a new dll is loaded to perform the |
michael@0 | 42 | // required patches. If the return value is false, this dll should not be |
michael@0 | 43 | // allowed to load. |
michael@0 | 44 | // |
michael@0 | 45 | // full_path is the (optional) full name of the module being loaded and name |
michael@0 | 46 | // is the internal module name. If full_path is provided, it will be used |
michael@0 | 47 | // before the internal name to determine if we care about this dll. |
michael@0 | 48 | bool OnDllLoad(const UNICODE_STRING* full_path, const UNICODE_STRING* name, |
michael@0 | 49 | void* base_address); |
michael@0 | 50 | |
michael@0 | 51 | // Performs cleanup when a dll is unloaded. |
michael@0 | 52 | void OnDllUnload(void* base_address); |
michael@0 | 53 | |
michael@0 | 54 | private: |
michael@0 | 55 | ~InterceptionAgent() {} |
michael@0 | 56 | |
michael@0 | 57 | // Performs initialization of the singleton. |
michael@0 | 58 | bool Init(SharedMemory* shared_memory); |
michael@0 | 59 | |
michael@0 | 60 | // Returns true if we are interested on this dll. dll_info is an entry of the |
michael@0 | 61 | // list of intercepted dlls. |
michael@0 | 62 | bool DllMatch(const UNICODE_STRING* full_path, const UNICODE_STRING* name, |
michael@0 | 63 | const DllPatchInfo* dll_info); |
michael@0 | 64 | |
michael@0 | 65 | // Performs the patching of the dll loaded at base_address. |
michael@0 | 66 | // The patches to perform are described on dll_info, and thunks is the thunk |
michael@0 | 67 | // storage for the whole dll. |
michael@0 | 68 | // Returns true on success. |
michael@0 | 69 | bool PatchDll(const DllPatchInfo* dll_info, DllInterceptionData* thunks); |
michael@0 | 70 | |
michael@0 | 71 | // Returns a resolver for a given interception type. |
michael@0 | 72 | ResolverThunk* GetResolver(InterceptionType type); |
michael@0 | 73 | |
michael@0 | 74 | // Shared memory containing the list of functions to intercept. |
michael@0 | 75 | SharedMemory* interceptions_; |
michael@0 | 76 | |
michael@0 | 77 | // Array of thunk data buffers for the intercepted dlls. This object singleton |
michael@0 | 78 | // is allocated with a placement new with enough space to hold the complete |
michael@0 | 79 | // array of pointers, not just the first element. |
michael@0 | 80 | DllInterceptionData* dlls_[1]; |
michael@0 | 81 | |
michael@0 | 82 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptionAgent); |
michael@0 | 83 | }; |
michael@0 | 84 | |
michael@0 | 85 | } // namespace sandbox |
michael@0 | 86 | |
michael@0 | 87 | #endif // SANDBOX_SRC_INTERCEPTION_AGENT_H__ |