OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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" | |
11 #include "sandbox/src/internal_types.h" | 10 #include "sandbox/src/internal_types.h" |
12 #include "sandbox/src/nt_internals.h" | 11 #include "sandbox/src/nt_internals.h" |
13 | 12 |
14 namespace sandbox { | 13 namespace sandbox { |
15 | 14 |
16 bool GetModuleHandleHelper(DWORD flags, const wchar_t* module_name, | 15 bool GetModuleHandleHelper(DWORD flags, const wchar_t* module_name, |
17 HMODULE* module) { | 16 HMODULE* module) { |
18 DCHECK(module); | 17 DCHECK(module); |
19 | 18 |
20 HMODULE kernel32_base = ::GetModuleHandle(kKerneldllName); | 19 HMODULE kernel32_base = ::GetModuleHandle(kKerneldllName); |
(...skipping 29 matching lines...) Expand all Loading... |
50 MEMORY_BASIC_INFORMATION info = {0}; | 49 MEMORY_BASIC_INFORMATION info = {0}; |
51 size_t returned = VirtualQuery(module_name, &info, sizeof(info)); | 50 size_t returned = VirtualQuery(module_name, &info, sizeof(info)); |
52 if (sizeof(info) != returned) | 51 if (sizeof(info) != returned) |
53 return false; | 52 return false; |
54 *module = reinterpret_cast<HMODULE>(info.AllocationBase); | 53 *module = reinterpret_cast<HMODULE>(info.AllocationBase); |
55 } | 54 } |
56 return true; | 55 return true; |
57 } | 56 } |
58 | 57 |
59 bool IsXPSP2OrLater() { | 58 bool IsXPSP2OrLater() { |
60 base::win::Version version = base::win::GetVersion(); | 59 OSVERSIONINFOEX version = {0}; |
61 return (version > base::win::VERSION_XP) || | 60 version.dwOSVersionInfoSize = sizeof(version); |
62 ((version == base::win::VERSION_XP) && | 61 if (!::GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version))) { |
63 (base::win::OSInfo::GetInstance()->service_pack().major >= 2)); | 62 NOTREACHED(); |
| 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; |
64 } | 86 } |
65 | 87 |
66 void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root, | 88 void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root, |
67 OBJECT_ATTRIBUTES* obj_attr, UNICODE_STRING* uni_name) { | 89 OBJECT_ATTRIBUTES* obj_attr, UNICODE_STRING* uni_name) { |
68 static RtlInitUnicodeStringFunction RtlInitUnicodeString; | 90 static RtlInitUnicodeStringFunction RtlInitUnicodeString; |
69 if (!RtlInitUnicodeString) { | 91 if (!RtlInitUnicodeString) { |
70 HMODULE ntdll = ::GetModuleHandle(kNtdllName); | 92 HMODULE ntdll = ::GetModuleHandle(kNtdllName); |
71 RtlInitUnicodeString = reinterpret_cast<RtlInitUnicodeStringFunction>( | 93 RtlInitUnicodeString = reinterpret_cast<RtlInitUnicodeStringFunction>( |
72 GetProcAddress(ntdll, "RtlInitUnicodeString")); | 94 GetProcAddress(ntdll, "RtlInitUnicodeString")); |
73 DCHECK(RtlInitUnicodeString); | 95 DCHECK(RtlInitUnicodeString); |
(...skipping 13 matching lines...) Expand all Loading... |
87 return std::string(); | 109 return std::string(); |
88 | 110 |
89 std::string mb; | 111 std::string mb; |
90 WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, | 112 WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, |
91 WriteInto(&mb, charcount), charcount, NULL, NULL); | 113 WriteInto(&mb, charcount), charcount, NULL, NULL); |
92 | 114 |
93 return mb; | 115 return mb; |
94 } | 116 } |
95 | 117 |
96 }; // namespace sandbox | 118 }; // namespace sandbox |
OLD | NEW |