OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <map> | 5 #include <map> |
6 | 6 |
7 #include "sandbox/win/src/policy_broker.h" | 7 #include "sandbox/win/src/policy_broker.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/win/pe_image.h" | 10 #include "base/win/pe_image.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 ntdll_image.GetProcAddress("Nt" #member)); \ | 31 ntdll_image.GetProcAddress("Nt" #member)); \ |
32 if (NULL == g_nt.member) \ | 32 if (NULL == g_nt.member) \ |
33 return false | 33 return false |
34 | 34 |
35 #define INIT_GLOBAL_RTL(member) \ | 35 #define INIT_GLOBAL_RTL(member) \ |
36 g_nt.member = reinterpret_cast<member##Function>( \ | 36 g_nt.member = reinterpret_cast<member##Function>( \ |
37 ntdll_image.GetProcAddress(#member)); \ | 37 ntdll_image.GetProcAddress(#member)); \ |
38 if (NULL == g_nt.member) \ | 38 if (NULL == g_nt.member) \ |
39 return false | 39 return false |
40 | 40 |
41 bool SetupNtdllImports(TargetProcess *child) { | 41 bool InitGlobalNt() { |
42 HMODULE ntdll = ::GetModuleHandle(kNtdllName); | 42 HMODULE ntdll = ::GetModuleHandle(kNtdllName); |
43 base::win::PEImage ntdll_image(ntdll); | 43 base::win::PEImage ntdll_image(ntdll); |
44 | 44 |
45 // Bypass purify's interception. | 45 // Bypass purify's interception. |
46 wchar_t* loader_get = reinterpret_cast<wchar_t*>( | 46 wchar_t* loader_get = reinterpret_cast<wchar_t*>( |
47 ntdll_image.GetProcAddress("LdrGetDllHandle")); | 47 ntdll_image.GetProcAddress("LdrGetDllHandle")); |
48 if (loader_get) { | 48 if (loader_get) { |
49 GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | | 49 GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | |
50 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, | 50 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, |
51 loader_get, &ntdll); | 51 loader_get, &ntdll); |
(...skipping 16 matching lines...) Expand all Loading... |
68 INIT_GLOBAL_RTL(RtlCompareUnicodeString); | 68 INIT_GLOBAL_RTL(RtlCompareUnicodeString); |
69 INIT_GLOBAL_RTL(RtlCreateHeap); | 69 INIT_GLOBAL_RTL(RtlCreateHeap); |
70 INIT_GLOBAL_RTL(RtlCreateUserThread); | 70 INIT_GLOBAL_RTL(RtlCreateUserThread); |
71 INIT_GLOBAL_RTL(RtlDestroyHeap); | 71 INIT_GLOBAL_RTL(RtlDestroyHeap); |
72 INIT_GLOBAL_RTL(RtlFreeHeap); | 72 INIT_GLOBAL_RTL(RtlFreeHeap); |
73 INIT_GLOBAL_RTL(_strnicmp); | 73 INIT_GLOBAL_RTL(_strnicmp); |
74 INIT_GLOBAL_RTL(strlen); | 74 INIT_GLOBAL_RTL(strlen); |
75 INIT_GLOBAL_RTL(wcslen); | 75 INIT_GLOBAL_RTL(wcslen); |
76 INIT_GLOBAL_RTL(memcpy); | 76 INIT_GLOBAL_RTL(memcpy); |
77 | 77 |
| 78 return true; |
| 79 } |
| 80 |
| 81 bool SetupNtdllImports(TargetProcess *child) { |
| 82 if (!InitGlobalNt()) { |
| 83 return false; |
| 84 } |
| 85 |
78 #ifndef NDEBUG | 86 #ifndef NDEBUG |
79 // Verify that the structure is fully initialized. | 87 // Verify that the structure is fully initialized. |
80 for (size_t i = 0; i < sizeof(g_nt)/sizeof(void*); i++) | 88 for (size_t i = 0; i < sizeof(g_nt)/sizeof(void*); i++) |
81 DCHECK(reinterpret_cast<char**>(&g_nt)[i]); | 89 DCHECK(reinterpret_cast<char**>(&g_nt)[i]); |
82 #endif | 90 #endif |
83 return (SBOX_ALL_OK == child->TransferVariable("g_nt", &g_nt, sizeof(g_nt))); | 91 return (SBOX_ALL_OK == child->TransferVariable("g_nt", &g_nt, sizeof(g_nt))); |
84 } | 92 } |
85 | 93 |
86 #undef INIT_GLOBAL_NT | 94 #undef INIT_GLOBAL_NT |
87 #undef INIT_GLOBAL_RTL | 95 #undef INIT_GLOBAL_RTL |
(...skipping 19 matching lines...) Expand all Loading... |
107 return false; | 115 return false; |
108 | 116 |
109 return INTERCEPT_NT(manager, NtOpenThreadTokenEx, OPEN_THREAD_TOKEN_EX_ID, | 117 return INTERCEPT_NT(manager, NtOpenThreadTokenEx, OPEN_THREAD_TOKEN_EX_ID, |
110 24); | 118 24); |
111 } | 119 } |
112 | 120 |
113 return true; | 121 return true; |
114 } | 122 } |
115 | 123 |
116 } // namespace sandbox | 124 } // namespace sandbox |
OLD | NEW |