OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 // Utilities for windows process and threads stuff. | 5 // Utilities for windows process and threads stuff. |
6 | 6 |
7 #include "ceee/common/process_utils_win.h" | 7 #include "ceee/common/process_utils_win.h" |
8 | 8 |
9 #include <sddl.h> | 9 #include <sddl.h> |
10 | 10 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 ProcessCompatibilityCheck::ProcessCompatibilityCheck() | 124 ProcessCompatibilityCheck::ProcessCompatibilityCheck() |
125 : initialization_result_(E_FAIL), | 125 : initialization_result_(E_FAIL), |
126 running_on_amd64_platform_(false), | 126 running_on_amd64_platform_(false), |
127 running_as_wow_64_(false), | 127 running_as_wow_64_(false), |
128 integrity_checks_on_(false), | 128 integrity_checks_on_(false), |
129 running_integrity_(base::INTEGRITY_UNKNOWN) { | 129 running_integrity_(base::INTEGRITY_UNKNOWN) { |
130 StandardInitialize(); | 130 StandardInitialize(); |
131 } | 131 } |
132 | 132 |
| 133 // static |
| 134 ProcessCompatibilityCheck* ProcessCompatibilityCheck::GetInstance() { |
| 135 return Singleton<ProcessCompatibilityCheck>::get(); |
| 136 } |
| 137 |
133 void ProcessCompatibilityCheck::StandardInitialize() { | 138 void ProcessCompatibilityCheck::StandardInitialize() { |
134 HRESULT hr = S_OK; | 139 HRESULT hr = S_OK; |
135 | 140 |
136 SYSTEM_INFO system_info; | 141 SYSTEM_INFO system_info; |
137 ::GetNativeSystemInfo(&system_info); | 142 ::GetNativeSystemInfo(&system_info); |
138 | 143 |
139 bool system_with_integrity_checks = | 144 bool system_with_integrity_checks = |
140 base::win::GetVersion() >= base::win::VERSION_VISTA; | 145 base::win::GetVersion() >= base::win::VERSION_VISTA; |
141 | 146 |
142 base::IntegrityLevel integrity_level = base::INTEGRITY_UNKNOWN; | 147 base::IntegrityLevel integrity_level = base::INTEGRITY_UNKNOWN; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 DWORD process_id = 0; | 197 DWORD process_id = 0; |
193 if (::GetWindowThreadProcessId(process_window, &process_id) != 0) { | 198 if (::GetWindowThreadProcessId(process_window, &process_id) != 0) { |
194 return IsCompatible(process_id, is_compatible); | 199 return IsCompatible(process_id, is_compatible); |
195 } | 200 } |
196 | 201 |
197 return E_FAIL; | 202 return E_FAIL; |
198 } | 203 } |
199 | 204 |
200 HRESULT ProcessCompatibilityCheck::IsCompatible(DWORD process_id, | 205 HRESULT ProcessCompatibilityCheck::IsCompatible(DWORD process_id, |
201 bool* is_compatible) { | 206 bool* is_compatible) { |
202 ProcessCompatibilityCheck* instance | 207 ProcessCompatibilityCheck* instance = GetInstance(); |
203 = Singleton<ProcessCompatibilityCheck>::get(); | |
204 | 208 |
205 DCHECK(instance != NULL); | 209 DCHECK(instance != NULL); |
206 DCHECK(is_compatible != NULL); | 210 DCHECK(is_compatible != NULL); |
207 | 211 |
208 if (instance != NULL && SUCCEEDED(instance->initialization_result_)) { | 212 if (instance != NULL && SUCCEEDED(instance->initialization_result_)) { |
209 return instance->IsProcessCompatible(process_id, is_compatible); | 213 return instance->IsProcessCompatible(process_id, is_compatible); |
210 } | 214 } |
211 | 215 |
212 return instance != NULL ? instance->initialization_result_ : E_FAIL; | 216 return instance != NULL ? instance->initialization_result_ : E_FAIL; |
213 } | 217 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 // Patching affects both static pointers and the state of the sigleton. | 303 // Patching affects both static pointers and the state of the sigleton. |
300 // To update the later, required variables are forwarded to its | 304 // To update the later, required variables are forwarded to its |
301 // KnownStateInitialize. | 305 // KnownStateInitialize. |
302 void ProcessCompatibilityCheck::PatchState( | 306 void ProcessCompatibilityCheck::PatchState( |
303 WORD system_type, bool current_process_wow64, | 307 WORD system_type, bool current_process_wow64, |
304 bool check_integrity, base::IntegrityLevel current_process_integrity, | 308 bool check_integrity, base::IntegrityLevel current_process_integrity, |
305 OpenProcessFuncType open_process_func, | 309 OpenProcessFuncType open_process_func, |
306 CloseHandleFuncType close_handle_func, | 310 CloseHandleFuncType close_handle_func, |
307 IsWOW64ProcessFuncType is_wow64_process_func) { | 311 IsWOW64ProcessFuncType is_wow64_process_func) { |
308 PatchState(open_process_func, close_handle_func, is_wow64_process_func); | 312 PatchState(open_process_func, close_handle_func, is_wow64_process_func); |
309 Singleton<ProcessCompatibilityCheck>::get()->KnownStateInitialize( | 313 GetInstance()->KnownStateInitialize( |
310 system_type, current_process_wow64, | 314 system_type, current_process_wow64, |
311 check_integrity, current_process_integrity); | 315 check_integrity, current_process_integrity); |
312 } | 316 } |
313 | 317 |
314 void ProcessCompatibilityCheck::PatchState( | 318 void ProcessCompatibilityCheck::PatchState( |
315 OpenProcessFuncType open_process_func, | 319 OpenProcessFuncType open_process_func, |
316 CloseHandleFuncType close_handle_func, | 320 CloseHandleFuncType close_handle_func, |
317 IsWOW64ProcessFuncType is_wow64_process_func) { | 321 IsWOW64ProcessFuncType is_wow64_process_func) { |
318 open_process_func_ = open_process_func; | 322 open_process_func_ = open_process_func; |
319 close_handle_func_ = close_handle_func; | 323 close_handle_func_ = close_handle_func; |
320 is_wow64_process_func_ = is_wow64_process_func; | 324 is_wow64_process_func_ = is_wow64_process_func; |
321 DCHECK(open_process_func_ != NULL && close_handle_func_ != NULL && | 325 DCHECK(open_process_func_ != NULL && close_handle_func_ != NULL && |
322 is_wow64_process_func_ != NULL); | 326 is_wow64_process_func_ != NULL); |
323 } | 327 } |
324 | 328 |
325 void ProcessCompatibilityCheck::ResetState() { | 329 void ProcessCompatibilityCheck::ResetState() { |
326 PatchState(OpenProcess, CloseHandle, IsWow64Process); | 330 PatchState(OpenProcess, CloseHandle, IsWow64Process); |
327 Singleton<ProcessCompatibilityCheck>::get()->StandardInitialize(); | 331 GetInstance()->StandardInitialize(); |
328 } | 332 } |
329 | 333 |
330 } // namespace com | 334 } // namespace com |
OLD | NEW |