| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stdint.h> | |
| 6 #include <windows.h> | |
| 7 | |
| 8 #include "sandbox/win/src/interception_internal.h" | |
| 9 #include "sandbox/win/src/internal_types.h" | |
| 10 #include "sandbox/win/src/sandbox_utils.h" | |
| 11 #include "sandbox/win/src/service_resolver.h" | |
| 12 | |
| 13 namespace { | |
| 14 enum Version { | |
| 15 VERSION_PRE_XP_SP2 = 0, // Not supported. | |
| 16 VERSION_XP_SP2, | |
| 17 VERSION_SERVER_2003, // Also includes XP Pro x64 and Server 2003 R2. | |
| 18 VERSION_VISTA, // Also includes Windows Server 2008. | |
| 19 VERSION_WIN7, // Also includes Windows Server 2008 R2. | |
| 20 VERSION_WIN8, // Also includes Windows Server 2012. | |
| 21 VERSION_WIN8_1, | |
| 22 VERSION_WIN10, | |
| 23 VERSION_WIN_LAST, // Indicates error condition. | |
| 24 }; | |
| 25 | |
| 26 #if !defined(_WIN64) | |
| 27 // Whether a process is running under WOW64 (the wrapper that allows 32-bit | |
| 28 // processes to run on 64-bit versions of Windows). This will return | |
| 29 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit | |
| 30 // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. | |
| 31 // the process does not have sufficient access rights to determine this. | |
| 32 enum WOW64Status { | |
| 33 WOW64_DISABLED, | |
| 34 WOW64_ENABLED, | |
| 35 WOW64_UNKNOWN, | |
| 36 }; | |
| 37 | |
| 38 WOW64Status GetWOW64StatusForCurrentProcess() { | |
| 39 typedef BOOL(WINAPI * IsWow64ProcessFunc)(HANDLE, PBOOL); | |
| 40 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( | |
| 41 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); | |
| 42 if (!is_wow64_process) | |
| 43 return WOW64_DISABLED; | |
| 44 BOOL is_wow64 = FALSE; | |
| 45 if (!is_wow64_process(GetCurrentProcess(), &is_wow64)) | |
| 46 return WOW64_UNKNOWN; | |
| 47 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; | |
| 48 } | |
| 49 #endif // !defined(_WIN64) | |
| 50 | |
| 51 class OSInfo { | |
| 52 public: | |
| 53 struct VersionNumber { | |
| 54 int major; | |
| 55 int minor; | |
| 56 int build; | |
| 57 }; | |
| 58 | |
| 59 struct ServicePack { | |
| 60 int major; | |
| 61 int minor; | |
| 62 }; | |
| 63 | |
| 64 OSInfo() { | |
| 65 OSVERSIONINFOEX version_info = {sizeof(version_info)}; | |
| 66 GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); | |
| 67 version_number_.major = version_info.dwMajorVersion; | |
| 68 version_number_.minor = version_info.dwMinorVersion; | |
| 69 version_number_.build = version_info.dwBuildNumber; | |
| 70 if ((version_number_.major == 5) && (version_number_.minor > 0)) { | |
| 71 // Treat XP Pro x64, Home Server, and Server 2003 R2 as Server 2003. | |
| 72 version_ = | |
| 73 (version_number_.minor == 1) ? VERSION_XP_SP2 : VERSION_SERVER_2003; | |
| 74 if (version_ == VERSION_XP_SP2 && version_info.wServicePackMajor < 2) | |
| 75 version_ = VERSION_PRE_XP_SP2; | |
| 76 } else if (version_number_.major == 6) { | |
| 77 switch (version_number_.minor) { | |
| 78 case 0: | |
| 79 // Treat Windows Server 2008 the same as Windows Vista. | |
| 80 version_ = VERSION_VISTA; | |
| 81 break; | |
| 82 case 1: | |
| 83 // Treat Windows Server 2008 R2 the same as Windows 7. | |
| 84 version_ = VERSION_WIN7; | |
| 85 break; | |
| 86 case 2: | |
| 87 // Treat Windows Server 2012 the same as Windows 8. | |
| 88 version_ = VERSION_WIN8; | |
| 89 break; | |
| 90 default: | |
| 91 version_ = VERSION_WIN8_1; | |
| 92 break; | |
| 93 } | |
| 94 } else if (version_number_.major == 10) { | |
| 95 version_ = VERSION_WIN10; | |
| 96 } else if (version_number_.major > 6) { | |
| 97 version_ = VERSION_WIN_LAST; | |
| 98 } else { | |
| 99 version_ = VERSION_PRE_XP_SP2; | |
| 100 } | |
| 101 | |
| 102 service_pack_.major = version_info.wServicePackMajor; | |
| 103 service_pack_.minor = version_info.wServicePackMinor; | |
| 104 } | |
| 105 | |
| 106 Version version() const { return version_; } | |
| 107 VersionNumber version_number() const { return version_number_; } | |
| 108 ServicePack service_pack() const { return service_pack_; } | |
| 109 | |
| 110 private: | |
| 111 Version version_; | |
| 112 VersionNumber version_number_; | |
| 113 ServicePack service_pack_; | |
| 114 | |
| 115 DISALLOW_COPY_AND_ASSIGN(OSInfo); | |
| 116 }; | |
| 117 | |
| 118 } // namespace | |
| 119 | |
| 120 sandbox::ServiceResolverThunk* GetThunk(bool relaxed) { | |
| 121 // Create a thunk via the appropriate ServiceResolver instance. | |
| 122 sandbox::ServiceResolverThunk* thunk = NULL; | |
| 123 | |
| 124 // No thunks for unsupported OS versions. | |
| 125 OSInfo os_info; | |
| 126 if (os_info.version() <= VERSION_PRE_XP_SP2) | |
| 127 return thunk; | |
| 128 | |
| 129 // Pseudo-handle, no need to close. | |
| 130 HANDLE current_process = ::GetCurrentProcess(); | |
| 131 | |
| 132 #if defined(_WIN64) | |
| 133 // ServiceResolverThunk can handle all the formats in 64-bit (instead only | |
| 134 // handling one like it does in 32-bit versions). | |
| 135 thunk = new sandbox::ServiceResolverThunk(current_process, relaxed); | |
| 136 #else | |
| 137 if (GetWOW64StatusForCurrentProcess() == WOW64_ENABLED) { | |
| 138 if (os_info.version() >= VERSION_WIN10) | |
| 139 thunk = new sandbox::Wow64W10ResolverThunk(current_process, relaxed); | |
| 140 else if (os_info.version() >= VERSION_WIN8) | |
| 141 thunk = new sandbox::Wow64W8ResolverThunk(current_process, relaxed); | |
| 142 else | |
| 143 thunk = new sandbox::Wow64ResolverThunk(current_process, relaxed); | |
| 144 } else if (os_info.version() >= VERSION_WIN8) { | |
| 145 thunk = new sandbox::Win8ResolverThunk(current_process, relaxed); | |
| 146 } else { | |
| 147 thunk = new sandbox::ServiceResolverThunk(current_process, relaxed); | |
| 148 } | |
| 149 #endif | |
| 150 | |
| 151 return thunk; | |
| 152 } | |
| OLD | NEW |