binary

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package binary inspects native executable and shared-object files and reports their format, architecture, dynamic dependencies, and toolchain producer strings.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnrecognized = errors.New("unrecognized native object format")

ErrUnrecognized is returned when the input is not a supported native object format.

Functions

This section is empty.

Types

type GoBuild

type GoBuild struct {
	Version string   `json:"version"`
	Path    string   `json:"path,omitempty"`
	Main    string   `json:"main,omitempty"`
	Deps    []string `json:"deps,omitempty"`
}

GoBuild is the subset of debug/buildinfo exposed in the report.

type Hint

type Hint struct {
	Library string `json:"library"`
	Version string `json:"version,omitempty"`
	Match   string `json:"match"`
}

Hint is a heuristic match for a statically-linked library.

type Object

type Object struct {
	// Path is the filesystem path the object was read from.
	Path string `json:"path"`

	// Format is the container format: "elf", "mach-o", "mach-o-universal",
	// or "pe".
	Format string `json:"format"`

	// Arch is the target architecture in GOARCH form where a mapping
	// exists, otherwise the format's native name. For universal Mach-O
	// binaries it lists each slice separated by "/".
	Arch string `json:"arch,omitempty"`

	// SOName is the object's declared install name: DT_SONAME for ELF,
	// LC_ID_DYLIB for Mach-O.
	SOName string `json:"soname,omitempty"`

	// Needed lists dynamic dependencies: DT_NEEDED for ELF, LC_LOAD_DYLIB
	// and LC_LOAD_WEAK_DYLIB for Mach-O, and the PE import directory.
	Needed []string `json:"needed,omitempty"`

	// Producer lists toolchain identification strings recovered from the
	// object: the ELF .comment section (GCC, clang, and rustc all write
	// there), Mach-O LC_BUILD_VERSION, and the Go version when build info
	// is present.
	Producer []string `json:"producer,omitempty"`

	// Go is set when the object was produced by the Go toolchain and
	// carries embedded build metadata.
	Go *GoBuild `json:"go,omitempty"`

	// Static lists libraries that appear to be statically linked into the
	// object, inferred from version banners in read-only data. These are
	// heuristic matches and should be reported as low confidence.
	Static []Hint `json:"static,omitempty"`
}

Object describes a single native object file.

func Inspect

func Inspect(path string) (*Object, error)

Inspect opens the file at path and returns its native object metadata.

func InspectReader

func InspectReader(r io.ReaderAt, size int64) (*Object, error)

InspectReader reads a native object from r. All reads are confined to the first size bytes.

Jump to

Keyboard shortcuts

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