Documentation
¶
Overview ¶
Package binary provides types for parsing and representing executable binaries.
Index ¶
Constants ¶
const ( NT_GNU_PROPERTY_TYPE_0 = 5 GNU_PROPERTY_X86_FEATURE_1_AND = 0xc0000002 GNU_PROPERTY_X86_FEATURE_1_IBT = 0x1 GNU_PROPERTY_X86_FEATURE_1_SHSTK = 0x2 GNU_PROPERTY_AARCH64_FEATURE_1_AND = 0xc0000000 GNU_PROPERTY_AARCH64_FEATURE_1_BTI = 0x1 GNU_PROPERTY_AARCH64_FEATURE_1_PAC = 0x2 )
GNU property constants for feature detection.
Variables ¶
var ( ARM64v83 = ISA{Major: 8, Minor: 3} ARM64v85 = ISA{Major: 8, Minor: 5} AMD64v1 = ISA{Major: 1} AMD64v2 = ISA{Major: 2} AMD64v3 = ISA{Major: 3} AMD64v4 = ISA{Major: 4} )
var ( PlatformAll = Platform{Architecture: ArchAll} PlatformAllX86 = Platform{Architecture: ArchAllX86} PlatformAllARM = Platform{Architecture: ArchAllARM} PlatformARM64v83 = Platform{Architecture: ArchARM64, MinISA: ARM64v83} PlatformARM64v85 = Platform{Architecture: ArchARM64, MinISA: ARM64v85} )
var ErrUnsupportedFormat = errors.New("unsupported binary format")
ErrUnsupportedFormat is returned when the file is not a supported binary format.
Functions ¶
This section is empty.
Types ¶
type Architecture ¶
type Architecture uint32
Architecture identifies CPU architecture as a bitmask, allowing combinations.
const ( ArchUnknown Architecture = 0 ArchX86 Architecture = 1 << 0 ArchAMD64 Architecture = 1 << 1 ArchARM Architecture = 1 << 2 ArchARM64 Architecture = 1 << 3 ArchRISCV Architecture = 1 << 4 ArchPPC64 Architecture = 1 << 5 ArchMIPS Architecture = 1 << 6 ArchS390X Architecture = 1 << 7 ArchAllX86 = ArchX86 | ArchAMD64 ArchAllARM = ArchARM | ArchARM64 ArchAll = ArchX86 | ArchAMD64 | ArchARM | ArchARM64 | ArchRISCV | ArchPPC64 | ArchMIPS | ArchS390X )
func ParseArchitecture ¶
func ParseArchitecture(s string) (Architecture, bool)
ParseArchitecture converts a string to Architecture. Returns false if unknown.
func (Architecture) Matches ¶
func (a Architecture) Matches(target Architecture) bool
Matches reports whether a has any overlap with target.
func (Architecture) String ¶
func (a Architecture) String() string
type Binary ¶
type Binary struct {
Format Format
Architecture Architecture
Bits BitWidth
Build toolchain.BuildInfo
LibC LibC
}
Binary holds common metadata for any executable format.
type ELFBinary ¶
type ELFBinary struct {
Binary
Type elf.Type
Progs []elf.Prog
Sections []elf.SectionHeader
// Symbols from .symtab section, or nil if missing/stripped.
Symbols []elf.Symbol
// DynSymbols from .dynsym section, or nil if missing.
DynSymbols []elf.Symbol
// DynEntries contains parsed entries from the .dynamic section.
// Exposed for custom rules that need direct access to dynamic tags
// beyond what HasDynFlag, HasDynTag, and DynString provide.
DynEntries []DynEntry
// contains filtered or unexported fields
}
ELFBinary represents a parsed ELF executable or shared library.
func ParseELF ¶
ParseELF parses an ELF binary. The caller owns the io.ReaderAt and must keep it open while ELFBinary is in use.
func ParseELFWithDetector ¶
ParseELFWithDetector parses an ELF binary using a custom compiler detector. The caller owns the io.ReaderAt and must keep it open while ELFBinary is in use.
func (*ELFBinary) HasDynFlag ¶
HasDynFlag reports whether a dynamic tag has the specified flag set.
func (*ELFBinary) HasGNUProperty ¶
HasGNUProperty reports whether the binary has a GNU property with the specified flag.
type ISA ¶
ISA represents an instruction set architecture version