gobinary

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	PropertyGOOS    = "goos"
	PropertyGOARCH  = "goarch"
	PropertyPackage = "go:package"
)

Property names recorded on the root node from the binary's build settings.

View Source
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

func ModuleSetFromBuildInfo(bi *debug.BuildInfo) *golang.ModuleSet

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 New

func New() *Decomposer

New returns a Go binary decomposer.

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, _ string, opts *api.DecomposerOptions) (*sbom.NodeList, error)

ExtractArtifact 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) 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL