Black Lives Matter. Support the Equal Justice Initiative.

Package macho

import "debug/macho"
Overview
Index

Overview ▾

软件包macho可以实现对Mach-O对象文件的访问.

Index ▾

Constants
Variables
type Cpu
    func (i Cpu) GoString() string
    func (i Cpu) String() string
type Dylib
type DylibCmd
type Dysymtab
type DysymtabCmd
type FatArch
type FatArchHeader
type FatFile
    func NewFatFile(r io.ReaderAt) (*FatFile, error)
    func OpenFat(name string) (*FatFile, error)
    func (ff *FatFile) Close() error
type File
    func NewFile(r io.ReaderAt) (*File, error)
    func Open(name string) (*File, error)
    func (f *File) Close() error
    func (f *File) DWARF() (*dwarf.Data, error)
    func (f *File) ImportedLibraries() ([]string, error)
    func (f *File) ImportedSymbols() ([]string, error)
    func (f *File) Section(name string) *Section
    func (f *File) Segment(name string) *Segment
type FileHeader
type FormatError
    func (e *FormatError) Error() string
type Load
type LoadBytes
    func (b LoadBytes) Raw() []byte
type LoadCmd
    func (i LoadCmd) GoString() string
    func (i LoadCmd) String() string
type Nlist32
type Nlist64
type Regs386
type RegsAMD64
type Reloc
type RelocTypeARM
    func (r RelocTypeARM) GoString() string
    func (i RelocTypeARM) String() string
type RelocTypeARM64
    func (r RelocTypeARM64) GoString() string
    func (i RelocTypeARM64) String() string
type RelocTypeGeneric
    func (r RelocTypeGeneric) GoString() string
    func (i RelocTypeGeneric) String() string
type RelocTypeX86_64
    func (r RelocTypeX86_64) GoString() string
    func (i RelocTypeX86_64) String() string
type Rpath
type RpathCmd
type Section
    func (s *Section) Data() ([]byte, error)
    func (s *Section) Open() io.ReadSeeker
type Section32
type Section64
type SectionHeader
type Segment
    func (s *Segment) Data() ([]byte, error)
    func (s *Segment) Open() io.ReadSeeker
type Segment32
type Segment64
type SegmentHeader
type Symbol
type Symtab
type SymtabCmd
type Thread
type Type
    func (t Type) GoString() string
    func (t Type) String() string

Package files

fat.go file.go macho.go reloctype.go reloctype_string.go

Constants

const (
    Magic32  uint32 = 0xfeedface
    Magic64  uint32 = 0xfeedfacf
    MagicFat uint32 = 0xcafebabe
)
const (
    FlagNoUndefs              uint32 = 0x1
    FlagIncrLink              uint32 = 0x2
    FlagDyldLink              uint32 = 0x4
    FlagBindAtLoad            uint32 = 0x8
    FlagPrebound              uint32 = 0x10
    FlagSplitSegs             uint32 = 0x20
    FlagLazyInit              uint32 = 0x40
    FlagTwoLevel              uint32 = 0x80
    FlagForceFlat             uint32 = 0x100
    FlagNoMultiDefs           uint32 = 0x200
    FlagNoFixPrebinding       uint32 = 0x400
    FlagPrebindable           uint32 = 0x800
    FlagAllModsBound          uint32 = 0x1000
    FlagSubsectionsViaSymbols uint32 = 0x2000
    FlagCanonical             uint32 = 0x4000
    FlagWeakDefines           uint32 = 0x8000
    FlagBindsToWeak           uint32 = 0x10000
    FlagAllowStackExecution   uint32 = 0x20000
    FlagRootSafe              uint32 = 0x40000
    FlagSetuidSafe            uint32 = 0x80000
    FlagNoReexportedDylibs    uint32 = 0x100000
    FlagPIE                   uint32 = 0x200000
    FlagDeadStrippableDylib   uint32 = 0x400000
    FlagHasTLVDescriptors     uint32 = 0x800000
    FlagNoHeapExecution       uint32 = 0x1000000
    FlagAppExtensionSafe      uint32 = 0x2000000
)

Variables

如果文件不是通用二进制文件,但根据其幻数可能是精简二进制文件,则从NewFatFile或OpenFat返回ErrNotFat.

var ErrNotFat = &FormatError{0, "not a fat Mach-O file", nil}

type Cpu

Cpu是Mach-O cpu类型.

type Cpu uint32
const (
    Cpu386   Cpu = 7
    CpuAmd64 Cpu = Cpu386 | cpuArch64
    CpuArm   Cpu = 12
    CpuArm64 Cpu = CpuArm | cpuArch64
    CpuPpc   Cpu = 18
    CpuPpc64 Cpu = CpuPpc | cpuArch64
)

func (Cpu) GoString

func (i Cpu) GoString() string

func (Cpu) String

func (i Cpu) String() string

type Dylib

Dylib代表Mach-O负载动态库命令.

type Dylib struct {
    LoadBytes
    Name           string
    Time           uint32
    CurrentVersion uint32
    CompatVersion  uint32
}

type DylibCmd

DylibCmd是Mach-O加载动态库命令.

type DylibCmd struct {
    Cmd            LoadCmd
    Len            uint32
    Name           uint32
    Time           uint32
    CurrentVersion uint32
    CompatVersion  uint32
}

type Dysymtab

Dysymtab代表Mach-O动态符号表命令.

type Dysymtab struct {
    LoadBytes
    DysymtabCmd
    IndirectSyms []uint32 // indices into Symtab.Syms
}

type DysymtabCmd

DysymtabCmd是Mach-O动态符号表命令.

type DysymtabCmd struct {
    Cmd            LoadCmd
    Len            uint32
    Ilocalsym      uint32
    Nlocalsym      uint32
    Iextdefsym     uint32
    Nextdefsym     uint32
    Iundefsym      uint32
    Nundefsym      uint32
    Tocoffset      uint32
    Ntoc           uint32
    Modtaboff      uint32
    Nmodtab        uint32
    Extrefsymoff   uint32
    Nextrefsyms    uint32
    Indirectsymoff uint32
    Nindirectsyms  uint32
    Extreloff      uint32
    Nextrel        uint32
    Locreloff      uint32
    Nlocrel        uint32
}

type FatArch 1.3

FatArch是FatFile中的Mach-O文件.

type FatArch struct {
    FatArchHeader
    *File
}

type FatArchHeader 1.3

FatArchHeader代表特定图像体系结构的胖标头.

type FatArchHeader struct {
    Cpu    Cpu
    SubCpu uint32
    Offset uint32
    Size   uint32
    Align  uint32
}

type FatFile 1.3

FatFile是Mach-O通用二进制文件,至少包含一个体系结构.

type FatFile struct {
    Magic  uint32
    Arches []FatArch
    // contains filtered or unexported fields
}

func NewFatFile 1.3

func NewFatFile(r io.ReaderAt) (*FatFile, error)

NewFatFile创建一个新的FatFile,用于访问通用二进制文件中的所有Mach-O图像. Mach-O二进制文件应从ReaderAt的位置0开始.

func OpenFat 1.3

func OpenFat(name string) (*FatFile, error)

OpenFat使用os.Open打开命名文件,并准备将其用作Mach-O通用二进制文件.

func (*FatFile) Close 1.3

func (ff *FatFile) Close() error

type File

文件代表打开的Mach-O文件.

type File struct {
    FileHeader
    ByteOrder binary.ByteOrder
    Loads     []Load
    Sections  []*Section

    Symtab   *Symtab
    Dysymtab *Dysymtab
    // contains filtered or unexported fields
}

func NewFile

func NewFile(r io.ReaderAt) (*File, error)

NewFile创建一个新文件,用于在基础阅读器中访问Mach-O二进制文件. Mach-O二进制文件应从ReaderAt的位置0开始.

func Open

func Open(name string) (*File, error)

Open使用os.Open打开命名的文件,并准备将其用作Mach-O二进制文件.

func (*File) Close

func (f *File) Close() error

关闭关闭文件. 如果文件是使用NewFile而不是直接使用Open创建的,则Close无效.

func (*File) DWARF

func (f *File) DWARF() (*dwarf.Data, error)

DWARF返回Mach-O文件的DWARF调试信息.

func (*File) ImportedLibraries

func (f *File) ImportedLibraries() ([]string, error)

ImportedLibraries返回由二进制f引用的所有库的路径,这些路径预计将在动态链接时与二进制链接.

func (*File) ImportedSymbols

func (f *File) ImportedSymbols() ([]string, error)

ImportedSymbols返回二进制f引用的所有符号的名称,这些符号预期在动态加载时由其他库满足.

func (*File) Section

func (f *File) Section(name string) *Section

Section返回具有给定名称的第一部分,如果不存在该部分,则返回nil.

func (*File) Segment

func (f *File) Segment(name string) *Segment

Segment返回具有给定名称的第一个Segment,如果不存在这样的细分,则返回nil.

type FileHeader

FileHeader代表Mach-O文件头.

type FileHeader struct {
    Magic  uint32
    Cpu    Cpu
    SubCpu uint32
    Type   Type
    Ncmd   uint32
    Cmdsz  uint32
    Flags  uint32
}

type FormatError

如果数据的目标文件格式不正确,则某些操作将返回FormatError.

type FormatError struct {
    // contains filtered or unexported fields
}

func (*FormatError) Error

func (e *FormatError) Error() string

type Load

负载代表任何Mach-O负载命令.

type Load interface {
    Raw() []byte
}

type LoadBytes

LoadBytes是Mach-O加载命令的未解释字节.

type LoadBytes []byte

func (LoadBytes) Raw

func (b LoadBytes) Raw() []byte

type LoadCmd

LoadCmd是Mach-O加载命令.

type LoadCmd uint32
const (
    LoadCmdSegment    LoadCmd = 0x1
    LoadCmdSymtab     LoadCmd = 0x2
    LoadCmdThread     LoadCmd = 0x4
    LoadCmdUnixThread LoadCmd = 0x5 // thread+stack
    LoadCmdDysymtab   LoadCmd = 0xb
    LoadCmdDylib      LoadCmd = 0xc // load dylib command
    LoadCmdDylinker   LoadCmd = 0xf // id dylinker command (not load dylinker command)
    LoadCmdSegment64  LoadCmd = 0x19
    LoadCmdRpath      LoadCmd = 0x8000001c
)

func (LoadCmd) GoString

func (i LoadCmd) GoString() string

func (LoadCmd) String

func (i LoadCmd) String() string

type Nlist32

Nlist32是一个Mach-O 32位符号表条目.

type Nlist32 struct {
    Name  uint32
    Type  uint8
    Sect  uint8
    Desc  uint16
    Value uint32
}

type Nlist64

Nlist64是Mach-O 64位符号表条目.

type Nlist64 struct {
    Name  uint32
    Type  uint8
    Sect  uint8
    Desc  uint16
    Value uint64
}

type Regs386

Regs386是Mach-O 386寄存器结构.

type Regs386 struct {
    AX    uint32
    BX    uint32
    CX    uint32
    DX    uint32
    DI    uint32
    SI    uint32
    BP    uint32
    SP    uint32
    SS    uint32
    FLAGS uint32
    IP    uint32
    CS    uint32
    DS    uint32
    ES    uint32
    FS    uint32
    GS    uint32
}

type RegsAMD64

RegsAMD64是Mach-O AMD64寄存器结构.

type RegsAMD64 struct {
    AX    uint64
    BX    uint64
    CX    uint64
    DX    uint64
    DI    uint64
    SI    uint64
    BP    uint64
    SP    uint64
    R8    uint64
    R9    uint64
    R10   uint64
    R11   uint64
    R12   uint64
    R13   uint64
    R14   uint64
    R15   uint64
    IP    uint64
    FLAGS uint64
    CS    uint64
    FS    uint64
    GS    uint64
}

type Reloc 1.10

重定位代表Mach-O重定位.

type Reloc struct {
    Addr  uint32
    Value uint32
    // 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       uint8 // 0=byte, 1=word, 2=long, 3=quad
    Pcrel     bool
    Extern    bool // valid if Scattered == false
    Scattered bool
}

type RelocTypeARM 1.10

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

func (RelocTypeARM) GoString 1.10

func (r RelocTypeARM) GoString() string

func (RelocTypeARM) String 1.10

func (i RelocTypeARM) String() string

type RelocTypeARM64 1.10

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

func (RelocTypeARM64) GoString 1.10

func (r RelocTypeARM64) GoString() string

func (RelocTypeARM64) String 1.10

func (i RelocTypeARM64) String() string

type RelocTypeGeneric 1.10

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

func (RelocTypeGeneric) GoString 1.10

func (r RelocTypeGeneric) GoString() string

func (RelocTypeGeneric) String 1.10

func (i RelocTypeGeneric) String() string

type RelocTypeX86_64 1.10

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

func (RelocTypeX86_64) GoString 1.10

func (r RelocTypeX86_64) GoString() string

func (RelocTypeX86_64) String 1.10

func (i RelocTypeX86_64) String() string

type Rpath 1.10

Rpath表示Mach-O rpath命令.

type Rpath struct {
    LoadBytes
    Path string
}

type RpathCmd 1.10

RpathCmd是Mach-O rpath命令.

type RpathCmd struct {
    Cmd  LoadCmd
    Len  uint32
    Path uint32
}

type Section

type Section struct {
    SectionHeader
    Relocs []Reloc // Go 1.10

    // 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.ReaderAt
    // contains filtered or unexported fields
}

func (*Section) Data

func (s *Section) Data() ([]byte, error)

数据读取并返回Mach-O部分的内容.

func (*Section) Open

func (s *Section) Open() io.ReadSeeker

打开将返回一个新的ReadSeeker,其中将读取Mach-O部分.

type Section32

Section32是一个32位Mach-O节头.

type Section32 struct {
    Name     [16]byte
    Seg      [16]byte
    Addr     uint32
    Size     uint32
    Offset   uint32
    Align    uint32
    Reloff   uint32
    Nreloc   uint32
    Flags    uint32
    Reserve1 uint32
    Reserve2 uint32
}

type Section64

Section64是64位Mach-O节头.

type Section64 struct {
    Name     [16]byte
    Seg      [16]byte
    Addr     uint64
    Size     uint64
    Offset   uint32
    Align    uint32
    Reloff   uint32
    Nreloc   uint32
    Flags    uint32
    Reserve1 uint32
    Reserve2 uint32
    Reserve3 uint32
}

type SectionHeader

type SectionHeader struct {
    Name   string
    Seg    string
    Addr   uint64
    Size   uint64
    Offset uint32
    Align  uint32
    Reloff uint32
    Nreloc uint32
    Flags  uint32
}

type Segment

段代表Mach-O的32位或64位负载段命令.

type Segment struct {
    LoadBytes
    SegmentHeader

    // 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.ReaderAt
    // contains filtered or unexported fields
}

func (*Segment) Data

func (s *Segment) Data() ([]byte, error)

数据读取并返回该段的内容.

func (*Segment) Open

func (s *Segment) Open() io.ReadSeeker

Open返回一个新的ReadSeeker来读取该段.

type Segment32

Segment32是32位Mach-O段加载命令.

type Segment32 struct {
    Cmd     LoadCmd
    Len     uint32
    Name    [16]byte
    Addr    uint32
    Memsz   uint32
    Offset  uint32
    Filesz  uint32
    Maxprot uint32
    Prot    uint32
    Nsect   uint32
    Flag    uint32
}

type Segment64

Segment64是64位Mach-O段加载命令.

type Segment64 struct {
    Cmd     LoadCmd
    Len     uint32
    Name    [16]byte
    Addr    uint64
    Memsz   uint64
    Offset  uint64
    Filesz  uint64
    Maxprot uint32
    Prot    uint32
    Nsect   uint32
    Flag    uint32
}

type SegmentHeader

SegmentHeader是Mach-O 32位或64位装入段命令的标头.

type SegmentHeader struct {
    Cmd     LoadCmd
    Len     uint32
    Name    string
    Addr    uint64
    Memsz   uint64
    Offset  uint64
    Filesz  uint64
    Maxprot uint32
    Prot    uint32
    Nsect   uint32
    Flag    uint32
}

type Symbol

符号是Mach-O的32位或64位符号表条目.

type Symbol struct {
    Name  string
    Type  uint8
    Sect  uint8
    Desc  uint16
    Value uint64
}

type Symtab

Symtab代表Mach-O符号表命令.

type Symtab struct {
    LoadBytes
    SymtabCmd
    Syms []Symbol
}

type SymtabCmd

SymtabCmd是Mach-O符号表命令.

type SymtabCmd struct {
    Cmd     LoadCmd
    Len     uint32
    Symoff  uint32
    Nsyms   uint32
    Stroff  uint32
    Strsize uint32
}

type Thread

线程是Mach-O线程状态命令.

type Thread struct {
    Cmd  LoadCmd
    Len  uint32
    Type uint32
    Data []uint32
}

type Type

类型是Mach-O文件类型,例如目标文件,可执行文件或动态库.

type Type uint32
const (
    TypeObj    Type = 1
    TypeExec   Type = 2
    TypeDylib  Type = 6
    TypeBundle Type = 8
)

func (Type) GoString 1.10

func (t Type) GoString() string

func (Type) String 1.10

func (t Type) String() string

by  ICOPY.SITE