github.com/google/osv-scalibr@v0.4.1/extractor/filesystem/ffa/unknownbinariesextr/unknownbinariesextr.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package unknownbinariesextr identifies binary files on the filesystem and adds them as packages.
    16  package unknownbinariesextr
    17  
    18  import (
    19  	"context"
    20  
    21  	//nolint:gosec //md5 used to identify files, not for security purposes
    22  	"github.com/google/osv-scalibr/extractor"
    23  	"github.com/google/osv-scalibr/extractor/filesystem"
    24  	"github.com/google/osv-scalibr/inventory"
    25  	"github.com/google/osv-scalibr/plugin"
    26  )
    27  
    28  const (
    29  	// Name is the unique name of this extractor.
    30  	Name = "ffa/unknownbinaries"
    31  )
    32  
    33  // Extractor finds unknown binaries on the filesystem
    34  type Extractor struct {
    35  }
    36  
    37  // Name of the extractor.
    38  func (e *Extractor) Name() string { return Name }
    39  
    40  // Version of the extractor.
    41  func (e *Extractor) Version() int { return 0 }
    42  
    43  // Requirements of the extractor.
    44  func (e *Extractor) Requirements() *plugin.Capabilities {
    45  	return &plugin.Capabilities{
    46  		OS: plugin.OSUnix,
    47  	}
    48  }
    49  
    50  // FileRequired returns true for likely directories to contain vendored c/c++ code
    51  func (e *Extractor) FileRequired(fapi filesystem.FileAPI) bool {
    52  	return filesystem.IsInterestingExecutable(fapi)
    53  }
    54  
    55  // Extract determines the most likely package version from the directory and returns them as
    56  // package entries with "Location" filled in.
    57  func (e *Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) (inventory.Inventory, error) {
    58  	return inventory.Inventory{
    59  		Packages: []*extractor.Package{
    60  			{
    61  				Locations: []string{input.Path},
    62  			},
    63  		}}, nil
    64  }
    65  
    66  var _ filesystem.Extractor = &Extractor{}