github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/debug/macho/macho.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Mach-O header data structures 6 // Originally at: 7 // http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html (since deleted by Apple) 8 // Archived copy at: 9 // https://web.archive.org/web/20090819232456/http://developer.apple.com/documentation/DeveloperTools/Conceptual/MachORuntime/index.html 10 // For cloned PDF see: 11 // https://github.com/aidansteele/osx-abi-macho-file-format-reference 12 13 package macho 14 15 // FileHeaderは、Mach-Oファイルヘッダーを表します。 16 type FileHeader struct { 17 Magic uint32 18 Cpu Cpu 19 SubCpu uint32 20 Type Type 21 Ncmd uint32 22 Cmdsz uint32 23 Flags uint32 24 } 25 26 const ( 27 Magic32 uint32 = 0xfeedface 28 Magic64 uint32 = 0xfeedfacf 29 MagicFat uint32 = 0xcafebabe 30 ) 31 32 // Typeは、Mach-Oファイルのタイプを表します。例えば、オブジェクトファイル、実行可能ファイル、または動的ライブラリなどです。 33 type Type uint32 34 35 const ( 36 TypeObj Type = 1 37 TypeExec Type = 2 38 TypeDylib Type = 6 39 TypeBundle Type = 8 40 ) 41 42 func (t Type) String() string 43 func (t Type) GoString() string 44 45 // Cpuは、Mach-OのCPUタイプを表します。 46 type Cpu uint32 47 48 const ( 49 Cpu386 Cpu = 7 50 CpuAmd64 Cpu = Cpu386 | cpuArch64 51 CpuArm Cpu = 12 52 CpuArm64 Cpu = CpuArm | cpuArch64 53 CpuPpc Cpu = 18 54 CpuPpc64 Cpu = CpuPpc | cpuArch64 55 ) 56 57 func (i Cpu) String() string 58 func (i Cpu) GoString() string 59 60 // LoadCmdは、Mach-Oのロードコマンドです。 61 type LoadCmd uint32 62 63 const ( 64 LoadCmdSegment LoadCmd = 0x1 65 LoadCmdSymtab LoadCmd = 0x2 66 LoadCmdThread LoadCmd = 0x4 67 LoadCmdUnixThread LoadCmd = 0x5 68 LoadCmdDysymtab LoadCmd = 0xb 69 LoadCmdDylib LoadCmd = 0xc 70 LoadCmdDylinker LoadCmd = 0xf 71 LoadCmdSegment64 LoadCmd = 0x19 72 LoadCmdRpath LoadCmd = 0x8000001c 73 ) 74 75 func (i LoadCmd) String() string 76 func (i LoadCmd) GoString() string 77 78 type ( 79 // Segment32は、32ビットMach-Oのセグメントロードコマンドです。 80 Segment32 struct { 81 Cmd LoadCmd 82 Len uint32 83 Name [16]byte 84 Addr uint32 85 Memsz uint32 86 Offset uint32 87 Filesz uint32 88 Maxprot uint32 89 Prot uint32 90 Nsect uint32 91 Flag uint32 92 } 93 94 // Segment64は、64ビットMach-Oのセグメントロードコマンドです。 95 Segment64 struct { 96 Cmd LoadCmd 97 Len uint32 98 Name [16]byte 99 Addr uint64 100 Memsz uint64 101 Offset uint64 102 Filesz uint64 103 Maxprot uint32 104 Prot uint32 105 Nsect uint32 106 Flag uint32 107 } 108 109 // SymtabCmdは、Mach-Oのシンボルテーブルコマンドです。 110 SymtabCmd struct { 111 Cmd LoadCmd 112 Len uint32 113 Symoff uint32 114 Nsyms uint32 115 Stroff uint32 116 Strsize uint32 117 } 118 119 // DysymtabCmdは、Mach-Oの動的シンボルテーブルコマンドです。 120 DysymtabCmd struct { 121 Cmd LoadCmd 122 Len uint32 123 Ilocalsym uint32 124 Nlocalsym uint32 125 Iextdefsym uint32 126 Nextdefsym uint32 127 Iundefsym uint32 128 Nundefsym uint32 129 Tocoffset uint32 130 Ntoc uint32 131 Modtaboff uint32 132 Nmodtab uint32 133 Extrefsymoff uint32 134 Nextrefsyms uint32 135 Indirectsymoff uint32 136 Nindirectsyms uint32 137 Extreloff uint32 138 Nextrel uint32 139 Locreloff uint32 140 Nlocrel uint32 141 } 142 143 // DylibCmdは、Mach-Oの動的ライブラリロードコマンドです。 144 DylibCmd struct { 145 Cmd LoadCmd 146 Len uint32 147 Name uint32 148 Time uint32 149 CurrentVersion uint32 150 CompatVersion uint32 151 } 152 153 // RpathCmdは、Mach-Oのrpathコマンドです。 154 RpathCmd struct { 155 Cmd LoadCmd 156 Len uint32 157 Path uint32 158 } 159 160 // Threadは、Mach-Oのスレッド状態コマンドです。 161 Thread struct { 162 Cmd LoadCmd 163 Len uint32 164 Type uint32 165 Data []uint32 166 } 167 ) 168 169 const ( 170 FlagNoUndefs uint32 = 0x1 171 FlagIncrLink uint32 = 0x2 172 FlagDyldLink uint32 = 0x4 173 FlagBindAtLoad uint32 = 0x8 174 FlagPrebound uint32 = 0x10 175 FlagSplitSegs uint32 = 0x20 176 FlagLazyInit uint32 = 0x40 177 FlagTwoLevel uint32 = 0x80 178 FlagForceFlat uint32 = 0x100 179 FlagNoMultiDefs uint32 = 0x200 180 FlagNoFixPrebinding uint32 = 0x400 181 FlagPrebindable uint32 = 0x800 182 FlagAllModsBound uint32 = 0x1000 183 FlagSubsectionsViaSymbols uint32 = 0x2000 184 FlagCanonical uint32 = 0x4000 185 FlagWeakDefines uint32 = 0x8000 186 FlagBindsToWeak uint32 = 0x10000 187 FlagAllowStackExecution uint32 = 0x20000 188 FlagRootSafe uint32 = 0x40000 189 FlagSetuidSafe uint32 = 0x80000 190 FlagNoReexportedDylibs uint32 = 0x100000 191 FlagPIE uint32 = 0x200000 192 FlagDeadStrippableDylib uint32 = 0x400000 193 FlagHasTLVDescriptors uint32 = 0x800000 194 FlagNoHeapExecution uint32 = 0x1000000 195 FlagAppExtensionSafe uint32 = 0x2000000 196 ) 197 198 // Section32は、32ビットMach-Oセクションヘッダーです。 199 type Section32 struct { 200 Name [16]byte 201 Seg [16]byte 202 Addr uint32 203 Size uint32 204 Offset uint32 205 Align uint32 206 Reloff uint32 207 Nreloc uint32 208 Flags uint32 209 Reserve1 uint32 210 Reserve2 uint32 211 } 212 213 // Section64は、64ビットMach-Oセクションヘッダーです。 214 type Section64 struct { 215 Name [16]byte 216 Seg [16]byte 217 Addr uint64 218 Size uint64 219 Offset uint32 220 Align uint32 221 Reloff uint32 222 Nreloc uint32 223 Flags uint32 224 Reserve1 uint32 225 Reserve2 uint32 226 Reserve3 uint32 227 } 228 229 // Nlist32は、Mach-O 32ビットのシンボルテーブルエントリです。 230 type Nlist32 struct { 231 Name uint32 232 Type uint8 233 Sect uint8 234 Desc uint16 235 Value uint32 236 } 237 238 // Nlist64は、Mach-O 64ビットのシンボルテーブルエントリです。 239 type Nlist64 struct { 240 Name uint32 241 Type uint8 242 Sect uint8 243 Desc uint16 244 Value uint64 245 } 246 247 // Regs386は、Mach-O 386のレジスタ構造体です。 248 type Regs386 struct { 249 AX uint32 250 BX uint32 251 CX uint32 252 DX uint32 253 DI uint32 254 SI uint32 255 BP uint32 256 SP uint32 257 SS uint32 258 FLAGS uint32 259 IP uint32 260 CS uint32 261 DS uint32 262 ES uint32 263 FS uint32 264 GS uint32 265 } 266 267 // RegsAMD64は、Mach-O AMD64のレジスタ構造体です。 268 type RegsAMD64 struct { 269 AX uint64 270 BX uint64 271 CX uint64 272 DX uint64 273 DI uint64 274 SI uint64 275 BP uint64 276 SP uint64 277 R8 uint64 278 R9 uint64 279 R10 uint64 280 R11 uint64 281 R12 uint64 282 R13 uint64 283 R14 uint64 284 R15 uint64 285 IP uint64 286 FLAGS uint64 287 CS uint64 288 FS uint64 289 GS uint64 290 }