This source file includes following definitions.
- GetWOW64StatusForCurrentProcess
- version
- version_number
- service_pack
- GetThunk
#include <stdint.h>
#include <windows.h>
#include "base/basictypes.h"
#include "sandbox/win/src/interception_internal.h"
#include "sandbox/win/src/internal_types.h"
#include "sandbox/win/src/sandbox_utils.h"
#include "sandbox/win/src/service_resolver.h"
namespace {
enum Version {
VERSION_PRE_XP_SP2 = 0,
VERSION_XP_SP2,
VERSION_SERVER_2003,
VERSION_VISTA,
VERSION_WIN7,
VERSION_WIN8,
VERSION_WIN8_1,
VERSION_WIN_LAST,
};
enum WOW64Status { WOW64_DISABLED, WOW64_ENABLED, WOW64_UNKNOWN, };
WOW64Status GetWOW64StatusForCurrentProcess() {
typedef BOOL(WINAPI * IsWow64ProcessFunc)(HANDLE, PBOOL);
IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>(
GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process"));
if (!is_wow64_process)
return WOW64_DISABLED;
BOOL is_wow64 = FALSE;
if (!is_wow64_process(GetCurrentProcess(), &is_wow64))
return WOW64_UNKNOWN;
return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED;
}
class OSInfo {
public:
struct VersionNumber {
int major;
int minor;
int build;
};
struct ServicePack {
int major;
int minor;
};
OSInfo() {
OSVERSIONINFOEX version_info = {sizeof(version_info)};
GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info));
version_number_.major = version_info.dwMajorVersion;
version_number_.minor = version_info.dwMinorVersion;
version_number_.build = version_info.dwBuildNumber;
if ((version_number_.major == 5) && (version_number_.minor > 0)) {
version_ =
(version_number_.minor == 1) ? VERSION_XP_SP2 : VERSION_SERVER_2003;
if (version_ == VERSION_XP_SP2 && version_info.wServicePackMajor < 2)
version_ = VERSION_PRE_XP_SP2;
} else if (version_number_.major == 6) {
switch (version_number_.minor) {
case 0:
version_ = VERSION_VISTA;
break;
case 1:
version_ = VERSION_WIN7;
break;
case 2:
version_ = VERSION_WIN8;
break;
default:
version_ = VERSION_WIN8_1;
break;
}
} else if (version_number_.major > 6) {
version_ = VERSION_WIN_LAST;
} else {
version_ = VERSION_PRE_XP_SP2;
}
service_pack_.major = version_info.wServicePackMajor;
service_pack_.minor = version_info.wServicePackMinor;
}
Version version() const { return version_; }
VersionNumber version_number() const { return version_number_; }
ServicePack service_pack() const { return service_pack_; }
private:
Version version_;
VersionNumber version_number_;
ServicePack service_pack_;
DISALLOW_COPY_AND_ASSIGN(OSInfo);
};
}
sandbox::ServiceResolverThunk* GetThunk(bool relaxed) {
sandbox::ServiceResolverThunk* thunk = NULL;
OSInfo os_info;
if (os_info.version() <= VERSION_PRE_XP_SP2)
return thunk;
HANDLE current_process = ::GetCurrentProcess();
#if defined(_WIN64)
thunk = new sandbox::ServiceResolverThunk(current_process, relaxed);
#else
if (GetWOW64StatusForCurrentProcess() == WOW64_ENABLED) {
if (os_info.version() >= VERSION_WIN8)
thunk = new sandbox::Wow64W8ResolverThunk(current_process, relaxed);
else
thunk = new sandbox::Wow64ResolverThunk(current_process, relaxed);
} else if (os_info.version() >= VERSION_WIN8) {
thunk = new sandbox::Win8ResolverThunk(current_process, relaxed);
} else {
thunk = new sandbox::ServiceResolverThunk(current_process, relaxed);
}
#endif
return thunk;
}