-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathbinary.go
45 lines (35 loc) · 1.19 KB
/
binary.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
package binary
import (
"context"
"errors"
"os"
"golang.org/x/xerrors"
"github.com/aquasecurity/go-dep-parser/pkg/rust/binary"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/language"
"github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/aquasecurity/trivy/pkg/fanal/utils"
)
func init() {
analyzer.RegisterAnalyzer(&rustBinaryLibraryAnalyzer{})
}
const version = 1
type rustBinaryLibraryAnalyzer struct{}
func (a rustBinaryLibraryAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
res, err := language.Analyze(types.RustBinary, input.FilePath, input.Content, binary.NewParser())
if errors.Is(err, binary.ErrUnrecognizedExe) || errors.Is(err, binary.ErrNonRustBinary) {
return nil, nil
} else if err != nil {
return nil, xerrors.Errorf("rust binary parse error: %w", err)
}
return res, nil
}
func (a rustBinaryLibraryAnalyzer) Required(_ string, fileInfo os.FileInfo) bool {
return utils.IsExecutable(fileInfo)
}
func (a rustBinaryLibraryAnalyzer) Type() analyzer.Type {
return analyzer.TypeRustBinary
}
func (a rustBinaryLibraryAnalyzer) Version() int {
return version
}