Overview
Package macho implements access to Mach-O object files.
Index
- Constants
- type Cpu
- type DylibCmd
- type DysymtabCmd
- type FatArchHeader
- type FileHeader
- type LoadBytes
- type LoadCmd
- type Nlist64
- type RegsAMD64
- type RelocTypeARM
- type RelocTypeGeneric
- type Rpath
- type Section
- type Section64
- type Segment
- type Segment64
- type Symbol
- type SymtabCmd
- type Type
Constants
- const (
- FlagNoUndefs uint32 = 0x1
- FlagIncrLink = 0x2
- FlagDyldLink uint32 = 0x4
- FlagBindAtLoad = 0x8
- FlagPrebound uint32 = 0x10
- FlagSplitSegs = 0x20
- FlagLazyInit uint32 = 0x40
- FlagTwoLevel = 0x80
- FlagForceFlat uint32 = 0x100
- FlagNoMultiDefs = 0x200
- FlagNoFixPrebinding uint32 = 0x400
- FlagPrebindable = 0x800
- FlagAllModsBound uint32 = 0x1000
- FlagSubsectionsViaSymbols = 0x2000
- FlagCanonical uint32 = 0x4000
- FlagWeakDefines = 0x8000
- FlagBindsToWeak uint32 = 0x10000
- FlagAllowStackExecution = 0x20000
- FlagRootSafe uint32 = 0x40000
- FlagSetuidSafe = 0x80000
- FlagNoReexportedDylibs uint32 = 0x100000
- FlagPIE = 0x200000
- FlagDeadStrippableDylib uint32 = 0x400000
- FlagHasTLVDescriptors = 0x800000
- FlagNoHeapExecution uint32 = 0x1000000
- FlagAppExtensionSafe = 0x2000000
- )
Variables
- var ErrNotFat = &FormatError{0, "not a fat Mach-O file", }
ErrNotFat is returned from NewFatFile or OpenFat when the file is not a
universal binary but may be a thin binary, based on its magic number.
type Cpu
- type Cpu uint32
A Cpu is a Mach-O cpu type.
func (Cpu) GoString
- func (i Cpu) GoString()
func (Cpu) String
- func (i Cpu) String()
type Dylib
A Dylib represents a Mach-O load dynamic library command.
type
¶
A DylibCmd is a Mach-O load dynamic library command.
type
¶
- type Dysymtab struct {
- DysymtabCmd
- IndirectSyms [] // indices into Symtab.Syms
- }
A Dysymtab represents a Mach-O dynamic symbol table command.
type DysymtabCmd
A DysymtabCmd is a Mach-O dynamic symbol table command.
type FatArch
- type FatArch struct {
- FatArchHeader
- *
- }
A FatArch is a Mach-O File inside a FatFile.
type FatArchHeader
A FatArchHeader represents a fat header for a specific image architecture.
type FatFile
- type FatFile struct {
- Magic uint32
- Arches []
- // contains filtered or unexported fields
- }
A FatFile is a Mach-O universal binary that contains at least one architecture.
func NewFatFile
NewFatFile creates a new FatFile for accessing all the Mach-O images in a
universal binary. The Mach-O binary is expected to start at position 0 in the
ReaderAt.
func OpenFat
OpenFat opens the named file using os.Open and prepares it for use as a Mach-O
universal binary.
func (*FatFile)
¶
- func (ff *) Close() error
type
¶
A File represents an open Mach-O file.
func NewFile
NewFile creates a new File for accessing a Mach-O binary in an underlying
reader. The Mach-O binary is expected to start at position 0 in the ReaderAt.
func Open
Open opens the named file using os.Open and prepares it for use as a Mach-O
binary.
func (*File)
¶
- func (f *) Close() error
Close closes the File. If the File was created using NewFile directly instead of
Open, Close has no effect.
func (*File)
¶
DWARF returns the DWARF debug information for the Mach-O file.
- func (f *) ImportedLibraries() ([]string, )
ImportedLibraries returns the paths of all libraries referred to by the binary f
that are expected to be linked with the binary at dynamic link time.
func (*File) ImportedSymbols
ImportedSymbols returns the names of all symbols referred to by the binary f
that are expected to be satisfied by other libraries at dynamic load time.
func (*File)
¶
- func (f *) Section(name string) *
Section returns the first section with the given name, or nil if no such section
exists.
func (*File) Segment
Segment returns the first Segment with the given name, or nil if no such segment
exists.
A FileHeader represents a Mach-O file header.
type
¶
- type FormatError struct {
- // contains filtered or unexported fields
- }
FormatError is returned by some operations if the data does not have the correct
format for an object file.
func (*FormatError)
¶
- func (e *) Error() string
type
¶
- type Load interface {
- Raw() []
- }
A Load represents any Mach-O load command.
type LoadBytes
- type LoadBytes []byte
A LoadBytes is the uninterpreted bytes of a Mach-O load command.
func (LoadBytes)
¶
- func (b ) Raw() []byte
type
¶
- type LoadCmd
A LoadCmd is a Mach-O load command.
- const (
- LoadCmdSegment LoadCmd = 0x1
- LoadCmdSymtab = 0x2
- LoadCmdThread LoadCmd = 0x4
- LoadCmdUnixThread = 0x5 // thread+stack
- LoadCmdDysymtab LoadCmd = 0xb
- LoadCmdDylib = 0xc // load dylib command
- LoadCmdDylinker LoadCmd = 0xf // id dylinker command (not load dylinker command)
- LoadCmdSegment64 = 0x19
- LoadCmdRpath LoadCmd = 0x8000001c
- )
func (LoadCmd)
¶
- func (i ) GoString() string
func (LoadCmd)
¶
- func (i ) String() string
type
¶
An Nlist32 is a Mach-O 32-bit symbol table entry.
type Nlist64
An Nlist64 is a Mach-O 64-bit symbol table entry.
type
¶
Regs386 is the Mach-O 386 register structure.
type
¶
RegsAMD64 is the Mach-O AMD64 register structure.
type Reloc
- type Reloc struct {
- Addr uint32
- Value
- // when Scattered == false && Extern == true, Value is the symbol number.
- // when Scattered == false && Extern == false, Value is the section number.
- // when Scattered == true, Value is the value that this reloc refers to.
- Type uint8
- Len // 0=byte, 1=word, 2=long, 3=quad
- Pcrel bool
- Extern // valid if Scattered == false
- Scattered bool
- }
A Reloc represents a Mach-O relocation.
type
¶
- type RelocTypeARM
- const (
- ARM_RELOC_VANILLA RelocTypeARM = 0
- ARM_RELOC_PAIR = 1
- ARM_RELOC_SECTDIFF RelocTypeARM = 2
- ARM_RELOC_LOCAL_SECTDIFF = 3
- ARM_RELOC_PB_LA_PTR RelocTypeARM = 4
- ARM_RELOC_BR24 = 5
- ARM_THUMB_RELOC_BR22 RelocTypeARM = 6
- ARM_THUMB_32BIT_BRANCH = 7
- ARM_RELOC_HALF RelocTypeARM = 8
- ARM_RELOC_HALF_SECTDIFF = 9
- )
func (RelocTypeARM) GoString
- func (r RelocTypeARM) GoString()
func (RelocTypeARM) String
- func (i RelocTypeARM) String()
type RelocTypeARM64
- type RelocTypeARM64 int
- const (
- ARM64_RELOC_UNSIGNED = 0
- ARM64_RELOC_SUBTRACTOR RelocTypeARM64 = 1
- ARM64_RELOC_BRANCH26 = 2
- ARM64_RELOC_PAGE21 RelocTypeARM64 = 3
- ARM64_RELOC_PAGEOFF12 = 4
- ARM64_RELOC_GOT_LOAD_PAGE21 RelocTypeARM64 = 5
- ARM64_RELOC_GOT_LOAD_PAGEOFF12 = 6
- ARM64_RELOC_POINTER_TO_GOT RelocTypeARM64 = 7
- ARM64_RELOC_TLVP_LOAD_PAGE21 = 8
- ARM64_RELOC_TLVP_LOAD_PAGEOFF12 RelocTypeARM64 = 9
- ARM64_RELOC_ADDEND = 10
- )
- func (r RelocTypeARM64) GoString()
func (RelocTypeARM64) String
- func (i RelocTypeARM64) String()
type RelocTypeGeneric
- type RelocTypeGeneric int
- const (
- GENERIC_RELOC_VANILLA = 0
- GENERIC_RELOC_PAIR RelocTypeGeneric = 1
- GENERIC_RELOC_SECTDIFF = 2
- GENERIC_RELOC_PB_LA_PTR RelocTypeGeneric = 3
- GENERIC_RELOC_LOCAL_SECTDIFF = 4
- GENERIC_RELOC_TLV RelocTypeGeneric = 5
- )
func (RelocTypeGeneric)
¶
- func (r ) GoString() string
func (RelocTypeGeneric)
¶
type
¶
- type RelocTypeX86_64
- const (
- X86_64_RELOC_SIGNED RelocTypeX86_64 = 1
- X86_64_RELOC_BRANCH = 2
- X86_64_RELOC_GOT_LOAD RelocTypeX86_64 = 3
- X86_64_RELOC_GOT = 4
- X86_64_RELOC_SUBTRACTOR RelocTypeX86_64 = 5
- X86_64_RELOC_SIGNED_1 = 6
- X86_64_RELOC_SIGNED_2 RelocTypeX86_64 = 7
- X86_64_RELOC_SIGNED_4 = 8
- X86_64_RELOC_TLV RelocTypeX86_64 = 9
- )
func (RelocTypeX86_64)
¶
- func (r ) GoString() string
func (RelocTypeX86_64)
¶
- func (i ) String() string
- type Rpath struct {
- Path string
- }
A Rpath represents a Mach-O rpath command.
type
¶
- type RpathCmd struct {
- Cmd
- Len uint32
- Path
- }
A RpathCmd is a Mach-O rpath command.
type Section
- type Section struct {
- SectionHeader
- Relocs []
- // Embed ReaderAt for ReadAt method.
- // Do not embed SectionReader directly
- // to avoid having Read and Seek.
- // If a client wants Read and Seek it must use
- // Open() to avoid fighting over the seek offset
- // with other clients.
- io.
- // contains filtered or unexported fields
- }
func (*Section) Data
Data reads and returns the contents of the Mach-O section.
func (*Section)
¶
- func (s *) Open() io.
Open returns a new ReadSeeker reading the Mach-O section.
type Section32
A Section32 is a 32-bit Mach-O section header.
type
¶
A Section64 is a 64-bit Mach-O section header.
type
¶
type Segment
- type Segment struct {
- LoadBytes
- // Embed ReaderAt for ReadAt method.
- // Do not embed SectionReader directly
- // to avoid having Read and Seek.
- // If a client wants Read and Seek it must use
- // Open() to avoid fighting over the seek offset
- // with other clients.
- io.
- // contains filtered or unexported fields
- }
A Segment represents a Mach-O 32-bit or 64-bit load segment command.
func (*Segment) Data
Data reads and returns the contents of the segment.
func (*Segment)
¶
- func (s *) Open() io.
Open returns a new ReadSeeker reading the segment.
type Segment32
A Segment32 is a 32-bit Mach-O segment load command.
type
¶
A Segment64 is a 64-bit Mach-O segment load command.
type SegmentHeader
A SegmentHeader is the header for a Mach-O 32-bit or 64-bit load segment
command.
type
¶
A Symbol is a Mach-O 32-bit or 64-bit symbol table entry.
type Symtab
A Symtab represents a Mach-O symbol table command.
type
¶
A SymtabCmd is a Mach-O symbol table command.
type
¶
A Thread is a Mach-O thread state command.
- type Type
A Type is the Mach-O file type, e.g. an object file, executable, or dynamic
library.
- func (t Type) GoString()