Documentation
¶
Overview ¶
machoパッケージは、Mach-Oオブジェクトファイルへのアクセスを実装します。
セキュリティ ¶
このパッケージは、敵対的な入力に対して強化されるように設計されていません、そして https://go.dev/security/policy の範囲外です。特に、オブジェクトファイルを解析する際には基本的な 検証のみが行われます。そのため、信頼できない入力を解析する際には注意が必要です、なぜなら、 不正なファイルを解析すると、大量のリソースを消費するか、パニックを引き起こす可能性があります。
Index ¶
- Constants
- Variables
- type Cpu
- type Dylib
- type DylibCmd
- type Dysymtab
- type DysymtabCmd
- type FatArch
- type FatArchHeader
- type FatFile
- type File
- type FileHeader
- type FormatError
- type Load
- type LoadBytes
- type LoadCmd
- type Nlist32
- type Nlist64
- type Regs386
- type RegsAMD64
- type Reloc
- type RelocTypeARM
- type RelocTypeARM64
- type RelocTypeGeneric
- type RelocTypeX86_64
- type Rpath
- type RpathCmd
- type Section
- type Section32
- type Section64
- type SectionHeader
- type Segment
- type Segment32
- type Segment64
- type SegmentHeader
- type Symbol
- type Symtab
- type SymtabCmd
- type Thread
- type Type
Constants ¶
const ( Magic32 uint32 = 0xfeedface Magic64 uint32 = 0xfeedfacf MagicFat uint32 = 0xcafebabe )
const ( FlagNoUndefs uint32 = 0x1 FlagIncrLink uint32 = 0x2 FlagDyldLink uint32 = 0x4 FlagBindAtLoad uint32 = 0x8 FlagPrebound uint32 = 0x10 FlagSplitSegs uint32 = 0x20 FlagLazyInit uint32 = 0x40 FlagTwoLevel uint32 = 0x80 FlagForceFlat uint32 = 0x100 FlagNoMultiDefs uint32 = 0x200 FlagNoFixPrebinding uint32 = 0x400 FlagPrebindable uint32 = 0x800 FlagAllModsBound uint32 = 0x1000 FlagSubsectionsViaSymbols uint32 = 0x2000 FlagCanonical uint32 = 0x4000 FlagWeakDefines uint32 = 0x8000 FlagBindsToWeak uint32 = 0x10000 FlagAllowStackExecution uint32 = 0x20000 FlagRootSafe uint32 = 0x40000 FlagSetuidSafe uint32 = 0x80000 FlagNoReexportedDylibs uint32 = 0x100000 FlagPIE uint32 = 0x200000 FlagDeadStrippableDylib uint32 = 0x400000 FlagHasTLVDescriptors uint32 = 0x800000 FlagNoHeapExecution uint32 = 0x1000000 FlagAppExtensionSafe uint32 = 0x2000000 )
Variables ¶
var ErrNotFat = &FormatError{0, "not a fat Mach-O file", nil}
ErrNotFatは、ファイルがユニバーサルバイナリではなく、 マジックナンバーに基づいてシンバイナリである可能性がある場合、 NewFatFile または OpenFat から返されます。
Functions ¶
This section is empty.
Types ¶
type DylibCmd ¶
type DylibCmd struct {
Cmd LoadCmd
Len uint32
Name uint32
Time uint32
CurrentVersion uint32
CompatVersion uint32
}
DylibCmdは、Mach-Oの動的ライブラリロードコマンドです。
type Dysymtab ¶
type Dysymtab struct {
LoadBytes
DysymtabCmd
IndirectSyms []uint32
}
A Dysymtab represents a Mach-O dynamic symbol table command.
type DysymtabCmd ¶
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
}
DysymtabCmdは、Mach-Oの動的シンボルテーブルコマンドです。
type FatArch ¶ added in v1.3.0
type FatArch struct {
FatArchHeader
*File
}
FatArchは、FatFile内のMach-Oファイルです。
type FatArchHeader ¶ added in v1.3.0
FatArchHeaderは、特定のイメージアーキテクチャのためのファットヘッダーを表します。
type FatFile ¶ added in v1.3.0
FatFileは、少なくとも1つのアーキテクチャを含むMach-Oユニバーサルバイナリです。
func NewFatFile ¶ added in v1.3.0
NewFatFileは、ユニバーサルバイナリ内のすべてのMach-Oイメージにアクセスするための新しい FatFile を作成します。 Mach-Oバイナリは、ReaderAtの位置0で開始することが期待されています。
type File ¶
type File struct {
FileHeader
ByteOrder binary.ByteOrder
Loads []Load
Sections []*Section
Symtab *Symtab
Dysymtab *Dysymtab
// contains filtered or unexported fields
}
Fileは、開かれたMach-Oファイルを表します。
func NewFile ¶
NewFileは、基礎となるリーダーでMach-Oバイナリにアクセスするための新しいFileを作成します。 Mach-Oバイナリは、ReaderAtの位置0で開始することが期待されています。
func (*File) ImportedLibraries ¶
ImportedLibrariesは、バイナリfが参照しているすべてのライブラリのパスを返します。 これらは、動的リンク時にバイナリとリンクされることが期待されています。
func (*File) ImportedSymbols ¶
ImportedSymbolsは、バイナリfが参照しているすべてのシンボルの名前を返します。 これらは、動的ロード時に他のライブラリによって満たされることが期待されています。
type FileHeader ¶
type FileHeader struct {
Magic uint32
Cpu Cpu
SubCpu uint32
Type Type
Ncmd uint32
Cmdsz uint32
Flags uint32
}
FileHeaderは、Mach-Oファイルヘッダーを表します。
type FormatError ¶
type FormatError struct {
// contains filtered or unexported fields
}
FormatErrorは、データがオブジェクトファイルの正しい形式でない場合、 一部の操作によって返されます。
func (*FormatError) Error ¶
func (e *FormatError) Error() string
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は、Mach-O 386のレジスタ構造体です。
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は、Mach-O AMD64のレジスタ構造体です。
type Reloc ¶ added in v1.10.0
type Reloc struct {
Addr uint32
Value uint32
// Scattered == false かつ Extern == true の場合、Valueはシンボル番号です。
// Scattered == false かつ Extern == false の場合、Valueはセクション番号です。
// Scattered == true の場合、Valueはこの再配置が参照する値です。
Type uint8
Len uint8
Pcrel bool
Extern bool
Scattered bool
}
Relocは、Mach-Oの再配置を表します。
type RelocTypeARM ¶ added in v1.10.0
type RelocTypeARM int
const ( ARM_RELOC_VANILLA RelocTypeARM = 0 ARM_RELOC_PAIR RelocTypeARM = 1 ARM_RELOC_SECTDIFF RelocTypeARM = 2 ARM_RELOC_LOCAL_SECTDIFF RelocTypeARM = 3 ARM_RELOC_PB_LA_PTR RelocTypeARM = 4 ARM_RELOC_BR24 RelocTypeARM = 5 ARM_THUMB_RELOC_BR22 RelocTypeARM = 6 ARM_THUMB_32BIT_BRANCH RelocTypeARM = 7 ARM_RELOC_HALF RelocTypeARM = 8 ARM_RELOC_HALF_SECTDIFF RelocTypeARM = 9 )
func (RelocTypeARM) GoString ¶ added in v1.10.0
func (r RelocTypeARM) GoString() string
func (RelocTypeARM) String ¶ added in v1.10.0
func (i RelocTypeARM) String() string
type RelocTypeARM64 ¶ added in v1.10.0
type RelocTypeARM64 int
const ( ARM64_RELOC_UNSIGNED RelocTypeARM64 = 0 ARM64_RELOC_SUBTRACTOR RelocTypeARM64 = 1 ARM64_RELOC_BRANCH26 RelocTypeARM64 = 2 ARM64_RELOC_PAGE21 RelocTypeARM64 = 3 ARM64_RELOC_PAGEOFF12 RelocTypeARM64 = 4 ARM64_RELOC_GOT_LOAD_PAGE21 RelocTypeARM64 = 5 ARM64_RELOC_GOT_LOAD_PAGEOFF12 RelocTypeARM64 = 6 ARM64_RELOC_POINTER_TO_GOT RelocTypeARM64 = 7 ARM64_RELOC_TLVP_LOAD_PAGE21 RelocTypeARM64 = 8 ARM64_RELOC_TLVP_LOAD_PAGEOFF12 RelocTypeARM64 = 9 ARM64_RELOC_ADDEND RelocTypeARM64 = 10 )
func (RelocTypeARM64) GoString ¶ added in v1.10.0
func (r RelocTypeARM64) GoString() string
func (RelocTypeARM64) String ¶ added in v1.10.0
func (i RelocTypeARM64) String() string
type RelocTypeGeneric ¶ added in v1.10.0
type RelocTypeGeneric int
const ( GENERIC_RELOC_VANILLA RelocTypeGeneric = 0 GENERIC_RELOC_PAIR RelocTypeGeneric = 1 GENERIC_RELOC_SECTDIFF RelocTypeGeneric = 2 GENERIC_RELOC_PB_LA_PTR RelocTypeGeneric = 3 GENERIC_RELOC_LOCAL_SECTDIFF RelocTypeGeneric = 4 GENERIC_RELOC_TLV RelocTypeGeneric = 5 )
func (RelocTypeGeneric) GoString ¶ added in v1.10.0
func (r RelocTypeGeneric) GoString() string
func (RelocTypeGeneric) String ¶ added in v1.10.0
func (i RelocTypeGeneric) String() string
type RelocTypeX86_64 ¶ added in v1.10.0
type RelocTypeX86_64 int
const ( X86_64_RELOC_UNSIGNED RelocTypeX86_64 = 0 X86_64_RELOC_SIGNED RelocTypeX86_64 = 1 X86_64_RELOC_BRANCH RelocTypeX86_64 = 2 X86_64_RELOC_GOT_LOAD RelocTypeX86_64 = 3 X86_64_RELOC_GOT RelocTypeX86_64 = 4 X86_64_RELOC_SUBTRACTOR RelocTypeX86_64 = 5 X86_64_RELOC_SIGNED_1 RelocTypeX86_64 = 6 X86_64_RELOC_SIGNED_2 RelocTypeX86_64 = 7 X86_64_RELOC_SIGNED_4 RelocTypeX86_64 = 8 X86_64_RELOC_TLV RelocTypeX86_64 = 9 )
func (RelocTypeX86_64) GoString ¶ added in v1.10.0
func (r RelocTypeX86_64) GoString() string
func (RelocTypeX86_64) String ¶ added in v1.10.0
func (i RelocTypeX86_64) String() string
type Section ¶
type Section struct {
SectionHeader
Relocs []Reloc
// ReadAtメソッドのためにReaderAtを埋め込みます。
// ReadとSeekを避けるために、SectionReaderを直接埋め込まないでください。
// クライアントがReadとSeekを使用したい場合は、
// 他のクライアントとのシークオフセットの競合を避けるために
// Open()を使用する必要があります。
io.ReaderAt
// contains filtered or unexported fields
}
func (*Section) Open ¶
func (s *Section) Open() io.ReadSeeker
Openは、Mach-Oセクションを読み取る新しいReadSeekerを返します。
type Section32 ¶
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
}
Section32は、32ビットMach-Oセクションヘッダーです。
type Section64 ¶
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
}
Section64は、64ビットMach-Oセクションヘッダーです。
type SectionHeader ¶
type Segment ¶
type Segment struct {
LoadBytes
SegmentHeader
// ReadAtメソッドのためにReaderAtを埋め込みます。
// ReadとSeekを避けるために、SectionReaderを直接埋め込まないでください。
// クライアントがReadとSeekを使用したい場合は、
// 他のクライアントとのシークオフセットの競合を避けるために
// Open()を使用する必要があります。
io.ReaderAt
// contains filtered or unexported fields
}
Segmentは、Mach-O 32ビットまたは64ビットのロードセグメントコマンドを表します。
type Segment32 ¶
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
}
Segment32は、32ビットMach-Oのセグメントロードコマンドです。
type Segment64 ¶
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
}
Segment64は、64ビットMach-Oのセグメントロードコマンドです。
type SegmentHeader ¶
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
}
SegmentHeaderは、Mach-O 32ビットまたは64ビットのロードセグメントコマンドのヘッダーです。
type SymtabCmd ¶
type SymtabCmd struct {
Cmd LoadCmd
Len uint32
Symoff uint32
Nsyms uint32
Stroff uint32
Strsize uint32
}
SymtabCmdは、Mach-Oのシンボルテーブルコマンドです。