forked from samwafgo/SamWaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_win.go
65 lines (55 loc) · 1.54 KB
/
common_win.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//go:build windows
package utils
import (
"runtime"
"syscall"
"unsafe"
)
// 定义 RtlGetVersion 函数
var modNtDll = syscall.NewLazyDLL("ntdll.dll")
var procRtlGetVersion = modNtDll.NewProc("RtlGetVersion")
type OsVersionInfoEx struct {
DwOSVersionInfoSize uint32
DwMajorVersion uint32
DwMinorVersion uint32
DwBuildNumber uint32
DwPlatformId uint32
SzCSDVersion [128]uint16
WServicePackMajor uint16
WServicePackMinor uint16
WSuiteMask uint16
WProductType byte
WReserved byte
}
// 使用 RtlGetVersion 函数获取版本信息
func getWindowsVersion() (uint32, uint32, uint32, error) {
var info OsVersionInfoEx
info.DwOSVersionInfoSize = uint32(unsafe.Sizeof(info))
ret, _, _ := procRtlGetVersion.Call(uintptr(unsafe.Pointer(&info)))
if ret != 0 {
return 0, 0, 0, syscall.Errno(ret)
}
return info.DwMajorVersion, info.DwMinorVersion, info.DwBuildNumber, nil
}
// 判断是否为 Windows 平台,并且是 Windows 7, Windows 8 或 Windows Server 2008 R2
func IsSupportedWindows7Version() bool {
// 检查是否是 Windows 系统
if runtime.GOOS != "windows" {
return false
}
// 调用 RtlGetVersion 获取准确的操作系统版本信息
major, minor, _, err := getWindowsVersion()
if err != nil {
return false
}
// 判断是否为 Windows 7 或 Windows Server 2008 R2 (版本 6.1)
if major == 6 && minor == 1 {
return true
}
// 判断是否为 Windows 8 (版本 6.2)
if major == 6 && minor == 2 {
return true
}
// 如果都不满足,返回 false
return false
}