2018-06-05 20:53:08 +00:00
|
|
|
package walker
|
|
|
|
|
|
|
|
import (
|
2018-06-05 21:34:58 +00:00
|
|
|
"fmt"
|
2018-06-05 20:53:08 +00:00
|
|
|
"os"
|
2018-06-05 21:34:58 +00:00
|
|
|
"plugin"
|
2018-06-05 20:53:08 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2018-06-05 21:34:58 +00:00
|
|
|
// LoadPlugin loads the file path and returns a Fuzzer
|
|
|
|
func LoadPlugin(path string) (Fuzzer, error) {
|
|
|
|
p, err := plugin.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-06-06 14:42:39 +00:00
|
|
|
sym, err := p.Lookup("NewFuzzer")
|
2018-06-05 21:34:58 +00:00
|
|
|
if err != nil {
|
2018-06-06 14:42:39 +00:00
|
|
|
return nil, fmt.Errorf("LoadPlugin: %q", err)
|
2018-06-05 21:34:58 +00:00
|
|
|
}
|
2018-06-06 14:42:39 +00:00
|
|
|
nf, ok := sym.(func() (Fuzzer, error))
|
2018-06-05 21:34:58 +00:00
|
|
|
if !ok {
|
2018-06-06 14:42:39 +00:00
|
|
|
return nil, fmt.Errorf("LoadPlugin: plugin at %q did not provide a NewFuzzer function", path)
|
2018-06-05 21:34:58 +00:00
|
|
|
}
|
2018-06-06 14:42:39 +00:00
|
|
|
return nf()
|
2018-06-05 21:34:58 +00:00
|
|
|
}
|
|
|
|
|
2018-06-06 14:42:39 +00:00
|
|
|
// NewFuzzer initializes a new Fuzzer
|
|
|
|
type NewFuzzer func() (Fuzzer, error)
|
|
|
|
|
2018-06-05 21:34:58 +00:00
|
|
|
// Fuzzer is a struct that produces a FuzzFunc
|
|
|
|
type Fuzzer interface {
|
|
|
|
Name() string
|
2018-06-06 14:42:39 +00:00
|
|
|
Func(path string, info os.FileInfo, timeout time.Duration) error
|
2018-06-05 21:34:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FuzzFunc is like filepath.WalkerFunc, but for poking at `path`
|
2018-06-05 20:53:08 +00:00
|
|
|
type FuzzFunc func(path string, info os.FileInfo, timeout time.Duration) error
|