go-tg-screenshot-bot
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
7package win8
9import (10"golang.org/x/sys/windows"11"syscall"12"unsafe"13)
14
15const KEY_READ REGSAM = 0x2001916const KEY_WRITE REGSAM = 0x2000617
18const (19HKEY_CLASSES_ROOT HKEY = 0x8000000020HKEY_CURRENT_USER HKEY = 0x8000000121HKEY_LOCAL_MACHINE HKEY = 0x8000000222HKEY_USERS HKEY = 0x8000000323HKEY_PERFORMANCE_DATA HKEY = 0x8000000424HKEY_CURRENT_CONFIG HKEY = 0x8000000525HKEY_DYN_DATA HKEY = 0x8000000626)
27
28const (29ERROR_NO_MORE_ITEMS = 25930)
31
32type (33ACCESS_MASK uint3234HKEY HANDLE
35REGSAM ACCESS_MASK
36)
37
38const (39REG_NONE uint64 = 0 // No value type40REG_SZ = 1 // Unicode nul terminated string41REG_EXPAND_SZ = 2 // Unicode nul terminated string42// (with environment variable references)43REG_BINARY = 3 // Free form binary44REG_DWORD = 4 // 32-bit number45REG_DWORD_LITTLE_ENDIAN = 4 // 32-bit number (same as REG_DWORD)46REG_DWORD_BIG_ENDIAN = 5 // 32-bit number47REG_LINK = 6 // Symbolic Link (unicode)48REG_MULTI_SZ = 7 // Multiple Unicode strings49REG_RESOURCE_LIST = 8 // Resource list in the resource map50REG_FULL_RESOURCE_DESCRIPTOR = 9 // Resource list in the hardware description51REG_RESOURCE_REQUIREMENTS_LIST = 1052REG_QWORD = 11 // 64-bit number53REG_QWORD_LITTLE_ENDIAN = 11 // 64-bit number (same as REG_QWORD)54
55)
56
57var (58// Library59libadvapi32 *windows.LazyDLL60
61// Functions62regCloseKey *windows.LazyProc63regOpenKeyEx *windows.LazyProc64regQueryValueEx *windows.LazyProc65regEnumValue *windows.LazyProc66regSetValueEx *windows.LazyProc67)
68
69func init() {70// Library71libadvapi32 = windows.NewLazySystemDLL("advapi32.dll")72
73// Functions74regCloseKey = libadvapi32.NewProc("RegCloseKey")75regOpenKeyEx = libadvapi32.NewProc("RegOpenKeyExW")76regQueryValueEx = libadvapi32.NewProc("RegQueryValueExW")77regEnumValue = libadvapi32.NewProc("RegEnumValueW")78regSetValueEx = libadvapi32.NewProc("RegSetValueExW")79}
80
81func RegCloseKey(hKey HKEY) int32 {82ret, _, _ := syscall.Syscall(regCloseKey.Addr(), 1,83uintptr(hKey),840,850)86
87return int32(ret)88}
89
90func RegOpenKeyEx(hKey HKEY, lpSubKey *uint16, ulOptions uint32, samDesired REGSAM, phkResult *HKEY) int32 {91ret, _, _ := syscall.Syscall6(regOpenKeyEx.Addr(), 5,92uintptr(hKey),93uintptr(unsafe.Pointer(lpSubKey)),94uintptr(ulOptions),95uintptr(samDesired),96uintptr(unsafe.Pointer(phkResult)),970)98
99return int32(ret)100}
101
102func RegQueryValueEx(hKey HKEY, lpValueName *uint16, lpReserved, lpType *uint32, lpData *byte, lpcbData *uint32) int32 {103ret, _, _ := syscall.Syscall6(regQueryValueEx.Addr(), 6,104uintptr(hKey),105uintptr(unsafe.Pointer(lpValueName)),106uintptr(unsafe.Pointer(lpReserved)),107uintptr(unsafe.Pointer(lpType)),108uintptr(unsafe.Pointer(lpData)),109uintptr(unsafe.Pointer(lpcbData)))110
111return int32(ret)112}
113
114func RegEnumValue(hKey HKEY, index uint32, lpValueName *uint16, lpcchValueName *uint32, lpReserved, lpType *uint32, lpData *byte, lpcbData *uint32) int32 {115ret, _, _ := syscall.Syscall9(regEnumValue.Addr(), 8,116uintptr(hKey),117uintptr(index),118uintptr(unsafe.Pointer(lpValueName)),119uintptr(unsafe.Pointer(lpcchValueName)),120uintptr(unsafe.Pointer(lpReserved)),121uintptr(unsafe.Pointer(lpType)),122uintptr(unsafe.Pointer(lpData)),123uintptr(unsafe.Pointer(lpcbData)),1240)125return int32(ret)126}
127
128func RegSetValueEx(hKey HKEY, lpValueName *uint16, lpReserved, lpDataType uint64, lpData *byte, cbData uint32) int32 {129ret, _, _ := syscall.Syscall6(regSetValueEx.Addr(), 6,130uintptr(hKey),131uintptr(unsafe.Pointer(lpValueName)),132uintptr(lpReserved),133uintptr(lpDataType),134uintptr(unsafe.Pointer(lpData)),135uintptr(cbData))136return int32(ret)137}
138