Documentation
¶
Overview ¶
Package gobinary implements the artifact decomposer for Go executables. Every binary the Go toolchain links since module support carries its build information: the main module, the exact set of modules linked into it with their versions and checksums, the Go release and the build settings. The decomposer reads that record with debug/buildinfo and renders it through the Go source decomposer's graph builder, so a binary and the codebase it came from produce the same shape of graph.
Index ¶
- Constants
- func ModuleSetFromBuildInfo(bi *debug.BuildInfo) *golang.ModuleSet
- type Decomposer
- func (d *Decomposer) DefaultOptions() any
- func (d *Decomposer) DefaultSubjects() []string
- func (d *Decomposer) Extract(opts *api.DecomposerOptions) (*sbom.NodeList, error)
- func (d *Decomposer) ExtractArtifact(ra io.ReaderAt, path string, opts *api.DecomposerOptions) (*sbom.NodeList, error)
- func (d *Decomposer) ExtractArtifactWithContext(ctx context.Context, ra io.ReaderAt, _ string, opts *api.DecomposerOptions) (*sbom.NodeList, error)
- func (d *Decomposer) GenerationContext() api.GenerationContext
- func (d *Decomposer) Matches(_ fs.FileInfo, header []byte) bool
- func (d *Decomposer) Name() string
- func (d *Decomposer) Requirements(*api.DecomposerOptions) []api.Requirement
Constants ¶
const ( PropertyGOOS = "goos" PropertyGOARCH = "goarch" PropertyPackage = "go:package" )
Property names recorded on the root node from the binary's build settings.
const Name = "gobinary"
Name is the name the decomposer is registered under in the artifact unpacker, and the key options refer to it by.
Variables ¶
This section is empty.
Functions ¶
func ModuleSetFromBuildInfo ¶
ModuleSetFromBuildInfo reduces a binary's build information to the module set the Go graph builder renders. The main module is the root; when the binary was built outside a module, the main package path stands in for it. Every linked module is both required by the root and a member of the set: build information does not say which modules the main module requires directly, so the honest graph is flat from the root, with edges among the linked modules resolved by the builder when networking allows.
Replaced modules enter the set as what was actually linked, the replacement, with the original recorded in Replaces so requirements naming the original resolve to it. A replacement by a local directory has no version or checksum worth recording, so the original module is kept instead, as the go.mod reader does.
Types ¶
type Decomposer ¶
type Decomposer struct {
// contains filtered or unexported fields
}
Decomposer reads dependency data out of Go executables.
func (*Decomposer) DefaultOptions ¶
func (d *Decomposer) DefaultOptions() any
DefaultOptions returns the options of the Go source decomposer, which does the graph resolution and license enrichment. Set them as this decomposer's driver options to control the module proxy, concurrency and cache use.
func (*Decomposer) DefaultSubjects ¶
func (d *Decomposer) DefaultSubjects() []string
DefaultSubjects lists the parents the decomposer runs under by default: a container image or a system root, where executables are the payload. A codebase is not among them, so `unpack extract` does not probe binaries it finds lying around a source tree unless asked to.
func (*Decomposer) Extract ¶
func (d *Decomposer) Extract(opts *api.DecomposerOptions) (*sbom.NodeList, error)
Extract reads the executable at opts.WorkDir. It is the plain api.Decomposer entry point; the artifact unpacker uses ExtractArtifact.
func (*Decomposer) ExtractArtifact ¶
func (d *Decomposer) ExtractArtifact(ra io.ReaderAt, path string, opts *api.DecomposerOptions) (*sbom.NodeList, error)
ExtractArtifact is ExtractArtifactWithContext with a background context, for a caller that has none to give.
func (*Decomposer) ExtractArtifactWithContext ¶ added in v0.4.1
func (d *Decomposer) ExtractArtifactWithContext( ctx context.Context, ra io.ReaderAt, _ string, opts *api.DecomposerOptions, ) (*sbom.NodeList, error)
ExtractArtifactWithContext reads the build information embedded in the executable and returns the program's module graph: the main module as the root, with the modules linked into the binary as its dependencies. Returns (nil, nil) when the file carries no Go build information, which is what any executable not built by the Go toolchain looks like.
func (*Decomposer) GenerationContext ¶ added in v0.4.1
func (d *Decomposer) GenerationContext() api.GenerationContext
GenerationContext says in what context the decomposer's data is read: the build information embedded in a binary already built.
func (*Decomposer) Matches ¶
func (d *Decomposer) Matches(_ fs.FileInfo, header []byte) bool
Matches reports whether the file looks like an executable in one of the formats debug/buildinfo reads: ELF, PE or Mach-O. The check is on the magic number alone; whether the executable is a Go program is settled by ExtractArtifact.
func (*Decomposer) Name ¶
func (d *Decomposer) Name() string
Name returns the decomposer's registration name.
func (*Decomposer) Requirements ¶
func (d *Decomposer) Requirements(*api.DecomposerOptions) []api.Requirement
Requirements returns nothing: the decomposer is pure Go.