Overview

Package macho implements access to Mach-O object files.

Index

file.go reloctype.go

Constants

  1. const (
  2. FlagNoUndefs uint32 = 0x1
  3. FlagIncrLink = 0x2
  4. FlagDyldLink uint32 = 0x4
  5. FlagBindAtLoad = 0x8
  6. FlagPrebound uint32 = 0x10
  7. FlagSplitSegs = 0x20
  8. FlagLazyInit uint32 = 0x40
  9. FlagTwoLevel = 0x80
  10. FlagForceFlat uint32 = 0x100
  11. FlagNoMultiDefs = 0x200
  12. FlagNoFixPrebinding uint32 = 0x400
  13. FlagPrebindable = 0x800
  14. FlagAllModsBound uint32 = 0x1000
  15. FlagSubsectionsViaSymbols = 0x2000
  16. FlagCanonical uint32 = 0x4000
  17. FlagWeakDefines = 0x8000
  18. FlagBindsToWeak uint32 = 0x10000
  19. FlagAllowStackExecution = 0x20000
  20. FlagRootSafe uint32 = 0x40000
  21. FlagSetuidSafe = 0x80000
  22. FlagNoReexportedDylibs uint32 = 0x100000
  23. FlagPIE = 0x200000
  24. FlagDeadStrippableDylib uint32 = 0x400000
  25. FlagHasTLVDescriptors = 0x800000
  26. FlagNoHeapExecution uint32 = 0x1000000
  27. FlagAppExtensionSafe = 0x2000000
  28. )

Variables

  1. 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

  1. type Cpu uint32

A Cpu is a Mach-O cpu type.

  1. const (
  2. Cpu386 = 7
  3. CpuAmd64 Cpu = | cpuArch64
  4. CpuArm Cpu = 12
  5. CpuPpc = 18
  6. CpuPpc64 Cpu = | cpuArch64
  7. )

func (Cpu) GoString

  1. func (i Cpu) GoString()

func (Cpu) String

  1. func (i Cpu) String()

type Dylib

  1. type Dylib struct {
  2. LoadBytes
  3. Name
  4. Time uint32
  5. CurrentVersion
  6. CompatVersion uint32
  7. }

A Dylib represents a Mach-O load dynamic library command.

type

  1. type DylibCmd struct {
  2. Cmd
  3. Len uint32
  4. Name
  5. Time uint32
  6. CurrentVersion
  7. CompatVersion uint32
  8. }

A DylibCmd is a Mach-O load dynamic library command.

type

  1. type Dysymtab struct {
  2. DysymtabCmd
  3. IndirectSyms [] // indices into Symtab.Syms
  4. }

A Dysymtab represents a Mach-O dynamic symbol table command.

type DysymtabCmd

  1. type DysymtabCmd struct {
  2. Cmd LoadCmd
  3. Len
  4. Ilocalsym uint32
  5. Nlocalsym
  6. Iextdefsym uint32
  7. Nextdefsym
  8. Iundefsym uint32
  9. Nundefsym
  10. Tocoffset uint32
  11. Ntoc
  12. Modtaboff uint32
  13. Nmodtab
  14. Extrefsymoff uint32
  15. Nextrefsyms
  16. Indirectsymoff uint32
  17. Nindirectsyms
  18. Extreloff uint32
  19. Nextrel
  20. Locreloff uint32
  21. Nlocrel
  22. }

A DysymtabCmd is a Mach-O dynamic symbol table command.

type FatArch

  1. type FatArch struct {
  2. FatArchHeader
  3. *
  4. }

A FatArch is a Mach-O File inside a FatFile.

type FatArchHeader

  1. type FatArchHeader struct {
  2. Cpu Cpu
  3. SubCpu
  4. Size uint32
  5. Align
  6. }

A FatArchHeader represents a fat header for a specific image architecture.

type FatFile

  1. type FatFile struct {
  2. Magic uint32
  3. Arches []
  4. // contains filtered or unexported fields
  5. }

A FatFile is a Mach-O universal binary that contains at least one architecture.

func NewFatFile

  1. func NewFatFile(r io.) (*FatFile, )

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

  1. func OpenFat(name string) (*, error)

OpenFat opens the named file using os.Open and prepares it for use as a Mach-O
universal binary.

func (*FatFile)

  1. func (ff *) Close() error

type

  1. type File struct {
  2. ByteOrder binary.
  3. Loads []Load
  4. Sections []*
  5.  
  6. Symtab *Symtab
  7. Dysymtab *
  8. // contains filtered or unexported fields
  9. }

A File represents an open Mach-O file.

func NewFile

  1. func NewFile(r io.) (*File, )

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

  1. func Open(name string) (*, error)

Open opens the named file using os.Open and prepares it for use as a Mach-O
binary.

func (*File)

  1. 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)

  1. func (f *) DWARF() (*dwarf., error)

DWARF returns the DWARF debug information for the Mach-O file.

  1. 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

  1. func (f *File) ImportedSymbols() ([], error)

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)

  1. func (f *) Section(name string) *

Section returns the first section with the given name, or nil if no such section
exists.

func (*File) Segment

  1. func (f *File) Segment(name ) *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

  1. type FormatError struct {
  2. // contains filtered or unexported fields
  3. }

FormatError is returned by some operations if the data does not have the correct
format for an object file.

func (*FormatError)

  1. func (e *) Error() string

type

  1. type Load interface {
  2. Raw() []
  3. }

A Load represents any Mach-O load command.

type LoadBytes

  1. type LoadBytes []byte

A LoadBytes is the uninterpreted bytes of a Mach-O load command.

func (LoadBytes)

  1. func (b ) Raw() []byte

type

  1. type LoadCmd

A LoadCmd is a Mach-O load command.

  1. const (
  2. LoadCmdSegment LoadCmd = 0x1
  3. LoadCmdSymtab = 0x2
  4. LoadCmdThread LoadCmd = 0x4
  5. LoadCmdUnixThread = 0x5 // thread+stack
  6. LoadCmdDysymtab LoadCmd = 0xb
  7. LoadCmdDylib = 0xc // load dylib command
  8. LoadCmdDylinker LoadCmd = 0xf // id dylinker command (not load dylinker command)
  9. LoadCmdSegment64 = 0x19
  10. LoadCmdRpath LoadCmd = 0x8000001c
  11. )

func (LoadCmd)

  1. func (i ) GoString() string

func (LoadCmd)

  1. func (i ) String() string

type

  1. type Nlist32 struct {
  2. Name
  3. Type uint8
  4. Sect
  5. Desc uint16
  6. Value
  7. }

An Nlist32 is a Mach-O 32-bit symbol table entry.

type Nlist64

  1. type Nlist64 struct {
  2. Name uint32
  3. Type
  4. Sect uint8
  5. Desc
  6. Value uint64
  7. }

An Nlist64 is a Mach-O 64-bit symbol table entry.

type

  1. type Regs386 struct {
  2. AX
  3. BX uint32
  4. CX
  5. DX uint32
  6. DI
  7. SI uint32
  8. BP
  9. SP uint32
  10. SS
  11. FLAGS uint32
  12. IP
  13. CS uint32
  14. DS
  15. ES uint32
  16. FS
  17. GS uint32
  18. }

Regs386 is the Mach-O 386 register structure.

type

  1. type RegsAMD64 struct {
  2. AX
  3. BX uint64
  4. CX
  5. DX uint64
  6. DI
  7. SI uint64
  8. BP
  9. SP uint64
  10. R8
  11. R9 uint64
  12. R10
  13. R11 uint64
  14. R12
  15. R13 uint64
  16. R14
  17. R15 uint64
  18. IP
  19. FLAGS uint64
  20. CS
  21. FS uint64
  22. GS
  23. }

RegsAMD64 is the Mach-O AMD64 register structure.

type Reloc

  1. type Reloc struct {
  2. Addr uint32
  3. Value
  4. // when Scattered == false && Extern == true, Value is the symbol number.
  5. // when Scattered == false && Extern == false, Value is the section number.
  6. // when Scattered == true, Value is the value that this reloc refers to.
  7. Type uint8
  8. Len // 0=byte, 1=word, 2=long, 3=quad
  9. Pcrel bool
  10. Extern // valid if Scattered == false
  11. Scattered bool
  12. }

A Reloc represents a Mach-O relocation.

type

  1. type RelocTypeARM
  1. const (
  2. ARM_RELOC_VANILLA RelocTypeARM = 0
  3. ARM_RELOC_PAIR = 1
  4. ARM_RELOC_SECTDIFF RelocTypeARM = 2
  5. ARM_RELOC_LOCAL_SECTDIFF = 3
  6. ARM_RELOC_PB_LA_PTR RelocTypeARM = 4
  7. ARM_RELOC_BR24 = 5
  8. ARM_THUMB_RELOC_BR22 RelocTypeARM = 6
  9. ARM_THUMB_32BIT_BRANCH = 7
  10. ARM_RELOC_HALF RelocTypeARM = 8
  11. ARM_RELOC_HALF_SECTDIFF = 9
  12. )

func (RelocTypeARM) GoString

  1. func (r RelocTypeARM) GoString()

func (RelocTypeARM) String

  1. func (i RelocTypeARM) String()

type RelocTypeARM64

  1. type RelocTypeARM64 int
  1. const (
  2. ARM64_RELOC_UNSIGNED = 0
  3. ARM64_RELOC_SUBTRACTOR RelocTypeARM64 = 1
  4. ARM64_RELOC_BRANCH26 = 2
  5. ARM64_RELOC_PAGE21 RelocTypeARM64 = 3
  6. ARM64_RELOC_PAGEOFF12 = 4
  7. ARM64_RELOC_GOT_LOAD_PAGE21 RelocTypeARM64 = 5
  8. ARM64_RELOC_GOT_LOAD_PAGEOFF12 = 6
  9. ARM64_RELOC_POINTER_TO_GOT RelocTypeARM64 = 7
  10. ARM64_RELOC_TLVP_LOAD_PAGE21 = 8
  11. ARM64_RELOC_TLVP_LOAD_PAGEOFF12 RelocTypeARM64 = 9
  12. ARM64_RELOC_ADDEND = 10
  13. )

  1. func (r RelocTypeARM64) GoString()

func (RelocTypeARM64) String

  1. func (i RelocTypeARM64) String()

type RelocTypeGeneric

  1. type RelocTypeGeneric int
  1. const (
  2. GENERIC_RELOC_VANILLA = 0
  3. GENERIC_RELOC_PAIR RelocTypeGeneric = 1
  4. GENERIC_RELOC_SECTDIFF = 2
  5. GENERIC_RELOC_PB_LA_PTR RelocTypeGeneric = 3
  6. GENERIC_RELOC_LOCAL_SECTDIFF = 4
  7. GENERIC_RELOC_TLV RelocTypeGeneric = 5
  8. )

func (RelocTypeGeneric)

  1. func (r ) GoString() string

func (RelocTypeGeneric)

type

  1. type RelocTypeX86_64
  1. const (
  2. X86_64_RELOC_SIGNED RelocTypeX86_64 = 1
  3. X86_64_RELOC_BRANCH = 2
  4. X86_64_RELOC_GOT_LOAD RelocTypeX86_64 = 3
  5. X86_64_RELOC_GOT = 4
  6. X86_64_RELOC_SUBTRACTOR RelocTypeX86_64 = 5
  7. X86_64_RELOC_SIGNED_1 = 6
  8. X86_64_RELOC_SIGNED_2 RelocTypeX86_64 = 7
  9. X86_64_RELOC_SIGNED_4 = 8
  10. X86_64_RELOC_TLV RelocTypeX86_64 = 9
  11. )

func (RelocTypeX86_64)

  1. func (r ) GoString() string

func (RelocTypeX86_64)

  1. func (i ) String() string

  1. type Rpath struct {
  2. Path string
  3. }

A Rpath represents a Mach-O rpath command.

type

  1. type RpathCmd struct {
  2. Cmd
  3. Len uint32
  4. Path
  5. }

A RpathCmd is a Mach-O rpath command.

type Section

  1. type Section struct {
  2. SectionHeader
  3. Relocs []
  4.  
  5. // Embed ReaderAt for ReadAt method.
  6. // Do not embed SectionReader directly
  7. // to avoid having Read and Seek.
  8. // If a client wants Read and Seek it must use
  9. // Open() to avoid fighting over the seek offset
  10. // with other clients.
  11. io.
  12. // contains filtered or unexported fields
  13. }

func (*Section) Data

  1. func (s *Section) Data() ([], error)

Data reads and returns the contents of the Mach-O section.

func (*Section)

  1. func (s *) Open() io.

Open returns a new ReadSeeker reading the Mach-O section.

type Section32

  1. type Section32 struct {
  2. Name [16]byte
  3. Seg [16]
  4. Addr uint32
  5. Size
  6. Offset uint32
  7. Align
  8. Reloff uint32
  9. Nreloc
  10. Flags uint32
  11. Reserve1
  12. Reserve2 uint32
  13. }

A Section32 is a 32-bit Mach-O section header.

type

  1. type Section64 struct {
  2. Name [16]
  3. Seg [16]byte
  4. Addr
  5. Size uint64
  6. Offset
  7. Align uint32
  8. Reloff
  9. Nreloc uint32
  10. Flags
  11. Reserve1 uint32
  12. Reserve2
  13. Reserve3 uint32
  14. }

A Section64 is a 64-bit Mach-O section header.

type

  1. type SectionHeader struct {
  2. Name
  3. Seg string
  4. Addr
  5. Size uint64
  6. Offset
  7. Align uint32
  8. Reloff
  9. Nreloc uint32
  10. Flags
  11. }

type Segment

  1. type Segment struct {
  2. LoadBytes
  3.  
  4. // Embed ReaderAt for ReadAt method.
  5. // Do not embed SectionReader directly
  6. // to avoid having Read and Seek.
  7. // If a client wants Read and Seek it must use
  8. // Open() to avoid fighting over the seek offset
  9. // with other clients.
  10. io.
  11. // contains filtered or unexported fields
  12. }

A Segment represents a Mach-O 32-bit or 64-bit load segment command.

func (*Segment) Data

  1. func (s *Segment) Data() ([], error)

Data reads and returns the contents of the segment.

func (*Segment)

  1. func (s *) Open() io.

Open returns a new ReadSeeker reading the segment.

type Segment32

  1. type Segment32 struct {
  2. Cmd LoadCmd
  3. Len
  4. Name [16]byte
  5. Addr
  6. Memsz uint32
  7. Offset
  8. Filesz uint32
  9. Maxprot
  10. Prot uint32
  11. Nsect
  12. Flag uint32
  13. }

A Segment32 is a 32-bit Mach-O segment load command.

type

  1. type Segment64 struct {
  2. Cmd
  3. Len uint32
  4. Name [16]
  5. Addr uint64
  6. Memsz
  7. Offset uint64
  8. Filesz
  9. Maxprot uint32
  10. Prot
  11. Nsect uint32
  12. Flag
  13. }

A Segment64 is a 64-bit Mach-O segment load command.

type SegmentHeader

  1. type SegmentHeader struct {
  2. Cmd LoadCmd
  3. Len
  4. Name string
  5. Addr
  6. Memsz uint64
  7. Offset
  8. Filesz uint64
  9. Maxprot
  10. Prot uint32
  11. Nsect
  12. Flag uint32
  13. }

A SegmentHeader is the header for a Mach-O 32-bit or 64-bit load segment
command.

type

  1. type Symbol struct {
  2. Name
  3. Type uint8
  4. Sect
  5. Desc uint16
  6. Value
  7. }

A Symbol is a Mach-O 32-bit or 64-bit symbol table entry.

type Symtab

  1. type Symtab struct {
  2. LoadBytes
  3. Syms []Symbol
  4. }

A Symtab represents a Mach-O symbol table command.

type

  1. type SymtabCmd struct {
  2. Cmd
  3. Len uint32
  4. Symoff
  5. Nsyms uint32
  6. Stroff
  7. Strsize uint32
  8. }

A SymtabCmd is a Mach-O symbol table command.

type

  1. type Thread struct {
  2. Cmd
  3. Len uint32
  4. Type
  5. Data []uint32
  6. }

A Thread is a Mach-O thread state command.

  1. type Type

A Type is the Mach-O file type, e.g. an object file, executable, or dynamic
library.

  1. const (
  2. TypeObj Type = 1
  3. TypeExec = 2
  4. TypeDylib Type = 6
  5. TypeBundle = 8
  6. )

  1. func (t Type) GoString()

func (Type) String