libregf

package module
v0.0.0-...-c4307db Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 4 Imported by: 0

README

go-libregf

Go bindings for the libregf C library, which exposes an API for handling Windows Registry files

What is Working

  • registry files (open, root key, get key, get value)
  • keys (name, classname, values, subkeys)
  • values (name, value, support for most types)
  • error handling

How to Use

inport (
  "fmt"
  "github.com/jdrowell/go-libregf"
)

func report(filepath string, values []string) error {
  file, err := libregf.OpenFile(filepath)
  if err != nil { return err }
  defer file.Close()

  for _, path := range values {
    v, err := file.Value(path)
    if err != nil { return err }
    fmt.Printf("%s: %s\n", path, v)
  }

  return nil
}

func main() {
  err := report("SOFTWARE", []string{
    "Microsoft\\Windows NT\\CurrentVersion\\RegisteredOrganization",
    "Microsoft\\Windows NT\\CurrentVersion\\RegisteredOwner",
    "Microsoft\\Windows NT\\CurrentVersion\\ProductName",
    "Microsoft\\Windows NT\\CurrentVersion\\InstallDate",
    "Microsoft\\Windows NT\\CurrentVersion\\ProductId",
  })
  if err != nil {
    fmt.Println(err)
    os.Exit(1)
  }
}

Dependencies

These bindings are up to date with release alpha-20230319 of libregf. You must have libregf-dev installed to be able to link your binary. Also, make sure NOT to have something like CGO_ENABLED=0 in your environment.

Documentation

There is inline documentation in go doc format. Just use that command to explore it.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Version

func Version() string

Version returns the version number of the libregf C library It wraps libregf_get_version().

Types

type Error

type Error C.libregf_error_t

Error is an opaque struct to group related method calls

func (*Error) Free

func (err *Error) Free()

Free frees memory allocated in C for the hidden Error struct. It wraps libregf_error_free().

func (*Error) String

func (err *Error) String() string

String returns the string representation of an error. It wraps libregf_error_sprint().

type File

type File C.libregf_file_t

File is an opaque struct to group related method calls

func OpenFile

func OpenFile(path string) (*File, error)

OpenFile opens a registry file by its path. It wraps libregf_file_initialize() and libregf_file_open().

func (*File) Close

func (file *File) Close()

Close closes a registry file. It wraps libregf_file_close().

func (*File) Key

func (file *File) Key(path string) (*Key, error)

Key returns a Key by its path inside the registry. It wraps libregf_file_get_key_by_utf8_path().

func (*File) RootKey

func (file *File) RootKey() (*Key, error)

RootKey returns the root Key of a registry file. It wraps libregf_file_get_root_key().

func (*File) Value

func (file *File) Value(path string) (string, error)

Value returns the string representation of a "value of a Value" by its path inside the registry. It does so by considering that the last part of the path if the Value's name. This is a quick way to get a displayable value for a full registry path in one call.

type Key

type Key C.libregf_key_t

Key is an opaque struct to group related method calls

func (*Key) ClassName

func (key *Key) ClassName() (string, error)

ClassName returns the Key's class name. It wraps libregf_key_get_utf8_class_name(). It returns a regular Go string, so you don't have to worry about the underlying C calls and memory allocations.

func (*Key) ClassNameLen

func (key *Key) ClassNameLen() (int, error)

ClassNameLen returns the length (in bytes) of the Key's class name. It wraps libregf_key_get_utf8_class_name_size(). You usually call it to know how much space to allocate before calling libregf_key_get_utf8_class_name(). You don't need to call this function if you call ClassName(), which calls ClassNameLen().

func (*Key) Free

func (key *Key) Free() error

Free frees memory allocated in C for the hidden Key struct. It wraps libregf_key_free().

func (*Key) Name

func (key *Key) Name() (string, error)

Name returns the Key's name. It wraps libregf_key_get_utf8_name(). It returns a regular Go string, so you don't have to worry about the underlying C calls and memory allocations.

func (*Key) NameLen

func (key *Key) NameLen() (int, error)

NameLen returns the length (in bytes) of the Key's name. It wraps libregf_key_get_utf8_name_size(). You usually call it to know how much space to allocate before calling libregf_key_get_utf8_name(). You don't need to call this function if you call Name(), which calls NameLen().

func (*Key) SubkeyAt

func (key *Key) SubkeyAt(index int) (*Key, error)

SubkeyAt returns the Key at a given position inside another Key. It wraps libregf_key_get_sub_key().

func (*Key) SubkeyByName

func (key *Key) SubkeyByName(name string) (*Key, error)

SubkeyByName returns the Key present inside another Key by its name. It wraps libregf_key_get_sub_key_by_utf8_name().

func (*Key) SubkeysLen

func (key *Key) SubkeysLen() (int, error)

SubkeysLen returns the count of sub-Keys present inside a Key. It wraps libregf_key_get_number_of_sub_keys().

func (*Key) Value

func (key *Key) Value(path string) (*Value, error)

Value returns the Value present inside a Key by its name. It wraps libregf_key_get_value_by_utf8_name().

func (*Key) ValueAt

func (key *Key) ValueAt(index int) (*Value, error)

ValueAt returns the Value at a given position inside a Key. It wraps libregf_key_get_value().

func (*Key) ValuesLen

func (key *Key) ValuesLen() (int, error)

ValuesLen returns the number of Values present inside a Key. It wraps libregf_key_get_number_of_values().

type MultiString

type MultiString C.libregf_multi_string_t

MultiString is an opaque struct to group related method calls

func (*MultiString) Free

func (ms *MultiString) Free() error

Free frees the memory allocated by C to an opaque *MultiString. It wraps libregf_multi_string_free(). Most of the time you will just defer a call to Free() right after calling a function that allocates a MultiString.

func (*MultiString) StringAt

func (ms *MultiString) StringAt(index int) (string, error)

StringAt returns the string at a position inside a MultiString. It wraps libregf_multi_string_get_utf8_string().

func (*MultiString) StringLenAt

func (ms *MultiString) StringLenAt(index int) (int, error)

StringLenAt returns the length (in bytes) of a particular string in a MultiString. It wraps libregf_multi_string_get_utf8_string_size(). You don't need to call this function if you call StringAt(), which calls StringLenAt().

func (*MultiString) Strings

func (ms *MultiString) Strings() ([]string, error)

Strings returns all of the strings inside a MultiString as a []string.

func (*MultiString) StringsLen

func (ms *MultiString) StringsLen() (int, error)

StringsLen returns the number of strings contained in a MultiString. It wraps libregf_multi_string_get_number_of_strings().

type Value

type Value C.libregf_value_t

Value is an opaque struct to group related method calls

func (*Value) Free

func (value *Value) Free() error

Free frees memory allocated in C for the hidden Value struct. It wraps libregf_value_free().

func (*Value) Name

func (value *Value) Name() (string, error)

Name returns the Value's name. It wraps libregf_value_get_utf8_name(). It returns a regular Go string, so you don't have to worry about the underlying C calls and memory allocations.

func (*Value) NameLen

func (value *Value) NameLen() (int, error)

NameLen returns the length (in bytes) of the Value's name. It wraps libregf_value_get_utf8_name_size(). You usually call it to know how much space to allocate before calling libregf_value_get_utf8_name(). You don't need to call this function if you call Name(), which calls NameLen().

func (*Value) String

func (value *Value) String() (string, error)

String returns any possible value as a string. These results may be truncated depending on the type and size of the underlying value.

func (*Value) TBinary

func (value *Value) TBinary() ([]byte, error)

TBinary returns a value of type LIBREGF_VALUE_TYPE_BINARY_DATANG as a Go []byte It wraps libregf_value_get_value_binary_data().

func (*Value) TBinaryLen

func (value *Value) TBinaryLen() (int, error)

TBinaryLen returns the length (in bytes) of a value of type LIBREGF_VALUE_TYPE_BINARY_DATA It wraps libregf_value_get_value_binary_data_size(). You don't need to call this function if you call TBinary(), which calls TBinaryLen().

func (*Value) TMultiString

func (value *Value) TMultiString() (*MultiString, error)

TMultiString returns a value of type LIBREGF_VALUE_TYPE_MULTI_VALUE_STRING as a pointer to a MultiString struct. You can only access the inner strings through the (*MultiString) methods. It wraps libregf_value_get_value_multi_string().

func (*Value) TString

func (value *Value) TString() (string, error)

TString returns a value of type LIBREGF_VALUE_TYPE_STRING as a Go string It wraps libregf_value_get_value_utf8_string().

func (*Value) TStringLen

func (value *Value) TStringLen() (int, error)

TStringLen returns the length (in bytes) of a value of type LIBREGF_VALUE_TYPE_STRING It wraps libregf_value_get_value_utf8_string_size(). You don't need to call this function if you call TString(), which calls TStringLen().

func (*Value) Tint32

func (value *Value) Tint32() (int, error)

Tint32 returns a value of type LIBREGF_VALUE_TYPE_INTEGER_32BIT_LITTLE_ENDIAN as a Go int It wraps libregf_value_get_value_32bit().

func (*Value) Tint64

func (value *Value) Tint64() (int, error)

Tint64 returns a value of type LIBREGF_VALUE_TYPE_INTEGER_64BIT_LITTLE_ENDIAN as a Go int It wraps libregf_value_get_value_64bit().

func (*Value) Type

func (value *Value) Type() (int, error)

Type returns the value's type. It wraps libregf_value_get_value_type().

Jump to

Keyboard shortcuts

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