?
This document uses PHP Chinese website manual Release
import "debug/macho"
概述
參數(shù)
macho 可以訪問 Mach-O 目標文件。
常量
變量
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 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
fat.go file.go macho.go
const ( Magic32 uint32 = 0xfeedface Magic64 uint32 = 0xfeedfacf MagicFat uint32 = 0xcafebabe)
當文件不是通用二進制文件時,ErrNotFat 從 NewFatFile 或 OpenFat 返回,但可能是基于其幻數(shù)的精簡二進制文件。
var ErrNotFat = &FormatError{0, "not a fat Mach-O file", nil}
Cpu 是一個 Mach-O CPU 類型。
type Cpu uint32
const ( Cpu386 Cpu = 7 CpuAmd64 Cpu = Cpu386 | cpuArch64 CpuArm Cpu = 12 CpuPpc Cpu = 18 CpuPpc64 Cpu = CpuPpc | cpuArch64)
func (i Cpu) GoString() string
func (i Cpu) String() string
Dylib 代表 Mach-O 加載動態(tài)庫命令。
type Dylib struct { LoadBytes Name string Time uint32 CurrentVersion uint32 CompatVersion uint32}
DylibCmd 是一個 Mach-O 加載動態(tài)庫命令。
type DylibCmd struct { Cmd LoadCmd Len uint32 Name uint32 Time uint32 CurrentVersion uint32 CompatVersion uint32}
Dysymtab 表示一個 Mach-O 動態(tài)符號表命令。
type Dysymtab struct { LoadBytes DysymtabCmd IndirectSyms []uint32 // 索引到Symtab.Syms}
DysymtabCmd 是一個 Mach-O 動態(tài)符號表命令。
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}
FatArch 是 FatFile 內的 Mach-O 文件。
type FatArch struct { FatArchHeader *File}
FatArchHeader 表示特定圖像體系結構的多頭。
type FatArchHeader struct { Cpu Cpu SubCpu uint32 Offset uint32 Size uint32 Align uint32}
FatFile 是一個包含至少一個體系結構的 Mach-O 通用二進制文件。
type FatFile struct { Magic uint32 Arches []FatArch // 包含已過濾或未導出的字段}
func NewFatFile(r io.ReaderAt) (*FatFile, error)
NewFatFile 創(chuàng)建一個新的 FatFile,用于訪問通用二進制文件中的所有 Mach-O 圖像。Mach-O 二進制文件預計從 ReaderAt 的位置0開始。
func OpenFat(name string) (*FatFile, error)
OpenFat 使用 os.Open 打開指定的文件并準備將其用作 Mach-O 通用二進制文件。
func (ff *FatFile) Close() error
文件表示一個開放的 Mach-O 文件。
type File struct { FileHeader ByteOrder binary.ByteOrder Loads []Load Sections []*Section Symtab *Symtab Dysymtab *Dysymtab // 包含已過濾或未導出的字段}
func NewFile(r io.ReaderAt) (*File, error)
NewFile 創(chuàng)建一個新的文件,用于訪問底層閱讀器中的 Mach-O 二進制文件。Mach-O 二進制文件預計從ReaderAt 的位置0開始。
func Open(name string) (*File, error)
打開使用 os.Open 打開命名文件,并準備將其用作 Mach-O 二進制文件。
func (f *File) Close() error
關閉文件。如果文件是直接使用 NewFile 而不是 Open 來創(chuàng)建的,則 Close 不起作用。
func (f *File) DWARF() (*dwarf.Data, error)
DWARF 返回 Mach-O 文件的 DWARF 調試信息。
func (f *File) ImportedLibraries() ([]string, error)
ImportedLibraries 返回由二進制文件 f 引用的所有庫的路徑,這些庫在動態(tài)鏈接時間期望與二進制鏈接。
func (f *File) ImportedSymbols() ([]string, error)
ImportedSymbols 返回二進制文件f引用的所有符號的名稱,動態(tài)加載時期望其他庫會滿足這些名稱。
func (f *File) Section(name string) *Section
Section 返回給定名稱的第一部分,如果不存在這樣的部分,則返回 nil。
func (f *File) Segment(name string) *Segment
Segment 會返回具有給定名稱的第一個 Segment,如果不存在此 Segment,則為零。
FileHeader 表示一個 Mach-O 文件頭。
type FileHeader struct { Magic uint32 Cpu Cpu SubCpu uint32 Type Type Ncmd uint32 Cmdsz uint32 Flags uint32}
如果數(shù)據(jù)的目標文件格式不正確,F(xiàn)ormatError 會被某些操作返回。
type FormatError struct { // 包含已過濾或未導出的字段}
func (e *FormatError) Error() string
Load 表示任何 Mach-O 加載命令。
type Load interface { Raw() []byte}
LoadBytes 是 Mach-O 加載命令的未解釋字節(jié)。
type LoadBytes []byte
func (b LoadBytes) Raw() []byte
LoadCmd 是一個 Mach-O 加載命令。
type LoadCmd uint32
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 (i LoadCmd) GoString() string
func (i LoadCmd) String() string
Nlist32 是 Mach-O 32 位符號表項。
type Nlist32 struct { Name uint32 Type uint8 Sect uint8 Desc uint16 Value uint32}
Nlist64 是一個 Mach-O 64 位符號表項。
type Nlist64 struct { Name uint32 Type uint8 Sect uint8 Desc uint16 Value uint64}
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}
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 Section struct { SectionHeader // 為ReadAt方法嵌入ReaderAt。 // 不要直接嵌入SectionReader // 避免Read和Seek。 // 如果客戶想要閱讀和尋求它必須使用 // Open()以避免爭奪搜索偏移量 // 與其他客戶。 io.ReaderAt // 包含已過濾或未導出的字段}
func (s *Section) Data() ([]byte, error)
數(shù)據(jù)讀取并返回 Mach-O 部分的內容。
func (s *Section) Open() io.ReadSeeker
Open 返回讀取 Mach-O 部分的新 ReadSeeker。
Section32 是一個32位 Mach-O 節(jié)頭。
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}
Section64 是一個64位 Mach-O 節(jié)頭。
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 struct { Name string Seg string Addr uint64 Size uint64 Offset uint32 Align uint32 Reloff uint32 Nreloc uint32 Flags uint32}
Segment 表示 Mach-O 32 位或64位加載段命令。
type Segment struct { LoadBytes SegmentHeader // 為ReadAt方法嵌入ReaderAt。 // 不要直接嵌入SectionReader // 避免Read閱讀和Seek尋求。 // 如果客戶想要閱讀和尋求它必須使用 // Open()以避免爭奪搜索偏移量 // 與其他客戶。 io.ReaderAt // 包含已過濾或未導出的字段}
func (s *Segment) Data() ([]byte, error)
數(shù)據(jù)讀取并返回段的內容。
func (s *Segment) Open() io.ReadSeeker
Open 返回一個新的 ReadSeeker 讀取該段。
Segment32 是一個32位的 Mach-O segment
加載命令。
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}
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}
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}
符號是一個 Mach-O 32 位或64位符號表條目。
type Symbol struct { Name string Type uint8 Sect uint8 Desc uint16 Value uint64}
Symtab 代表 Mach-O 符號表命令。
type Symtab struct { LoadBytes SymtabCmd Syms []Symbol}
SymtabCmd 是一個 Mach-O符號表命令。
type SymtabCmd struct { Cmd LoadCmd Len uint32 Symoff uint32 Nsyms uint32 Stroff uint32 Strsize uint32}
線程是一個 Mach-O 線程狀態(tài)命令。
type Thread struct { Cmd LoadCmd Len uint32 Type uint32 Data []uint32}
Type 是 Mach-O 文件類型,例如目標文件,可執(zhí)行文件或動態(tài)庫。
type Type uint32
const ( TypeObj Type = 1 TypeExec Type = 2 TypeDylib Type = 6 TypeBundle Type = 8)