utils

package
v1.8.0-beta.7 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Kilo
	Mega
	Giga
)
View Source
const (
	// DefaultPerms default permissions for output files
	DefaultPerms = 0740
)

Variables

View Source
var (
	RegexUuid = regexp.MustCompile(`^(?i:[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12})$`)
)

Functions

func CountFiles added in v1.5.0

func CountFiles(directory string) (cnt int)

CountFiles counts files in a directory

func DisableAuditPolicy

func DisableAuditPolicy(subCatOrGuid string) error

func EnableAuditPolicy

func EnableAuditPolicy(subCatOrGuid string) error

func ExpandEnvs

func ExpandEnvs(s ...string) (o []string)

ExpandEnvs expands several strings with environment variable it is just a loop calling os.ExpandEnv for every element

func GetCurFuncName

func GetCurFuncName() string

func GzipFileBestSpeed

func GzipFileBestSpeed(path string) (err error)

GzipFileBestSpeed compresses a file to gzip and deletes the original file

func HashEventBytes

func HashEventBytes(b []byte) string

HashEventBytes return a hash from a byte slice assuming the event has been JSON encoded with the json.Marshal

func HashInterface

func HashInterface(i interface{}) (h string, err error)

HashInterface return a sha1 hash from an interface

func HidsCreateFile

func HidsCreateFile(filename string) (*os.File, error)

HidsCreateFile creates a file with the good permissions

func HidsMkTmpDir

func HidsMkTmpDir() (dir string, err error)

func HidsMkdirAll

func HidsMkdirAll(dir string) error

HidsMkdirAll is a wrapper around os.MkdirAll with appropriate permissions

func HidsWriteData

func HidsWriteData(dest string, data []byte) error

HidsWriteData is a wrapper around ioutil.WriteFile to write a file with the good permissions

func HidsWriteReader

func HidsWriteReader(dst string, content io.Reader, compress bool) (err error)

HidsWriteReader writes the content of a reader to a destination file. If compress is true .gz extension is added to destination file name.

func IsDirEmpty

func IsDirEmpty(dir string) (empty bool, err error)

func IsPipePath added in v1.5.0

func IsPipePath(path string) bool

IsPipePath checks whether the argument path is a pipe

func IsValidUUID

func IsValidUUID(uuid string) bool

func Json

func Json(i interface{}) []byte

func JsonString

func JsonString(i interface{}) string

JsonString returns a Json string out of i

func PrettyJson

func PrettyJson(i interface{}) string

PrettyJson returns a JSON pretty string out of i

func ReadFileString added in v1.5.0

func ReadFileString(path string) (string, error)

ReadFileString reads bytes from a file

func RegQuery added in v1.6.0

func RegQuery(key, value string) (string, error)

RegQuery issues a reg query command to dump registry

func RelativePath

func RelativePath(path string) string

func RemoveEDRAuditACL

func RemoveEDRAuditACL(directories ...string) (err error)

func Round added in v1.5.0

func Round(f float64, precision int) float64

Round float f to precision

func SetAuditPolicy

func SetAuditPolicy(subCatOrGuid string, success, failure bool) error

func SetEDRAuditACL

func SetEDRAuditACL(directories ...string) (err error)

func Sha256StringArray

func Sha256StringArray(array []string) string

Sha256StringArray utility

func StdDir

func StdDir(dir string) string

StdDir makes a directory ending with os separator

func StdDirs

func StdDirs(directories ...string) (o []string)

StdDirs makes a directories are ending with os separator

func Toml

func Toml(i interface{}) (b []byte, err error)

func TomlString

func TomlString(i any) (s string, err error)

func UnsafeKeyGen

func UnsafeKeyGen(size int) string

UnsafeKeyGen is an API key generator, supposed to generate an [[:alnum:]] key

func UnsafeUUIDGen

func UnsafeUUIDGen() uuid.UUID

UnsafeUUIDGen generates a random UUID

func Unzip

func Unzip(zipfile, dest string) (err error)

Unzip helper function to unzip a file to a destination folder source code from : https://stackoverflow.com/questions/20357223/easy-way-to-unzip-file-with-golang

func Utf16ToUtf8 added in v1.7.0

func Utf16ToUtf8(b []byte) ([]byte, error)

Utf16ToUtf8 converts a utf16 encoded byte slice to utf8 byte slice it returns error if there is any decoding / encoding issue Inspired by: https://gist.github.com/bradleypeabody/185b1d7ed6c0c2ab6cec#file-gistfile1-go

Types

type ByteSlice added in v1.5.0

type ByteSlice []byte

func (ByteSlice) Len added in v1.5.0

func (b ByteSlice) Len() int

func (ByteSlice) Less added in v1.5.0

func (b ByteSlice) Less(i, j int) bool

func (ByteSlice) Swap added in v1.5.0

func (b ByteSlice) Swap(i, j int)

type WindowsLogger

type WindowsLogger struct {
	Channel string
	Source  string
	// contains filtered or unexported fields
}

WindowsLogger structure definition

func NewWindowsLogger

func NewWindowsLogger(channel, source string) (wl *WindowsLogger, err error)

NewWindowsLogger creates a new WindowsLogger structure

func (*WindowsLogger) Close

func (w *WindowsLogger) Close() error

Close closes the logger in a clean fashion

func (*WindowsLogger) Log

func (w *WindowsLogger) Log(eventid int, entrytype, message string)

Log logs a message through powershell Write-EventLog

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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