Module: MachO::LoadCommands

Defined in:
lib/macho/load_commands.rb

Overview

Classes and constants for parsing load commands in Mach-O binaries.

Defined Under Namespace

Classes: BuildVersionCommand, DyldInfoCommand, DylibCommand, DylinkerCommand, DysymtabCommand, EncryptionInfoCommand, EncryptionInfoCommand64, EntryPointCommand, FvmfileCommand, FvmlibCommand, IdentCommand, LinkeditDataCommand, LinkerOptionCommand, LoadCommand, NoteCommand, PrebindCksumCommand, PreboundDylibCommand, RoutinesCommand, RoutinesCommand64, RpathCommand, SegmentCommand, SegmentCommand64, SourceVersionCommand, SubClientCommand, SubFrameworkCommand, SubLibraryCommand, SubUmbrellaCommand, SymsegCommand, SymtabCommand, ThreadCommand, TwolevelHintsCommand, UUIDCommand, VersionMinCommand

Constant Summary collapse

LC_REQ_DYLD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

load commands added after OS X 10.1 need to be bitwise ORed with LC_REQ_DYLD to be recognized by the dynamic linker (dyld)

0x80000000
LOAD_COMMANDS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

association of load commands to symbol representations

{
  0x1 => :LC_SEGMENT,
  0x2 => :LC_SYMTAB,
  0x3 => :LC_SYMSEG,
  0x4 => :LC_THREAD,
  0x5 => :LC_UNIXTHREAD,
  0x6 => :LC_LOADFVMLIB,
  0x7 => :LC_IDFVMLIB,
  0x8 => :LC_IDENT,
  0x9 => :LC_FVMFILE,
  0xa => :LC_PREPAGE,
  0xb => :LC_DYSYMTAB,
  0xc => :LC_LOAD_DYLIB,
  0xd => :LC_ID_DYLIB,
  0xe => :LC_LOAD_DYLINKER,
  0xf => :LC_ID_DYLINKER,
  0x10 => :LC_PREBOUND_DYLIB,
  0x11 => :LC_ROUTINES,
  0x12 => :LC_SUB_FRAMEWORK,
  0x13 => :LC_SUB_UMBRELLA,
  0x14 => :LC_SUB_CLIENT,
  0x15 => :LC_SUB_LIBRARY,
  0x16 => :LC_TWOLEVEL_HINTS,
  0x17 => :LC_PREBIND_CKSUM,
  (0x18 | LC_REQ_DYLD) => :LC_LOAD_WEAK_DYLIB,
  0x19 => :LC_SEGMENT_64,
  0x1a => :LC_ROUTINES_64,
  0x1b => :LC_UUID,
  (0x1c | LC_REQ_DYLD) => :LC_RPATH,
  0x1d => :LC_CODE_SIGNATURE,
  0x1e => :LC_SEGMENT_SPLIT_INFO,
  (0x1f | LC_REQ_DYLD) => :LC_REEXPORT_DYLIB,
  0x20 => :LC_LAZY_LOAD_DYLIB,
  0x21 => :LC_ENCRYPTION_INFO,
  0x22 => :LC_DYLD_INFO,
  (0x22 | LC_REQ_DYLD) => :LC_DYLD_INFO_ONLY,
  (0x23 | LC_REQ_DYLD) => :LC_LOAD_UPWARD_DYLIB,
  0x24 => :LC_VERSION_MIN_MACOSX,
  0x25 => :LC_VERSION_MIN_IPHONEOS,
  0x26 => :LC_FUNCTION_STARTS,
  0x27 => :LC_DYLD_ENVIRONMENT,
  (0x28 | LC_REQ_DYLD) => :LC_MAIN,
  0x29 => :LC_DATA_IN_CODE,
  0x2a => :LC_SOURCE_VERSION,
  0x2b => :LC_DYLIB_CODE_SIGN_DRS,
  0x2c => :LC_ENCRYPTION_INFO_64,
  0x2d => :LC_LINKER_OPTION,
  0x2e => :LC_LINKER_OPTIMIZATION_HINT,
  0x2f => :LC_VERSION_MIN_TVOS,
  0x30 => :LC_VERSION_MIN_WATCHOS,
  0x31 => :LC_NOTE,
  0x32 => :LC_BUILD_VERSION,
  (0x33 | LC_REQ_DYLD) => :LC_DYLD_EXPORTS_TRIE,
  (0x34 | LC_REQ_DYLD) => :LD_DYLD_CHAINED_FIXUPS,
}.freeze
LOAD_COMMAND_CONSTANTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

association of symbol representations to load command constants

LOAD_COMMANDS.invert.freeze
DYLIB_LOAD_COMMANDS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

load commands responsible for loading dylibs

%i[
  LC_LOAD_DYLIB
  LC_LOAD_WEAK_DYLIB
  LC_REEXPORT_DYLIB
  LC_LAZY_LOAD_DYLIB
  LC_LOAD_UPWARD_DYLIB
].freeze
CREATABLE_LOAD_COMMANDS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

load commands that can be created manually via LoadCommand.create

DYLIB_LOAD_COMMANDS + %i[
  LC_ID_DYLIB
  LC_RPATH
  LC_LOAD_DYLINKER
].freeze
LC_STRUCTURES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

association of load command symbols to string representations of classes

{
  :LC_SEGMENT => "SegmentCommand",
  :LC_SYMTAB => "SymtabCommand",
  # "obsolete"
  :LC_SYMSEG => "SymsegCommand",
  # seems obsolete, but not documented as such
  :LC_THREAD => "ThreadCommand",
  :LC_UNIXTHREAD => "ThreadCommand",
  # "obsolete"
  :LC_LOADFVMLIB => "FvmlibCommand",
  # "obsolete"
  :LC_IDFVMLIB => "FvmlibCommand",
  # "obsolete"
  :LC_IDENT => "IdentCommand",
  # "reserved for internal use only"
  :LC_FVMFILE => "FvmfileCommand",
  # "reserved for internal use only", no public struct
  :LC_PREPAGE => "LoadCommand",
  :LC_DYSYMTAB => "DysymtabCommand",
  :LC_LOAD_DYLIB => "DylibCommand",
  :LC_ID_DYLIB => "DylibCommand",
  :LC_LOAD_DYLINKER => "DylinkerCommand",
  :LC_ID_DYLINKER => "DylinkerCommand",
  :LC_PREBOUND_DYLIB => "PreboundDylibCommand",
  :LC_ROUTINES => "RoutinesCommand",
  :LC_SUB_FRAMEWORK => "SubFrameworkCommand",
  :LC_SUB_UMBRELLA => "SubUmbrellaCommand",
  :LC_SUB_CLIENT => "SubClientCommand",
  :LC_SUB_LIBRARY => "SubLibraryCommand",
  :LC_TWOLEVEL_HINTS => "TwolevelHintsCommand",
  :LC_PREBIND_CKSUM => "PrebindCksumCommand",
  :LC_LOAD_WEAK_DYLIB => "DylibCommand",
  :LC_SEGMENT_64 => "SegmentCommand64",
  :LC_ROUTINES_64 => "RoutinesCommand64",
  :LC_UUID => "UUIDCommand",
  :LC_RPATH => "RpathCommand",
  :LC_CODE_SIGNATURE => "LinkeditDataCommand",
  :LC_SEGMENT_SPLIT_INFO => "LinkeditDataCommand",
  :LC_REEXPORT_DYLIB => "DylibCommand",
  :LC_LAZY_LOAD_DYLIB => "DylibCommand",
  :LC_ENCRYPTION_INFO => "EncryptionInfoCommand",
  :LC_DYLD_INFO => "DyldInfoCommand",
  :LC_DYLD_INFO_ONLY => "DyldInfoCommand",
  :LC_LOAD_UPWARD_DYLIB => "DylibCommand",
  :LC_VERSION_MIN_MACOSX => "VersionMinCommand",
  :LC_VERSION_MIN_IPHONEOS => "VersionMinCommand",
  :LC_FUNCTION_STARTS => "LinkeditDataCommand",
  :LC_DYLD_ENVIRONMENT => "DylinkerCommand",
  :LC_MAIN => "EntryPointCommand",
  :LC_DATA_IN_CODE => "LinkeditDataCommand",
  :LC_SOURCE_VERSION => "SourceVersionCommand",
  :LC_DYLIB_CODE_SIGN_DRS => "LinkeditDataCommand",
  :LC_ENCRYPTION_INFO_64 => "EncryptionInfoCommand64",
  :LC_LINKER_OPTION => "LinkerOptionCommand",
  :LC_LINKER_OPTIMIZATION_HINT => "LinkeditDataCommand",
  :LC_VERSION_MIN_TVOS => "VersionMinCommand",
  :LC_VERSION_MIN_WATCHOS => "VersionMinCommand",
  :LC_NOTE => "NoteCommand",
  :LC_BUILD_VERSION => "BuildVersionCommand",
  :LC_DYLD_EXPORTS_TRIE => "LinkeditDataCommand",
  :LD_DYLD_CHAINED_FIXUPS => "LinkeditDataCommand",
}.freeze
SEGMENT_NAMES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

association of segment name symbols to names

{
  :SEG_PAGEZERO => "__PAGEZERO",
  :SEG_TEXT => "__TEXT",
  :SEG_DATA => "__DATA",
  :SEG_OBJC => "__OBJC",
  :SEG_ICON => "__ICON",
  :SEG_LINKEDIT => "__LINKEDIT",
  :SEG_UNIXSTACK => "__UNIXSTACK",
  :SEG_IMPORT => "__IMPORT",
}.freeze
SEGMENT_FLAGS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

association of segment flag symbols to values

{
  :SG_HIGHVM => 0x1,
  :SG_FVMLIB => 0x2,
  :SG_NORELOC => 0x4,
  :SG_PROTECTED_VERSION_1 => 0x8,
}.freeze