Documentation
¶
Overview ¶
Package yara provides bindings to the YARA library.
Index ¶
- Constants
- func Finalize() error
- func GetMaxMatchData() int
- func Initialize() error
- func SetMaxMatchData(n int)
- type ByCostDesc
- type Callback
- type Compiler
- func (c *Compiler) AddFile(file *os.File, namespace string) (err error)
- func (c *Compiler) AddString(rules string, namespace string) (err error)
- func (c *Compiler) DefineVariable(identifier string, value interface{}) (err error)
- func (c *Compiler) Destroy()
- func (c *Compiler) DisableIncludes()
- func (c *Compiler) GetRules() (*Rules, error)
- func (c *Compiler) LoadAtomQualityTable(path string, qualityWarningThreshold uint8) error
- func (c *Compiler) SetIncludeCallback(cb CompilerIncludeFunc)
- type CompilerIncludeFunc
- type CompilerMessage
- type Error
- type ImportModuleCallback
- type Match
- type MatchRule
- type MatchRules
- type MatchString
- type ModuleImportedCallback
- type Object
- type Rule
- type RuleCost
- type RuleMatchingCallback
- type RuleNotMatchingCallback
- type Rules
- func (r *Rules) DefineVariable(identifier string, value interface{}) (err error)
- func (r *Rules) Destroy()
- func (r *Rules) GetMostCostlyRules(n int) []RuleCost
- func (r *Rules) GetRules() (rv []Rule)
- func (r *Rules) ResetCosts()
- func (r *Rules) Save(filename string) (err error)
- func (r *Rules) ScanFile(filename string, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
- func (r *Rules) ScanFileDescriptor(fd uintptr, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
- func (r *Rules) ScanFileDescriptorWithCallback(fd uintptr, flags ScanFlags, timeout time.Duration, cb Callback) (err error)
- func (r *Rules) ScanFileWithCallback(filename string, flags ScanFlags, timeout time.Duration, cb Callback) (err error)
- func (r *Rules) ScanMem(buf []byte, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
- func (r *Rules) ScanMemWithCallback(buf []byte, flags ScanFlags, timeout time.Duration, cb Callback) (err error)
- func (r *Rules) ScanProc(pid int, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
- func (r *Rules) ScanProcWithCallback(pid int, flags ScanFlags, timeout time.Duration, cb Callback) (err error)
- func (r *Rules) Write(wr io.Writer) (err error)
- type ScanError
- type ScanFinishedCallback
- type ScanFlags
- type Scanner
- func (s *Scanner) DefineVariable(identifier string, value interface{}) (err error)
- func (s *Scanner) Destroy()
- func (s *Scanner) GetLastErrorRule() *Rule
- func (s *Scanner) GetLastErrorString() *String
- func (s *Scanner) ScanMem(buf []byte, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
- func (s *Scanner) ScanMemWithCallback(buf []byte, flags ScanFlags, timeout time.Duration, cb Callback) (err error)
- type String
Constants ¶
const ( // ScanFlagsFastMode avoids multiple matches of the same string // when not necessary. ScanFlagsFastMode = C.SCAN_FLAGS_FAST_MODE // ScanFlagsProcessMemory causes the scanned data to be // interpreted like live, in-prcess memory rather than an on-disk // file. ScanFlagsProcessMemory = C.SCAN_FLAGS_PROCESS_MEMORY )
Variables ¶
This section is empty.
Functions ¶
func Finalize ¶
func Finalize() error
Finalize releases all the resources allocated by the library. It should be called when the program finishes using it.
func GetMaxMatchData ¶
func GetMaxMatchData() int
GetMaxMatchData returns the value for YARA's YR_CONFIG_MAX_MATCH_DATA configuration option. This controls the maximum amount of bytes that YARA stores for each matching string.
func SetMaxMatchData ¶
func SetMaxMatchData(n int)
SetMaxMatchData sets the value for YR_CONFIG_MAX_MATCH_DATA configuration option, which controls the maximum amount of bytes that YARA stores for each matching string. If this value is zero YARA won't copy any data at all.
Types ¶
type ByCostDesc ¶
type ByCostDesc []Rule
ByCostDesc is a type used for sorting an slice of Rule by time cost in descending order.
func (ByCostDesc) Len ¶
func (r ByCostDesc) Len() int
func (ByCostDesc) Less ¶
func (r ByCostDesc) Less(i, j int) bool
func (ByCostDesc) Swap ¶
func (r ByCostDesc) Swap(i, j int)
type Callback ¶
type Callback interface{}
Callback is the interface for the callback object passed to the Scan*WithCallback functions.
type Compiler ¶
type Compiler struct { Errors []CompilerMessage Warnings []CompilerMessage // contains filtered or unexported fields }
A Compiler encapsulates the YARA compiler that transforms rules into YARA's internal, binary form which in turn is used for scanning files or memory blocks.
func (*Compiler) AddFile ¶
AddFile compiles rules from a file. Rules are added to the specified namespace.
func (*Compiler) AddString ¶
AddString compiles rules from a string. Rules are added to the specified namespace.
func (*Compiler) DefineVariable ¶
DefineVariable defines a named variable for use by the compiler. Boolean, int64, float64, and string types are supported.
func (*Compiler) Destroy ¶
func (c *Compiler) Destroy()
Destroy destroys the YARA data structure representing a compiler. Since a Finalizer for the underlying YR_COMPILER structure is automatically set up on creation, it should not be necessary to explicitly call this method.
func (*Compiler) DisableIncludes ¶
func (c *Compiler) DisableIncludes()
DisableIncludes disables all include statements in the compiler. See yr_compiler_set_include_callbacks.
func (*Compiler) LoadAtomQualityTable ¶
LoadAtomQualityTable loads an atom quality table from a file.
func (*Compiler) SetIncludeCallback ¶
func (c *Compiler) SetIncludeCallback(cb CompilerIncludeFunc)
SetIncludeCallback sets up cb as an include callback that is called (through Go glue code) by the YARA compiler for every include statement.
type CompilerIncludeFunc ¶
CompilerIncludeFunc is the type of the function that can be registered through SetIncludeCallback. It is called for every include statement encountered by the compiler. The argument "name" specifies the rule file to be included, "filename" specifies the name of the rule file where the include statement has been encountered, and "namespace" specifies the rule namespace. The sole return value is a byte slice containing the contents of the included file. A return value of nil signals an error to the YARA compiler.
See also: yr_compiler_set_include_callback in the YARA C API documentation.
type CompilerMessage ¶
A CompilerMessage contains an error or warning message produced while compiling sets of rules using AddString or AddFile.
type Error ¶
type Error struct {
Code int
}
Error is an implementation of the error interface that includes the YARA error code. All functions in this package return this type of errors.
type ImportModuleCallback ¶
ImportModuleCallback is the interface that must satisfy the object passed to Scan*WithCallback in order to receive a message when a module is about to be loaded.
type Match ¶
type Match struct {
// contains filtered or unexported fields
}
Match represents a string match
type MatchRule ¶
type MatchRule struct { Rule string Namespace string Tags []string Meta map[string]interface{} Strings []MatchString }
A MatchRule represents a rule successfully matched against a block of data.
type MatchRules ¶
type MatchRules []MatchRule
MatchRules implements the RuleMatchingCallback interface and is used to collect matches that are returned by the simple (*Rules).Scan* methods.
func (*MatchRules) OnRuleMatching ¶
func (mr *MatchRules) OnRuleMatching(r *Rule) (abort bool, err error)
type MatchString ¶
A MatchString represents a string declared and matched in a rule.
type ModuleImportedCallback ¶
ModuleImportedCallback is the interface that must satisfy the object passed to Scan*WithCallback in order to receive a message when a module has been imported.
type Rule ¶
type Rule struct {
// contains filtered or unexported fields
}
Rule represents a single rule as part of a ruleset
type RuleMatchingCallback ¶
RuleMatchingCallback is the interface that must satisfy the object passed to Scan*WithCallback in order to receive messages about matching rules.
type RuleNotMatchingCallback ¶
RuleNotMatchingCallback is the interface that must satisfy the object passed to Scan*WithCallback in order to receive messages about not matching rules.
type Rules ¶
type Rules struct {
// contains filtered or unexported fields
}
Rules contains a compiled YARA ruleset.
func Compile ¶
Compile compiles rules and an (optional) set of variables into a Rules object in a single step.
func MustCompile ¶
MustCompile is like Compile but panics if the rules and optional variables can't be compiled. Like regexp.MustCompile, it allows for simple, safe initialization of global or test data.
func (*Rules) DefineVariable ¶
DefineVariable defines a named variable for use by the compiler. Boolean, int64, float64, and string types are supported.
func (*Rules) Destroy ¶
func (r *Rules) Destroy()
Destroy destroys the YARA data structure representing a ruleset. Since a Finalizer for the underlying YR_RULES structure is automatically set up on creation, it should not be necessary to explicitly call this method.
func (*Rules) GetMostCostlyRules ¶
GetMostCostlyRules returns the top n rules according to their cost. The cost is calculated according to the time spend in matching the rule's strings and evaluating its condition. If the same Rules are used for scanning multiple files, buffers or processes the costs are accumulated.
func (*Rules) ResetCosts ¶
func (r *Rules) ResetCosts()
ResetCosts resets the rules' cost counters to zero. The cost computation is cumulative, which means that everytime you scan some data with a set of Rules the counters are incremented according to the time spent by each rule, those counters are never reset to zero unless you call this function.
func (*Rules) ScanFile ¶
func (r *Rules) ScanFile(filename string, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
ScanFile scans a file using the ruleset, returning matches via a list of MatchRule objects.
func (*Rules) ScanFileDescriptor ¶
func (r *Rules) ScanFileDescriptor(fd uintptr, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
ScanFileDescriptor scans a file using the ruleset, returning matches via a list of MatchRule objects.
func (*Rules) ScanFileDescriptorWithCallback ¶
func (r *Rules) ScanFileDescriptorWithCallback(fd uintptr, flags ScanFlags, timeout time.Duration, cb Callback) (err error)
ScanFileDescriptorWithCallback scans a file using the ruleset, calling methods on the ScanCallback object for the various events generated from libyara.
func (*Rules) ScanFileWithCallback ¶
func (r *Rules) ScanFileWithCallback(filename string, flags ScanFlags, timeout time.Duration, cb Callback) (err error)
ScanFileWithCallback scans a file using the ruleset, calling methods on the ScanCallback object for the various events generated from libyara.
func (*Rules) ScanMem ¶
func (r *Rules) ScanMem(buf []byte, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
ScanMem scans an in-memory buffer using the ruleset, returning matches via a list of MatchRule objects.
func (*Rules) ScanMemWithCallback ¶
func (r *Rules) ScanMemWithCallback(buf []byte, flags ScanFlags, timeout time.Duration, cb Callback) (err error)
ScanMemWithCallback scans an in-memory buffer using the ruleset, calling methods on the ScanCallback object for the various events generated from libyara.
func (*Rules) ScanProc ¶
func (r *Rules) ScanProc(pid int, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
ScanProc scans a live process using the ruleset, returning matches via a list of MatchRule objects.
type ScanFinishedCallback ¶
ScanFinishedCallback is the interface that must satisfy the object passed to Scan*WithCallback in order to receive a message when the scan finishes.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
A Scanner allows scanning files, in-memory data and processes using the compiled rules built with a Compiler.
func NewScanner ¶
NewScanner creates a scanner for scanning files, in-memory data or processes with the provided Rules.
func (*Scanner) DefineVariable ¶
DefineVariable defines a named variable for use by the scanner. Boolean, int64, float64, and string types are supported.
func (*Scanner) Destroy ¶
func (s *Scanner) Destroy()
Destroy destroys the YARA data structure representing a scanner. Since a Finalizer for the underlying YR_SCANNER structure is automatically set up on creation, it should not be necessary to explicitly call this method.
func (*Scanner) GetLastErrorRule ¶
GetLastErrorRule returns the rule that caused the last scanner error.
func (*Scanner) GetLastErrorString ¶
GetLastErrorString returns the string that caused the last scanner error.
func (*Scanner) ScanMem ¶
func (s *Scanner) ScanMem(buf []byte, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error)
ScanMem scans an in-memory buffer using the scanner, returning matches via a list of MatchRule objects.
func (*Scanner) ScanMemWithCallback ¶
func (s *Scanner) ScanMemWithCallback(buf []byte, flags ScanFlags, timeout time.Duration, cb Callback) (err error)
ScanMemWithCallback scans an in-memory buffer using the scanner, calling methods on the ScanCallback object for the various events generated from libyara.
type String ¶
type String struct {
// contains filtered or unexported fields
}
String represents a string as part of a rule
func (*String) Identifier ¶
Identifier returns the string's name
Source Files
¶
- callback-util.go
- cgo.go
- compiler.go
- compiler_yara37.go
- compiler_yara38.go
- error.go
- error_yara34.go
- error_yara35.go
- error_yara36.go
- error_yara37.go
- keepalive_go17.go
- main.go
- object.go
- rule.go
- rule_yara37.go
- rules.go
- rules_callback.go
- rules_yara311.go
- rules_yara34.go
- rules_yara38.go
- scanner.go
- stream.go
- util.go