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バイナリへアクセスするFileを作成します。Mach-OELFバイナリの読み込み開始位置が0となっている必要があります。
Open関数
func Open(name string) (*File, os.Error)
Openは、指定されたファイル名をos.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
// 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 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
// 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 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
)
Trackback URL
Comments