import "debug/macho"

http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.htmlで 定義されているMach-Oオブジェクトファイルへのアクセスを実装しています。

パッケージファイル

file.go macho.go

定数

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

Cpu型

CpuはMach-O CPUタイプです。

type Cpu uint32

const (
    Cpu386   Cpu = 7
    CpuAmd64 Cpu = Cpu386 + 1<<24
)

(Cpu) GoString関数

func (i Cpu) GoString() string

(Cpu) String関数

func (i Cpu) String() string

File型

FileはMach-Oファイルを扱います。

type File struct {
    FileHeader
    ByteOrder binary.ByteOrder
    Loads     []Load
    Sections  []*Section
    // contains unexported fields
}

NewFile関数

func NewFile(r io.ReaderAt) (*File, os.Error)

NewFileはMach-Oバイナリへアクセスする基本的なリーダーを作成します。Mach-Oバイナリは開始位置0となっています。

Open関数

func Open(name string) (*File, os.Error)

Openは指定されたファイル名よりファイルを開きます。また、Mach-Oバイナリとして使用するための準備をします。

(*File) Close関数

func (f *File) Close() os.Error

Closeはファイルを閉じます。FileがOpenではなく、NewFileを使用して作成された場合はCloseを呼び出す必要はありません。

(*File) DWARF関数

func (f *File) DWARF() (*dwarf.Data, os.Error)

DWARFはMach-OファイルのDWARFデバッグ情報を返します。

(*File) Section関数

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

Sectionは指定されたnameより該当するセクションを返します。該当するセクションが存在しない場合はnilを返します。

(*File) Segment関数

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

Segmentは指定されたnameより該当するセグメントを返します。該当するセグメントが存在しない場合はnilを返します。

FileHeader型

FileHeaderはMach-Oファイルヘッダーを表します。

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

FormatError型

type FormatError struct {
    // contains unexported fields
}

(*FormatError) String関数

func (e *FormatError) String() string

Load型

LoadはMach-Oロードコマンドを表します。

type Load interface {
    Raw() []byte
}

LoadBytes型

LoadBytesはMach-Oロードコマンドの非解釈バイトです。

type LoadBytes []byte

(LoadBytes) Raw関数

func (b LoadBytes) Raw() []byte

LoadCmd型

LoadCmdはMach-Oロードコマンドです。

type LoadCmd uint32

const (
    LoadCmdSegment    LoadCmd = 1
    LoadCmdSegment64  LoadCmd = 25
    LoadCmdThread     LoadCmd = 4
    LoadCmdUnixThread LoadCmd = 5 // thread+stack
)

(LoadCmd) GoString関数

func (i LoadCmd) GoString() string

(LoadCmd) String関数

func (i LoadCmd) String() string

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
}

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
}

Section型

type Section struct {
    SectionHeader

    // ReadAtメソッドにReaderAtを埋め込んでください。
    // ReadとSeekを持つことを避けるために、直接SectionReaderを埋め込まないでください。
    // クライアントにてReadおよびSeekが必要な場合、他のクライアントとのシークオフセットの
    // 競合を避けるため、Openを使用してください。
    io.ReaderAt
    // contains unexported fields
}

(*Section) Data関数

func (s *Section) Data() ([]byte, os.Error)

DataはMach-Oセクションのコンテンツの読み込みおよび返却を行います。

(*Section) Open関数

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

OpenはMach-Oセクションを読み込み、ReadSeekerを返します。

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
}

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
}

SectionHeader型

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

Segment型

SegmentはMach-O32ビット、または64ビットロードセグメントコマンドを表します。

type Segment struct {
    LoadBytes
    SegmentHeader

    // ReadAtメソッドにReaderAtを埋め込んでください。
    // ReadとSeekを持つことを避けるために、直接SectionReaderを埋め込まないでください。
    // クライアントにてReadおよびSeekが必要な場合、他のクライアントとのシークオフセットの
    // 競合を避けるため、Openを使用してください。
    io.ReaderAt
    // contains unexported fields
}

(*Segment) Data関数

func (s *Segment) Data() ([]byte, os.Error)

Dataはセグメントのコンテンツの読み込みおよび返却を行います。

(*Segment) Open関数

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

Openはセグメントを読み込み、ReadSeekerを返します。

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
}

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
}

SegmentHeader型

SegmentHeaderはMach-O32ビット、または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
}

Thread型

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
)