binary

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 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

Index

Constants

View Source
const (
	// GOOS labels.
	LINUX  = "linux"
	DARWIN = "darwin"
	WIN    = "windows"
)
View Source
const (
	MachO32Magic   uint32 = 0xfeedface // 32 bit, big endian
	MachO64Magic   uint32 = 0xfeedfacf // 64 bit, big endian
	MachO32LIMagic uint32 = 0xcefaedfe // 32 bit, little endian
	MachO64LIMagic uint32 = 0xcffaedfe // 64 bit, little endian
	MachOFat       uint32 = 0xcafebabe // Universal Binary
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Binary

type Binary struct {
	// contains filtered or unexported fields
}

Binary is the base type of the package. It abstracts a binary executable.

func New

func New(filePath string) (bin *Binary, err error)

New creates a new binary instance.

func NewWithOptions

func NewWithOptions(filePath string, opts *Options) (bin *Binary, err error)

NewWithOptions creates a new binary with the specified options.

func (*Binary) Arch

func (b *Binary) Arch() string

Arch returns a string with the GOARCH label of the file.

func (*Binary) ContainsStrings added in v0.10.0

func (b *Binary) ContainsStrings(s ...string) (match bool, err error)

ContainsStrings searches the printable strings un a binary file.

func (*Binary) LinkMode added in v0.15.0

func (b *Binary) LinkMode() (LinkMode, error)

LinkMode returns the linking mode of the binary.

func (*Binary) OS

func (b *Binary) OS() string

OS returns a string with the GOOS label of the binary file.

func (*Binary) SetImplementation

func (b *Binary) SetImplementation(impl binaryImplementation)

SetImplementation sets the implementation to handle this sort of executable.

type ELFBinary

type ELFBinary struct {
	Header  *ELFHeader
	Options *Options
}

ELFBinary abstracts a binary in ELF format.

func NewELFBinary

func NewELFBinary(filePath string, opts *Options) (*ELFBinary, error)

NewELFBinary opens a file and returns an ELF binary if it is one.

func (*ELFBinary) Arch

func (elf *ELFBinary) Arch() string

Arch return the GOOS label of the binary.

func (*ELFBinary) LinkMode added in v0.15.0

func (elf *ELFBinary) LinkMode() (LinkMode, error)

LinkMode returns the linking mode of the binary.

func (*ELFBinary) OS

func (elf *ELFBinary) OS() string

OS returns the GOOS label for the operating system.

type ELFHeader

type ELFHeader struct {
	WordFlag uint8 // Flag: 32 or 64 bit binary

	OSABI      uint8 // Binary Interface
	ABIVersion uint8 // ABI Version

	EType    uint16 // Executable Type: Executable, relocatable, etc
	EMachine uint16 // Machine architecture
	// contains filtered or unexported fields
}

ELFHeader abstracts the data we need from the elf header.

func GetELFHeader

func GetELFHeader(path string) (*ELFHeader, error)

GetELFHeader returns the header if the binary is and EF binary.

func (*ELFHeader) MachineType

func (eh *ELFHeader) MachineType() string

MachineType returns a string with the architecture moniker.

func (*ELFHeader) String

func (eh *ELFHeader) String() string

String returns the relevant info of the header as a string.

func (*ELFHeader) WordLength

func (eh *ELFHeader) WordLength() int

WordLength returns either 32 or 64 for 32bit or 64 bit architectures.

type Header interface {
	MachineType() string
	String() string
	WordLength() int
}

Header is a struct that captures the header of a binary executable.

type LinkMode added in v0.15.0

type LinkMode string

LinkMode is the enum for all available linking modes.

const (
	LinkModeUnknown LinkMode = "unknown"
	LinkModeStatic  LinkMode = "static"
	LinkModeDynamic LinkMode = "dynamic"
)

type MachOBinary

type MachOBinary struct {
	Header  *MachOHeader
	Options *Options
}

MachOBinary is an abstraction for a Mach-O executable.

func NewMachOBinary

func NewMachOBinary(filePath string, opts *Options) (*MachOBinary, error)

NewMachOBinary returns a Mach-O binary if the specified file is one.

func (*MachOBinary) Arch

func (macho *MachOBinary) Arch() string

Arch returns a string with the GOARCH label of the file.

func (*MachOBinary) LinkMode added in v0.15.0

func (macho *MachOBinary) LinkMode() (LinkMode, error)

LinkMode returns the linking mode of the binary.

func (*MachOBinary) OS

func (macho *MachOBinary) OS() string

OS returns a string with the GOOS label of the binary file.

type MachOHeader

type MachOHeader struct {
	Magic  uint32
	CPU    uint32
	SubCPU uint32
}

MachOHeader is a structure to capture the data we need from the binary header.

func GetMachOHeader

func GetMachOHeader(path string) (*MachOHeader, error)

GetMachOHeader returns a struct with the executable header information.

func (*MachOHeader) MachineType

func (machoh *MachOHeader) MachineType() string

MachineType returns the architecture as a GOARCH label.

func (*MachOHeader) String

func (machoh *MachOHeader) String() string

String returns the header information as a string.

func (*MachOHeader) WordLength

func (machoh *MachOHeader) WordLength() int

WordLength returns an integer indicating if this is a 32 or 64bit binary.

type Options

type Options struct {
	Path string
}

Options to control the binary checker.

type PEBinary

type PEBinary struct {
	Header  *PEHeader
	Options *Options
}

PEBinary is a struct that abstracts a Windows Portable Executable.

func NewPEBinary

func NewPEBinary(filePath string, opts *Options) (bin *PEBinary, err error)

NewPEBinary Returns a binary implementation for a Windows executable.

func (*PEBinary) Arch

func (pe *PEBinary) Arch() string

Arch return the architecture.

func (*PEBinary) LinkMode added in v0.15.0

func (pe *PEBinary) LinkMode() (LinkMode, error)

LinkMode returns the linking mode of the binary.

func (*PEBinary) OS

func (pe *PEBinary) OS() string

OS returns the operating system of the binary.

type PEFileHeader

type PEFileHeader struct {
	Machine              uint16
	NumberOfSections     uint16
	TimeDateStamp        uint32
	PointerToSymbolTable uint32
	NumberOfSymbols      uint32
	SizeOfOptionalHeader uint16
	Characteristics      uint16
}

PEFileHeader captures the header information of the executable.

type PEHeader

type PEHeader struct {
	Machine uint16
	Magic   uint16
}

PEHeader captures the header information of the executable.

func GetPEHeader

func GetPEHeader(path string) (*PEHeader, error)

GetPEHeader returns a portable executable header from the specified file.

func (*PEHeader) MachineType

func (peh *PEHeader) MachineType() string

MachineType returns the moniker of the binary architecture.

func (*PEHeader) String

func (peh *PEHeader) String() string

Return the header information as a string.

func (*PEHeader) WordLength

func (peh *PEHeader) WordLength() int

WordLength Returns an integer indicating if it's a 64 or 32 bit binary.

type PEOptionalHeader

type PEOptionalHeader struct {
	Magic uint16
}

PEOptionalHeader we only care about the magic number to determine the binary wordsize.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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