macho

package module
v1.1.205 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 27 Imported by: 26

README ¶

go-macho

Go Go Reference License

Package macho implements access to and creation of Mach-O object files.


Why 🤔

This package goes beyond the Go's debug/macho to:

  • Cover ALL load commands and architectures
  • Provide nice summary string output
  • Allow for creating custom MachO files
  • Parse Objective-C runtime information
  • Parse Swift runtime information
  • Read/Write code signature information
  • Parse fixup chain information

Install

$ go get github.com/blacktop/go-macho

Getting Started

package main

import "github.com/blacktop/go-macho"

func main() {
    m, err := macho.Open("/path/to/macho")
    if err != nil {
        panic(err)
    }
    defer m.Close()

    fmt.Println(m.FileTOC.String())
}

License

MIT Copyright (c) 2020-2024 blacktop

Documentation ¶

Overview ¶

Package macho implements access to and creation of Mach-O object files.

Index ¶

Constants ¶

View Source
const (
	BitcodeWrapperMagic = 0x0b17c0de
	RawBitcodeMagic     = 0xdec04342 // 'BC' 0xc0de
)
View Source
const (
	ABIName           = `N`
	SymbolNamespace   = `S`
	RelatedEntityName = `R`

	CTypedef = `t`
)

Variables ¶

View Source
var ErrMachODyldInfoNotFound = errors.New("LC_DYLD_INFO(_ONLY) not found")
View Source
var ErrMachONoBindInfo = errors.New("MachO does not contain bind information (fixups)")
View Source
var ErrMachOSectionNotFound = errors.New("MachO missing required section")
View Source
var ErrNotFat = &FormatError{0, "not a fat Mach-O file", nil}

ErrNotFat is returned from NewFatFile or OpenFat when the file is not a universal binary but may be a thin binary, based on its magic number.

View Source
var ErrObjcSectionNEmpty = errors.New("required ObjC section is empty")
View Source
var ErrObjcSectionNotFound = errors.New("missing required ObjC section")
View Source
var ErrSwiftSectionError = fmt.Errorf("missing swift section")

Functions ¶

func Align ¶ added in v1.1.168

func Align(addr uint64, align uint64) uint64

Types ¶

type AtomInfo ¶ added in v1.1.161

type AtomInfo struct {
	LinkEditData
}

type BitstreamWrapperHeader ¶ added in v1.1.130

type BitstreamWrapperHeader struct {
	Magic   uint32
	Version uint32
	Offset  uint32
	Size    uint32
	CPUType uint32
}

type BuildVersion ¶

type BuildVersion struct {
	LoadBytes
	types.BuildVersionCmd
	Tools []types.BuildVersionTool
}

A BuildVersion represents a Mach-O build for platform min OS version.

func (*BuildVersion) LoadSize ¶ added in v1.1.117

func (b *BuildVersion) LoadSize() uint32

func (*BuildVersion) MarshalJSON ¶ added in v1.1.117

func (b *BuildVersion) MarshalJSON() ([]byte, error)

func (*BuildVersion) String ¶ added in v1.0.4

func (b *BuildVersion) String() string

func (*BuildVersion) Write ¶ added in v1.1.117

func (b *BuildVersion) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type CodeSignature ¶

type CodeSignature struct {
	LoadBytes
	types.CodeSignatureCmd
	codesign.CodeSignature
}

A CodeSignature represents a Mach-O LC_CODE_SIGNATURE command.

func (*CodeSignature) LoadSize ¶ added in v1.1.117

func (l *CodeSignature) LoadSize() uint32

func (*CodeSignature) MarshalJSON ¶ added in v1.1.117

func (l *CodeSignature) MarshalJSON() ([]byte, error)

func (*CodeSignature) String ¶ added in v1.0.8

func (l *CodeSignature) String() string

func (*CodeSignature) Write ¶ added in v1.1.33

func (l *CodeSignature) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type DataInCode ¶

type DataInCode struct {
	LoadBytes
	types.DataInCodeCmd
	Entries []types.DataInCodeEntry
}

A DataInCode represents a Mach-O LC_DATA_IN_CODE command.

func (*DataInCode) LoadSize ¶ added in v1.1.117

func (l *DataInCode) LoadSize() uint32

func (*DataInCode) MarshalJSON ¶ added in v1.1.117

func (l *DataInCode) MarshalJSON() ([]byte, error)

func (*DataInCode) String ¶ added in v1.0.8

func (d *DataInCode) String() string

func (*DataInCode) Write ¶ added in v1.1.33

func (l *DataInCode) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type DyldChainedFixups ¶ added in v1.0.6

type DyldChainedFixups struct {
	LinkEditData
}

A DyldChainedFixups used with linkedit_data_command

type DyldEnvironment ¶ added in v1.0.13

type DyldEnvironment struct {
	Dylinker
}

DyldEnvironment represents a Mach-O LC_DYLD_ENVIRONMENT command.

type DyldExportsTrie ¶ added in v1.0.6

type DyldExportsTrie struct {
	LinkEditData
}

A DyldExportsTrie used with linkedit_data_command, payload is trie

type DyldInfo ¶

type DyldInfo struct {
	LoadBytes
	types.DyldInfoCmd
}

A DyldInfo represents a Mach-O LC_DYLD_INFO command.

func (*DyldInfo) LoadSize ¶ added in v1.0.8

func (d *DyldInfo) LoadSize() uint32

func (*DyldInfo) MarshalJSON ¶ added in v1.1.117

func (l *DyldInfo) MarshalJSON() ([]byte, error)

func (*DyldInfo) Put ¶ added in v1.0.8

func (d *DyldInfo) Put(b []byte, o binary.ByteOrder) int

func (*DyldInfo) String ¶ added in v1.0.8

func (d *DyldInfo) String() string

func (*DyldInfo) Write ¶ added in v1.1.33

func (l *DyldInfo) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type DyldInfoOnly ¶ added in v1.0.8

type DyldInfoOnly struct {
	DyldInfo
}

DyldInfoOnly is compressed dyld information only

type Dylib ¶

type Dylib struct {
	LoadBytes
	types.DylibCmd
	Name string
}

A Dylib represents a Mach-O LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB,LC_REEXPORT_DYLIB load command.

func (*Dylib) LoadSize ¶ added in v1.1.117

func (d *Dylib) LoadSize() uint32

func (*Dylib) MarshalJSON ¶ added in v1.1.117

func (d *Dylib) MarshalJSON() ([]byte, error)

func (*Dylib) Put ¶ added in v1.1.117

func (d *Dylib) Put(b []byte, o binary.ByteOrder) int

func (*Dylib) String ¶ added in v1.0.4

func (d *Dylib) String() string

func (*Dylib) Write ¶ added in v1.1.117

func (d *Dylib) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type DylibCodeSignDrs ¶ added in v1.1.33

type DylibCodeSignDrs struct {
	LinkEditData
}

type Dylinker ¶ added in v1.1.117

type Dylinker struct {
	LoadBytes
	types.DylinkerCmd
	Name string
}

A Dylinker represents a Mach-O LC_ID_DYLINKER, LC_LOAD_DYLINKER or LC_DYLD_ENVIRONMENT load command.

func (*Dylinker) LoadSize ¶ added in v1.1.117

func (d *Dylinker) LoadSize() uint32

func (*Dylinker) MarshalJSON ¶ added in v1.1.117

func (d *Dylinker) MarshalJSON() ([]byte, error)

func (*Dylinker) Put ¶ added in v1.1.117

func (d *Dylinker) Put(b []byte, o binary.ByteOrder) int

func (*Dylinker) String ¶ added in v1.1.117

func (d *Dylinker) String() string

func (*Dylinker) Write ¶ added in v1.1.117

func (d *Dylinker) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type DylinkerID ¶ added in v1.0.26

type DylinkerID struct {
	Dylinker
}

DylinkerID represents a Mach-O LC_ID_DYLINKER command.

type Dysymtab ¶

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

A Dysymtab represents a Mach-O LC_DYSYMTAB command.

func (*Dysymtab) LoadSize ¶ added in v1.1.117

func (d *Dysymtab) LoadSize() uint32

func (*Dysymtab) MarshalJSON ¶ added in v1.1.117

func (d *Dysymtab) MarshalJSON() ([]byte, error)

func (*Dysymtab) String ¶ added in v1.0.8

func (d *Dysymtab) String() string

func (*Dysymtab) Write ¶ added in v1.1.33

func (d *Dysymtab) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type EncryptionInfo ¶ added in v1.0.26

type EncryptionInfo struct {
	LoadBytes
	types.EncryptionInfoCmd
}

A EncryptionInfo represents a Mach-O 32-bit encrypted segment information

func (*EncryptionInfo) LoadSize ¶ added in v1.0.26

func (e *EncryptionInfo) LoadSize() uint32

func (*EncryptionInfo) MarshalJSON ¶ added in v1.1.117

func (l *EncryptionInfo) MarshalJSON() ([]byte, error)

func (*EncryptionInfo) Put ¶ added in v1.0.26

func (e *EncryptionInfo) Put(b []byte, o binary.ByteOrder) int

func (*EncryptionInfo) String ¶ added in v1.0.26

func (e *EncryptionInfo) String() string

func (*EncryptionInfo) Write ¶ added in v1.1.33

func (l *EncryptionInfo) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type EncryptionInfo64 ¶ added in v1.0.6

type EncryptionInfo64 struct {
	LoadBytes
	types.EncryptionInfo64Cmd
}

A EncryptionInfo64 represents a Mach-O 64-bit encrypted segment information

func (*EncryptionInfo64) LoadSize ¶ added in v1.0.6

func (e *EncryptionInfo64) LoadSize() uint32

func (*EncryptionInfo64) MarshalJSON ¶ added in v1.1.117

func (e *EncryptionInfo64) MarshalJSON() ([]byte, error)

func (*EncryptionInfo64) Put ¶ added in v1.0.6

func (e *EncryptionInfo64) Put(b []byte, o binary.ByteOrder) int

func (*EncryptionInfo64) String ¶ added in v1.0.6

func (e *EncryptionInfo64) String() string

func (*EncryptionInfo64) Write ¶ added in v1.1.33

func (e *EncryptionInfo64) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type EntryPoint ¶ added in v1.0.4

type EntryPoint struct {
	LoadBytes
	types.EntryPointCmd
}

EntryPoint represents a Mach-O LC_MAIN command.

func (*EntryPoint) LoadSize ¶ added in v1.0.4

func (e *EntryPoint) LoadSize() uint32

func (*EntryPoint) MarshalJSON ¶ added in v1.1.117

func (e *EntryPoint) MarshalJSON() ([]byte, error)

func (*EntryPoint) Put ¶ added in v1.0.4

func (e *EntryPoint) Put(b []byte, o binary.ByteOrder) int

func (*EntryPoint) String ¶ added in v1.0.4

func (e *EntryPoint) String() string

func (*EntryPoint) Write ¶ added in v1.1.33

func (e *EntryPoint) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type FatArch ¶

type FatArch struct {
	FatArchHeader
	*File
	// contains filtered or unexported fields
}

A FatArch is a Mach-O File inside a FatFile.

type FatArchHeader ¶

type FatArchHeader struct {
	CPU    types.CPU
	SubCPU types.CPUSubtype
	Offset uint32
	Size   uint32
	Align  uint32
}

A FatArchHeader represents a fat header for a specific image architecture.

type FatFile ¶

type FatFile struct {
	FatHeader
	// contains filtered or unexported fields
}

A FatFile is a Mach-O universal binary that contains at least one architecture.

func CreateFat ¶ added in v1.1.123

func CreateFat(name string, files ...string) (*FatFile, error)

func NewFatFile ¶

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

NewFatFile creates a new FatFile for accessing all the Mach-O images in a universal binary. The Mach-O binary is expected to start at position 0 in the ReaderAt.

func OpenFat ¶

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

OpenFat opens the named file using os.Open and prepares it for use as a Mach-O universal binary.

func (*FatFile) Close ¶

func (ff *FatFile) Close() error

Close with close the Mach-O Fat file.

type FatHeader ¶ added in v1.1.123

type FatHeader struct {
	Magic  types.Magic
	Count  uint32
	Arches []FatArch
}

type File ¶

type File struct {
	FileTOC

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

A File represents an open Mach-O file.

func NewFile ¶

func NewFile(r io.ReaderAt, config ...FileConfig) (*File, error)

NewFile creates a new File for accessing 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, error)

Open opens the named file using os.Open and prepares it for use as a Mach-O binary.

func (*File) BuildVersion ¶

func (f *File) BuildVersion() *BuildVersion

BuildVersion returns the build version load command, or nil if no build version exists.

func (*File) Close ¶

func (f *File) Close() error

Close closes the File. If the File was created using NewFile directly instead of Open, Close has no effect.

func (*File) CodeSign ¶ added in v1.1.119

func (f *File) CodeSign(config *codesign.Config) error

func (*File) CodeSignature ¶ added in v1.0.12

func (f *File) CodeSignature() *CodeSignature

CodeSignature returns the code signature, or nil if none exists.

func (*File) DWARF ¶

func (f *File) DWARF() (*dwarf.Data, error)

DWARF returns the DWARF debug information for the Mach-O file.

func (*File) DataInCode ¶ added in v1.1.59

func (f *File) DataInCode() *DataInCode

DataInCode returns the LC_DATA_IN_CODE, or nil if none exists.

func (*File) DyldChainedFixups ¶ added in v1.0.21

func (f *File) DyldChainedFixups() (*fixupchains.DyldChainedFixups, error)

DyldChainedFixups returns the dyld chained fixups.

func (*File) DyldExports ¶ added in v1.1.8

func (f *File) DyldExports() ([]trie.TrieExport, error)

DyldExports returns the dyld export trie symbols

func (*File) DyldExportsTrie ¶ added in v1.0.23

func (f *File) DyldExportsTrie() *DyldExportsTrie

DyldExportsTrie returns the dyld export trie load command, or nil if no dyld info exists.

func (*File) DyldInfo ¶

func (f *File) DyldInfo() *DyldInfo

DyldInfo returns the dyld info load command, or nil if no dyld info exists.

func (*File) DyldInfoOnly ¶ added in v1.1.63

func (f *File) DyldInfoOnly() *DyldInfoOnly

DyldInfoOnly returns the dyld info only load command, or nil if no dyld info only exists.

func (*File) DylibID ¶

func (f *File) DylibID() *IDDylib

DylibID returns the dylib ID load command, or nil if no dylib ID exists.

func (*File) Export ¶ added in v1.1.33

func (f *File) Export(path string, dcf *fixupchains.DyldChainedFixups, baseAddress uint64, locals []Symbol) (err error)

Export exports an in-memory or cached dylib|kext MachO to a file

func (*File) FileSets ¶ added in v1.1.9

func (f *File) FileSets() []*FilesetEntry

FileSets returns an array of Fileset entries.

func (*File) FindAddressSymbols ¶ added in v1.0.24

func (f *File) FindAddressSymbols(addr uint64) ([]Symbol, error)

func (*File) FindSectionForVMAddr ¶ added in v1.0.12

func (f *File) FindSectionForVMAddr(vmAddr uint64) *types.Section

FindSectionForVMAddr returns the section containing a given virtual memory ddress.

func (*File) FindSegmentForVMAddr ¶ added in v1.1.21

func (f *File) FindSegmentForVMAddr(vmAddr uint64) *Segment

FindSegmentForVMAddr returns the segment containing a given virtual memory ddress.

func (*File) FindSymbolAddress ¶

func (f *File) FindSymbolAddress(symbol string) (uint64, error)

func (*File) ForEachV2SplitSegReference ¶ added in v1.1.113

func (f *File) ForEachV2SplitSegReference(handler func(fromSectionIndex, fromSectionOffset, toSectionIndex, toSectionOffset uint64, kind types.SplitInfoKind)) error

func (*File) FunctionStarts ¶ added in v1.0.5

func (f *File) FunctionStarts() *FunctionStarts

FunctionStarts returns the function starts array, or nil if none exists.

func (*File) GetBaseAddress ¶ added in v1.0.24

func (f *File) GetBaseAddress() uint64

GetBaseAddress returns the MachO's preferred load address

func (*File) GetBindInfo ¶ added in v1.1.77

func (f *File) GetBindInfo() (types.Binds, error)

func (*File) GetBindName ¶ added in v1.1.3

func (f *File) GetBindName(pointer uint64) (string, error)

GetBindName returns the import name for a given dyld chained pointer

func (*File) GetCFStrings ¶ added in v1.1.1

func (f *File) GetCFStrings() ([]objc.CFString, error)

GetCFStrings returns the Objective-C CFStrings

func (*File) GetCString ¶ added in v1.0.5

func (f *File) GetCString(addr uint64) (string, error)

GetCString returns a c-string at a given virtual address in the MachO

func (*File) GetCStringAtOffset ¶ added in v1.0.32

func (f *File) GetCStringAtOffset(strOffset int64) (string, error)

GetCStringAtOffset returns a c-string at a given offset into the MachO

func (*File) GetDyldExport ¶ added in v1.1.85

func (f *File) GetDyldExport(symbol string) (*trie.TrieExport, error)

DyldExports returns the dyld export trie symbols

func (*File) GetEmbeddedInfoPlist ¶ added in v1.1.120

func (f *File) GetEmbeddedInfoPlist() ([]byte, error)

func (*File) GetEmbeddedLLVMBitcode ¶ added in v1.1.130

func (f *File) GetEmbeddedLLVMBitcode() (*xar.Reader, error)

func (*File) GetExports ¶ added in v1.1.77

func (f *File) GetExports() ([]trie.TrieExport, error)

func (*File) GetFileSetFileByName ¶ added in v1.1.9

func (f *File) GetFileSetFileByName(name string) (*File, error)

GetFileSetFileByName returns the Fileset MachO for a given name.

func (*File) GetFunctionData ¶ added in v1.1.31

func (f *File) GetFunctionData(fn types.Function) ([]byte, error)

func (*File) GetFunctionForVMAddr ¶ added in v1.1.21

func (f *File) GetFunctionForVMAddr(addr uint64) (types.Function, error)

GetFunctionForVMAddr returns the function containing a given virual address

func (*File) GetFunctions ¶ added in v1.1.21

func (f *File) GetFunctions(data ...byte) []types.Function

GetFunctions returns the function array, or nil if none exists.

func (*File) GetFunctionsForRange ¶ added in v1.1.101

func (f *File) GetFunctionsForRange(start, end uint64) ([]types.Function, error)

GetFunctionsForRange returns the functions contained in a given virual address range

func (*File) GetLoadsByName ¶ added in v1.1.118

func (f *File) GetLoadsByName(name string) []Load

func (*File) GetObjC ¶ added in v1.1.107

func (f *File) GetObjC(addr uint64) (any, bool)

func (*File) GetObjCCategories ¶ added in v1.0.12

func (f *File) GetObjCCategories() ([]objc.Category, error)

GetObjCCategories returns an array of Objective-C categories by parsing the __objc_catlist data

func (*File) GetObjCClass ¶ added in v1.0.12

func (f *File) GetObjCClass(vmaddr uint64) (*objc.Class, error)

GetObjCClass parses an Objective-C class at a given virtual memory address

func (*File) GetObjCClass2 ¶ added in v1.1.107

func (f *File) GetObjCClass2(vmaddr uint64) (*objc.Class, error)

TODO: get rid of old GetObjCClass GetObjCClass parses an Objective-C class at a given virtual memory address

func (*File) GetObjCClassInfo ¶ added in v1.0.12

func (f *File) GetObjCClassInfo(vmaddr uint64) (*objc.ClassRO64, error)

GetObjCClassInfo returns the ClassRO64 (class_ro_t) for a given virtual memory address

func (*File) GetObjCClassNames ¶ added in v1.1.75

func (f *File) GetObjCClassNames() (map[uint64]string, error)

GetObjCClassNames returns a map of section data virtual memory address to their class names

func (*File) GetObjCClassReferences ¶ added in v1.1.29

func (f *File) GetObjCClassReferences() (map[uint64]*objc.Class, error)

GetObjCClassReferences returns a map of classes to their section data virtual memory address

func (*File) GetObjCClasses ¶ added in v1.0.12

func (f *File) GetObjCClasses() ([]objc.Class, error)

GetObjCClasses returns an array of Objective-C classes

func (*File) GetObjCImageInfo ¶ added in v1.0.12

func (f *File) GetObjCImageInfo() (*objc.ImageInfo, error)

GetObjCImageInfo returns the parsed __objc_imageinfo data

func (*File) GetObjCIntegerObjects ¶ added in v1.1.109

func (f *File) GetObjCIntegerObjects() (map[uint64]*objc.IntObj, error)

GetObjCIntObj parses the __objc_intobj section and returns a map of

func (*File) GetObjCIvars ¶ added in v1.0.12

func (f *File) GetObjCIvars(vmaddr uint64) ([]objc.Ivar, error)

GetObjCIvars returns the Objective-C instance variables

func (*File) GetObjCMethodLists ¶ added in v1.1.107

func (f *File) GetObjCMethodLists() ([]objc.Method, error)

GetObjCMethodLists parses the method lists in the __objc_methlist section

func (*File) GetObjCMethodNames ¶ added in v1.0.12

func (f *File) GetObjCMethodNames() (map[uint64]string, error)

GetObjCMethodNames returns a map of section data virtual memory addresses to their method names

func (*File) GetObjCMethods ¶ added in v1.0.12

func (f *File) GetObjCMethods(vmaddr uint64) ([]objc.Method, error)

func (*File) GetObjCNonLazyCategories ¶ added in v1.1.107

func (f *File) GetObjCNonLazyCategories() ([]objc.Category, error)

GetObjCNonLazyCategories returns an array of Objective-C classes that implement +load

func (*File) GetObjCNonLazyClasses ¶ added in v1.1.75

func (f *File) GetObjCNonLazyClasses() ([]objc.Class, error)

GetObjCNonLazyClasses returns an array of Objective-C classes that implement +load

func (*File) GetObjCProperties ¶ added in v1.0.12

func (f *File) GetObjCProperties(vmaddr uint64) ([]objc.Property, error)

GetObjCProperties returns the Objective-C properties

func (*File) GetObjCProtoReferences ¶ added in v1.1.29

func (f *File) GetObjCProtoReferences() (map[uint64]*objc.Protocol, error)

GetObjCProtoReferences returns a map of protocol names to their section data virtual memory address

func (*File) GetObjCProtocols ¶ added in v1.0.12

func (f *File) GetObjCProtocols() ([]objc.Protocol, error)

GetObjCProtocols returns the Objective-C protocols

func (*File) GetObjCSelectorReferences ¶ added in v1.0.12

func (f *File) GetObjCSelectorReferences() (map[uint64]*objc.Selector, error)

GetObjCSelectorReferences returns a map of selector names to their section data virtual memory address

func (*File) GetObjCStubs ¶ added in v1.1.107

func (f *File) GetObjCStubs(parse func(uint64, []byte) (map[uint64]*objc.Stub, error)) (map[uint64]*objc.Stub, error)

GetObjCStubs returns the Objective-C stubs

func (*File) GetObjCSuperReferences ¶ added in v1.1.29

func (f *File) GetObjCSuperReferences() (map[uint64]*objc.Class, error)

GetObjCSuperReferences returns a map of super classes to their section data virtual memory address

func (*File) GetObjCToc ¶ added in v1.1.68

func (f *File) GetObjCToc() objc.Toc

GetObjCToc returns a table of contents of the ObjC objects in the MachO

func (*File) GetOffset ¶ added in v1.0.4

func (f *File) GetOffset(address uint64) (uint64, error)

GetOffset returns the file offset for a given virtual address

func (*File) GetPointer ¶ added in v1.1.82

func (f *File) GetPointer(offset uint64) (uint64, error)

GetPointer returns pointer at a given offset

func (*File) GetPointerAtAddress ¶ added in v1.1.82

func (f *File) GetPointerAtAddress(address uint64) (uint64, error)

GetPointerAtAddress returns pointer at a given virtual address

func (*File) GetRebaseInfo ¶ added in v1.1.77

func (f *File) GetRebaseInfo() ([]types.Rebase, error)

func (*File) GetSectionsForSegment ¶ added in v1.1.21

func (f *File) GetSectionsForSegment(name string) []*types.Section

GetSectionsForSegment returns all the segment's sections or nil if it doesn't have any

func (*File) GetSwiftAccessibleFunctions ¶ added in v1.1.101

func (f *File) GetSwiftAccessibleFunctions() (funcs []swift.TargetAccessibleFunctionRecord, err error)

GetSwiftAccessibleFunctions parses the __TEXT.__swift5_acfuncs section

func (*File) GetSwiftAssociatedTypes ¶ added in v1.0.33

func (f *File) GetSwiftAssociatedTypes() (asstypes []swift.AssociatedType, err error)

GetSwiftAssociatedTypes parses all the associated types in the __TEXT.__swift5_assocty section

func (*File) GetSwiftBuiltinTypes ¶ added in v1.0.33

func (f *File) GetSwiftBuiltinTypes() (builtins []swift.BuiltinType, err error)

GetSwiftBuiltinTypes parses all the built-in types in the __TEXT.__swift5_builtin section

func (*File) GetSwiftClosures ¶ added in v1.0.33

func (f *File) GetSwiftClosures() (closures []swift.Capture, err error)

GetSwiftClosures parses all the closure context objects in the __TEXT.__swift5_capture section

func (*File) GetSwiftColocateMetadata ¶ added in v1.1.169

func (f *File) GetSwiftColocateMetadata() ([]swift.ConformanceDescriptor, error)

GetSwiftColocateMetadata parses all the colocated metadata in the __TEXT.__textg_swiftm section

func (*File) GetSwiftColocateTypeDescriptors ¶ added in v1.1.169

func (f *File) GetSwiftColocateTypeDescriptors() ([]swift.Type, error)

GetSwiftColocateTypeDescriptors parses all the colocated type descriptors in the __TEXT.__constg_swiftt section

func (*File) GetSwiftDynamicReplacementInfo ¶ added in v1.1.101

func (f *File) GetSwiftDynamicReplacementInfo() (*swift.AutomaticDynamicReplacements, error)

GetSwiftDynamicReplacementInfo parses the __TEXT.__swift5_replace section

func (*File) GetSwiftDynamicReplacementInfoForOpaqueTypes ¶ added in v1.1.101

func (f *File) GetSwiftDynamicReplacementInfoForOpaqueTypes() (*swift.AutomaticDynamicReplacementsSome, error)

GetSwiftDynamicReplacementInfoForOpaqueTypes parses the __TEXT.__swift5_replac2 section

func (*File) GetSwiftEntry ¶ added in v1.1.100

func (f *File) GetSwiftEntry() (uint64, error)

GetSwiftEntry parses the __TEXT.__swift5_entry section

func (*File) GetSwiftFields ¶ added in v1.0.33

func (f *File) GetSwiftFields() (fields []swift.Field, err error)

GetSwiftFields parses all the fields in the __TEXT.__swift5_fields section

func (*File) GetSwiftMultiPayloadEnums ¶ added in v1.1.169

func (f *File) GetSwiftMultiPayloadEnums() (mpenums []swift.MultiPayloadEnum, err error)

GetSwiftMultiPayloadEnums TODO: finish me

func (*File) GetSwiftProtocolConformances ¶ added in v1.0.33

func (f *File) GetSwiftProtocolConformances() (protoConfDescs []swift.ConformanceDescriptor, err error)

GetSwiftProtocolConformances parses all the protocol conformances in the __TEXT.__swift5_proto section

func (*File) GetSwiftProtocols ¶ added in v1.0.32

func (f *File) GetSwiftProtocols() (protos []swift.Protocol, err error)

GetSwiftProtocols parses all the protocols in the __TEXT.__swift5_protos section

func (*File) GetSwiftReflectionStrings ¶ added in v1.1.100

func (f *File) GetSwiftReflectionStrings() (map[uint64]string, error)

GetSwiftReflectionStrings parses all the reflection strings in the __TEXT.__swift5_reflstr section

func (*File) GetSwiftTOC ¶ added in v1.1.174

func (f *File) GetSwiftTOC() swift.TOC

GetSwiftTOC returns a table of contents of the Swift objects in the MachO

func (*File) GetSwiftTypes ¶ added in v1.0.32

func (f *File) GetSwiftTypes() (typs []swift.Type, err error)

GetSwiftTypes parses all the swift in the __TEXT.__swift5_types section

func (*File) GetVMAddress ¶ added in v1.0.4

func (f *File) GetVMAddress(offset uint64) (uint64, error)

GetVMAddress returns the virtal address for a given file offset

func (*File) HasDyldChainedFixups ¶ added in v1.1.182

func (f *File) HasDyldChainedFixups() bool

func (*File) HasDyldInfoOnly ¶ added in v1.1.182

func (f *File) HasDyldInfoOnly() bool

func (*File) HasFixups ¶ added in v1.0.26

func (f *File) HasFixups() bool

HasFixups does macho contain a LC_DYLD_CHAINED_FIXUPS load command

func (*File) HasObjC ¶ added in v1.0.12

func (f *File) HasObjC() bool

HasObjC returns true if MachO contains a __objc_imageinfo section

func (*File) HasObjCMessageReferences ¶ added in v1.0.12

func (f *File) HasObjCMessageReferences() bool

HasObjCMessageReferences returns true if MachO contains a __objc_msgrefs section

func (*File) HasPlusLoadMethod ¶ added in v1.0.12

func (f *File) HasPlusLoadMethod() bool

HasPlusLoadMethod returns true if MachO contains a __objc_nlclslist or __objc_nlcatlist section

func (*File) HasSwift ¶ added in v1.1.174

func (f *File) HasSwift() bool

HasSwift checks if the MachO has swift info

func (*File) ImportedLibraries ¶

func (f *File) ImportedLibraries() []string

ImportedLibraries returns the paths of all libraries referred to by the binary f that are expected to be linked with the binary at dynamic link time.

func (*File) ImportedSymbolNames ¶ added in v1.0.24

func (f *File) ImportedSymbolNames() ([]string, error)

ImportedSymbolNames returns the names of all symbols referred to by the binary f that are expected to be satisfied by other libraries at dynamic load time.

func (*File) ImportedSymbols ¶

func (f *File) ImportedSymbols() ([]Symbol, error)

ImportedSymbols returns the names of all symbols referred to by the binary f that are expected to be satisfied by other libraries at dynamic load time.

func (*File) IsCString ¶ added in v1.1.80

func (f *File) IsCString(addr uint64) (string, bool)

IsCString returns cstring at given virtual address if is in a CstringLiterals section

func (*File) LibraryOrdinalName ¶ added in v1.0.28

func (f *File) LibraryOrdinalName(libraryOrdinal int) string

LibraryOrdinalName returns the depancy library oridinal's name

func (*File) PreCache ¶ added in v1.1.169

func (f *File) PreCache() error

PreCache will precache all swift fields, types and built-in types (to hopefully improve performance)

func (*File) PutObjC ¶ added in v1.1.107

func (f *File) PutObjC(addr uint64, obj any)

func (*File) ReadAt ¶ added in v1.1.10

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

ReadAt reads data at offset within MachO

func (*File) Save ¶ added in v1.1.118

func (f *File) Save(outpath string) error

func (*File) Section ¶

func (f *File) Section(segment, section string) *types.Section

Section returns the section with the given name in the given segment, 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.

func (*File) Segments ¶

func (f *File) Segments() Segments

Segments returns all Segments.

func (*File) SlidePointer ¶ added in v1.1.82

func (f *File) SlidePointer(ptr uint64) uint64

SlidePointer returns slid or un-chained pointer

func (*File) SourceVersion ¶

func (f *File) SourceVersion() *SourceVersion

SourceVersion returns the source version load command, or nil if no source version exists.

func (*File) UUID ¶

func (f *File) UUID() *UUID

UUID returns the UUID load command, or nil if no UUID exists.

func (*File) VersionMin ¶ added in v1.1.194

func (f *File) VersionMin() *VersionMin

VersionMin returns the minimum-version load command, or nil if no minimum-version exists.

type FileConfig ¶ added in v1.1.10

type FileConfig struct {
	Offset               int64
	LoadIncluding        []types.LoadCmd
	LoadExcluding        []types.LoadCmd
	VMAddrConverter      types.VMAddrConverter
	SectionReader        types.MachoReader
	CacheReader          types.MachoReader
	RelativeSelectorBase uint64
}

FileConfig is a MachO file config object

type FileTOC ¶

type FileTOC struct {
	types.FileHeader
	ByteOrder binary.ByteOrder
	Loads     loads
	Sections  []*types.Section
	// contains filtered or unexported fields
}

func (*FileTOC) AddLoad ¶

func (t *FileTOC) AddLoad(l Load) uint32

func (*FileTOC) AddSection ¶

func (t *FileTOC) AddSection(s *types.Section)

AddSection adds section to the most recently added Segment

func (*FileTOC) AddSegment ¶

func (t *FileTOC) AddSegment(s *Segment)

AddSegment adds segment s to the file table of contents, and also zeroes out the segment information with the expectation that this will be added next.

func (*FileTOC) DerivedCopy ¶

func (t *FileTOC) DerivedCopy(Type types.HeaderFileType, Flags types.HeaderFlag) *FileTOC

DerivedCopy returns a modified copy of the TOC, with empty loads and sections, and with the specified header type and flags.

func (*FileTOC) FileSize ¶

func (t *FileTOC) FileSize() uint64

FileSize returns the size in bytes of the header, load commands, and the in-file contents of all the segments and sections included in those load commands, accounting for their offsets within the file.

func (*FileTOC) HdrSize ¶

func (t *FileTOC) HdrSize() uint32

HdrSize returns the size in bytes of the Macho header for a given magic number (where the magic number has been appropriately byte-swapped).

func (*FileTOC) LoadAlign ¶

func (t *FileTOC) LoadAlign() uint64

LoadAlign returns the required alignment of Load commands in a binary. This is used to add padding for necessary alignment.

func (*FileTOC) LoadSize ¶

func (t *FileTOC) LoadSize() uint32

LoadSize returns the size of all the load commands in a file's table-of contents (but not their associated data, e.g., sections and symbol tables)

func (*FileTOC) MarshalJSON ¶ added in v1.1.117

func (t *FileTOC) MarshalJSON() ([]byte, error)

func (*FileTOC) ModifySizeCommands ¶ added in v1.1.118

func (t *FileTOC) ModifySizeCommands(prev, curr int32) int32

func (*FileTOC) Print ¶ added in v1.1.117

func (t *FileTOC) Print(printer func(t *FileTOC) string) string

func (*FileTOC) RemoveLoad ¶ added in v1.1.118

func (t *FileTOC) RemoveLoad(l Load) error

func (*FileTOC) String ¶

func (t *FileTOC) String() string

func (*FileTOC) TOCSize ¶

func (t *FileTOC) TOCSize() uint32

TOCSize returns the size in bytes of the object file representation of the header and Load Commands (including Segments and Sections, but not their contents) at the beginning of a Mach-O file. This typically overlaps the text segment in the object file.

type FilesetEntry ¶ added in v1.0.9

type FilesetEntry struct {
	LoadBytes
	types.FilesetEntryCmd
	EntryID string // contained entry id
}

FilesetEntry used with fileset_entry_command

func (*FilesetEntry) LoadSize ¶ added in v1.1.117

func (l *FilesetEntry) LoadSize() uint32

func (*FilesetEntry) MarshalJSON ¶ added in v1.1.117

func (l *FilesetEntry) MarshalJSON() ([]byte, error)

func (*FilesetEntry) String ¶ added in v1.0.9

func (f *FilesetEntry) String() string

func (*FilesetEntry) Write ¶ added in v1.1.33

func (l *FilesetEntry) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type FormatError ¶

type FormatError struct {
	// contains filtered or unexported fields
}

FormatError is returned by some operations if the data does not have the correct format for an object file.

func (*FormatError) Error ¶

func (e *FormatError) Error() string

type FunctionStarts ¶

type FunctionStarts struct {
	LinkEditData
}

A FunctionStarts represents a Mach-O function starts command.

type FvmFile ¶ added in v1.1.46

type FvmFile struct {
	LoadBytes
	types.FvmFileCmd
	Name string
}

A FvmFile represents a Mach-O LC_FVMFILE command.

func (*FvmFile) LoadSize ¶ added in v1.1.117

func (l *FvmFile) LoadSize() uint32

func (*FvmFile) MarshalJSON ¶ added in v1.1.117

func (l *FvmFile) MarshalJSON() ([]byte, error)

func (*FvmFile) String ¶ added in v1.1.46

func (l *FvmFile) String() string

func (*FvmFile) Write ¶ added in v1.1.117

func (l *FvmFile) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type IDDylib ¶ added in v1.1.117

type IDDylib struct {
	Dylib
}

A IDDylib represents a Mach-O LC_ID_DYLIB command.

type IDFvmlib ¶ added in v1.1.46

type IDFvmlib struct {
	LoadFvmlib
}

A IDFvmlib represents a Mach-O LC_IDFVMLIB command.

type Ident ¶ added in v1.1.46

type Ident struct {
	LoadBytes
	types.IdentCmd
	StrTable []string
}

A Ident represents a Mach-O LC_IDENT command.

func (*Ident) LoadSize ¶ added in v1.1.117

func (i *Ident) LoadSize() uint32

func (*Ident) MarshalJSON ¶ added in v1.1.117

func (i *Ident) MarshalJSON() ([]byte, error)

func (*Ident) String ¶ added in v1.1.46

func (i *Ident) String() string

func (*Ident) Write ¶ added in v1.1.117

func (i *Ident) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type LazyLoadDylib ¶ added in v1.0.26

type LazyLoadDylib struct {
	Dylib
}

A LazyLoadDylib represents a Mach-O LC_LAZY_LOAD_DYLIB command.

type LinkEditData ¶

type LinkEditData struct {
	LoadBytes
	types.LinkEditDataCmd
}

A LinkEditData represents a Mach-O linkedit data command.

LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, LC_FUNCTION_STARTS, LC_DATA_IN_CODE,
  LC_DYLIB_CODE_SIGN_DRS, LC_LINKER_OPTIMIZATION_HINT, LC_DYLD_EXPORTS_TRIE, or LC_DYLD_CHAINED_FIXUPS.

func (*LinkEditData) LoadSize ¶ added in v1.1.117

func (l *LinkEditData) LoadSize() uint32

func (*LinkEditData) MarshalJSON ¶ added in v1.1.117

func (l *LinkEditData) MarshalJSON() ([]byte, error)

func (*LinkEditData) String ¶ added in v1.1.117

func (l *LinkEditData) String() string

func (*LinkEditData) Write ¶ added in v1.1.33

func (l *LinkEditData) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type LinkerOptimizationHint ¶ added in v1.1.33

type LinkerOptimizationHint struct {
	LinkEditData
}

type LinkerOption ¶ added in v1.1.46

type LinkerOption struct {
	LoadBytes
	types.LinkerOptionCmd
	Options []string
}

A LinkerOption represents a Mach-O LC_LINKER_OPTION command.

func (*LinkerOption) LoadSize ¶ added in v1.1.117

func (l *LinkerOption) LoadSize() uint32

func (*LinkerOption) MarshalJSON ¶ added in v1.1.117

func (l *LinkerOption) MarshalJSON() ([]byte, error)

func (*LinkerOption) String ¶ added in v1.1.46

func (l *LinkerOption) String() string

func (*LinkerOption) Write ¶ added in v1.1.117

func (l *LinkerOption) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type Load ¶

type Load interface {
	Command() types.LoadCmd
	LoadSize() uint32 // Need the TOC for alignment, sigh.
	Raw() []byte
	Write(buf *bytes.Buffer, o binary.ByteOrder) error
	String() string
	MarshalJSON() ([]byte, error)
}

A Load represents any Mach-O load command.

type LoadBytes ¶

type LoadBytes []byte

A LoadBytes is the uninterpreted bytes of a Mach-O load command.

func (LoadBytes) Copy ¶

func (b LoadBytes) Copy() LoadBytes

func (LoadBytes) LoadSize ¶

func (b LoadBytes) LoadSize() uint32

func (LoadBytes) MarshalJSON ¶ added in v1.1.117

func (b LoadBytes) MarshalJSON() ([]byte, error)

func (LoadBytes) Raw ¶

func (b LoadBytes) Raw() []byte

func (LoadBytes) String ¶

func (b LoadBytes) String() string

func (LoadBytes) Write ¶ added in v1.1.33

func (b LoadBytes) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type LoadCmdBytes ¶

type LoadCmdBytes struct {
	types.LoadCmd
	LoadBytes
}

LoadCmdBytes is a command-tagged sequence of bytes. This is used for Load Commands that are not (yet) interesting to us, and to common up this behavior for all those that are.

func (LoadCmdBytes) Copy ¶

func (s LoadCmdBytes) Copy() LoadCmdBytes

func (LoadCmdBytes) String ¶

func (s LoadCmdBytes) String() string

type LoadDylib ¶ added in v1.1.117

type LoadDylib struct {
	Dylib
}

A LoadDylib represents a Mach-O LC_LOAD_DYLIB command.

type LoadDylinker ¶ added in v1.0.4

type LoadDylinker struct {
	Dylinker
}

A LoadDylinker represents a Mach-O LC_LOAD_DYLINKER command.

type LoadFvmlib ¶ added in v1.1.46

type LoadFvmlib struct {
	LoadBytes
	types.LoadFvmLibCmd
	Name string
}

A LoadFvmlib represents a Mach-O LC_LOADFVMLIB command.

func (*LoadFvmlib) LoadSize ¶ added in v1.1.117

func (l *LoadFvmlib) LoadSize() uint32

func (*LoadFvmlib) MarshalJSON ¶ added in v1.1.117

func (l *LoadFvmlib) MarshalJSON() ([]byte, error)

func (*LoadFvmlib) String ¶ added in v1.1.46

func (l *LoadFvmlib) String() string

func (*LoadFvmlib) Write ¶ added in v1.1.117

func (l *LoadFvmlib) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type Note ¶ added in v1.1.46

type Note struct {
	LoadBytes
	types.NoteCmd
}

A Note represents a Mach-O LC_NOTE command.

func (*Note) LoadSize ¶ added in v1.1.117

func (n *Note) LoadSize() uint32

func (*Note) MarshalJSON ¶ added in v1.1.117

func (n *Note) MarshalJSON() ([]byte, error)

func (*Note) String ¶ added in v1.1.46

func (n *Note) String() string

func (*Note) Write ¶ added in v1.1.117

func (n *Note) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type PrebindCheckSum ¶ added in v1.1.117

type PrebindCheckSum struct {
	LoadBytes
	types.PrebindCksumCmd
}

A PrebindCheckSum is a Mach-O LC_PREBIND_CKSUM command.

func (*PrebindCheckSum) LoadSize ¶ added in v1.1.117

func (l *PrebindCheckSum) LoadSize() uint32

func (*PrebindCheckSum) MarshalJSON ¶ added in v1.1.117

func (l *PrebindCheckSum) MarshalJSON() ([]byte, error)

func (*PrebindCheckSum) String ¶ added in v1.1.117

func (l *PrebindCheckSum) String() string

func (*PrebindCheckSum) Write ¶ added in v1.1.117

func (l *PrebindCheckSum) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type PreboundDylib ¶ added in v1.1.46

type PreboundDylib struct {
	LoadBytes
	types.PreboundDylibCmd
	Name                   string
	LinkedModulesBitVector string
}

PreboundDylib represents a Mach-O LC_PREBOUND_DYLIB command.

func (*PreboundDylib) LoadSize ¶ added in v1.1.117

func (d *PreboundDylib) LoadSize() uint32

func (*PreboundDylib) MarshalJSON ¶ added in v1.1.117

func (d *PreboundDylib) MarshalJSON() ([]byte, error)

func (*PreboundDylib) Put ¶ added in v1.1.117

func (d *PreboundDylib) Put(b []byte, o binary.ByteOrder) int

func (*PreboundDylib) String ¶ added in v1.1.46

func (d *PreboundDylib) String() string

func (*PreboundDylib) Write ¶ added in v1.1.117

func (d *PreboundDylib) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type Prepage ¶ added in v1.1.46

type Prepage struct {
	LoadBytes
	types.PrePageCmd
}

A Prepage represents a Mach-O LC_PREPAGE command.

func (*Prepage) LoadSize ¶ added in v1.1.117

func (c *Prepage) LoadSize() uint32

func (*Prepage) MarshalJSON ¶ added in v1.1.117

func (c *Prepage) MarshalJSON() ([]byte, error)

func (*Prepage) String ¶ added in v1.1.117

func (c *Prepage) String() string

func (*Prepage) Write ¶ added in v1.1.117

func (c *Prepage) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type ReExportDylib ¶

type ReExportDylib struct {
	Dylib
}

A ReExportDylib represents a Mach-O LC_REEXPORT_DYLIB command.

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 is the Mach-O 386 register structure.

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 is the Mach-O AMD64 register structure.

type RegsARM ¶

type RegsARM struct {
	R0   uint32
	R1   uint32
	R2   uint32
	R3   uint32
	R4   uint32
	R5   uint32
	R6   uint32
	R7   uint32
	R8   uint32
	R9   uint32
	R10  uint32
	R11  uint32
	R12  uint32
	SP   uint32
	LR   uint32
	PC   uint32
	CPSR uint32
}

RegsARM is the Mach-O ARM register structure.

type RegsARM64 ¶

type RegsARM64 struct {
	X0   uint64
	X1   uint64
	X2   uint64
	X3   uint64
	X4   uint64
	X5   uint64
	X6   uint64
	X7   uint64
	X8   uint64
	X9   uint64
	X10  uint64
	X11  uint64
	X12  uint64
	X13  uint64
	X14  uint64
	X15  uint64
	X16  uint64
	X17  uint64
	X18  uint64
	X19  uint64
	X20  uint64
	X21  uint64
	X22  uint64
	X23  uint64
	X24  uint64
	X25  uint64
	X26  uint64
	X27  uint64
	X28  uint64
	FP   uint64
	LR   uint64
	SP   uint64
	PC   uint64
	CPSR uint32
	PAD  uint32
}

RegsARM64 is the Mach-O ARM 64 register structure.

type Routines ¶ added in v1.1.20

type Routines struct {
	LoadBytes
	types.RoutinesCmd
}

A Routines is a Mach-O LC_ROUTINES command.

func (*Routines) LoadSize ¶ added in v1.1.117

func (l *Routines) LoadSize() uint32

func (*Routines) MarshalJSON ¶ added in v1.1.117

func (l *Routines) MarshalJSON() ([]byte, error)

func (*Routines) String ¶ added in v1.1.20

func (l *Routines) String() string

func (*Routines) Write ¶ added in v1.1.117

func (l *Routines) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type Routines64 ¶

type Routines64 struct {
	LoadBytes
	types.Routines64Cmd
}

A Routines64 is a Mach-O LC_ROUTINES_64 command.

func (*Routines64) LoadSize ¶ added in v1.1.117

func (l *Routines64) LoadSize() uint32

func (*Routines64) MarshalJSON ¶ added in v1.1.117

func (l *Routines64) MarshalJSON() ([]byte, error)

func (*Routines64) String ¶ added in v1.1.20

func (l *Routines64) String() string

func (*Routines64) Write ¶ added in v1.1.117

func (l *Routines64) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type Rpath ¶

type Rpath struct {
	LoadBytes
	types.RpathCmd
	Path string
}

A Rpath represents a Mach-O LC_RPATH command.

func (*Rpath) LoadSize ¶ added in v1.1.117

func (r *Rpath) LoadSize() uint32

func (*Rpath) MarshalJSON ¶ added in v1.1.117

func (r *Rpath) MarshalJSON() ([]byte, error)

func (*Rpath) String ¶ added in v1.0.9

func (r *Rpath) String() string

func (*Rpath) Write ¶ added in v1.1.117

func (r *Rpath) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type Segment ¶

type Segment struct {
	SegmentHeader
	LoadBytes

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

A Segment represents a Mach-O 32-bit or 64-bit load segment command.

func (*Segment) Copy ¶

func (s *Segment) Copy() *Segment

func (*Segment) CopyZeroed ¶

func (s *Segment) CopyZeroed() *Segment

func (*Segment) Data ¶

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

Data reads and returns the contents of the segment.

func (*Segment) LessThan ¶ added in v1.1.56

func (s *Segment) LessThan(o *Segment) bool

func (*Segment) LoadSize ¶

func (s *Segment) LoadSize() uint32

func (*Segment) MarshalJSON ¶ added in v1.1.117

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

func (*Segment) Open ¶

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

Open returns a new ReadSeeker reading the segment.

func (*Segment) Put32 ¶

func (s *Segment) Put32(b []byte, o binary.ByteOrder) int

func (*Segment) Put64 ¶

func (s *Segment) Put64(b []byte, o binary.ByteOrder) int

func (*Segment) String ¶

func (s *Segment) String() string

func (*Segment) UncompressedSize ¶

func (s *Segment) UncompressedSize(t *FileTOC, align uint64) uint64

UncompressedSize returns the size of the segment with its sections uncompressed, ignoring its offset within the file. The returned size is rounded up to the power of two in align.

func (*Segment) Write ¶ added in v1.1.33

func (s *Segment) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type SegmentHeader ¶

type SegmentHeader struct {
	types.LoadCmd
	Len       uint32
	Name      string
	Addr      uint64
	Memsz     uint64
	Offset    uint64
	Filesz    uint64
	Maxprot   types.VmProtection
	Prot      types.VmProtection
	Nsect     uint32
	Flag      types.SegFlag
	Firstsect uint32
}

A SegmentHeader is the header for a Mach-O 32-bit or 64-bit load segment command.

func (*SegmentHeader) String ¶

func (s *SegmentHeader) String() string

type Segments ¶ added in v1.1.56

type Segments []*Segment

func (Segments) Len ¶ added in v1.1.56

func (v Segments) Len() int

func (Segments) Less ¶ added in v1.1.56

func (v Segments) Less(i, j int) bool

func (Segments) Swap ¶ added in v1.1.56

func (v Segments) Swap(i, j int)

type SourceVersion ¶

type SourceVersion struct {
	LoadBytes
	types.SourceVersionCmd
}

A SourceVersion represents a Mach-O LC_SOURCE_VERSION command.

func (*SourceVersion) LoadSize ¶ added in v1.1.117

func (s *SourceVersion) LoadSize() uint32

func (*SourceVersion) MarshalJSON ¶ added in v1.1.117

func (s *SourceVersion) MarshalJSON() ([]byte, error)

func (*SourceVersion) String ¶ added in v1.0.4

func (s *SourceVersion) String() string

func (*SourceVersion) Write ¶ added in v1.1.117

func (s *SourceVersion) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type SplitInfo ¶

type SplitInfo struct {
	LoadBytes
	types.SegmentSplitInfoCmd
	Version uint8
}

A SplitInfo represents a Mach-O LC_SEGMENT_SPLIT_INFO command.

func (*SplitInfo) LoadSize ¶ added in v1.1.117

func (l *SplitInfo) LoadSize() uint32

func (*SplitInfo) MarshalJSON ¶ added in v1.1.117

func (l *SplitInfo) MarshalJSON() ([]byte, error)

func (*SplitInfo) String ¶ added in v1.0.9

func (s *SplitInfo) String() string

func (*SplitInfo) Write ¶ added in v1.1.33

func (l *SplitInfo) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type SubClient ¶

type SubClient struct {
	LoadBytes
	types.SubClientCmd
	Name string
}

A SubClient is a Mach-O LC_SUB_CLIENT command.

func (*SubClient) LoadSize ¶ added in v1.1.117

func (l *SubClient) LoadSize() uint32

func (*SubClient) MarshalJSON ¶ added in v1.1.117

func (l *SubClient) MarshalJSON() ([]byte, error)

func (*SubClient) String ¶ added in v1.0.9

func (l *SubClient) String() string

func (*SubClient) Write ¶ added in v1.1.117

func (l *SubClient) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type SubFramework ¶

type SubFramework struct {
	LoadBytes
	types.SubFrameworkCmd
	Framework string
}

A SubFramework is a Mach-O LC_SUB_FRAMEWORK command.

func (*SubFramework) LoadSize ¶ added in v1.1.117

func (l *SubFramework) LoadSize() uint32

func (*SubFramework) MarshalJSON ¶ added in v1.1.117

func (l *SubFramework) MarshalJSON() ([]byte, error)

func (*SubFramework) String ¶ added in v1.0.24

func (l *SubFramework) String() string

func (*SubFramework) Write ¶ added in v1.1.117

func (l *SubFramework) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type SubLibrary ¶ added in v1.1.46

type SubLibrary struct {
	LoadBytes
	types.SubLibraryCmd
	Library string
}

A SubLibrary is a Mach-O LC_SUB_LIBRARY command.

func (*SubLibrary) LoadSize ¶ added in v1.1.117

func (l *SubLibrary) LoadSize() uint32

func (*SubLibrary) MarshalJSON ¶ added in v1.1.117

func (l *SubLibrary) MarshalJSON() ([]byte, error)

func (*SubLibrary) String ¶ added in v1.1.46

func (l *SubLibrary) String() string

func (*SubLibrary) Write ¶ added in v1.1.117

func (l *SubLibrary) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type SubUmbrella ¶ added in v1.1.46

type SubUmbrella struct {
	LoadBytes
	types.SubUmbrellaCmd
	Umbrella string
}

A SubUmbrella is a Mach-O LC_SUB_UMBRELLA command.

func (*SubUmbrella) LoadSize ¶ added in v1.1.117

func (l *SubUmbrella) LoadSize() uint32

func (*SubUmbrella) MarshalJSON ¶ added in v1.1.117

func (l *SubUmbrella) MarshalJSON() ([]byte, error)

func (*SubUmbrella) String ¶ added in v1.1.46

func (l *SubUmbrella) String() string

func (*SubUmbrella) Write ¶ added in v1.1.117

func (l *SubUmbrella) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type SymSeg ¶ added in v1.1.46

type SymSeg struct {
	LoadBytes
	types.SymsegCmd
}

A SymSeg represents a Mach-O LC_SYMSEG command.

func (*SymSeg) LoadSize ¶ added in v1.1.117

func (s *SymSeg) LoadSize() uint32

func (*SymSeg) MarshalJSON ¶ added in v1.1.117

func (s *SymSeg) MarshalJSON() ([]byte, error)

func (*SymSeg) String ¶ added in v1.1.46

func (s *SymSeg) String() string

func (*SymSeg) Write ¶ added in v1.1.117

func (s *SymSeg) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type Symbol ¶

type Symbol struct {
	Name  string
	Type  types.NType
	Sect  uint8
	Desc  types.NDescType
	Value uint64
}

A Symbol is a Mach-O 32-bit or 64-bit symbol table entry.

func (Symbol) GetLib ¶ added in v1.1.150

func (s Symbol) GetLib(m *File) string

func (Symbol) GetType ¶ added in v1.1.150

func (s Symbol) GetType(m *File) string

func (*Symbol) MarshalJSON ¶ added in v1.1.117

func (s *Symbol) MarshalJSON() ([]byte, error)

func (Symbol) String ¶ added in v1.0.24

func (s Symbol) String(m *File) string

type Symtab ¶

type Symtab struct {
	LoadBytes
	types.SymtabCmd
	Syms []Symbol
}

A Symtab represents a Mach-O LC_SYMTAB command.

func (*Symtab) LoadSize ¶

func (s *Symtab) LoadSize() uint32

func (*Symtab) MarshalJSON ¶ added in v1.1.117

func (s *Symtab) MarshalJSON() ([]byte, error)

func (*Symtab) Put ¶

func (s *Symtab) Put(b []byte, o binary.ByteOrder) int

func (*Symtab) Search ¶ added in v1.1.85

func (s *Symtab) Search(name string) (*Symbol, error)

func (*Symtab) String ¶

func (s *Symtab) String() string

func (*Symtab) Write ¶ added in v1.1.33

func (s *Symtab) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type Thread ¶ added in v1.1.46

type Thread struct {
	LoadBytes
	types.ThreadCmd

	Threads []types.ThreadState
	// contains filtered or unexported fields
}

A Thread represents a Mach-O LC_THREAD command.

func (*Thread) LoadSize ¶ added in v1.1.117

func (t *Thread) LoadSize() uint32

func (*Thread) MarshalJSON ¶ added in v1.1.117

func (t *Thread) MarshalJSON() ([]byte, error)

func (*Thread) String ¶ added in v1.1.46

func (t *Thread) String() string

func (*Thread) Write ¶ added in v1.1.117

func (t *Thread) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type TwolevelHints ¶ added in v1.1.46

type TwolevelHints struct {
	LoadBytes
	types.TwolevelHintsCmd
	Hints []types.TwolevelHint
}

A TwolevelHints is a Mach-O LC_TWOLEVEL_HINTS command.

func (*TwolevelHints) LoadSize ¶ added in v1.1.117

func (l *TwolevelHints) LoadSize() uint32

func (*TwolevelHints) MarshalJSON ¶ added in v1.1.117

func (l *TwolevelHints) MarshalJSON() ([]byte, error)

func (*TwolevelHints) String ¶ added in v1.1.46

func (l *TwolevelHints) String() string

func (*TwolevelHints) Write ¶ added in v1.1.117

func (l *TwolevelHints) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type UUID ¶

type UUID struct {
	LoadBytes
	types.UUIDCmd
}

UUID represents a Mach-O LC_UUID command.

func (*UUID) LoadSize ¶

func (l *UUID) LoadSize() uint32

func (*UUID) MarshalJSON ¶ added in v1.1.117

func (l *UUID) MarshalJSON() ([]byte, error)

func (*UUID) String ¶

func (l *UUID) String() string

func (*UUID) Write ¶ added in v1.1.117

func (l *UUID) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type UnixThread ¶

type UnixThread struct {
	Thread
}

A UnixThread represents a Mach-O LC_UNIXTHREAD command.

type UpwardDylib ¶

type UpwardDylib struct {
	Dylib
}

A UpwardDylib represents a Mach-O LC_LOAD_UPWARD_DYLIB load command.

type VersionMin ¶ added in v1.1.117

type VersionMin struct {
	LoadBytes
	types.VersionMinCmd
}

A VersionMin represents a Mach-O LC_VERSION_MIN_* command.

func (*VersionMin) LoadSize ¶ added in v1.1.117

func (v *VersionMin) LoadSize() uint32

func (*VersionMin) MarshalJSON ¶ added in v1.1.117

func (v *VersionMin) MarshalJSON() ([]byte, error)

func (*VersionMin) String ¶ added in v1.1.117

func (v *VersionMin) String() string

func (*VersionMin) Write ¶ added in v1.1.117

func (v *VersionMin) Write(buf *bytes.Buffer, o binary.ByteOrder) error

type VersionMinMacOSX ¶ added in v1.0.9

type VersionMinMacOSX struct {
	VersionMin
}

VersionMinMacOSX build for MacOSX min OS version

type VersionMinTvOS ¶ added in v1.0.9

type VersionMinTvOS struct {
	VersionMin
}

VersionMinTvOS build for AppleTV min OS version

type VersionMinWatchOS ¶ added in v1.0.9

type VersionMinWatchOS struct {
	VersionMin
}

VersionMinWatchOS build for Watch min OS version

type VersionMiniPhoneOS ¶ added in v1.0.9

type VersionMiniPhoneOS struct {
	VersionMin
}

VersionMiniPhoneOS build for iPhoneOS min OS version

type WeakDylib ¶

type WeakDylib struct {
	Dylib
}

A WeakDylib represents a Mach-O LC_LOAD_WEAK_DYLIB command.

Directories ¶

Path Synopsis
internal
obscuretestdata
Package obscuretestdata contains functionality used by tests to more easily work with testdata that must be obscured primarily due to golang.org/issue/34986.
Package obscuretestdata contains functionality used by tests to more easily work with testdata that must be obscured primarily due to golang.org/issue/34986.
saferio
Package saferio provides I/O functions that avoid allocating large amounts of memory unnecessarily.
Package saferio provides I/O functions that avoid allocating large amounts of memory unnecessarily.
pkg
xar
Package xar provides for reading and writing XAR archives.
Package xar provides for reading and writing XAR archives.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL