binary

package
v0.0.3-pre Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPclntabMagic

func IsPclntabMagic(v uint32) bool

IsPclntabMagic returns true if the 4-byte value matches any known pclntab magic.

func ScanForPclntab

func ScanForPclntab(data []byte) int

ScanForPclntab searches data for a gopclntab magic at any 4-byte aligned offset. Returns the offset within data, or -1 if not found. Validates that the header looks like a real pclntab (pad bytes zero, valid ptrSize).

Types

type Binary

type Binary interface {
	// Section returns raw bytes for the named section.
	Section(name string) ([]byte, error)
	// SectionVA returns the virtual address of a section.
	SectionVA(name string) (uint64, error)
	// TextSectionRange returns (startVA, endVA) for the executable text section.
	TextSectionRange() (uint64, uint64, error)
	// ImageBase returns the preferred load address.
	ImageBase() uint64
	// GoVersion returns the embedded Go version string if detectable.
	GoVersion() string
	// Format returns "PE" or "ELF".
	Format() string
	// Arch returns the architecture string.
	Arch() string
	// Size returns the file size in bytes.
	Size() int64
	// Path returns the file path.
	Path() string
	// FindGopclntab searches all sections for gopclntab magic bytes.
	// Needed for PE binaries where gopclntab may not be in its own section.
	FindGopclntab() ([]byte, uint64, error)
	// Close releases file resources.
	Close() error
}

Binary is the platform-agnostic interface over PE and ELF files.

func Open

func Open(path string) (Binary, error)

Open detects the binary format and returns the appropriate loader.

type ELFBinary

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

ELFBinary implements Binary for Linux ELF files.

func (*ELFBinary) Arch

func (b *ELFBinary) Arch() string

func (*ELFBinary) Close

func (b *ELFBinary) Close() error

func (*ELFBinary) DynSymbols

func (b *ELFBinary) DynSymbols() map[uint64]string

DynSymbols returns name->addr map of dynamic symbols (for PLT resolution).

func (*ELFBinary) FindGopclntab

func (b *ELFBinary) FindGopclntab() ([]byte, uint64, error)

func (*ELFBinary) Format

func (b *ELFBinary) Format() string

func (*ELFBinary) GoVersion

func (b *ELFBinary) GoVersion() string

func (*ELFBinary) ImageBase

func (b *ELFBinary) ImageBase() uint64

func (*ELFBinary) Path

func (b *ELFBinary) Path() string

func (*ELFBinary) Section

func (b *ELFBinary) Section(name string) ([]byte, error)

func (*ELFBinary) SectionVA

func (b *ELFBinary) SectionVA(name string) (uint64, error)

func (*ELFBinary) Size

func (b *ELFBinary) Size() int64

func (*ELFBinary) TextSectionRange

func (b *ELFBinary) TextSectionRange() (uint64, uint64, error)
func (b *ELFBinary) TypeLinks() ([]byte, uint64, error)

TypeLinks returns the raw bytes of the .typelinks section, if present.

type PEBinary

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

PEBinary implements Binary for Windows PE files.

func (*PEBinary) Arch

func (b *PEBinary) Arch() string

func (*PEBinary) Close

func (b *PEBinary) Close() error

func (*PEBinary) FindGopclntab

func (b *PEBinary) FindGopclntab() ([]byte, uint64, error)

func (*PEBinary) Format

func (b *PEBinary) Format() string

func (*PEBinary) GoVersion

func (b *PEBinary) GoVersion() string

func (*PEBinary) ImageBase

func (b *PEBinary) ImageBase() uint64

func (*PEBinary) Path

func (b *PEBinary) Path() string

func (*PEBinary) Section

func (b *PEBinary) Section(name string) ([]byte, error)

func (*PEBinary) SectionVA

func (b *PEBinary) SectionVA(name string) (uint64, error)

func (*PEBinary) Size

func (b *PEBinary) Size() int64

func (*PEBinary) TextSectionRange

func (b *PEBinary) TextSectionRange() (uint64, uint64, error)

Jump to

Keyboard shortcuts

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