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)
/* sort by: | */
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 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
A RpathCmd is a Mach-O rpath command. Cmd LoadCmd Len uint32 Path uint32
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
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
A SymtabCmd is a Mach-O symbol table command. Cmd LoadCmd Len uint32 Nsyms uint32 Stroff uint32 Strsize uint32 Symoff uint32
A Thread is a Mach-O thread state command. Cmd LoadCmd Data []uint32 Len uint32 Type uint32
A Type is the Mach-O file type, e.g. an object file, executable, or dynamic library. ( Type) GoString() string ( Type) String() string Type : expvar.Var Type : fmt.GoStringer Type : fmt.Stringer const TypeBundle const TypeDylib const TypeExec const TypeObj
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 Cpu386 Cpu = 7
const CpuAmd64 Cpu = 16777223
const CpuArm Cpu = 12
const CpuArm64 Cpu = 16777228
const CpuPpc Cpu = 18
const CpuPpc64 Cpu = 16777234
const FlagAllModsBound uint32 = 4096
const FlagAppExtensionSafe uint32 = 33554432
const FlagBindsToWeak uint32 = 65536
const FlagCanonical uint32 = 16384
const FlagForceFlat uint32 = 256
const FlagHasTLVDescriptors uint32 = 8388608
const FlagLazyInit uint32 = 64
const FlagNoHeapExecution uint32 = 16777216
const FlagNoMultiDefs uint32 = 512
const FlagNoUndefs uint32 = 1
const FlagPIE uint32 = 2097152
const FlagPrebindable uint32 = 2048
const FlagPrebound uint32 = 16
const FlagRootSafe uint32 = 262144
const FlagSetuidSafe uint32 = 524288
const FlagSplitSegs uint32 = 32
const FlagTwoLevel uint32 = 128
const FlagWeakDefines uint32 = 32768
const LoadCmdDylib LoadCmd = 12 // load dylib command
const LoadCmdDylinker LoadCmd = 15 // id dylinker command (not load dylinker command)
const LoadCmdRpath LoadCmd = 2147483676
const LoadCmdUnixThread LoadCmd = 5 // thread+stack
const Magic32 uint32 = 4277009102
const Magic64 uint32 = 4277009103
const MagicFat uint32 = 3405691582
const TypeBundle Type = 8
const TypeDylib Type = 6
const TypeExec Type = 2
const TypeObj Type = 1