/
storeOutputPlugin.go
63 lines (54 loc) · 1.52 KB
/
storeOutputPlugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package elementary
import (
"github.com/forensicanalysis/elementary/pluginlib"
"github.com/forensicanalysis/forensicstore"
)
var (
AddToStoreParameter = &pluginlib.Parameter{
Name: "add-to-store",
Description: "output to store",
Type: pluginlib.Bool,
Value: false,
Required: false,
}
ForensicStoreParameter = &pluginlib.Parameter{
Name: "forensicstore",
Type: pluginlib.Path,
Required: true,
Argument: true,
}
)
type StoreOutputPlugin struct {
Internal pluginlib.Plugin
}
func (s *StoreOutputPlugin) Name() string {
return s.Internal.Name()
}
func (s *StoreOutputPlugin) Short() string {
return s.Internal.Short()
}
func (s *StoreOutputPlugin) Parameter() pluginlib.ParameterList {
pl := append(s.Internal.Parameter(), AddToStoreParameter)
_, err := s.Internal.Parameter().Get("forensicstore")
if err != nil {
return append(pl, ForensicStoreParameter)
}
return pl
}
func (s *StoreOutputPlugin) Output() *pluginlib.Config {
return s.Internal.Output()
}
func (s *StoreOutputPlugin) Run(p pluginlib.Plugin, writer pluginlib.LineWriter) error {
path := p.Parameter().StringValue("forensicstore")
store, teardown, err := forensicstore.Open(path)
if err != nil {
return err
}
defer teardown()
if p.Parameter().BoolValue("add-to-store") {
forensicStoreOutput := NewForensicStoreOutput(store)
writer = &pluginlib.MultiLineWriter{LineWriter: []pluginlib.LineWriter{writer, forensicStoreOutput}}
defer forensicStoreOutput.WriteFooter()
}
return s.Internal.Run(p, writer)
}