Golang标准库——debug/macho

DevilRoshan · · 590 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

macho

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

Constants

const (
    Magic32  uint32 = 0xfeedface
    Magic64  uint32 = 0xfeedfacf
    MagicFat uint32 = 0xcafebabe
)

Variables

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

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

type Cpu

type Cpu uint32

Cpu是Mach-O cpu类型。

const (
    Cpu386   Cpu = 7
    CpuAmd64 Cpu = Cpu386 | cpuArch64
    CpuArm   Cpu = 12
    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

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

Dylib表示Mach-O负载动态库命令。

type DylibCmd

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

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

type Dysymtab

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

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

type DysymtabCmd

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
}

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

type FatArch

type FatArch struct {
    FatArchHeader
    *File
}

FatArch是FatFile中的Mach-O文件。

type FatArchHeader

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

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

type FatFile

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

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

func NewFatFile

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

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

func OpenFat

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

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

func (*FatFile) Close

func (ff *FatFile) Close() error

type File

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

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

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

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

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

FileHeader代表Mach-O文件头。

type FormatError

type FormatError struct {
    off int64
    msg string
    val interface{}
}

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

func (*FormatError) Error

func (e *FormatError) Error() string

type Load

type Load interface {
    Raw() []byte
}

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

type LoadBytes

type LoadBytes []byte

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

func (LoadBytes) Raw

func (b LoadBytes) Raw() []byte

type LoadCmd

type LoadCmd uint32

LoadCmd是Mach-O加载命令。

const (
    LoadCmdSegment    LoadCmd = 1
    LoadCmdSymtab     LoadCmd = 2
    LoadCmdThread     LoadCmd = 4
    LoadCmdUnixThread LoadCmd = 5 // thread+stack
    LoadCmdDysymtab   LoadCmd = 11
    LoadCmdDylib      LoadCmd = 12
    LoadCmdDylinker   LoadCmd = 15
    LoadCmdSegment64  LoadCmd = 25
)

func (LoadCmd) GoString

func (i LoadCmd) GoString() string

func (LoadCmd) String

func (i LoadCmd) String() string

type Nlist32

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

Nlist32是一个Mach-O 32位符号表入口。

type Nlist64

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

Nlist64是一个Mach-O 64位符号表入口。

type Regs386

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
}

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

type RegsAMD64

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
}

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

type Section

type Section struct {
    SectionHeader

    // 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

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
}

Section32是32位Mach-O节头。

type Section64

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
}

Section64是64位Mach-O节头。

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

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
}

Segment代表Mach-O 32位或64位负载段命令。

func (*Segment) Data

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

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

func (*Segment) Open

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

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

type Segment32

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
}

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

type Segment64

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
}

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

type SegmentHeader

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
}

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

type Symbol

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

Symbol是Mach-O的32位或64位符号表入口。

type Symtab

type Symtab struct {
    LoadBytes
    SymtabCmd
    Syms []Symbol
}

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

type SymtabCmd

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

SymtabCmd是Mach-O符号表命令。

type Thread

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

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

type Type

type Type uint32

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

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

有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:DevilRoshan

查看原文:Golang标准库——debug/macho

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

590 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传