OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "sandbox/src/sandbox_utils.h" | 5 #include "sandbox/src/sandbox_utils.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/win/windows_version.h" | |
10 #include "sandbox/src/internal_types.h" | 11 #include "sandbox/src/internal_types.h" |
11 #include "sandbox/src/nt_internals.h" | 12 #include "sandbox/src/nt_internals.h" |
12 | 13 |
13 namespace sandbox { | 14 namespace sandbox { |
14 | 15 |
15 bool GetModuleHandleHelper(DWORD flags, const wchar_t* module_name, | 16 bool GetModuleHandleHelper(DWORD flags, const wchar_t* module_name, |
16 HMODULE* module) { | 17 HMODULE* module) { |
17 DCHECK(module); | 18 DCHECK(module); |
18 | 19 |
19 HMODULE kernel32_base = ::GetModuleHandle(kKerneldllName); | 20 HMODULE kernel32_base = ::GetModuleHandle(kKerneldllName); |
(...skipping 29 matching lines...) Expand all Loading... | |
49 MEMORY_BASIC_INFORMATION info = {0}; | 50 MEMORY_BASIC_INFORMATION info = {0}; |
50 size_t returned = VirtualQuery(module_name, &info, sizeof(info)); | 51 size_t returned = VirtualQuery(module_name, &info, sizeof(info)); |
51 if (sizeof(info) != returned) | 52 if (sizeof(info) != returned) |
52 return false; | 53 return false; |
53 *module = reinterpret_cast<HMODULE>(info.AllocationBase); | 54 *module = reinterpret_cast<HMODULE>(info.AllocationBase); |
54 } | 55 } |
55 return true; | 56 return true; |
56 } | 57 } |
57 | 58 |
58 bool IsXPSP2OrLater() { | 59 bool IsXPSP2OrLater() { |
59 OSVERSIONINFOEX version = {0}; | 60 base::win::Version version = base::win::GetVersion(); |
60 version.dwOSVersionInfoSize = sizeof(version); | 61 return (version > base::win::VERSION_XP) || |
61 if (!::GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version))) { | 62 ((version == base::win::VERSION_XP) && |
rvargas (doing something else)
2011/04/06 23:28:05
nit: I think this should be indented like an if (u
Peter Kasting
2011/04/07 00:29:19
ifs are indent-4 too. It coincidentally happens t
| |
62 NOTREACHED(); | 63 (base::win::OSInfo::GetInstance()->service_pack()[0] >= 2)); |
63 return false; | |
64 } | |
65 | |
66 // Vista or later | |
67 if (version.dwMajorVersion > 5) | |
68 return true; | |
69 | |
70 // 2k, xp or 2003 | |
71 if (version.dwMajorVersion == 5) { | |
72 // 2003 | |
73 if (version.dwMinorVersion > 1) | |
74 return true; | |
75 | |
76 // 2000 | |
77 if (version.dwMinorVersion == 0) | |
78 return false; | |
79 | |
80 // Windows Xp Sp2 or later | |
81 if (version.wServicePackMajor >= 2) | |
82 return true; | |
83 } | |
84 | |
85 return false; | |
86 } | 64 } |
87 | 65 |
88 void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root, | 66 void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root, |
89 OBJECT_ATTRIBUTES* obj_attr, UNICODE_STRING* uni_name) { | 67 OBJECT_ATTRIBUTES* obj_attr, UNICODE_STRING* uni_name) { |
90 static RtlInitUnicodeStringFunction RtlInitUnicodeString; | 68 static RtlInitUnicodeStringFunction RtlInitUnicodeString; |
91 if (!RtlInitUnicodeString) { | 69 if (!RtlInitUnicodeString) { |
92 HMODULE ntdll = ::GetModuleHandle(kNtdllName); | 70 HMODULE ntdll = ::GetModuleHandle(kNtdllName); |
93 RtlInitUnicodeString = reinterpret_cast<RtlInitUnicodeStringFunction>( | 71 RtlInitUnicodeString = reinterpret_cast<RtlInitUnicodeStringFunction>( |
94 GetProcAddress(ntdll, "RtlInitUnicodeString")); | 72 GetProcAddress(ntdll, "RtlInitUnicodeString")); |
95 DCHECK(RtlInitUnicodeString); | 73 DCHECK(RtlInitUnicodeString); |
(...skipping 13 matching lines...) Expand all Loading... | |
109 return std::string(); | 87 return std::string(); |
110 | 88 |
111 std::string mb; | 89 std::string mb; |
112 WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, | 90 WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, |
113 WriteInto(&mb, charcount), charcount, NULL, NULL); | 91 WriteInto(&mb, charcount), charcount, NULL, NULL); |
114 | 92 |
115 return mb; | 93 return mb; |
116 } | 94 } |
117 | 95 |
118 }; // namespace sandbox | 96 }; // namespace sandbox |
OLD | NEW |