go-tg-screenshot-bot

Форк
0
137 строк · 3.9 Кб
1
// Copyright 2010 The win Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4

5
// +build windows
6

7
package win
8

9
import (
10
	"golang.org/x/sys/windows"
11
	"syscall"
12
	"unsafe"
13
)
14

15
const KEY_READ REGSAM = 0x20019
16
const KEY_WRITE REGSAM = 0x20006
17

18
const (
19
	HKEY_CLASSES_ROOT     HKEY = 0x80000000
20
	HKEY_CURRENT_USER     HKEY = 0x80000001
21
	HKEY_LOCAL_MACHINE    HKEY = 0x80000002
22
	HKEY_USERS            HKEY = 0x80000003
23
	HKEY_PERFORMANCE_DATA HKEY = 0x80000004
24
	HKEY_CURRENT_CONFIG   HKEY = 0x80000005
25
	HKEY_DYN_DATA         HKEY = 0x80000006
26
)
27

28
const (
29
	ERROR_NO_MORE_ITEMS = 259
30
)
31

32
type (
33
	ACCESS_MASK uint32
34
	HKEY        HANDLE
35
	REGSAM      ACCESS_MASK
36
)
37

38
const (
39
	REG_NONE      uint64 = 0 // No value type
40
	REG_SZ               = 1 // Unicode nul terminated string
41
	REG_EXPAND_SZ        = 2 // Unicode nul terminated string
42
	// (with environment variable references)
43
	REG_BINARY                     = 3 // Free form binary
44
	REG_DWORD                      = 4 // 32-bit number
45
	REG_DWORD_LITTLE_ENDIAN        = 4 // 32-bit number (same as REG_DWORD)
46
	REG_DWORD_BIG_ENDIAN           = 5 // 32-bit number
47
	REG_LINK                       = 6 // Symbolic Link (unicode)
48
	REG_MULTI_SZ                   = 7 // Multiple Unicode strings
49
	REG_RESOURCE_LIST              = 8 // Resource list in the resource map
50
	REG_FULL_RESOURCE_DESCRIPTOR   = 9 // Resource list in the hardware description
51
	REG_RESOURCE_REQUIREMENTS_LIST = 10
52
	REG_QWORD                      = 11 // 64-bit number
53
	REG_QWORD_LITTLE_ENDIAN        = 11 // 64-bit number (same as REG_QWORD)
54

55
)
56

57
var (
58
	// Library
59
	libadvapi32 *windows.LazyDLL
60

61
	// Functions
62
	regCloseKey     *windows.LazyProc
63
	regOpenKeyEx    *windows.LazyProc
64
	regQueryValueEx *windows.LazyProc
65
	regEnumValue    *windows.LazyProc
66
	regSetValueEx   *windows.LazyProc
67
)
68

69
func init() {
70
	// Library
71
	libadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
72

73
	// Functions
74
	regCloseKey = libadvapi32.NewProc("RegCloseKey")
75
	regOpenKeyEx = libadvapi32.NewProc("RegOpenKeyExW")
76
	regQueryValueEx = libadvapi32.NewProc("RegQueryValueExW")
77
	regEnumValue = libadvapi32.NewProc("RegEnumValueW")
78
	regSetValueEx = libadvapi32.NewProc("RegSetValueExW")
79
}
80

81
func RegCloseKey(hKey HKEY) int32 {
82
	ret, _, _ := syscall.Syscall(regCloseKey.Addr(), 1,
83
		uintptr(hKey),
84
		0,
85
		0)
86

87
	return int32(ret)
88
}
89

90
func RegOpenKeyEx(hKey HKEY, lpSubKey *uint16, ulOptions uint32, samDesired REGSAM, phkResult *HKEY) int32 {
91
	ret, _, _ := syscall.Syscall6(regOpenKeyEx.Addr(), 5,
92
		uintptr(hKey),
93
		uintptr(unsafe.Pointer(lpSubKey)),
94
		uintptr(ulOptions),
95
		uintptr(samDesired),
96
		uintptr(unsafe.Pointer(phkResult)),
97
		0)
98

99
	return int32(ret)
100
}
101

102
func RegQueryValueEx(hKey HKEY, lpValueName *uint16, lpReserved, lpType *uint32, lpData *byte, lpcbData *uint32) int32 {
103
	ret, _, _ := syscall.Syscall6(regQueryValueEx.Addr(), 6,
104
		uintptr(hKey),
105
		uintptr(unsafe.Pointer(lpValueName)),
106
		uintptr(unsafe.Pointer(lpReserved)),
107
		uintptr(unsafe.Pointer(lpType)),
108
		uintptr(unsafe.Pointer(lpData)),
109
		uintptr(unsafe.Pointer(lpcbData)))
110

111
	return int32(ret)
112
}
113

114
func RegEnumValue(hKey HKEY, index uint32, lpValueName *uint16, lpcchValueName *uint32, lpReserved, lpType *uint32, lpData *byte, lpcbData *uint32) int32 {
115
	ret, _, _ := syscall.Syscall9(regEnumValue.Addr(), 8,
116
		uintptr(hKey),
117
		uintptr(index),
118
		uintptr(unsafe.Pointer(lpValueName)),
119
		uintptr(unsafe.Pointer(lpcchValueName)),
120
		uintptr(unsafe.Pointer(lpReserved)),
121
		uintptr(unsafe.Pointer(lpType)),
122
		uintptr(unsafe.Pointer(lpData)),
123
		uintptr(unsafe.Pointer(lpcbData)),
124
		0)
125
	return int32(ret)
126
}
127

128
func RegSetValueEx(hKey HKEY, lpValueName *uint16, lpReserved, lpDataType uint64, lpData *byte, cbData uint32) int32 {
129
	ret, _, _ := syscall.Syscall6(regSetValueEx.Addr(), 6,
130
		uintptr(hKey),
131
		uintptr(unsafe.Pointer(lpValueName)),
132
		uintptr(lpReserved),
133
		uintptr(lpDataType),
134
		uintptr(unsafe.Pointer(lpData)),
135
		uintptr(cbData))
136
	return int32(ret)
137
}
138

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.