Skip to content

Commit

Permalink
Add individual functions to set/get coonfiguration parameters
Browse files Browse the repository at this point in the history
Inspired by discussion in #126, thanks to @zdiff
  • Loading branch information
hillu committed Aug 29, 2023
1 parent 5caf6bb commit 9d03c66
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
)

// SetConfiguration sets a global YARA configuration option.
//
// Deprecated. Use the specialized SetConfig* functions instead.
func SetConfiguration(name ConfigName, src interface{}) error {
i, ok := src.(int)
if !ok {
Expand All @@ -31,6 +33,8 @@ func SetConfiguration(name ConfigName, src interface{}) error {
}

// GetConfiguration gets a global YARA configuration option.
//
// Deprecated. Use the specialized GetConfig* functions instead.
func GetConfiguration(name ConfigName) (interface{}, error) {
var u C.uint32_t
if err := newError(C.yr_get_configuration(
Expand All @@ -40,3 +44,75 @@ func GetConfiguration(name ConfigName) (interface{}, error) {
}
return int(u), nil
}

// SetConfigStackSize sets the size of the stack used by the bytecode interpreter.
func SetConfigStackSize(val uint32) error {
u := (C.uint32_t)(val)
return newError(
C.yr_set_configuration(C.YR_CONFIG_STACK_SIZE, unsafe.Pointer(&u)))
}

// GetConfigStackSize returns the size of the stack used by the bytecode interpreter.
func GetConfigStackSize() (uint32, error) {
var u C.uint32_t
if err := newError(C.yr_get_configuration(
C.YR_CONFIG_STACK_SIZE, unsafe.Pointer(&u)),
); err != nil {
return nil, err
}
return uint32(u), nil
}

// SetConfigMaxMatchData sets the maximum number of data copies per scan.
func SetConfigMaxMatchData(val uint32) error {
u := (C.uint32_t)(val)
return newError(
C.yr_set_configuration(C.YR_CONFIG_MATCH_DATA, unsafe.Pointer(&u)))

Check failure on line 70 in config.go

View workflow job for this annotation

GitHub Actions / buildtest

could not determine kind of name for C.YR_CONFIG_MATCH_DATA

Check failure on line 70 in config.go

View workflow job for this annotation

GitHub Actions / buildtest

could not determine kind of name for C.YR_CONFIG_MATCH_DATA
}

// GetConfigMaxMatchData returns the maximum number of data copies per scan.
func GetConfigMaxMatchData() (uint32, error) {
var u C.uint32_t
if err := newError(C.yr_get_configuration(
C.YR_CONFIG_MATCH_DATA, unsafe.Pointer(&u)),
); err != nil {
return nil, err
}
return uint32(u), nil
}

// SetConfigMaxStringsPerRule sets the maximum number of string that can match per rule.
func SetConfigMaxStringsPerRule(val uint32) error {
u := (C.uint32_t)(val)
return newError(
C.yr_set_configuration(C.YR_CONFIG_MAX_STRINGS_PER_RULE, unsafe.Pointer(&u)))
}

// GetConfigMaxStringsPerRule returns the maximum number of string that can match per rule.
func GetConfigMaxStringsPerRule() (uint32, error) {
var u C.uint32_t
if err := newError(C.yr_get_configuration(
C.YR_CONFIG_MAX_STRINGS_PER_RULE, unsafe.Pointer(&u)),
); err != nil {
return nil, err
}
return uint32(u), nil
}

// SetConfigMaxProcessMemoryChunk sets the maximum size per scanned memory chunk.
func SetConfigMaxProcessMemoryChunk(val uint64) error {
u := (C.uint32_t)(val)
return newError(
C.yr_set_configuration(C.YR_CONFIG_MAX_PROCESS_MEMORY_CHUNK, unsafe.Pointer(&u)))
}

// GetConfigMaxProcessMemoryChunk returns the maximum size per scanned memory chunk.
func GetConfigMaxProcessMemoryChunk() (uint64, error) {
var u C.uint64_t
if err := newError(C.yr_get_configuration(
C.YR_CONFIG_MAX_PROCESS_MEMORY_CHUNK, unsafe.Pointer(&u)),
); err != nil {
return nil, err
}
return uint64(u), nil
}

0 comments on commit 9d03c66

Please sign in to comment.