Package macho
import "debug/macho"
Package macho implements access to Mach-O object files, as defined by http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html.
Package files
file.go macho.goConstants
const (
Magic32 uint32 = 0xfeedface
Magic64 uint32 = 0xfeedfacf
)
type Cpu
A Cpu is a Mach-O cpu type.
type Cpu uint32
const (
Cpu386 Cpu = 7
CpuAmd64 Cpu = Cpu386 + 1<<24
)
func (Cpu) GoString
func (i Cpu) GoString() string
func (Cpu) String
func (i Cpu) String() string
type File
A File represents an open Mach-O file.
type File struct {
FileHeader
ByteOrder binary.ByteOrder
Loads []Load
Sections []*Section
// contains unexported fields
}
func NewFile
func NewFile(r io.ReaderAt) (*File, os.Error)
NewFile creates a new File for acecssing a Mach-O binary in an underlying reader. The Mach-O binary is expected to start at position 0 in the ReaderAt.
func Open
func Open(name string) (*File, os.Error)
Open opens the named file using os.Open and prepares it for use as a Mach-O binary.
func (*File) Close
func (f *File) Close() os.Error
Close closes the File. If the File was created using NewFile directly instead of Open, Close has no effect.
func (*File) DWARF
func (f *File) DWARF() (*dwarf.Data, os.Error)
DWARF returns the DWARF debug information for the Mach-O file.
func (*File) Section
func (f *File) Section(name string) *Section
Section returns the first section with the given name, or nil if no such section exists.
func (*File) Segment
func (f *File) Segment(name string) *Segment
Segment returns the first Segment with the given name, or nil if no such segment exists.
type FileHeader
A FileHeader represents a Mach-O file header.
type FileHeader struct {
Magic uint32
Cpu Cpu
SubCpu uint32
Type Type
Ncmd uint32
Cmdsz uint32
Flags uint32
}
type FormatError
type FormatError struct {
// contains unexported fields
}
func (*FormatError) String
func (e *FormatError) String() string
type Load
A Load represents any Mach-O load command.
type Load interface {
Raw() []byte
}
type LoadBytes
A LoadBytes is the uninterpreted bytes of a Mach-O load command.
type LoadBytes []byte
func (LoadBytes) Raw
func (b LoadBytes) Raw() []byte
type LoadCmd
A LoadCmd is a Mach-O load command.
type LoadCmd uint32
const (
LoadCmdSegment LoadCmd = 1
LoadCmdSegment64 LoadCmd = 25
LoadCmdThread LoadCmd = 4
LoadCmdUnixThread LoadCmd = 5 // thread+stack
)
func (LoadCmd) GoString
func (i LoadCmd) GoString() string
func (LoadCmd) String
func (i LoadCmd) String() string
type Regs386
Regs386 is the Mach-O 386 register structure.
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 is the Mach-O AMD64 register structure.
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
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
}
func (*Section) Data
func (s *Section) Data() ([]byte, os.Error)
Data reads and returns the contents of the Mach-O section.
func (*Section) Open
func (s *Section) Open() io.ReadSeeker
Open returns a new ReadSeeker reading the Mach-O section.
type Section32
A Section32 is a 32-bit Mach-O section header.
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
A Section32 is a 64-bit Mach-O section header.
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
A Segment represents a Mach-O 32-bit or 64-bit load segment command.
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
}
func (*Segment) Data
func (s *Segment) Data() ([]byte, os.Error)
Data reads and returns the contents of the segment.
func (*Segment) Open
func (s *Segment) Open() io.ReadSeeker
Open returns a new ReadSeeker reading the segment.
type Segment32
A Segment32 is a 32-bit Mach-O segment load command.
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
A Segment64 is a 64-bit Mach-O segment load command.
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
A SegmentHeader is the header for a Mach-O 32-bit or 64-bit load segment command.
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 Thread
A Thread is a Mach-O thread state command.
type Thread struct {
Cmd LoadCmd
Len uint32
Type uint32
Data []uint32
}
type Type
A Type is a Mach-O file type, either an object or an executable.
type Type uint32
const (
TypeObj Type = 1
TypeExec Type = 2
)
