package macho
Import Path
debug/macho (on go.dev)
Dependency Relation
imports 10 packages, and imported by one package
Involved Source Files
fat.go
Package macho implements access to Mach-O object files.
# Security
This package is not designed to be hardened against adversarial inputs, and is
outside the scope of https://go.dev/security/policy. In particular, only basic
validation is done when parsing object files. As such, care should be taken when
parsing untrusted inputs, as parsing malformed files may consume significant
resources, or cause panics.
macho.go
reloctype.go
reloctype_string.go
Package-Level Type Names (total 38)
A Cpu is a Mach-O cpu type.
( Cpu) GoString() string
( Cpu) String() string
Cpu : expvar.Var
Cpu : fmt.GoStringer
Cpu : fmt.Stringer
const Cpu386
const CpuAmd64
const CpuArm
const CpuArm64
const CpuPpc
const CpuPpc64
A Dylib represents a Mach-O load dynamic library command.
CompatVersion uint32
CurrentVersion uint32
LoadBytes LoadBytes
Name string
Time uint32
( Dylib) Raw() []byte
Dylib : Load
A DylibCmd is a Mach-O load dynamic library command.
Cmd LoadCmd
CompatVersion uint32
CurrentVersion uint32
Len uint32
Name uint32
Time uint32
A Dysymtab represents a Mach-O dynamic symbol table command.
DysymtabCmd DysymtabCmd
DysymtabCmd.Cmd LoadCmd
DysymtabCmd.Extrefsymoff uint32
DysymtabCmd.Extreloff uint32
DysymtabCmd.Iextdefsym uint32
DysymtabCmd.Ilocalsym uint32
DysymtabCmd.Indirectsymoff uint32
DysymtabCmd.Iundefsym uint32
DysymtabCmd.Len uint32
DysymtabCmd.Locreloff uint32
DysymtabCmd.Modtaboff uint32
DysymtabCmd.Nextdefsym uint32
DysymtabCmd.Nextrefsyms uint32
DysymtabCmd.Nextrel uint32
DysymtabCmd.Nindirectsyms uint32
DysymtabCmd.Nlocalsym uint32
DysymtabCmd.Nlocrel uint32
DysymtabCmd.Nmodtab uint32
DysymtabCmd.Ntoc uint32
DysymtabCmd.Nundefsym uint32
DysymtabCmd.Tocoffset uint32
// indices into Symtab.Syms
LoadBytes LoadBytes
( Dysymtab) Raw() []byte
Dysymtab : Load
A DysymtabCmd is a Mach-O dynamic symbol table command.
Cmd LoadCmd
Extrefsymoff uint32
Extreloff uint32
Iextdefsym uint32
Ilocalsym uint32
Indirectsymoff uint32
Iundefsym uint32
Len uint32
Locreloff uint32
Modtaboff uint32
Nextdefsym uint32
Nextrefsyms uint32
Nextrel uint32
Nindirectsyms uint32
Nlocalsym uint32
Nlocrel uint32
Nmodtab uint32
Ntoc uint32
Nundefsym uint32
Tocoffset uint32
A FatArch is a Mach-O File inside a FatFile.
FatArchHeader FatArchHeader
FatArchHeader.Align uint32
FatArchHeader.Cpu Cpu
FatArchHeader.Offset uint32
FatArchHeader.Size uint32
FatArchHeader.SubCpu uint32
File *File
File.ByteOrder binary.ByteOrder
File.Dysymtab *Dysymtab
File.FileHeader FileHeader
File.FileHeader.Cmdsz uint32
File.FileHeader.Flags uint32
File.FileHeader.Magic uint32
File.FileHeader.Ncmd uint32
File.FileHeader.Type Type
File.Loads []Load
File.Sections []*Section
File.Symtab *Symtab
Close closes the [File].
If the [File] was created using [NewFile] directly instead of [Open],
Close has no effect.
DWARF returns the DWARF debug information for the Mach-O file.
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.
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.
Section returns the first section with the given name, or nil if no such
section exists.
Segment returns the first Segment with the given name, or nil if no such segment exists.
FatArch : io.Closer
A FatArchHeader represents a fat header for a specific image architecture.
Align uint32
Cpu Cpu
Offset uint32
Size uint32
SubCpu uint32
A FatFile is a Mach-O universal binary that contains at least one architecture.
Arches []FatArch
Magic uint32
(*FatFile) Close() error
*FatFile : io.Closer
func NewFatFile(r io.ReaderAt) (*FatFile, error)
func OpenFat(name string) (*FatFile, error)
A File represents an open Mach-O file.
ByteOrder binary.ByteOrder
Dysymtab *Dysymtab
FileHeader FileHeader
FileHeader.Cmdsz uint32
FileHeader.Cpu Cpu
FileHeader.Flags uint32
FileHeader.Magic uint32
FileHeader.Ncmd uint32
FileHeader.SubCpu uint32
FileHeader.Type Type
Loads []Load
Sections []*Section
Symtab *Symtab
Close closes the [File].
If the [File] was created using [NewFile] directly instead of [Open],
Close has no effect.
DWARF returns the DWARF debug information for the Mach-O file.
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.
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.
Section returns the first section with the given name, or nil if no such
section exists.
Segment returns the first Segment with the given name, or nil if no such segment exists.
*File : io.Closer
func NewFile(r io.ReaderAt) (*File, error)
func Open(name string) (*File, error)
A FileHeader represents a Mach-O file header.
Cmdsz uint32
Cpu Cpu
Flags uint32
Magic uint32
Ncmd uint32
SubCpu uint32
Type Type
FormatError is returned by some operations if the data does
not have the correct format for an object file.
(*FormatError) Error() string
*FormatError : error
var ErrNotFat *FormatError
A Load represents any Mach-O load command.
( Load) Raw() []byte
Dylib
Dysymtab
LoadBytes
Rpath
Segment
Symtab
A LoadBytes is the uninterpreted bytes of a Mach-O load command.
( LoadBytes) Raw() []byte
LoadBytes : Load
A LoadCmd is a Mach-O load command.
( LoadCmd) GoString() string
( LoadCmd) String() string
LoadCmd : expvar.Var
LoadCmd : fmt.GoStringer
LoadCmd : fmt.Stringer
const LoadCmdDylib
const LoadCmdDylinker
const LoadCmdDysymtab
const LoadCmdRpath
const LoadCmdSegment
const LoadCmdSegment64
const LoadCmdSymtab
const LoadCmdThread
const LoadCmdUnixThread
An Nlist32 is a Mach-O 32-bit symbol table entry.
Desc uint16
Name uint32
Sect uint8
Type uint8
Value uint32
An Nlist64 is a Mach-O 64-bit symbol table entry.
Desc uint16
Name uint32
Sect uint8
Type uint8
Value uint64
Regs386 is the Mach-O 386 register structure.
AX uint32
BP uint32
BX uint32
CS uint32
CX uint32
DI uint32
DS uint32
DX uint32
ES uint32
FLAGS uint32
FS uint32
GS uint32
IP uint32
SI uint32
SP uint32
SS uint32
RegsAMD64 is the Mach-O AMD64 register structure.
AX uint64
BP uint64
BX uint64
CS uint64
CX uint64
DI uint64
DX uint64
FLAGS uint64
FS uint64
GS uint64
IP uint64
R10 uint64
R11 uint64
R12 uint64
R13 uint64
R14 uint64
R15 uint64
R8 uint64
R9 uint64
SI uint64
SP uint64
A Reloc represents a Mach-O relocation.
Addr uint32
// valid if Scattered == false
// 0=byte, 1=word, 2=long, 3=quad
Pcrel bool
Scattered bool
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.
Value uint32
( RelocTypeARM) GoString() string
( RelocTypeARM) String() string
RelocTypeARM : expvar.Var
RelocTypeARM : fmt.GoStringer
RelocTypeARM : fmt.Stringer
const ARM_RELOC_BR24
const ARM_RELOC_HALF
const ARM_RELOC_HALF_SECTDIFF
const ARM_RELOC_LOCAL_SECTDIFF
const ARM_RELOC_PAIR
const ARM_RELOC_PB_LA_PTR
const ARM_RELOC_SECTDIFF
const ARM_RELOC_VANILLA
const ARM_THUMB_32BIT_BRANCH
const ARM_THUMB_RELOC_BR22
( RelocTypeARM64) GoString() string
( RelocTypeARM64) String() string
RelocTypeARM64 : expvar.Var
RelocTypeARM64 : fmt.GoStringer
RelocTypeARM64 : fmt.Stringer
const ARM64_RELOC_ADDEND
const ARM64_RELOC_BRANCH26
const ARM64_RELOC_GOT_LOAD_PAGE21
const ARM64_RELOC_GOT_LOAD_PAGEOFF12
const ARM64_RELOC_PAGE21
const ARM64_RELOC_PAGEOFF12
const ARM64_RELOC_POINTER_TO_GOT
const ARM64_RELOC_SUBTRACTOR
const ARM64_RELOC_TLVP_LOAD_PAGE21
const ARM64_RELOC_TLVP_LOAD_PAGEOFF12
const ARM64_RELOC_UNSIGNED
( RelocTypeGeneric) GoString() string
( RelocTypeGeneric) String() string
RelocTypeGeneric : expvar.Var
RelocTypeGeneric : fmt.GoStringer
RelocTypeGeneric : fmt.Stringer
const GENERIC_RELOC_LOCAL_SECTDIFF
const GENERIC_RELOC_PAIR
const GENERIC_RELOC_PB_LA_PTR
const GENERIC_RELOC_SECTDIFF
const GENERIC_RELOC_TLV
const GENERIC_RELOC_VANILLA
( RelocTypeX86_64) GoString() string
( RelocTypeX86_64) String() string
RelocTypeX86_64 : expvar.Var
RelocTypeX86_64 : fmt.GoStringer
RelocTypeX86_64 : fmt.Stringer
const X86_64_RELOC_BRANCH
const X86_64_RELOC_GOT
const X86_64_RELOC_GOT_LOAD
const X86_64_RELOC_SIGNED
const X86_64_RELOC_SIGNED_1
const X86_64_RELOC_SIGNED_2
const X86_64_RELOC_SIGNED_4
const X86_64_RELOC_SUBTRACTOR
const X86_64_RELOC_TLV
const X86_64_RELOC_UNSIGNED
A Rpath represents a Mach-O rpath command.
LoadBytes LoadBytes
Path string
( Rpath) Raw() []byte
Rpath : Load
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.
Relocs []Reloc
SectionHeader SectionHeader
SectionHeader.Addr uint64
SectionHeader.Align uint32
SectionHeader.Flags uint32
SectionHeader.Name string
SectionHeader.Nreloc uint32
SectionHeader.Offset uint32
SectionHeader.Reloff uint32
SectionHeader.Seg string
SectionHeader.Size uint64
Data reads and returns the contents of the Mach-O section.
Open returns a new ReadSeeker reading the Mach-O section.
( Section) ReadAt(p []byte, off int64) (n int, err error)
Section : io.ReaderAt
func (*File).Section(name string) *Section
A Section32 is a 32-bit Mach-O section header.
Addr uint32
Align uint32
Flags uint32
Name [16]byte
Nreloc uint32
Offset uint32
Reloff uint32
Reserve1 uint32
Reserve2 uint32
Seg [16]byte
Size uint32
A Section64 is a 64-bit Mach-O section header.
Addr uint64
Align uint32
Flags uint32
Name [16]byte
Nreloc uint32
Offset uint32
Reloff uint32
Reserve1 uint32
Reserve2 uint32
Reserve3 uint32
Seg [16]byte
Size uint64
Addr uint64
Align uint32
Flags uint32
Name string
Nreloc uint32
Offset uint32
Reloff uint32
Seg string
Size uint64
A Segment represents a Mach-O 32-bit or 64-bit load segment command.
LoadBytes 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.
SegmentHeader SegmentHeader
SegmentHeader.Addr uint64
SegmentHeader.Cmd LoadCmd
SegmentHeader.Filesz uint64
SegmentHeader.Flag uint32
SegmentHeader.Len uint32
SegmentHeader.Maxprot uint32
SegmentHeader.Memsz uint64
SegmentHeader.Name string
SegmentHeader.Nsect uint32
SegmentHeader.Offset uint64
SegmentHeader.Prot uint32
Data reads and returns the contents of the segment.
Open returns a new ReadSeeker reading the segment.
( Segment) Raw() []byte
( Segment) ReadAt(p []byte, off int64) (n int, err error)
Segment : Load
Segment : io.ReaderAt
func (*File).Segment(name string) *Segment
A Segment32 is a 32-bit Mach-O segment load command.
Addr uint32
Cmd LoadCmd
Filesz uint32
Flag uint32
Len uint32
Maxprot uint32
Memsz uint32
Name [16]byte
Nsect uint32
Offset uint32
Prot uint32
A Segment64 is a 64-bit Mach-O segment load command.
Addr uint64
Cmd LoadCmd
Filesz uint64
Flag uint32
Len uint32
Maxprot uint32
Memsz uint64
Name [16]byte
Nsect uint32
Offset uint64
Prot uint32
A SegmentHeader is the header for a Mach-O 32-bit or 64-bit load segment command.
Addr uint64
Cmd LoadCmd
Filesz uint64
Flag uint32
Len uint32
Maxprot uint32
Memsz uint64
Name string
Nsect uint32
Offset uint64
Prot uint32
A Symbol is a Mach-O 32-bit or 64-bit symbol table entry.
Desc uint16
Name string
Sect uint8
Type uint8
Value uint64
A Symtab represents a Mach-O symbol table command.
LoadBytes LoadBytes
Syms []Symbol
SymtabCmd SymtabCmd
SymtabCmd.Cmd LoadCmd
SymtabCmd.Len uint32
SymtabCmd.Nsyms uint32
SymtabCmd.Stroff uint32
SymtabCmd.Strsize uint32
SymtabCmd.Symoff uint32
( Symtab) Raw() []byte
Symtab : Load
Package-Level Functions (total 4)
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.
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.
Open opens the named file using [os.Open] and prepares it for use as a Mach-O binary.
OpenFat opens the named file using [os.Open] and prepares it for use as a Mach-O
universal binary.
Package-Level Variables (only one)
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.
Package-Level Constants (total 85)
const ARM64_RELOC_ADDEND RelocTypeARM64 = 10 const ARM64_RELOC_BRANCH26 RelocTypeARM64 = 2 const ARM64_RELOC_GOT_LOAD_PAGE21 RelocTypeARM64 = 5 const ARM64_RELOC_GOT_LOAD_PAGEOFF12 RelocTypeARM64 = 6 const ARM64_RELOC_PAGE21 RelocTypeARM64 = 3 const ARM64_RELOC_PAGEOFF12 RelocTypeARM64 = 4 const ARM64_RELOC_POINTER_TO_GOT RelocTypeARM64 = 7 const ARM64_RELOC_SUBTRACTOR RelocTypeARM64 = 1 const ARM64_RELOC_TLVP_LOAD_PAGE21 RelocTypeARM64 = 8 const ARM64_RELOC_UNSIGNED RelocTypeARM64 = 0 const ARM_RELOC_BR24 RelocTypeARM = 5 const ARM_RELOC_HALF RelocTypeARM = 8 const ARM_RELOC_HALF_SECTDIFF RelocTypeARM = 9 const ARM_RELOC_LOCAL_SECTDIFF RelocTypeARM = 3 const ARM_RELOC_PAIR RelocTypeARM = 1 const ARM_RELOC_PB_LA_PTR RelocTypeARM = 4 const ARM_RELOC_SECTDIFF RelocTypeARM = 2 const ARM_RELOC_VANILLA RelocTypeARM = 0 const ARM_THUMB_32BIT_BRANCH RelocTypeARM = 7 const ARM_THUMB_RELOC_BR22 RelocTypeARM = 6 const FlagAllModsBound uint32 = 4096 const FlagAllowStackExecution uint32 = 131072 const FlagAppExtensionSafe uint32 = 33554432 const FlagBindAtLoad uint32 = 8 const FlagBindsToWeak uint32 = 65536 const FlagCanonical uint32 = 16384 const FlagDeadStrippableDylib uint32 = 4194304 const FlagDyldLink uint32 = 4 const FlagForceFlat uint32 = 256 const FlagHasTLVDescriptors uint32 = 8388608 const FlagIncrLink uint32 = 2 const FlagLazyInit uint32 = 64 const FlagNoFixPrebinding uint32 = 1024 const FlagNoHeapExecution uint32 = 16777216 const FlagNoMultiDefs uint32 = 512 const FlagNoReexportedDylibs uint32 = 1048576 const FlagNoUndefs uint32 = 1 const FlagPrebindable uint32 = 2048 const FlagPrebound uint32 = 16 const FlagRootSafe uint32 = 262144 const FlagSetuidSafe uint32 = 524288 const FlagSplitSegs uint32 = 32 const FlagSubsectionsViaSymbols uint32 = 8192 const FlagTwoLevel uint32 = 128 const FlagWeakDefines uint32 = 32768 const GENERIC_RELOC_LOCAL_SECTDIFF RelocTypeGeneric = 4 const GENERIC_RELOC_PAIR RelocTypeGeneric = 1 const GENERIC_RELOC_PB_LA_PTR RelocTypeGeneric = 3 const GENERIC_RELOC_SECTDIFF RelocTypeGeneric = 2 const GENERIC_RELOC_TLV RelocTypeGeneric = 5 const GENERIC_RELOC_VANILLA RelocTypeGeneric = 0 const LoadCmdDylib LoadCmd = 12 // load dylib command const LoadCmdDylinker LoadCmd = 15 // id dylinker command (not load dylinker command) const LoadCmdDysymtab LoadCmd = 11 const LoadCmdRpath LoadCmd = 2147483676 const LoadCmdSegment LoadCmd = 1 const LoadCmdSegment64 LoadCmd = 25 const LoadCmdSymtab LoadCmd = 2 const LoadCmdThread LoadCmd = 4 const LoadCmdUnixThread LoadCmd = 5 // thread+stack const TypeBundle Type = 8 const X86_64_RELOC_BRANCH RelocTypeX86_64 = 2 const X86_64_RELOC_GOT RelocTypeX86_64 = 4 const X86_64_RELOC_GOT_LOAD RelocTypeX86_64 = 3 const X86_64_RELOC_SIGNED RelocTypeX86_64 = 1 const X86_64_RELOC_SIGNED_1 RelocTypeX86_64 = 6 const X86_64_RELOC_SIGNED_2 RelocTypeX86_64 = 7 const X86_64_RELOC_SIGNED_4 RelocTypeX86_64 = 8 const X86_64_RELOC_SUBTRACTOR RelocTypeX86_64 = 5 const X86_64_RELOC_TLV RelocTypeX86_64 = 9 const X86_64_RELOC_UNSIGNED RelocTypeX86_64 = 0
The pages are generated with Golds v0.7.0-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |