registry

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Rendered for windows/amd64

Overview

Package registry

Optimized copy from sys/windows/registry to work with Crypt.

Index

Constants

View Source
const (
	CLASSES_ROOT     = Key(syscall.HKEY_CLASSES_ROOT)
	CURRENT_USER     = Key(syscall.HKEY_CURRENT_USER)
	LOCAL_MACHINE    = Key(syscall.HKEY_LOCAL_MACHINE)
	USERS            = Key(syscall.HKEY_USERS)
	CURRENT_CONFIG   = Key(syscall.HKEY_CURRENT_CONFIG)
	PERFORMANCE_DATA = Key(syscall.HKEY_PERFORMANCE_DATA)
)

Windows defines some predefined root keys that are always open.

An application can use these keys as entry points to the registry. Normally these keys are used in OpenKey to open new keys, but they can also be used anywhere a Key is required.

View Source
const (
	TypeString         = 1
	TypeExpandString   = 2
	TypeBinary         = 3
	TypeDword          = 4
	TypeDwordBigEndian = 5
	TypeStringList     = 7
	TypeQword          = 11
)

Registry value types.

Variables

View Source
var (
	// ErrNotExist is returned when a registry key or value does not exist.
	ErrNotExist = syscall.ERROR_FILE_NOT_FOUND
	// ErrShortBuffer is returned when the buffer was too short for the operation.
	ErrShortBuffer = syscall.ERROR_MORE_DATA
	// ErrUnexpectedSize is returned when the key data size was unexpected.
	ErrUnexpectedSize = xerr.Sub("unexpected key size", 0x10)
	// ErrUnexpectedType is returned by Get*Value when the value's type was
	// unexpected.
	ErrUnexpectedType = xerr.Sub("unexpected key type", 0xD)
)

Functions

func DeleteKey

func DeleteKey(k Key, s string) error

DeleteKey deletes the subkey path of the key and its values.

Types

type Key

type Key uintptr

Key is a handle to an open Windows registry key.

Keys can be obtained by calling OpenKey.

func CreateKey

func CreateKey(k Key, s string, a uint32) (Key, bool, error)

CreateKey creates a key named path under the open key.

CreateKey returns the new key and a boolean flag that reports whether the key already existed.

The access parameter specifies the access rights for the key to be created.

func OpenKey

func OpenKey(k Key, s string, a uint32) (Key, error)

OpenKey opens a new key with path name relative to the key.

It accepts any open key, including CURRENT_USER and others, and returns the new key and an error.

The access parameter specifies desired access rights to the key to be opened.

func (Key) Close

func (k Key) Close() error

Close closes the open key.

func (Key) DeleteValue

func (k Key) DeleteValue(n string) error

DeleteValue removes a named value from the key.

func (Key) GetBinaryValue

func (k Key) GetBinaryValue(s string) ([]byte, uint32, error)

GetBinaryValue retrieves the binary value for the specified value name associated with the open key. It also returns the value's type.

If value does not exist, GetBinaryValue returns ErrNotExist.

If value is not BINARY, it will return the correct value type and ErrUnexpectedType.

func (Key) GetIntegerValue

func (k Key) GetIntegerValue(s string) (uint64, uint32, error)

GetIntegerValue retrieves the integer value for the specified value name associated with the open key. It also returns the value's type.

If value does not exist, GetIntegerValue returns ErrNotExist.

If value is not DWORD or QWORD, it will return the correct value type and ErrUnexpectedType.

func (Key) GetStringValue

func (k Key) GetStringValue(s string) (string, uint32, error)

GetStringValue retrieves the string value for the specified value name associated with the open key. It also returns the value's type.

If value does not exist, GetStringValue returns ErrNotExist.

If value is not SZ or EXPAND_SZ, it will return the correct value type and ErrUnexpectedType.

func (Key) GetStringsValue

func (k Key) GetStringsValue(s string) ([]string, uint32, error)

GetStringsValue retrieves the []string value for the specified value name associated with an open key k. It also returns the value's type.

If value does not exist, GetStringsValue returns ErrNotExist.

If value is not MULTI_SZ, it will return the correct value type and ErrUnexpectedType.

func (Key) GetValue

func (k Key) GetValue(s string, b []byte) (int, uint32, error)

GetValue retrieves the type and data for the specified value associated with the open key.

It fills up buffer buf and returns the retrieved byte count n. If buf is too small to fit the stored value it returns an ErrShortBuffer error along with the required buffer size n.

If no buffer is provided, it returns true and actual buffer size and the value's type only.

If the value does not exist, the error returned is ErrNotExist.

GetValue is a low level function. If value's type is known, use the appropriate Get*Value function instead.

func (Key) ReadSubKeyNames

func (k Key) ReadSubKeyNames(n int) ([]string, error)

ReadSubKeyNames returns the names of subkeys of key k.

The parameter controls the number of returned names, analogous to the way 'os.File.Readdirnames' works.

func (Key) ReadValueNames

func (k Key) ReadValueNames(n int) ([]string, error)

ReadValueNames returns the value names in the key.

The parameter controls the number of returned names, analogous to the way 'os.File.Readdirnames' works.

func (Key) SetBinaryValue

func (k Key) SetBinaryValue(n string, v []byte) error

SetBinaryValue sets the data and type of a name value under key k to value and BINARY.

func (Key) SetDWordValue

func (k Key) SetDWordValue(n string, v uint32) error

SetDWordValue sets the data and type of a named value under the key to the supplied value and DWORD.

func (Key) SetExpandStringValue

func (k Key) SetExpandStringValue(n, v string) error

SetExpandStringValue sets the data and type of a named value under the key to the supplied value and EXPAND_SZ.

The value must not contain a zero byte.

func (Key) SetQWordValue

func (k Key) SetQWordValue(n string, v uint64) error

SetQWordValue sets the data and type of a named value under the key to the supplied value and QWORD.

func (Key) SetStringValue

func (k Key) SetStringValue(n, v string) error

SetStringValue sets the data and type of a named value under the key to the supplied value and SZ.

The value must not contain a zero byte.

func (Key) SetStringsValue

func (k Key) SetStringsValue(n string, v []string) error

SetStringsValue sets the data and type of a named value under the key to the supplied value and MULTI_SZ.

The value strings must not contain a zero byte.

func (Key) Stat

func (k Key) Stat() (*KeyInfo, error)

Stat retrieves information about the open key.

type KeyInfo

type KeyInfo struct {
	SubKeyCount     uint32
	MaxSubKeyLen    uint32
	ValueCount      uint32
	MaxValueNameLen uint32
	MaxValueLen     uint32
	// contains filtered or unexported fields
}

KeyInfo describes the statistics of a key.

It is returned by a call to Stat.

func (*KeyInfo) ModTime

func (i *KeyInfo) ModTime() time.Time

ModTime returns the key's last write time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL